Skip to contentSkip to conversation

Add GPIO hog support

PATCH Superseded Eddie James 1 participant 7 messages Feb 7, 2022

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#4 lore raw

PATCH v3 4/6 gpio: Enable hogging support in SPL

In reply to Eddie James

Use the CONFIG macros to conditionally build the GPIO hogging support in either the SPL or U-Boot, or both, depending on the configuration. Also call the GPIO hog probe function in the common SPL board initialization as an equivalent to adding it to the U-Boot init sequence functions.

---
 common/spl/spl.c           |  4 ++++
 drivers/gpio/Kconfig       | 10 ++++++++++
 drivers/gpio/gpio-uclass.c | 12 +++++++-----
 3 files changed, 21 insertions(+), 5 deletions(-)
common/spl/spl.c +4 -0
index a1d4514fd3..927e072778 100644
@@ -12,6 +12,7 @@
 #include <dm.h>
 #include <handoff.h>
 #include <spl.h>
+#include <asm/gpio.h>
 #include <asm/sections.h>
 #include <asm/u-boot.h>
 #include <nand.h>
@@ -652,6 +653,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	timer_init();
 #endif
 
+	if (CONFIG_IS_ENABLED(GPIO_HOG))
+		gpio_hog_probe_all();
+
 #if CONFIG_IS_ENABLED(BOARD_INIT)
 	spl_board_init();
 #endif
drivers/gpio/Kconfig +10 -0
index a8dc16ca0e..69ca18c15b 100644
@@ -24,6 +24,16 @@ config GPIO_HOG
 	  is a mechanism providing automatic GPIO request and config-
 	  uration as part of the gpio-controller's driver probe function.
 
+config SPL_GPIO_HOG
+	bool "Enable GPIO hog support in SPL"
+	depends on SPL_GPIO_SUPPORT
+	default n
+	help
+	  Enable gpio hog support in SPL
+	  The GPIO chip may contain GPIO hog definitions. GPIO hogging
+	  is a mechanism providing automatic GPIO request and config-
+	  uration as part of the gpio-controller's driver probe function.
+
 config ALTERA_PIO
 	bool "Altera PIO driver"
 	depends on DM_GPIO
drivers/gpio/gpio-uclass.c +7 -5
index 01cfa2f788..219caa651b 100644
@@ -144,7 +144,7 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,
 		return gpio_xlate_offs_flags(desc->dev, desc, args);
 }
 
