Skip to contentSkip to conversation

Documentation: gpio: board: add flags parameter to gpiod_get*() functions

PATCH Superseded Dirk Behme 2 participants 7 messages Jul 25, 2015 – Aug 31, 2015

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dirk Behme

author
#0 lore raw

PATCH 1/2 Documentation: gpio: board: add flags parameter to gpiod_get*() functions

With commit 39b2bbe3d715 ("gpio: add flags argument to gpiod_get*() functions") the gpiod_get*() functions got a 'flags' parameter. Reflect this in the documentation, too.

---
 Documentation/gpio/board.txt | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
Documentation/gpio/board.txt +8 -9
index b80606d..7605773 100644
@@ -39,11 +39,11 @@ This property will make GPIOs 15, 16 and 17 available to the driver under the
 
 	struct gpio_desc *red, *green, *blue, *power;
 
-	red = gpiod_get_index(dev, "led", 0);
-	green = gpiod_get_index(dev, "led", 1);
-	blue = gpiod_get_index(dev, "led", 2);
+	red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH);
+	green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH);
+	blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH);
 
-	power = gpiod_get(dev, "power");
+	power = gpiod_get(dev, "power", GPIOD_OUT_HIGH);
 
 The led GPIOs will be active-high, while the power GPIO will be active-low (i.e.
 gpiod_is_active_low(power) will be true).
@@ -142,12 +142,11 @@ The driver controlling "foo.0" will then be able to obtain its GPIOs as follows:
 
 	struct gpio_desc *red, *green, *blue, *power;
 
-	red = gpiod_get_index(dev, "led", 0);
-	green = gpiod_get_index(dev, "led", 1);
-	blue = gpiod_get_index(dev, "led", 2);
+	red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH);
+	green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH);
+	blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH);
 
-	power = gpiod_get(dev, "power");
-	gpiod_direction_output(power, 1);
+	power = gpiod_get(dev, "power", GPIOD_OUT_HIGH);
 
 Since the "power" GPIO is mapped as active-low, its actual signal will be 0
 after this code. Contrary to the legacy integer GPIO interface, the active-low
Signature · 1 line
2.4.6
author
#1 lore raw

PATCH 2/2 Documentation: gpio: board: describe the con_id parameter

The con_id parameter has to match the GPIO description and is automatically extended by the GPIO suffix if not NULL. I had to look into the code to understand this and properly find the GPIO I've been looking for, so document this.

---
 Documentation/gpio/board.txt    | 36 ++++++++++++++++++++++++++++++++++++
 Documentation/gpio/consumer.txt |  3 +++
 2 files changed, 39 insertions(+)
Documentation/gpio/board.txt +36 -0
index 7605773..eac78fc 100644
@@ -48,6 +48,42 @@ This property will make GPIOs 15, 16 and 17 available to the driver under the
 The led GPIOs will be active-high, while the power GPIO will be active-low (i.e.
 gpiod_is_active_low(power) will be true).
 
+If in the consumer device's node the property doesn't have a <function>- prefix,
+the second parameter (con_id) of the gpiod_get*() functions has to be NULL:
+
+E.g. if in the above device tree example the GPIO array is just called 'gpios'
+
+	foo_device {
+		compatible = "acme,foo";
+		...
+		gpios = <&gpio 15 GPIO_ACTIVE_HIGH>, /* red */
+			<&gpio 16 GPIO_ACTIVE_HIGH>, /* green */
+			<&gpio 17 GPIO_ACTIVE_HIGH>; /* blue */
+	};
+
+the gpiod_get*() calls will be:
+
+	struct gpio_desc *red, *green, *blue, *power;
+
+	red = gpiod_get_index(dev, NULL, 0, GPIOD_OUT_HIGH);
+	green = gpiod_get_index(dev, NULL, 1, GPIOD_OUT_HIGH);
+	blue = gpiod_get_index(dev, NULL, 2, GPIOD_OUT_HIGH);
+
+To summarize:
+
+The con_id string parameter has to be either NULL or the <function>-prefix
+of the GPIO suffixes ("gpios" or "gpio", automatically looked up by the
+gpiod functions internally):
+
+* If the GPIO description is just named with one of the GPIO suffixes
+  ("gpios" or "gpio"), use NULL.
+* If the GPIO description is prefixed with anything, e.g. "led-gpios", use the
+  prefix without the "-" as con_id parameter (in this example "led").
+
+In case con_id is not NULL, the GPIO subsystem prefixes the GPIO suffix
+("gpios" or "gpio") with the string passed in con_id to get the resulting string
+(snprintf(... "%s-%s", con_id, gpio_suffixes[]).
+
 ACPI
 ----
 ACPI also supports function names for GPIOs in a similar fashion to DT.
Documentation/gpio/consumer.txt +3 -0
index 75542b9..47ce4fd 100644
@@ -39,6 +39,9 @@ device that displays digits), an additional index argument can be specified:
 					  const char *con_id, unsigned int idx,
 					  enum gpiod_flags flags)
 
