gpio-properties.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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-gpio", Package() {^BTH, 1, 1, 0 }},
  27. Package () {"shutdown-gpio", 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-gpio" refers to the second GpioIo()
  42. resource, second pin in that resource with the GPIO number of 31.
  43. ACPI GPIO Mappings Provided by Drivers
  44. --------------------------------------
  45. There are systems in which the ACPI tables do not contain _DSD but provide _CRS
  46. with GpioIo()/GpioInt() resources and device drivers still need to work with
  47. them.
  48. In those cases ACPI device identification objects, _HID, _CID, _CLS, _SUB, _HRV,
  49. available to the driver can be used to identify the device and that is supposed
  50. to be sufficient to determine the meaning and purpose of all of the GPIO lines
  51. listed by the GpioIo()/GpioInt() resources returned by _CRS. In other words,
  52. the driver is supposed to know what to use the GpioIo()/GpioInt() resources for
  53. once it has identified the device. Having done that, it can simply assign names
  54. to the GPIO lines it is going to use and provide the GPIO subsystem with a
  55. mapping between those names and the ACPI GPIO resources corresponding to them.
  56. To do that, the driver needs to define a mapping table as a NULL-terminated
  57. array of struct acpi_gpio_mapping objects that each contain a name, a pointer
  58. to an array of line data (struct acpi_gpio_params) objects and the size of that
  59. array. Each struct acpi_gpio_params object consists of three fields,
  60. crs_entry_index, line_index, active_low, representing the index of the target
  61. GpioIo()/GpioInt() resource in _CRS starting from zero, the index of the target
  62. line in that resource starting from zero, and the active-low flag for that line,
  63. respectively, in analogy with the _DSD GPIO property format specified above.
  64. For the example Bluetooth device discussed previously the data structures in
  65. question would look like this:
  66. static const struct acpi_gpio_params reset_gpio = { 1, 1, false };
  67. static const struct acpi_gpio_params shutdown_gpio = { 0, 0, false };
  68. static const struct acpi_gpio_mapping bluetooth_acpi_gpios[] = {
  69. { "reset-gpio", &reset_gpio, 1 },
  70. { "shutdown-gpio", &shutdown_gpio, 1 },
  71. { },
  72. };
  73. Next, the mapping table needs to be passed as the second argument to
  74. acpi_dev_add_driver_gpios() that will register it with the ACPI device object
  75. pointed to by its first argument. That should be done in the driver's .probe()
  76. routine. On removal, the driver should unregister its GPIO mapping table by
  77. calling acpi_dev_remove_driver_gpios() on the ACPI device object where that
  78. table was previously registered.