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

* Re: [PATCH v2] iio: imu: bno055: Fix reset pin operation
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Arnav Kapoor @ 2026-12-04  9:25 UTC (permalink / raw)
  To: Jochen Henneberg
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Philipp Zabel, Maoyi Xie, Andrea Merello, linux-iio

On Fri, Dec 04, 2026 at 09:48:43AM +0100, Jochen Henneberg wrote:
> 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.

Thanks for the respin. The logic looks right to me now: reset-gpio
requests the line asserted, probe deasserts it after 5-10 ms, and
bno055_system_reset() asserts then deasserts. It applies to
iio/testing, and checkpatch --strict and a W=1 build are clean.

Some comments:

- The DT still describes the line as reset-gpios, so it now only works
  when CONFIG_RESET_GPIO is enabled (see my reply to your question on
  v1). Please say that in the commit message. It would also help to
  say why the driver switches to the reset API (Andy's request) rather
  than only flipping the values.

- Fixes: and stable. The reset-gpio driver only exists since v6.9
  (cee544a40e44), but the bno055 driver is in v6.1. If this goes to
  6.1 or 6.6 stable as is, the reset is silently lost there. One option
  is a 2-patch series: your v1 polarity fix with the Fixes: tag first,
  then the conversion to the reset API without it. Jonathan may prefer
  something else, though.

> +#include <linux/reset.h>
>  #include <linux/module.h>

Please keep the includes sorted: this goes after linux/regmap.h.

> +	else if (!priv->reset)
> +		dev_info(dev, "No reset controller, fallback to reset register\n");
> +	else
> +		dev_info(dev, "Using reset controller\n");

I'd drop these two messages (or make them dev_dbg()). The driver
already warns when there is no usable reset method at all, and
otherwise a successful probe shouldn't need to print anything.

Thanks,
Arnav

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

* Re: [PATCH v2] iio: imu: bno055: Fix reset pin operation
  2026-12-04  9:25 ` Arnav Kapoor
@ 2026-12-04 10:52   ` Jochen Henneberg
  0 siblings, 0 replies; 3+ messages in thread
From: Jochen Henneberg @ 2026-12-04 10:52 UTC (permalink / raw)
  To: Arnav Kapoor
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Philipp Zabel, Maoyi Xie, Andrea Merello, linux-iio

Thanks for the quick feedback,

> On Fri, Dec 04, 2026 at 09:48:43AM +0100, Jochen Henneberg wrote:
>> 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.
>
> Thanks for the respin. The logic looks right to me now: reset-gpio
> requests the line asserted, probe deasserts it after 5-10 ms, and
> bno055_system_reset() asserts then deasserts. It applies to
> iio/testing, and checkpatch --strict and a W=1 build are clean.
>
> Some comments:
>
> - The DT still describes the line as reset-gpios, so it now only works
>   when CONFIG_RESET_GPIO is enabled (see my reply to your question on
>   v1). Please say that in the commit message. It would also help to
>   say why the driver switches to the reset API (Andy's request) rather
>   than only flipping the values.

Would it make sense to also leave a note in the bindings description
that the gpio is used by a reset controller? Because then it's obvious
that a reference to a reset controller would also work. Or maybe add
such an example to the bindings?

>
> - Fixes: and stable. The reset-gpio driver only exists since v6.9
>   (cee544a40e44), but the bno055 driver is in v6.1. If this goes to
>   6.1 or 6.6 stable as is, the reset is silently lost there. One option
>   is a 2-patch series: your v1 polarity fix with the Fixes: tag first,
>   then the conversion to the reset API without it. Jonathan may prefer
>   something else, though.

Will wait for further feedback then.

>
>> +#include <linux/reset.h>
>>  #include <linux/module.h>
>
> Please keep the includes sorted: this goes after linux/regmap.h.
>
>> +	else if (!priv->reset)
>> + dev_info(dev, "No reset controller, fallback to reset
>> register\n");
>> +	else
>> +		dev_info(dev, "Using reset controller\n");
>
> I'd drop these two messages (or make them dev_dbg()). The driver
> already warns when there is no usable reset method at all, and
> otherwise a successful probe shouldn't need to print anything.

I prepared the requested changes for the next version. I dropped the
messages, I wanted to remove them anyway, just used them to get an
explicit feedback during testing.

Regards
-Jochen

^ permalink raw reply	[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