Skip to contentSkip to conversation

gpio: fixes for gpio-hog support

PATCH New Heiko Schocher 2 participants 2 messages Jul 17, 2019 – Jul 30, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: fixes for gpio-hog support

recently added gpio hog patch was "in discussion" state with Simon Glass. This patch now adds most of comments from Simon Glass.

---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/558774593

Based on mainline:
6070ef409c - Merge branch '2019-07-12-master-imports'

Tom applied version 4 of the patchset, but patch is in discussion with Simon and I prepared already a v5

This patch includes now comments from Simon:
- add example for line-name in Documentation
- drop .gpio-hog suffix in Documentation
as not longer needed.
- rework gpio_hog_lookup_name() which now returns error code and pointer to gpio desc is passed.
- rename DM_GPIO_HOG to GPIO_HOG
- set device name only if line-name property is set
- remove dm_gpio_set_dir() call as this is already done through gpio_dev_request_index()
- check some error codes
- tried to add a comment to gpio_dev_request_index()) and renamed function paramter "dev" to "gpio_dev"
- use IS_ENABLED()
- fix comments for gpio_dev_request_index()
- add warning if probing one gpio_hog fails and continue with probing the next gpio hog.

not yet implemented:
- question if gpio_desc can be stored in private device data, but this can be fixed later.

 common/board_r.c                       |   4 +-
 doc/device-tree-bindings/gpio/gpio.txt |  17 ++--
 drivers/gpio/Kconfig                   |   2 +-
 drivers/gpio/gpio-uclass.c             | 103 ++++++++++++++++++-------
 include/asm-generic/gpio.h             |  12 +--
 5 files changed, 96 insertions(+), 42 deletions(-)
common/board_r.c +2 -2
index abc31b17b8..e7ce11c30a 100644
@@ -49,7 +49,7 @@
 #include <linux/err.h>
 #include <efi_loader.h>
 #include <wdt.h>
-#if defined(CONFIG_DM_GPIO_HOG)
+#if defined(CONFIG_GPIO_HOG)
 #include <asm/gpio.h>
 #endif
 
@@ -799,7 +799,7 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_CMD_NET
 	initr_ethaddr,
 #endif
-#if defined(CONFIG_DM_GPIO_HOG)
+#if defined(CONFIG_GPIO_HOG)
 	gpio_hog_probe_all,
 #endif
 #ifdef CONFIG_BOARD_LATE_INIT
doc/device-tree-bindings/gpio/gpio.txt +11 -6
index e774439369..e146917ff3 100644
@@ -252,6 +252,7 @@ Example:
                 boot_rescue {
                         gpio-hog;
                         input;
+                        line-name = "foo-bar-gpio";
                         gpios = <7 GPIO_ACTIVE_LOW>;
                 };
         };
@@ -259,9 +260,13 @@ Example:
 For the above Example you can than access the gpio in your boardcode
 with:
 
-        desc = gpio_hog_lookup_name("boot_rescue.gpio-hog");
-        if (desc) {
-                if (dm_gpio_get_value(desc))
-                        printf("\nBooting into Rescue System\n");
-		else
-			printf("\nBoot normal\n");
+	struct gpio_desc *desc;
+	int ret;
+
+	ret = gpio_hog_lookup_name("boot_rescue", &desc);
+	if (ret)
+		return;
+	if (dm_gpio_get_value(desc) == 1)
+		printf("\nBooting into Rescue System\n");
+	else if (dm_gpio_get_value(desc) == 0)
+		printf("\nBoot normal\n");
drivers/gpio/Kconfig +1 -1
index fa1c99700f..3f1a24013c 100644
@@ -14,7 +14,7 @@ config DM_GPIO
 	  particular GPIOs that they provide. The uclass interface
 	  is defined in include/asm-generic/gpio.h.
 
-config DM_GPIO_HOG
+config GPIO_HOG
 	bool "Enable GPIO hog support"
 	depends on DM_GPIO
 	default n
drivers/gpio/gpio-uclass.c +75 -28

187 lines not on this page · raw message

include/asm-generic/gpio.h +7 -5
index 37f71e5708..d6cf18744f 100644
@@ -352,9 +352,10 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc);
  * gpio_hog_lookup_name() - Look up a named GPIO and return the gpio descr.
  *
  * @name:	Name to look up
- * @return:	Returns gpio_desc for gpio
+ * @desc:	Returns GPIO description, on success, else NULL
+ * @return:	Returns 0 if OK, else -ENODEV
  */
-struct gpio_desc *gpio_hog_lookup_name(const char *name);
+int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc);
 
 /**
  * gpio_hog_probe_all() - probe all gpio devices with
@@ -523,12 +524,13 @@ int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,
  * gpio_dev_request_index() - request single GPIO from gpio device
  *
  * @dev:	GPIO device
- * @nodename:	Name of node
+ * @nodename:	Name of node for which gpio gets requested, used
+ *		for the gpio label name
  * @list_name:	Name of GPIO list (e.g. "board-id-gpios")
  * @index:	Index number of the GPIO in that list use request (0=first)
  * @flags:	GPIOD_* flags
- * @dtflags:	GPIO flags read from DT
- * @desc:	GPIO descriotor filled from this function
+ * @dtflags:	GPIO flags read from DT defined see GPIOD_*
+ * @desc:	returns GPIO descriptor filled from this function
  * @return:	return value from gpio_request_tail()
  */
 int gpio_dev_request_index(struct udevice *dev, const char *nodename,
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/1 gpio: fixes for gpio-hog support

Quoted 5 lines · Heiko Schocher

recently added gpio hog patch was "in discussion"
state with Simon Glass. This patch now adds most
of comments from Simon Glass.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190729/db5d7c5e/attachment.sig>