mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ad7944: max high bits on direct read
@ 2025-05-05 18:28 David Lechner
  2025-05-07  6:29 ` Nuno Sá
  2025-05-08 21:03 ` David Lechner
  0 siblings, 2 replies; 4+ messages in thread
From: David Lechner @ 2025-05-05 18:28 UTC (permalink / raw)
  To: Michael Hennerich, Nuno Sá, Jonathan Cameron
  Cc: Jonathan Cameron, linux-iio, linux-kernel, David Lechner

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.
---
 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,
-- 
David Lechner <dlechner@baylibre.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-15 16:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-05 18:28 [PATCH] iio: adc: ad7944: max high bits on direct read David Lechner
2025-05-07  6:29 ` Nuno Sá
2025-05-08 21:03 ` David Lechner
2025-05-15 16:16   ` Jonathan Cameron

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®