u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers
@ 2023-03-17 20:12 Rasmus Villemoes
  2023-03-18 20:20 ` Simon Glass
  2023-03-31 14:16 ` Tom Rini
  0 siblings, 2 replies; 5+ messages in thread
From: Rasmus Villemoes @ 2023-03-17 20:12 UTC (permalink / raw)
  To: u-boot
  Cc: Andrew Jeffery, Eddie James, Simon Glass, Tom Rini, Rasmus Villemoes

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers
  2023-03-17 20:12 [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers Rasmus Villemoes
@ 2023-03-18 20:20 ` Simon Glass
  2023-03-19  0:38   ` Rasmus Villemoes
  2023-03-31 14:16 ` Tom Rini
  1 sibling, 1 reply; 5+ messages in thread
From: Simon Glass @ 2023-03-18 20:20 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: u-boot, Andrew Jeffery, Eddie James, Tom Rini

Hi Rasmus,

On Fri, 17 Mar 2023 at 14:13, Rasmus Villemoes
<rasmus.villemoes@prevas.dk> wrote:
>
> 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(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

What is a line name? I don't see any mention of its purpose in the
binding doc[1].

Regards,
Simon

[1] https://github.com/devicetree-org/dt-schema/blob/3c35bfee83c2e38e2ae7af5f83eb89ca94a521e8/dtschema/schemas/gpio/gpio.yaml#L17

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers
  2023-03-18 20:20 ` Simon Glass
@ 2023-03-19  0:38   ` Rasmus Villemoes
  2023-03-19 19:29     ` Simon Glass
  0 siblings, 1 reply; 5+ messages in thread
From: Rasmus Villemoes @ 2023-03-19  0:38 UTC (permalink / raw)
  To: Simon Glass; +Cc: u-boot, Andrew Jeffery, Eddie James, Tom Rini

On 18/03/2023 21.20, Simon Glass wrote:
> Hi Rasmus,
> 
> On Fri, 17 Mar 2023 at 14:13, Rasmus Villemoes
> <rasmus.villemoes@prevas.dk> wrote:
>>
>> 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(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> What is a line name? I don't see any mention of its purpose in the
> binding doc[1].

Nah, those yaml-files are usually completely useless to gain some
understanding of what stuff is for, I much preferred the free-form prose.

https://www.kernel.org/doc/Documentation/devicetree/bindings/gpio/gpio.txt
has this text:

Optionally, a GPIO controller may have a "gpio-line-names" property. This is
an array of strings defining the names of the GPIO lines going out of the
GPIO controller. This name should be the most meaningful producer name
for the system, such as a rail name indicating the usage. Package names
such as pin name are discouraged: such lines have opaque names (since they
are by definition generic purpose) and such names are usually not very
helpful. For example "MMC-CD", "Red LED Vdd" and "ethernet reset" are
reasonable line names as they describe what the line is used for.

Rasmus


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers
  2023-03-19  0:38   ` Rasmus Villemoes
@ 2023-03-19 19:29     ` Simon Glass
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2023-03-19 19:29 UTC (permalink / raw)
  To: Rasmus Villemoes, Rob Herring
  Cc: u-boot, Andrew Jeffery, Eddie James, Tom Rini

Hi Rasmus,

On Sun, 19 Mar 2023 at 13:38, Rasmus Villemoes
<rasmus.villemoes@prevas.dk> wrote:
>
> On 18/03/2023 21.20, Simon Glass wrote:
> > Hi Rasmus,
> >
> > On Fri, 17 Mar 2023 at 14:13, Rasmus Villemoes
> > <rasmus.villemoes@prevas.dk> wrote:
> >>
> >> 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(-)
> >
> > Reviewed-by: Simon Glass <sjg@chromium.org>
> >
> > What is a line name? I don't see any mention of its purpose in the
> > binding doc[1].
>
> Nah, those yaml-files are usually completely useless to gain some
> understanding of what stuff is for, I much preferred the free-form prose.
>
> https://www.kernel.org/doc/Documentation/devicetree/bindings/gpio/gpio.txt
> has this text:
>
> Optionally, a GPIO controller may have a "gpio-line-names" property. This is
> an array of strings defining the names of the GPIO lines going out of the
> GPIO controller. This name should be the most meaningful producer name
> for the system, such as a rail name indicating the usage. Package names
> such as pin name are discouraged: such lines have opaque names (since they
> are by definition generic purpose) and such names are usually not very
> helpful. For example "MMC-CD", "Red LED Vdd" and "ethernet reset" are
> reasonable line names as they describe what the line is used for.

OK thank you. I wonder why that is not included in the yaml? There is
a description field, I think.

+Rob Herring who may know

Regards,
Simon

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers
  2023-03-17 20:12 [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers Rasmus Villemoes
  2023-03-18 20:20 ` Simon Glass
@ 2023-03-31 14:16 ` Tom Rini
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Rini @ 2023-03-31 14:16 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: u-boot, Andrew Jeffery, Eddie James, Simon Glass

[-- Attachment #1: Type: text/plain, Size: 458 bytes --]

On Fri, Mar 17, 2023 at 09:12:22PM +0100, Rasmus Villemoes wrote:

> 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>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/next, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-31 14:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17 20:12 [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers Rasmus Villemoes
2023-03-18 20:20 ` Simon Glass
2023-03-19  0:38   ` Rasmus Villemoes
2023-03-19 19:29     ` Simon Glass
2023-03-31 14:16 ` Tom Rini

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).