gpio.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. Optionally, a GPIO controller may have a "ngpios" property. This property
  102. indicates the number of in-use slots of available slots for GPIOs. The
  103. typical example is something like this: the hardware register is 32 bits
  104. wide, but only 18 of the bits have a physical counterpart. The driver is
  105. generally written so that all 32 bits can be used, but the IP block is reused
  106. in a lot of designs, some using all 32 bits, some using 18 and some using
  107. 12. In this case, setting "ngpios = <18>;" informs the driver that only the
  108. first 18 GPIOs, at local offset 0 .. 17, are in use.
  109. If these GPIOs do not happen to be the first N GPIOs at offset 0...N-1, an
  110. additional bitmask is needed to specify which GPIOs are actually in use,
  111. and which are dummies. The bindings for this case has not yet been
  112. specified, but should be specified if/when such hardware appears.
  113. Example:
  114. gpio-controller@00000000 {
  115. compatible = "foo";
  116. reg = <0x00000000 0x1000>;
  117. gpio-controller;
  118. #gpio-cells = <2>;
  119. ngpios = <18>;
  120. }
  121. The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism
  122. providing automatic GPIO request and configuration as part of the
  123. gpio-controller's driver probe function.
  124. Each GPIO hog definition is represented as a child node of the GPIO controller.
  125. Required properties:
  126. - gpio-hog: A property specifying that this child node represent a GPIO hog.
  127. - gpios: Store the GPIO information (id, flags, ...). Shall contain the
  128. number of cells specified in its parent node (GPIO controller
  129. node).
  130. Only one of the following properties scanned in the order shown below.
  131. This means that when multiple properties are present they will be searched
  132. in the order presented below and the first match is taken as the intended
  133. configuration.
  134. - input: A property specifying to set the GPIO direction as input.
  135. - output-low A property specifying to set the GPIO direction as output with
  136. the value low.
  137. - output-high A property specifying to set the GPIO direction as output with
  138. the value high.
  139. Optional properties:
  140. - line-name: The GPIO label name. If not present the node name is used.
  141. Example of two SOC GPIO banks defined as gpio-controller nodes:
  142. qe_pio_a: gpio-controller@1400 {
  143. compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank";
  144. reg = <0x1400 0x18>;
  145. gpio-controller;
  146. #gpio-cells = <2>;
  147. line_b {
  148. gpio-hog;
  149. gpios = <6 0>;
  150. output-low;
  151. line-name = "foo-bar-gpio";
  152. };
  153. };
  154. qe_pio_e: gpio-controller@1460 {
  155. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  156. reg = <0x1460 0x18>;
  157. gpio-controller;
  158. #gpio-cells = <2>;
  159. };
  160. 2.1) gpio- and pin-controller interaction
  161. -----------------------------------------
  162. Some or all of the GPIOs provided by a GPIO controller may be routed to pins
  163. on the package via a pin controller. This allows muxing those pins between
  164. GPIO and other functions.
  165. It is useful to represent which GPIOs correspond to which pins on which pin
  166. controllers. The gpio-ranges property described below represents this, and
  167. contains information structures as follows:
  168. gpio-range-list ::= <single-gpio-range> [gpio-range-list]
  169. single-gpio-range ::= <numeric-gpio-range> | <named-gpio-range>
  170. numeric-gpio-range ::=
  171. <pinctrl-phandle> <gpio-base> <pinctrl-base> <count>
  172. named-gpio-range ::= <pinctrl-phandle> <gpio-base> '<0 0>'
  173. pinctrl-phandle : phandle to pin controller node
  174. gpio-base : Base GPIO ID in the GPIO controller
  175. pinctrl-base : Base pinctrl pin ID in the pin controller
  176. count : The number of GPIOs/pins in this range
  177. The "pin controller node" mentioned above must conform to the bindings
  178. described in ../pinctrl/pinctrl-bindings.txt.
  179. In case named gpio ranges are used (ranges with both <pinctrl-base> and
  180. <count> set to 0), the property gpio-ranges-group-names contains one string
  181. for every single-gpio-range in gpio-ranges:
  182. gpiorange-names-list ::= <gpiorange-name> [gpiorange-names-list]
  183. gpiorange-name : Name of the pingroup associated to the GPIO range in
  184. the respective pin controller.
  185. Elements of gpiorange-names-list corresponding to numeric ranges contain
  186. the empty string. Elements of gpiorange-names-list corresponding to named
  187. ranges contain the name of a pin group defined in the respective pin
  188. controller. The number of pins/GPIOs in the range is the number of pins in
  189. that pin group.
  190. Previous versions of this binding required all pin controller nodes that
  191. were referenced by any gpio-ranges property to contain a property named
  192. #gpio-range-cells with value <3>. This requirement is now deprecated.
  193. However, that property may still exist in older device trees for
  194. compatibility reasons, and would still be required even in new device
  195. trees that need to be compatible with older software.
  196. Example 1:
  197. qe_pio_e: gpio-controller@1460 {
  198. #gpio-cells = <2>;
  199. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  200. reg = <0x1460 0x18>;
  201. gpio-controller;
  202. gpio-ranges = <&pinctrl1 0 20 10>, <&pinctrl2 10 50 20>;
  203. };
  204. Here, a single GPIO controller has GPIOs 0..9 routed to pin controller
  205. pinctrl1's pins 20..29, and GPIOs 10..19 routed to pin controller pinctrl2's
  206. pins 50..59.
  207. Example 2:
  208. gpio_pio_i: gpio-controller@14B0 {
  209. #gpio-cells = <2>;
  210. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  211. reg = <0x1480 0x18>;
  212. gpio-controller;
  213. gpio-ranges = <&pinctrl1 0 20 10>,
  214. <&pinctrl2 10 0 0>,
  215. <&pinctrl1 15 0 10>,
  216. <&pinctrl2 25 0 0>;
  217. gpio-ranges-group-names = "",
  218. "foo",
  219. "",
  220. "bar";
  221. };
  222. Here, three GPIO ranges are defined wrt. two pin controllers. pinctrl1 GPIO
  223. ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2
  224. are named "foo" and "bar".