-#if defined(CONFIG_GPIO_HOG)
+#if CONFIG_IS_ENABLED(GPIO_HOG)
 
 struct gpio_hog_priv {
 	struct gpio_desc gpiod;
@@ -1033,9 +1033,6 @@ int gpio_dev_request_index(struct udevice *dev, const char *nodename,
 
 static int gpio_post_bind(struct udevice *dev)
 {
-	struct udevice *child;
-	ofnode node;
-
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
 	struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops(dev);
 	static int reloc_done;
@@ -1066,7 +1063,11 @@ static int gpio_post_bind(struct udevice *dev)
 	}
 #endif
 
-	if (IS_ENABLED(CONFIG_GPIO_HOG)) {
+#if CONFIG_IS_ENABLED(GPIO_HOG)
+	{
+		struct udevice *child;
+		ofnode node;
+
 		dev_for_each_subnode(node, dev) {
 			if (ofnode_read_bool(node, "gpio-hog")) {
 				const char *name = ofnode_get_name(node);
@@ -1081,6 +1082,7 @@ static int gpio_post_bind(struct udevice *dev)
 			}
 		}
 	}
+#endif
 	return 0;
 }
 
Signature · 1 line
2.27.0
#3 lore raw

PATCH v3 3/6 gpio: fixes for gpio-hog support

In reply to Eddie James

From: Heiko Schocher <[email protected]>

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

(cherry-picked from 49b10cb4926285b856b207c1f5bb40c75487f08b)

---
 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 5bb8f88bd0..429b9a2833 100644
@@ -48,7 +48,7 @@
 #include <linux/compiler.h>
 #include <linux/err.h>
 #include <efi_loader.h>
-#if defined(CONFIG_DM_GPIO_HOG)
+#if defined(CONFIG_GPIO_HOG)
 #include <asm/gpio.h>
 #endif
 
@@ -788,7 +788,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 56ed37c2b5..a8dc16ca0e 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.27.0
#5 lore raw

PATCH v3 5/6 Add GPIO hogging support for AST2600 openbmc config

In reply to Eddie James

Enable GPIO support in the SPL and hog the GPIOs in the SPL only. Also increase the size of the malloc size in the SPL to get the GPIO driver loaded.

---
 configs/ast2600_openbmc_spl_emmc_defconfig | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
configs/ast2600_openbmc_spl_emmc_defconfig +3 -1
index 344a4d8f9c..5f50298a58 100644
@@ -11,6 +11,7 @@ CONFIG_SYS_TEXT_BASE=0x81000000
 CONFIG_ASPEED_AST2600=y
 # CONFIG_ASPEED_LOADERS is not set
 CONFIG_TARGET_EVB_AST2600A1=y
+CONFIG_SPL_GPIO_SUPPORT=y
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_SYS_MALLOC_F_LEN=0x2000
@@ -19,7 +20,7 @@ CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL_DRIVERS_MISC_SUPPORT=y
 CONFIG_ENV_SIZE=0x10000
 CONFIG_ENV_OFFSET=0x5000
-CONFIG_SPL_SYS_MALLOC_F_LEN=0x800
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x1000
 CONFIG_SPL=y
 CONFIG_SPL_STACK_R_ADDR=0x90300000
 CONFIG_ARMV7_BOOT_SEC_DEFAULT=y
@@ -94,6 +95,7 @@ CONFIG_CLK=y
 CONFIG_SPL_CLK=y
 CONFIG_ASPEED_HACE=y
 CONFIG_DM_GPIO=y
+CONFIG_SPL_GPIO_HOG=y
 CONFIG_ASPEED_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_ASPEED=y
Signature · 1 line
2.27.0
#6 lore raw

PATCH v3 6/6 ast2600: Add GPIO controller and hog TPM reset pin

In reply to Eddie James

Hog the GPIO pin to reset the TPM.

---
 arch/arm/dts/ast2600-rainier.dts | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/dts/ast2600-rainier.dts +11 -0
index aae507b4c2..d0e82d1512 100755
@@ -108,3 +108,14 @@
 	u-boot,dm-pre-reloc;
 	status = "okay";
 };
+
+&gpio0 {
+	u-boot,dm-pre-reloc;
+
+	tpm_reset {
+		u-boot,dm-pre-reloc;
+		gpio-hog;
+		output-high;
+		gpios = <ASPEED_GPIO(R, 0) GPIO_ACTIVE_HIGH>;
+	};
+};
Signature · 1 line
2.27.0
#2 lore raw

PATCH v3 2/6 gpio: add gpio-hog support

In reply to Eddie James

From: Heiko Schocher <[email protected]>

add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.

for more infos see:
doc/device-tree-bindings/gpio/gpio.txt

(cherry-picked from 5fc7cf8c8e268590f3b0037eecea7f6798209f78)

---
 common/board_r.c                       |   6 +
 doc/device-tree-bindings/gpio/gpio.txt |  55 ++++++++
 drivers/gpio/Kconfig                   |  10 ++
 drivers/gpio/gpio-uclass.c             | 181 ++++++++++++++++++++++---
 include/asm-generic/gpio.h             |  32 +++++
 5 files changed, 268 insertions(+), 16 deletions(-)
common/board_r.c +6 -0
index 472987d5d5..5bb8f88bd0 100644
@@ -48,6 +48,9 @@
 #include <linux/compiler.h>
 #include <linux/err.h>
 #include <efi_loader.h>
+#if defined(CONFIG_DM_GPIO_HOG)
+#include <asm/gpio.h>
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -785,6 +788,9 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_CMD_NET
 	initr_ethaddr,
 #endif
+#if defined(CONFIG_DM_GPIO_HOG)
+	gpio_hog_probe_all,
+#endif
 #ifdef CONFIG_BOARD_LATE_INIT
 	board_late_init,
 #endif
doc/device-tree-bindings/gpio/gpio.txt +55 -0

58 lines not on this page · raw message

drivers/gpio/Kconfig +10 -0
index a519a0a169..56ed37c2b5 100644
@@ -14,6 +14,16 @@ config DM_GPIO
 	  particular GPIOs that they provide. The uclass interface
 	  is defined in include/asm-generic/gpio.h.
 
+config DM_GPIO_HOG
+	bool "Enable GPIO hog support"
+	depends on DM_GPIO
+	default n
+	help
+	  Enable gpio hog support
+	  The GPIO chip may contain GPIO hog definitions. GPIO hogging
+	  is a mechanism providing automatic GPIO request and config-
+	  uration as part of the gpio-controller's driver probe function.
+
 config ALTERA_PIO
 	bool "Altera PIO driver"
 	depends on DM_GPIO
drivers/gpio/gpio-uclass.c +165 -16

249 lines not on this page · raw message

include/asm-generic/gpio.h +32 -0
index d03602696f..37f71e5708 100644
@@ -348,6 +348,22 @@ const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);
  */
 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
