[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aBz_Nlgx18UK2GIc@smile.fi.intel.com>
Date: Thu, 8 May 2025 22:00:06 +0300
From: Andy Shevchenko <andy@...nel.org>
To: Angelo Dureghello <adureghello@...libre.com>
Cc: Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>,
Nuno Sá <nuno.sa@...log.com>,
Lars-Peter Clausen <lars@...afoo.de>,
Michael Hennerich <Michael.Hennerich@...log.com>,
Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, devicetree@...r.kernel.org
Subject: Re: [PATCH v4 5/5] iio: adc: ad7606: add gain calibration support
On Thu, May 08, 2025 at 12:06:09PM +0200, Angelo Dureghello wrote:
> From: Angelo Dureghello <adureghello@...libre.com>
>
> 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.
...
> +static int ad7606_chan_calib_gain_setup(struct iio_dev *indio_dev)
> +{
> + 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;
> +
> + /*
> + * This function is called once, and parses all the channel nodes,
> + * so continuing on next channel node on errors, informing of them.
> + */
> + 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;
> + }
But this will allow to have a broken DT. This check basically diminishes the
effort of the DT schema validation. If there are limits one still would be able
to create a DT that passes the driver but doesn't pass the validation.
> + 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;
> + }
> +
> + 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;
> + }
> + }
> +
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists