]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: accel: bma220: add i2c watchdog feature
authorPetre Rodan <petre.rodan@subdimension.ro>
Sun, 5 Oct 2025 13:12:24 +0000 (16:12 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 19 Oct 2025 10:59:20 +0000 (11:59 +0100)
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 <petre.rodan@subdimension.ro>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/bma220_core.c

index 050827bfb9e67e9fe386ebb99c831cb5ec02f586..38a2f36783cd320fea57f1c9d4c0b2d64d2b798f 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/errno.h>
+#include <linux/i2c.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
@@ -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;
 }