From: Rasmus Villemoes <ravi@prevas.dk>
To: u-boot@lists.denx.de
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
Tom Rini <trini@konsulko.com>, Heiko Schocher <hs@denx.de>,
Simon Glass <sjg@chromium.org>, Rasmus Villemoes <ravi@prevas.dk>
Subject: [PATCH v3 2/3] gpio: search gpio-line-names property in dm_gpio_lookup_name
Date: Tue, 4 Nov 2025 18:44:57 +0100 [thread overview]
Message-ID: <20251104174458.3385564-3-ravi@prevas.dk> (raw)
In-Reply-To: <20251104174458.3385564-1-ravi@prevas.dk>
In scripts as well as interactively, it's much nicer to be able to
refer to GPIOs via their names defined in the device tree property
"gpio-line-names", instead of the rather opaque names derived from the
bank name with a _xx suffix. E.g.
gpio read factory_reset FACTORY_RESET
if test $factory_reset = 1 ; then ...
versus
gpio read factory_reset gpio@481ac000_16
if test $factory_reset = 1 ; then ...
This is also consistent with the move on the linux/userspace side towards
using line names instead of legacy chip+offset or the even more legacy
global gpio numbering in sysfs.
As dev_read_stringlist_search() depends on both OF_CONTROL and
OF_LIBFDT (which matters for the SPL case), we need some .config
conditional. However, it only adds about ~50 bytes of code to U-Boot
proper, and dm_gpio_lookup_name() most often ends up being GC'ed for
SPL, thus adds no overhead there, so for now make it a hidden symbol
which is merely a convenient shorthand for
CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(OF_LIBFDT).
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
---
drivers/gpio/Kconfig | 16 ++++++++++++++++
drivers/gpio/gpio-uclass.c | 11 ++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index db077e472a8..a47c127d98c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -97,6 +97,22 @@ config SPL_DM_GPIO_LOOKUP_LABEL
different gpios on different hardware versions
for the same functionality in board code.
+config DM_GPIO_LOOKUP_LINE_NAME
+ def_bool y
+ depends on OF_CONTROL && OF_LIBFDT
+ help
+ This option enables specifying a GPIO by referring to its
+ name as defined by the "gpio-line-names" property in the
+ gpio controller's devicetree node.
+
+config SPL_DM_GPIO_LOOKUP_LINE_NAME
+ def_bool y
+ depends on SPL_OF_CONTROL && SPL_OF_LIBFDT
+ help
+ This option enables specifying a GPIO by referring to its
+ name as defined by the "gpio-line-names" property in the
+ gpio controller's devicetree node.
+
config ADI_GPIO
bool "ADI GPIO driver"
depends on DM_GPIO && ARCH_SC5XX
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 3d9f8b32b8d..6f52fdf4ef4 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -164,7 +164,7 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
for (uclass_first_device(UCLASS_GPIO, &dev);
dev;
uclass_next_device(&dev)) {
- int len;
+ int len, ret;
uc_priv = dev_get_uclass_priv(dev);
if (numeric != -1) {
@@ -188,6 +188,15 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
*/
if (!dm_gpio_lookup_label(name, uc_priv, &offset))
break;
+
+ /* Also search the "gpio-line-names" property in DT for a match. */
+ if (CONFIG_IS_ENABLED(DM_GPIO_LOOKUP_LINE_NAME)) {
+ ret = dev_read_stringlist_search(dev, "gpio-line-names", name);
+ if (ret >= 0) {
+ offset = ret;
+ break;
+ }
+ }
}
if (!dev)
--
2.51.0
next prev parent reply other threads:[~2025-11-04 17:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 17:44 [PATCH v3 0/3] reenable dm_gpio tests, add support for gpio-line-names lookup Rasmus Villemoes
2025-11-04 17:44 ` [PATCH v3 1/3] test: gpio: include in build, and fixup bitrot Rasmus Villemoes
2025-11-05 5:48 ` Heiko Schocher
2025-11-04 17:44 ` Rasmus Villemoes [this message]
2025-11-05 5:52 ` [PATCH v3 2/3] gpio: search gpio-line-names property in dm_gpio_lookup_name Heiko Schocher
2025-11-04 17:44 ` [PATCH v3 3/3] test: gpio: add test for gpio-line-names lookup Rasmus Villemoes
2025-11-05 5:53 ` Heiko Schocher
2025-11-05 15:20 ` [PATCH v3 0/3] reenable dm_gpio tests, add support " Tom Rini
2025-11-11 22:16 ` Tom Rini
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=20251104174458.3385564-3-ravi@prevas.dk \
--to=ravi@prevas.dk \
--cc=hs@denx.de \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.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