Skip to content

Commit 76e12a7

Browse files
jmaneyrol-invngregkh
authored andcommitted
iio: imu: inv_icm42600: fix timestamping by limiting FIFO reading
commit affe3f0 upstream. Timestamps are made by measuring the chip clock using the watermark interrupts. If we read more than watermark samples as done today, we are reducing the period between interrupts and distort the time measurement. Fix that by reading only watermark samples in the interrupt case. Fixes: 7f85e42 ("iio: imu: inv_icm42600: add buffer support in iio devices") Cc: stable@vger.kernel.org Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 34656a5 commit 76e12a7

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ int inv_icm42600_buffer_update_watermark(struct inv_icm42600_state *st)
248248

249249
/* compute watermark value in bytes */
250250
wm_size = watermark * packet_size;
251+
st->fifo.watermark.value = watermark;
251252

252253
/* changing FIFO watermark requires to turn off watermark interrupt */
253254
ret = regmap_update_bits_check(st->map, INV_ICM42600_REG_INT_SOURCE0,
@@ -454,11 +455,10 @@ int inv_icm42600_buffer_fifo_read(struct inv_icm42600_state *st,
454455
st->fifo.nb.accel = 0;
455456
st->fifo.nb.total = 0;
456457

457-
/* compute maximum FIFO read size */
458+
/* compute maximum FIFO read size (watermark for max = 0 interrupt case) */
458459
if (max == 0)
459-
max_count = sizeof(st->fifo.data);
460-
else
461-
max_count = max * inv_icm42600_get_packet_size(st->fifo.en);
460+
max = st->fifo.watermark.value;
461+
max_count = max * inv_icm42600_get_packet_size(st->fifo.en);
462462

463463
/* read FIFO count value */
464464
raw_fifo_count = (__be16 *)st->buffer;
@@ -574,6 +574,7 @@ int inv_icm42600_buffer_init(struct inv_icm42600_state *st)
574574

575575
st->fifo.watermark.eff_gyro = 1;
576576
st->fifo.watermark.eff_accel = 1;
577+
st->fifo.watermark.value = 1;
577578

578579
/*
579580
* Default FIFO configuration (bits 7 to 5)

drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct inv_icm42600_fifo {
3434
unsigned int accel;
3535
unsigned int eff_gyro;
3636
unsigned int eff_accel;
37+
unsigned int value;
3738
} watermark;
3839
size_t count;
3940
struct {

0 commit comments

Comments
 (0)