Commit 4d57fb54 authored by Gwendal Grignou's avatar Gwendal Grignou Committed by Jonathan Cameron

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: default avatarGwendal Grignou <gwendal@chromium.org>
Link: https://lore.kernel.org/r/20211104082413.3681212-11-gwendal@chromium.orgSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent a5cd0e7f
...@@ -291,7 +291,8 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, ...@@ -291,7 +291,8 @@ static int mag3110_read_raw(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
goto release; goto release;
*val = sign_extend32( *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; ret = IIO_VAL_INT;
break; break;
case IIO_TEMP: /* in 1 C / LSB */ case IIO_TEMP: /* in 1 C / LSB */
...@@ -306,7 +307,8 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, ...@@ -306,7 +307,8 @@ static int mag3110_read_raw(struct iio_dev *indio_dev,
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
if (ret < 0) if (ret < 0)
goto release; goto release;
*val = sign_extend32(ret, 7); *val = sign_extend32(ret,
chan->scan_type.realbits - 1);
ret = IIO_VAL_INT; ret = IIO_VAL_INT;
break; break;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment