Commit 34993752 authored by Petre Rodan's avatar Petre Rodan Committed by Jonathan Cameron
Browse files

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: default avatarPetre Rodan <petre.rodan@subdimension.ro>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 7a23e6d9
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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;
}