[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250907134819.5289f4fa@jic23-huawei>
Date: Sun, 7 Sep 2025 13:48:19 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Petre Rodan <petre.rodan@...dimension.ro>
Cc: linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org, David Lechner
<dlechner@...libre.com>, Nuno Sá <nuno.sa@...log.com>, Andy
Shevchenko <andy@...nel.org>
Subject: Re: [PATCH 05/10] iio: accel: BMA220 make use of the watchdog
functionality
On Mon, 1 Sep 2025 22:47:31 +0300
Petre Rodan <petre.rodan@...dimension.ro> wrote:
> Sometimes the sensor gets stuck and enters a condition in which it pulls
> SDA low, thus making the entire i2c bus unusable.
> The optional bosch,watchdog property mitigates this problem by clearing
> the condition after a period of 1 or 10ms.
As I think was discussed with the binding, I'd turn this on by default
and we can figure out if we want to change that if it causes anyone
problems long run.
>
> Signed-off-by: Petre Rodan <petre.rodan@...dimension.ro>
> ---
> drivers/iio/accel/bma220_core.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
> index fae84823d52b..86347cf8ab1e 100644
> --- a/drivers/iio/accel/bma220_core.c
> +++ b/drivers/iio/accel/bma220_core.c
> @@ -158,6 +158,12 @@ enum bma220_axis {
> AXIS_Z,
> };
>
> +enum bma220_prop_wdt {
> + BMA220_PROP_WDT_OFF,
> + BMA220_PROP_WDT_1MS,
> + BMA220_PROP_WDT_10MS,
> +};
> +
> static const int bma220_scale_table[][2] = {
> {0, 623000}, {1, 248000}, {2, 491000}, {4, 983000},
> };
> @@ -428,10 +434,17 @@ static int bma220_power(struct bma220_data *data, bool up)
> return -EBUSY;
> }
>
> +static int bma220_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)
> {
> int ret;
> unsigned int val;
> + u32 watchdog;
> static const char * const regulator_names[] = { "vddd", "vddio", "vdda" };
>
> ret = devm_regulator_bulk_get_enable(data->dev,
> @@ -462,6 +475,25 @@ static int bma220_init(struct bma220_data *data)
> return ret;
> }
>
> + ret = device_property_read_u32(data->dev, "bosch,watchdog", &watchdog);
> + if (!ret) {
> + switch (watchdog) {
> + case BMA220_PROP_WDT_1MS:
> + ret = bma220_wdt(data, BMA220_WDT_1MS);
> + break;
> + case BMA220_PROP_WDT_10MS:
> + ret = bma220_wdt(data, BMA220_WDT_10MS);
> + break;
> + default:
> + ret = bma220_wdt(data, BMA220_WDT_OFF);
> + break;
> + }
> + if (ret) {
> + dev_err(data->dev, "Failed to set watchdog\n");
dev_err_probe()
> + return ret;
> + }
> + }
> +
> return 0;
> }
>
> --
> 2.49.1
>
>
Powered by blists - more mailing lists