Re: [PATCH 2/2] iio: dac: mcp47a1: add support for new device

From: Andy Shevchenko

Date: Tue Jul 21 2026 - 18:42:46 EST


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, &reg_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