Commit 3aed83ca authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Jonathan Cameron

iio: imu: st_lsm6dsx: do not use a fixed read len in read_oneshot

Generalize st_lsm6dsx_shub_read_oneshot in order to not use a fixed
read length and take into account iio channel realbits for single
read operations
Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 8611b69e
...@@ -432,8 +432,8 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor, ...@@ -432,8 +432,8 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor,
struct iio_chan_spec const *ch, struct iio_chan_spec const *ch,
int *val) int *val)
{ {
int err, delay, len = ch->scan_type.realbits >> 3; int err, delay, len;
__le16 data; u8 data[4];
err = st_lsm6dsx_shub_set_enable(sensor, true); err = st_lsm6dsx_shub_set_enable(sensor, true);
if (err < 0) if (err < 0)
...@@ -442,15 +442,17 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor, ...@@ -442,15 +442,17 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor,
delay = 1000000 / sensor->odr; delay = 1000000 / sensor->odr;
usleep_range(delay, 2 * delay); usleep_range(delay, 2 * delay);
err = st_lsm6dsx_shub_read(sensor, ch->address, (u8 *)&data, len); len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3);
if (err < 0) err = st_lsm6dsx_shub_read(sensor, ch->address, data, len);
return err;
st_lsm6dsx_shub_set_enable(sensor, false); st_lsm6dsx_shub_set_enable(sensor, false);
if (err < 0)
return err;
switch (len) { switch (len) {
case 2: case 2:
*val = (s16)le16_to_cpu(data); *val = (s16)le16_to_cpu(*((__le16 *)data));
break; break;
default: default:
return -EINVAL; return -EINVAL;
......
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