mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix hardware reset
@ 2026-12-04 12:14 Rickard Andersson
  2026-12-04 12:14 ` [PATCH v2 1/3] iio: adc: ti-ads7924: Wait after " Rickard Andersson
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Rickard Andersson @ 2026-12-04 12:14 UTC (permalink / raw)
  To: hvilleneuve, jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel
  Cc: rickard.andersson, kernel

From: Rickard x Andersson <rickard.andersson@axis.com>

Changes in v2:
- Replace "Allow sleepable GPIO for reset" with a conversion to the
  reset controller API, as suggested by Andy Shevchenko. The
  reset-gpio driver already uses the _cansleep() GPIO calls.
- Use msleep() instead of fsleep() for the 100 ms reset pulse
  (delays of 20 ms or more should use msleep()).
- Move "Wait after hardware reset" first, since it is a fix.
- Use func() notation in commit messages.
- Collect Reviewed-by from Joshua Crofts on patch 1.

Rickard x Andersson (3):
  iio: adc: ti-ads7924: Wait after hardware reset
  iio: adc: ti-ads7924: Use msleep() for reset pulse
  iio: adc: ti-ads7924: Use reset controller for hardware reset

 drivers/iio/adc/ti-ads7924.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

-- 
2.43.0


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

* [PATCH v2 1/3] iio: adc: ti-ads7924: Wait after hardware reset
  2026-12-04 12:14 [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix hardware reset Rickard Andersson
@ 2026-12-04 12:14 ` Rickard Andersson
  2026-12-04 17:00   ` Andy Shevchenko
  2026-12-04 12:14 ` [PATCH v2 2/3] iio: adc: ti-ads7924: Use msleep() for reset pulse Rickard Andersson
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Rickard Andersson @ 2026-12-04 12:14 UTC (permalink / raw)
  To: hvilleneuve, jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel
  Cc: rickard.andersson, kernel, Joshua Crofts

From: Rickard x Andersson <rickard.andersson@axis.com>

After the reset GPIO is deasserted, ads7924_reset() returns and the
driver immediately writes MODECNTRL. On a board where the reset line
is on an I2C GPIO expander (TCA6424), this first write fails:

  ads7924 2-0049: failed to set awake mode (-EIO)
  ads7924 2-0049: error -EIO: failed to set conversion mode

The device responds normally on the bus some time later. The
datasheet does not specify a startup time after reset, so wait
10 ms before the first register access.

Fixes: 4d82b2f98a25 ("iio: adc: ti-ads7924: add Texas Instruments ADS7924 driver")
Reviewed-by: Joshua Crofts <crofts@kernel.org>
Signed-off-by: Rickard x Andersson <rickard.andersson@axis.com>
---
 drivers/iio/adc/ti-ads7924.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/adc/ti-ads7924.c b/drivers/iio/adc/ti-ads7924.c
index ff30a52d2850..7b3fcfb98ae2 100644
--- a/drivers/iio/adc/ti-ads7924.c
+++ b/drivers/iio/adc/ti-ads7924.c
@@ -327,6 +327,11 @@ static int ads7924_reset(struct iio_dev *indio_dev)
 		/* Educated guess: assert time not specified in datasheet... */
 		mdelay(100);
 		gpiod_set_value(data->reset_gpio, 0); /* Deassert. */
+		/*
+		 * Startup time after reset is not specified in the datasheet.
+		 * Need to wait before the first register access on some systems.
+		 */
+		fsleep(10 * USEC_PER_MSEC);
 		return 0;
 	}
 
-- 
2.43.0


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

