From 484de8b6bda133e30e613cee06cb9e6bebfc8506 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ishii Date: Tue, 12 Oct 2021 11:30:05 +0900 Subject: [PATCH] imu: st_lsm6dsx: tentative: Fix invalid value read from asm330lhh With respect to ASM330LHH's datasheet, we need to wait between enabling accelerometer and reading value for designated samples depend on frequency and/or other configurations. Current implementation intends to wait for more than 1 sample and less than 2 samples but it's obviously incompliant against the spec and results to read of invalid-value (-32764) from sensors occasionally. As mentioned above we need complicated control actually, however, it looks enough to wait for 3 samples for all availavle configurations currently supported, so that we do it as of now. Signed-off-by: Hiroyuki Ishii --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 13 ++++++++++++- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 057a4b010010..99c92c345971 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -1086,7 +1086,18 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor, return err; delay = 1000000 / sensor->odr; - usleep_range(delay, 2 * delay); + if (!strcmp(sensor->name, "asm330lhh_accel")) { + /* + * FIXME: With respect to ASM330LHH's datasheet, we need to wait between + * enabling sensors and reading value for designated samples depend on + * frequency and/or other configurations. However it looks enough to wait + * for 3 samples for all availavle configurations currently supported, so + * that we do it as of now. + */ + usleep_range(3 * delay, 3 * delay + 100); + } else { + usleep_range(delay, 2 * delay); + } err = st_lsm6dsx_read_locked(hw, addr, &data, sizeof(data)); if (err < 0) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c index ea472cf6db7b..2be7e2a63d02 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c @@ -441,7 +441,18 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor, return err; delay = 1000000 / sensor->odr; - usleep_range(delay, 2 * delay); + if (!strcmp(sensor->name, "asm330lhh_accel")) { + /* + * FIXME: With respect to ASM330LHH's datasheet, we need to wait between + * enabling sensors and reading value for designated samples depend on + * frequency and/or other configurations. However it looks enough to wait + * for 3 samples for all availavle configurations currently supported, so + * that we do it as of now. + */ + usleep_range(3 * delay, 3 * delay + 100); + } else { + usleep_range(delay, 2 * delay); + } len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3); err = st_lsm6dsx_shub_read(sensor, ch->address, data, len); -- 2.25.1