From 08a2bed2193258a5cfcdc672f3c73a7bd96807b0 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Thu, 25 Apr 2019 16:59:28 -0700 Subject: driver: bmi160: Check enable_fifo flags before processing FIFO If there is an interrupt pending after we suspend the BMI160, we will try to collect length from the FIFO, but the FIFO is suspended. Bring back enable_fifo flags check before processing the FIFO. It has been move after gathering the length in CL:1128555 BUG=b:127321764,b:131272795 BRANCH=master TEST=Using flip_flop.sh script at b/131272795#comment2 Check the messages "unexpected empty FIFO" disappear. Change-Id: Iaab1a7f3607b902acd92b75c926365d7eb09fd5e Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1585420 Reviewed-by: Enrico Granata (cherry picked from commit d17cd2add14f1f1e32bd58d51d60a2c93f17f055) Reviewed-on: https://chromium-review.googlesource.com/1585471 (cherry picked from commit 2cc3e7ce65016520162198c0cafa30ef54271c21) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1597065 Reviewed-by: Marco Chen --- driver/accelgyro_bmi160.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index 2629f59340..9ffa86e363 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -852,6 +852,19 @@ static int load_fifo(struct motion_sensor_t *s, uint32_t last_ts) if (s->type != MOTIONSENSE_TYPE_ACCEL) return EC_SUCCESS; + if (!(data->flags & + (BMI160_FIFO_ALL_MASK << BMI160_FIFO_FLAG_OFFSET))) { + /* + * The FIFO was disabled while we were processing it. + * + * Flush potential left over: + * When sensor is resumed, we won't read old data. + */ + raw_write8(s->port, s->addr, BMI160_CMD_REG, + BMI160_CMD_FIFO_FLUSH); + return EC_SUCCESS; + } + raw_read_n(s->port, s->addr, BMI160_FIFO_LENGTH_0, (uint8_t *)&length, sizeof(length)); length &= BMI160_FIFO_LENGTH_MASK; @@ -872,19 +885,6 @@ static int load_fifo(struct motion_sensor_t *s, uint32_t last_ts) CPRINTS("unexpected large FIFO: %d", length); length = MIN(length, sizeof(bmi160_buffer)); - if (!(data->flags & - (BMI160_FIFO_ALL_MASK << BMI160_FIFO_FLAG_OFFSET))) { - /* - * The FIFO was disabled while we were processing it. - * - * Flush potential left over: - * When sensor is resumed, we won't read old data. - */ - raw_write8(s->port, s->addr, BMI160_CMD_REG, - BMI160_CMD_FIFO_FLUSH); - return EC_SUCCESS; - } - raw_read_n(s->port, s->addr, BMI160_FIFO_DATA, bmi160_buffer, length); -- cgit v1.2.1