+For a more detailed description of the con_id parameter in the DeviceTree case
+see Documentation/gpio/board.txt
+
 The flags parameter is used to optionally specify a direction and initial value
 for the GPIO. Values can be:
 
Signature · 1 line
2.4.6
author
#2 lore raw

Re: [PATCH 2/2] Documentation: gpio: board: describe the con_id parameter

Quoted 63 lines · Dirk Behme

The con_id parameter has to match the GPIO description and is automatically extended by the GPIO suffix if not NULL. I had to look into the code to understand this and properly find the GPIO I've been looking for, so document this.

---
  Documentation/gpio/board.txt    | 36 ++++++++++++++++++++++++++++++++++++
  Documentation/gpio/consumer.txt |  3 +++
  2 files changed, 39 insertions(+)
Documentation/gpio/board.txt +36 -0
index 7605773..eac78fc 100644
@@ -48,6 +48,42 @@ This property will make GPIOs 15, 16 and 17 available to the driver under the
  The led GPIOs will be active-high, while the power GPIO will be active-low (i.e.
  gpiod_is_active_low(power) will be true).
 
+If in the consumer device's node the property doesn't have a <function>- prefix,
+the second parameter (con_id) of the gpiod_get*() functions has to be NULL:
+
+E.g. if in the above device tree example the GPIO array is just called 'gpios'
+
+	foo_device {
+		compatible = "acme,foo";
+		...
+		gpios = <&gpio 15 GPIO_ACTIVE_HIGH>, /* red */
+			<&gpio 16 GPIO_ACTIVE_HIGH>, /* green */
+			<&gpio 17 GPIO_ACTIVE_HIGH>; /* blue */
+	};
+
+the gpiod_get*() calls will be:
+
+	struct gpio_desc *red, *green, *blue, *power;
+
+	red = gpiod_get_index(dev, NULL, 0, GPIOD_OUT_HIGH);
+	green = gpiod_get_index(dev, NULL, 1, GPIOD_OUT_HIGH);
+	blue = gpiod_get_index(dev, NULL, 2, GPIOD_OUT_HIGH);
+
+To summarize:
+
+The con_id string parameter has to be either NULL or the <function>-prefix
+of the GPIO suffixes ("gpios" or "gpio", automatically looked up by the
+gpiod functions internally):
+
+* If the GPIO description is just named with one of the GPIO suffixes
+  ("gpios" or "gpio"), use NULL.
+* If the GPIO description is prefixed with anything, e.g. "led-gpios", use the
+  prefix without the "-" as con_id parameter (in this example "led").
+
+In case con_id is not NULL, the GPIO subsystem prefixes the GPIO suffix
+("gpios" or "gpio") with the string passed in con_id to get the resulting string
+(snprintf(... "%s-%s", con_id, gpio_suffixes[]).
+
  ACPI
  ----
  ACPI also supports function names for GPIOs in a similar fashion to DT.
Documentation/gpio/consumer.txt +0 -0
index 75542b9..47ce4fd 100644

Documentation/gpio/consumer.txt device that displays digits), an additional index argument can be specified: · line 46

Quoted 8 lines
Documentation/gpio/consumer.txt +3 -0
@@ -39,6 +39,9 @@ device that displays digits), an additional index argument can be specified:
  					  const char *con_id, unsigned int idx,
  					  enum gpiod_flags flags)
 
