Skip to contentSkip to conversation

gpiolib: Initializing GPIOs using DT property gpio-initval

PATCH New Markus Pargmann 4 participants 10 messages Aug 19, 2015 – Sep 15, 2015

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

cover gpiolib: Initializing GPIOs using DT property gpio-initval

Hi,

This series adds a gpio-initval property to the devicetree. It provides a way to initialize GPIOs to a defined value.

The previous patch was '[PATCH v2] gpio: Allow hogged gpios to be requested' which would have allowed to request hogged GPIOs. Linus suggested a separate DT property as hogged gpios should not be requested.

There are 3 patches. The first two simplify the function gpiod_hog. The third reuses the gpiod_hog()_code for a new gpiod_initialize() and adds the parsing of the DT.

This series is based on the series
"[PATCH v3 0/9] gpiolib: Add GPIO name support".

Best regards,

Markus

Markus Pargmann (3):
gpio: Use __gpiod_request directly
gpiolib: gpiod_hog remove separate name argument
gpiolib: Add GPIO initialization

 Documentation/devicetree/bindings/gpio/gpio.txt | 29 ++++++----
 drivers/gpio/gpiolib-of.c                       | 11 +++-
 drivers/gpio/gpiolib.c                          | 74 +++++++++++++++++--------
 drivers/gpio/gpiolib.h                          |  6 +-
 4 files changed, 83 insertions(+), 37 deletions(-)
Signature · 1 line
2.4.6
#1 lore raw

PATCH 1/3 gpio: Use __gpiod_request directly

From: Markus Pargmann <[email protected]>

There is no reason to find out chip and hwnum to use to request a gpio and get another gpio descriptor. We already have the descriptor we want to use so we can directly use it.

---
 drivers/gpio/gpiolib.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/gpio/gpiolib.c +6 -11
index 79a0b41ce57b..872fdd3617c1 100644
@@ -2189,25 +2189,20 @@ EXPORT_SYMBOL_GPL(__gpiod_get_index_optional);
 int gpiod_hog(struct gpio_desc *desc, const char *name,
 	      unsigned long lflags, enum gpiod_flags dflags)
 {
-	struct gpio_chip *chip;
-	struct gpio_desc *local_desc;
-	int hwnum;
 	int status;
 
-	chip = gpiod_to_chip(desc);
-	hwnum = gpio_chip_hwgpio(desc);
-
-	local_desc = gpiochip_request_own_desc(chip, hwnum, name);
-	if (IS_ERR(local_desc)) {
+	status = __gpiod_request(desc, name);
+	if (status) {
 		pr_err("requesting hog GPIO %s (chip %s, offset %d) failed\n",
-		       name, chip->label, hwnum);
-		return PTR_ERR(local_desc);
+		       name, gpiod_to_chip(desc)->label,
+		       gpio_chip_hwgpio(desc));
+		return status;
 	}
 
 	status = gpiod_configure_flags(desc, name, lflags, dflags);
 	if (status < 0) {
 		pr_err("setup of hog GPIO %s (chip %s, offset %d) failed\n",
-		       name, chip->label, hwnum);
+		       name, gpiod_to_chip(desc)->label, gpio_chip_hwgpio(desc));
 		gpiochip_free_own_desc(desc);
 		return status;
 	}
Signature · 1 line
2.4.6
#2 lore raw

PATCH 1/3 gpio: Use __gpiod_request directly

Quoted 7 lines · Markus Pargmann

From: Markus Pargmann <[email protected]>

There is no reason to find out chip and hwnum to use to request a gpio and get another gpio descriptor. We already have the descriptor we want to use so we can directly use it.

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#3 lore raw

PATCH 2/3 gpiolib: gpiod_hog remove separate name argument

In reply to Markus Pargmann

From: Markus Pargmann <[email protected]>

The gpio name is now stored in the gpio descriptor, so we can simply use that instead of an argument to the function.

---
 drivers/gpio/gpiolib-of.c | 2 +-
 drivers/gpio/gpiolib.c    | 8 ++++----
 drivers/gpio/gpiolib.h    | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/gpio/gpiolib-of.c +1 -1
index 48a7579dd62d..f1fe5123da28 100644
@@ -232,7 +232,7 @@ static void of_gpiochip_scan_gpios(struct gpio_chip *chip)
 				continue;
 			}
 
-			if (gpiod_hog(desc, name, lflags, dflags))
+			if (gpiod_hog(desc, lflags, dflags))
 				continue;
 		}
 	}
drivers/gpio/gpiolib.c +4 -4
index 872fdd3617c1..f1559fa72c36 100644
@@ -2181,15 +2181,15 @@ EXPORT_SYMBOL_GPL(__gpiod_get_index_optional);
 /**
  * gpiod_hog - Hog the specified GPIO desc given the provided flags
  * @desc:	gpio whose value will be assigned
- * @name:	gpio line name
  * @lflags:	gpio_lookup_flags - returned from of_find_gpio() or
  *		of_get_gpio_hog()
  * @dflags:	gpiod_flags - optional GPIO initialization flags
  */
