* [PATCH v2] iio: imu: inv_mpu6050: stabilized timestamping in interrupt
@ 2024-05-27 15:01 inv.git-commit
2024-06-02 13:06 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: inv.git-commit @ 2024-05-27 15:01 UTC (permalink / raw)
To: jic23; +Cc: lars, linux-iio, stable, Jean-Baptiste Maneyrol
From: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
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>
---
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 4 ++--
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
index 0dc0f22a5582..3d3b27f28c9d 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
@@ -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));
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
index 1b603567ccc8..84273660ca2e 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
@@ -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,
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] iio: imu: inv_mpu6050: stabilized timestamping in interrupt
2024-05-27 15:01 [PATCH v2] iio: imu: inv_mpu6050: stabilized timestamping in interrupt inv.git-commit
@ 2024-06-02 13:06 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2024-06-02 13:06 UTC (permalink / raw)
To: inv.git-commit; +Cc: lars, linux-iio, stable, Jean-Baptiste Maneyrol
On Mon, 27 May 2024 15:01:17 +0000
inv.git-commit@tdk.com wrote:
> From: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
>
> 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>
Applied
> ---
> drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 4 ++--
> drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 1 +
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> index 0dc0f22a5582..3d3b27f28c9d 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> @@ -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));
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> index 1b603567ccc8..84273660ca2e 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> @@ -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,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-02 13:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-27 15:01 [PATCH v2] iio: imu: inv_mpu6050: stabilized timestamping in interrupt inv.git-commit
2024-06-02 13:06 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox