Skip to content

Commit 2215f31

Browse files
itirdeajic23
authored andcommitted
iio: accel: bmc150: fix endianness when reading axes
For big endian platforms, reading the axes will return invalid values. The device stores each axis value in a 16 bit little endian register. The driver uses regmap_read_bulk to get the axis value, resulting in a 16 bit little endian value. This needs to be converted to cpu endianness to work on big endian platforms. Fix endianness for big endian platforms by converting the values for the axes read from little endian to cpu. This is also partially fixed in commit b6fb9b6d6552 ("iio: accel: bmc150: optimize transfers in trigger handler"). Signed-off-by: Irina Tirdea <irina.tirdea@intel.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 9b090a9 commit 2215f31

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/iio/accel/bmc150-accel-core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data,
547547
{
548548
int ret;
549549
int axis = chan->scan_index;
550-
unsigned int raw_val;
550+
__le16 raw_val;
551551

552552
mutex_lock(&data->mutex);
553553
ret = bmc150_accel_set_power_state(data, true);
@@ -557,14 +557,14 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data,
557557
}
558558

559559
ret = regmap_bulk_read(data->regmap, BMC150_ACCEL_AXIS_TO_REG(axis),
560-
&raw_val, 2);
560+
&raw_val, sizeof(raw_val));
561561
if (ret < 0) {
562562
dev_err(data->dev, "Error reading axis %d\n", axis);
563563
bmc150_accel_set_power_state(data, false);
564564
mutex_unlock(&data->mutex);
565565
return ret;
566566
}
567-
*val = sign_extend32(raw_val >> chan->scan_type.shift,
567+
*val = sign_extend32(le16_to_cpu(raw_val) >> chan->scan_type.shift,
568568
chan->scan_type.realbits - 1);
569569
ret = bmc150_accel_set_power_state(data, false);
570570
mutex_unlock(&data->mutex);
@@ -988,6 +988,7 @@ static const struct iio_event_spec bmc150_accel_event = {
988988
.realbits = (bits), \
989989
.storagebits = 16, \
990990
.shift = 16 - (bits), \
991+
.endianness = IIO_LE, \
991992
}, \
992993
.event_spec = &bmc150_accel_event, \
993994
.num_event_specs = 1 \

0 commit comments

Comments
 (0)