linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] gpiolib: Initializing GPIOs using DT property gpio-initval
@ 2015-12-04 13:06 Markus Pargmann
  2015-12-04 13:06 ` [PATCH v4 1/2] dt-bindings: GPIO: Add gpio-initval Markus Pargmann
  2015-12-04 13:06 ` [PATCH v4 2/2] gpiolib: Add GPIO initialization Markus Pargmann
  0 siblings, 2 replies; 4+ messages in thread
From: Markus Pargmann @ 2015-12-04 13:06 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-gpio-u79uwXL29TY76Z2rM5mHXA, kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
	Markus Pargmann

Hi,

sorry for the delay.

Here is the next version of this series. I added gpiod_parse_flags() to the
code for the initialization. Otherwise there are no differences. As the
gpio-hog bindings already exist I didn't change the gpio-initval bindings.

Best Regards,

Markus


Markus Pargmann (2):
  dt-bindings: GPIO: Add gpio-initval
  gpiolib: Add GPIO initialization

 Documentation/devicetree/bindings/gpio/gpio.txt | 34 ++++++++++++++++---------
 drivers/gpio/gpiolib-of.c                       | 13 ++++++----
 drivers/gpio/gpiolib.c                          | 26 +++++++++++++++++++
 drivers/gpio/gpiolib.h                          |  2 ++
 4 files changed, 58 insertions(+), 17 deletions(-)

-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v4 1/2] dt-bindings: GPIO: Add gpio-initval
  2015-12-04 13:06 [PATCH v4 0/2] gpiolib: Initializing GPIOs using DT property gpio-initval Markus Pargmann
@ 2015-12-04 13:06 ` Markus Pargmann
  2015-12-04 16:39   ` Philipp Zabel
  2015-12-04 13:06 ` [PATCH v4 2/2] gpiolib: Add GPIO initialization Markus Pargmann
  1 sibling, 1 reply; 4+ messages in thread
From: Markus Pargmann @ 2015-12-04 13:06 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, devicetree, linux-gpio, kernel,
	Markus Pargmann

Add a binding for GPIO initialization.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 Documentation/devicetree/bindings/gpio/gpio.txt | 34 ++++++++++++++++---------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/Documentation/devicetree/bindings/gpio/gpio.txt b/Documentation/devicetree/bindings/gpio/gpio.txt
index 069cdf6f9dac..d11abfa13add 100644
--- a/Documentation/devicetree/bindings/gpio/gpio.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio.txt
@@ -155,29 +155,39 @@ gpio-controller@00000000 {
 	ngpios = <18>;
 }
 
-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.
+There are two types of GPIO definitions:
+
+- GPIO hogging is a mechanism providing automatic GPIO request and
+  configuration as part of the gpio-controller driver's probe function. The
+  GPIO is held until the gpio-controller is removed.
+- GPIO initialization provides an automatic initialization to known save
+  values. The GPIO can be used normally afterwards.
+
+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.
+
+ The following two options are mutually exclusive. One of them should be
+ specified, but not both:
+- gpio-hog:   A property specifying that this child node represent a GPIO hog.
+- gpio-initval: This GPIO should be initialized to the specified configuration.
+
+ The following three options are mutually exclusive. They change the setting of
+ the GPIO pin. One of them should 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@1400 {
-- 
2.6.2


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

* [PATCH v4 2/2] gpiolib: Add GPIO initialization
  2015-12-04 13:06 [PATCH v4 0/2] gpiolib: Initializing GPIOs using DT property gpio-initval Markus Pargmann
  2015-12-04 13:06 ` [PATCH v4 1/2] dt-bindings: GPIO: Add gpio-initval Markus Pargmann