+For a more detailed description of the con_id parameter in the DeviceTree case
+see Documentation/gpio/board.txt
+
  The flags parameter is used to optionally specify a direction and initial value
  for the GPIO. Values can be:

Any further comments on this? Or could this be applied?

Best regards

Dirk

#3 lore raw

Re: [PATCH 2/2] Documentation: gpio: board: describe the con_id parameter

Quoted 82 lines · Dirk Behme
Quoted 81 lines · Dirk Behme

The con_id parameter has to match the GPIO description and is automatically
extended by the GPIO suffix if not NULL. I had to look into the code to understand this and properly find the GPIO I've been looking for, so document
this.

---
  Documentation/gpio/board.txt    | 36
++++++++++++++++++++++++++++++++++++
  Documentation/gpio/consumer.txt |  3 +++
  2 files changed, 39 insertions(+)
Documentation/gpio/board.txt +0 -0
index 7605773..eac78fc 100644
@@ -48,6 +48,42 @@ This property will make GPIOs 15, 16 and 17 available

to the driver under the
The led GPIOs will be active-high, while the power GPIO will be
active-low (i.e.
gpiod_is_active_low(power) will be true).

+If in the consumer device's node the property doesn't have a <function>- prefix,
+the second parameter (con_id) of the gpiod_get*() functions has to be NULL:

Documentation/gpio/board.txt +2 -0
+
+E.g. if in the above device tree example the GPIO array is just called

'gpios'

Documentation/gpio/board.txt +20 -0
+
+       foo_device {
+               compatible = "acme,foo";
+               ...
+               gpios = <&gpio 15 GPIO_ACTIVE_HIGH>, /* red */
+                       <&gpio 16 GPIO_ACTIVE_HIGH>, /* green */
+                       <&gpio 17 GPIO_ACTIVE_HIGH>; /* blue */
+       };
+
+the gpiod_get*() calls will be:
+
+       struct gpio_desc *red, *green, *blue, *power;
+
+       red = gpiod_get_index(dev, NULL, 0, GPIOD_OUT_HIGH);
+       green = gpiod_get_index(dev, NULL, 1, GPIOD_OUT_HIGH);
+       blue = gpiod_get_index(dev, NULL, 2, GPIOD_OUT_HIGH);
+
+To summarize:
+
+The con_id string parameter has to be either NULL or the

<function>-prefix

Documentation/gpio/board.txt +6 -0
+of the GPIO suffixes ("gpios" or "gpio", automatically looked up by the
+gpiod functions internally):
+
+* If the GPIO description is just named with one of the GPIO suffixes
+  ("gpios" or "gpio"), use NULL.
+* If the GPIO description is prefixed with anything, e.g. "led-gpios",

use the

Documentation/gpio/board.txt +4 -0
+  prefix without the "-" as con_id parameter (in this example "led").
+
+In case con_id is not NULL, the GPIO subsystem prefixes the GPIO suffix
+("gpios" or "gpio") with the string passed in con_id to get the resulting

string

Documentation/gpio/board.txt +2 -0
+(snprintf(... "%s-%s", con_id, gpio_suffixes[]).
+
  ACPI
  ----
  ACPI also supports function names for GPIOs in a similar fashion to DT.
Documentation/gpio/consumer.txt +0 -0
index 75542b9..47ce4fd 100644
@@ -39,6 +39,9 @@ device that displays digits), an additional index

argument can be specified:
const char *con_id, unsigned int
idx,
enum gpiod_flags flags)

Quoted 11 lines
Quoted 7 lines

+For a more detailed description of the con_id parameter in the DeviceTree case

Documentation/gpio/consumer.txt +2 -0
+see Documentation/gpio/board.txt
+
  The flags parameter is used to optionally specify a direction and

initial value
for the GPIO. Values can be:

Any further comments on this? Or could this be applied?

