mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: "David Lechner" <dlechner@baylibre.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Jonathan Cameron" <jic23@kernel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	linux-iio@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ad7944: max high bits on direct read
Date: Wed, 07 May 2025 07:29:41 +0100	[thread overview]
Message-ID: <dd7dda31525f2947060386a2b605300cf02677f2.camel@gmail.com> (raw)
In-Reply-To: <20250505-iio-adc-ad7944-max-high-bits-on-direct-read-v1-1-b173facceefe@baylibre.com>

On Mon, 2025-05-05 at 13:28 -0500, David Lechner wrote:
> Apply a mask to the raw value received over the SPI bus for unsigned
> direct reads. As we found recently, SPI controllers may not set unused
> bits to 0 when reading with bits_per_word != {8,16,32}. The ad7944 uses
> bits_per_word of 14 and 18, so we need to mask the value to be sure we
> returning the correct value to userspace during a direct read.
> 
> Fixes: d1efcf8871db ("iio: adc: ad7944: add driver for AD7944/AD7985/AD7986")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> The sign_extend32() already takes care of signed reads in case that
> isn't obvious - it overwrites the unknown bits with the sign bit.
> ---

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

>  drivers/iio/adc/ad7944.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c
> index
> 2f949fe5587318957f2e423029294ced0a6f803d..37a137bd83571b055e970a8cd483d8726972d637
> 100644
> --- a/drivers/iio/adc/ad7944.c
> +++ b/drivers/iio/adc/ad7944.c
> @@ -377,6 +377,8 @@ static int ad7944_single_conversion(struct ad7944_adc *adc,
>  
>  	if (chan->scan_type.sign == 's')
>  		*val = sign_extend32(*val, chan->scan_type.realbits - 1);
> +	else
> +		*val &= GENMASK(chan->scan_type.realbits - 1, 0);
>  
>  	return IIO_VAL_INT;
>  }
> 
> ---
> base-commit: b72f1157bfb9b92b0439e11469f7f94e47363460
> change-id: 20250505-iio-adc-ad7944-max-high-bits-on-direct-read-b358289d0337
> 
> Best regards,


  reply	other threads:[~2025-05-07  7:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-05 18:28 David Lechner
2025-05-07  6:29 ` Nuno Sá [this message]
2025-05-08 21:03 ` David Lechner
2025-05-15 16:16   ` 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=dd7dda31525f2947060386a2b605300cf02677f2.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /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

all inboxes | Powered by JetHome®