-int gpiod_hog(struct gpio_desc *desc, const char *name,
-	      unsigned long lflags, enum gpiod_flags dflags)
+int gpiod_hog(struct gpio_desc *desc, unsigned long lflags,
+	      enum gpiod_flags dflags)
 {
 	int status;
+	const char *name = desc->name;
 
 	status = __gpiod_request(desc, name);
 	if (status) {
@@ -2211,7 +2211,7 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
 	set_bit(FLAG_IS_HOGGED, &desc->flags);
 
 	pr_info("GPIO line %d (%s) hogged as %s%s\n",
-		desc_to_gpio(desc), name,
+		desc_to_gpio(desc), desc->name,
 		(dflags&GPIOD_FLAGS_BIT_DIR_OUT) ? "output" : "input",
 		(dflags&GPIOD_FLAGS_BIT_DIR_OUT) ?
 		  (dflags&GPIOD_FLAGS_BIT_DIR_VAL) ? "/high" : "/low":"");
drivers/gpio/gpiolib.h +2 -2
index 78e634d1c719..6c2aeff59f86 100644
@@ -97,8 +97,8 @@ struct gpio_desc {
 
 int gpiod_request(struct gpio_desc *desc, const char *label);
 void gpiod_free(struct gpio_desc *desc);
-int gpiod_hog(struct gpio_desc *desc, const char *name,
-		unsigned long lflags, enum gpiod_flags dflags);
+int gpiod_hog(struct gpio_desc *desc, unsigned long lflags,
+	      enum gpiod_flags dflags);
 
 /*
  * Return the GPIO number of the passed descriptor relative to its chip
Signature · 1 line
2.4.6
#4 lore raw

PATCH 2/3 gpiolib: gpiod_hog remove separate name argument

Quoted 3 lines · Markus Pargmann

From: Markus Pargmann <[email protected]>

The gpio name is now stored in the gpio descriptor, so we can simply use

What is now? Does this introduce a dependency; maybe better reference a commit here?

Quoted 1 line

that instead of an argument to the function.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#5 lore raw

PATCH 2/3 gpiolib: gpiod_hog remove separate name argument

Hi,

Quoted 7 lines · Uwe Kleine-K?nig
Quoted 3 lines · Markus Pargmann

From: Markus Pargmann <[email protected]>

The gpio name is now stored in the gpio descriptor, so we can simply use

What is now? Does this introduce a dependency; maybe better reference a commit here?

Thanks. Yes this was refering to patch 3 of series "gpiolib: Add GPIO name support",
patch "gpiolib: Use GPIO name from names array for gpio descriptor".

However I can only reference by name here. Will add it to the commit message.

Best Regards,

Markus

Signature · 11 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150915/74eb2c75/attachment.sig>
#6 lore raw

PATCH 3/3 gpiolib: Add GPIO initialization

In reply to Markus Pargmann

From: Markus Pargmann <[email protected]>

This functions adds a way to initialize a GPIO without hogging it.

---
 Documentation/devicetree/bindings/gpio/gpio.txt | 29 +++++++------
 drivers/gpio/gpiolib-of.c                       |  9 ++++
 drivers/gpio/gpiolib.c                          | 55 ++++++++++++++++++++-----
 drivers/gpio/gpiolib.h                          |  2 +
 4 files changed, 73 insertions(+), 22 deletions(-)
Documentation/devicetree/bindings/gpio/gpio.txt +17 -12
index 5788d5cf1252..55d58983ba43 100644
@@ -116,29 +116,34 @@ Every GPIO controller node must contain both an empty "gpio-controller"
 property, and a #gpio-cells integer property, which indicates the number of
 cells in a gpio-specifier.
 
-The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism
-providing automatic GPIO request and configuration as part of the
-gpio-controller's driver probe function.
+The GPIO chip may contain GPIO definitions. These define properties for single
+GPIOs of this controller.
 
-Each GPIO hog definition is represented as a child node of the GPIO controller.
+GPIO hogging is a mechanism providing automatic GPIO request and configuration
+as part of the gpio-controller's driver probe function.
+
+GPIO initialization provides an automatic initialization to known save values.
+Instead of GPIO hogging the GPIO's value and direction can be modified by other
+users after it was initialized.
+
+Each GPIO definition is represented as a child node of the GPIO controller.
 Required properties:
-- gpio-hog:   A property specifying that this child node represent a GPIO hog.
 - gpios:      Store the GPIO information (id, flags, ...). Shall contain the
 	      number of cells specified in its parent node (GPIO controller
 	      node).
-Only one of the following properties scanned in the order shown below.
-This means that when multiple properties are present they will be searched
-in the order presented below and the first match is taken as the intended
-configuration.
+
+Optional properties:
+- line-name:  The GPIO label name. If not present the node name is used.
+ Only one of gpio-hog and gpio-initval may be specified.
+- gpio-hog:   A property specifying that this child node represent a GPIO hog.
+- gpio-initval: This GPIO should be initialized to the specified configuration.
+ Only one of input, output-low and output-high may be specified:
 - input:      A property specifying to set the GPIO direction as input.
 - output-low  A property specifying to set the GPIO direction as output with
 	      the value low.
 - output-high A property specifying to set the GPIO direction as output with
 	      the value high.
 
-Optional properties:
-- line-name:  The GPIO label name. If not present the node name is used.
-
 Example of two SOC GPIO banks defined as gpio-controller nodes:
 
 	qe_pio_a: gpio-controller at 1400 {
drivers/gpio/gpiolib-of.c +9 -0
index f1fe5123da28..ee00c2c63f57 100644
@@ -234,6 +234,15 @@ static void of_gpiochip_scan_gpios(struct gpio_chip *chip)
 
 			if (gpiod_hog(desc, lflags, dflags))
 				continue;
+		} else if (of_property_read_bool(np, "gpio-initval")) {
+			if (!dflags) {
+				dev_warn(chip->dev, "GPIO line %d (%s): no initialization state specified, bailing out\n",
+					 desc_to_gpio(desc), np->name);
+				continue;
+			}
+
+			if (gpiod_initialize(desc, lflags, dflags))
+				continue;
 		}
 	}
 }
drivers/gpio/gpiolib.c +45 -10

77 lines not on this page · raw message

drivers/gpio/gpiolib.h +2 -0
index 6c2aeff59f86..b6dfa3526e3a 100644
@@ -99,6 +99,8 @@ int gpiod_request(struct gpio_desc *desc, const char *label);
 void gpiod_free(struct gpio_desc *desc);
 int gpiod_hog(struct gpio_desc *desc, unsigned long lflags,
 	      enum gpiod_flags dflags);
+int gpiod_initialize(struct gpio_desc *desc, unsigned long lflags,
+		     enum gpiod_flags dflags);
 
 /*
  * Return the GPIO number of the passed descriptor relative to its chip
Signature · 1 line
2.4.6
#7 lore raw

PATCH 3/3 gpiolib: Add GPIO initialization

Quoted 7 lines · Markus Pargmann

From: Markus Pargmann <[email protected]>

This functions adds a way to initialize a GPIO without hogging it.

---
 Documentation/devicetree/bindings/gpio/gpio.txt | 29 +++++++------

This needs to go to devicetree at vger.kernel.org for review.

Yours,
Linus Walleij

#8 lore raw

cover gpiolib: Initializing GPIOs using DT property gpio-initval

In reply to Markus Pargmann
Quoted 9 lines · Markus Pargmann

Hi,

This series adds a gpio-initval property to the devicetree. It provides a way to initialize GPIOs to a defined value.

The previous patch was '[PATCH v2] gpio: Allow hogged gpios to be requested' which would have allowed to request hogged GPIOs. Linus suggested a separate DT property as hogged gpios should not be requested.

Quoted 6 lines

There are 3 patches. The first two simplify the function gpiod_hog. The third reuses the gpiod_hog()_code for a new gpiod_initialize() and adds the parsing of the DT.

This series is based on the series
"[PATCH v3 0/9] gpiolib: Add GPIO name support".

Messed up all the author/signed-off-bys. I will fix it in v2 but will wait for some feedback first.

Best regards,

Markus

Quoted 22 lines

Best regards,

Markus

Markus Pargmann (3):
gpio: Use __gpiod_request directly
gpiolib: gpiod_hog remove separate name argument
gpiolib: Add GPIO initialization

 Documentation/devicetree/bindings/gpio/gpio.txt | 29 ++++++----
 drivers/gpio/gpiolib-of.c                       | 11 +++-
 drivers/gpio/gpiolib.c                          | 74 +++++++++++++++++--------
 drivers/gpio/gpiolib.h                          |  6 +-
 4 files changed, 83 insertions(+), 37 deletions(-)
Signature · 1 line
2.4.6
Signature · 11 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150819/bbf71c15/attachment.sig>
#9 lore raw

cover gpiolib: Initializing GPIOs using DT property gpio-initval

In reply to Markus Pargmann
Quoted 2 lines · Markus Pargmann

This series adds a gpio-initval property to the devicetree. It provides a way to initialize GPIOs to a defined value.

This is actually a good thing to have. I know at least one SoC contains a paragraph in its hardware spec:

General Purpose Pins (GPP)
Each individual pin can be defined as an input, output, or level interrupt input. These pins can be used for indications retrieving or for peripherals control. When not in use, program interface to GPIOs and set GPIOs as output.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.