* [PATCH v2 2/3] iio: adc: ti-ads7924: Use msleep() for reset pulse
  2026-12-04 12:14 [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix hardware reset Rickard Andersson
  2026-12-04 12:14 ` [PATCH v2 1/3] iio: adc: ti-ads7924: Wait after " Rickard Andersson
@ 2026-12-04 12:14 ` Rickard Andersson
  2026-12-04 12:14 ` [PATCH v2 3/3] iio: adc: ti-ads7924: Use reset controller for hardware reset Rickard Andersson
  2026-12-06  1:05 ` [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix " Jonathan Cameron
  3 siblings, 0 replies; 8+ messages in thread
From: Rickard Andersson @ 2026-12-04 12:14 UTC (permalink / raw)
  To: hvilleneuve, jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel
  Cc: rickard.andersson, kernel

From: Rickard x Andersson <rickard.andersson@axis.com>

The reset pulse in ads7924_reset() is generated with mdelay(), which
busy-waits for 100 ms. ads7924_reset() is only called from
ads7924_probe(), which runs in process context, so sleeping is
allowed.

Replace mdelay() with msleep().

Signed-off-by: Rickard x Andersson <rickard.andersson@axis.com>
---
 drivers/iio/adc/ti-ads7924.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ti-ads7924.c b/drivers/iio/adc/ti-ads7924.c
index 7b3fcfb98ae2..c19441586b02 100644
--- a/drivers/iio/adc/ti-ads7924.c
+++ b/drivers/iio/adc/ti-ads7924.c
@@ -325,7 +325,7 @@ static int ads7924_reset(struct iio_dev *indio_dev)
 	if (data->reset_gpio) {
 		gpiod_set_value(data->reset_gpio, 1); /* Assert. */
 		/* Educated guess: assert time not specified in datasheet... */
-		mdelay(100);
+		msleep(100);
 		gpiod_set_value(data->reset_gpio, 0); /* Deassert. */
 		/*
 		 * Startup time after reset is not specified in the datasheet.
-- 
2.43.0


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

* [PATCH v2 3/3] iio: adc: ti-ads7924: Use reset controller for hardware reset
  2026-12-04 12:14 [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix hardware reset Rickard Andersson
  2026-12-04 12:14 ` [PATCH v2 1/3] iio: adc: ti-ads7924: Wait after " Rickard Andersson
  2026-12-04 12:14 ` [PATCH v2 2/3] iio: adc: ti-ads7924: Use msleep() for reset pulse Rickard Andersson
@ 2026-12-04 12:14 ` Rickard Andersson
  2026-12-04 17:02   ` Andy Shevchenko
  2026-12-06  1:05 ` [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix " Jonathan Cameron
  3 siblings, 1 reply; 8+ messages in thread
From: Rickard Andersson @ 2026-12-04 12:14 UTC (permalink / raw)
  To: hvilleneuve, jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel
  Cc: rickard.andersson, kernel

From: Rickard x Andersson <rickard.andersson@axis.com>

The reset GPIO may be provided by a controller that can sleep, such
as an I2C GPIO expander. ads7924_reset() toggles it with
gpiod_set_value(), which triggers WARN_ON(can_sleep) in gpiolib on
such systems.

Use the reset controller API instead because it can sleep.

Note that the hardware reset now requires CONFIG_RESET_GPIO. Without
it, the reset GPIO will be unused.

Signed-off-by: Rickard x Andersson <rickard.andersson@axis.com>
---
 drivers/iio/adc/ti-ads7924.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/adc/ti-ads7924.c b/drivers/iio/adc/ti-ads7924.c
index c19441586b02..e8a215df96ce 100644
--- a/drivers/iio/adc/ti-ads7924.c
+++ b/drivers/iio/adc/ti-ads7924.c
@@ -14,7 +14,6 @@
 #include <linux/bitfield.h>
 #include <linux/cleanup.h>
 #include <linux/delay.h>
-#include <linux/gpio/consumer.h>
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/i2c.h>
@@ -22,6 +21,7 @@
 #include <linux/mutex.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
+#include <linux/reset.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/types.h>
@@ -135,8 +135,8 @@ struct ads7924_data {
 	struct regmap *regmap;
 	struct regulator *vref_reg;
 
-	/* GPIO descriptor for device hard-reset pin. */
-	struct gpio_desc *reset_gpio;
+	/* Reset control for device hard-reset pin. */
+	struct reset_control *reset;
 
 	/*
 	 * Protects ADC ops, e.g: concurrent sysfs/buffered
@@ -321,12 +321,17 @@ static int ads7924_set_conv_mode(struct ads7924_data *data, int mode)
 static int ads7924_reset(struct iio_dev *indio_dev)
 {
 	struct ads7924_data *data = iio_priv(indio_dev);
+	int ret;
 
-	if (data->reset_gpio) {
-		gpiod_set_value(data->reset_gpio, 1); /* Assert. */
+	if (data->reset) {
+		ret = reset_control_assert(data->reset);
+		if (ret)
+			return ret;
 		/* Educated guess: assert time not specified in datasheet... */
 		msleep(100);
-		gpiod_set_value(data->reset_gpio, 0); /* Deassert. */
+		ret = reset_control_deassert(data->reset);
+		if (ret)
+			return ret;
 		/*
 		 * Startup time after reset is not specified in the datasheet.
 		 * Need to wait before the first register access on some systems.
@@ -367,11 +372,10 @@ static int ads7924_probe(struct i2c_client *client)
 
 	data->dev = dev;
 
-	/* Initialize the reset GPIO as output with an initial value of 0. */
-	data->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
-	if (IS_ERR(data->reset_gpio))
-		return dev_err_probe(dev, PTR_ERR(data->reset_gpio),
-				     "failed to get request reset GPIO\n");
+	data->reset = devm_reset_control_get_optional_exclusive(dev, NULL);
+	if (IS_ERR(data->reset))
+		return dev_err_probe(dev, PTR_ERR(data->reset),
+				     "failed to get reset control\n");
 
 	mutex_init(&data->lock);
 
-- 
2.43.0


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

* Re: [PATCH v2 1/3] iio: adc: ti-ads7924: Wait after hardware reset
  2026-12-04 12:14 ` [PATCH v2 1/3] iio: adc: ti-ads7924: Wait after " Rickard Andersson
@ 2026-12-04 17:00   ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-12-04 17:00 UTC (permalink / raw)
  To: Rickard Andersson
  Cc: hvilleneuve, jic23, dlechner, nuno.sa, andy, linux-iio,
	linux-kernel, kernel, Joshua Crofts

On Fri, Dec 04, 2026 at 01:14:56PM +0100, Rickard Andersson wrote:
> 
> After the reset GPIO is deasserted, ads7924_reset() returns and the
> driver immediately writes MODECNTRL. On a board where the reset line
> is on an I2C GPIO expander (TCA6424), this first write fails:
> 
>   ads7924 2-0049: failed to set awake mode (-EIO)
>   ads7924 2-0049: error -EIO: failed to set conversion mode
> 
> The device responds normally on the bus some time later. The
> datasheet does not specify a startup time after reset, so wait
> 10 ms before the first register access.

...

> +		/*
> +		 * Startup time after reset is not specified in the datasheet.
> +		 * Need to wait before the first register access on some systems.
> +		 */
> +		fsleep(10 * USEC_PER_MSEC);

msleep(10) is also okay (the usual threshold is 20 ms, though).
But the current approach is acceptable.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 3/3] iio: adc: ti-ads7924: Use reset controller for hardware reset
  2026-12-04 12:14 ` [PATCH v2 3/3] iio: adc: ti-ads7924: Use reset controller for hardware reset Rickard Andersson
@ 2026-12-04 17:02   ` Andy Shevchenko
  2026-12-06  1:02     ` Jonathan Cameron
  0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-12-04 17:02 UTC (permalink / raw)
  To: Rickard Andersson
  Cc: hvilleneuve, jic23, dlechner, nuno.sa, andy, linux-iio,
	linux-kernel, kernel

On Fri, Dec 04, 2026 at 01:14:58PM +0100, Rickard Andersson wrote:
> 
> The reset GPIO may be provided by a controller that can sleep, such
> as an I2C GPIO expander. ads7924_reset() toggles it with
> gpiod_set_value(), which triggers WARN_ON(can_sleep) in gpiolib on
> such systems.
> 
> Use the reset controller API instead because it can sleep.
> 
> Note that the hardware reset now requires CONFIG_RESET_GPIO. Without
> it, the reset GPIO will be unused.

Yeah, this rises the question about configuration and dependencies.
We need to work out the common approach in IIO for this type of conversions.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 3/3] iio: adc: ti-ads7924: Use reset controller for hardware reset
  2026-12-04 17:02   ` Andy Shevchenko
@ 2026-12-06  1:02     ` Jonathan Cameron
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2026-12-06  1:02 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Rickard Andersson, hvilleneuve, dlechner, nuno.sa, andy,
	linux-iio, linux-kernel, kernel

On Fri, 4 Dec 2026 19:02:03 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Fri, Dec 04, 2026 at 01:14:58PM +0100, Rickard Andersson wrote:
> > 
> > The reset GPIO may be provided by a controller that can sleep, such
> > as an I2C GPIO expander. ads7924_reset() toggles it with
> > gpiod_set_value(), which triggers WARN_ON(can_sleep) in gpiolib on
> > such systems.
> > 
> > Use the reset controller API instead because it can sleep.
> > 
> > Note that the hardware reset now requires CONFIG_RESET_GPIO. Without
> > it, the reset GPIO will be unused.  
> 
> Yeah, this rises the question about configuration and dependencies.
> We need to work out the common approach in IIO for this type of conversions.

Where we have a fallback to a software reset (like here) I'm not that
bothered. We tend to prefer hardware pin if available as it can for
some devices work when comms are lost, but in general hardware and
software triggered resets are near equivalents.

In other cases where it is the only way to reset then we probably have
to have the driver depend on it being available.

Jonathan



> 


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

* Re: [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix hardware reset
  2026-12-04 12:14 [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix hardware reset Rickard Andersson
                   ` (2 preceding siblings ...)
  2026-12-04 12:14 ` [PATCH v2 3/3] iio: adc: ti-ads7924: Use reset controller for hardware reset Rickard Andersson
@ 2026-12-06  1:05 ` Jonathan Cameron
  3 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2026-12-06  1:05 UTC (permalink / raw)
  To: Rickard Andersson
  Cc: hvilleneuve, dlechner, nuno.sa, andy, linux-iio, linux-kernel, kernel

On Fri, 4 Dec 2026 13:14:55 +0100
Rickard Andersson <rickard.andersson@axis.com> wrote:

> From: Rickard x Andersson <rickard.andersson@axis.com>
> 
> Changes in v2:
> - Replace "Allow sleepable GPIO for reset" with a conversion to the
>   reset controller API, as suggested by Andy Shevchenko. The
>   reset-gpio driver already uses the _cansleep() GPIO calls.
> - Use msleep() instead of fsleep() for the 100 ms reset pulse
>   (delays of 20 ms or more should use msleep()).
> - Move "Wait after hardware reset" first, since it is a fix.
> - Use func() notation in commit messages.
> - Collect Reviewed-by from Joshua Crofts on patch 1.

Given there is a software fallback, I'm not going to wait
for discussion around dependencies for patch 3 to resolve.

Applied to the testing branch of iio.git.

Thanks,

Jonathan

> 
> Rickard x Andersson (3):
>   iio: adc: ti-ads7924: Wait after hardware reset
>   iio: adc: ti-ads7924: Use msleep() for reset pulse
>   iio: adc: ti-ads7924: Use reset controller for hardware reset
> 
>  drivers/iio/adc/ti-ads7924.c | 33 +++++++++++++++++++++------------
>  1 file changed, 21 insertions(+), 12 deletions(-)
> 


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

end of thread, other threads:[~2026-12-06  1:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04 12:14 [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix hardware reset Rickard Andersson
2026-12-04 12:14 ` [PATCH v2 1/3] iio: adc: ti-ads7924: Wait after " Rickard Andersson
2026-12-04 17:00   ` Andy Shevchenko
2026-12-04 12:14 ` [PATCH v2 2/3] iio: adc: ti-ads7924: Use msleep() for reset pulse Rickard Andersson
2026-12-04 12:14 ` [PATCH v2 3/3] iio: adc: ti-ads7924: Use reset controller for hardware reset Rickard Andersson
2026-12-04 17:02   ` Andy Shevchenko
2026-12-06  1:02     ` Jonathan Cameron
2026-12-06  1:05 ` [PATCH v2 0/3] [PATCH v2 0/3] iio: adc: ti-ads7924: Fix " Jonathan Cameron

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

all inboxes | Powered by JetHome®