From: David Lechner <dlechner@baylibre.com>
To: "Angelo Dureghello" <adureghello@baylibre.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v7 6/6] iio: adc: ad7606: add gain calibration support
Date: Fri, 30 May 2025 12:13:19 -0500 [thread overview]
Message-ID: <98ccc736-a44f-43a7-acff-ac5a4cc33023@baylibre.com> (raw)
In-Reply-To: <20250526-wip-bl-ad7606-calibration-v7-6-b487022ce199@baylibre.com>
On 5/26/25 5:03 AM, Angelo Dureghello wrote:
> From: Angelo Dureghello <adureghello@baylibre.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.
>
> Tested-by: David Lechner <dlechner@baylibre.com>
Testing this with parallel interface today instead of SPI and found a bug.
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
> ---
...
> +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;
> +
> + device_for_each_child_node_scoped(dev, child) {
> + u32 reg, r_gain;
> +
> + ret = fwnode_property_read_u32(child, "reg", ®);
> + if (ret)
> + return ret;
> +
> + /* Chan reg is a 1-based index. */
> + if (reg < 1 || reg > num_channels)
> + return ret;
> +
> + r_gain = 0;
> + ret = fwnode_property_read_u32(child, "adi,rfilter-ohms",
> + &r_gain);
> + if (r_gain > AD7606_CALIB_GAIN_MAX)
> + return -EINVAL;
> +
> + ret = st->bops->reg_write(st, AD7606_CALIB_GAIN(reg - 1),
> + DIV_ROUND_CLOSEST(r_gain, AD7606_CALIB_GAIN_STEP));
ad7606_chan_calib_gain_setup() is called before ad7606_reset() so any value
written here will be cleared by the reset.
Also, this is called before st->bops->iio_backend_config() so when using
the parallel bus, this causes a segfault.
The simplest thing to do is probably store the r_gain values and then
create a new function to write that data to the registers and call that
near the end of the probe() function.
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +
next prev parent reply other threads:[~2025-05-30 17:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-26 10:03 [PATCH v7 0/6] iio: adc: add ad7606 calibration support Angelo Dureghello
2025-05-26 10:03 ` [PATCH v7 1/6] Documentation: ABI: IIO: add calibconv_delay documentation Angelo Dureghello
2025-05-28 10:32 ` Andy Shevchenko
2025-05-30 7:36 ` Angelo Dureghello
2025-05-31 16:07 ` Jonathan Cameron
2025-05-26 10:03 ` [PATCH v7 2/6] iio: core: add ADC delay calibration definition Angelo Dureghello
2025-05-26 10:03 ` [PATCH v7 3/6] iio: adc: ad7606: add offset and phase calibration support Angelo Dureghello
2025-05-31 16:09 ` Jonathan Cameron
2025-05-26 10:03 ` [PATCH v7 4/6] dt-bindings: iio: adc: adi,ad7606: add gain " Angelo Dureghello
2025-05-26 10:03 ` [PATCH v7 5/6] iio: adc: ad7606: exit for invalid fdt dt_schema properties Angelo Dureghello
2025-05-26 10:03 ` [PATCH v7 6/6] iio: adc: ad7606: add gain calibration support Angelo Dureghello
2025-05-30 17:13 ` David Lechner [this message]
2025-05-30 17:17 ` David Lechner
2025-05-30 17:19 ` David Lechner
2025-05-30 17:21 ` David Lechner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=98ccc736-a44f-43a7-acff-ac5a4cc33023@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Michael.Hennerich@analog.com \
--cc=adureghello@baylibre.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox