Re: [PATCH v2 5/7] iio: adc: ad4170: Add GPIO controller support

Andy Shevchenko
2025-04-29T22:14:54Z

On Mon, Apr 28, 2025 at 3:29 PM Marcelo Schmitt
<marcelo.schmitt@analog.com> wrote:
>
> The AD4170 has four multifunctional pins that can be used as GPIOs. The
> GPIO functionality can be accessed when the AD4170 chip is not busy
> performing continuous data capture or handling any other register
> read/write request. Also, the AD4170 does not provide any interrupt based
> on GPIO pin states so AD4170 GPIOs can't be used as interrupt sources.
>
> Implement gpio_chip callbacks to make AD4170 GPIO pins controllable through
> the gpiochip interface.

...

> +static int ad4170_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
> +{
> + struct iio_dev *indio_dev = gpiochip_get_data(gc);
> + struct ad4170_state *st = iio_priv(indio_dev);
> + unsigned int val;
> + int ret;
> +
> + if (!iio_device_claim_direct(indio_dev))
> + return -EBUSY;
> +
> + guard(mutex)(&st->lock);
> + ret = regmap_read(st->regmap, AD4170_GPIO_MODE_REG, &val);
> + if (ret)
> + goto err_release;
> +
> + if (val & BIT(offset * 2 + 1))
> + ret = regmap_update_bits(st->regmap, AD4170_GPIO_OUTPUT_REG,
> + BIT(offset), value << offset);

Haven't you seen my previous review (v1)? I asked what if the value is > 1?
I also recommended looking at regmap_assign_bits().

> + else
> + ret = -EPERM;
> +
> +err_release:
> + iio_device_release_direct(indio_dev);
> + return ret;
> +}

--
With Best Regards,
Andy Shevchenko