@ 2015-12-04 13:06 ` Markus Pargmann
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Pargmann @ 2015-12-04 13:06 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, devicetree, linux-gpio, kernel,
	Markus Pargmann

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

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib-of.c | 13 ++++++++-----
 drivers/gpio/gpiolib.c    | 26 ++++++++++++++++++++++++++
 drivers/gpio/gpiolib.h    |  2 ++
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 5fe34a9df3e6..48cdc22eabf2 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -211,15 +211,18 @@ static void of_gpiochip_scan_gpios(struct gpio_chip *chip)
 	enum gpiod_flags dflags;
 
 	for_each_child_of_node(chip->of_node, np) {
-		if (!of_property_read_bool(np, "gpio-hog"))
-			continue;
 
 		desc = of_parse_own_gpio(np, &name, &lflags, &dflags);
-		if (IS_ERR(desc))
+		if (IS_ERR(desc) || !dflags)
 			continue;
 
-		if (gpiod_hog(desc, name, lflags, dflags))
-			continue;
+		if (of_property_read_bool(np, "gpio-hog"))
+			gpiod_hog(desc, name, lflags, dflags);
+		else if (of_property_read_bool(np, "gpio-initval"))
+			gpiod_initialize(desc, lflags, dflags);
+		else
+			dev_dbg(chip->dev, "GPIO line %d (%s): neither gpio-hog nor gpio-initval found.\n",
+				desc_to_gpio(desc), np->name);
 	}
 }
 
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a18f00fc1bb8..10e16b3f0667 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2329,6 +2329,32 @@ static void gpiochip_free_hogs(struct gpio_chip *chip)
 }
 
 /**
+ * gpiod_initialize - Initialize a GPIO with a given value
+ * @desc:	gpio whose value will be assigned
+ * @lflags:	gpio_lookup_flags - returned from of_find_gpio() or
+ *		of_get_gpio_hog()
+ * @dflags:	gpiod_flags - optional GPIO initialization flags
+ *
+ * This is used to initialize GPIOs that were defined in DT
+ */
+int gpiod_initialize(struct gpio_desc *desc, unsigned long lflags,
+		     enum gpiod_flags dflags)
+{
+	int status;
+
+	gpiod_parse_flags(desc, lflags);
+
+	status = gpiod_configure_flags(desc, NULL, dflags);
+	if (status < 0) {
+		pr_err("initial setup of GPIO (chip %s, offset %d) failed\n",
+		       gpiod_to_chip(desc)->label, gpio_chip_hwgpio(desc));
+		return status;
+	}
+
+	return 0;
+}
+
+/**
  * gpiod_get_array - obtain multiple GPIOs from a multi-index GPIO function
  * @dev:	GPIO consumer, can be NULL for system-global GPIOs
  * @con_id:	function within the GPIO consumer
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 98ab08c0aa2d..4abf53a5e651 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -107,6 +107,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, const char *name,
 		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
-- 
2.6.2


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

* Re: [PATCH v4 1/2] dt-bindings: GPIO: Add gpio-initval
  2015-12-04 13:06 ` [PATCH v4 1/2] dt-bindings: GPIO: Add gpio-initval Markus Pargmann
@ 2015-12-04 16:39   ` Philipp Zabel
  0 siblings, 0 replies; 4+ messages in thread
From: Philipp Zabel @ 2015-12-04 16:39 UTC (permalink / raw)
  To: Markus Pargmann
  Cc: Linus Walleij, Alexandre Courbot, linux-gpio, kernel, devicetree

Am Freitag, den 04.12.2015, 14:06 +0100 schrieb Markus Pargmann:
> Add a binding for GPIO initialization.
> 
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>

Both patches
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

small nitpick:

> ---
>  Documentation/devicetree/bindings/gpio/gpio.txt | 34 ++++++++++++++++---------
>  1 file changed, 22 insertions(+), 12 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/gpio/gpio.txt b/Documentation/devicetree/bindings/gpio/gpio.txt
> index 069cdf6f9dac..d11abfa13add 100644
> --- a/Documentation/devicetree/bindings/gpio/gpio.txt
> +++ b/Documentation/devicetree/bindings/gpio/gpio.txt
> @@ -155,29 +155,39 @@ gpio-controller@00000000 {
>  	ngpios = <18>;
>  }
>  
> -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.
> +There are two types of GPIO definitions:
> +
> +- GPIO hogging is a mechanism providing automatic GPIO request and
> +  configuration as part of the gpio-controller driver's probe function. The
> +  GPIO is held until the gpio-controller is removed.
> +- GPIO initialization provides an automatic initialization to known save

safe

regards
Philipp


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

end of thread, other threads:[~2015-12-04 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-04 13:06 [PATCH v4 0/2] gpiolib: Initializing GPIOs using DT property gpio-initval Markus Pargmann
2015-12-04 13:06 ` [PATCH v4 1/2] dt-bindings: GPIO: Add gpio-initval Markus Pargmann
2015-12-04 16:39   ` Philipp Zabel
2015-12-04 13:06 ` [PATCH v4 2/2] gpiolib: Add GPIO initialization Markus Pargmann

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