Commit f905772e authored by Gwendal Grignou's avatar Gwendal Grignou Committed by Jonathan Cameron

iio: bma220: 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-2-gwendal@chromium.orgSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 0d376dc9
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#define BMA220_CHIP_ID 0xDD #define BMA220_CHIP_ID 0xDD
#define BMA220_READ_MASK BIT(7) #define BMA220_READ_MASK BIT(7)
#define BMA220_RANGE_MASK GENMASK(1, 0) #define BMA220_RANGE_MASK GENMASK(1, 0)
#define BMA220_DATA_SHIFT 2
#define BMA220_SUSPEND_SLEEP 0xFF #define BMA220_SUSPEND_SLEEP 0xFF
#define BMA220_SUSPEND_WAKE 0x00 #define BMA220_SUSPEND_WAKE 0x00
...@@ -45,7 +44,7 @@ ...@@ -45,7 +44,7 @@
.sign = 's', \ .sign = 's', \
.realbits = 6, \ .realbits = 6, \
.storagebits = 8, \ .storagebits = 8, \
.shift = BMA220_DATA_SHIFT, \ .shift = 2, \
.endianness = IIO_CPU, \ .endianness = IIO_CPU, \
}, \ }, \
} }
...@@ -125,7 +124,8 @@ static int bma220_read_raw(struct iio_dev *indio_dev, ...@@ -125,7 +124,8 @@ static int bma220_read_raw(struct iio_dev *indio_dev,
ret = bma220_read_reg(data->spi_device, chan->address); ret = bma220_read_reg(data->spi_device, chan->address);
if (ret < 0) if (ret < 0)
return -EINVAL; return -EINVAL;
*val = sign_extend32(ret >> BMA220_DATA_SHIFT, 5); *val = sign_extend32(ret >> chan->scan_type.shift,
chan->scan_type.realbits - 1);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
ret = bma220_read_reg(data->spi_device, BMA220_REG_RANGE); ret = bma220_read_reg(data->spi_device, BMA220_REG_RANGE);
......
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