Re: [PATCH v2 7/8] iio: dac: ds4424: add Rfs-based scale and per-variant limits

Andy Shevchenko
2026-01-27T10:46:18Z

On Tue, Jan 27, 2026 at 07:09:38AM +0100, Oleksij Rempel wrote:
> Parse optional maxim,rfs-ohms values to derive the per-channel output
> current scale (mA per step) for the IIO current ABI.
>
> Select per-variant parameters to match the shared register map while
> handling different data widths and full-scale current calculations.
>
> Behavior changes:
> - If maxim,rfs-ohms is present, IIO_CHAN_INFO_SCALE becomes available
> and reports mA/step derived from Rfs.
> - If maxim,rfs-ohms is missing, SCALE is not exposed to keep older DTs
> working without requiring updates.
> - RAW writes are now limited to the representable sign-magnitude range
> of the detected variant to avoid silent truncation (e.g. +/-31 on
> DS440x).

...

> +struct ds4424_chip_info {
> + int vref_mv;

_mV ?

> + int scale_denom;
> + u8 result_mask;
> +};

...

> +static int ds4424_setup_channels(struct i2c_client *client,
> + struct ds4424_data *data,
> + struct iio_dev *indio_dev)
> +{
> + struct iio_chan_spec *channels;
> + size_t channels_size;
> +
> + channels_size = indio_dev->num_channels * sizeof(ds4424_channels[0]);
> + /* Use a local non-const pointer for modification */
> + channels = devm_kmemdup(&client->dev, ds4424_channels, channels_size,
> + GFP_KERNEL);

Why not devm_kmemdup_array()?

> + if (!channels)
> + return -ENOMEM;
> +
> + if (data->has_rfs) {
> + for (unsigned int i = 0; i < indio_dev->num_channels; i++)
> + channels[i].info_mask_separate |=
> + BIT(IIO_CHAN_INFO_SCALE);
> + }
> +
> + indio_dev->channels = channels;
> +
> + return 0;
> +}

...

> +static int ds4424_parse_rfs(struct i2c_client *client,
> + struct ds4424_data *data,
> + struct iio_dev *indio_dev)
> +{
> + struct device *dev = &client->dev;
> + int count, ret;

Can count be negative?

> + if (!device_property_present(dev, "maxim,rfs-ohms")) {
> + dev_info_once(dev, "maxim,rfs-ohms missing, scale not supported\n");
> + return 0;
> + }
> +
> + count = device_property_count_u32(dev, "maxim,rfs-ohms");
> + if (count != indio_dev->num_channels)
> + return dev_err_probe(dev, -EINVAL, "maxim,rfs-ohms must have %u entries\n",
> + indio_dev->num_channels);
> +
> + ret = device_property_read_u32_array(dev, "maxim,rfs-ohms",
> + data->rfs_ohms,
> + indio_dev->num_channels);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to read maxim,rfs-ohms property\n");
> +
> + for (unsigned int i = 0; i < indio_dev->num_channels; i++) {
> + if (!data->rfs_ohms[i])
> + return dev_err_probe(dev, -EINVAL, "maxim,rfs-ohms entry %d is zero\n",

%u

> + i);

I would leave it on the same line.

> + }
> +
> + data->has_rfs = true;
> +
> + return 0;
> +}

--
With Best Regards,
Andy Shevchenko