Skip to content

Commit 69d301f

Browse files
committed
gpio: add DT bindings for existing consumer flags
It is customary for GPIO controllers to support open drain/collector and open source/emitter configurations. Add standard GPIO line flags to account for this and augment the documentation to say that these are the most generic bindings. Several people approached me to add new flags to the lines, and this makes sense, but let's first bind up the most common cases before we start to add exotic stuff. Thanks to H. Nikolaus Schaller for ideas on how to encode single-ended wiring such as open drain/source and open collector/emitter. Cc: Tony Lindgren <[email protected]> Cc: Grygorii Strashko <[email protected]> Cc: H. Nikolaus Schaller <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent b866492 commit 69d301f

File tree

2 files changed

+27
-2
lines changed
  • Documentation/devicetree/bindings/gpio
  • include/dt-bindings/gpio

2 files changed

+27
-2
lines changed

Documentation/devicetree/bindings/gpio/gpio.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ only uses one.
5252

5353
gpio-specifier may encode: bank, pin position inside the bank,
5454
whether pin is open-drain and whether pin is logically inverted.
55+
5556
Exact meaning of each specifier cell is controller specific, and must
56-
be documented in the device tree binding for the device. Use the macros
57-
defined in include/dt-bindings/gpio/gpio.h whenever possible:
57+
be documented in the device tree binding for the device.
58+
59+
Most controllers are however specifying a generic flag bitfield
60+
in the last cell, so for these, use the macros defined in
61+
include/dt-bindings/gpio/gpio.h whenever possible:
5862

5963
Example of a node using GPIOs:
6064

@@ -65,6 +69,15 @@ Example of a node using GPIOs:
6569
GPIO_ACTIVE_HIGH is 0, so in this example gpio-specifier is "18 0" and encodes
6670
GPIO pin number, and GPIO flags as accepted by the "qe_pio_e" gpio-controller.
6771

72+
Optional standard bitfield specifiers for the last cell:
73+
74+
- Bit 0: 0 means active high, 1 means active low
75+
- Bit 1: 1 means single-ended wiring, see:
76+
https://en.wikipedia.org/wiki/Single-ended_triode
77+
When used with active-low, this means open drain/collector, see:
78+
https://en.wikipedia.org/wiki/Open_collector
79+
When used with active-high, this means open source/emitter
80+
6881
1.1) GPIO specifier best practices
6982
----------------------------------
7083

include/dt-bindings/gpio/gpio.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@
99
#ifndef _DT_BINDINGS_GPIO_GPIO_H
1010
#define _DT_BINDINGS_GPIO_GPIO_H
1111

12+
/* Bit 0 express polarity */
1213
#define GPIO_ACTIVE_HIGH 0
1314
#define GPIO_ACTIVE_LOW 1
1415

16+
/* Bit 1 express single-endedness */
17+
#define GPIO_PUSH_PULL 0
18+
#define GPIO_SINGLE_ENDED 2
19+
20+
/*
21+
* Open Drain/Collector is the combination of single-ended active low,
22+
* Open Source/Emitter is the combination of single-ended active high.
23+
*/
24+
#define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_ACTIVE_LOW)
25+
#define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_ACTIVE_HIGH)
26+
1527
#endif

0 commit comments

Comments
 (0)