Re: [PATCH v5 5/5] iio: adc: ad7606: add gain calibration support
From: Andy Shevchenko
Date: Mon May 19 2025 - 07:23:31 EST
On Mon, May 19, 2025 at 12:13:42PM +0200, Angelo Dureghello wrote:
> From: Angelo Dureghello <adureghello@xxxxxxxxxxxx>
>
> Add gain calibration support, using resistor values set on devicetree,
> values to be set accordingly with ADC external RFilter, as explained in
> the ad7606c-16 datasheet, rev0, page 37.
>
> Usage example in the fdt yaml documentation.
...
> + device_for_each_child_node_scoped(dev, child) {
> + u32 reg, r_gain;
> +
> + ret = fwnode_property_read_u32(child, "reg", ®);
> + if (ret)
> + continue;
> +
> + /* Chan reg is a 1-based index. */
> + if (reg < 1 || reg > num_channels) {
> + dev_warn(dev, "wrong ch number (ignoring): %d\n", reg);
> + continue;
> + }
Like I said, we should leave the validation to the schema or do it correctly here.
Otherwise it's an inconsistency between DT schema validator and this check.
I.o.w. this check *allows* the b0rken DT to be handled and I think this is simply
wrong.
> + ret = fwnode_property_read_u32(child, "adi,rfilter-ohms",
> + &r_gain);
> + if (ret)
> + /* Keep the default register value. */
> + continue;
> +
> + if (r_gain > AD7606_CALIB_GAIN_MAX) {
> + dev_warn(dev, "wrong gain calibration value");
> + continue;
> + }
Same here.
> + ret = st->bops->reg_write(st, AD7606_CALIB_GAIN(reg - 1),
> + DIV_ROUND_CLOSEST(r_gain, AD7606_CALIB_GAIN_STEP));
> + if (ret) {
> + dev_warn(dev, "error writing r_gain");
> + continue;
Not sure about this, though.
> + }
> + }
--
With Best Regards,
Andy Shevchenko