Skip to content

Commit

Permalink
iio: imu: st_lsm6dsx: wait for settling time in st_lsm6dsx_read_oneshot
Browse files Browse the repository at this point in the history
We need to wait for sensor settling time (~ 3/ODR) before reading data
in st_lsm6dsx_read_oneshot routine in order to avoid corrupted samples.

Fixes: 290a6ce ("iio: imu: add support to lsm6dsx driver")
Reported-by: Mario Tesi <mario.tesi@st.com>
Tested-by: Mario Tesi <mario.tesi@st.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Link: https://lore.kernel.org/r/b41ebda5535895298716c76d939f9f165fcd2d13.1644098120.git.lorenzo@kernel.org
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
  • Loading branch information
LorenzoBianconi authored and jic23 committed Feb 7, 2022
1 parent 632fe0b commit ea85bf9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,12 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
if (err < 0)
return err;

/*
* we need to wait for sensor settling time before
* reading data in order to avoid corrupted samples
*/
delay = 1000000000 / sensor->odr;
usleep_range(delay, 2 * delay);
usleep_range(3 * delay, 4 * delay);

err = st_lsm6dsx_read_locked(hw, addr, &data, sizeof(data));
if (err < 0)
Expand Down

0 comments on commit ea85bf9

Please sign in to comment.