From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: Michael Hennerich <Michael.Hennerich@analog.com>,
Alexandru Ardelean <aardelean@baylibre.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ad7606: fix raw read for 18-bit chips
Date: Sun, 4 May 2025 15:42:31 +0100 [thread overview]
Message-ID: <20250504154231.5a50c97b@jic23-huawei> (raw)
In-Reply-To: <20250502-iio-adc-ad7606-fix-raw-read-for-18-bit-chips-v1-1-06caa92d8f11@baylibre.com>
On Fri, 02 May 2025 10:04:30 -0500
David Lechner <dlechner@baylibre.com> wrote:
> Fix 18-bit raw read for 18-bit chips by applying a mask to the value
> we receive from the SPI controller.
>
> SPI controllers either return 1, 2 or 4 bytes per word depending on the
> bits_per_word. For 16-bit chips, there was no problem since they raw
> data fit exactly in the 2 bytes received from the SPI controller. But
> now that we have 18-bit chips and we are using bits_per_word = 18, we
> cannot assume that the extra bits in the 32-bit word are always zero.
> In fact, with the AXI SPI Engine controller, these bits are not always
> zero which caused the raw values to read 10s of 1000s of volts instead
> of the correct value. Therefore, we need to mask the value we receive
> from the SPI controller to ensure that only the 18 bits of real data
> are used.
>
> Fixes: f3838e934dff ("iio: adc: ad7606: add support for AD7606C-{16,18} parts")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> Jonathan, I based this on the fixes-togreg branch since I assume it will
> go that route, but beware that there is a trivial merge conflict with
> https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=togreg&id=3b5b55ca940733b7b533fe3137a307ceacb4fb90
> as that patch modifies an adjacent line.
Applied to the fixes-togreg branch of iio.git. Let's see if this causes
much trouble in next. Given it's just adjacent lines hopefully won't be a
problem.
Thanks,
Jonathan
> ---
> drivers/iio/adc/ad7606.c | 21 ++++++++++-----------
> 1 file changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index 703556eb7257ea0647135c4b268a8ead93115c6f..8ed65a35b4862315431a4852453639b4e056178e 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -727,17 +727,16 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch,
> goto error_ret;
>
> chan = &indio_dev->channels[ch + 1];
> - if (chan->scan_type.sign == 'u') {
> - if (realbits > 16)
> - *val = st->data.buf32[ch];
> - else
> - *val = st->data.buf16[ch];
> - } else {
> - if (realbits > 16)
> - *val = sign_extend32(st->data.buf32[ch], realbits - 1);
> - else
> - *val = sign_extend32(st->data.buf16[ch], realbits - 1);
> - }
> +
> + if (realbits > 16)
> + *val = st->data.buf32[ch];
> + else
> + *val = st->data.buf16[ch];
> +
> + *val &= GENMASK(realbits - 1, 0);
> +
> + if (chan->scan_type.sign == 's')
> + *val = sign_extend32(*val, realbits - 1);
>
> error_ret:
> if (!st->gpio_convst) {
>
> ---
> base-commit: 609bc31eca06c7408e6860d8b46311ebe45c1fef
> change-id: 20250502-iio-adc-ad7606-fix-raw-read-for-18-bit-chips-ed035c488eca
>
> Best regards,
prev parent reply other threads:[~2025-05-04 14:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 15:04 [PATCH] iio: adc: ad7606: fix raw read for 18-bit chips David Lechner
2025-05-04 14:42 ` Jonathan Cameron [this message]
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=20250504154231.5a50c97b@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=aardelean@baylibre.com \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.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