diff mbox series

[2/2] iio: adc: ad4130: only set GPIO_CTRL if pin is unused

Message ID 20240207132007.253768-2-demonsingur@gmail.com (mailing list archive)
State Accepted
Headers show
Series [1/2] iio: adc: ad4130: zero-initialize clock init data | expand

Commit Message

Cosmin Tanislav Feb. 7, 2024, 1:20 p.m. UTC
Currently, GPIO_CTRL bits are set even if the pins are used for
measurements.

GPIO_CTRL bits should only be set if the pin is not used for
other functionality.

Fix this by only setting the GPIO_CTRL bits if the pin has no
other function.

Fixes: 62094060cf3a ("iio: adc: ad4130: add AD4130 driver")
Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com>
---
 drivers/iio/adc/ad4130.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Nuno Sá Feb. 8, 2024, 8:16 a.m. UTC | #1
On Wed, 2024-02-07 at 15:20 +0200, Cosmin Tanislav wrote:
> Currently, GPIO_CTRL bits are set even if the pins are used for
> measurements.
> 
> GPIO_CTRL bits should only be set if the pin is not used for
> other functionality.
> 
> Fix this by only setting the GPIO_CTRL bits if the pin has no
> other function.
> 
> Fixes: 62094060cf3a ("iio: adc: ad4130: add AD4130 driver")
> Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com>
> ---

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

>  drivers/iio/adc/ad4130.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad4130.c b/drivers/iio/adc/ad4130.c
> index c7df499f9775..febb64e67955 100644
> --- a/drivers/iio/adc/ad4130.c
> +++ b/drivers/iio/adc/ad4130.c
> @@ -1864,10 +1864,14 @@ static int ad4130_setup(struct iio_dev *indio_dev)
>  		return ret;
>  
>  	/*
> -	 * Configure all GPIOs for output. If configured, the interrupt
> function
> -	 * of P2 takes priority over the GPIO out function.
> +	 * Configure unused GPIOs for output. If configured, the interrupt
> +	 * function of P2 takes priority over the GPIO out function.
>  	 */
> -	val =  AD4130_IO_CONTROL_GPIO_CTRL_MASK;
> +	val = 0;
> +	for (i = 0; i < AD4130_MAX_GPIOS; i++)
> +		if (st->pins_fn[i + AD4130_AIN2_P1] == AD4130_PIN_FN_NONE)
> +			val |= FIELD_PREP(AD4130_IO_CONTROL_GPIO_CTRL_MASK,
> BIT(i));
> +
>  	val |= FIELD_PREP(AD4130_IO_CONTROL_INT_PIN_SEL_MASK, st-
> >int_pin_sel);
>  
>  	ret = regmap_write(st->regmap, AD4130_IO_CONTROL_REG, val);
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad4130.c b/drivers/iio/adc/ad4130.c
index c7df499f9775..febb64e67955 100644
--- a/drivers/iio/adc/ad4130.c
+++ b/drivers/iio/adc/ad4130.c
@@ -1864,10 +1864,14 @@  static int ad4130_setup(struct iio_dev *indio_dev)
 		return ret;
 
 	/*
-	 * Configure all GPIOs for output. If configured, the interrupt function
-	 * of P2 takes priority over the GPIO out function.
+	 * Configure unused GPIOs for output. If configured, the interrupt
+	 * function of P2 takes priority over the GPIO out function.
 	 */
-	val =  AD4130_IO_CONTROL_GPIO_CTRL_MASK;
+	val = 0;
+	for (i = 0; i < AD4130_MAX_GPIOS; i++)
+		if (st->pins_fn[i + AD4130_AIN2_P1] == AD4130_PIN_FN_NONE)
+			val |= FIELD_PREP(AD4130_IO_CONTROL_GPIO_CTRL_MASK, BIT(i));
+
 	val |= FIELD_PREP(AD4130_IO_CONTROL_INT_PIN_SEL_MASK, st->int_pin_sel);
 
 	ret = regmap_write(st->regmap, AD4130_IO_CONTROL_REG, val);