gpio.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. Specifying GPIO information for devices
  2. ============================================
  3. 1) gpios property
  4. -----------------
  5. Nodes that makes use of GPIOs should specify them using one or more
  6. properties, each containing a 'gpio-list':
  7. gpio-list ::= <single-gpio> [gpio-list]
  8. single-gpio ::= <gpio-phandle> <gpio-specifier>
  9. gpio-phandle : phandle to gpio controller node
  10. gpio-specifier : Array of #gpio-cells specifying specific gpio
  11. (controller specific)
  12. GPIO properties should be named "[<name>-]gpios", with <name> being the purpose
  13. of this GPIO for the device. While a non-existent <name> is considered valid
  14. for compatibility reasons (resolving to the "gpios" property), it is not allowed
  15. for new bindings. Also, GPIO properties named "[<name>-]gpio" are valid and old
  16. bindings use it, but are only supported for compatibility reasons and should not
  17. be used for newer bindings since it has been deprecated.
  18. GPIO properties can contain one or more GPIO phandles, but only in exceptional
  19. cases should they contain more than one. If your device uses several GPIOs with
  20. distinct functions, reference each of them under its own property, giving it a
  21. meaningful name. The only case where an array of GPIOs is accepted is when
  22. several GPIOs serve the same function (e.g. a parallel data line).
  23. The exact purpose of each gpios property must be documented in the device tree
  24. binding of the device.
  25. The following example could be used to describe GPIO pins used as device enable
  26. and bit-banged data signals:
  27. gpio1: gpio1 {
  28. gpio-controller
  29. #gpio-cells = <2>;
  30. };
  31. gpio2: gpio2 {
  32. gpio-controller
  33. #gpio-cells = <1>;
  34. };
  35. [...]
  36. enable-gpios = <&gpio2 2>;
  37. data-gpios = <&gpio1 12 0>,
  38. <&gpio1 13 0>,
  39. <&gpio1 14 0>,
  40. <&gpio1 15 0>;
  41. Note that gpio-specifier length is controller dependent. In the
  42. above example, &gpio1 uses 2 cells to specify a gpio, while &gpio2
  43. only uses one.
  44. gpio-specifier may encode: bank, pin position inside the bank,
  45. whether pin is open-drain and whether pin is logically inverted.
  46. Exact meaning of each specifier cell is controller specific, and must
  47. be documented in the device tree binding for the device.
  48. Most controllers are however specifying a generic flag bitfield
  49. in the last cell, so for these, use the macros defined in
  50. include/dt-bindings/gpio/gpio.h whenever possible:
  51. Example of a node using GPIOs:
  52. node {
  53. enable-gpios = <&qe_pio_e 18 GPIO_ACTIVE_HIGH>;
  54. };
  55. GPIO_ACTIVE_HIGH is 0, so in this example gpio-specifier is "18 0" and encodes
  56. GPIO pin number, and GPIO flags as accepted by the "qe_pio_e" gpio-controller.
  57. Optional standard bitfield specifiers for the last cell:
  58. - Bit 0: 0 means active high, 1 means active low
  59. - Bit 1: 0 mean push-pull wiring, see:
  60. https://en.wikipedia.org/wiki/Push-pull_output
  61. 1 means single-ended wiring, see:
  62. https://en.wikipedia.org/wiki/Single-ended_triode
  63. - Bit 2: 0 means open-source, 1 means open drain, see:
  64. https://en.wikipedia.org/wiki/Open_collector
  65. - Bit 3: 0 means the output should be maintained during sleep/low-power mode
  66. 1 means the output state can be lost during sleep/low-power mode
  67. 1.1) GPIO specifier best practices
  68. ----------------------------------
  69. A gpio-specifier should contain a flag indicating the GPIO polarity; active-
  70. high or active-low. If it does, the following best practices should be
  71. followed:
  72. The gpio-specifier's polarity flag should represent the physical level at the
  73. GPIO controller that achieves (or represents, for inputs) a logically asserted
  74. value at the device. The exact definition of logically asserted should be
  75. defined by the binding for the device. If the board inverts the signal between
  76. the GPIO controller and the device, then the gpio-specifier will represent the
  77. opposite physical level than the signal at the device's pin.
  78. When the device's signal polarity is configurable, the binding for the
  79. device must either:
  80. a) Define a single static polarity for the signal, with the expectation that
  81. any software using that binding would statically program the device to use
  82. that signal polarity.
  83. The static choice of polarity may be either:
  84. a1) (Preferred) Dictated by a binding-specific DT property.
  85. or:
  86. a2) Defined statically by the DT binding itself.
  87. In particular, the polarity cannot be derived from the gpio-specifier, since
  88. that would prevent the DT from separately representing the two orthogonal
  89. concepts of configurable signal polarity in the device, and possible board-
  90. level signal inversion.
  91. or:
  92. b) Pick a single option for device signal polarity, and document this choice
  93. in the binding. The gpio-specifier should represent the polarity of the signal
  94. (at the GPIO controller) assuming that the device is configured for this
  95. particular signal polarity choice. If software chooses to program the device
  96. to generate or receive a signal of the opposite polarity, software will be
  97. responsible for correctly interpreting (inverting) the GPIO signal at the GPIO
  98. controller.
  99. 2) gpio-controller nodes
  100. ------------------------
  101. Every GPIO controller node must contain both an empty "gpio-controller"
  102. property, and a #gpio-cells integer property, which indicates the number of
  103. cells in a gpio-specifier.
  104. Some system-on-chips (SoCs) use the concept of GPIO banks. A GPIO bank is an
  105. instance of a hardware IP core on a silicon die, usually exposed to the
  106. programmer as a coherent range of I/O addresses. Usually each such bank is
  107. exposed in the device tree as an individual gpio-controller node, reflecting
  108. the fact that the hardware was synthesized by reusing the same IP block a
  109. few times over.
  110. Optionally, a GPIO controller may have a "ngpios" property. This property
  111. indicates the number of in-use slots of available slots for GPIOs. The
  112. typical example is something like this: the hardware register is 32 bits
  113. wide, but only 18 of the bits have a physical counterpart. The driver is
  114. generally written so that all 32 bits can be used, but the IP block is reused
  115. in a lot of designs, some using all 32 bits, some using 18 and some using
  116. 12. In this case, setting "ngpios = <18>;" informs the driver that only the
  117. first 18 GPIOs, at local offset 0 .. 17, are in use.
  118. If these GPIOs do not happen to be the first N GPIOs at offset 0...N-1, an
  119. additional set of tuples is needed to specify which GPIOs are unusable, with
  120. the gpio-reserved-ranges binding. This property indicates the start and size
  121. of the GPIOs that can't be used.
  122. Optionally, a GPIO controller may have a "gpio-line-names" property. This is
  123. an array of strings defining the names of the GPIO lines going out of the
  124. GPIO controller. This name should be the most meaningful producer name
  125. for the system, such as a rail name indicating the usage. Package names
  126. such as pin name are discouraged: such lines have opaque names (since they
  127. are by definition generic purpose) and such names are usually not very
  128. helpful. For example "MMC-CD", "Red LED Vdd" and "ethernet reset" are
  129. reasonable line names as they describe what the line is used for. "GPIO0"
  130. is not a good name to give to a GPIO line. Placeholders are discouraged:
  131. rather use the "" (blank string) if the use of the GPIO line is undefined
  132. in your design. The names are assigned starting from line offset 0 from
  133. left to right from the passed array. An incomplete array (where the number
  134. of passed named are less than ngpios) will still be used up until the last
  135. provided valid line index.
  136. Example:
  137. gpio-controller@00000000 {
  138. compatible = "foo";
  139. reg = <0x00000000 0x1000>;
  140. gpio-controller;
  141. #gpio-cells = <2>;
  142. ngpios = <18>;
  143. gpio-reserved-ranges = <0 4>, <12 2>;
  144. gpio-line-names = "MMC-CD", "MMC-WP", "VDD eth", "RST eth", "LED R",
  145. "LED G", "LED B", "Col A", "Col B", "Col C", "Col D",
  146. "Row A", "Row B", "Row C", "Row D", "NMI button",
  147. "poweroff", "reset";
  148. }
  149. The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism
  150. providing automatic GPIO request and configuration as part of the
  151. gpio-controller's driver probe function.
  152. Each GPIO hog definition is represented as a child node of the GPIO controller.
  153. Required properties:
  154. - gpio-hog: A property specifying that this child node represents a GPIO hog.
  155. - gpios: Store the GPIO information (id, flags, ...) for each GPIO to
  156. affect. Shall contain an integer multiple of the number of cells
  157. specified in its parent node (GPIO controller node).
  158. Only one of the following properties scanned in the order shown below.
  159. This means that when multiple properties are present they will be searched
  160. in the order presented below and the first match is taken as the intended
  161. configuration.
  162. - input: A property specifying to set the GPIO direction as input.
  163. - output-low A property specifying to set the GPIO direction as output with
  164. the value low.
  165. - output-high A property specifying to set the GPIO direction as output with
  166. the value high.
  167. Optional properties:
  168. - line-name: The GPIO label name. If not present the node name is used.
  169. Example of two SOC GPIO banks defined as gpio-controller nodes:
  170. qe_pio_a: gpio-controller@1400 {
  171. compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank";
  172. reg = <0x1400 0x18>;
  173. gpio-controller;
  174. #gpio-cells = <2>;
  175. line_b {
  176. gpio-hog;
  177. gpios = <6 0>;
  178. output-low;
  179. line-name = "foo-bar-gpio";
  180. };
  181. };
  182. qe_pio_e: gpio-controller@1460 {
  183. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  184. reg = <0x1460 0x18>;
  185. gpio-controller;
  186. #gpio-cells = <2>;
  187. };
  188. 2.1) gpio- and pin-controller interaction
  189. -----------------------------------------
  190. Some or all of the GPIOs provided by a GPIO controller may be routed to pins
  191. on the package via a pin controller. This allows muxing those pins between
  192. GPIO and other functions.
  193. It is useful to represent which GPIOs correspond to which pins on which pin
  194. controllers. The gpio-ranges property described below represents this, and
  195. contains information structures as follows:
  196. gpio-range-list ::= <single-gpio-range> [gpio-range-list]
  197. single-gpio-range ::= <numeric-gpio-range> | <named-gpio-range>
  198. numeric-gpio-range ::=
  199. <pinctrl-phandle> <gpio-base> <pinctrl-base> <count>
  200. named-gpio-range ::= <pinctrl-phandle> <gpio-base> '<0 0>'
  201. pinctrl-phandle : phandle to pin controller node
  202. gpio-base : Base GPIO ID in the GPIO controller
  203. pinctrl-base : Base pinctrl pin ID in the pin controller
  204. count : The number of GPIOs/pins in this range
  205. The "pin controller node" mentioned above must conform to the bindings
  206. described in ../pinctrl/pinctrl-bindings.txt.
  207. In case named gpio ranges are used (ranges with both <pinctrl-base> and
  208. <count> set to 0), the property gpio-ranges-group-names contains one string
  209. for every single-gpio-range in gpio-ranges:
  210. gpiorange-names-list ::= <gpiorange-name> [gpiorange-names-list]
  211. gpiorange-name : Name of the pingroup associated to the GPIO range in
  212. the respective pin controller.
  213. Elements of gpiorange-names-list corresponding to numeric ranges contain
  214. the empty string. Elements of gpiorange-names-list corresponding to named
  215. ranges contain the name of a pin group defined in the respective pin
  216. controller. The number of pins/GPIOs in the range is the number of pins in
  217. that pin group.
  218. Previous versions of this binding required all pin controller nodes that
  219. were referenced by any gpio-ranges property to contain a property named
  220. #gpio-range-cells with value <3>. This requirement is now deprecated.
  221. However, that property may still exist in older device trees for
  222. compatibility reasons, and would still be required even in new device
  223. trees that need to be compatible with older software.
  224. Example 1:
  225. qe_pio_e: gpio-controller@1460 {
  226. #gpio-cells = <2>;
  227. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  228. reg = <0x1460 0x18>;
  229. gpio-controller;
  230. gpio-ranges = <&pinctrl1 0 20 10>, <&pinctrl2 10 50 20>;
  231. };
  232. Here, a single GPIO controller has GPIOs 0..9 routed to pin controller
  233. pinctrl1's pins 20..29, and GPIOs 10..29 routed to pin controller pinctrl2's
  234. pins 50..69.
  235. Example 2:
  236. gpio_pio_i: gpio-controller@14b0 {
  237. #gpio-cells = <2>;
  238. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  239. reg = <0x1480 0x18>;
  240. gpio-controller;
  241. gpio-ranges = <&pinctrl1 0 20 10>,
  242. <&pinctrl2 10 0 0>,
  243. <&pinctrl1 15 0 10>,
  244. <&pinctrl2 25 0 0>;
  245. gpio-ranges-group-names = "",
  246. "foo",
  247. "",
  248. "bar";
  249. };
  250. Here, three GPIO ranges are defined wrt. two pin controllers. pinctrl1 GPIO
  251. ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2
  252. are named "foo" and "bar".