From: Petre Rodan <petre.rodan@subdimension.ro>
To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Petre Rodan" <petre.rodan@subdimension.ro>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Subject: [PATCH 05/10] iio: accel: BMA220 make use of the watchdog functionality
Date: Mon, 1 Sep 2025 22:47:31 +0300 [thread overview]
Message-ID: <20250901194742.11599-6-petre.rodan@subdimension.ro> (raw)
In-Reply-To: <20250901194742.11599-1-petre.rodan@subdimension.ro>
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.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.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");
+ return ret;
+ }
+ }
+
return 0;
}
--
2.49.1
next prev parent reply other threads:[~2025-09-01 19:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-01 19:47 [PATCH 0/10] iio: accel: BMA220 improvements Petre Rodan
2025-09-01 19:47 ` [PATCH 01/10] dt-bindings: iio: accel: bosch,BMA220 improvements Petre Rodan
2025-09-02 5:57 ` Krzysztof Kozlowski
2025-09-02 16:02 ` Petre Rodan
2025-09-02 16:14 ` David Lechner
2025-09-02 19:22 ` Krzysztof Kozlowski
2025-09-01 19:47 ` [PATCH 02/10] iio: accel: BMA220 split original spi driver Petre Rodan
2025-09-01 19:47 ` [PATCH 03/10] iio: accel: BMA220 migrate to regmap API Petre Rodan
2025-09-01 19:47 ` [PATCH 04/10] iio: accel: BMA220 add i2c module Petre Rodan
2025-09-01 19:47 ` Petre Rodan [this message]
2025-09-01 19:47 ` [PATCH 06/10] iio: accel: BMA220 add LPF cut-off frequency mapping Petre Rodan
2025-09-01 19:47 ` [PATCH 07/10] iio: accel: BMA220 add debugfs reg access Petre Rodan
2025-09-01 19:47 ` [PATCH 08/10] iio: accel: BMA220 add events Petre Rodan
2025-09-01 19:47 ` [PATCH 09/10] iio: accel: BMA220 add event attrs Petre Rodan
2025-09-01 19:47 ` [PATCH 10/10] iio: accel: BMA220 add maintainer Petre Rodan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250901194742.11599-6-petre.rodan@subdimension.ro \
--to=petre.rodan@subdimension.ro \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).