u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: u-boot@lists.denx.de
Cc: Andrew Jeffery <andrew@aj.id.au>,
	Eddie James <eajames@linux.ibm.com>,
	Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
	Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Subject: [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers
Date: Fri, 17 Mar 2023 21:12:22 +0100	[thread overview]
Message-ID: <20230317201222.734132-1-rasmus.villemoes@prevas.dk> (raw)

The API is more convenient to use if one doesn't have to know upfront
which gpio controller has a line with the name one is searching for,
and arrange to look that device up somehow. Or implement this loop
oneself.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 drivers/gpio/gpio-uclass.c | 7 +++++++
 include/asm-generic/gpio.h | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 0ed32b7217..4912dc8375 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -1192,6 +1192,13 @@ int gpio_request_by_line_name(struct udevice *dev, const char *line_name,
 {
 	int ret;
 
+	if (!dev) {
+		uclass_foreach_dev_probe(UCLASS_GPIO, dev)
+			if (!gpio_request_by_line_name(dev, line_name, desc, flags))
+				return 0;
+		return -ENOENT;
+	}
+
 	ret = dev_read_stringlist_search(dev, "gpio-line-names", line_name);
 	if (ret < 0)
 		return ret;
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 81f63f06f1..44ca2458cf 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -587,7 +587,8 @@ int gpio_request_by_name(struct udevice *dev, const char *list_name,
  * This allows boards to implement common behaviours using GPIOs while not
  * requiring specific GPIO offsets be used.
  *
- * @dev:	An instance of a GPIO controller udevice
+ * @dev:        An instance of a GPIO controller udevice, or NULL to search
+ *              all GPIO controller devices
  * @line_name:	The name of the GPIO (e.g. "bmc-secure-boot")
  * @desc:	A GPIO descriptor that is populated with the requested GPIO
  *              upon return
-- 
2.37.2


             reply	other threads:[~2023-03-17 20:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-17 20:12 Rasmus Villemoes [this message]
2023-03-18 20:20 ` [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers Simon Glass
2023-03-19  0:38   ` Rasmus Villemoes
2023-03-19 19:29     ` Simon Glass
2023-03-31 14: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=20230317201222.734132-1-rasmus.villemoes@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=andrew@aj.id.au \
    --cc=eajames@linux.ibm.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.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;
as well as URLs for NNTP newsgroup(s).