Using the "gpios" property is considered deprecated, so I am not sure that is a good idea to mention this too extensively in the boards file (people might be tempted to use that option while we clearly don't want them to).

A precise description of the lookup method is clearly missing though. I don't know what the right place would be for it. consumer.txt? board.txt in a more concise (and with a big "DEPRECATED") way?

author
#4 lore raw

Re: [PATCH 2/2] Documentation: gpio: board: describe the con_id parameter

Quoted 95 lines · Alexandre Courbot
Quoted 82 lines · Dirk Behme
Quoted 81 lines · Dirk Behme

The con_id parameter has to match the GPIO description and is automatically
extended by the GPIO suffix if not NULL. I had to look into the code to understand this and properly find the GPIO I've been looking for, so document
this.

---
   Documentation/gpio/board.txt    | 36
++++++++++++++++++++++++++++++++++++
   Documentation/gpio/consumer.txt |  3 +++
   2 files changed, 39 insertions(+)
Documentation/gpio/board.txt +0 -0
index 7605773..eac78fc 100644
@@ -48,6 +48,42 @@ This property will make GPIOs 15, 16 and 17 available

to the driver under the
The led GPIOs will be active-high, while the power GPIO will be
active-low (i.e.
gpiod_is_active_low(power) will be true).

+If in the consumer device's node the property doesn't have a <function>- prefix,
+the second parameter (con_id) of the gpiod_get*() functions has to be NULL:

Documentation/gpio/board.txt +2 -0
+
+E.g. if in the above device tree example the GPIO array is just called

'gpios'

Documentation/gpio/board.txt +20 -0
+
+       foo_device {
+               compatible = "acme,foo";
+               ...
+               gpios = <&gpio 15 GPIO_ACTIVE_HIGH>, /* red */
+                       <&gpio 16 GPIO_ACTIVE_HIGH>, /* green */
+                       <&gpio 17 GPIO_ACTIVE_HIGH>; /* blue */
+       };
+
+the gpiod_get*() calls will be:
+
+       struct gpio_desc *red, *green, *blue, *power;
+
+       red = gpiod_get_index(dev, NULL, 0, GPIOD_OUT_HIGH);
+       green = gpiod_get_index(dev, NULL, 1, GPIOD_OUT_HIGH);
+       blue = gpiod_get_index(dev, NULL, 2, GPIOD_OUT_HIGH);
+
+To summarize:
+
+The con_id string parameter has to be either NULL or the

<function>-prefix

Documentation/gpio/board.txt +6 -0
+of the GPIO suffixes ("gpios" or "gpio", automatically looked up by the
+gpiod functions internally):
+
+* If the GPIO description is just named with one of the GPIO suffixes
+  ("gpios" or "gpio"), use NULL.
+* If the GPIO description is prefixed with anything, e.g. "led-gpios",

use the

Documentation/gpio/board.txt +4 -0
+  prefix without the "-" as con_id parameter (in this example "led").
+
+In case con_id is not NULL, the GPIO subsystem prefixes the GPIO suffix
+("gpios" or "gpio") with the string passed in con_id to get the resulting

string

Documentation/gpio/board.txt +2 -0
+(snprintf(... "%s-%s", con_id, gpio_suffixes[]).
+
   ACPI
   ----
   ACPI also supports function names for GPIOs in a similar fashion to DT.
Documentation/gpio/consumer.txt +0 -0
index 75542b9..47ce4fd 100644
@@ -39,6 +39,9 @@ device that displays digits), an additional index

argument can be specified:
const char *con_id, unsigned int
idx,
enum gpiod_flags flags)

Quoted 11 lines
Quoted 7 lines

+For a more detailed description of the con_id parameter in the DeviceTree case

Documentation/gpio/consumer.txt +2 -0
+see Documentation/gpio/board.txt
+
   The flags parameter is used to optionally specify a direction and

initial value
for the GPIO. Values can be:

Any further comments on this? Or could this be applied?

Quoted 8 lines

