Skip to content

Commit 7762902

Browse files
LorenzoBianconijic23
authored andcommitted
iio: imu: st_lsm6dsx: fix read misalignment on untagged FIFO
st_lsm6dsx suffers of a read misalignment on untagged FIFO when all 3 supported sensors (accel, gyro and ext device) are running at different ODRs (the use-case is reported in the LSM6DSM Application Note at pag 100). Fix the issue taking into account decimation factor reading the 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 e2042d2 commit 7762902

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ enum st_lsm6dsx_fifo_mode {
337337
* @gain: Configured sensor sensitivity.
338338
* @odr: Output data rate of the sensor [Hz].
339339
* @watermark: Sensor watermark level.
340+
* @decimator: Sensor decimation factor.
340341
* @sip: Number of samples in a given pattern.
341342
* @ts_ref: Sensor timestamp reference for hw one.
342343
* @ext_info: Sensor settings if it is connected to i2c controller
@@ -350,6 +351,7 @@ struct st_lsm6dsx_sensor {
350351
u32 odr;
351352

352353
u16 watermark;
354+
u8 decimator;
353355
u8 sip;
354356
s64 ts_ref;
355357

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ st_lsm6dsx_get_decimator_val(struct st_lsm6dsx_sensor *sensor, u32 max_odr)
9393
break;
9494
}
9595

96+
sensor->decimator = decimator;
9697
return i == max_size ? 0 : st_lsm6dsx_decimator_table[i].val;
9798
}
9899

@@ -337,7 +338,7 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr,
337338
int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
338339
{
339340
struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor, *ext_sensor = NULL;
340-
int err, acc_sip, gyro_sip, ts_sip, ext_sip, read_len, offset;
341+
int err, sip, acc_sip, gyro_sip, ts_sip, ext_sip, read_len, offset;
341342
u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
342343
u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
343344
u8 gyro_buff[ST_LSM6DSX_IIO_BUFF_SIZE];
@@ -399,19 +400,20 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
399400
acc_sip = acc_sensor->sip;
400401
ts_sip = hw->ts_sip;
401402
offset = 0;
403+
sip = 0;
402404

403405
while (acc_sip > 0 || gyro_sip > 0 || ext_sip > 0) {
404-
if (gyro_sip > 0) {
406+
if (gyro_sip > 0 && !(sip % gyro_sensor->decimator)) {
405407
memcpy(gyro_buff, &hw->buff[offset],
406408
ST_LSM6DSX_SAMPLE_SIZE);
407409
offset += ST_LSM6DSX_SAMPLE_SIZE;
408410
}
409-
if (acc_sip > 0) {
411+
if (acc_sip > 0 && !(sip % acc_sensor->decimator)) {
410412
memcpy(acc_buff, &hw->buff[offset],
411413
ST_LSM6DSX_SAMPLE_SIZE);
412414
offset += ST_LSM6DSX_SAMPLE_SIZE;
413415
}
414-
if (ext_sip > 0) {
416+
if (ext_sip > 0 && !(sip % ext_sensor->decimator)) {
415417
memcpy(ext_buff, &hw->buff[offset],
416418
ST_LSM6DSX_SAMPLE_SIZE);
417419
offset += ST_LSM6DSX_SAMPLE_SIZE;
@@ -441,18 +443,25 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
441443
offset += ST_LSM6DSX_SAMPLE_SIZE;
442444
}
443445

444-
if (gyro_sip-- > 0)
446+
if (gyro_sip > 0 && !(sip % gyro_sensor->decimator)) {
445447
iio_push_to_buffers_with_timestamp(
446448
hw->iio_devs[ST_LSM6DSX_ID_GYRO],
447449
gyro_buff, gyro_sensor->ts_ref + ts);
448-
if (acc_sip-- > 0)
450+
gyro_sip--;
451+
}
452+
if (acc_sip > 0 && !(sip % acc_sensor->decimator)) {
449453
iio_push_to_buffers_with_timestamp(
450454
hw->iio_devs[ST_LSM6DSX_ID_ACC],
451455
acc_buff, acc_sensor->ts_ref + ts);
452-
if (ext_sip-- > 0)
456+
acc_sip--;
457+
}
458+
if (ext_sip > 0 && !(sip % ext_sensor->decimator)) {
453459
iio_push_to_buffers_with_timestamp(
454460
hw->iio_devs[ST_LSM6DSX_ID_EXT0],
455461
ext_buff, ext_sensor->ts_ref + ts);
462+
ext_sip--;
463+
}
464+
sip++;
456465
}
457466
}
458467

0 commit comments

Comments
 (0)