From f6c02f49136a06dc0e4c8a898c7a37ac645aee97 Mon Sep 17 00:00:00 2001 From: AlvinCC_Hsu Date: Sat, 14 Nov 2020 21:15:38 +0800 Subject: driver: bmi: Fix accelerometer sensor data read failed This patch reverts CL:2483357. Fix accelerometer sensor data read failed after EC reboot. BUG=b:173207451 BRANCH=none TEST=read sensor data use "ectool motionsense" after EC reboot Signed-off-by: AlvinCC_Hsu Change-Id: I1cd6f8364335244a3037e94d859ac1f81a63b395 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2543565 Reviewed-by: Alexandru M Stan Commit-Queue: Alexandru M Stan --- driver/accelgyro_bmi_common.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'driver') diff --git a/driver/accelgyro_bmi_common.c b/driver/accelgyro_bmi_common.c index d699c34cf0..9be2fe2bad 100644 --- a/driver/accelgyro_bmi_common.c +++ b/driver/accelgyro_bmi_common.c @@ -200,6 +200,14 @@ int bmi_write8(const int port, const uint16_t i2c_spi_addr_flags, reg, data); #endif } + /* + * From Bosch: BMI needs a delay of 450us after each write if it + * is in suspend mode, otherwise the operation may be ignored by + * the sensor. Given we are only doing write during init, add + * the delay unconditionally. + */ + msleep(1); + return rv; } @@ -225,6 +233,34 @@ int bmi_read16(const int port, const uint16_t i2c_spi_addr_flags, return rv; } +/** + * Write 16bit register from accelerometer. + */ +int bmi_write16(const int port, const uint16_t i2c_spi_addr_flags, + const int reg, int data) +{ + int rv = -EC_ERROR_PARAM1; + + if (SLAVE_IS_SPI(i2c_spi_addr_flags)) { +#ifdef CONFIG_SPI_ACCEL_PORT + CPRINTS("%s() spi part is not implemented", __func__); +#endif + } else { +#ifdef I2C_PORT_ACCEL + rv = i2c_write16(port, i2c_spi_addr_flags, + reg, data); +#endif + } + /* + * From Bosch: BMI needs a delay of 450us after each write if it + * is in suspend mode, otherwise the operation may be ignored by + * the sensor. Given we are only doing write during init, add + * the delay unconditionally. + */ + msleep(1); + return rv; +} + /** * Read 32bit register from accelerometer. */ @@ -287,6 +323,14 @@ int bmi_write_n(const int port, const uint16_t i2c_spi_addr_flags, reg, data_ptr, len); #endif } + /* + * From Bosch: BMI needs a delay of 450us after each write if it + * is in suspend mode, otherwise the operation may be ignored by + * the sensor. Given we are only doing write during init, add + * the delay unconditionally. + */ + msleep(1); + return rv; } /* -- cgit v1.2.1