diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2021-11-04 09:24:10 +0100 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2021-11-17 18:51:43 +0100 |
commit | 4d57fb548a1b086fc216c94cc186fba03c396190 (patch) | |
tree | f2f2eaf6c90e2fa9bbc9b383c455f7bba8806468 /drivers/iio/magnetometer/mag3110.c | |
parent | iio: ti-adc12138: Use scan_type when processing raw data (diff) | |
download | linux-4d57fb548a1b086fc216c94cc186fba03c396190.tar.xz linux-4d57fb548a1b086fc216c94cc186fba03c396190.zip |
iio: mag3110: Use scan_type when processing raw data
Use channel definition as root of trust and replace constant
when reading elements directly using the raw sysfs attributes.
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Link: https://lore.kernel.org/r/20211104082413.3681212-11-gwendal@chromium.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/magnetometer/mag3110.c')
-rw-r--r-- | drivers/iio/magnetometer/mag3110.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c index c96415a1aead..17c62d806218 100644 --- a/drivers/iio/magnetometer/mag3110.c +++ b/drivers/iio/magnetometer/mag3110.c @@ -291,7 +291,8 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, if (ret < 0) goto release; *val = sign_extend32( - be16_to_cpu(buffer[chan->scan_index]), 15); + be16_to_cpu(buffer[chan->scan_index]), + chan->scan_type.realbits - 1); ret = IIO_VAL_INT; break; case IIO_TEMP: /* in 1 C / LSB */ @@ -306,7 +307,8 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, mutex_unlock(&data->lock); if (ret < 0) goto release; - *val = sign_extend32(ret, 7); + *val = sign_extend32(ret, + chan->scan_type.realbits - 1); ret = IIO_VAL_INT; break; default: |