u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: Add gpio_request_by_line_name()
@ 2022-01-31  3:24 Andrew Jeffery
  2022-01-31 16:10 ` Fabio Estevam
  2022-04-10 15:20 ` Tom Rini
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Jeffery @ 2022-01-31  3:24 UTC (permalink / raw)
  To: u-boot; +Cc: sjg, joel, openbmc

Add support for the upstream gpio-line-names property already described
in the common GPIO binding document[1]. The ability to search for a line
name allows boards to lift the implementation of common GPIO behaviours
away from specific line indexes on a GPIO controller.

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

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
Hi,

This patch is extracted from and motivated by a series adding run-time
control of FIT signature verification to u-boot in OpenBMC:

https://lore.kernel.org/openbmc/20220131012538.73021-1-andrew@aj.id.au/

Unfortunately the OpenBMC u-boot tree is quite a way behind on tracking
upstream and contains a bunch of out-of-tree work as well. As such I'm
looking to upstream the couple of changes that make sense against
master.

Please take a look!

Andrew

 drivers/gpio/gpio-uclass.c | 26 ++++++++++++++++++++++++++
 include/asm-generic/gpio.h | 19 +++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 125ae53d612f..be00a1f7d871 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -1187,6 +1187,32 @@ int gpio_request_by_name(struct udevice *dev, const char *list_name, int index,
 				 index, desc, flags, index > 0, NULL);
 }
 
+int gpio_request_by_line_name(struct udevice *dev, const char *line_name,
+			      struct gpio_desc *desc, int flags)
+{
+	int ret;
+
+	ret = dev_read_stringlist_search(dev, "gpio-line-names", line_name);
+	if (ret < 0)
+		return ret;
+
+	desc->dev = dev;
+	desc->offset = ret;
+	desc->flags = 0;
+
+	ret = dm_gpio_request(desc, line_name);
+	if (ret) {
+		debug("%s: dm_gpio_requestf failed\n", __func__);
+		return ret;
+	}
+
+	ret = dm_gpio_set_dir_flags(desc, flags | desc->flags);
+	if (ret)
+		debug("%s: dm_gpio_set_dir failed\n", __func__);
+
+	return ret;
+}
+
 int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,
 				    struct gpio_desc *desc, int max_count,
 				    int flags)
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index adc19e9765d7..81f63f06f15e 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -579,6 +579,25 @@ int gpio_claim_vector(const int *gpio_num_array, const char *fmt);
 int gpio_request_by_name(struct udevice *dev, const char *list_name,
 			 int index, struct gpio_desc *desc, int flags);
 
+/* gpio_request_by_line_name - Locate and request a GPIO by line name
+ *
+ * Request a GPIO using the offset of the provided line name in the
+ * gpio-line-names property found in the OF node of the GPIO udevice.
+ *
+ * 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
+ * @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
+ * @flags:	The GPIO settings apply to the request
+ * @return 0 if the named line was found and requested successfully, or a
+ * negative error code if the GPIO cannot be found or the request failed.
+ */
+int gpio_request_by_line_name(struct udevice *dev, const char *line_name,
+			      struct gpio_desc *desc, int flags);
+
 /**
  * gpio_request_list_by_name() - Request a list of GPIOs
  *
-- 
2.32.0


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

* Re: [PATCH] gpio: Add gpio_request_by_line_name()
  2022-01-31  3:24 [PATCH] gpio: Add gpio_request_by_line_name() Andrew Jeffery
@ 2022-01-31 16:10 ` Fabio Estevam
  2022-01-31 21:39   ` Andrew Jeffery
  2022-04-10 15:20 ` Tom Rini
  1 sibling, 1 reply; 4+ messages in thread
From: Fabio Estevam @ 2022-01-31 16:10 UTC (permalink / raw)
  To: Andrew Jeffery; +Cc: U-Boot-Denx, Simon Glass, Joel Stanley, openbmc

On Mon, Jan 31, 2022 at 9:55 AM Andrew Jeffery <andrew@aj.id.au> wrote:
>
> Add support for the upstream gpio-line-names property already described
> in the common GPIO binding document[1]. The ability to search for a line
> name allows boards to lift the implementation of common GPIO behaviours
> away from specific line indexes on a GPIO controller.
>
> [1] https://github.com/devicetree-org/dt-schema/blob/3c35bfee83c2e38e2ae7af5f83eb89ca94a521e8/dtschema/schemas/gpio/gpio.yaml#L17
>
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>

Please also add a user for the newly introduced gpio_request_by_line_name().

Otherwise, this is just dead code.

Thanks

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

* Re: [PATCH] gpio: Add gpio_request_by_line_name()
  2022-01-31 16:10 ` Fabio Estevam
@ 2022-01-31 21:39   ` Andrew Jeffery
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Jeffery @ 2022-01-31 21:39 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: U-Boot-Denx, Simon Glass, Joel Stanley, openbmc

Hi Fabio, thanks for taking a look.

On Tue, 1 Feb 2022, at 02:40, Fabio Estevam wrote:
> On Mon, Jan 31, 2022 at 9:55 AM Andrew Jeffery <andrew@aj.id.au> wrote:
>>
>> Add support for the upstream gpio-line-names property already described
>> in the common GPIO binding document[1]. The ability to search for a line
>> name allows boards to lift the implementation of common GPIO behaviours
>> away from specific line indexes on a GPIO controller.
>>
>> [1] https://github.com/devicetree-org/dt-schema/blob/3c35bfee83c2e38e2ae7af5f83eb89ca94a521e8/dtschema/schemas/gpio/gpio.yaml#L17
>>
>> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
>
> Please also add a user for the newly introduced gpio_request_by_line_name().
>
> Otherwise, this is just dead code.

Indeed. I will be working to get some other pieces upstream so I can 
introduce a user of this API. I will resend the patch once I have that 
sorted.

My hope was that I could get a head start on any other feedback people 
might have for the patch while I work to get the other pieces together.

Cheers,

Andrew

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

* Re: [PATCH] gpio: Add gpio_request_by_line_name()
  2022-01-31  3:24 [PATCH] gpio: Add gpio_request_by_line_name() Andrew Jeffery
  2022-01-31 16:10 ` Fabio Estevam
@ 2022-04-10 15:20 ` Tom Rini
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Rini @ 2022-04-10 15:20 UTC (permalink / raw)
  To: Andrew Jeffery; +Cc: u-boot, sjg, joel, openbmc

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

On Mon, Jan 31, 2022 at 01:54:05PM +1030, Andrew Jeffery wrote:

> Add support for the upstream gpio-line-names property already described
> in the common GPIO binding document[1]. The ability to search for a line
> name allows boards to lift the implementation of common GPIO behaviours
> away from specific line indexes on a GPIO controller.
> 
> [1] https://github.com/devicetree-org/dt-schema/blob/3c35bfee83c2e38e2ae7af5f83eb89ca94a521e8/dtschema/schemas/gpio/gpio.yaml#L17
> 
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>

Applied to u-boot/master, thanks!

-- 
Tom

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

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

end of thread, other threads:[~2022-04-10 15:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-31  3:24 [PATCH] gpio: Add gpio_request_by_line_name() Andrew Jeffery
2022-01-31 16:10 ` Fabio Estevam
2022-01-31 21:39   ` Andrew Jeffery
2022-04-10 15:20 ` 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).