Skip to content

Commit ef5f5e7

Browse files
jmaneyrol-invnjic23
authored andcommitted
iio: invensense: fix multiple odr switch when FIFO is off
When multiple ODR switch happens during FIFO off, the change could not be taken into account if you get back to previous FIFO on value. For example, if you run sensor buffer at 50Hz, stop, change to 200Hz, then back to 50Hz and restart buffer, data will be timestamped at 200Hz. This due to testing against mult and not new_mult. To prevent this, let's just run apply_odr automatically when FIFO is off. It will also simplify driver code. Update inv_mpu6050 and inv_icm42600 to delete now useless apply_odr. Fixes: 95444b9 ("iio: invensense: fix odr switching to same value") Cc: [email protected] Signed-off-by: Jean-Baptiste Maneyrol <[email protected]> Link: https://patch.msgid.link/20241021-invn-inv-sensors-timestamp-fix-switch-fifo-off-v2-1-39ffd43edcc4@tdk.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent d0bc3b9 commit ef5f5e7

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

drivers/iio/common/inv_sensors/inv_sensors_timestamp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ int inv_sensors_timestamp_update_odr(struct inv_sensors_timestamp *ts,
7070
if (mult != ts->mult)
7171
ts->new_mult = mult;
7272

73+
/* When FIFO is off, directly apply the new ODR */
74+
if (!fifo)
75+
inv_sensors_timestamp_apply_odr(ts, 0, 0, 0);
76+
7377
return 0;
7478
}
7579
EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_update_odr, IIO_INV_SENSORS_TIMESTAMP);

drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev,
200200
{
201201
struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
202202
struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev);
203-
struct inv_sensors_timestamp *ts = &accel_st->ts;
204203
struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
205204
unsigned int fifo_en = 0;
206205
unsigned int sleep_temp = 0;
@@ -229,7 +228,6 @@ static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev,
229228
}
230229

231230
/* update data FIFO write */
232-
inv_sensors_timestamp_apply_odr(ts, 0, 0, 0);
233231
ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en);
234232

235233
out_unlock:

drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ static int inv_icm42600_gyro_update_scan_mode(struct iio_dev *indio_dev,
9999
const unsigned long *scan_mask)
100100
{
101101
struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
102-
struct inv_icm42600_sensor_state *gyro_st = iio_priv(indio_dev);
103-
struct inv_sensors_timestamp *ts = &gyro_st->ts;
104102
struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
105103
unsigned int fifo_en = 0;
106104
unsigned int sleep_gyro = 0;
@@ -128,7 +126,6 @@ static int inv_icm42600_gyro_update_scan_mode(struct iio_dev *indio_dev,
128126
}
129127

130128
/* update data FIFO write */
131-
inv_sensors_timestamp_apply_odr(ts, 0, 0, 0);
132129
ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en);
133130

134131
out_unlock:

drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable)
112112
if (enable) {
113113
/* reset timestamping */
114114
inv_sensors_timestamp_reset(&st->timestamp);
115-
inv_sensors_timestamp_apply_odr(&st->timestamp, 0, 0, 0);
116115
/* reset FIFO */
117116
d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_RST;
118117
ret = regmap_write(st->map, st->reg->user_ctrl, d);

0 commit comments

Comments
 (0)