Commit c2b82a69 authored by Jean-Baptiste Maneyrol's avatar Jean-Baptiste Maneyrol Committed by Jonathan Cameron

iio: imu: inv_mpu6050: skip first sample when gyro is on

Implement generic skip first samples mechanism and use it to
filter out first sample when gyro is on.

The problem for these chips is that the first sample of the gyro
is out of specs, because gyro is not completely stabilized. To
ensure all data are within sensor specs, we just skip the first
sample when turning gyro on.
Signed-off-by: default avatarJean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent ca4c8fc9
...@@ -148,6 +148,7 @@ struct inv_mpu6050_state { ...@@ -148,6 +148,7 @@ struct inv_mpu6050_state {
struct regmap *map; struct regmap *map;
int irq; int irq;
u8 irq_mask; u8 irq_mask;
unsigned skip_samples;
}; };
/*register and associated bit definition*/ /*register and associated bit definition*/
......
...@@ -185,7 +185,12 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) ...@@ -185,7 +185,12 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
if (result == 0) if (result == 0)
timestamp = 0; timestamp = 0;
iio_push_to_buffers_with_timestamp(indio_dev, data, timestamp); /* skip first samples if needed */
if (st->skip_samples)
st->skip_samples--;
else
iio_push_to_buffers_with_timestamp(indio_dev, data,
timestamp);
fifo_count -= bytes_per_datum; fifo_count -= bytes_per_datum;
} }
......
...@@ -49,11 +49,14 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) ...@@ -49,11 +49,14 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable)
if (result) if (result)
return result; return result;
inv_scan_query(indio_dev); inv_scan_query(indio_dev);
st->skip_samples = 0;
if (st->chip_config.gyro_fifo_enable) { if (st->chip_config.gyro_fifo_enable) {
result = inv_mpu6050_switch_engine(st, true, result = inv_mpu6050_switch_engine(st, true,
INV_MPU6050_BIT_PWR_GYRO_STBY); INV_MPU6050_BIT_PWR_GYRO_STBY);
if (result) if (result)
goto error_power_off; goto error_power_off;
/* gyro first sample is out of specs, skip it */
st->skip_samples = 1;
} }
if (st->chip_config.accl_fifo_enable) { if (st->chip_config.accl_fifo_enable) {
result = inv_mpu6050_switch_engine(st, true, result = inv_mpu6050_switch_engine(st, true,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment