mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Philipp Zabel <p.zabel@pengutronix.de>
To: Pufan Jin <cyan2254650260@gmail.com>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>
Subject: Re: [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices
Date: Tue, 01 Dec 2026 10:57:40 +0100	[thread overview]
Message-ID: <63bac83829bb0662340d044a19e4d79cb457a9f6.camel@pengutronix.de> (raw)
In-Reply-To: <20261128165814.740455-1-cyan2254650260@gmail.com>

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@vger.kernel.org
> Signed-off-by: Pufan Jin <cyan2254650260@gmail.com>
> ---
>  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).

> +			struct of_phandle_args of_args;
> +			u32 of_flags = flags;
> +			unsigned int i;
> +			int xlate_ret;
> +
> +			of_args.np = to_of_node(args->fwnode);
> +			of_args.args_count = args->nargs;
> +			for (i = 0; i < args->nargs; i++)
> +				of_args.args[i] = args->args[i];
> +
> +			xlate_ret = chip->of_xlate(chip, &of_args, &of_flags);
> +			if (xlate_ret < 0)
> +				return xlate_ret;
> +
> +			offset = xlate_ret;
> +			flags = of_flags;
> +		}
> +	}
> +#endif
> +
>  	/*
>  	 * Later we map GPIO flags between OF and Linux, however not all
>  	 * constants from include/dt-bindings/gpio/gpio.h and
> @@ -1086,11 +1116,6 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
>  		return -EINVAL;
>  	}
>  
> -	struct gpio_device *gdev __free(gpio_device_put) =
> -			gpio_device_find_by_fwnode(args->fwnode);
> -	if (!gdev)
> -		return -EPROBE_DEFER;
> -
>  	guard(mutex)(&reset_gpio_lookup_mutex);
>  
>  	list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) {

regards
Philipp

  reply	other threads:[~2026-12-01  9:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 16:58 Pufan Jin
2026-12-01  9:57 ` Philipp Zabel [this message]
2026-12-01 13:27   ` Bartosz Golaszewski
2026-12-01 13:49     ` Philipp Zabel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=63bac83829bb0662340d044a19e4d79cb457a9f6.camel@pengutronix.de \
    --to=p.zabel@pengutronix.de \
    --cc=brgl@kernel.org \
    --cc=cyan2254650260@gmail.com \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®