Re: [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices

From: Bartosz Golaszewski

Date: Tue Dec 01 2026 - 08:27:57 EST


On Tue, Dec 01, 2026 at 10:57:40AM +0100, Philipp Zabel wrote:
> Cc: Linus, Bartosz
>
> On So, 2026-11-29 at 00:58 +0800, Pufan Jin wrote:
> > In __reset_add_reset_gpio_device(), when parsing GPIO arguments from
> > firmware nodes, the code assigns:
> > offset = args->args[0];
> > flags = args->args[1];
> >
> > However, this assumes a direct mapping between the devicetree GPIO
> > specifier argument and the driver's internal GPIO chip pin offset. While
> > this holds for controllers using the standard simple 2-cell binding,
> > it fails on GPIO controllers that implement a custom of_xlate() callback
> > (such as Tegra's tegra186-gpio, where GPIOs are addressed as
> > TEGRA186_MAIN_GPIO(port, pin)).
> >
> > This leads to two issues on such platforms:
> > 1. Wrong pin assignment or lookup failure: Since args->args[0] is not
> > translated through chip->of_xlate, the GPIO hardware offset passed to
> > PROPERTY_ENTRY_GPIO() does not match the chip-relative pin offset,
> > causing the driver to request the wrong GPIO pin or fail with -EINVAL.
> > 2. Unparsed or corrupted flags: Devicetree GPIO flags are not parsed
> > through chip->of_xlate(), preventing drivers from translating or
> > validating custom cell flags.
> >
> > Fix this by looking up the gpio_device from args->fwnode earlier,
> > retrieving its gpio_chip, and invoking chip->of_xlate() when the node is
> > an OF node. The resulting translated hardware offset and flags are then
> > used for subsequent reset-gpio device registration.
> >
> > Fixes: c721f189e89c ("reset: Instantiate reset GPIO controller for shared reset-gpios")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Pufan Jin <cyan2254650260@xxxxxxxxx>
> > ---
> > drivers/reset/core.c | 35 ++++++++++++++++++++++++++++++-----
> > 1 file changed, 30 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> > index 1ae7ca1e8..ce524820b 100644
> > --- a/drivers/reset/core.c
> > +++ b/drivers/reset/core.c
> > @@ -1072,6 +1072,36 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
> > offset = args->args[0];
> > flags = args->args[1];
> >
> > + struct gpio_device *gdev __free(gpio_device_put) =
> > + gpio_device_find_by_fwnode(args->fwnode);
> > + if (!gdev)
> > + return -EPROBE_DEFER;
> > +
> > +#if IS_ENABLED(CONFIG_OF_GPIO)
> > + if (is_of_node(args->fwnode)) {
> > + struct gpio_chip *chip = gpio_device_get_chip(gdev);
> > +
> > + if (chip && chip->of_xlate) {
>
> Please, not more poking into gpiolib-of internals.
>
> This should be a function in gpiolib and also address the TODO above
> (#gpio-cells > 2) and the FIXME below (GPIO flag matching).
>

TBH I don't see much "poking" into GPIOLIB internals in existing code in
reset/core.c. This however is awful, I agree. gpio_device_get_chip() is
also deprecated and must not be used in new code.

I'm open to having a dedicated interface in GPIOLIB for such cases.

Bartosz