+ */
+struct gpio_desc *gpio_hog_lookup_name(const char *name);
+
+/**
+ * gpio_hog_probe_all() - probe all gpio devices with
+ * gpio-hog subnodes.
+ *
+ * @return:	Returns return value from device_probe()
+ */
+int gpio_hog_probe_all(void);
+
 /**
  * gpio_lookup_name - Look up a GPIO name and return its details
  *
@@ -503,6 +519,22 @@ int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,
 				    struct gpio_desc *desc_list, int max_count,
 				    int flags);
 
+/**
+ * gpio_dev_request_index() - request single GPIO from gpio device
+ *
+ * @dev:	GPIO device
+ * @nodename:	Name of node
+ * @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
+ * @return:	return value from gpio_request_tail()
+ */
+int gpio_dev_request_index(struct udevice *dev, const char *nodename,
+			   char *list_name, int index, int flags,
+			   int dtflags, struct gpio_desc *desc);
+
 /**
  * dm_gpio_free() - Free a single GPIO
  *
Signature · 1 line
2.27.0
#1 lore raw

PATCH v3 1/6 dm: Add a No-op uclass

In reply to Eddie James

From: Jean-Jacques Hiblot <[email protected]>

This uclass is intended for devices that do not need any features from the uclass, including binding children.
This will typically be used by devices that are used to bind child devices but do not use dm_scan_fdt_dev() to do it. That is for example the case of several USB wrappers that have 2 child devices (1 for device and 1 for host) but bind only one at a any given time.

(cherry-picked from 07e33711fec4f1106f36805b5dc830da07c783c5)

---
 arch/sandbox/dts/test.dts | 12 +++++++
 drivers/core/uclass.c     |  5 +++
 include/dm/uclass-id.h    |  1 +
 test/dm/Makefile          |  1 +
 test/dm/nop.c             | 73 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 92 insertions(+)
 create mode 100644 test/dm/nop.c
arch/sandbox/dts/test.dts +12 -0
index 87d8e5bcc9..b705161086 100644
@@ -400,6 +400,18 @@
 		sandbox,silent;	/* Don't emit sounds while testing */
 	};
 
+	nop-test_0 {
+		compatible = "sandbox,nop_sandbox1";
+		nop-test_1 {
+			compatible = "sandbox,nop_sandbox2";
+			bind = "True";
+		};
+		nop-test_2 {
+			compatible = "sandbox,nop_sandbox2";
+			bind = "False";
+		};
+	};
+
 	misc-test {
 		compatible = "sandbox,misc_sandbox";
 	};
drivers/core/uclass.c +5 -0
index fc3157de39..dc9eb62893 100644
@@ -757,3 +757,8 @@ int uclass_pre_remove_device(struct udevice *dev)
 	return 0;
 }
 #endif
+
+UCLASS_DRIVER(nop) = {
+	.id		= UCLASS_NOP,
+	.name		= "nop",
+};
include/dm/uclass-id.h +1 -0
index 13ae6e1e4c..281c0d6ed2 100644
@@ -62,6 +62,7 @@ enum uclass_id {
 	UCLASS_MMC,		/* SD / MMC card or chip */
 	UCLASS_MOD_EXP,		/* RSA Mod Exp device */
 	UCLASS_MTD,		/* Memory Technology Device (MTD) device */
+	UCLASS_NOP,		/* No-op devices */
 	UCLASS_NORTHBRIDGE,	/* Intel Northbridge / SDRAM controller */
 	UCLASS_NVME,		/* NVM Express device */
 	UCLASS_PANEL,		/* Display panel, such as an LCD */
test/dm/Makefile +1 -0
index 49857c5092..aeb3aa0ca7 100644
@@ -3,6 +3,7 @@
 # Copyright (c) 2013 Google, Inc
 
 obj-$(CONFIG_UT_DM) += bus.o
+obj-$(CONFIG_UT_DM) += nop.o
 obj-$(CONFIG_UT_DM) += test-driver.o
 obj-$(CONFIG_UT_DM) += test-fdt.o
 obj-$(CONFIG_UT_DM) += test-main.o
test/dm/nop.c new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
2.27.0
#0 lore raw

v3 cover Add GPIO hog support

This series adds support for GPIO hogging based on upstream patches. I added additional support for hogging in the SPL, and enabled this for the AST2600 rainier openbmc platform.

Changes since v2:
- Sorry for the spam; I missed a change in the SPL patch from pulling my changes back from upstream.

Changes since v1:
- Add some tags to cherry-picked commits
- Make changes from upstream review for the SPL hogging patch

Eddie James (3):
gpio: Enable hogging support in SPL
Add GPIO hogging support for AST2600 openbmc config
ast2600: Add GPIO controller and hog TPM reset pin

Heiko Schocher (2):
gpio: add gpio-hog support
gpio: fixes for gpio-hog support

Jean-Jacques Hiblot (1):
dm: Add a No-op uclass

 arch/arm/dts/ast2600-rainier.dts           |  11 +
 arch/sandbox/dts/test.dts                  |  12 ++
 common/board_r.c                           |   6 +
 common/spl/spl.c                           |   4 +
 configs/ast2600_openbmc_spl_emmc_defconfig |   4 +-
 doc/device-tree-bindings/gpio/gpio.txt     |  60 ++++++
 drivers/core/uclass.c                      |   5 +
 drivers/gpio/Kconfig                       |  20 ++
 drivers/gpio/gpio-uclass.c                 | 230 +++++++++++++++++++--
 include/asm-generic/gpio.h                 |  34 +++
 include/dm/uclass-id.h                     |   1 +
 test/dm/Makefile                           |   1 +
 test/dm/nop.c                              |  73 +++++++
 13 files changed, 444 insertions(+), 17 deletions(-)
 create mode 100644 test/dm/nop.c
Signature · 1 line
2.27.0