Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <tony@atomide.com>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: H. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+27 -2
+15 -2
Documentation/devicetree/bindings/gpio/gpio.txt
··· 52 52 53 53 gpio-specifier may encode: bank, pin position inside the bank, 54 54 whether pin is open-drain and whether pin is logically inverted. 55 + 55 56 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: 58 62 59 63 Example of a node using GPIOs: 60 64 ··· 68 64 69 65 GPIO_ACTIVE_HIGH is 0, so in this example gpio-specifier is "18 0" and encodes 70 66 GPIO pin number, and GPIO flags as accepted by the "qe_pio_e" gpio-controller. 67 + 68 + Optional standard bitfield specifiers for the last cell: 69 + 70 + - Bit 0: 0 means active high, 1 means active low 71 + - Bit 1: 1 means single-ended wiring, see: 72 + https://en.wikipedia.org/wiki/Single-ended_triode 73 + When used with active-low, this means open drain/collector, see: 74 + https://en.wikipedia.org/wiki/Open_collector 75 + When used with active-high, this means open source/emitter 71 76 72 77 1.1) GPIO specifier best practices 73 78 ----------------------------------
+12
include/dt-bindings/gpio/gpio.h
··· 9 9 #ifndef _DT_BINDINGS_GPIO_GPIO_H 10 10 #define _DT_BINDINGS_GPIO_GPIO_H 11 11 12 + /* Bit 0 express polarity */ 12 13 #define GPIO_ACTIVE_HIGH 0 13 14 #define GPIO_ACTIVE_LOW 1 15 + 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) 14 26 15 27 #endif