Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: adc: ad7923: fix channel readings for some variants

Some of the supported devices have 4 or 2 LSB trailing bits that should
not be taken into account. Hence we need to shift these bits out which
fits perfectly on the scan type shift property. This change fixes both
raw and buffered reads.

Fixes: f2f7a449707e ("iio:adc:ad7923: Add support for the ad7904/ad7914/ad7924")
Fixes: 851644a60d20 ("iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20220912081223.173584-2-nuno.sa@analog.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
f4f43f01 54861624

+3 -1
+3 -1
drivers/iio/adc/ad7923.c
··· 93 93 .sign = 'u', \ 94 94 .realbits = (bits), \ 95 95 .storagebits = 16, \ 96 + .shift = 12 - (bits), \ 96 97 .endianness = IIO_BE, \ 97 98 }, \ 98 99 } ··· 269 268 return ret; 270 269 271 270 if (chan->address == EXTRACT(ret, 12, 4)) 272 - *val = EXTRACT(ret, 0, 12); 271 + *val = EXTRACT(ret, chan->scan_type.shift, 272 + chan->scan_type.realbits); 273 273 else 274 274 return -EIO; 275 275