Re: [PATCH v7 7/7] iio: dac: Add AD5529R DAC driver support

From: Jonathan Cameron

Date: Fri Jul 24 2026 - 19:59:19 EST


On Wed, 22 Jul 2026 09:54:19 +0200
Janani Sunil <janani.sunil@xxxxxxxxxx> wrote:

> Add support for AD5529R 16-channel, 12/16 bit Digital to Analog Converter
> from Analog Devices.
>
> The device communicates over SPI and supports per-channel output range
> configuration. An optional external 4.096V reference can be used in
> place of the internal reference.
>
> Signed-off-by: Janani Sunil <janani.sunil@xxxxxxxxxx>

Sashiko had one comment that I think deserves a tiny modification.

Otherwise looks good to me.

I would have just tweaked that and the [] (and still may) bit giving time for that SPI
ack from Mark for the generic property before I pick this series up.

Feel free to send a new version if you prefer.

Thanks,

Jonathan


> diff --git a/drivers/iio/dac/ad5529r.c b/drivers/iio/dac/ad5529r.c
> new file mode 100644
> index 000000000000..2fd1dd053da5
> --- /dev/null
> +++ b/drivers/iio/dac/ad5529r.c

> +
> +static int ad5529r_parse_channel_ranges(struct device *dev,
> + struct ad5529r_state *st)
> +{
> + s32 vals[2];
> + int ret, range_idx;
> + u32 ch;
> +
> + device_for_each_child_node_scoped(dev, child) {

As below, lets check we don't come in here once too many.
if (st->num_channels == ARRAY_SIZE(st->channels))
return dev_err_probe(dev, -EINVAL, "Too many channels\n");

> + ret = fwnode_property_read_u32(child, "reg", &ch);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Missing reg property in channel node\n");
> +
> + if (ch >= 16)
> + return dev_err_probe(dev, -EINVAL,
> + "Channel %u exceeds maximum 15\n",
> + ch);
> +
> + if (fwnode_property_present(child, "output-range-microvolt")) {
> + /*
> + * DT stores cells as raw 32-bit values; signed endpoints are
> + * encoded by dtc in two's-complement and then interpreted
> + * here as s32.
> + */
> + ret = fwnode_property_read_u32_array(child,
> + "output-range-microvolt",
> + (u32 *)vals, ARRAY_SIZE(vals));
> + if (ret < 0)
> + return dev_err_probe(dev, ret,
> + "Failed to read range for ch %u\n",
> + ch);
> +
> + range_idx = ad5529r_find_output_range(vals);
> + if (range_idx < 0)
> + return dev_err_probe(dev, range_idx,
> + "Invalid range [%d %d] for ch %u\n",
> + vals[0], vals[1], ch);
> + } else {
> + range_idx = AD5529R_RANGE_0V_5V;
> + }
> +
> + st->output_range_idx[ch] = range_idx;
> + ret = regmap_write(st->regmap_16bit,
> + AD5529R_REG_OUT_RANGE(ch), range_idx);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Failed to configure range for ch %u\n",
> + ch);
> +
> + st->channels[st->num_channels++] = AD5529R_DAC_CHANNEL(ch);

Sashiko calls out that a malformed DT could have repeat entries and so overflow channels.
Given it is easy to harden against that, let us do so alongside that check on
if (ch < 16) above.

> + }
> +
> + return 0;
> +}