Using the "gpios" property is considered deprecated, so I am not sure that is a good idea to mention this too extensively in the boards file (people might be tempted to use that option while we clearly don't want them to).

A precise description of the lookup method is clearly missing though. I don't know what the right place would be for it. consumer.txt? board.txt in a more concise (and with a big "DEPRECATED") way?

Ok, thanks!

In a previous comment there was the proposal to put it into board.txt, as this applies only to the device tree case and board.txt has a device tree section.

I'll drop the description of the deprecated part and send an update.

Best regards

Dirk

author
#5 lore raw
In reply to Dirk Behme
Quoted 36 lines · Dirk Behme

With commit 39b2bbe3d715 ("gpio: add flags argument to gpiod_get*() functions") the gpiod_get*() functions got a 'flags' parameter. Reflect this in the documentation, too.

---
  Documentation/gpio/board.txt | 17 ++++++++---------
  1 file changed, 8 insertions(+), 9 deletions(-)
Documentation/gpio/board.txt +4 -7
index b80606d..7605773 100644
@@ -39,11 +39,11 @@ This property will make GPIOs 15, 16 and 17 available to the driver under the
 
  	struct gpio_desc *red, *green, *blue, *power;
 
-	red = gpiod_get_index(dev, "led", 0);
-	green = gpiod_get_index(dev, "led", 1);
-	blue = gpiod_get_index(dev, "led", 2);
+	red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH);
+	green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH);
+	blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH);
 
-	power = gpiod_get(dev, "power");
+	power = gpiod_get(dev, "power", GPIOD_OUT_HIGH);
 
  The led GPIOs will be active-high, while the power GPIO will be active-low (i.e.
  gpiod_is_active_low(power) will be true).
@@ -142,12 +142,11 @@ The driver controlling "foo.0" will then be able to obtain its GPIOs as follows:
 
  	struct gpio_desc *red, *green, *blue, *power;
 
-	red = gpiod_get_index(dev, "led", 0);
-	green = gpiod_get_index(dev, "led", 1);
-	blue = gpiod_get_index(dev, "led", 2);

Documentation/gpio/board.txt The driver controlling "foo.0" will then be able to obtain its GPIOs as follows: · line 152

Quoted 10 lines
Documentation/gpio/board.txt +4 -2
+	red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH);
+	green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH);
+	blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH);
 
-	power = gpiod_get(dev, "power");
-	gpiod_direction_output(power, 1);
+	power = gpiod_get(dev, "power", GPIOD_OUT_HIGH);
 
  Since the "power" GPIO is mapped as active-low, its actual signal will be 0
  after this code. Contrary to the legacy integer GPIO interface, the active-low

Any further comments on this? Or could this be applied?

Best regards

Dirk

#6 lore raw
In reply to Dirk Behme
Quoted 30 lines · Dirk Behme

With commit 39b2bbe3d715 ("gpio: add flags argument to gpiod_get*() functions") the gpiod_get*() functions got a 'flags' parameter. Reflect this in the documentation, too.

---
 Documentation/gpio/board.txt | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
Documentation/gpio/board.txt +4 -4
index b80606d..7605773 100644
@@ -39,11 +39,11 @@ This property will make GPIOs 15, 16 and 17 available to the driver under the
 
        struct gpio_desc *red, *green, *blue, *power;
 
-       red = gpiod_get_index(dev, "led", 0);
-       green = gpiod_get_index(dev, "led", 1);
-       blue = gpiod_get_index(dev, "led", 2);
+       red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH);
+       green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH);
+       blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH);
 
-       power = gpiod_get(dev, "power");
+       power = gpiod_get(dev, "power", GPIOD_OUT_HIGH);
 
 The led GPIOs will be active-high, while the power GPIO will be active-low (i.e.
 gpiod_is_active_low(power) will be true).

Documentation/gpio/board.txt The driver controlling "foo.0" will then be able to obtain its GPIOs as follows: · line 147

Quoted 9 lines
Documentation/gpio/board.txt +3 -3
@@ -142,12 +142,11 @@ The driver controlling "foo.0" will then be able to obtain its GPIOs as follows:
 
        struct gpio_desc *red, *green, *blue, *power;
 
-       red = gpiod_get_index(dev, "led", 0);
-       green = gpiod_get_index(dev, "led", 1);
-       blue = gpiod_get_index(dev, "led", 2);
+       red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH);
+       green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH);
+       blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH);

You are right in that the documentation needs to be updated. But since the new code sets an output value for the 3 leds GPIO, could you also add a short note in this paragraph to mention the fact that it will switch the LEDs on, similarly to the explanation for the "power" GPIO below?

Oh, and apologies for taking so long to come back to this m(__)m