From a8a67a8073028bb825a53c74859c688240bd34f3 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Tue, 10 Jan 2017 14:14:35 -0800 Subject: [PATCH] driver: bmi160: Set odr to 0 at init. When we switch to a state where the sensor is not powered, we don't call set_data_rate(0), because we may trigger an i2c/spi access to a sensor already powered off. It has the side effect to leave data->odr to the last set sensor frequency. When we init the BMI160, it starts in suspend mode. We will set it to normal mode only if data->odr is 0. Therefore, we must set odr to 0 in the init routine. BUG=chrome-os-partner:61502 BRANCH=reef,kevin TEST=On reef, without this change. When going to S5 (shutdown -h 0) and power back up, sensor is stuck (on EC, accelread 1 reads old value). With this fix, sensor is active and working. This fix a regression due to CL:411964. Check others driver do not check odr for setting suspend/normal mode. Change-Id: Ibc7519d49e55a0b43b4c12ed545bd75ab0260766 Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/426766 Reviewed-by: Aaron Durbin --- driver/accelgyro_bmi160.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index a92cc1f54c..4ea5a6a66a 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -1087,6 +1087,7 @@ static int read(const struct motion_sensor_t *s, vector_3_t v) static int init(const struct motion_sensor_t *s) { int ret = 0, tmp; + struct accelgyro_saved_data_t *data = BMI160_GET_SAVED_DATA(s); ret = raw_read8(s->port, s->addr, BMI160_CHIP_ID, &tmp); if (ret) @@ -1214,6 +1215,11 @@ static int init(const struct motion_sensor_t *s) } #endif + /* + * The sensor is in Suspend mode at init, + * so set data rate to 0. + */ + data->odr = 0; set_range(s, s->default_range, 0); if (s->type == MOTIONSENSE_TYPE_ACCEL) {