aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/gpio.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/gpio.txt')
-rw-r--r--Documentation/gpio.txt36
1 files changed, 34 insertions, 2 deletions
diff --git a/Documentation/gpio.txt b/Documentation/gpio.txt
index 576ce463cf44..f8528db967fa 100644
--- a/Documentation/gpio.txt
+++ b/Documentation/gpio.txt
@@ -27,7 +27,7 @@ The exact capabilities of GPIOs vary between systems. Common options:
27 - Output values are writable (high=1, low=0). Some chips also have 27 - Output values are writable (high=1, low=0). Some chips also have
28 options about how that value is driven, so that for example only one 28 options about how that value is driven, so that for example only one
29 value might be driven ... supporting "wire-OR" and similar schemes 29 value might be driven ... supporting "wire-OR" and similar schemes
30 for the other value. 30 for the other value (notably, "open drain" signaling).
31 31
32 - Input values are likewise readable (1, 0). Some chips support readback 32 - Input values are likewise readable (1, 0). Some chips support readback
33 of pins configured as "output", which is very useful in such "wire-OR" 33 of pins configured as "output", which is very useful in such "wire-OR"
@@ -105,12 +105,15 @@ setting up a platform_device using the GPIO, is mark its direction:
105 105
106 /* set as input or output, returning 0 or negative errno */ 106 /* set as input or output, returning 0 or negative errno */
107 int gpio_direction_input(unsigned gpio); 107 int gpio_direction_input(unsigned gpio);
108 int gpio_direction_output(unsigned gpio); 108 int gpio_direction_output(unsigned gpio, int value);
109 109
110The return value is zero for success, else a negative errno. It should 110The return value is zero for success, else a negative errno. It should
111be checked, since the get/set calls don't have error returns and since 111be checked, since the get/set calls don't have error returns and since
112misconfiguration is possible. (These calls could sleep.) 112misconfiguration is possible. (These calls could sleep.)
113 113
114For output GPIOs, the value provided becomes the initial output value.
115This helps avoid signal glitching during system startup.
116
114Setting the direction can fail if the GPIO number is invalid, or when 117Setting the direction can fail if the GPIO number is invalid, or when
115that particular GPIO can't be used in that mode. It's generally a bad 118that particular GPIO can't be used in that mode. It's generally a bad
116idea to rely on boot firmware to have set the direction correctly, since 119idea to rely on boot firmware to have set the direction correctly, since
@@ -244,6 +247,35 @@ with gpio_get_value(), for example to initialize or update driver state
244when the IRQ is edge-triggered. 247when the IRQ is edge-triggered.
245 248
246 249
250Emulating Open Drain Signals
251----------------------------
252Sometimes shared signals need to use "open drain" signaling, where only the
253low signal level is actually driven. (That term applies to CMOS transistors;
254"open collector" is used for TTL.) A pullup resistor causes the high signal
255level. This is sometimes called a "wire-AND"; or more practically, from the
256negative logic (low=true) perspective this is a "wire-OR".
257
258One common example of an open drain signal is a shared active-low IRQ line.
259Also, bidirectional data bus signals sometimes use open drain signals.
260
261Some GPIO controllers directly support open drain outputs; many don't. When
262you need open drain signaling but your hardware doesn't directly support it,
263there's a common idiom you can use to emulate it with any GPIO pin that can
264be used as either an input or an output:
265
266 LOW: gpio_direction_output(gpio, 0) ... this drives the signal
267 and overrides the pullup.
268
269 HIGH: gpio_direction_input(gpio) ... this turns off the output,
270 so the pullup (or some other device) controls the signal.
271
272If you are "driving" the signal high but gpio_get_value(gpio) reports a low
273value (after the appropriate rise time passes), you know some other component
274is driving the shared signal low. That's not necessarily an error. As one
275common example, that's how I2C clocks are stretched: a slave that needs a
276slower clock delays the rising edge of SCK, and the I2C master adjusts its
277signaling rate accordingly.
278
247 279
248What do these conventions omit? 280What do these conventions omit?
249=============================== 281===============================