From 3499375209ca839a741e775d579f8bb9b85529d5 Mon Sep 17 00:00:00 2001 From: Petre Rodan Date: Sun, 5 Oct 2025 16:12:24 +0300 Subject: [PATCH] iio: accel: bma220: add i2c watchdog feature Sometimes the sensor gets stuck and enters a condition in which it pulls SDA low, thus making the entire i2c bus unusable. This problem is mitigated by activating a 1ms watchdog implemented in the sensor. Signed-off-by: Petre Rodan Signed-off-by: Jonathan Cameron --- drivers/iio/accel/bma220_core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c index 050827bfb9e67..38a2f36783cd3 100644 --- a/drivers/iio/accel/bma220_core.c +++ b/drivers/iio/accel/bma220_core.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -356,6 +357,12 @@ static int bma220_power(struct bma220_data *data, bool up) return -EBUSY; } +static int bma220_set_wdt(struct bma220_data *data, const u8 val) +{ + return regmap_update_bits(data->regmap, BMA220_REG_WDT, BMA220_WDT_MASK, + FIELD_PREP(BMA220_WDT_MASK, val)); +} + static int bma220_init(struct device *dev, struct bma220_data *data) { int ret; @@ -384,6 +391,13 @@ static int bma220_init(struct device *dev, struct bma220_data *data) if (ret) return dev_err_probe(dev, ret, "Failed to soft reset chip\n"); + if (i2c_verify_client(dev)) { + ret = bma220_set_wdt(data, BMA220_WDT_1MS); + if (ret) + return dev_err_probe(dev, ret, + "Failed to set i2c watchdog\n"); + } + return 0; } -- 2.47.3