Skip to contentSkip to conversation

iio: adc: ti-ads7924: Allow sleepable GPIO for reset

PATCH In review Rickard Andersson 3 participants 6 messages Dec 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 iio: adc: ti-ads7924: Allow sleepable GPIO for reset

From: Rickard x Andersson <[email protected]>

The reset GPIO may be provided by a controller that can sleep, such as an I2C GPIO expander. On some systems this triggers a WARN_ON(can_sleep) stacktrace in gpiolib.

Use gpiod_set_value_cansleep instead. ads7924_reset is only called from probe function, so sleeping is allowed.

Fixes 4d82b2f98a25 ("iio: adc: ti-ads7924: add Texas Instruments ADS7924 driver")
---
 drivers/iio/adc/ti-ads7924.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ti-ads7924.c +2 -2
index ff30a52d2850..b357f131018c 100644
@@ -323,10 +323,10 @@ static int ads7924_reset(struct iio_dev *indio_dev)
 	struct ads7924_data *data = iio_priv(indio_dev);
 
 	if (data->reset_gpio) {
-		gpiod_set_value(data->reset_gpio, 1); /* Assert. */
+		gpiod_set_value_cansleep(data->reset_gpio, 1); /* Assert. */
 		/* Educated guess: assert time not specified in datasheet... */
 		mdelay(100);
-		gpiod_set_value(data->reset_gpio, 0); /* Deassert. */
+		gpiod_set_value_cansleep(data->reset_gpio, 0); /* Deassert. */
 		return 0;
 	}
 
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/3 iio: adc: ti-ads7924: Wait after hardware reset

From: Rickard x Andersson <[email protected]>

After the reset GPIO is deasserted, 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")
---
 drivers/iio/adc/ti-ads7924.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iio/adc/ti-ads7924.c +5 -0
index b357f131018c..82700cb4e932 100644
@@ -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_cansleep(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;
 	}
 
Signature · 1 line
2.43.0
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] iio: adc: ti-ads7924: Wait after hardware reset

Quoted 9 lines · Rickard Andersson

From: Rickard x Andersson <[email protected]>

After the reset GPIO is deasserted, 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

Quoted 7 lines

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")

---

Makes sense.

Signature · 2 lines
Kind regards,
Joshua Crofts
#3 lore raw

PATCH 3/3 iio: adc: ti-ads7924: Use fsleep for reset pulse

In reply to Rickard Andersson

From: Rickard x Andersson <[email protected]>

The reset pulse in ads7924_reset is generated with mdelay, which busy-waits. ads7924_reset is only called from probe, which runs in process context, so sleeping is allowed.

Replace mdelay with fsleep to make whole reset function being able to sleep.

---
 drivers/iio/adc/ti-ads7924.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ti-ads7924.c +1 -1
index 82700cb4e932..8d23b15a384c 100644
@@ -325,7 +325,7 @@ static int ads7924_reset(struct iio_dev *indio_dev)
 	if (data->reset_gpio) {
 		gpiod_set_value_cansleep(data->reset_gpio, 1); /* Assert. */
 		/* Educated guess: assert time not specified in datasheet... */
-		mdelay(100);
+		fsleep(100 * USEC_PER_MSEC);
 		gpiod_set_value_cansleep(data->reset_gpio, 0); /* Deassert. */
 		/*
 		 * Startup time after reset is not specified in the datasheet.
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH 3/3] iio: adc: ti-ads7924: Use fsleep for reset pulse

Quoted 3 lines · Rickard Andersson

The reset pulse in ads7924_reset is generated with mdelay, which busy-waits. ads7924_reset is only called from probe,

In all your commit messages please refer to the functions as func(). Exempli gratia, mdelay(), ads7924_reset().

Quoted 4 lines

which runs in process context, so sleeping is allowed.

Replace mdelay with fsleep to make whole reset function being able to sleep.

...

drivers/iio/adc/ti-ads7924.c static int ads7924_reset(struct iio_dev *indio_dev) · line 329

Quoted 6 lines
drivers/iio/adc/ti-ads7924.c +1 -1
 	if (data->reset_gpio) {
 		gpiod_set_value_cansleep(data->reset_gpio, 1); /* Assert. */
 		/* Educated guess: assert time not specified in datasheet... */
-		mdelay(100);
+		fsleep(100 * USEC_PER_MSEC);
 		gpiod_set_value_cansleep(data->reset_gpio, 0); /* Deassert. */

When such a long delay (usually >= 20ms) in in place we use msleep() directly.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
In reply to Rickard Andersson
Quoted 7 lines · Rickard Andersson

The reset GPIO may be provided by a controller that can sleep, such as an I2C GPIO expander. On some systems this triggers a WARN_ON(can_sleep) stacktrace in gpiolib.

Use gpiod_set_value_cansleep instead. ads7924_reset is only called from probe function, so sleeping is allowed.

Can we switch to use reset-gpio driver and hence reset APIs here? It would be a better fix in my opinion.

Signature · 2 lines
With Best Regards,
Andy Shevchenko