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 <trent.piepho@igorinstitute.com>
This commit is contained in:
Trent Piepho 2022-12-20 15:45:40 -08:00 committed by Lauren Murphy
commit 25579d95b1

View file

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