Refactor Microchip MCP47FEB02 I2C driver in separate modules to add support for MCP48FEB02 SPI driver
Subsystems (4)
Ariana Lazar
maintainerv7 cover Refactor Microchip MCP47FEB02 I2C driver in separate modules to add support for MCP48FEB02 SPI driver
Refactor I2C driver implementation into separate modules in order to add support for SPI MCP48FxBy1/2/4/8 DAC family on top of the I2C implementation. The I2C and SPI devices have the same memory map and supported functionalities.
---
Changes in v7:
- replace custom mask define with standard field_prep()
- use "Suggested-by" instead of "Reported-by" where it was more suitable
- use "Fixes:" with "Closes:" instead of "Link:" for fixes tags in commit
messages
- modified module description for core when adding support for SPI parts
in order to specify SPI families too
- remove unused macro MCP47FEB02_GAIN_BIT_MASK from the second commit
- Link to v6: https://lore.kernel.org/r/[email protected]
Changes in v6:
- use field_get() in Gain, Vref and Power-Down registers channel formulas
- rebase from 7.2 to 7.3-rc1
- add fixes tags and Cc stable in the commit messages
- add numeric constants in front of time defines for better readability
- replaced dev_err() with dev_warn_probe() for missing label
- if match data is not found at probe, return -ENODATA and a suitable
error message
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- improve commit messages by justifying the changes made
- increase polling time for EEPROM writes
- delete unnecessary comments and extra blank line from header file
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- remove unused headers
- add missing header types.h in protocol files
- create 6 precursor commits before the refactor patch for handling:
- comment typo
- renaming command mask define
- for an invalid label use a debug message instead of probe error
- correct return value in store_eeprom_store() for false state case
- correct channel gain formula
- read DAC value register to initialize channel data struct field at
probe
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- renumbering the patch version to include the first patch submision
- fix review comments device tree binding:
- change 'additionalProperties' to unevaluatedProperties
- add else branch with spi-max-frequency in the condition which checks
if a device has SPI interface
- correct SPI address example
- add clock polarity and clock phase properties for SPI devices
- enumerate I2C devices in lexicographic order from the description section
- specify supported SPI modes using dependencies
- fix review comments driver:
- remove unneccesarry libraries and add the missing ones
- correct comment typo
- return -ENODEV using dev_err_probe() in protocol probe functions
- use named initializers
- move defines for registers and enums from the header to the core file
- add dev_set_drvdata() in probe()
- move mutex aquiring from mcp47feb02_write_to_eeprom() to
store_eeprom_store()
- write correct value into Vref register in resume()
- Link to v2: https://lore.kernel.org/r/[email protected]
v2:
- include in the same patch series the refactoring of the driver and the
support for SPI devices, but in different patches
- remove changes regarding review comments received not related to the
code refactoring
- first version of the combined refactoring I2C and adding support for SPI
driver
- Link to v1: https://lore.kernel.org/all/[email protected]
v1:
- first version which did not separate the refactoring and adding support for SPI devices (into different patches from the same series)
---
Ariana Lazar (11):
iio: dac: mcp47feb02: initialize dac_data field in channel data struct at probe
iio: dac: mcp47feb02: Fix gain field initialization for active channels
iio: dac: mcp47feb02: use field_get() instead of custom dynamic macros
iio: dac: mcp47feb02: Return len when disabling EEPROM store
iio: dac: mcp47feb02: Increase EEPROM Programming Write Cycle Time
iio: dac: mcp47feb02: Avoid unjustified probe error on missing label
iio: dac: mcp47feb02: correct typo from a comment
iio: dac: mcp47feb02: use field_prep() instead of custom dynamic macros
iio: dac: mcp47feb02: refactor MCP47FEB02 I2C driver into two modules
dt-bindings: iio: dac: add support for MCP48FEB02 SPI
iio: dac: add support for Microchip MCP48FEB02
.../bindings/iio/dac/microchip,mcp47feb02.yaml | 221 +++++++++---
MAINTAINERS | 2 +-
drivers/iio/dac/Kconfig | 32 +-
drivers/iio/dac/Makefile | 4 +-
.../iio/dac/{mcp47feb02.c => mcp47feb02-core.c} | 388 ++++-----------------
drivers/iio/dac/mcp47feb02-i2c.c | 145 ++++++++
drivers/iio/dac/mcp47feb02-spi.c | 145 ++++++++
drivers/iio/dac/mcp47feb02.h | 43 +++
8 files changed, 600 insertions(+), 380 deletions(-)---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260625-mcp47feb02_refactor-fa8420ae3282
Best regards,
Signature · 1 line
Ariana Lazar <[email protected]>
Ariana Lazar
maintainerPATCH v7 1/11 iio: dac: mcp47feb02: initialize dac_data field in channel data struct at probe
Prevent operations which use cache from overwriting default hardware values with zeros by reading active DAC registers during probe to correctly initialize the channel struct DAC values.
--- drivers/iio/dac/mcp47feb02.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/iio/dac/mcp47feb02.c +6 -1
@@ -1019,7 +1019,12 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data) gain_ch = gain_ch &MCP47FEB02_GAIN_BITS_MASK ;for_each_set_bit (i, &data->active_channels_mask, data->phys_channels) {struct device *dev =regmap_get_device (data->regmap); -unsigned int pd_tmp; +unsigned int pd_tmp, dac_val; + + ret =regmap_read (data->regmap,REG_ADDR (i), &dac_val); +if (ret) +return ret; + data->chdata[i].dac_data = dac_val; data->chdata[i].ref_mode = (vref_ch >> (2 * i)) &MCP47FEB02_DAC_CTRL_MASK ; data->chdata[i].use_2x_gain = (gain_ch >> i) &MCP47FEB02_GAIN_BIT_MASK ;
Signature · 1 line
2.43.0
Re: [PATCH v7 01/11] iio: dac: mcp47feb02: initialize dac_data field in channel data struct at probe
Quoted 3 lines · Ariana Lazar
Prevent operations which use cache from overwriting default hardware values with zeros by reading active DAC registers during probe to correctly initialize the channel struct DAC values.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ariana Lazar
maintainerPATCH v7 2/11 iio: dac: mcp47feb02: Fix gain field initialization for active channels
In reply to Ariana LazarAs per MCP47FXBX48 Datasheet, in the format of the Gain Control and System Status Register each DAC channel has one bit to control its gain, starting at bit 8, while bits 0-7 contain status or unimplemented bits.
The previous formula didn't initialize correctly all channels, being replaced by using field_get() with the already defined macro used in write operations where needed in the rest of the driver implementation. DAC_GAIN_MASK(i) extracts the gain control bit for each active channel correctly in one step.
--- drivers/iio/dac/mcp47feb02.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iio/dac/mcp47feb02.c +1 -3
@@ -36,7 +36,6 @@#define MCP47FEB02_DAC_CTRL_MASK GENMASK(1, 0)#define MCP47FEB02_GAIN_CTRL_STATUS_REG_ADDR 0x50 -#define MCP47FEB02_GAIN_BIT_MASK BIT(0)#define MCP47FEB02_GAIN_BIT_STATUS_EEWA_MASK BIT(6)#define MCP47FEB02_GAIN_BITS_MASK GENMASK(15, 8)
@@ -1016,7 +1015,6 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)if (ret)return ret; - gain_ch = gain_ch &MCP47FEB02_GAIN_BITS_MASK ;for_each_set_bit (i, &data->active_channels_mask, data->phys_channels) {struct device *dev =regmap_get_device (data->regmap);unsigned int pd_tmp, dac_val;
@@ -1027,7 +1025,7 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data) data->chdata[i].dac_data = dac_val; data->chdata[i].ref_mode = (vref_ch >> (2 * i)) &MCP47FEB02_DAC_CTRL_MASK ; - data->chdata[i].use_2x_gain = (gain_ch >> i) &MCP47FEB02_GAIN_BIT_MASK ; + data->chdata[i].use_2x_gain =field_get (DAC_GAIN_MASK (i), gain_ch);/* * Inform the user that the current voltage reference read from the volatile
Signature · 1 line
2.43.0
Re: [PATCH v7 02/11] iio: dac: mcp47feb02: Fix gain field initialization for active channels
Quoted 9 lines · Ariana Lazar
As per MCP47FXBX48 Datasheet, in the format of the Gain Control and System Status Register each DAC channel has one bit to control its gain, starting at bit 8, while bits 0-7 contain status or unimplemented bits.
The previous formula didn't initialize correctly all channels, being replaced by using
field_get()with the already defined macro used in write operations where needed in the rest of the driver implementation.DAC_GAIN_MASK(i)extracts the gain control bit for each active channel correctly in one step.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ariana Lazar
maintainerPATCH v7 3/11 iio: dac: mcp47feb02: use field_get() instead of custom dynamic macros
In reply to Ariana LazarReplace manual bit operations which select channel corresponding bits from a control register in mcp47feb02_init_ctrl_regs() with field_get() macro used with masks already defined for regmap operations within the driver.
--- drivers/iio/dac/mcp47feb02.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/dac/mcp47feb02.c +2 -2
@@ -1024,7 +1024,7 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)return ret; data->chdata[i].dac_data = dac_val; - data->chdata[i].ref_mode = (vref_ch >> (2 * i)) &MCP47FEB02_DAC_CTRL_MASK ; + data->chdata[i].ref_mode =field_get (DAC_CTRL_MASK (i), vref_ch); data->chdata[i].use_2x_gain =field_get (DAC_GAIN_MASK (i), gain_ch);/*
@@ -1068,7 +1068,7 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)break ; } - pd_tmp = (pd_ch >> (2 * i)) &MCP47FEB02_DAC_CTRL_MASK ; + pd_tmp =field_get (DAC_CTRL_MASK (i), pd_ch); data->chdata[i].powerdown_mode = pd_tmp ? (pd_tmp -1 ) : pd_tmp; data->chdata[i].powerdown = !!(data->chdata[i].powerdown_mode); }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v7 03/11] iio: dac: mcp47feb02: use field_get() instead of custom dynamic macros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] iio: dac: unused macro MCP47FEB02_DAC_CTRL_MASK left behind --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] iio: dac: unused macro MCP47FEB02_DAC_CTRL_MASK left behind
--
commit d3bd49e7115fae14b0ecbbde0aa73b674836dfd2
Author: Ariana Lazar <[email protected]>
iio: dac: mcp47feb02: use field_get() instead of custom dynamic macros
This commit replaces manual bit operations for selecting channel-specific bits with the field_get() macro in mcp47feb02_init_ctrl_regs().
Quoted 4 lines
drivers/iio/dac/mcp47feb02.c +0
-0
[ ... ]
drivers/iio/dac/mcp47feb02.c static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data) · line 1027
Quoted 6 lines
drivers/iio/dac/mcp47feb02.c +1
-1@@ -1024,7 +1024,7 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)return ret; data->chdata[i].dac_data = dac_val; - data->chdata[i].ref_mode = (vref_ch >> (2 * i)) &MCP47FEB02_DAC_CTRL_MASK ; + data->chdata[i].ref_mode =field_get (DAC_CTRL_MASK (i), vref_ch);
[Severity: Low]
Does this change leave behind MCP47FEB02_DAC_CTRL_MASK as unused dead code?
Since this patch replaces all instances of MCP47FEB02_DAC_CTRL_MASK, should the original definition be removed from the file to prevent code clutter?
drivers/iio/dac/mcp47feb02.c:
#define MCP47FEB02_DAC_CTRL_MASK GENMASK(1, 0)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v7 03/11] iio: dac: mcp47feb02: use field_get() instead of custom dynamic macros
In reply to Ariana LazarQuoted 8 lines · Ariana Lazar
Replace manual bit operations which select channel corresponding bits from a control register in
mcp47feb02_init_ctrl_regs()withfield_get()macro used with masks already defined for regmap operations within the driver.Suggested-by Jonathan Cameron <[email protected]>
No need a Link tag for the simple suggestion. I believe there no any unobvious things that were discussed at that Link.
Quoted 1 line
Signed-off-by Ariana Lazar <[email protected]>
Also this is not a fix, move it towards the tail of the series.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v7 03/11] iio: dac: mcp47feb02: use field_get() instead of custom dynamic macros
In reply to Ariana LazarQuoted 8 lines · On Fri, 18 Sep 2026 12:06:29 +0300 Ariana Lazar <[email protected]>…
Replace manual bit operations which select channel corresponding bits from a control register in
mcp47feb02_init_ctrl_regs()withfield_get()macro used with masks already defined for regmap operations within the driver.
The Eagle eyed sashiko points out that MCP47FEB02_DAC_CTRL_MASK seems to be no longer used after this patch. Please drop that as well.
Jonathan
Quoted 27 lines
--- drivers/iio/dac/mcp47feb02.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/iio/dac/mcp47feb02.c +2
-2@@ -1024,7 +1024,7 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)return ret; data->chdata[i].dac_data = dac_val; - data->chdata[i].ref_mode = (vref_ch >> (2 * i)) &MCP47FEB02_DAC_CTRL_MASK ; + data->chdata[i].ref_mode =field_get (DAC_CTRL_MASK (i), vref_ch); data->chdata[i].use_2x_gain =field_get (DAC_GAIN_MASK (i), gain_ch);/* @@ -1068,7 +1068,7 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)break ; } - pd_tmp = (pd_ch >> (2 * i)) &MCP47FEB02_DAC_CTRL_MASK ; + pd_tmp =field_get (DAC_CTRL_MASK (i), pd_ch); data->chdata[i].powerdown_mode = pd_tmp ? (pd_tmp -1 ) : pd_tmp; data->chdata[i].powerdown = !!(data->chdata[i].powerdown_mode); }
Ariana Lazar
maintainerPATCH v7 4/11 iio: dac: mcp47feb02: Return len when disabling EEPROM store
In reply to Ariana LazarWhen state is false, return the number of bytes (len) the buffer has instead of 0 to properly signal that the input buffer was fully consumed, preventing unnecessary write retries.
--- drivers/iio/dac/mcp47feb02.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/mcp47feb02.c +1 -1
@@ -467,7 +467,7 @@ static ssize_t store_eeprom_store(struct device *dev, struct device_attribute *areturn ret;if (!state) -return 0 ; +return len;/* * Verify DAC Wiper and DAC Configuration are unlocked. If both are disabled,
Signature · 1 line
2.43.0
Re: [PATCH v7 04/11] iio: dac: mcp47feb02: Return len when disabling EEPROM store
Quoted 3 lines · Ariana Lazar
When state is false, return the number of bytes (len) the buffer has instead of 0 to properly signal that the input buffer was fully consumed, preventing unnecessary write retries.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ariana Lazar
maintainerPATCH v7 5/11 iio: dac: mcp47feb02: Increase EEPROM Programming Write Cycle Time
In reply to Ariana LazarIncrease the EEPROM write polling timeout to prevent -ETIMEDOUT errors and incomplete nonvolatile write cycle, according to the time specified in the datasheets (11-16 ms).
--- drivers/iio/dac/mcp47feb02.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/dac/mcp47feb02.c +2 -2
@@ -447,7 +447,7 @@ static int mcp47feb02_write_to_eeprom(struct mcp47feb02_data *data, unsigned int ret =regmap_read_poll_timeout (data->regmap,MCP47FEB02_GAIN_CTRL_STATUS_REG_ADDR , eewa_val, !(eewa_val &MCP47FEB02_GAIN_BIT_STATUS_EEWA_MASK ), -USEC_PER_MSEC ,USEC_PER_MSEC *5 ); +1 *USEC_PER_MSEC ,150 *USEC_PER_MSEC );if (ret)return ret;
@@ -507,7 +507,7 @@ static ssize_t store_eeprom_store(struct device *dev, struct device_attribute *a ret =regmap_read_poll_timeout (data->regmap,MCP47FEB02_GAIN_CTRL_STATUS_REG_ADDR , eewa_val, !(eewa_val &MCP47FEB02_GAIN_BIT_STATUS_EEWA_MASK ), -USEC_PER_MSEC ,USEC_PER_MSEC *5 ); +1 *USEC_PER_MSEC ,150 *USEC_PER_MSEC );if (ret)return ret;
Signature · 1 line
2.43.0
Re: [PATCH v7 05/11] iio: dac: mcp47feb02: Increase EEPROM Programming Write Cycle Time
Quoted 3 lines · Ariana Lazar
Increase the EEPROM write polling timeout to prevent
-ETIMEDOUTerrors and incomplete nonvolatile write cycle, according to the time specified in the datasheets (11-16 ms).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ariana Lazar
maintainerPATCH v7 6/11 iio: dac: mcp47feb02: Avoid unjustified probe error on missing label
In reply to Ariana LazarFix unjustified probe error on missing optional 'label' property by replacing dev_err_probe() with dev_warn_probe(). Correct %pfw usage by passing the child fwnode handle directly in the error message. Besides the probe warning a read error is returned at the attempt of reading a null label.
--- drivers/iio/dac/mcp47feb02.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/iio/dac/mcp47feb02.c +5 -3
@@ -921,7 +921,10 @@ static int mcp47feb02_read_label(struct iio_dev *indio_dev, struct iio_chan_spec {struct mcp47feb02_data *data =iio_priv (indio_dev); -return sysfs_emit (label,"%s\n" , data->labels[ch->address]); +if (data->labels[ch->address]) +return sysfs_emit (label,"%s\n" , data->labels[ch->address]); + +return -ENOENT ; }static const struct iio_info mcp47feb02_info = {
@@ -976,8 +979,7 @@ static int mcp47feb02_parse_fw(struct iio_dev *indio_dev, ret =fwnode_property_read_string (child,"label" , &data->labels[reg]);if (ret) -return dev_err_probe (dev, ret,"%pfw: invalid label\n" , -fwnode_get_name (child)); +dev_warn_probe (dev, ret,"%pfw: invalid label\n" , child); chanspec.address = reg; chanspec.channel = reg;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v7 06/11] iio: dac: mcp47feb02: Avoid unjustified probe error on missing label
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] iio: dac: mcp47feb02: dev_warn_probe() spams on valid missing optional label --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] iio: dac: mcp47feb02: dev_warn_probe() spams on valid missing optional label --
commit e0f4987920f8a3564ad483dd9c2d2cc4904bdc2f
Author: Ariana Lazar <[email protected]>
iio: dac: mcp47feb02: Avoid unjustified probe error on missing label
This commit avoids a probe failure when the optional 'label' property is missing by replacing dev_err_probe() with dev_warn_probe(). It also returns -ENOENT in the read_label sysfs callback when attempting to read a missing label.
Quoted 4 lines
drivers/iio/dac/mcp47feb02.c +0
-0
[ ... ]
drivers/iio/dac/mcp47feb02.c static int mcp47feb02_parse_fw(struct iio_dev *indio_dev, · line 982
Quoted 7 lines
drivers/iio/dac/mcp47feb02.c +1
-2@@ -976,8 +979,7 @@ static int mcp47feb02_parse_fw(struct iio_dev *indio_dev, ret =fwnode_property_read_string (child,"label" , &data->labels[reg]);if (ret) -return dev_err_probe (dev, ret,"%pfw: invalid label\n" , -fwnode_get_name (child)); +dev_warn_probe (dev, ret,"%pfw: invalid label\n" , child);
[Severity: Medium]
Since the label is an optional property, fwnode_property_read_string() returning a non-zero value is a valid and expected condition when the property is omitted.
Does this unconditional dev_warn_probe() cause unnecessary warning spam in the kernel boot log for valid configurations that don't specify a label?
Quoted 3 lines
drivers/iio/dac/mcp47feb02.c +0
-0chanspec.address = reg; chanspec.channel = reg;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH v7 06/11] iio: dac: mcp47feb02: Avoid unjustified probe error on missing label
In reply to Ariana LazarQuoted 5 lines · Ariana Lazar
Fix unjustified probe error on missing optional 'label' property by replacing
dev_err_probe()withdev_warn_probe(). Correct %pfw usage by passing the child fwnode handle directly in the error message. Besides the probe warning a read error is returned at the attempt of reading a null label.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v7 06/11] iio: dac: mcp47feb02: Avoid unjustified probe error on missing label
In reply to Ariana LazarQuoted 29 lines
Fix unjustified probe error on missing optional 'label' property by replacing
dev_err_probe()withdev_warn_probe(). Correct %pfw usage by passing the child fwnode handle directly in the error message. Besides the probe warning a read error is returned at the attempt of reading a null label.Fixes bf394cc80369 ("iio: dac: adding support for Microchip MCP47FEB02")Reported-by [email protected]Signed-off-by Ariana Lazar <[email protected]>drivers/iio/dac/mcp47feb02.c +4
-1@@ -921,7 +921,10 @@ static int mcp47feb02_read_label(struct iio_dev *indio_dev, struct iio_chan_spec {struct mcp47feb02_data *data =iio_priv (indio_dev); -return sysfs_emit (label,"%s\n" , data->labels[ch->address]); +if (data->labels[ch->address]) +return sysfs_emit (label,"%s\n" , data->labels[ch->address]); + +return -ENOENT ; }static const struct iio_info mcp47feb02_info = {
drivers/iio/dac/mcp47feb02.c static int mcp47feb02_parse_fw(struct iio_dev *indio_dev, · line 982
Quoted 6 lines
drivers/iio/dac/mcp47feb02.c +1
-2@@ -976,8 +979,7 @@ static int mcp47feb02_parse_fw(struct iio_dev *indio_dev, ret =fwnode_property_read_string (child,"label" , &data->labels[reg]);if (ret) -return dev_err_probe (dev, ret,"%pfw: invalid label\n" , -fwnode_get_name (child)); +dev_warn_probe (dev, ret,"%pfw: invalid label\n" , child);
Sashiko says:
[Severity: Medium]
Since the label is an optional property, fwnode_property_read_string() returning a non-zero value is a valid and expected condition when the property is omitted.
Does this unconditional dev_warn_probe() cause unnecessary warning spam in the kernel boot log for valid configurations that don't specify a label?
-
I think I agree on this. We should perhaps wrap this in a property_present check. If it is simply not there carry on without a warning print.
Signature · 1 line
Jonathan Cameron <[email protected]>
Ariana Lazar
maintainerPATCH v7 7/11 iio: dac: mcp47feb02: correct typo from a comment
In reply to Ariana LazarTypo corrected to 'Register' in the comment regarding defined masks for the gain register.
--- drivers/iio/dac/mcp47feb02.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/mcp47feb02.c +1 -1
@@ -51,7 +51,7 @@#define DAC_CTRL_MASK (ch) (GENMASK(1, 0) << (2 * (ch)))#define DAC_CTRL_VAL (ch, val) ((val) << (2 * (ch))) -/* Gain Control and I2C Slave Address Reguster fields */ +/* Gain Control and I2C Slave Address Register fields */ #define DAC_GAIN_MASK (ch) (BIT(0) << (8 + (ch)))#define DAC_GAIN_VAL (ch, val) ((val) << (8 + (ch)))
Signature · 1 line
2.43.0
Re: [PATCH v7 07/11] iio: dac: mcp47feb02: correct typo from a comment
Quoted 5 lines · Ariana Lazar
Typo corrected to 'Register' in the comment regarding defined masks for the gain register.
No Link for non-controversial / pretty much obvious suggestions.
Quoted 1 line
Signed-off-by Ariana Lazar <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ariana Lazar
maintainerPATCH v7 8/11 iio: dac: mcp47feb02: use field_prep() instead of custom dynamic macros
In reply to Ariana LazarReplace manual bit operations which select channel corresponding bits from a control register for each write to regmap operation using regmap_update_bits(). This approach matches the use of field_get() in probe() and improves code readability.
--- drivers/iio/dac/mcp47feb02.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)
drivers/iio/dac/mcp47feb02.c +22 -14
@@ -48,12 +48,10 @@#define MCP47FEB02_NV_I2C_SLAVE_ADDR_MASK GENMASK(7, 0)/* Voltage reference, Power-Down control register and DAC Wiperlock status register fields */ -#define DAC_CTRL_MASK (ch) (GENMASK(1, 0) << (2 * (ch))) -#define DAC_CTRL_VAL (ch, val) ((val) << (2 * (ch))) +#define MCP47FEB02_VREF_PD_MASK (ch) (GENMASK(1, 0) << (2 * (ch)))/* Gain Control and I2C Slave Address Register fields */ #define DAC_GAIN_MASK (ch) (BIT(0) << (8 + (ch))) -#define DAC_GAIN_VAL (ch, val) ((val) << (8 + (ch)))#define REG_ADDR (reg) ((reg) << 3)#define NV_REG_ADDR (reg) ((NV_DAC_ADDR_OFFSET + (reg)) << 3)
@@ -550,11 +548,13 @@ static int mcp47feb02_suspend(struct device *dev)for_each_set_bit (ch, &data->active_channels_mask, data->phys_channels) {u8 pd_mode; +u32 mask; data->chdata[ch].powerdown = true; pd_mode = data->chdata[ch].powerdown_mode +1 ; + mask =MCP47FEB02_VREF_PD_MASK (ch); ret =regmap_update_bits (data->regmap,MCP47FEB02_POWER_DOWN_REG_ADDR , -DAC_CTRL_MASK (ch),DAC_CTRL_VAL (ch, pd_mode)); + mask,field_prep (mask, pd_mode));if (ret)return ret;
@@ -576,6 +576,7 @@ static int mcp47feb02_resume(struct device *dev)for_each_set_bit (ch, &data->active_channels_mask, data->phys_channels) {u8 pd_mode; +u32 mask;int ret; data->chdata[ch].powerdown = false;
@@ -585,20 +586,21 @@ static int mcp47feb02_resume(struct device *dev)if (ret)return ret; + mask =MCP47FEB02_VREF_PD_MASK (ch); ret =regmap_update_bits (data->regmap,MCP47FEB02_VREF_REG_ADDR , -DAC_CTRL_MASK (ch),DAC_CTRL_VAL (ch, pd_mode)); + mask,field_prep (mask, pd_mode));if (ret)return ret; + mask =DAC_GAIN_MASK (ch); ret =regmap_update_bits (data->regmap,MCP47FEB02_GAIN_CTRL_STATUS_REG_ADDR , -DAC_GAIN_MASK (ch), -DAC_GAIN_VAL (ch, data->chdata[ch].use_2x_gain)); + mask,field_prep (mask, data->chdata[ch].use_2x_gain));if (ret)return ret; + mask =MCP47FEB02_VREF_PD_MASK (ch); ret =regmap_update_bits (data->regmap,MCP47FEB02_POWER_DOWN_REG_ADDR , -DAC_CTRL_MASK (ch), -DAC_CTRL_VAL (ch,MCP47FEB02_NORMAL_OPERATION )); + mask,field_prep (mask,MCP47FEB02_NORMAL_OPERATION ));if (ret)return ret; }
@@ -641,6 +643,7 @@ static ssize_t mcp47feb02_write_powerdown(struct iio_dev *indio_dev, uintptr_t pu32 reg = ch->address;u8 tmp_pd_mode;bool state; +u32 mask;int ret;guard (mutex)(&data->lock);
@@ -654,8 +657,9 @@ static ssize_t mcp47feb02_write_powerdown(struct iio_dev *indio_dev, uintptr_t p* requires writing normal operation mode (0) to the channel-specific register bits. */ tmp_pd_mode = state ? (data->chdata[reg].powerdown_mode +1 ) :MCP47FEB02_NORMAL_OPERATION ; + mask =MCP47FEB02_VREF_PD_MASK (reg); ret =regmap_update_bits (data->regmap,MCP47FEB02_POWER_DOWN_REG_ADDR , -DAC_CTRL_MASK (reg),DAC_CTRL_VAL (reg, tmp_pd_mode)); + mask,field_prep (mask, tmp_pd_mode));if (ret)return ret;
@@ -799,6 +803,7 @@ static int mcp47feb02_check_scale(struct mcp47feb02_data *data, int val, int valstatic int mcp47feb02_ch_scale (struct mcp47feb02_data *data,int ch,int scale) {int tmp_val, ret; +u32 mask;if (scale ==MCP47FEB02_SCALE_VDD ) { tmp_val =MCP47FEB02_VREF_VDD ;
@@ -820,8 +825,9 @@ static int mcp47feb02_ch_scale(struct mcp47feb02_data *data, int ch, int scale) tmp_val =MCP47FEB02_INTERNAL_BAND_GAP ; } + mask =MCP47FEB02_VREF_PD_MASK (ch); ret =regmap_update_bits (data->regmap,MCP47FEB02_VREF_REG_ADDR , -DAC_CTRL_MASK (ch),DAC_CTRL_VAL (ch, tmp_val)); + mask,field_prep (mask, tmp_val));if (ret)return ret;
@@ -844,6 +850,7 @@ static int mcp47feb02_ch_scale(struct mcp47feb02_data *data, int ch, int scale)static int mcp47feb02_set_scale (struct mcp47feb02_data *data,int ch,int scale) {int tmp_val, ret; +u32 mask; ret =mcp47feb02_ch_scale (data, ch, scale);if (ret)
@@ -854,8 +861,9 @@ static int mcp47feb02_set_scale(struct mcp47feb02_data *data, int ch, int scale)else tmp_val =MCP47FEB02_GAIN_BIT_X1 ; + mask =DAC_GAIN_MASK (ch); ret =regmap_update_bits (data->regmap,MCP47FEB02_GAIN_CTRL_STATUS_REG_ADDR , -DAC_GAIN_MASK (ch),DAC_GAIN_VAL (ch, tmp_val)); + mask,field_prep (mask, tmp_val));if (ret)return ret;
@@ -1026,7 +1034,7 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)return ret; data->chdata[i].dac_data = dac_val; - data->chdata[i].ref_mode =field_get (DAC_CTRL_MASK (i), vref_ch); + data->chdata[i].ref_mode =field_get (MCP47FEB02_VREF_PD_MASK (i), vref_ch); data->chdata[i].use_2x_gain =field_get (DAC_GAIN_MASK (i), gain_ch);/*
@@ -1070,7 +1078,7 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)break ; } - pd_tmp =field_get (DAC_CTRL_MASK (i), pd_ch); + pd_tmp =field_get (MCP47FEB02_VREF_PD_MASK (i), pd_ch); data->chdata[i].powerdown_mode = pd_tmp ? (pd_tmp -1 ) : pd_tmp; data->chdata[i].powerdown = !!(data->chdata[i].powerdown_mode); }
Signature · 1 line
2.43.0
Ariana Lazar
maintainerPATCH v7 9/11 iio: dac: mcp47feb02: refactor MCP47FEB02 I2C driver into two modules
In reply to Ariana LazarPrepare the driver for the bus-specific code by refactoring into separate files. The renamed file will contain the common DAC functionality shared by the MCP47FxBy1/2/4/8 I2C and MCP48FxBy1/2/4/8 SPI drivers. The MCP47FEB02 driver was refactored into two modules: mcp47feb02-core.c and mcp47feb02-i2c.c in order to prepare the support for SPI MCP48FxBy1/2/4/8 DAC family on top of the current implementation.
---
MAINTAINERS | 2 +-
drivers/iio/dac/Kconfig | 9 +-
drivers/iio/dac/Makefile | 3 +-
.../iio/dac/{mcp47feb02.c => mcp47feb02-core.c} | 325 ++-------------------
drivers/iio/dac/mcp47feb02-i2c.c | 145 +++++++++
drivers/iio/dac/mcp47feb02.h | 43 +++
6 files changed, 220 insertions(+), 307 deletions(-)MAINTAINERS +1 -1
@@ -16297,7 +16297,7 @@ M: Ariana Lazar <[email protected]> L: [email protected] S: Supported F: Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml -F: drivers/iio/dac/mcp47feb02.c +F: drivers/iio/dac/mcp47feb02* MCP4821 DAC DRIVER M: Anshul Dalal <[email protected]>
drivers/iio/dac/Kconfig +7 -2
@@ -593,9 +593,13 @@ config MCP47A1 will be called mcp47a1. config MCP47FEB02 - tristate "MCP47F(E/V)B01/02/04/08/11/12/14/18/21/22/24/28 DAC driver" + tristate + +config MCP47FEB02_I2C + tristate "MCP47F(E/V)B01/02/04/08/11/12/14/18/21/22/24/28 I2C DAC driver" depends on I2C select REGMAP_I2C + select MCP47FEB02 help Say yes here if you want to build the driver for the Microchip: - 8-bit DAC:
@@ -611,7 +615,8 @@ config MCP47FEB02 (DAC) with I2C interface. To compile this driver as a module, choose M here: the module - will be called mcp47feb02. + will be called mcp47feb02_i2c and you will also get + mcp47feb02_core for the core module. config MCP4821 tristate "MCP4801/02/11/12/21/22 DAC driver"
drivers/iio/dac/Makefile +2 -1
@@ -56,7 +56,8 @@ obj-$(CONFIG_MCF54415_DAC) += mcf54415_dac.o obj-$(CONFIG_MCP4725) += mcp4725.o obj-$(CONFIG_MCP4728) += mcp4728.o obj-$(CONFIG_MCP47A1) += mcp47a1.o -obj-$(CONFIG_MCP47FEB02) += mcp47feb02.o +obj-$(CONFIG_MCP47FEB02) += mcp47feb02-core.o +obj-$(CONFIG_MCP47FEB02_I2C) += mcp47feb02-i2c.o obj-$(CONFIG_MCP4821) += mcp4821.o obj-$(CONFIG_MCP4922) += mcp4922.o obj-$(CONFIG_STM32_DAC_CORE) += stm32-dac-core.o
drivers/iio/dac/mcp47feb02-core.c renamed from drivers/iio/dac/mcp47feb02.c +22 -303
436 lines not on this page · raw message
drivers/iio/dac/mcp47feb02-i2c.c new file +145 -0
145 lines not on this page · raw message
drivers/iio/dac/mcp47feb02.h new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v7 09/11] iio: dac: mcp47feb02: refactor MCP47FEB02 I2C driver into two modules
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] kbuild: Kconfig backward compatibility breakage during module split - [Low] iio: dac…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] kbuild: Kconfig backward compatibility breakage during module split
- [Low] iio: dac: mcp47feb02: PM operations exported outside driver namespace --
commit 8ebb6f8ca4b9fbd374359f689f69be2c855ffca3
Author: Ariana Lazar <[email protected]>
iio: dac: mcp47feb02: refactor MCP47FEB02 I2C driver into two modules
This commit prepares the MCP47FEB02 driver for bus-specific code by refactoring it into separate core and I2C files. It creates a shared core module to support upcoming SPI parts and renames Kconfig and file structures accordingly.
drivers/iio/dac/Kconfig config MCP47A1 · line 599
Quoted 13 lines
drivers/iio/dac/Kconfig +4
-1@@ -593,9 +593,13 @@ config MCP47A1 will be called mcp47a1. config MCP47FEB02 - tristate "MCP47F(E/V)B01/02/04/08/11/12/14/18/21/22/24/28 DAC driver" + tristate + +config MCP47FEB02_I2C + tristate "MCP47F(E/V)B01/02/04/08/11/12/14/18/21/22/24/28 I2C DAC driver"
[Severity: Medium]
Does renaming the user-visible Kconfig prompt break backward compatibility during kernel upgrades?
When users upgrade their kernels using make oldconfig or make olddefconfig, their existing CONFIG_MCP47FEB02 setting will be discarded because it lacks a prompt. The new CONFIG_MCP47FEB02_I2C defaults to 'n', resulting in the driver being silently disabled on existing configurations.
Is it possible to keep the original config name for the user-visible option and create a new hidden config (e.g., CONFIG_MCP47FEB02_CORE) for the shared code to ensure seamless upgrades?
[ ... ]
Quoted 7 lines
drivers/iio/dac/mcp47feb02-core.c renamed from drivers/iio/dac/mcp47feb02.c +0
-0
[ ... ]
drivers/iio/dac/mcp47feb02-core.c static ssize_t mcp47feb02_write_powerdown(struct iio_dev *indio_dev, uintptr_t p · line 464
Quoted 6 lines
drivers/iio/dac/mcp47feb02-core.c renamed from drivers/iio/dac/mcp47feb02.c +1
-1@@ -668,7 +461,7 @@ static ssize_t mcp47feb02_write_powerdown(struct iio_dev *indio_dev, uintptr_t preturn len; } -static DEFINE_SIMPLE_DEV_PM_OPS(mcp47feb02_pm_ops, mcp47feb02_suspend, mcp47feb02_resume); +EXPORT_SIMPLE_DEV_PM_OPS (mcp47feb02_pm_ops, mcp47feb02_suspend, mcp47feb02_resume);
[Severity: Low]
Does this macro export the PM ops symbol without the intended IIO_MCP47FEB02 namespace?
The driver establishes a dedicated namespace IIO_MCP47FEB02 for its core exported symbols, but mcp47feb02_pm_ops is exported using EXPORT_SIMPLE_DEV_PM_OPS, which places it into the global namespace.
Should this use EXPORT_NS_SIMPLE_DEV_PM_OPS(mcp47feb02_pm_ops, mcp47feb02_suspend, mcp47feb02_resume, IIO_MCP47FEB02) instead to maintain namespace encapsulation?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Jonathan Cameron
maintainerRe: [PATCH v7 09/11] iio: dac: mcp47feb02: refactor MCP47FEB02 I2C driver into two modules
In reply to Ariana LazarQuoted 8 lines
Prepare the driver for the bus-specific code by refactoring into separate files. The renamed file will contain the common DAC functionality shared by the MCP47FxBy1/2/4/8 I2C and MCP48FxBy1/2/4/8 SPI drivers. The MCP47FEB02 driver was refactored into two modules:
mcp47feb02-core.candmcp47feb02-i2c.cin order to prepare the support for SPI MCP48FxBy1/2/4/8 DAC family on top of the current implementation.Signed-off-by Ariana Lazar <[email protected]>
Sashiko makes a point about change of Kconfig symbol and make oldconfig etc. Not ideal but we've done this before and I don't think it has proved a signficant problem in practice. We could carry an extra symbol to avoid the problem but it is going to be a long term bit of mess so I think what you have here is the way to go.
Otherwise a few small things inline.
Quoted 10 lines
drivers/iio/dac/mcp47feb02-core.c renamed from drivers/iio/dac/mcp47feb02.c +0
-0unsigned int val)
drivers/iio/dac/mcp47feb02-core.c static int mcp47feb02_write_to_eeprom(struct mcp47feb02_data *data, unsigned int · line 444
Quoted 5 lines
drivers/iio/dac/mcp47feb02-core.c renamed from drivers/iio/dac/mcp47feb02.c +0
-2@@ -440,8 +235,6 @@ static int mcp47feb02_write_to_eeprom(struct mcp47feb02_data *data, unsigned int* Wait until the currently occurring EEPROM Write Cycle is completed. * Only serial commands to the volatile memory are allowed. */ -guard (mutex)(&data->lock); -
What is this change doing in this patch? Looking at the code I think is indeed a good thing to do, just shouldn't be hidden down in here.
Break this out as a separate precursor patch.
Quoted 35 lines
drivers/iio/dac/mcp47feb02-core.c renamed from drivers/iio/dac/mcp47feb02.c +3
-3ret = regmap_read_poll_timeout(data->regmap, MCP47FEB02_GAIN_CTRL_STATUS_REG_ADDR, eewa_val, !(eewa_val & MCP47FEB02_GAIN_BIT_STATUS_EEWA_MASK),@@ -467,6 +260,8 @@ static ssize_t store_eeprom_store(struct device *dev, struct device_attribute *aif (!state)return len; +guard (mutex)(&data->lock); +/* * Verify DAC Wiper and DAC Configuration are unlocked. If both are disabled, * writing to EEPROM is available. @@ -575,12 +370,10 @@ static int mcp47feb02_resume(struct device *dev)guard (mutex)(&data->lock);for_each_set_bit (ch, &data->active_channels_mask, data->phys_channels) { -u8 pd_mode;u32 mask;int ret; data->chdata[ch].powerdown = false; - pd_mode = data->chdata[ch].powerdown_mode +1 ; ret =regmap_write (data->regmap,REG_ADDR (ch), data->chdata[ch].dac_data);if (ret)@@ -588,7 +381,7 @@ static int mcp47feb02_resume(struct device *dev) mask =MCP47FEB02_VREF_PD_MASK (ch); ret =regmap_update_bits (data->regmap,MCP47FEB02_VREF_REG_ADDR , - mask,field_prep (mask, pd_mode)); + mask,field_prep (mask, data->chdata[ch].ref_mode));if (ret)return ret;
drivers/iio/dac/mcp47feb02-core.c static ssize_t mcp47feb02_write_powerdown(struct iio_dev *indio_dev, uintptr_t p · line 464
Quoted 5 lines
drivers/iio/dac/mcp47feb02-core.c renamed from drivers/iio/dac/mcp47feb02.c +1
-1@@ -668,7 +461,7 @@ static ssize_t mcp47feb02_write_powerdown(struct iio_dev *indio_dev, uintptr_t preturn len; } -static DEFINE_SIMPLE_DEV_PM_OPS(mcp47feb02_pm_ops, mcp47feb02_suspend, mcp47feb02_resume); +EXPORT_SIMPLE_DEV_PM_OPS (mcp47feb02_pm_ops, mcp47feb02_suspend, mcp47feb02_resume);
Sashiko:
[Severity: Low]
Does this macro export the PM ops symbol without the intended IIO_MCP47FEB02 namespace?
The driver establishes a dedicated namespace IIO_MCP47FEB02 for its core exported symbols, but mcp47feb02_pm_ops is exported using EXPORT_SIMPLE_DEV_PM_OPS, which places it into the global namespace.
Should this use EXPORT_NS_SIMPLE_DEV_PM_OPS(mcp47feb02_pm_ops, mcp47feb02_suspend, mcp47feb02_resume, IIO_MCP47FEB02) instead to maintain namespace encapsulation?
-
That is a good spot. Yes, this should use the NS variant.
Thanks,
Jonathan
Signature · 1 line
Jonathan Cameron <[email protected]>
Ariana Lazar
maintainerPATCH v7 10/11 dt-bindings: iio: dac: add support for MCP48FEB02 SPI
In reply to Ariana LazarAdd the SPI MCP48FxBy1/2/4/8 part numbers, the spi-max-frequency property and a devicetree example for SPI usage to the existing binding.
--- .../bindings/iio/dac/microchip,mcp47feb02.yaml | 221 ++++++++++++++++----- 1 file changed, 173 insertions(+), 48 deletions(-)
Documentation/devicetree/bindings/iio/dac/microchip,mcp47feb02.yaml +173 -48
@@ -4,58 +4,92 @@ $id: http://devicetree.org/schemas/iio/dac/microchip,mcp47feb02.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Microchip MCP47F(E/V)B(0/1/2)(1/2/4/8) DAC with I2C Interface Families +title: Microchip MCP4(7/8)F(E/V)B(0/1/2)(1/2/4/8) DAC with I2C/SPI Interface Families maintainers: - Ariana Lazar <[email protected]> description: | - Datasheet for MCP47FEB01, MCP47FEB11, MCP47FEB21, MCP47FEB02, MCP47FEB12, - MCP47FEB22 can be found here: - https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005375A.pdf - Datasheet for MCP47FVB01, MCP47FVB11, MCP47FVB21, MCP47FVB02, MCP47FVB12, - MCP47FVB22 can be found here: - https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005405A.pdf - Datasheet for MCP47FEB04, MCP47FEB14, MCP47FEB24, MCP47FEB08, MCP47FEB18, - MCP47FEB28, MCP47FVB04, MCP47FVB14, MCP47FVB24, MCP47FVB08, MCP47FVB18, - MCP47FVB28 can be found here: - https://ww1.microchip.com/downloads/aemDocuments/documents/MSLD/ProductDocuments/DataSheets/MCP47FXBX48-Data-Sheet-DS200006368A.pdf - - +------------+--------------+-------------+-------------+------------+ - | Device | Resolution | Channels | Vref number | Memory | - |------------|--------------|-------------|-------------|------------| - | MCP47FEB01 | 8-bit | 1 | 1 | EEPROM | - | MCP47FEB11 | 10-bit | 1 | 1 | EEPROM | - | MCP47FEB21 | 12-bit | 1 | 1 | EEPROM | - |------------|--------------|-------------|-------------|------------| - | MCP47FEB02 | 8-bit | 2 | 1 | EEPROM | - | MCP47FEB12 | 10-bit | 2 | 1 | EEPROM | - | MCP47FEB22 | 12-bit | 2 | 1 | EEPROM | - |------------|--------------|-------------|-------------|------------| - | MCP47FVB01 | 8-bit | 1 | 1 | RAM | - | MCP47FVB11 | 10-bit | 1 | 1 | RAM | - | MCP47FVB21 | 12-bit | 1 | 1 | RAM | - |------------|--------------|-------------|-------------|------------| - | MCP47FVB02 | 8-bit | 2 | 1 | RAM | - | MCP47FVB12 | 10-bit | 2 | 1 | RAM | - | MCP47FVB22 | 12-bit | 2 | 1 | RAM | - |------------|--------------|-------------|-------------|------------| - | MCP47FVB04 | 8-bit | 4 | 2 | RAM | - | MCP47FVB14 | 10-bit | 4 | 2 | RAM | - | MCP47FVB24 | 12-bit | 4 | 2 | RAM | - |------------|--------------|-------------|-------------|------------| - | MCP47FVB08 | 8-bit | 8 | 2 | RAM | - | MCP47FVB18 | 10-bit | 8 | 2 | RAM | - | MCP47FVB28 | 12-bit | 8 | 2 | RAM | - |------------|--------------|-------------|-------------|------------| - | MCP47FEB04 | 8-bit | 4 | 2 | EEPROM | - | MCP47FEB14 | 10-bit | 4 | 2 | EEPROM | - | MCP47FEB24 | 12-bit | 4 | 2 | EEPROM | - |------------|--------------|-------------|-------------|------------| - | MCP47FEB08 | 8-bit | 8 | 2 | EEPROM | - | MCP47FEB18 | 10-bit | 8 | 2 | EEPROM | - | MCP47FEB28 | 12-bit | 8 | 2 | EEPROM | - +------------+--------------+-------------+-------------+------------+ + Datasheets for MCP47F(E/V)B(0/1/2)(1/2/4/8) DAC with I2C Interface Families: + Datasheet for MCP47FEB01, MCP47FEB02, MCP47FEB11, MCP47FEB12, MCP47FEB21, + MCP47FEB22 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005375A.pdf + Datasheet for MCP47FVB01, MCP47FVB02, MCP47FVB11, MCP47FVB12, MCP47FVB21, + MCP47FVB22 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005405A.pdf + Datasheet for MCP47FEB04, MCP47FEB08, MCP47FEB14, MCP47FEB18, MCP47FEB24, + MCP47FEB28, MCP47FVB04, MCP47FVB08, MCP47FVB14, MCP47FVB18, MCP47FVB24, + MCP47FVB28 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/MSLD/ProductDocuments/DataSheets/MCP47FXBX48-Data-Sheet-DS200006368A.pdf + Datasheets for MCP48F(E/V)B(0/1/2)(1/2/4/8) DAC with SPI Interface Families: + Datasheet for MCP48FEB01, MCP48FEB02, MCP48FEB11, MCP48FEB12, MCP48FEB21, + MCP48FEB22 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005429B.pdf + Datasheet for MCP48FVB01, MCP48FVB02, MCP48FVB11, MCP48FVB12, MCP48FVB21, + MCP48FVB22 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005466A.pdf + Datasheet for MCP48FEB04, MCP48FEB14, MCP48FEB24, MCP48FEB08, MCP48FEB18, + MCP48FEB28, MCP48FVB04, MCP48FVB14, MCP48FVB24, MCP48FVB08, MCP48FVB18, + MCP48FVB28 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/MSLD/ProductDocuments/DataSheets/MCP48FXBX4-8-Family-Data-Sheet-DS20006362A.pdf + + +------------+--------------+-------------+-------------+------------+------------+ + | Device | Resolution | Channels | Vref number | Memory | Interface | + |------------|--------------|-------------|-------------|------------|------------| + | MCP47FEB01 | | 1 | 1 | EEPROM | I2C | + | MCP47FEB02 | | 2 | 1 | EEPROM | I2C | + | MCP47FEB04 | | 4 | 2 | EEPROM | I2C | + | MCP47FEB08 | 8-bit | 8 | 2 | EEPROM | I2C | + | MCP48FEB01 | | 1 | 1 | EEPROM | SPI | + | MCP48FEB02 | | 2 | 1 | EEPROM | SPI | + | MCP48FEB04 | | 4 | 2 | EEPROM | SPI | + | MCP48FEB08 | | 8 | 2 | EEPROM | SPI | + |------------|--------------|-------------|-------------|------------|------------| + | MCP47FEB11 | | 1 | 1 | EEPROM | I2C | + | MCP47FEB12 | | 2 | 1 | EEPROM | I2C | + | MCP47FEB14 | | 4 | 2 | EEPROM | I2C | + | MCP47FEB18 | 10-bit | 8 | 2 | EEPROM | I2C | + | MCP48FEB11 | | 1 | 1 | EEPROM | SPI | + | MCP48FEB12 | | 2 | 1 | EEPROM | SPI | + | MCP48FEB14 | | 4 | 2 | EEPROM | SPI | + | MCP48FEB18 | | 8 | 2 | EEPROM | SPI | + |------------|--------------|-------------|-------------|------------|------------| + | MCP47FEB21 | | 1 | 1 | EEPROM | I2C | + | MCP47FEB22 | | 2 | 1 | EEPROM | I2C | + | MCP47FEB24 | | 4 | 2 | EEPROM | I2C | + | MCP47FEB28 | 12-bit | 8 | 2 | EEPROM | I2C | + | MCP48FEB21 | | 1 | 1 | EEPROM | SPI | + | MCP48FEB22 | | 2 | 1 | EEPROM | SPI | + | MCP48FEB24 | | 4 | 2 | EEPROM | SPI | + | MCP48FEB28 | | 8 | 2 | EEPROM | SPI | + |------------|--------------|-------------|-------------|------------|------------| + | MCP47FVB01 | | 1 | 1 | RAM | I2C | + | MCP47FVB02 | | 2 | 1 | RAM | I2C | + | MCP47FVB04 | | 4 | 2 | RAM | I2C | + | MCP47FVB08 | 8-bit | 8 | 2 | RAM | I2C | + | MCP48FVB01 | | 1 | 1 | RAM | SPI | + | MCP48FVB02 | | 2 | 1 | RAM | SPI | + | MCP48FVB04 | | 4 | 2 | RAM | SPI | + | MCP48FVB08 | | 8 | 2 | RAM | SPI | + |------------|--------------|-------------|-------------|------------|------------| + | MCP47FVB11 | | 1 | 1 | RAM | I2C | + | MCP47FVB12 | | 2 | 1 | RAM | I2C | + | MCP47FVB14 | | 4 | 2 | RAM | I2C | + | MCP47FVB18 | 10-bit | 8 | 2 | RAM | I2C | + | MCP48FVB11 | | 1 | 1 | RAM | SPI | + | MCP48FVB12 | | 2 | 1 | RAM | SPI | + | MCP48FVB14 | | 4 | 2 | RAM | SPI | + | MCP48FVB18 | | 8 | 2 | RAM | SPI | + |------------|--------------|-------------|-------------|------------|------------| + | MCP47FVB21 | | 1 | 1 | RAM | I2C | + | MCP47FVB22 | | 2 | 1 | RAM | I2C | + | MCP47FVB24 | | 4 | 2 | RAM | I2C | + | MCP47FVB28 | 12-bit | 8 | 2 | RAM | I2C | + | MCP48FVB21 | | 1 | 1 | RAM | SPI | + | MCP48FVB22 | | 2 | 1 | RAM | SPI | + | MCP48FVB24 | | 4 | 2 | RAM | SPI | + | MCP48FVB28 | | 8 | 2 | RAM | SPI | + +------------+--------------+-------------+-------------+------------+------------+ properties: compatible:
@@ -84,10 +118,37 @@ properties: - microchip,mcp47feb08 - microchip,mcp47feb18 - microchip,mcp47feb28 + - microchip,mcp48feb01 + - microchip,mcp48feb02 + - microchip,mcp48feb04 + - microchip,mcp48feb08 + - microchip,mcp48feb11 + - microchip,mcp48feb12 + - microchip,mcp48feb14 + - microchip,mcp48feb18 + - microchip,mcp48feb21 + - microchip,mcp48feb22 + - microchip,mcp48feb24 + - microchip,mcp48feb28 + - microchip,mcp48fvb01 + - microchip,mcp48fvb02 + - microchip,mcp48fvb04 + - microchip,mcp48fvb08 + - microchip,mcp48fvb11 + - microchip,mcp48fvb12 + - microchip,mcp48fvb14 + - microchip,mcp48fvb18 + - microchip,mcp48fvb21 + - microchip,mcp48fvb22 + - microchip,mcp48fvb24 + - microchip,mcp48fvb28 reg: maxItems: 1 + spi-max-frequency: + maximum: 10000000 + "#address-cells": const: 1
@@ -178,6 +239,21 @@ required: - vdd-supply allOf: + - if: + properties: + compatible: + contains: + pattern: "^microchip,mcp48f[ev]b[0-2][1248]$" + then: + $ref: /schemas/spi/spi-peripheral-props.yaml# + dependencies: + spi-cpha: [ spi-cpol ] + spi-cpol: [ spi-cpha ] + else: + properties: + spi-max-frequency: false + spi-cpha: false + spi-cpol: false - if: properties: compatible:
@@ -189,6 +265,12 @@ allOf: - microchip,mcp47fvb01 - microchip,mcp47fvb11 - microchip,mcp47fvb21 + - microchip,mcp48feb01 + - microchip,mcp48feb11 + - microchip,mcp48feb21 + - microchip,mcp48fvb01 + - microchip,mcp48fvb11 + - microchip,mcp48fvb21 then: properties: lat1-gpios: false
@@ -211,6 +293,12 @@ allOf: - microchip,mcp47fvb02 - microchip,mcp47fvb12 - microchip,mcp47fvb22 + - microchip,mcp48feb02 + - microchip,mcp48feb12 + - microchip,mcp48feb22 + - microchip,mcp48fvb02 + - microchip,mcp48fvb12 + - microchip,mcp48fvb22 then: properties: lat1-gpios: false
@@ -233,6 +321,12 @@ allOf: - microchip,mcp47feb04 - microchip,mcp47feb14 - microchip,mcp47feb24 + - microchip,mcp48feb04 + - microchip,mcp48feb14 + - microchip,mcp48feb24 + - microchip,mcp48fvb04 + - microchip,mcp48fvb14 + - microchip,mcp48fvb24 then: patternProperties: "^channel@[0-3]$":
@@ -251,6 +345,12 @@ allOf: - microchip,mcp47feb08 - microchip,mcp47feb18 - microchip,mcp47feb28 + - microchip,mcp48feb08 + - microchip,mcp48feb18 + - microchip,mcp48feb28 + - microchip,mcp48fvb08 + - microchip,mcp48fvb18 + - microchip,mcp48fvb28 then: patternProperties: "^channel@[0-7]$":
@@ -272,7 +372,7 @@ allOf: properties: microchip,vref1-buffered: false -additionalProperties: false +unevaluatedProperties: false examples: - |
@@ -299,4 +399,29 @@ examples: }; }; }; + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + dac@0 { + compatible = "microchip,mcp48feb02"; + reg = <0x0>; + vdd-supply = <&vdac_vdd>; + vref-supply = <&vref_reg>; + spi-max-frequency = <10000000>; + + #address-cells = <1>; + #size-cells = <0>; + channel@0 { + reg = <0>; + label = "Adjustable_voltage_ch0"; + }; + + channel@1 { + reg = <0x1>; + label = "Adjustable_voltage_ch1"; + }; + }; + }; ...
Signature · 1 line
2.43.0
Ariana Lazar
maintainerPATCH v7 11/11 iio: dac: add support for Microchip MCP48FEB02
In reply to Ariana LazarThis is the IIO driver for Microchip MCP48FxBy1/2/4/8 series of buffered voltage output Digital-to-Analog Converters with nonvolatile or volatile memory and an SPI Interface.
The families support up to 8 output channels.
The devices can be 8-bit, 10-bit and 12-bit.
--- drivers/iio/dac/Kconfig | 23 ++++++ drivers/iio/dac/Makefile | 1 + drivers/iio/dac/mcp47feb02-core.c | 2 +- drivers/iio/dac/mcp47feb02-spi.c | 145 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 170 insertions(+), 1 deletion(-)
drivers/iio/dac/Kconfig +23 -0
@@ -618,6 +618,29 @@ config MCP47FEB02_I2C will be called mcp47feb02_i2c and you will also get mcp47feb02_core for the core module. +config MCP47FEB02_SPI + tristate "MCP48F(E/V)B01/02/04/08/11/12/14/18/21/22/24/28 SPI DAC driver" + depends on SPI + select REGMAP_SPI + select MCP47FEB02 + help + Say yes here if you want to build the driver for the Microchip: + - 8-bit DAC: + MCP48FEB01, MCP48FEB02, MCP48FEB04, MCP48FEB08, + MCP48FVB01, MCP48FVB02, MCP48FVB04, MCP48FVB08 + - 10-bit DAC: + MCP48FEB11, MCP48FEB12, MCP48FEB14, MCP48FEB18, + MCP48FVB11, MCP48FVB12, MCP48FVB14, MCP48FVB18 + - 12-bit DAC: + MCP48FEB21, MCP48FEB22, MCP48FEB24, MCP48FEB28, + MCP48FVB21, MCP48FVB22, MCP48FVB24, MCP48FVB28 + having 1 to 8 channels, 8/10/12-bit digital-to-analog converter + (DAC) with SPI interface. + + To compile this driver as a module, choose M here: the module + will be called mcp47feb02_spi and you will also get + mcp47feb02_core for the core module. + config MCP4821 tristate "MCP4801/02/11/12/21/22 DAC driver" depends on SPI
drivers/iio/dac/Makefile +1 -0
@@ -58,6 +58,7 @@ obj-$(CONFIG_MCP4728) += mcp4728.o obj-$(CONFIG_MCP47A1) += mcp47a1.o obj-$(CONFIG_MCP47FEB02) += mcp47feb02-core.o obj-$(CONFIG_MCP47FEB02_I2C) += mcp47feb02-i2c.o +obj-$(CONFIG_MCP47FEB02_SPI) += mcp47feb02-spi.o obj-$(CONFIG_MCP4821) += mcp4821.o obj-$(CONFIG_MCP4922) += mcp4922.o obj-$(CONFIG_STM32_DAC_CORE) += stm32-dac-core.o
drivers/iio/dac/mcp47feb02-core.c +1 -1
@@ -977,5 +977,5 @@ int mcp47feb02_common_probe(const struct mcp47feb02_features *chip_features,EXPORT_SYMBOL_NS (mcp47feb02_common_probe,"IIO_MCP47FEB02" );MODULE_AUTHOR ("Ariana Lazar <[email protected]>" ); -MODULE_DESCRIPTION ("IIO driver for MCP47FEB02 Multi-Channel DAC with I2C interface" ); +MODULE_DESCRIPTION ("IIO driver for MCP47FEB02/MCP48FEB02 Multi-Channel DAC" );MODULE_LICENSE ("GPL" );
drivers/iio/dac/mcp47feb02-spi.c new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 4 lines · Ariana Lazar
Refactor I2C driver implementation into separate modules in order to add support for SPI MCP48FxBy1/2/4/8 DAC family on top of the I2C implementation. The I2C and SPI devices have the same memory map and supported functionalities.
Jonathan, can you pick up the fixes from the series, please? It will reduce a burden a lot (yeah, I know that it might mess with Sashiko, but wouldn't simple delay fix this, I mean to give Sashiko a time it needs and then update the branch?).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 11 lines · On Fri, 18 Sep 2026 12:52:53 +0300 Andy Shevchenko…
Quoted 4 lines · Ariana Lazar
Refactor I2C driver implementation into separate modules in order to add support for SPI MCP48FxBy1/2/4/8 DAC family on top of the I2C implementation. The I2C and SPI devices have the same memory map and supported functionalities.
Jonathan, can you pick up the fixes from the series, please? It will reduce a burden a lot (yeah, I know that it might mess with Sashiko, but wouldn't simple delay fix this, I mean to give Sashiko a time it needs and then update the branch?).
I'm not sure sashiko ever looks beyond mainline and given recent general comments from Linus about only sending him late cycle fixes for stuff that went wrong this cycle or is a major issue (which I've been interpreting
as applying after rc4) I'm not thinking these fixes will go upstream before the merge window. I don't mind applying them to the togreg branch now but
that isn't currently picked up by sashiko.
My biggest current issue with these bots is they make the workflow of nibbling away at patch sets like I traditionally did not work so well. One option is to just send the whole series but edit the titles to say they are already applied? Hopefully that lets reviewers jump over them or even maybe filter them out?
Anyhow, let me queue some of these. I doubt we'll see anything new from sashiko given the minor tweaks the rest of this series.
So with that in mind, applied patches in this order 1 2 4 5
held 6 back for the thing about checking if property present. 3 7 8 with link dropped.
So just 6 9 and 10 for next version please.
All the above on the testing branch of iio.git.
Thanks,
Jonathan
[email protected]
maintainerHi Jonathan,
Thank you for the review.
Quoted 11 lines
Anyhow, let me queue some of these. I doubt we'll see anything new from sashiko given the minor tweaks the rest of this series.
So with that in mind, applied patches in this order 1 2 4 5
held 6 back for the thing about checking if property present. 3 7 8 with link dropped.So just 6 9 and 10 for next version please.
All the above on the testing branch of iio.git.
I was wondering if the correct approach for the v8 series is to create a new branch based on iio/testing and add the remaining patches onto it?
These would include the needed changes: the property_present check for the label (former patch 6), the new precursor patch for the EEPROM mutex (former patch 9 split into 2 patches), along with the refactoring and SPI support additions (former patches 10 and 11).
Please let me know if this is the preferred way to handle it.
Best regards,
Ariana
Jonathan Cameron
maintainerQuoted 20 lines · On Mon, 21 Sep 2026 14:16:34 +0000 <[email protected]> wrote:
Hi Jonathan,
Thank you for the review.
Quoted 11 lines
Anyhow, let me queue some of these. I doubt we'll see anything new from sashiko given the minor tweaks the rest of this series.
So with that in mind, applied patches in this order 1 2 4 5
held 6 back for the thing about checking if property present. 3 7 8 with link dropped.So just 6 9 and 10 for next version please.
All the above on the testing branch of iio.git.
I was wondering if the correct approach for the v8 series is to create a new branch based on iio/testing and add the remaining patches onto it?
Quoted 6 lines
These would include the needed changes: the
property_presentcheck for the label (former patch 6), the new precursor patch for the EEPROM mutex (former patch 9 split into 2 patches), along with the refactoring and SPI support additions (former patches 10 and 11).Please let me know if this is the preferred way to handle it.
Yes please do that. It will probably confuse sashiko but as discussed above the chances of Sashiko spotting new stuff at this point should be low anyway. Prior to the LLMs becoming useful we used to do this sort of partial series being merged a lot. It's less common now as we loose bot coverage.
Thanks,
Jonathan
Quoted 5 lines
Best regards,
Ariana