diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2016-04-05 10:49:57 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2016-04-09 14:14:26 -0400 |
commit | 6b5029d3ec86ee9558a1ab0b4b41a98e970e2204 (patch) | |
tree | 00722e622de49da9fa748f0d02762f74d47b3fb5 | |
parent | a0e637387a9858f9c2e8228bc15e299387dadcd1 (diff) |
gpio: document open drain/source behaviour
This has been a totally undocumented feature for years so add some
generic concepts and documentation about open drain/source, include
some facts on how we now support for hardware.
Cc: Michael Hennerich <michael.hennerich@analog.com>
Cc: Nicolas Saenz Julienne <nicolassaenzj@gmail.com>
Cc: H. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | Documentation/gpio/driver.txt | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/Documentation/gpio/driver.txt b/Documentation/gpio/driver.txt index bbeec415f406..ae6e0299b16c 100644 --- a/Documentation/gpio/driver.txt +++ b/Documentation/gpio/driver.txt | |||
@@ -68,6 +68,95 @@ control callbacks) if it is expected to call GPIO APIs from atomic context | |||
68 | on -RT (inside hard IRQ handlers and similar contexts). Normally this should | 68 | on -RT (inside hard IRQ handlers and similar contexts). Normally this should |
69 | not be required. | 69 | not be required. |
70 | 70 | ||
71 | |||
72 | GPIOs with open drain/source support | ||
73 | ------------------------------------ | ||
74 | |||
75 | Open drain (CMOS) or open collector (TTL) means the line is not actively driven | ||
76 | high: instead you provide the drain/collector as output, so when the transistor | ||
77 | is not open, it will present a high-impedance (tristate) to the external rail. | ||
78 | |||
79 | |||
80 | CMOS CONFIGURATION TTL CONFIGURATION | ||
81 | |||
82 | ||--- out +--- out | ||
83 | in ----|| |/ | ||
84 | ||--+ in ----| | ||
85 | | |\ | ||
86 | GND GND | ||
87 | |||
88 | This configuration is normally used as a way to achieve one of two things: | ||
89 | |||
90 | - Level-shifting: to reach a logical level higher than that of the silicon | ||
91 | where the output resides. | ||
92 | |||
93 | - inverse wire-OR on an I/O line, for example a GPIO line, making it possible | ||
94 | for any driving stage on the line to drive it low even if any other output | ||
95 | to the same line is simultaneously driving it high. A special case of this | ||
96 | is driving the SCL and SCA lines of an I2C bus, which is by definition a | ||
97 | wire-OR bus. | ||
98 | |||
99 | Both usecases require that the line be equipped with a pull-up resistor. This | ||
100 | resistor will make the line tend to high level unless one of the transistors on | ||
101 | the rail actively pulls it down. | ||
102 | |||
103 | Integrated electronics often have an output driver stage in the form of a CMOS | ||
104 | "totem-pole" with one N-MOS and one P-MOS transistor where one of them drives | ||
105 | the line high and one of them drives the line low. This is called a push-pull | ||
106 | output. The "totem-pole" looks like so: | ||
107 | |||
108 | VDD | ||
109 | | | ||
110 | OD ||--+ | ||
111 | +--/ ---o|| P-MOS-FET | ||
112 | | ||--+ | ||
113 | in --+ +----- out | ||
114 | | ||--+ | ||
115 | +--/ ----|| N-MOS-FET | ||
116 | OS ||--+ | ||
117 | | | ||
118 | GND | ||
119 | |||
120 | You see the little "switches" named "OD" and "OS" that enable/disable the | ||
121 | P-MOS or N-MOS transistor right after the split of the input. As you can see, | ||
122 | either transistor will go totally numb if this switch is open. The totem-pole | ||
123 | is then halved and give high impedance instead of actively driving the line | ||
124 | high or low respectively. That is usually how software-controlled open | ||
125 | drain/source works. | ||
126 | |||
127 | Some GPIO hardware come in open drain / open source configuration. Some are | ||
128 | hard-wired lines that will only support open drain or open source no matter | ||
129 | what: there is only one transistor there. Some are software-configurable: | ||
130 | by flipping a bit in a register the output can be configured as open drain | ||
131 | or open source, by flicking open the switches labeled "OD" and "OS" in the | ||
132 | drawing above. | ||
133 | |||
134 | By disabling the P-MOS transistor, the output can be driven between GND and | ||
135 | high impedance (open drain), and by disabling the N-MOS transistor, the output | ||
136 | can be driven between VDD and high impedance (open source). In the first case, | ||
137 | a pull-up resistor is needed on the outgoing rail to complete the circuit, and | ||
138 | in the second case, a pull-down resistor is needed on the rail. | ||
139 | |||
140 | Hardware that supports open drain or open source or both, can implement a | ||
141 | special callback in the gpio_chip: .set_single_ended() that takes an enum flag | ||
142 | telling whether to configure the line as open drain, open source or push-pull. | ||
143 | This will happen in response to the GPIO_OPEN_DRAIN or GPIO_OPEN_SOURCE flag | ||
144 | set in the machine file, or coming from other hardware descriptions. | ||
145 | |||
146 | If this state can not be configured in hardware, i.e. if the GPIO hardware does | ||
147 | not support open drain/open source in hardware, the GPIO library will instead | ||
148 | use a trick: when a line is set as output, if the line is flagged as open | ||
149 | drain, and the output value is negative, it will be driven low as usual. But | ||
150 | if the output value is set to positive, it will instead *NOT* be driven high, | ||
151 | instead it will be switched to input, as input mode is high impedance, thus | ||
152 | achieveing an "open drain emulation" of sorts: electrically the behaviour will | ||
153 | be identical, with the exception of possible hardware glitches when switching | ||
154 | the mode of the line. | ||
155 | |||
156 | For open source configuration the same principle is used, just that instead | ||
157 | of actively driving the line low, it is set to input. | ||
158 | |||
159 | |||
71 | GPIO drivers providing IRQs | 160 | GPIO drivers providing IRQs |
72 | --------------------------- | 161 | --------------------------- |
73 | It is custom that GPIO drivers (GPIO chips) are also providing interrupts, | 162 | It is custom that GPIO drivers (GPIO chips) are also providing interrupts, |