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