Skip to content

Commit 76551a3

Browse files
LorenzoBianconijic23
authored andcommitted
iio: imu: st_lsm6dsx: specify slave odr in slv_odr
Introduce slv_odr in ext_info data structure in order to distinguish between sensor hub trigger (accel sensor) odr and i2c slave odr and properly compute samples in FIFO pattern Fixes: e485e2a ("iio: imu: st_lsm6dsx: enable sensor-hub support for lsm6dsm") Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 7762902 commit 76551a3

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ struct st_lsm6dsx_sensor {
357357

358358
struct {
359359
const struct st_lsm6dsx_ext_dev_settings *settings;
360+
u32 slv_odr;
360361
u8 addr;
361362
} ext_info;
362363
};

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ int st_lsm6dsx_shub_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable)
421421

422422
settings = sensor->ext_info.settings;
423423
if (enable) {
424-
err = st_lsm6dsx_shub_set_odr(sensor, sensor->odr);
424+
err = st_lsm6dsx_shub_set_odr(sensor,
425+
sensor->ext_info.slv_odr);
425426
if (err < 0)
426427
return err;
427428
} else {
@@ -459,7 +460,7 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor,
459460
if (err < 0)
460461
return err;
461462

462-
delay = 1000000000 / sensor->odr;
463+
delay = 1000000000 / sensor->ext_info.slv_odr;
463464
usleep_range(delay, 2 * delay);
464465

465466
len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3);
@@ -500,8 +501,8 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev,
500501
iio_device_release_direct_mode(iio_dev);
501502
break;
502503
case IIO_CHAN_INFO_SAMP_FREQ:
503-
*val = sensor->odr / 1000;
504-
*val2 = (sensor->odr % 1000) * 1000;
504+
*val = sensor->ext_info.slv_odr / 1000;
505+
*val2 = (sensor->ext_info.slv_odr % 1000) * 1000;
505506
ret = IIO_VAL_INT_PLUS_MICRO;
506507
break;
507508
case IIO_CHAN_INFO_SCALE:
@@ -535,8 +536,20 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
535536

536537
val = val * 1000 + val2 / 1000;
537538
err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data);
538-
if (!err)
539-
sensor->odr = val;
539+
if (!err) {
540+
struct st_lsm6dsx_hw *hw = sensor->hw;
541+
struct st_lsm6dsx_sensor *ref_sensor;
542+
u8 odr_val;
543+
int odr;
544+
545+
ref_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
546+
odr = st_lsm6dsx_check_odr(ref_sensor, val, &odr_val);
547+
if (odr < 0)
548+
return odr;
549+
550+
sensor->ext_info.slv_odr = val;
551+
sensor->odr = odr;
552+
}
540553
break;
541554
}
542555
default:
@@ -613,6 +626,7 @@ st_lsm6dsx_shub_alloc_iiodev(struct st_lsm6dsx_hw *hw,
613626
const struct st_lsm6dsx_ext_dev_settings *info,
614627
u8 i2c_addr, const char *name)
615628
{
629+
enum st_lsm6dsx_sensor_id ref_id = ST_LSM6DSX_ID_ACC;
616630
struct iio_chan_spec *ext_channels;
617631
struct st_lsm6dsx_sensor *sensor;
618632
struct iio_dev *iio_dev;
@@ -628,7 +642,8 @@ st_lsm6dsx_shub_alloc_iiodev(struct st_lsm6dsx_hw *hw,
628642
sensor = iio_priv(iio_dev);
629643
sensor->id = id;
630644
sensor->hw = hw;
631-
sensor->odr = info->odr_table.odr_avl[0].milli_hz;
645+
sensor->odr = hw->settings->odr_table[ref_id].odr_avl[0].milli_hz;
646+
sensor->ext_info.slv_odr = info->odr_table.odr_avl[0].milli_hz;
632647
sensor->gain = info->fs_table.fs_avl[0].gain;
633648
sensor->ext_info.settings = info;
634649
sensor->ext_info.addr = i2c_addr;

0 commit comments

Comments
 (0)