]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
iio: imu: inv_mpu6050: stabilized timestamping in interrupt
authorJean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Mon, 27 May 2024 15:01:17 +0000 (15:01 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 3 Jun 2024 18:05:56 +0000 (19:05 +0100)
Use IRQ ONESHOT flag to ensure the timestamp is not updated in the
hard handler during the thread handler. And use a fixed value of 1
sample that correspond to this first timestamp.

This way we can ensure the timestamp is always corresponding to the
value used by the timestamping mechanism. Otherwise, it is possible
that between FIFO count read and FIFO processing the timestamp is
overwritten in the hard handler.

Fixes: 111e1abd0045 ("iio: imu: inv_mpu6050: use the common inv_sensors timestamp module")
Cc: stable@vger.kernel.org
Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Link: https://lore.kernel.org/r/20240527150117.608792-1-inv.git-commit@tdk.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c

index 0dc0f22a5582799441bb8ed3ccd2baad93322dee..3d3b27f28c9d1c94aba93678261ce0d63099e1dc 100644 (file)
@@ -100,8 +100,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
                goto end_session;
        /* Each FIFO data contains all sensors, so same number for FIFO and sensor data */
        fifo_period = NSEC_PER_SEC / INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider);
-       inv_sensors_timestamp_interrupt(&st->timestamp, nb, pf->timestamp);
-       inv_sensors_timestamp_apply_odr(&st->timestamp, fifo_period, nb, 0);
+       inv_sensors_timestamp_interrupt(&st->timestamp, 1, pf->timestamp);
+       inv_sensors_timestamp_apply_odr(&st->timestamp, fifo_period, 1, 0);
 
        /* clear internal data buffer for avoiding kernel data leak */
        memset(data, 0, sizeof(data));
index 1b603567ccc80452c92d5bde41472ce54d252c78..84273660ca2eb9b4a3943a8bae719065909972a4 100644 (file)
@@ -300,6 +300,7 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type)
        if (!st->trig)
                return -ENOMEM;
 
+       irq_type |= IRQF_ONESHOT;
        ret = devm_request_threaded_irq(&indio_dev->dev, st->irq,
                                        &inv_mpu6050_interrupt_timestamp,
                                        &inv_mpu6050_interrupt_handle,