iio: inv_mpu6050: Clear timestamps fifo while resetting hardware fifo

A hardware fifo reset always imply an invalidation of the
existing timestamps, so we'll clear timestamps fifo on
successfull hardware fifo reset.

Signed-off-by: Viorel Suman <viorel.suman@gmail.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
Viorel Suman 2015-02-18 20:05:21 +02:00 committed by Jonathan Cameron
parent 8d09f48adf
commit 4dac0a8eef

View file

@ -24,6 +24,16 @@
#include <linux/poll.h> #include <linux/poll.h>
#include "inv_mpu_iio.h" #include "inv_mpu_iio.h"
static void inv_clear_kfifo(struct inv_mpu6050_state *st)
{
unsigned long flags;
/* take the spin lock sem to avoid interrupt kick in */
spin_lock_irqsave(&st->time_stamp_lock, flags);
kfifo_reset(&st->timestamps);
spin_unlock_irqrestore(&st->time_stamp_lock, flags);
}
int inv_reset_fifo(struct iio_dev *indio_dev) int inv_reset_fifo(struct iio_dev *indio_dev)
{ {
int result; int result;
@ -50,6 +60,10 @@ int inv_reset_fifo(struct iio_dev *indio_dev)
INV_MPU6050_BIT_FIFO_RST); INV_MPU6050_BIT_FIFO_RST);
if (result) if (result)
goto reset_fifo_fail; goto reset_fifo_fail;
/* clear timestamps fifo */
inv_clear_kfifo(st);
/* enable interrupt */ /* enable interrupt */
if (st->chip_config.accl_fifo_enable || if (st->chip_config.accl_fifo_enable ||
st->chip_config.gyro_fifo_enable) { st->chip_config.gyro_fifo_enable) {
@ -83,16 +97,6 @@ reset_fifo_fail:
return result; return result;
} }
static void inv_clear_kfifo(struct inv_mpu6050_state *st)
{
unsigned long flags;
/* take the spin lock sem to avoid interrupt kick in */
spin_lock_irqsave(&st->time_stamp_lock, flags);
kfifo_reset(&st->timestamps);
spin_unlock_irqrestore(&st->time_stamp_lock, flags);
}
/** /**
* inv_mpu6050_irq_handler() - Cache a timestamp at each data ready interrupt. * inv_mpu6050_irq_handler() - Cache a timestamp at each data ready interrupt.
*/ */
@ -184,7 +188,6 @@ end_session:
flush_fifo: flush_fifo:
/* Flush HW and SW FIFOs. */ /* Flush HW and SW FIFOs. */
inv_reset_fifo(indio_dev); inv_reset_fifo(indio_dev);
inv_clear_kfifo(st);
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
iio_trigger_notify_done(indio_dev->trig); iio_trigger_notify_done(indio_dev->trig);