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

gpio: clarify open drain/source docs

Make the text clearer, remove reference to confusing "positive"
and "negative" and elaborate a bit.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+14 -6
+14 -6
Documentation/gpio/driver.txt
··· 100 100 resistor will make the line tend to high level unless one of the transistors on 101 101 the rail actively pulls it down. 102 102 103 + The level on the line will go as high as the VDD on the pull-up resistor, which 104 + may be higher than the level supported by the transistor, achieveing a 105 + level-shift to the higher VDD. 106 + 103 107 Integrated electronics often have an output driver stage in the form of a CMOS 104 108 "totem-pole" with one N-MOS and one P-MOS transistor where one of them drives 105 109 the line high and one of them drives the line low. This is called a push-pull ··· 114 110 OD ||--+ 115 111 +--/ ---o|| P-MOS-FET 116 112 | ||--+ 117 - in --+ +----- out 113 + IN --+ +----- out 118 114 | ||--+ 119 115 +--/ ----|| N-MOS-FET 120 116 OS ||--+ 121 117 | 122 118 GND 123 119 124 - You see the little "switches" named "OD" and "OS" that enable/disable the 120 + The desired output signal (e.g. coming directly from some GPIO output register) 121 + arrives at IN. The switches named "OD" and "OS" are normally closed, creating 122 + a push-pull circuit. 123 + 124 + Consider the little "switches" named "OD" and "OS" that enable/disable the 125 125 P-MOS or N-MOS transistor right after the split of the input. As you can see, 126 126 either transistor will go totally numb if this switch is open. The totem-pole 127 127 is then halved and give high impedance instead of actively driving the line ··· 136 128 hard-wired lines that will only support open drain or open source no matter 137 129 what: there is only one transistor there. Some are software-configurable: 138 130 by flipping a bit in a register the output can be configured as open drain 139 - or open source, by flicking open the switches labeled "OD" and "OS" in the 140 - drawing above. 131 + or open source, in practice by flicking open the switches labeled "OD" and "OS" 132 + in the drawing above. 141 133 142 134 By disabling the P-MOS transistor, the output can be driven between GND and 143 135 high impedance (open drain), and by disabling the N-MOS transistor, the output ··· 154 146 If this state can not be configured in hardware, i.e. if the GPIO hardware does 155 147 not support open drain/open source in hardware, the GPIO library will instead 156 148 use a trick: when a line is set as output, if the line is flagged as open 157 - drain, and the output value is negative, it will be driven low as usual. But 158 - if the output value is set to positive, it will instead *NOT* be driven high, 149 + drain, and the IN output value is low, it will be driven low as usual. But 150 + if the IN output value is set to high, it will instead *NOT* be driven high, 159 151 instead it will be switched to input, as input mode is high impedance, thus 160 152 achieveing an "open drain emulation" of sorts: electrically the behaviour will 161 153 be identical, with the exception of possible hardware glitches when switching