gpio-properties.txt 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. _DSD Device Properties Related to GPIO
  2. --------------------------------------
  3. With the release of ACPI 5.1, the _DSD configuration object finally
  4. allows names to be given to GPIOs (and other things as well) returned
  5. by _CRS. Previously, we were only able to use an integer index to find
  6. the corresponding GPIO, which is pretty error prone (it depends on
  7. the _CRS output ordering, for example).
  8. With _DSD we can now query GPIOs using a name instead of an integer
  9. index, like the ASL example below shows:
  10. // Bluetooth device with reset and shutdown GPIOs
  11. Device (BTH)
  12. {
  13. Name (_HID, ...)
  14. Name (_CRS, ResourceTemplate ()
  15. {
  16. GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
  17. "\\_SB.GPO0", 0, ResourceConsumer) {15}
  18. GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
  19. "\\_SB.GPO0", 0, ResourceConsumer) {27, 31}
  20. })
  21. Name (_DSD, Package ()
  22. {
  23. ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  24. Package ()
  25. {
  26. Package () {"reset-gpios", Package() {^BTH, 1, 1, 0 }},
  27. Package () {"shutdown-gpios", Package() {^BTH, 0, 0, 0 }},
  28. }
  29. })
  30. }
  31. The format of the supported GPIO property is:
  32. Package () { "name", Package () { ref, index, pin, active_low }}
  33. ref - The device that has _CRS containing GpioIo()/GpioInt() resources,
  34. typically this is the device itself (BTH in our case).
  35. index - Index of the GpioIo()/GpioInt() resource in _CRS starting from zero.
  36. pin - Pin in the GpioIo()/GpioInt() resource. Typically this is zero.
  37. active_low - If 1 the GPIO is marked as active_low.
  38. Since ACPI GpioIo() resource does not have a field saying whether it is
  39. active low or high, the "active_low" argument can be used here. Setting
  40. it to 1 marks the GPIO as active low.
  41. In our Bluetooth example the "reset-gpios" refers to the second GpioIo()
  42. resource, second pin in that resource with the GPIO number of 31.
  43. It is possible to leave holes in the array of GPIOs. This is useful in
  44. cases like with SPI host controllers where some chip selects may be
  45. implemented as GPIOs and some as native signals. For example a SPI host
  46. controller can have chip selects 0 and 2 implemented as GPIOs and 1 as
  47. native:
  48. Package () {
  49. "cs-gpios",
  50. Package () {
  51. ^GPIO, 19, 0, 0, // chip select 0: GPIO
  52. 0, // chip select 1: native signal
  53. ^GPIO, 20, 0, 0, // chip select 2: GPIO
  54. }
  55. }
  56. Other supported properties
  57. --------------------------
  58. Following Device Tree compatible device properties are also supported by
  59. _DSD device properties for GPIO controllers:
  60. - gpio-hog
  61. - output-high
  62. - output-low
  63. - input
  64. - line-name
  65. Example:
  66. Name (_DSD, Package () {
  67. // _DSD Hierarchical Properties Extension UUID
  68. ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
  69. Package () {
  70. Package () {"hog-gpio8", "G8PU"}
  71. }
  72. })
  73. Name (G8PU, Package () {
  74. ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  75. Package () {
  76. Package () {"gpio-hog", 1},
  77. Package () {"gpios", Package () {8, 0}},
  78. Package () {"output-high", 1},
  79. Package () {"line-name", "gpio8-pullup"},
  80. }
  81. })
  82. - gpio-line-names
  83. Example:
  84. Package () {
  85. "gpio-line-names",
  86. Package () {
  87. "SPI0_CS_N", "EXP2_INT", "MUX6_IO", "UART0_RXD", "MUX7_IO",
  88. "LVL_C_A1", "MUX0_IO", "SPI1_MISO"
  89. }
  90. }
  91. See Documentation/devicetree/bindings/gpio/gpio.txt for more information
  92. about these properties.
  93. ACPI GPIO Mappings Provided by Drivers
  94. --------------------------------------
  95. There are systems in which the ACPI tables do not contain _DSD but provide _CRS
  96. with GpioIo()/GpioInt() resources and device drivers still need to work with
  97. them.
  98. In those cases ACPI device identification objects, _HID, _CID, _CLS, _SUB, _HRV,
  99. available to the driver can be used to identify the device and that is supposed
  100. to be sufficient to determine the meaning and purpose of all of the GPIO lines
  101. listed by the GpioIo()/GpioInt() resources returned by _CRS. In other words,
  102. the driver is supposed to know what to use the GpioIo()/GpioInt() resources for
  103. once it has identified the device. Having done that, it can simply assign names
  104. to the GPIO lines it is going to use and provide the GPIO subsystem with a
  105. mapping between those names and the ACPI GPIO resources corresponding to them.
  106. To do that, the driver needs to define a mapping table as a NULL-terminated
  107. array of struct acpi_gpio_mapping objects that each contain a name, a pointer
  108. to an array of line data (struct acpi_gpio_params) objects and the size of that
  109. array. Each struct acpi_gpio_params object consists of three fields,
  110. crs_entry_index, line_index, active_low, representing the index of the target
  111. GpioIo()/GpioInt() resource in _CRS starting from zero, the index of the target
  112. line in that resource starting from zero, and the active-low flag for that line,
  113. respectively, in analogy with the _DSD GPIO property format specified above.
  114. For the example Bluetooth device discussed previously the data structures in
  115. question would look like this:
  116. static const struct acpi_gpio_params reset_gpio = { 1, 1, false };
  117. static const struct acpi_gpio_params shutdown_gpio = { 0, 0, false };
  118. static const struct acpi_gpio_mapping bluetooth_acpi_gpios[] = {
  119. { "reset-gpios", &reset_gpio, 1 },
  120. { "shutdown-gpios", &shutdown_gpio, 1 },
  121. { },
  122. };
  123. Next, the mapping table needs to be passed as the second argument to
  124. acpi_dev_add_driver_gpios() that will register it with the ACPI device object
  125. pointed to by its first argument. That should be done in the driver's .probe()
  126. routine. On removal, the driver should unregister its GPIO mapping table by
  127. calling acpi_dev_remove_driver_gpios() on the ACPI device object where that
  128. table was previously registered.
  129. Using the _CRS fallback
  130. -----------------------
  131. If a device does not have _DSD or the driver does not create ACPI GPIO
  132. mapping, the Linux GPIO framework refuses to return any GPIOs. This is
  133. because the driver does not know what it actually gets. For example if we
  134. have a device like below:
  135. Device (BTH)
  136. {
  137. Name (_HID, ...)
  138. Name (_CRS, ResourceTemplate () {
  139. GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone,
  140. "\\_SB.GPO0", 0, ResourceConsumer) {15}
  141. GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone,
  142. "\\_SB.GPO0", 0, ResourceConsumer) {27}
  143. })
  144. }
  145. The driver might expect to get the right GPIO when it does:
  146. desc = gpiod_get(dev, "reset", GPIOD_OUT_LOW);
  147. but since there is no way to know the mapping between "reset" and
  148. the GpioIo() in _CRS desc will hold ERR_PTR(-ENOENT).
  149. The driver author can solve this by passing the mapping explictly
  150. (the recommended way and documented in the above chapter).
  151. The ACPI GPIO mapping tables should not contaminate drivers that are not
  152. knowing about which exact device they are servicing on. It implies that
  153. the ACPI GPIO mapping tables are hardly linked to ACPI ID and certain
  154. objects, as listed in the above chapter, of the device in question.
  155. Getting GPIO descriptor
  156. -----------------------
  157. There are two main approaches to get GPIO resource from ACPI:
  158. desc = gpiod_get(dev, connection_id, flags);
  159. desc = gpiod_get_index(dev, connection_id, index, flags);
  160. We may consider two different cases here, i.e. when connection ID is
  161. provided and otherwise.
  162. Case 1:
  163. desc = gpiod_get(dev, "non-null-connection-id", flags);
  164. desc = gpiod_get_index(dev, "non-null-connection-id", index, flags);
  165. Case 2:
  166. desc = gpiod_get(dev, NULL, flags);
  167. desc = gpiod_get_index(dev, NULL, index, flags);
  168. Case 1 assumes that corresponding ACPI device description must have
  169. defined device properties and will prevent to getting any GPIO resources
  170. otherwise.
  171. Case 2 explicitly tells GPIO core to look for resources in _CRS.
  172. Be aware that gpiod_get_index() in cases 1 and 2, assuming that there
  173. are two versions of ACPI device description provided and no mapping is
  174. present in the driver, will return different resources. That's why a
  175. certain driver has to handle them carefully as explained in previous
  176. chapter.