Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2] iio: imu: bno055: Fix reset pin operation
@ 2026-12-04  8:48 Jochen Henneberg
  2026-12-04  9:25 ` Arnav Kapoor
  0 siblings, 1 reply; 3+ messages in thread
From: Jochen Henneberg @ 2026-12-04  8:48 UTC (permalink / raw)
  To: Arnav Kapoor, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Philipp Zabel, Maoyi Xie, Jochen Henneberg,
	Andrea Merello, linux-iio

The reset input is low-active and this is how the dt bindings example
configures it. However, the driver code treats it as high-active
because the gpio functions set the logical state not the physical
state.

Instead of using the gpio the driver now probes for a reset
controller.

Be aware that old devicetree workarounds using active-high
configuration for the reset gpio will not work anymore.

Fixes: 4aefe1c2bd0c ("iio: imu: add Bosch Sensortec BNO055 core driver")
Signed-off-by: Jochen Henneberg <jh@henneberg-systemdesign.com>
---
Changelog:
- Switch from plain reset gpio to reset controller
- Fixed typos in commit message
- Added 'Fixes' tag

 drivers/iio/imu/bno055/bno055.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/imu/bno055/bno055.c b/drivers/iio/imu/bno055/bno055.c
index c64c155db4f5..19624116a7d5 100644
--- a/drivers/iio/imu/bno055/bno055.c
+++ b/drivers/iio/imu/bno055/bno055.c
@@ -20,7 +20,7 @@
 #include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/firmware.h>
-#include <linux/gpio/consumer.h>
+#include <linux/reset.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/regmap.h>
@@ -208,7 +208,7 @@ struct bno055_priv {
 	int xfer_burst_break_thr;
 	struct mutex lock;
 	u8 uid[BNO055_UID_LEN];
-	struct gpio_desc *reset_gpio;
+	struct reset_control *reset;
 	bool sw_reset;
 	union {
 		IIO_DECLARE_BUFFER_WITH_TS(__le16, chans, BNO055_SCAN_CH_COUNT);
@@ -354,10 +354,10 @@ static int bno055_system_reset(struct bno055_priv *priv)
 {
 	int ret;
 
-	if (priv->reset_gpio) {
-		gpiod_set_value_cansleep(priv->reset_gpio, 0);
+	if (priv->reset) {
+		reset_control_assert(priv->reset);
 		usleep_range(5000, 10000);
-		gpiod_set_value_cansleep(priv->reset_gpio, 1);
+		reset_control_deassert(priv->reset);
 	} else if (priv->sw_reset) {
 		ret = regmap_write(priv->regmap, BNO055_SYS_TRIGGER_REG,
 				   BNO055_SYS_TRIGGER_RST_SYS);
@@ -1603,17 +1603,22 @@ int bno055_probe(struct device *dev, struct regmap *regmap,
 	priv->xfer_burst_break_thr = xfer_burst_break_thr;
 	priv->sw_reset = sw_reset;
 
-	priv->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
-	if (IS_ERR(priv->reset_gpio))
-		return dev_err_probe(dev, PTR_ERR(priv->reset_gpio), "Failed to get reset GPIO\n");
+	priv->reset = devm_reset_control_get_optional_exclusive(dev, NULL);
+	if (IS_ERR(priv->reset))
+		return dev_err_probe(dev, PTR_ERR(priv->reset),
+				     "Failed to get reset controller\n");
+	else if (!priv->reset)
+		dev_info(dev, "No reset controller, fallback to reset register\n");
+	else
+		dev_info(dev, "Using reset controller\n");
 
 	priv->clk = devm_clk_get_optional_enabled(dev, "clk");
 	if (IS_ERR(priv->clk))
 		return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to get CLK\n");
 
-	if (priv->reset_gpio) {
+	if (priv->reset) {
 		usleep_range(5000, 10000);
-		gpiod_set_value_cansleep(priv->reset_gpio, 1);
+		reset_control_deassert(priv->reset);
 		usleep_range(650000, 750000);
 	} else if (!sw_reset) {
 		dev_warn(dev, "No usable reset method; IMU may be unreliable\n");
@@ -1633,7 +1638,7 @@ int bno055_probe(struct device *dev, struct regmap *regmap,
 	 * we don't write to unknown chips), so we perform SW reset only after
 	 * chip magic ID check
 	 */
-	if (!priv->reset_gpio) {
+	if (!priv->reset) {
 		ret = bno055_system_reset(priv);
 		if (ret)
 			return ret;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04 10:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  8:48 [PATCH v2] iio: imu: bno055: Fix reset pin operation Jochen Henneberg
2026-12-04  9:25 ` Arnav Kapoor
2026-12-04 10:52   ` Jochen Henneberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox