gpio.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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.
  16. GPIO properties can contain one or more GPIO phandles, but only in exceptional
  17. cases should they contain more than one. If your device uses several GPIOs with
  18. distinct functions, reference each of them under its own property, giving it a
  19. meaningful name. The only case where an array of GPIOs is accepted is when
  20. several GPIOs serve the same function (e.g. a parallel data line).
  21. The exact purpose of each gpios property must be documented in the device tree
  22. binding of the device.
  23. The following example could be used to describe GPIO pins used as device enable
  24. and bit-banged data signals:
  25. gpio1: gpio1 {
  26. gpio-controller
  27. #gpio-cells = <2>;
  28. };
  29. gpio2: gpio2 {
  30. gpio-controller
  31. #gpio-cells = <1>;
  32. };
  33. [...]
  34. enable-gpios = <&gpio2 2>;
  35. data-gpios = <&gpio1 12 0>,
  36. <&gpio1 13 0>,
  37. <&gpio1 14 0>,
  38. <&gpio1 15 0>;
  39. Note that gpio-specifier length is controller dependent. In the
  40. above example, &gpio1 uses 2 cells to specify a gpio, while &gpio2
  41. only uses one.
  42. gpio-specifier may encode: bank, pin position inside the bank,
  43. whether pin is open-drain and whether pin is logically inverted.
  44. Exact meaning of each specifier cell is controller specific, and must
  45. be documented in the device tree binding for the device. Use the macros
  46. defined in include/dt-bindings/gpio/gpio.h whenever possible:
  47. Example of a node using GPIOs:
  48. node {
  49. enable-gpios = <&qe_pio_e 18 GPIO_ACTIVE_HIGH>;
  50. };
  51. GPIO_ACTIVE_HIGH is 0, so in this example gpio-specifier is "18 0" and encodes
  52. GPIO pin number, and GPIO flags as accepted by the "qe_pio_e" gpio-controller.
  53. 1.1) GPIO specifier best practices
  54. ----------------------------------
  55. A gpio-specifier should contain a flag indicating the GPIO polarity; active-
  56. high or active-low. If it does, the following best practices should be
  57. followed:
  58. The gpio-specifier's polarity flag should represent the physical level at the
  59. GPIO controller that achieves (or represents, for inputs) a logically asserted
  60. value at the device. The exact definition of logically asserted should be
  61. defined by the binding for the device. If the board inverts the signal between
  62. the GPIO controller and the device, then the gpio-specifier will represent the
  63. opposite physical level than the signal at the device's pin.
  64. When the device's signal polarity is configurable, the binding for the
  65. device must either:
  66. a) Define a single static polarity for the signal, with the expectation that
  67. any software using that binding would statically program the device to use
  68. that signal polarity.
  69. The static choice of polarity may be either:
  70. a1) (Preferred) Dictated by a binding-specific DT property.
  71. or:
  72. a2) Defined statically by the DT binding itself.
  73. In particular, the polarity cannot be derived from the gpio-specifier, since
  74. that would prevent the DT from separately representing the two orthogonal
  75. concepts of configurable signal polarity in the device, and possible board-
  76. level signal inversion.
  77. or:
  78. b) Pick a single option for device signal polarity, and document this choice
  79. in the binding. The gpio-specifier should represent the polarity of the signal
  80. (at the GPIO controller) assuming that the device is configured for this
  81. particular signal polarity choice. If software chooses to program the device
  82. to generate or receive a signal of the opposite polarity, software will be
  83. responsible for correctly interpreting (inverting) the GPIO signal at the GPIO
  84. controller.
  85. 2) gpio-controller nodes
  86. ------------------------
  87. Every GPIO controller node must contain both an empty "gpio-controller"
  88. property, and a #gpio-cells integer property, which indicates the number of
  89. cells in a gpio-specifier.
  90. Example of two SOC GPIO banks defined as gpio-controller nodes:
  91. qe_pio_a: gpio-controller@1400 {
  92. compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank";
  93. reg = <0x1400 0x18>;
  94. gpio-controller;
  95. #gpio-cells = <2>;
  96. };
  97. qe_pio_e: gpio-controller@1460 {
  98. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  99. reg = <0x1460 0x18>;
  100. gpio-controller;
  101. #gpio-cells = <2>;
  102. };
  103. 2.1) gpio- and pin-controller interaction
  104. -----------------------------------------
  105. Some or all of the GPIOs provided by a GPIO controller may be routed to pins
  106. on the package via a pin controller. This allows muxing those pins between
  107. GPIO and other functions.
  108. It is useful to represent which GPIOs correspond to which pins on which pin
  109. controllers. The gpio-ranges property described below represents this, and
  110. contains information structures as follows:
  111. gpio-range-list ::= <single-gpio-range> [gpio-range-list]
  112. single-gpio-range ::= <numeric-gpio-range> | <named-gpio-range>
  113. numeric-gpio-range ::=
  114. <pinctrl-phandle> <gpio-base> <pinctrl-base> <count>
  115. named-gpio-range ::= <pinctrl-phandle> <gpio-base> '<0 0>'
  116. pinctrl-phandle : phandle to pin controller node
  117. gpio-base : Base GPIO ID in the GPIO controller
  118. pinctrl-base : Base pinctrl pin ID in the pin controller
  119. count : The number of GPIOs/pins in this range
  120. The "pin controller node" mentioned above must conform to the bindings
  121. described in ../pinctrl/pinctrl-bindings.txt.
  122. In case named gpio ranges are used (ranges with both <pinctrl-base> and
  123. <count> set to 0), the property gpio-ranges-group-names contains one string
  124. for every single-gpio-range in gpio-ranges:
  125. gpiorange-names-list ::= <gpiorange-name> [gpiorange-names-list]
  126. gpiorange-name : Name of the pingroup associated to the GPIO range in
  127. the respective pin controller.
  128. Elements of gpiorange-names-list corresponding to numeric ranges contain
  129. the empty string. Elements of gpiorange-names-list corresponding to named
  130. ranges contain the name of a pin group defined in the respective pin
  131. controller. The number of pins/GPIOs in the range is the number of pins in
  132. that pin group.
  133. Previous versions of this binding required all pin controller nodes that
  134. were referenced by any gpio-ranges property to contain a property named
  135. #gpio-range-cells with value <3>. This requirement is now deprecated.
  136. However, that property may still exist in older device trees for
  137. compatibility reasons, and would still be required even in new device
  138. trees that need to be compatible with older software.
  139. Example 1:
  140. qe_pio_e: gpio-controller@1460 {
  141. #gpio-cells = <2>;
  142. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  143. reg = <0x1460 0x18>;
  144. gpio-controller;
  145. gpio-ranges = <&pinctrl1 0 20 10>, <&pinctrl2 10 50 20>;
  146. };
  147. Here, a single GPIO controller has GPIOs 0..9 routed to pin controller
  148. pinctrl1's pins 20..29, and GPIOs 10..19 routed to pin controller pinctrl2's
  149. pins 50..59.
  150. Example 2:
  151. gpio_pio_i: gpio-controller@14B0 {
  152. #gpio-cells = <2>;
  153. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  154. reg = <0x1480 0x18>;
  155. gpio-controller;
  156. gpio-ranges = <&pinctrl1 0 20 10>,
  157. <&pinctrl2 10 0 0>,
  158. <&pinctrl1 15 0 10>,
  159. <&pinctrl2 25 0 0>;
  160. gpio-ranges-group-names = "",
  161. "foo",
  162. "",
  163. "bar";
  164. };
  165. Here, three GPIO ranges are defined wrt. two pin controllers. pinctrl1 GPIO
  166. ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2
  167. are named "foo" and "bar".