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 <trent.piepho@igorinstitute.com>
This commit is contained in:
Trent Piepho 2022-12-20 17:42:06 -08:00 committed by Lauren Murphy
commit c379f86dbd

View file

@ -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;