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