Re: [PATCH 5/6] gpio: ad7768: Add AD7768 GPIO auxiliary driver

From: Linus Walleij

Date: Fri Jul 10 2026 - 16:07:06 EST


Hi Janani,

thanks for your patch!

On Thu, Jul 9, 2026 at 10:51 AM Janani Sunil <janani.sunil@xxxxxxxxxx> wrote:

> The AD7768/AD7768-4 ADC exposes 5 general-purpose I/O pins that can be
> independently configured as inputs or outputs. Add an auxiliary bus driver
> to expose these pins as a GPIO chip, registered by the parent IIO driver.
>
> The driver uses the parent's regmap for register access and delegates
> runtime power management to the parent device.
>
> Signed-off-by: Janani Sunil <janani.sunil@xxxxxxxxxx>

(...)

When I look at these functions I see they are very close to something
the GPIO_REGMAP helpers should be able to do.

Bascically all that stops you from doing this is:

> +static int ad7768_gpio_direction_input(struct gpio_chip *chip,
> + unsigned int offset)
> +{
> + struct ad7768_gpio_state *st = gpiochip_get_data(chip);
> +
> + PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(st->parent, pm);
> + int ret = PM_RUNTIME_ACQUIRE_ERR(&pm);

These two things.

> +static int ad7768_gpio_get_direction(struct gpio_chip *chip,
> + unsigned int offset)
> +{
> + struct ad7768_gpio_state *st = gpiochip_get_data(chip);
> + unsigned int val;
> + int ret;
> +
> + PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(st->parent, pm);
> + ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
> + if (ret)
> + return ret;

Here again, etc.

Can't we just add a

struct device *pm_dev; to struct gpio_regmap_config, pass
st->parent there at init, modify drivers/gpio/gpio-regmap.c adding:

static int gpio_regmap_pm(struct gpio_regmap *gpio)
{
PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(gpio->pm_device, pm);
ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
if (ret)
return ret;
return 0;
}

And call this in each of the standard callbacks so gpio-regmap.c
can handle PM as well for free? The above can be an ifdef stub if
runtime PM is not enabled.

Yours,
Linus Walleij