blob: 69b90968a8a8bbb29c41a0dd2603df7c8899a81e [file] [log] [blame]
Simon Glassebb2e832020-07-07 13:11:39 -06001/* 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 Glass8965cc92020-07-07 13:11:40 -060012#include <linux/bitops.h>
13
Simon Glass3d39c132020-07-07 13:11:43 -060014struct acpi_ctx;
15struct irq;
Simon Glassebb2e832020-07-07 13:11:39 -060016struct udevice;
17
Simon Glassb24cbf42020-07-07 13:11:41 -060018/* ACPI descriptor values for common descriptors: SERIAL_BUS means I2C */
19#define ACPI_DESCRIPTOR_LARGE BIT(7)
20#define ACPI_DESCRIPTOR_INTERRUPT (ACPI_DESCRIPTOR_LARGE | 9)
21#define ACPI_DESCRIPTOR_GPIO (ACPI_DESCRIPTOR_LARGE | 12)
22#define ACPI_DESCRIPTOR_SERIAL_BUS (ACPI_DESCRIPTOR_LARGE | 14)
23
Simon Glassebb2e832020-07-07 13:11:39 -060024/* Length of a full path to an ACPI device */
25#define ACPI_PATH_MAX 30
26
Simon Glass8965cc92020-07-07 13:11:40 -060027/* Values that can be returned for ACPI device _STA method */
28enum acpi_dev_status {
29 ACPI_DSTATUS_PRESENT = BIT(0),
30 ACPI_DSTATUS_ENABLED = BIT(1),
31 ACPI_DSTATUS_SHOW_IN_UI = BIT(2),
32 ACPI_DSTATUS_OK = BIT(3),
33 ACPI_DSTATUS_HAS_BATTERY = BIT(4),
34
35 ACPI_DSTATUS_ALL_OFF = 0,
36 ACPI_DSTATUS_HIDDEN_ON = ACPI_DSTATUS_PRESENT | ACPI_DSTATUS_ENABLED |
37 ACPI_DSTATUS_OK,
38 ACPI_DSTATUS_ALL_ON = ACPI_DSTATUS_HIDDEN_ON |
39 ACPI_DSTATUS_SHOW_IN_UI,
40};
41
Simon Glassb24cbf42020-07-07 13:11:41 -060042/** enum acpi_irq_mode - edge/level trigger mode */
43enum acpi_irq_mode {
44 ACPI_IRQ_EDGE_TRIGGERED,
45 ACPI_IRQ_LEVEL_TRIGGERED,
46};
47
48/**
49 * enum acpi_irq_polarity - polarity of interrupt
50 *
51 * @ACPI_IRQ_ACTIVE_LOW - for ACPI_IRQ_EDGE_TRIGGERED this means falling edge
52 * @ACPI_IRQ_ACTIVE_HIGH - for ACPI_IRQ_EDGE_TRIGGERED this means rising edge
53 * @ACPI_IRQ_ACTIVE_BOTH - not meaningful for ACPI_IRQ_EDGE_TRIGGERED
54 */
55enum acpi_irq_polarity {
56 ACPI_IRQ_ACTIVE_LOW,
57 ACPI_IRQ_ACTIVE_HIGH,
58 ACPI_IRQ_ACTIVE_BOTH,
59};
60
61/**
62 * enum acpi_irq_shared - whether interrupt is shared or not
63 *
64 * @ACPI_IRQ_EXCLUSIVE: only this device uses the interrupt
65 * @ACPI_IRQ_SHARED: other devices may use this interrupt
66 */
67enum acpi_irq_shared {
68 ACPI_IRQ_EXCLUSIVE,
69 ACPI_IRQ_SHARED,
70};
71
72/** enum acpi_irq_wake - indicates whether this interrupt can wake the device */
73enum acpi_irq_wake {
74 ACPI_IRQ_NO_WAKE,
75 ACPI_IRQ_WAKE,
76};
77
78/**
79 * struct acpi_irq - representation of an ACPI interrupt
80 *
81 * @pin: ACPI pin that is monitored for the interrupt
82 * @mode: Edge/level triggering
83 * @polarity: Interrupt polarity
84 * @shared: Whether interrupt is shared or not
85 * @wake: Whether interrupt can wake the device from sleep
86 */
87struct acpi_irq {
88 unsigned int pin;
89 enum acpi_irq_mode mode;
90 enum acpi_irq_polarity polarity;
91 enum acpi_irq_shared shared;
92 enum acpi_irq_wake wake;
93};
94
Simon Glassebb2e832020-07-07 13:11:39 -060095/**
Simon Glass3176b6c2020-07-07 13:11:44 -060096 * enum acpi_gpio_type - type of the descriptor
97 *
98 * @ACPI_GPIO_TYPE_INTERRUPT: GpioInterrupt
99 * @ACPI_GPIO_TYPE_IO: GpioIo
100 */
101enum acpi_gpio_type {
102 ACPI_GPIO_TYPE_INTERRUPT,
103 ACPI_GPIO_TYPE_IO,
104};
105
106/**
107 * enum acpi_gpio_pull - pull direction
108 *
109 * @ACPI_GPIO_PULL_DEFAULT: Use default value for pin
110 * @ACPI_GPIO_PULL_UP: Pull up
111 * @ACPI_GPIO_PULL_DOWN: Pull down
112 * @ACPI_GPIO_PULL_NONE: No pullup/pulldown
113 */
114enum acpi_gpio_pull {
115 ACPI_GPIO_PULL_DEFAULT,
116 ACPI_GPIO_PULL_UP,
117 ACPI_GPIO_PULL_DOWN,
118 ACPI_GPIO_PULL_NONE,
119};
120
121/**
122 * enum acpi_gpio_io_restrict - controls input/output of pin
123 *
124 * @ACPI_GPIO_IO_RESTRICT_NONE: no restrictions
125 * @ACPI_GPIO_IO_RESTRICT_INPUT: input only (no output)
126 * @ACPI_GPIO_IO_RESTRICT_OUTPUT: output only (no input)
127 * @ACPI_GPIO_IO_RESTRICT_PRESERVE: preserve settings when driver not active
128 */
129enum acpi_gpio_io_restrict {
130 ACPI_GPIO_IO_RESTRICT_NONE,
131 ACPI_GPIO_IO_RESTRICT_INPUT,
132 ACPI_GPIO_IO_RESTRICT_OUTPUT,
133 ACPI_GPIO_IO_RESTRICT_PRESERVE,
134};
135
136/** enum acpi_gpio_polarity - controls the GPIO polarity */
137enum acpi_gpio_polarity {
138 ACPI_GPIO_ACTIVE_HIGH = 0,
139 ACPI_GPIO_ACTIVE_LOW = 1,
140};
141
142#define ACPI_GPIO_REVISION_ID 1
143#define ACPI_GPIO_MAX_PINS 2
144
145/**
146 * struct acpi_gpio - representation of an ACPI GPIO
147 *
148 * @pin_count: Number of pins represented
149 * @pins: List of pins
150 * @pin0_addr: Address in memory of the control registers for pin 0. This is
151 * used when generating ACPI tables
152 * @type: GPIO type
153 * @pull: Pullup/pulldown setting
154 * @resource: Resource name for this GPIO controller
155 * For GpioInt:
156 * @interrupt_debounce_timeout: Debounce timeout in units of 10us
157 * @irq: Interrupt
158 *
159 * For GpioIo:
160 * @output_drive_strength: Drive strength in units of 10uA
161 * @io_shared; true if GPIO is shared
162 * @io_restrict: I/O restriction setting
163 * @polarity: GPIO polarity
164 */
165struct acpi_gpio {
166 int pin_count;
167 u16 pins[ACPI_GPIO_MAX_PINS];
168 ulong pin0_addr;
169
170 enum acpi_gpio_type type;
171 enum acpi_gpio_pull pull;
172 char resource[ACPI_PATH_MAX];
173
174 /* GpioInt */
175 u16 interrupt_debounce_timeout;
176 struct acpi_irq irq;
177
178 /* GpioIo */
179 u16 output_drive_strength;
180 bool io_shared;
181 enum acpi_gpio_io_restrict io_restrict;
182 enum acpi_gpio_polarity polarity;
183};
184
185/**
Simon Glassebb2e832020-07-07 13:11:39 -0600186 * acpi_device_path() - Get the full path to an ACPI device
187 *
188 * This gets the full path in the form XXXX.YYYY.ZZZZ where XXXX is the root
189 * and ZZZZ is the device. All parent devices are added to the path.
190 *
191 * @dev: Device to check
192 * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
193 * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
194 * @return 0 if OK, -ve on error
195 */
196int acpi_device_path(const struct udevice *dev, char *buf, int maxlen);
197
198/**
199 * acpi_device_scope() - Get the scope of an ACPI device
200 *
201 * This gets the scope which is the full path of the parent device, as per
202 * acpi_device_path().
203 *
204 * @dev: Device to check
205 * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
206 * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
207 * @return 0 if OK, -EINVAL if the device has no parent, other -ve on other
208 * error
209 */
210int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen);
211
Simon Glass8965cc92020-07-07 13:11:40 -0600212/**
213 * acpi_device_status() - Get the status of a device
214 *
215 * This currently just returns ACPI_DSTATUS_ALL_ON. It does not support
216 * inactive or hidden devices.
217 *
218 * @dev: Device to check
219 * @return device status, as ACPI_DSTATUS_...
220 */
221enum acpi_dev_status acpi_device_status(const struct udevice *dev);
222
Simon Glass3d39c132020-07-07 13:11:43 -0600223/**
224 * acpi_device_write_interrupt_irq() - Write an interrupt descriptor
225 *
226 * This writes an ACPI interrupt descriptor for the given interrupt, converting
227 * fields as needed.
228 *
229 * @ctx: ACPI context pointer
230 * @req_irq: Interrupt to output
231 * @return IRQ pin number if OK, -ve on error
232 */
233int acpi_device_write_interrupt_irq(struct acpi_ctx *ctx,
234 const struct irq *req_irq);
235
Simon Glassebb2e832020-07-07 13:11:39 -0600236#endif