* [PATCH 0/2] iio: dac: mcp47a1: add support for new device
@ 2026-07-21 18:24 Joshua Crofts
2026-07-21 18:24 ` [PATCH 1/2] dt-bindings: iio: dac: add support for mcp47a1 Joshua Crofts
2026-07-21 18:24 ` [PATCH 2/2] iio: dac: mcp47a1: add support for new device Joshua Crofts
0 siblings, 2 replies; 8+ messages in thread
From: Joshua Crofts @ 2026-07-21 18:24 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-iio, devicetree, linux-kernel, Joshua Crofts
This patch series adds support for the MCP47A1 DAC.
The Microchip MCP47A1 is a volatile 6-bit Digital-to-Analog converter
which communicates via I2C. It is a low-power, low-cost DAC commonly
used in embedded systems.
Reasons for adding a new driver:
- Existing Microchip DACs use a more complicated set of commands
whereas the MCP47A1 communicates via SMBus using only one command.
- The closest Microchip DAC already in the tree - the MCP4725 - uses
an EEPROM while the MCP47A1 is volatile, meaning that altering
the driver of the former would worsen the code flow.
- The MCP47A1 maps cleanly to a standard regmap.
The driver was tested on a Raspberry Pi 4 using a breakout board with
the MCP47A1.
The datasheet can be viewed here:
https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/25154A.pdf
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
Joshua Crofts (2):
dt-bindings: iio: dac: add support for mcp47a1
iio: dac: mcp47a1: add support for new device
.../bindings/iio/dac/microchip,mcp47a1.yaml | 56 ++++++
MAINTAINERS | 7 +
drivers/iio/dac/Kconfig | 11 ++
drivers/iio/dac/Makefile | 1 +
drivers/iio/dac/mcp47a1.c | 193 +++++++++++++++++++++
5 files changed, 268 insertions(+)
---
base-commit: 036d96ceec6d966339aea34d034420991e24cfac
change-id: 20260711-mcp47a1-add-support-3af1248f13a5
Best regards,
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/2] dt-bindings: iio: dac: add support for mcp47a1 2026-07-21 18:24 [PATCH 0/2] iio: dac: mcp47a1: add support for new device Joshua Crofts @ 2026-07-21 18:24 ` Joshua Crofts 2026-07-21 18:33 ` sashiko-bot 2026-07-21 18:24 ` [PATCH 2/2] iio: dac: mcp47a1: add support for new device Joshua Crofts 1 sibling, 1 reply; 8+ messages in thread From: Joshua Crofts @ 2026-07-21 18:24 UTC (permalink / raw) To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-iio, devicetree, linux-kernel, Joshua Crofts The Microchip MCP47A1 is a 6-bit volatile Digital-to-Analog converted which communicates via I2C. Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com> --- .../bindings/iio/dac/microchip,mcp47a1.yaml | 56 ++++++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 62 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/dac/microchip,mcp47a1.yaml b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47a1.yaml new file mode 100644 index 000000000000..3322fca03b3a --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47a1.yaml @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/iio/dac/microchip,mcp47a1.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip MCP47A1 DAC + +maintainers: + - Joshua Crofts <joshua.crofts1@gmail.com> + +description: | + The Microchip MCP47A1 is a 6-bit single output volatile DAC. + This device can have different IDs (0x2e and 0x3e). + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/25154A.pdf + +properties: + compatible: + const: microchip,mcp47a1 + + reg: + maxItems: 1 + + vref-supply: true + + vdd-supply: true + +required: + - compatible + - reg + - vref-supply + - vdd-supply + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + dac@2e { + compatible = "microchip,mcp47a1"; + reg = <0x2e>; + vref-supply = <&vref_regulator>; + vdd-supply = <&vdd_regulator>; + }; + + dac@3e { + compatible = "microchip,mcp47a1"; + reg = <0x3e>; + vref-supply = <&vref_regulator>; + vdd-supply = <&vdd_regulator>; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 2b1ec46c5919..b44693593b94 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17699,6 +17699,12 @@ S: Maintained F: Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml F: drivers/iio/adc/mcp3911.c +MICROCHIP MCP47A1 DAC DRIVER +M: Joshua Crofts <joshua.crofts1@gmail.com> +L: linux-iio@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/iio/dac/microchip,mcp47a1.yaml + MICROCHIP MCP9982 TEMPERATURE DRIVER M: Victor Duicu <victor.duicu@microchip.com> L: linux-hwmon@vger.kernel.org -- 2.55.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] dt-bindings: iio: dac: add support for mcp47a1 2026-07-21 18:24 ` [PATCH 1/2] dt-bindings: iio: dac: add support for mcp47a1 Joshua Crofts @ 2026-07-21 18:33 ` sashiko-bot 2026-07-21 18:37 ` Joshua Crofts 0 siblings, 1 reply; 8+ messages in thread From: sashiko-bot @ 2026-07-21 18:33 UTC (permalink / raw) To: Joshua Crofts; +Cc: robh, devicetree, conor+dt Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The binding incorrectly requires `vref-supply`, but the MCP47A1 likely does not have a dedicated VREF pin. -- --- Patch [1]: [PATCH 1/2] dt-bindings: iio: dac: add support for mcp47a1 --- commit d1dc3c2e573f4f52e69aabeb608ccb23acd5a123 Author: Joshua Crofts <joshua.crofts1@gmail.com> dt-bindings: iio: dac: add support for mcp47a1 This commit introduces the device tree bindings and MAINTAINERS entry for the Microchip MCP47A1, a 6-bit volatile digital-to-analog converter. > diff --git a/Documentation/devicetree/bindings/iio/dac/microchip,mcp47a1.yaml b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47a1.yaml > new file mode 100644 > index 0000000000000..3322fca03b3a7 > --- /dev/null > +++ b/Documentation/devicetree/bindings/iio/dac/microchip,mcp47a1.yaml [ ... ] > +required: > + - compatible > + - reg > + - vref-supply [Severity: Medium] Does the MCP47A1 actually have a dedicated VREF pin? Standard Microchip I2C DACs in this class (such as the 6-pin MCP4725) typically use VDD as their voltage reference. If there is no physical VREF pin on this hardware, requiring vref-supply here forces device tree authors to define dummy regulators in their device trees just to pass schema validation. > + - vdd-supply > + > +additionalProperties: false -- Sashiko AI review · https://sashiko.dev/#/patchset/20260721-mcp47a1-add-support-v1-0-da045a2567e3@gmail.com?part=1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] dt-bindings: iio: dac: add support for mcp47a1 2026-07-21 18:33 ` sashiko-bot @ 2026-07-21 18:37 ` Joshua Crofts 0 siblings, 0 replies; 8+ messages in thread From: Joshua Crofts @ 2026-07-21 18:37 UTC (permalink / raw) To: sashiko-bot; +Cc: sashiko-reviews, robh, devicetree, conor+dt On Tue, 21 Jul 2026 18:33:58 +0000 sashiko-bot@kernel.org wrote: Clarifying Sashiko's comment: > [Severity: Medium] > Does the MCP47A1 actually have a dedicated VREF pin? Standard Microchip I2C > DACs in this class (such as the 6-pin MCP4725) typically use VDD as their > voltage reference. > > If there is no physical VREF pin on this hardware, requiring vref-supply > here forces device tree authors to define dummy regulators in their > device trees just to pass schema validation. Yes, the MCP47A1 does have a physical VREF pin, as seen in the block diagram: https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/25154A.pdf -- Kind regards, Joshua Crofts ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] iio: dac: mcp47a1: add support for new device 2026-07-21 18:24 [PATCH 0/2] iio: dac: mcp47a1: add support for new device Joshua Crofts 2026-07-21 18:24 ` [PATCH 1/2] dt-bindings: iio: dac: add support for mcp47a1 Joshua Crofts @ 2026-07-21 18:24 ` Joshua Crofts 2026-07-21 19:20 ` sashiko-bot 2026-07-21 20:47 ` Andy Shevchenko 1 sibling, 2 replies; 8+ messages in thread From: Joshua Crofts @ 2026-07-21 18:24 UTC (permalink / raw) To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-iio, devicetree, linux-kernel, Joshua Crofts The Microchip MCP47A1 is a 6-bit volatile Digital-to-Analog converted which communicates via I2C. Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com> --- MAINTAINERS | 1 + drivers/iio/dac/Kconfig | 11 +++ drivers/iio/dac/Makefile | 1 + drivers/iio/dac/mcp47a1.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index b44693593b94..9b124bbdd6ff 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17704,6 +17704,7 @@ M: Joshua Crofts <joshua.crofts1@gmail.com> L: linux-iio@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/iio/dac/microchip,mcp47a1.yaml +F: drivers/iio/dac/mcp47a1.c MICROCHIP MCP9982 TEMPERATURE DRIVER M: Victor Duicu <victor.duicu@microchip.com> diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig index 17529509da9d..a7f5711e9c3b 100644 --- a/drivers/iio/dac/Kconfig +++ b/drivers/iio/dac/Kconfig @@ -563,6 +563,17 @@ config MCP4728 To compile this driver as a module, choose M here: the module will be called mcp4728. +config MCP47A1 + tristate "MCP47A1 DAC driver" + depends on I2C + select REGMAP_I2C + help + Say Y here if you want to build a driver for the Microchip + MCP47A1 digital-to-analog converter with an I2C interface. + + To compile this driver as a module, choose M here: the module + will be called mcp47a1. + config MCP47FEB02 tristate "MCP47F(E/V)B01/02/04/08/11/12/14/18/21/22/24/28 DAC driver" depends on I2C diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile index 5d20d37e44ce..992f8930f95c 100644 --- a/drivers/iio/dac/Makefile +++ b/drivers/iio/dac/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_MAX5821) += max5821.o 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_MCP4821) += mcp4821.o obj-$(CONFIG_MCP4922) += mcp4922.o diff --git a/drivers/iio/dac/mcp47a1.c b/drivers/iio/dac/mcp47a1.c new file mode 100644 index 000000000000..251c2281634f --- /dev/null +++ b/drivers/iio/dac/mcp47a1.c @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Microchip MCP47A1 DAC driver + * + * Copyright (c) 2026 Joshua Crofts <joshua.crofts1@gmail.com> + * + * Datasheet: https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/25154A.pdf + */ + +#include <linux/array_size.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/regmap.h> +#include <linux/regulator/consumer.h> +#include <linux/types.h> +#include <linux/units.h> + +#include <linux/iio/iio.h> + +#define MCP47A1_REG_MAX 0x40 +#define MCP47A1_CMD_CODE 0x00 +#define MCP47A1_MAX_STEPS 64 + +struct mcp47a1_data { + struct regmap *regmap; + int vref_mv; +}; + +static const int mcp47a1_raw_avail[] = { 0, 1, MCP47A1_MAX_STEPS }; + +static const struct regmap_config mcp47a1_regmap_config = { + .name = "mcp47a1", + .reg_bits = 8, + .val_bits = 8, + .max_register = MCP47A1_CMD_CODE, +}; + +static const struct iio_chan_spec mcp47a1_channels[] = { + { + .type = IIO_VOLTAGE, + .indexed = 1, + .output = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + }, +}; + +static int mcp47a1_write(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct mcp47a1_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + if (val < 0 || val > MCP47A1_REG_MAX) + return -EINVAL; + + return regmap_write(data->regmap, MCP47A1_CMD_CODE, val); + default: + return -EINVAL; + } +} + +static int mcp47a1_read(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct mcp47a1_data *data = iio_priv(indio_dev); + int reg_val; + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = regmap_read(data->regmap, MCP47A1_CMD_CODE, ®_val); + if (ret) + return ret; + + *val = reg_val; + + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = data->vref_mv; + *val2 = MCP47A1_MAX_STEPS; + + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } +} + +static int mcp47a1_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_RAW: + *vals = mcp47a1_raw_avail; + *type = IIO_VAL_INT; + return IIO_AVAIL_RANGE; + default: + return -EINVAL; + } +} + +static const struct iio_info mcp47a1_info = { + .write_raw = mcp47a1_write, + .read_raw = mcp47a1_read, + .read_avail = mcp47a1_read_avail, +}; + +static int mcp47a1_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct mcp47a1_data *data; + struct iio_dev *indio_dev; + int reg_val; + int ret; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + + data->regmap = devm_regmap_init_i2c(client, &mcp47a1_regmap_config); + if (IS_ERR(data->regmap)) + return dev_err_probe(dev, PTR_ERR(data->regmap), + "Failed to initialize regmap\n"); + + ret = devm_regulator_get_enable(dev, "vdd"); + if (ret) + return dev_err_probe(dev, ret, "Failed to enable regulator\n"); + + ret = devm_regulator_get_enable_read_voltage(dev, "vref"); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to read vref\n"); + + data->vref_mv = ret / MILLI; + + /* + * This is a volatile DAC which doesn't have an ID register, instead + * the value register is set to 0x20 every Power-on-Reset (table 4-1). + * Any other read value at startup could indicate that the device is + * damaged etc. + */ + ret = regmap_read(data->regmap, MCP47A1_CMD_CODE, ®_val); + if (ret) + return dev_err_probe(dev, ret, + "Failed to read register on startup\n"); + + if (reg_val != 0x20) + dev_info(dev, "Read value 0x%02x at startup\n", reg_val); + + indio_dev->name = "mcp47a1"; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &mcp47a1_info; + indio_dev->channels = mcp47a1_channels; + indio_dev->num_channels = ARRAY_SIZE(mcp47a1_channels); + + return devm_iio_device_register(dev, indio_dev); +} + +static const struct of_device_id mcp47a1_of_match[] = { + { .compatible = "microchip,mcp47a1" }, + { } +}; +MODULE_DEVICE_TABLE(of, mcp47a1_of_match); + +static const struct i2c_device_id mcp47a1_id[] = { + { .name = "mcp47a1" }, + { } +}; +MODULE_DEVICE_TABLE(i2c, mcp47a1_id); + +static struct i2c_driver mcp47a1_driver = { + .driver = { + .name = "mcp47a1", + .of_match_table = mcp47a1_of_match, + }, + .probe = mcp47a1_probe, + .id_table = mcp47a1_id, +}; +module_i2c_driver(mcp47a1_driver); + +MODULE_AUTHOR("Joshua Crofts <joshua.crofts1@gmail.com>"); +MODULE_DESCRIPTION("MCP47A1 DAC"); +MODULE_LICENSE("GPL"); -- 2.55.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] iio: dac: mcp47a1: add support for new device 2026-07-21 18:24 ` [PATCH 2/2] iio: dac: mcp47a1: add support for new device Joshua Crofts @ 2026-07-21 19:20 ` sashiko-bot 2026-07-21 20:47 ` Andy Shevchenko 1 sibling, 0 replies; 8+ messages in thread From: sashiko-bot @ 2026-07-21 19:20 UTC (permalink / raw) To: Joshua Crofts; +Cc: conor+dt, devicetree, robh Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] The driver incorrectly allows a maximum raw value of 64 (0x40) to be written to a 6-bit DAC register. - [High] The driver performs an I2C read immediately after enabling the VDD regulator, without waiting for the device's Power-On Reset (POR) to complete. - [Medium] The driver requests a non-existent 'vref' regulator instead of using 'vdd' for the reference voltage. -- --- Patch [2]: [PATCH 2/2] iio: dac: mcp47a1: add support for new device --- commit 8241b9b8cd61665484502687ea7820769722f397 Author: Joshua Crofts <joshua.crofts1@gmail.com> iio: dac: mcp47a1: add support for new device The Microchip MCP47A1 is a 6-bit volatile Digital-to-Analog converted which communicates via I2C. > diff --git a/drivers/iio/dac/mcp47a1.c b/drivers/iio/dac/mcp47a1.c > new file mode 100644 > index 0000000000000..251c2281634ff > --- /dev/null > +++ b/drivers/iio/dac/mcp47a1.c > @@ -0,0 +1,193 @@ [ ... ] > +#define MCP47A1_REG_MAX 0x40 > +#define MCP47A1_CMD_CODE 0x00 > +#define MCP47A1_MAX_STEPS 64 > + > +struct mcp47a1_data { > + struct regmap *regmap; > + int vref_mv; > +}; > + > +static const int mcp47a1_raw_avail[] = { 0, 1, MCP47A1_MAX_STEPS }; [Severity: High] For a 6-bit DAC, the maximum value is 63 (0x3F). Does defining MCP47A1_REG_MAX to 0x40 (64) allow 7-bit values to bypass validation in mcp47a1_write() and be written to the register, potentially causing the data to wrap around or corrupt configuration bits? [ ... ] > +static int mcp47a1_probe(struct i2c_client *client) > +{ [ ... ] > + ret = devm_regulator_get_enable(dev, "vdd"); > + if (ret) > + return dev_err_probe(dev, ret, "Failed to enable regulator\n"); > + > + ret = devm_regulator_get_enable_read_voltage(dev, "vref"); [Severity: Medium] Does the MCP47A1 have a dedicated VREF pin? If the hardware derives its reference voltage from VDD, does requiring a fictitious "vref" regulator here force device tree authors to mismodel their hardware just to satisfy the driver? > + if (ret < 0) > + return dev_err_probe(dev, ret, "Failed to read vref\n"); > + > + data->vref_mv = ret / MILLI; > + > + /* > + * This is a volatile DAC which doesn't have an ID register, instead > + * the value register is set to 0x20 every Power-on-Reset (table 4-1). > + * Any other read value at startup could indicate that the device is > + * damaged etc. > + */ > + ret = regmap_read(data->regmap, MCP47A1_CMD_CODE, ®_val); [Severity: High] Since the VDD regulator is enabled a few lines above, is there a missing delay to wait for the device's Power-On Reset (POR) to complete? Without an explicit delay, could this I2C read happen before the internal boot sequence finishes, potentially resulting in an I2C NACK and probe failure? > + if (ret) > + return dev_err_probe(dev, ret, > + "Failed to read register on startup\n"); -- Sashiko AI review · https://sashiko.dev/#/patchset/20260721-mcp47a1-add-support-v1-0-da045a2567e3@gmail.com?part=2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] iio: dac: mcp47a1: add support for new device 2026-07-21 18:24 ` [PATCH 2/2] iio: dac: mcp47a1: add support for new device Joshua Crofts 2026-07-21 19:20 ` sashiko-bot @ 2026-07-21 20:47 ` Andy Shevchenko 2026-07-22 6:30 ` Joshua Crofts 1 sibling, 1 reply; 8+ messages in thread From: Andy Shevchenko @ 2026-07-21 20:47 UTC (permalink / raw) To: Joshua Crofts Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree, linux-kernel On Tue, Jul 21, 2026 at 08:24:39PM +0200, Joshua Crofts wrote: > The Microchip MCP47A1 is a 6-bit volatile Digital-to-Analog converted > which communicates via I2C. ... > +#include <linux/array_size.h> > +#include <linux/err.h> > +#include <linux/i2c.h> > +#include <linux/module.h> > +#include <linux/regmap.h> > +#include <linux/regulator/consumer.h> > +#include <linux/types.h> > +#include <linux/units.h> > +struct mcp47a1_data { > + struct regmap *regmap; > + int vref_mv; _mV ... > +static const struct regmap_config mcp47a1_regmap_config = { > + .name = "mcp47a1", > + .reg_bits = 8, > + .val_bits = 8, > + .max_register = MCP47A1_CMD_CODE, > +}; No cache? ... > +static int mcp47a1_probe(struct i2c_client *client) > +{ > + struct device *dev = &client->dev; > + struct mcp47a1_data *data; > + struct iio_dev *indio_dev; > + int reg_val; > + int ret; > + > + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); > + if (!indio_dev) > + return -ENOMEM; > + > + data = iio_priv(indio_dev); > + i2c_set_clientdata(client, indio_dev); Is it used? > + data->regmap = devm_regmap_init_i2c(client, &mcp47a1_regmap_config); > + if (IS_ERR(data->regmap)) > + return dev_err_probe(dev, PTR_ERR(data->regmap), > + "Failed to initialize regmap\n"); > + > + ret = devm_regulator_get_enable(dev, "vdd"); > + if (ret) > + return dev_err_probe(dev, ret, "Failed to enable regulator\n"); > + > + ret = devm_regulator_get_enable_read_voltage(dev, "vref"); > + if (ret < 0) > + return dev_err_probe(dev, ret, "Failed to read vref\n"); > + > + data->vref_mv = ret / MILLI; (MICRO / MILLI) > + /* > + * This is a volatile DAC which doesn't have an ID register, instead > + * the value register is set to 0x20 every Power-on-Reset (table 4-1). > + * Any other read value at startup could indicate that the device is > + * damaged etc. > + */ > + ret = regmap_read(data->regmap, MCP47A1_CMD_CODE, ®_val); > + if (ret) > + return dev_err_probe(dev, ret, > + "Failed to read register on startup\n"); > + > + if (reg_val != 0x20) > + dev_info(dev, "Read value 0x%02x at startup\n", reg_val); > + > + indio_dev->name = "mcp47a1"; > + indio_dev->modes = INDIO_DIRECT_MODE; > + indio_dev->info = &mcp47a1_info; > + indio_dev->channels = mcp47a1_channels; > + indio_dev->num_channels = ARRAY_SIZE(mcp47a1_channels); > + > + return devm_iio_device_register(dev, indio_dev); > +} -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] iio: dac: mcp47a1: add support for new device 2026-07-21 20:47 ` Andy Shevchenko @ 2026-07-22 6:30 ` Joshua Crofts 0 siblings, 0 replies; 8+ messages in thread From: Joshua Crofts @ 2026-07-22 6:30 UTC (permalink / raw) To: Andy Shevchenko Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree, linux-kernel On Tue, 21 Jul 2026 23:47:58 +0300 Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > On Tue, Jul 21, 2026 at 08:24:39PM +0200, Joshua Crofts wrote: > > The Microchip MCP47A1 is a 6-bit volatile Digital-to-Analog converted > > which communicates via I2C. > > ... > > > +#include <linux/array_size.h> > > +#include <linux/err.h> > > +#include <linux/i2c.h> > > +#include <linux/module.h> > > +#include <linux/regmap.h> > > +#include <linux/regulator/consumer.h> > > +#include <linux/types.h> > > +#include <linux/units.h> > > > > +struct mcp47a1_data { > > + struct regmap *regmap; > > + int vref_mv; > > _mV ACK. > > ... > > > +static const struct regmap_config mcp47a1_regmap_config = { > > + .name = "mcp47a1", > > + .reg_bits = 8, > > + .val_bits = 8, > > + .max_register = MCP47A1_CMD_CODE, > > +}; > > No cache? Hmmm, could you elaborate a bit more? I assume you're talking about regcache but I'm not sure on how to use it here. > > ... > > > +static int mcp47a1_probe(struct i2c_client *client) > > +{ > > + struct device *dev = &client->dev; > > + struct mcp47a1_data *data; > > + struct iio_dev *indio_dev; > > + int reg_val; > > + int ret; > > + > > + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); > > + if (!indio_dev) > > + return -ENOMEM; > > + > > + data = iio_priv(indio_dev); > > > + i2c_set_clientdata(client, indio_dev); > > Is it used? Nope, it isn't, good catch. > > > + data->regmap = devm_regmap_init_i2c(client, &mcp47a1_regmap_config); > > + if (IS_ERR(data->regmap)) > > + return dev_err_probe(dev, PTR_ERR(data->regmap), > > + "Failed to initialize regmap\n"); > > + > > + ret = devm_regulator_get_enable(dev, "vdd"); > > + if (ret) > > + return dev_err_probe(dev, ret, "Failed to enable regulator\n"); > > + > > + ret = devm_regulator_get_enable_read_voltage(dev, "vref"); > > + if (ret < 0) > > + return dev_err_probe(dev, ret, "Failed to read vref\n"); > > + > > + data->vref_mv = ret / MILLI; > > (MICRO / MILLI) ACK. -- Kind regards, Joshua Crofts ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-07-22 6:30 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-21 18:24 [PATCH 0/2] iio: dac: mcp47a1: add support for new device Joshua Crofts 2026-07-21 18:24 ` [PATCH 1/2] dt-bindings: iio: dac: add support for mcp47a1 Joshua Crofts 2026-07-21 18:33 ` sashiko-bot 2026-07-21 18:37 ` Joshua Crofts 2026-07-21 18:24 ` [PATCH 2/2] iio: dac: mcp47a1: add support for new device Joshua Crofts 2026-07-21 19:20 ` sashiko-bot 2026-07-21 20:47 ` Andy Shevchenko 2026-07-22 6:30 ` Joshua Crofts
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.