From: Pufan Jin <cyan2254650260@gmail.com>
To: Bartosz Golaszewski <brgl@kernel.org>,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Linus Walleij <linusw@kernel.org>,
Philipp Zabel <p.zabel@pengutronix.de>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 5/5] reset: core: translate GPIO specifier via gpio_device_find_by_fwnode_args()
Date: Sat, 5 Dec 2026 14:43:55 +0800 [thread overview]
Message-ID: <20261205064355.137581-6-cyan2254650260@gmail.com> (raw)
In-Reply-To: <20261205064355.137581-1-cyan2254650260@gmail.com>
__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@gmail.com>
---
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
prev parent reply other threads:[~2026-12-05 6:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 6:43 [PATCH v2 0/5] gpiolib / reset: resolve GPIO specifiers via gpiolib Pufan Jin
2026-12-05 6:43 ` [PATCH v2 1/5] gpiolib: add gpio_device_find_by_fwnode_args() Pufan Jin
2026-12-05 6:43 ` [PATCH v2 2/5] gpiolib: swnode: prefer matching parent gpio_device Pufan Jin
2026-12-05 6:43 ` [PATCH v2 3/5] gpiolib: shared: match reset-gpio against translated entry offset Pufan Jin
2026-12-05 6:43 ` [PATCH v2 4/5] reset: gpio: derive fwnode_reset_n_cells from platform data Pufan Jin
2026-12-05 6:43 ` Pufan Jin [this message]
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=20261205064355.137581-6-cyan2254650260@gmail.com \
--to=cyan2254650260@gmail.com \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=brgl@kernel.org \
--cc=krzk@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
/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®