Re: [PATCH v3 5/5] iio: adc: ad7606: add gain calibration support

From: David Lechner
Date: Thu May 08 2025 - 09:51:08 EST


On 5/8/25 4:16 AM, Angelo Dureghello wrote:
> Hi all,
> On 07.05.2025 07:14, Nuno Sá wrote:
>> On Tue, 2025-05-06 at 23:03 +0200, Angelo Dureghello wrote:
>>> From: Angelo Dureghello <adureghello@xxxxxxxxxxxx>
>>>

...

>>> +static int ad7606_chan_calib_gain_setup(struct iio_dev *indio_dev,
>>> + struct iio_chan_spec *chan)
>>> +{
>>> + struct ad7606_state *st = iio_priv(indio_dev);
>>> + unsigned int num_channels = st->chip_info->num_adc_channels;
>>> + struct device *dev = st->dev;
>>> + int ret;
>>> +
>>> + device_for_each_child_node_scoped(dev, child) {
>>> + u32 reg, r_gain;
>>> +
>
> working on further features, i noticed this function is called
> for each channel, that is not correct, so need to fix this,
> will send a v4.

Why is this not correct? Each input could have an amplifier with different
series resistor value so this seems correct to me.

>
> Regards,
> angelo
>
>>> + ret = fwnode_property_read_u32(child, "reg", &reg);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + /* channel number (here) is from 1 to num_channels */
>>> + if (reg < 1 || reg > num_channels) {
>>> + dev_warn(dev, "wrong ch number (ignoring): %d\n", reg);
>>> + continue;
>>> + }
>>> +
>>
>> Sorry Angelo, just realized this now. Any reason for not treating the above as a real
>> invalid argument? It's minor and not a big deal but odd enough...
>>
>> - Nuno Sá
>>
>>> + ret = fwnode_property_read_u32(child, "adi,rfilter-ohms",
>>> +        &r_gain);
>>> + if (ret == -EINVAL)
>>> + /* Keep the default register value. */
>>> + continue;
>>> + if (ret)
>>> + return ret;
>>> +
>>> + if (r_gain > AD7606_CALIB_GAIN_MAX)
>>> + return dev_err_probe(st->dev, -EINVAL,
>>> +      "wrong gain calibration value.");
>>> +
>>> + /* Chan reg is 1-based index. */
>>> + ret = st->bops->reg_write(st, AD7606_CALIB_GAIN(reg - 1),
>>> + DIV_ROUND_CLOSEST(r_gain, AD7606_CALIB_GAIN_STEP));
>>> + if (ret)
>>> + return ret;
>>> + }
>>> +
>>> + return 0;
>>> +}
>>> +