gpio.txt 12 KB

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