From 25579d95b129c0eace4e0dbbffd936175648a556 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Tue, 20 Dec 2022 15:45:40 -0800 Subject: [PATCH] drivers/sensor: lsm6dso: Disable sensor hub before reset Per an ST app note, the sensor hub I2C controller should be disabled before doing a software reset. Possibly, this is because the sensor hub could be in the middle of the an I2C transaction to a sensor when it is reset. Disabling it and then waiting makes sure it has quiesced before resetting. Signed-off-by: Trent Piepho --- drivers/sensor/lsm6dso/lsm6dso.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/sensor/lsm6dso/lsm6dso.c b/drivers/sensor/lsm6dso/lsm6dso.c index 80ba9fd5e85..a00aaa2f781 100644 --- a/drivers/sensor/lsm6dso/lsm6dso.c +++ b/drivers/sensor/lsm6dso/lsm6dso.c @@ -712,7 +712,7 @@ static int lsm6dso_init_chip(const struct device *dev) const struct lsm6dso_config *cfg = dev->config; stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; struct lsm6dso_data *lsm6dso = dev->data; - uint8_t chip_id; + uint8_t chip_id, master_on; uint8_t odr, fs; if (lsm6dso_device_id_get(ctx, &chip_id) < 0) { @@ -733,6 +733,19 @@ static int lsm6dso_init_chip(const struct device *dev) return -EIO; } + /* Per AN5192 §7.2.1, "… when applying the software reset procedure, the I2C master + * must be disabled, followed by a 300 μs wait." + */ + if (lsm6dso_sh_master_get(ctx, &master_on) < 0) { + LOG_DBG("Failed to get I2C_MASTER status"); + return -EIO; + } + if (master_on) { + LOG_DBG("Disable shub before reset"); + lsm6dso_sh_master_set(ctx, 0); + k_busy_wait(300); + } + /* reset device */ if (lsm6dso_reset_set(ctx, 1) < 0) { return -EIO;