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>
---
ChangeLog:
- hardcode 1ms timer watchdog to any i2c-based sensor instead of
configuring a dt-based property
- rename bma220_wdt() to bma220_set_wdt()
---
drivers/iio/accel/bma220_core.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 191074d8618ea2638f69283781b8677921876681..b619f5a0bf713b4d386a5d4fc1d919e144798f02 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/kernel.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
@@ -359,6 +360,11 @@ 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 bma220_data *data)
{
@@ -390,6 +396,13 @@ static int bma220_init(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