[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aBTKW538TX-jw977@smile.fi.intel.com>
Date: Fri, 2 May 2025 16:36:27 +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 v2 5/5] iio: adc: ad7606: add gain calibration support
On Fri, May 02, 2025 at 03:27:02PM +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.
...
> + device_for_each_child_node_scoped(dev, child) {
> + int reg, r_gain;
Both are defined in DT as unsigned. Are you able to use int as u32 in DT compiler?
> + ret = fwnode_property_read_u32(child, "reg", ®);
> + if (ret)
> + return ret;
> +
> + /* channel number (here) is from 1 to num_channels */
> + if (reg < 1 || reg > num_channels) {
> + dev_warn(dev, "invalid ch number (ignoring): %d\n", reg);
> + continue;
> + }
> +
> + 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_MIN ||
> + r_gain > AD7606_CALIB_GAIN_MAX)
Seems like minimum check is not needed. See above why.
> + 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),
> + r_gain / AD7606_CALIB_GAIN_STEP);
Wonder if we need DIV_ROUND_CLOSEST() instead...
> + if (ret)
> + return ret;
> + }
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists