[PATCH v2 5/5] reset: core: translate GPIO specifier via gpio_device_find_by_fwnode_args()

From: Pufan Jin

Date: Sat Dec 05 2026 - 01:44:34 EST


__reset_add_reset_gpio_device() reads the GPIO offset and flags from
args->args[0] and args->args[1], rejecting args->nargs != 2 and
flags > GPIO_ACTIVE_LOW.

This fails on devicetree GPIO controllers with a custom of_xlate()
callback such as tegra186-gpio. It also rejects devicetree controllers
with #gpio-cells != 2 and does not translate other devicetree GPIO
flags such as open-drain or transitory.

Use gpio_device_find_by_fwnode_args() to resolve the gpio_device,
hardware offset, and lookup flags. This removes the #gpio-cells == 2
restriction for devicetree providers and the flag check in
drivers/reset/core.c. Software node references remain 2-cell per
swnode_gpio_get_reference() and return -EINVAL instead of -ENOENT when
nargs != 2.

Fixes: c721f189e89c ("reset: Instantiate reset GPIO controller for shared reset-gpios")
Signed-off-by: Pufan Jin <cyan2254650260@xxxxxxxxx>
---
drivers/reset/core.c | 37 +++++--------------------------------
1 file changed, 5 insertions(+), 32 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 1ae7ca1e85..35e0050f7e 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -14,7 +14,6 @@
#include <linux/export.h>
#include <linux/fwnode.h>
#include <linux/gpio/driver.h>
-#include <linux/gpio/machine.h>
#include <linux/gpio/property.h>
#include <linux/idr.h>
#include <linux/kernel.h>
@@ -1048,20 +1047,12 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
const struct fwnode_reference_args *args)
{
struct property_entry properties[3] = { };
- unsigned int offset, flags, lflags;
struct reset_gpio_lookup *rgpio_dev;
+ unsigned long lflags;
struct device *parent;
+ unsigned int offset;
int ret, prop = 0;

- /*
- * Currently only #gpio-cells=2 is supported with the meaning of:
- * args[0]: GPIO number
- * args[1]: GPIO flags
- * TODO: Handle other cases.
- */
- if (args->nargs != 2)
- return -ENOENT;
-
/*
* Registering reset-gpio device might cause immediate
* bind, resulting in its probe() registering new reset controller thus
@@ -1069,27 +1060,10 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
*/
lockdep_assert_not_held(&reset_list_mutex);

- offset = args->args[0];
- flags = args->args[1];
-
- /*
- * Later we map GPIO flags between OF and Linux, however not all
- * constants from include/dt-bindings/gpio/gpio.h and
- * include/linux/gpio/machine.h match each other.
- *
- * FIXME: Find a better way of translating OF flags to GPIO lookup
- * flags.
- */
- if (flags > GPIO_ACTIVE_LOW) {
- pr_err("reset-gpio code does not support GPIO flags %u for GPIO %u\n",
- flags, offset);
- return -EINVAL;
- }
-
struct gpio_device *gdev __free(gpio_device_put) =
- gpio_device_find_by_fwnode(args->fwnode);
- if (!gdev)
- return -EPROBE_DEFER;
+ gpio_device_find_by_fwnode_args(args, &offset, &lflags);
+ if (IS_ERR(gdev))
+ return PTR_ERR(gdev);

guard(mutex)(&reset_gpio_lookup_mutex);

@@ -1104,7 +1078,6 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
}
}

- lflags = GPIO_PERSISTENT | (flags & GPIO_ACTIVE_LOW);
parent = gpio_device_to_device(gdev);
properties[prop++] = PROPERTY_ENTRY_STRING("compatible", "reset-gpio");
properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags);
--
2.56.1