Re: [PATCH v4 12/17] iio: adc: ad7768-1: Add GPIO controller support

From: Marcelo Schmitt
Date: Fri Apr 04 2025 - 17:11:33 EST


Hey Jonathan,

The AD7768-1 GPIO controller support looks good to me.
Besides reviewing it, I've also inspired on your patch to implement GPIO
controller support for AD4170. I have one inline suggestion, though.

With that sorted out
Reviewed-by: Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx>

Thanks,
Marcelo

On 03/06, Jonathan Santos wrote:
> From: Sergiu Cuciurean <sergiu.cuciurean@xxxxxxxxxx>
>
> The AD7768-1 has the ability to control other local hardware (such as gain
> stages),to power down other blocks in the signal chain, or read local
> status signals over the SPI interface.
>
> Add direct mode conditional locks in the gpio callbacks to prevent register
> access when the device is in buffered mode.
>
> This change exports the AD7768-1's four gpios and makes them accessible
> at an upper layer.
>
> Reviewed-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@xxxxxxxxxx>
> Co-developed-by: Jonathan Santos <Jonathan.Santos@xxxxxxxxxx>
> Signed-off-by: Jonathan Santos <Jonathan.Santos@xxxxxxxxxx>
> ---
...
> ---
> drivers/iio/adc/ad7768-1.c | 143 ++++++++++++++++++++++++++++++++++++-
> 1 file changed, 141 insertions(+), 2 deletions(-)
>
...
> +static int ad7768_gpio_init(struct iio_dev *indio_dev)
> +{
> + struct ad7768_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + ret = regmap_write(st->regmap, AD7768_REG_GPIO_CONTROL,
> + AD7768_GPIO_UNIVERSAL_EN);
> + if (ret)
> + return ret;
> +
> + st->gpiochip = (struct gpio_chip) {
> + .label = "ad7768_1_gpios",
> + .base = -1,
> + .ngpio = 4,
> + .parent = &st->spi->dev,
> + .can_sleep = true,
> + .direction_input = ad7768_gpio_direction_input,
> + .direction_output = ad7768_gpio_direction_output,
> + .get = ad7768_gpio_get,
> + .set = ad7768_gpio_set,
> + .owner = THIS_MODULE,
> + };
> +
> + return gpiochip_add_data(&st->gpiochip, indio_dev);
Use devm_gpiochip_add_data(), otherwise the gpiochip is not removed on device
detach.

> +}
> +