Skip to content

Commit

Permalink
iio: adc: ad7923: fix channel readings for some variants
Browse files Browse the repository at this point in the history
commit f4f43f0 upstream.

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: f2f7a44 ("iio:adc:ad7923: Add support for the ad7904/ad7914/ad7924")
Fixes: 851644a ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
nunojsa authored and gregkh committed Oct 21, 2022
1 parent 14fd9ed commit fe2852b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/iio/adc/ad7923.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ enum ad7923_id {
.sign = 'u', \
.realbits = (bits), \
.storagebits = 16, \
.shift = 12 - (bits), \
.endianness = IIO_BE, \
}, \
}
Expand Down Expand Up @@ -268,7 +269,8 @@ static int ad7923_read_raw(struct iio_dev *indio_dev,
return ret;

if (chan->address == EXTRACT(ret, 12, 4))
*val = EXTRACT(ret, 0, 12);
*val = EXTRACT(ret, chan->scan_type.shift,
chan->scan_type.realbits);
else
return -EIO;

Expand Down

0 comments on commit fe2852b

Please sign in to comment.