acpi_device.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Generation of tables for particular device types
  4. *
  5. * Copyright 2019 Google LLC
  6. * Mostly taken from coreboot file of the same name
  7. */
  8. #ifndef __ACPI_DEVICE_H
  9. #define __ACPI_DEVICE_H
  10. #include <linux/bitops.h>
  11. struct udevice;
  12. /* ACPI descriptor values for common descriptors: SERIAL_BUS means I2C */
  13. #define ACPI_DESCRIPTOR_LARGE BIT(7)
  14. #define ACPI_DESCRIPTOR_INTERRUPT (ACPI_DESCRIPTOR_LARGE | 9)
  15. #define ACPI_DESCRIPTOR_GPIO (ACPI_DESCRIPTOR_LARGE | 12)
  16. #define ACPI_DESCRIPTOR_SERIAL_BUS (ACPI_DESCRIPTOR_LARGE | 14)
  17. /* Length of a full path to an ACPI device */
  18. #define ACPI_PATH_MAX 30
  19. /* Values that can be returned for ACPI device _STA method */
  20. enum acpi_dev_status {
  21. ACPI_DSTATUS_PRESENT = BIT(0),
  22. ACPI_DSTATUS_ENABLED = BIT(1),
  23. ACPI_DSTATUS_SHOW_IN_UI = BIT(2),
  24. ACPI_DSTATUS_OK = BIT(3),
  25. ACPI_DSTATUS_HAS_BATTERY = BIT(4),
  26. ACPI_DSTATUS_ALL_OFF = 0,
  27. ACPI_DSTATUS_HIDDEN_ON = ACPI_DSTATUS_PRESENT | ACPI_DSTATUS_ENABLED |
  28. ACPI_DSTATUS_OK,
  29. ACPI_DSTATUS_ALL_ON = ACPI_DSTATUS_HIDDEN_ON |
  30. ACPI_DSTATUS_SHOW_IN_UI,
  31. };
  32. /** enum acpi_irq_mode - edge/level trigger mode */
  33. enum acpi_irq_mode {
  34. ACPI_IRQ_EDGE_TRIGGERED,
  35. ACPI_IRQ_LEVEL_TRIGGERED,
  36. };
  37. /**
  38. * enum acpi_irq_polarity - polarity of interrupt
  39. *
  40. * @ACPI_IRQ_ACTIVE_LOW - for ACPI_IRQ_EDGE_TRIGGERED this means falling edge
  41. * @ACPI_IRQ_ACTIVE_HIGH - for ACPI_IRQ_EDGE_TRIGGERED this means rising edge
  42. * @ACPI_IRQ_ACTIVE_BOTH - not meaningful for ACPI_IRQ_EDGE_TRIGGERED
  43. */
  44. enum acpi_irq_polarity {
  45. ACPI_IRQ_ACTIVE_LOW,
  46. ACPI_IRQ_ACTIVE_HIGH,
  47. ACPI_IRQ_ACTIVE_BOTH,
  48. };
  49. /**
  50. * enum acpi_irq_shared - whether interrupt is shared or not
  51. *
  52. * @ACPI_IRQ_EXCLUSIVE: only this device uses the interrupt
  53. * @ACPI_IRQ_SHARED: other devices may use this interrupt
  54. */
  55. enum acpi_irq_shared {
  56. ACPI_IRQ_EXCLUSIVE,
  57. ACPI_IRQ_SHARED,
  58. };
  59. /** enum acpi_irq_wake - indicates whether this interrupt can wake the device */
  60. enum acpi_irq_wake {
  61. ACPI_IRQ_NO_WAKE,
  62. ACPI_IRQ_WAKE,
  63. };
  64. /**
  65. * struct acpi_irq - representation of an ACPI interrupt
  66. *
  67. * @pin: ACPI pin that is monitored for the interrupt
  68. * @mode: Edge/level triggering
  69. * @polarity: Interrupt polarity
  70. * @shared: Whether interrupt is shared or not
  71. * @wake: Whether interrupt can wake the device from sleep
  72. */
  73. struct acpi_irq {
  74. unsigned int pin;
  75. enum acpi_irq_mode mode;
  76. enum acpi_irq_polarity polarity;
  77. enum acpi_irq_shared shared;
  78. enum acpi_irq_wake wake;
  79. };
  80. /**
  81. * acpi_device_path() - Get the full path to an ACPI device
  82. *
  83. * This gets the full path in the form XXXX.YYYY.ZZZZ where XXXX is the root
  84. * and ZZZZ is the device. All parent devices are added to the path.
  85. *
  86. * @dev: Device to check
  87. * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
  88. * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
  89. * @return 0 if OK, -ve on error
  90. */
  91. int acpi_device_path(const struct udevice *dev, char *buf, int maxlen);
  92. /**
  93. * acpi_device_scope() - Get the scope of an ACPI device
  94. *
  95. * This gets the scope which is the full path of the parent device, as per
  96. * acpi_device_path().
  97. *
  98. * @dev: Device to check
  99. * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
  100. * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
  101. * @return 0 if OK, -EINVAL if the device has no parent, other -ve on other
  102. * error
  103. */
  104. int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen);
  105. /**
  106. * acpi_device_status() - Get the status of a device
  107. *
  108. * This currently just returns ACPI_DSTATUS_ALL_ON. It does not support
  109. * inactive or hidden devices.
  110. *
  111. * @dev: Device to check
  112. * @return device status, as ACPI_DSTATUS_...
  113. */
  114. enum acpi_dev_status acpi_device_status(const struct udevice *dev);
  115. #endif