aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-04-05 10:49:57 -0400
committerLinus Walleij <linus.walleij@linaro.org>2016-04-09 14:14:26 -0400
commit6b5029d3ec86ee9558a1ab0b4b41a98e970e2204 (patch)
tree00722e622de49da9fa748f0d02762f74d47b3fb5
parenta0e637387a9858f9c2e8228bc15e299387dadcd1 (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.txt89
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
68on -RT (inside hard IRQ handlers and similar contexts). Normally this should 68on -RT (inside hard IRQ handlers and similar contexts). Normally this should
69not be required. 69not be required.
70 70
71
72GPIOs with open drain/source support
73------------------------------------
74
75Open drain (CMOS) or open collector (TTL) means the line is not actively driven
76high: instead you provide the drain/collector as output, so when the transistor
77is 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
88This 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
99Both usecases require that the line be equipped with a pull-up resistor. This
100resistor will make the line tend to high level unless one of the transistors on
101the rail actively pulls it down.
102
103Integrated 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
105the line high and one of them drives the line low. This is called a push-pull
106output. The "totem-pole" looks like so:
107
108 VDD
109 |
110 OD ||--+
111 +--/ ---o|| P-MOS-FET
112 | ||--+
113in --+ +----- out
114 | ||--+
115 +--/ ----|| N-MOS-FET
116 OS ||--+
117 |
118 GND
119
120You see the little "switches" named "OD" and "OS" that enable/disable the
121P-MOS or N-MOS transistor right after the split of the input. As you can see,
122either transistor will go totally numb if this switch is open. The totem-pole
123is then halved and give high impedance instead of actively driving the line
124high or low respectively. That is usually how software-controlled open
125drain/source works.
126
127Some GPIO hardware come in open drain / open source configuration. Some are
128hard-wired lines that will only support open drain or open source no matter
129what: there is only one transistor there. Some are software-configurable:
130by flipping a bit in a register the output can be configured as open drain
131or open source, by flicking open the switches labeled "OD" and "OS" in the
132drawing above.
133
134By disabling the P-MOS transistor, the output can be driven between GND and
135high impedance (open drain), and by disabling the N-MOS transistor, the output
136can be driven between VDD and high impedance (open source). In the first case,
137a pull-up resistor is needed on the outgoing rail to complete the circuit, and
138in the second case, a pull-down resistor is needed on the rail.
139
140Hardware that supports open drain or open source or both, can implement a
141special callback in the gpio_chip: .set_single_ended() that takes an enum flag
142telling whether to configure the line as open drain, open source or push-pull.
143This will happen in response to the GPIO_OPEN_DRAIN or GPIO_OPEN_SOURCE flag
144set in the machine file, or coming from other hardware descriptions.
145
146If this state can not be configured in hardware, i.e. if the GPIO hardware does
147not support open drain/open source in hardware, the GPIO library will instead
148use a trick: when a line is set as output, if the line is flagged as open
149drain, and the output value is negative, it will be driven low as usual. But
150if the output value is set to positive, it will instead *NOT* be driven high,
151instead it will be switched to input, as input mode is high impedance, thus
152achieveing an "open drain emulation" of sorts: electrically the behaviour will
153be identical, with the exception of possible hardware glitches when switching
154the mode of the line.
155
156For open source configuration the same principle is used, just that instead
157of actively driving the line low, it is set to input.
158
159
71GPIO drivers providing IRQs 160GPIO drivers providing IRQs
72--------------------------- 161---------------------------
73It is custom that GPIO drivers (GPIO chips) are also providing interrupts, 162It is custom that GPIO drivers (GPIO chips) are also providing interrupts,