iio: adc: ti-ads7924: Allow sleepable GPIO for reset
Subsystems (2)
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.
--- drivers/iio/adc/ti-ads7924.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ti-ads7924.c +2 -2
@@ -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
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.
--- drivers/iio/adc/ti-ads7924.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/iio/adc/ti-ads7924.c +5 -0
@@ -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
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")Signed-off-by Rickard x Andersson <[email protected]>---
Makes sense.
Signature · 2 lines
Kind regards, Joshua Crofts
PATCH 3/3 iio: adc: ti-ads7924: Use fsleep for reset pulse
In reply to Rickard AnderssonFrom: 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
@@ -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
Re: [PATCH 3/3] iio: adc: ti-ads7924: Use fsleep for reset pulse
Quoted 3 lines · Rickard Andersson
The reset pulse in
ads7924_resetis generated with mdelay, which busy-waits.ads7924_resetis 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
-1if (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
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_cansleepinstead.ads7924_resetis 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