[PATCH v3 05/10] iio: adc: ad7476: use *_cansleep GPIO APIs

Matti Vaittinen posted 10 patches 4 months, 1 week ago
There is a newer version of this series
[PATCH v3 05/10] iio: adc: ad7476: use *_cansleep GPIO APIs
Posted by Matti Vaittinen 4 months, 1 week ago
The ad7476 driver supports ADCs which require a GPIO pin to be used to
start conversion. The GPIO line status seems to be always toggled from
a process context, either from the user-initiated "raw-read conversion",
or from a threaded IRQ handler. Furthermore, these ICs are connected via
SPI bus, which is usually implemented in a way that the access to the
device can sleep. The GPIO here is toggled from the same context which
is reading the results over SPI.

Thus it seems very likely these GPIOs are toggled from a context which
can sleep.

Swap the gpiod_set_value() to gpiod_set_value_cansleep() accordinlgy.

Suggested-by: Nuno Sá <noname.nuno@gmail.com>
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>

---
Revision history:
 v2 => v3:
 - New patch
---
 drivers/iio/adc/ad7476.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
index fc701267358e..1445f0f599d9 100644
--- a/drivers/iio/adc/ad7476.c
+++ b/drivers/iio/adc/ad7476.c
@@ -57,9 +57,9 @@ static void ad7091_convst(struct ad7476_state *st)
 	if (!st->convst_gpio)
 		return;
 
-	gpiod_set_value(st->convst_gpio, 0);
+	gpiod_set_value_cansleep(st->convst_gpio, 0);
 	udelay(1); /* CONVST pulse width: 10 ns min */
-	gpiod_set_value(st->convst_gpio, 1);
+	gpiod_set_value_cansleep(st->convst_gpio, 1);
 	udelay(1); /* Conversion time: 650 ns max */
 }
 
-- 
2.50.1

Re: [PATCH v3 05/10] iio: adc: ad7476: use *_cansleep GPIO APIs
Posted by Nuno Sá 4 months, 1 week ago
On Fri, Aug 08, 2025 at 11:52:13AM +0300, Matti Vaittinen wrote:
> The ad7476 driver supports ADCs which require a GPIO pin to be used to
> start conversion. The GPIO line status seems to be always toggled from
> a process context, either from the user-initiated "raw-read conversion",
> or from a threaded IRQ handler. Furthermore, these ICs are connected via
> SPI bus, which is usually implemented in a way that the access to the
> device can sleep. The GPIO here is toggled from the same context which
> is reading the results over SPI.
> 
> Thus it seems very likely these GPIOs are toggled from a context which
> can sleep.
> 
> Swap the gpiod_set_value() to gpiod_set_value_cansleep() accordinlgy.
> 
> Suggested-by: Nuno Sá <noname.nuno@gmail.com>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> 
> ---
> Revision history:
>  v2 => v3:
>  - New patch
> ---

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

>  drivers/iio/adc/ad7476.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
> index fc701267358e..1445f0f599d9 100644
> --- a/drivers/iio/adc/ad7476.c
> +++ b/drivers/iio/adc/ad7476.c
> @@ -57,9 +57,9 @@ static void ad7091_convst(struct ad7476_state *st)
>  	if (!st->convst_gpio)
>  		return;
>  
> -	gpiod_set_value(st->convst_gpio, 0);
> +	gpiod_set_value_cansleep(st->convst_gpio, 0);
>  	udelay(1); /* CONVST pulse width: 10 ns min */
> -	gpiod_set_value(st->convst_gpio, 1);
> +	gpiod_set_value_cansleep(st->convst_gpio, 1);
>  	udelay(1); /* Conversion time: 650 ns max */
>  }
>  
> -- 
> 2.50.1
>