Refactor Microchip MCP47FEB02 I2C driver in separate modules to add support for MCP48FEB02 SPI driver
Subsystems (4)
Ariana Lazar
maintainerv6 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 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: rename channel mask and value 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} | 373 +++------------------
drivers/iio/dac/mcp47feb02-i2c.c | 145 ++++++++
drivers/iio/dac/mcp47feb02-spi.c | 145 ++++++++
drivers/iio/dac/mcp47feb02.h | 43 +++
8 files changed, 591 insertions(+), 374 deletions(-)---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260625-mcp47feb02_refactor-fa8420ae3282
Best regards,
Signature · 1 line
Ariana Lazar <[email protected]>
Ariana Lazar
maintainerPATCH v6 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
Ariana Lazar
maintainerPATCH v6 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 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/dac/mcp47feb02.c +1 -2
@@ -1016,7 +1016,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 +1026,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
[email protected]
AI reviewRe: [PATCH v6 02/11] iio: dac: mcp47feb02: Fix gain field initialization for active channels
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] iio: dac: unused macro MCP47FEB02_GAIN_BIT_MASK --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] iio: dac: unused macro MCP47FEB02_GAIN_BIT_MASK
--
commit 9156f8c32ec03099abf89f1f0f71cf04b9870e24
Author: Ariana Lazar <[email protected]>
iio: dac: mcp47feb02: Fix gain field initialization for active channels
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 patch updates the driver to use field_get() for correctly extracting the gain control bit for each active channel.
Quoted 13 lines
drivers/iio/dac/mcp47feb02.c +0
-1@@ -1016,7 +1016,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;
drivers/iio/dac/mcp47feb02.c static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data) · line 1029
Quoted 5 lines
drivers/iio/dac/mcp47feb02.c +1
-1@@ -1027,7 +1026,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);
[Severity: Low]
Does this leave the MCP47FEB02_GAIN_BIT_MASK macro defined but unused?
Since this was its only usage in mcp47feb02_init_ctrl_regs(), should the definition also be removed from drivers/iio/dac/mcp47feb02.c?
Quoted 2 lines
drivers/iio/dac/mcp47feb02.c +0
-0/* * Inform the user that the current voltage reference read from the volatile
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Ariana Lazar
maintainerPATCH v6 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
@@ -1025,7 +1025,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);/*
@@ -1069,7 +1069,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
Re: [PATCH v6 03/11] iio: dac: mcp47feb02: use field_get() instead of custom dynamic macros
Quoted 6 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.Reported-by Jonathan Cameron <[email protected]>
If it's a fix then better to add a Fixes tag, otherwise I would use Suggested-by.
Quoted 1 line
Again, if it's a fix, this should be Closes:.
Quoted 1 line
Signed-off-by Ariana Lazar <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ariana Lazar
maintainerPATCH v6 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
@@ -468,7 +468,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
Ariana Lazar
maintainerPATCH v6 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
@@ -448,7 +448,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;
@@ -508,7 +508,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
Ariana Lazar
maintainerPATCH v6 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
@@ -922,7 +922,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 = {
@@ -977,8 +980,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 v6 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: spurious warning logged for missing optional label --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] iio: dac: spurious warning logged for missing optional label
--
commit e24a38fff253c54913e6b4136af8560e0bb6d2da
Author: Ariana Lazar <[email protected]>
iio: dac: mcp47feb02: Avoid unjustified probe error on missing label
This commit resolves an unjustified probe error when the optional 'label' property is missing by substituting dev_err_probe() with dev_warn_probe(). It also corrects %pfw usage and safely handles null label reads.
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 983
Quoted 7 lines
drivers/iio/dac/mcp47feb02.c +1
-2@@ -977,8 +980,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 commit message indicates the 'label' property is optional, does this code unintentionally cause log spam for valid configurations?
When the label is not present in the devicetree, fwnode_property_read_string() will return an error. Because this code checks if (ret) and calls dev_warn_probe() unconditionally, a warning will be logged on every boot even when the missing label is a valid setup.
Looking at the rest of the patch series, it does not appear that this warning behavior is updated in subsequent patches like mcp47feb02-core.c.
Is there a way to verify the exact error code or avoid the warning entirely when the property is simply absent?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Ariana Lazar
maintainerPATCH v6 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
@@ -52,7 +52,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 v6 07/11] iio: dac: mcp47feb02: correct typo from a comment
Quoted 7 lines · Ariana Lazar
Typo corrected to 'Register' in the comment regarding defined masks for the gain register.
I agree with what Andy said on the cover letter, Suggested-by is better in these cases.
--
Kind regards,
Joshua Crofts
Ariana Lazar
maintainerPATCH v6 8/11 iio: dac: mcp47feb02: rename channel mask and value macros
In reply to Ariana LazarRename generic DAC_CTRL_MASK/VAL macros to MCP47FEB02_VREF_PD_MASK/VAL in order to clearly indicate for which control registers these channel masks are suitable.
--- drivers/iio/dac/mcp47feb02.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
drivers/iio/dac/mcp47feb02.c +13 -10
@@ -49,8 +49,8 @@#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))) +#define MCP47FEB02_VREF_PD_VAL (ch, val) ((val) << (2 * (ch)))/* Gain Control and I2C Slave Address Register fields */ #define DAC_GAIN_MASK (ch) (BIT(0) << (8 + (ch)))
@@ -555,7 +555,8 @@ static int mcp47feb02_suspend(struct device *dev) data->chdata[ch].powerdown = true; pd_mode = data->chdata[ch].powerdown_mode +1 ; ret =regmap_update_bits (data->regmap,MCP47FEB02_POWER_DOWN_REG_ADDR , -DAC_CTRL_MASK (ch),DAC_CTRL_VAL (ch, pd_mode)); +MCP47FEB02_VREF_PD_MASK (ch), +MCP47FEB02_VREF_PD_VAL (ch, pd_mode));if (ret)return ret;
@@ -587,7 +588,8 @@ static int mcp47feb02_resume(struct device *dev)return ret; ret =regmap_update_bits (data->regmap,MCP47FEB02_VREF_REG_ADDR , -DAC_CTRL_MASK (ch),DAC_CTRL_VAL (ch, pd_mode)); +MCP47FEB02_VREF_PD_MASK (ch), +MCP47FEB02_VREF_PD_VAL (ch, pd_mode));if (ret)return ret;
@@ -598,8 +600,8 @@ static int mcp47feb02_resume(struct device *dev)return ret; ret =regmap_update_bits (data->regmap,MCP47FEB02_POWER_DOWN_REG_ADDR , -DAC_CTRL_MASK (ch), -DAC_CTRL_VAL (ch,MCP47FEB02_NORMAL_OPERATION )); +MCP47FEB02_VREF_PD_MASK (ch), +MCP47FEB02_VREF_PD_VAL (ch,MCP47FEB02_NORMAL_OPERATION ));if (ret)return ret; }
@@ -656,7 +658,8 @@ static ssize_t mcp47feb02_write_powerdown(struct iio_dev *indio_dev, uintptr_t p*/ tmp_pd_mode = state ? (data->chdata[reg].powerdown_mode +1 ) :MCP47FEB02_NORMAL_OPERATION ; ret =regmap_update_bits (data->regmap,MCP47FEB02_POWER_DOWN_REG_ADDR , -DAC_CTRL_MASK (reg),DAC_CTRL_VAL (reg, tmp_pd_mode)); +MCP47FEB02_VREF_PD_MASK (reg), +MCP47FEB02_VREF_PD_VAL (reg, tmp_pd_mode));if (ret)return ret;
@@ -822,7 +825,7 @@ static int mcp47feb02_ch_scale(struct mcp47feb02_data *data, int ch, int scale) } ret =regmap_update_bits (data->regmap,MCP47FEB02_VREF_REG_ADDR , -DAC_CTRL_MASK (ch),DAC_CTRL_VAL (ch, tmp_val)); +MCP47FEB02_VREF_PD_MASK (ch),MCP47FEB02_VREF_PD_VAL (ch, tmp_val));if (ret)return ret;
@@ -1027,7 +1030,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);/*
@@ -1071,7 +1074,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
Jonathan Cameron
maintainerRe: [PATCH v6 08/11] iio: dac: mcp47feb02: rename channel mask and value macros
Quoted 16 lines · On Wed, 16 Sep 2026 17:16:34 +0300 Ariana Lazar <[email protected]>…
Rename generic DAC_CTRL_MASK/VAL macros to MCP47FEB02_VREF_PD_MASK/VAL in order to clearly indicate for which control registers these channel masks are suitable.
Reported-by Jonathan Cameron <[email protected]>Signed-off-by Ariana Lazar <[email protected]>--- drivers/iio/dac/mcp47feb02.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)drivers/iio/dac/mcp47feb02.c +0
-0
drivers/iio/dac/mcp47feb02.c line 53
Quoted 7 lines
drivers/iio/dac/mcp47feb02.c +2
-2@@ -49,8 +49,8 @@#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))) +#define MCP47FEB02_VREF_PD_VAL (ch, val) ((val) << (2 * (ch)))
Can we drop this one...
drivers/iio/dac/mcp47feb02.c static int mcp47feb02_suspend(struct device *dev) · line 559
Quoted 10 lines
drivers/iio/dac/mcp47feb02.c +2
-1/* Gain Control and I2C Slave Address Register fields */ #define DAC_GAIN_MASK (ch) (BIT(0) << (8 + (ch)))@@ -555,7 +555,8 @@ static int mcp47feb02_suspend(struct device *dev) data->chdata[ch].powerdown = true; pd_mode = data->chdata[ch].powerdown_mode +1 ; ret =regmap_update_bits (data->regmap,MCP47FEB02_POWER_DOWN_REG_ADDR , -DAC_CTRL_MASK (ch),DAC_CTRL_VAL (ch, pd_mode)); +MCP47FEB02_VREF_PD_MASK (ch), +MCP47FEB02_VREF_PD_VAL (ch, pd_mode));
.. and here have a local for mask.
mask = MCP47FEB02_VREF_PD_MASK(ch); ret = regmap_update_bits(data->regmap, MCP47FEB02_POWER_DOWN_REG_ADDR, mask, field_prep(mask, pd_mode));
Same in all the other cases. Will then match you do the field_get().
Quoted 64 lines
drivers/iio/dac/mcp47feb02.c +2
-1if (ret)return ret;@@ -587,7 +588,8 @@ static int mcp47feb02_resume(struct device *dev)return ret; ret =regmap_update_bits (data->regmap,MCP47FEB02_VREF_REG_ADDR , -DAC_CTRL_MASK (ch),DAC_CTRL_VAL (ch, pd_mode)); +MCP47FEB02_VREF_PD_MASK (ch), +MCP47FEB02_VREF_PD_VAL (ch, pd_mode));if (ret)drivers/iio/dac/mcp47feb02.c +7
-6return ret;@@ -598,8 +600,8 @@ static int mcp47feb02_resume(struct device *dev)return ret; ret =regmap_update_bits (data->regmap,MCP47FEB02_POWER_DOWN_REG_ADDR , -DAC_CTRL_MASK (ch), -DAC_CTRL_VAL (ch,MCP47FEB02_NORMAL_OPERATION )); +MCP47FEB02_VREF_PD_MASK (ch), +MCP47FEB02_VREF_PD_VAL (ch,MCP47FEB02_NORMAL_OPERATION ));if (ret)return ret; }@@ -656,7 +658,8 @@ static ssize_t mcp47feb02_write_powerdown(struct iio_dev *indio_dev, uintptr_t p*/ tmp_pd_mode = state ? (data->chdata[reg].powerdown_mode +1 ) :MCP47FEB02_NORMAL_OPERATION ; ret =regmap_update_bits (data->regmap,MCP47FEB02_POWER_DOWN_REG_ADDR , -DAC_CTRL_MASK (reg),DAC_CTRL_VAL (reg, tmp_pd_mode)); +MCP47FEB02_VREF_PD_MASK (reg), +MCP47FEB02_VREF_PD_VAL (reg, tmp_pd_mode));if (ret)return ret;@@ -822,7 +825,7 @@ static int mcp47feb02_ch_scale(struct mcp47feb02_data *data, int ch, int scale) } ret =regmap_update_bits (data->regmap,MCP47FEB02_VREF_REG_ADDR , -DAC_CTRL_MASK (ch),DAC_CTRL_VAL (ch, tmp_val)); +MCP47FEB02_VREF_PD_MASK (ch),MCP47FEB02_VREF_PD_VAL (ch, tmp_val));if (ret)return ret;@@ -1027,7 +1030,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);/* @@ -1071,7 +1074,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); }
Ariana Lazar
maintainerPATCH v6 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} | 326 ++-------------------
drivers/iio/dac/mcp47feb02-i2c.c | 145 +++++++++
drivers/iio/dac/mcp47feb02.h | 43 +++
6 files changed, 221 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 +23 -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
Ariana Lazar
maintainerPATCH v6 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 v6 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-spi.c | 145 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+)
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-spi.c new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 6 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.
Signed-off-by Ariana Lazar <[email protected]>
Quoted 10 lines
---
Changes in v6:
- usefield_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
- replaceddev_err()withdev_warn_probe()for missing label
- if match data is not found at probe, return-ENODATAand a suitable
error message
- Link to v5: https://lore.kernel.org/r/[email protected]
My main comment against this version is the usage of Reported-by + Closes + Fixes versus Suggested-by. Note, some of the changes doesn't look like a fix, such as a typo in the comment, I dunno if Reported + Closes (no Fixes) is legitimate approach there.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 18 lines · On Wed, 16 Sep 2026 18:26:07 +0300 Andy Shevchenko…
Quoted 6 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.
Signed-off-by Ariana Lazar <[email protected]>Quoted 10 lines
---
Changes in v6:
- usefield_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
- replaceddev_err()withdev_warn_probe()for missing label
- if match data is not found at probe, return-ENODATAand a suitable
error message
- Link to v5: https://lore.kernel.org/r/[email protected]
Quoted 5 lines
My main comment against this version is the usage of Reported-by + Closes + Fixes versus Suggested-by. Note, some of the changes doesn't look like a fix, such as a typo in the comment, I dunno if Reported + Closes (no Fixes) is legitimate approach there.
Other than that one minor thing I raised around field_prep() I think only need to sort out those tags. Given that it is probably near to merge, feel free to send a v7 a little quicker than normal.
Jonathan