[PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature

Petre Rodan posted 19 patches 2 months, 1 week ago
[PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature
Posted by Petre Rodan 2 months, 1 week ago
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>
---
v1->v2
- hardcode 1ms timer watchdog to any i2c-based sensor instead of
  configuring a dt-based property
- rename bma220_wdt() to bma220_set_wdt()
v2->v4 no change
---
 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 a3faf1f5ec6d79f2c6105697b404d6eb1f4501db..a957751be40c63c25963283be813db97f73bf004 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -10,6 +10,7 @@
 #include <linux/bitfield.h>
 #include <linux/cleanup.h>
 #include <linux/device.h>
+#include <linux/i2c.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
@@ -355,6 +356,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;
@@ -383,6 +390,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.49.1
Re: [PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature
Posted by Jonathan Cameron 2 months ago
On Sun, 05 Oct 2025 16:12:24 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:

> 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>
Applied.

Thanks.

J