From: "Nuno Sá" <noname.nuno@gmail.com>
To: Marcelo Schmitt <marcelo.schmitt@analog.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: jic23@kernel.org, lars@metafoo.de, Michael.Hennerich@analog.com,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
linus.walleij@linaro.org, brgl@bgdev.pl,
marcelo.schmitt1@gmail.com
Subject: Re: [PATCH v3 04/10] iio: adc: ad4170: Add support for calibration bias
Date: Mon, 26 May 2025 11:27:02 +0100 [thread overview]
Message-ID: <b198ab8bcae5e9a31164bb565a089d14ff297b81.camel@gmail.com> (raw)
In-Reply-To: <6213d7b7fb913520f1f143e7ccf8fe16b8579d0c.1747083143.git.marcelo.schmitt@analog.com>
On Tue, 2025-05-13 at 09:34 -0300, Marcelo Schmitt wrote:
> Add support for ADC calibration bias/offset configuration.
>
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
> ---
> Change log v2 -> v3
> - New patch spun out of the base driver patch.
>
> drivers/iio/adc/ad4170.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/drivers/iio/adc/ad4170.c b/drivers/iio/adc/ad4170.c
> index 1df214f7fdec..b02fdd25b4c8 100644
> --- a/drivers/iio/adc/ad4170.c
> +++ b/drivers/iio/adc/ad4170.c
> @@ -643,6 +643,7 @@ static const struct iio_chan_spec ad4170_channel_template
> = {
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> BIT(IIO_CHAN_INFO_SCALE) |
> BIT(IIO_CHAN_INFO_OFFSET) |
> + BIT(IIO_CHAN_INFO_CALIBBIAS) |
> BIT(IIO_CHAN_INFO_CALIBSCALE),
> .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),
> .scan_type = {
> @@ -954,6 +955,9 @@ static int ad4170_read_raw(struct iio_dev *indio_dev,
> pga = FIELD_GET(AD4170_AFE_PGA_GAIN_MSK, setup->afe);
> *val = chan_info->offset_tbl[pga];
> return IIO_VAL_INT;
> + case IIO_CHAN_INFO_CALIBBIAS:
> + *val = setup->offset;
same nit...
> + return IIO_VAL_INT;
> case IIO_CHAN_INFO_CALIBSCALE:
> *val = setup->gain;
> return IIO_VAL_INT;
> @@ -1083,6 +1087,25 @@ static int ad4170_set_pga(struct ad4170_state *st,
> return 0;
> }
>
> +static int ad4170_set_calib_offset(struct ad4170_state *st,
> + struct iio_chan_spec const *chan, int val)
> +{
> + struct ad4170_chan_info *chan_info = &st->chan_infos[chan->address];
> + struct ad4170_setup *setup = &chan_info->setup;
> + u32 old_offset;
> + int ret;
> +
> + guard(mutex)(&st->lock);
> + old_offset = setup->offset;
> + setup->offset = val;
Why doing the above dance?
> +
> + ret = ad4170_write_channel_setup(st, chan->address, false);
> + if (ret)
> + setup->offset = old_offset;
> +
We could update the value in here.
> + return ret;
I guess ret > 0 is not a thing? I find it more readable:
return 0;
It makes it clear we got success :)
- Nuno Sá
> +}
> +
> static int ad4170_set_calib_gain(struct ad4170_state *st,
> struct iio_chan_spec const *chan, int val)
> {
> @@ -1111,6 +1134,8 @@ static int __ad4170_write_raw(struct iio_dev *indio_dev,
> switch (info) {
> case IIO_CHAN_INFO_SCALE:
> return ad4170_set_pga(st, chan, val, val2);
> + case IIO_CHAN_INFO_CALIBBIAS:
> + return ad4170_set_calib_offset(st, chan, val);
> case IIO_CHAN_INFO_CALIBSCALE:
> return ad4170_set_calib_gain(st, chan, val);
> default:
> @@ -1139,6 +1164,7 @@ static int ad4170_write_raw_get_fmt(struct iio_dev
> *indio_dev,
> switch (info) {
> case IIO_CHAN_INFO_SCALE:
> return IIO_VAL_INT_PLUS_NANO;
> + case IIO_CHAN_INFO_CALIBBIAS:
> case IIO_CHAN_INFO_CALIBSCALE:
> return IIO_VAL_INT;
> default:
next prev parent reply other threads:[~2025-05-26 10:27 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-13 12:32 [PATCH v3 00/10] Add support for AD4170 series of ADCs Marcelo Schmitt
2025-05-13 12:33 ` [PATCH v3 01/10] dt-bindings: iio: adc: Add AD4170 Marcelo Schmitt
2025-05-13 15:47 ` David Lechner
2025-05-16 15:45 ` Marcelo Schmitt
2025-05-16 16:06 ` David Lechner
2025-05-21 8:33 ` Krzysztof Kozlowski
2025-05-21 8:41 ` Krzysztof Kozlowski
2025-05-22 15:07 ` Marcelo Schmitt
2025-05-25 10:05 ` Jonathan Cameron
2025-05-25 10:11 ` Jonathan Cameron
2025-05-26 21:59 ` Marcelo Schmitt
2025-05-31 15:50 ` Jonathan Cameron
2025-05-13 12:34 ` [PATCH v3 02/10] iio: adc: Add basic support for AD4170 Marcelo Schmitt
2025-05-25 10:36 ` Jonathan Cameron
2025-05-26 10:21 ` Nuno Sá
2025-05-13 12:34 ` [PATCH v3 03/10] iio: adc: ad4170: Add support for calibration gain Marcelo Schmitt
2025-05-26 10:24 ` Nuno Sá
2025-05-13 12:34 ` [PATCH v3 04/10] iio: adc: ad4170: Add support for calibration bias Marcelo Schmitt
2025-05-26 10:27 ` Nuno Sá [this message]
2025-05-13 12:35 ` [PATCH v3 05/10] iio: adc: ad4170: Add digital filter and sample frequency config support Marcelo Schmitt
2025-05-25 10:41 ` Jonathan Cameron
2025-05-13 12:35 ` [PATCH v3 06/10] iio: adc: ad4170: Add support for buffered data capture Marcelo Schmitt
2025-05-25 10:46 ` Jonathan Cameron
2025-05-13 12:35 ` [PATCH v3 07/10] iio: adc: ad4170: Add clock provider support Marcelo Schmitt
2025-05-13 16:59 ` David Lechner
2025-05-13 12:36 ` [PATCH v3 08/10] iio: adc: ad4170: Add GPIO controller support Marcelo Schmitt
2025-05-20 17:06 ` Bartosz Golaszewski
2025-05-13 12:36 ` [PATCH v3 09/10] iio: adc: ad4170: Add support for internal temperature sensor Marcelo Schmitt
2025-05-13 12:36 ` [PATCH v3 10/10] iio: adc: ad4170: Add support for weigh scale and RTD sensors Marcelo Schmitt
2025-05-25 10:57 ` Jonathan Cameron
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=b198ab8bcae5e9a31164bb565a089d14ff297b81.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--cc=marcelo.schmitt@analog.com \
--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;
as well as URLs for NNTP newsgroup(s).