gpio.txt 7.0 KB

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