]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: ad7768-1: Fix conversion result sign
authorSergiu Cuciurean <sergiu.cuciurean@analog.com>
Thu, 6 Mar 2025 21:00:29 +0000 (18:00 -0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 11 Mar 2025 19:09:16 +0000 (19:09 +0000)
The ad7768-1 ADC output code is two's complement, meaning that the voltage
conversion result is a signed value.. Since the value is a 24 bit one,
stored in a 32 bit variable, the sign should be extended in order to get
the correct representation.

Also the channel description has been updated to signed representation,
to match the ADC specifications.

Fixes: a5f8c7da3dbe ("iio: adc: Add AD7768-1 ADC basic support")
Reviewed-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
Cc: <Stable@vger.kernel.org>
Link: https://patch.msgid.link/505994d3b71c2aa38ba714d909a68e021f12124c.1741268122.git.Jonathan.Santos@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7768-1.c

index ea829c51e80b5d26d5a07e41315a9a88ed5166c4..09e7cccfd51cfd45dff3bcf3a324f6f57016564e 100644 (file)
@@ -142,7 +142,7 @@ static const struct iio_chan_spec ad7768_channels[] = {
                .channel = 0,
                .scan_index = 0,
                .scan_type = {
-                       .sign = 'u',
+                       .sign = 's',
                        .realbits = 24,
                        .storagebits = 32,
                        .shift = 8,
@@ -373,7 +373,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
                iio_device_release_direct(indio_dev);
                if (ret < 0)
                        return ret;
-               *val = ret;
+               *val = sign_extend32(ret, chan->scan_type.realbits - 1);
 
                return IIO_VAL_INT;