* [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices
@ 2026-11-28 16:58 Pufan Jin
2026-12-01 9:57 ` Philipp Zabel
0 siblings, 1 reply; 5+ messages in thread
From: Pufan Jin @ 2026-11-28 16:58 UTC (permalink / raw)
To: Philipp Zabel; +Cc: linux-kernel, stable
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) {
+ 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) {
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices
2026-11-28 16:58 [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices Pufan Jin
@ 2026-12-01 9:57 ` Philipp Zabel
2026-12-01 13:27 ` Bartosz Golaszewski
0 siblings, 1 reply; 5+ messages in thread
From: Philipp Zabel @ 2026-12-01 9:57 UTC (permalink / raw)
To: Pufan Jin; +Cc: linux-kernel, stable, Linus Walleij, Bartosz Golaszewski
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices
2026-12-01 9:57 ` Philipp Zabel
@ 2026-12-01 13:27 ` Bartosz Golaszewski
2026-12-01 13:49 ` Philipp Zabel
0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-12-01 13:27 UTC (permalink / raw)
To: Philipp Zabel; +Cc: Pufan Jin, linux-kernel, stable, Linus Walleij
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@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).
>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices
2026-12-01 13:27 ` Bartosz Golaszewski
@ 2026-12-01 13:49 ` Philipp Zabel
2026-12-02 8:08 ` Pufan Jin
0 siblings, 1 reply; 5+ messages in thread
From: Philipp Zabel @ 2026-12-01 13:49 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: Pufan Jin, linux-kernel, stable, Linus Walleij
On Di, 2026-12-01 at 14:27 +0100, Bartosz Golaszewski wrote:
> 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@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).
> >
>
> TBH I don't see much "poking" into GPIOLIB internals in existing code in
> reset/core.c.
Sorry, the "more" part was hyberbole.
What we are currently doing in reset/core.c is not so much "poking" as
partially reimplementing GPIO phandle parsing.
regards
Philipp
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices
2026-12-01 13:49 ` Philipp Zabel
@ 2026-12-02 8:08 ` Pufan Jin
0 siblings, 0 replies; 5+ messages in thread
From: Pufan Jin @ 2026-12-02 8:08 UTC (permalink / raw)
To: Philipp Zabel, Bartosz Golaszewski; +Cc: linux-kernel, stable, Linus Walleij
On 12/1/26 9:49 PM, Philipp Zabel wrote:
> On Di, 2026-12-01 at 14:27 +0100, Bartosz Golaszewski wrote:
>> 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@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).
>>>
>> TBH I don't see much "poking" into GPIOLIB internals in existing code in
>> reset/core.c.
> Sorry, the "more" part was hyberbole.
>
> What we are currently doing in reset/core.c is not so much "poking" as
> partially reimplementing GPIO phandle parsing.
>
> regards
> Philipp
Hi Philipp, Bartosz,
Thanks for the review and feedback.
Agreed -- calling the deprecated gpio_device_get_chip() and invoking
chip->of_xlate() directly in drivers/reset/core.c is not the
right approach.
Before I prepare a v2 series, I would like to check what GPIOLIB
interface design you would prefer for this use case.
Looking at what __reset_add_reset_gpio_device() needs from a parsed
struct fwnode_reference_args *args:
1. The target struct gpio_device * (to set the reset-gpio auxiliary
device's parent via gpio_device_to_device() and obtain parent->fwnode
for PROPERTY_ENTRY_GPIO()).
2. The chip-relative hardware GPIO offset (unsigned int *offset).
3. The translated Linux lookup flags (unsigned long *lflags, using
enum gpio_lookup_flags for PROPERTY_ENTRY_GPIO()).
Would an interface along these lines in gpiolib make sense?
struct gpio_device *
gpio_device_find_by_fwnode_args(const struct fwnode_reference_args *args,
unsigned int *offset,
unsigned long *lflags);
Inside gpiolib (with kernel-doc in drivers/gpio/gpiolib.c and prototype
in include/linux/gpio/driver.h):
- For OF nodes (is_of_node(args->fwnode)):
Convert args to struct of_phandle_args, look up the matching
gpio_device via of_find_gpio_device_by_xlate() (which handles
custom of_xlate() and arbitrary #gpio-cells cleanly), invoke
gc->of_xlate() safely under guard(srcu)(&gdev->srcu) and
srcu_dereference(gdev->chip, &gdev->srcu), and convert the resulting
of_gpio_flags to Linux lookup flags via of_convert_gpio_flags().
This eliminates both the #gpio-cells == 2 restriction (TODO) and the
manual flag matching (FIXME) in drivers/reset/core.c.
- For software nodes (is_software_node(args->fwnode)):
Look up via gpio_device_find_by_fwnode(args->fwnode) and extract
args->args[0] / args->args[1] (with nargs == 2 validation).
- Return ERR_PTR(-EPROBE_DEFER) if no matching gpio_device is
registered yet, or the corresponding negative errno on invalid args.
Two related details I noticed while checking the surrounding code:
1. In drivers/reset/reset-gpio.c, reset_gpio_probe() hardcodes
priv->rc.fwnode_reset_n_cells = 2, which would trigger
WARN_ON(args.nargs != rcdev->fwnode_reset_n_cells) in
__fwnode_reset_control_get() once #gpio-cells != 2 is supported.
Since drivers/reset/core.c already passes &rgpio_dev->ref_args via
adev->dev.platform_data, reset_gpio_probe() can read nargs from
platform_data.
2. In drivers/gpio/gpiolib-shared.c, gpio_shared_dev_is_reset_gpio()
compares ref_args.args[0] from the DT consumer (pre-xlate)
against aux_args.args[0] from the reset-gpio swnode (post-xlate if
translated here), and assumes 2 args. If a shared reset-gpios uses a
custom of_xlate() like tegra186-gpio, that comparison would mismatch
(though that can be tracked/handled separately if appropriate).
Bartosz, Philipp: does this API shape (name, signature, and header
placement) look reasonable to you, or would you prefer a different
naming or design?
Best regards,
Pufan Jin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-02 8:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 16:58 [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices Pufan Jin
2026-12-01 9:57 ` Philipp Zabel
2026-12-01 13:27 ` Bartosz Golaszewski
2026-12-01 13:49 ` Philipp Zabel
2026-12-02 8:08 ` Pufan Jin
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®