From c379f86dbd9de887c4b673565eb844e7b835ff43 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Tue, 20 Dec 2022 17:42:06 -0800 Subject: [PATCH] drivers/sensor: lsm6dso: Set to user bank on init The lsm6dso initialization will fail if the device is not already set to the user register bank. All the registers used will be the wrong ones from whatever bank it is in, e.g. sensor hub bank. This includes the registers to reset the device! The bank will default to the user bank on reset, but the chip has no hardware reset line. On a reboot it will be in whatever bank it was last in. If the sensor hub is enabled, it will switch banks on every sample, so it's entirely possible to reset or reboot when it happens to be set to the sensor hub bank, which will cause the driver to fail to initialize. It will not work again until the lsm6dso is power cycled. Signed-off-by: Trent Piepho --- drivers/sensor/lsm6dso/lsm6dso.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/sensor/lsm6dso/lsm6dso.c b/drivers/sensor/lsm6dso/lsm6dso.c index a00aaa2f781..6d40ff0fc97 100644 --- a/drivers/sensor/lsm6dso/lsm6dso.c +++ b/drivers/sensor/lsm6dso/lsm6dso.c @@ -715,6 +715,16 @@ static int lsm6dso_init_chip(const struct device *dev) uint8_t chip_id, master_on; uint8_t odr, fs; + /* All registers except 0x01 are different between banks, including the WHO_AM_I + * register and the register used for a SW reset. If the lsm6dso wasn't on the user + * bank when it reset, then both the chip id check and the sw reset will fail unless we + * set the bank now. + */ + if (lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK) < 0) { + LOG_DBG("Failed to set user bank"); + return -EIO; + } + if (lsm6dso_device_id_get(ctx, &chip_id) < 0) { LOG_DBG("Failed reading chip id"); return -EIO;