1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Generation of tables for particular device types
5 * Copyright 2019 Google LLC
6 * Mostly taken from coreboot file of the same name
9 #ifndef __ACPI_DEVICE_H
10 #define __ACPI_DEVICE_H
14 #include <linux/bitops.h>
21 /* ACPI descriptor values for common descriptors: SERIAL_BUS means I2C */
22 #define ACPI_DESCRIPTOR_LARGE BIT(7)
23 #define ACPI_DESCRIPTOR_REGISTER (ACPI_DESCRIPTOR_LARGE | 2)
24 #define ACPI_DESCRIPTOR_INTERRUPT (ACPI_DESCRIPTOR_LARGE | 9)
25 #define ACPI_DESCRIPTOR_GPIO (ACPI_DESCRIPTOR_LARGE | 12)
26 #define ACPI_DESCRIPTOR_SERIAL_BUS (ACPI_DESCRIPTOR_LARGE | 14)
28 /* Length of a full path to an ACPI device */
29 #define ACPI_PATH_MAX 30
31 /* Values that can be returned for ACPI device _STA method */
32 enum acpi_dev_status {
33 ACPI_DSTATUS_PRESENT = BIT(0),
34 ACPI_DSTATUS_ENABLED = BIT(1),
35 ACPI_DSTATUS_SHOW_IN_UI = BIT(2),
36 ACPI_DSTATUS_OK = BIT(3),
37 ACPI_DSTATUS_HAS_BATTERY = BIT(4),
39 ACPI_DSTATUS_ALL_OFF = 0,
40 ACPI_DSTATUS_HIDDEN_ON = ACPI_DSTATUS_PRESENT | ACPI_DSTATUS_ENABLED |
42 ACPI_DSTATUS_ALL_ON = ACPI_DSTATUS_HIDDEN_ON |
43 ACPI_DSTATUS_SHOW_IN_UI,
46 /** enum acpi_irq_mode - edge/level trigger mode */
48 ACPI_IRQ_EDGE_TRIGGERED,
49 ACPI_IRQ_LEVEL_TRIGGERED,
53 * enum acpi_irq_polarity - polarity of interrupt
55 * @ACPI_IRQ_ACTIVE_LOW - for ACPI_IRQ_EDGE_TRIGGERED this means falling edge
56 * @ACPI_IRQ_ACTIVE_HIGH - for ACPI_IRQ_EDGE_TRIGGERED this means rising edge
57 * @ACPI_IRQ_ACTIVE_BOTH - not meaningful for ACPI_IRQ_EDGE_TRIGGERED
59 enum acpi_irq_polarity {
66 * enum acpi_irq_shared - whether interrupt is shared or not
68 * @ACPI_IRQ_EXCLUSIVE: only this device uses the interrupt
69 * @ACPI_IRQ_SHARED: other devices may use this interrupt
71 enum acpi_irq_shared {
76 /** enum acpi_irq_wake - indicates whether this interrupt can wake the device */
83 * struct acpi_irq - representation of an ACPI interrupt
85 * @pin: ACPI pin that is monitored for the interrupt
86 * @mode: Edge/level triggering
87 * @polarity: Interrupt polarity
88 * @shared: Whether interrupt is shared or not
89 * @wake: Whether interrupt can wake the device from sleep
93 enum acpi_irq_mode mode;
94 enum acpi_irq_polarity polarity;
95 enum acpi_irq_shared shared;
96 enum acpi_irq_wake wake;
100 * enum acpi_gpio_type - type of the descriptor
102 * @ACPI_GPIO_TYPE_INTERRUPT: GpioInterrupt
103 * @ACPI_GPIO_TYPE_IO: GpioIo
105 enum acpi_gpio_type {
106 ACPI_GPIO_TYPE_INTERRUPT,
111 * enum acpi_gpio_pull - pull direction
113 * @ACPI_GPIO_PULL_DEFAULT: Use default value for pin
114 * @ACPI_GPIO_PULL_UP: Pull up
115 * @ACPI_GPIO_PULL_DOWN: Pull down
116 * @ACPI_GPIO_PULL_NONE: No pullup/pulldown
118 enum acpi_gpio_pull {
119 ACPI_GPIO_PULL_DEFAULT,
126 * enum acpi_gpio_io_restrict - controls input/output of pin
128 * @ACPI_GPIO_IO_RESTRICT_NONE: no restrictions
129 * @ACPI_GPIO_IO_RESTRICT_INPUT: input only (no output)
130 * @ACPI_GPIO_IO_RESTRICT_OUTPUT: output only (no input)
131 * @ACPI_GPIO_IO_RESTRICT_PRESERVE: preserve settings when driver not active
133 enum acpi_gpio_io_restrict {
134 ACPI_GPIO_IO_RESTRICT_NONE,
135 ACPI_GPIO_IO_RESTRICT_INPUT,
136 ACPI_GPIO_IO_RESTRICT_OUTPUT,
137 ACPI_GPIO_IO_RESTRICT_PRESERVE,
140 /** enum acpi_gpio_polarity - controls the GPIO polarity */
141 enum acpi_gpio_polarity {
142 ACPI_GPIO_ACTIVE_HIGH = 0,
143 ACPI_GPIO_ACTIVE_LOW = 1,
146 #define ACPI_GPIO_REVISION_ID 1
147 #define ACPI_GPIO_MAX_PINS 2
150 * struct acpi_gpio - representation of an ACPI GPIO
152 * @pin_count: Number of pins represented
153 * @pins: List of pins
154 * @pin0_addr: Address in memory of the control registers for pin 0. This is
155 * used when generating ACPI tables
157 * @pull: Pullup/pulldown setting
158 * @resource: Resource name for this GPIO controller
160 * @interrupt_debounce_timeout: Debounce timeout in units of 10us
164 * @output_drive_strength: Drive strength in units of 10uA
165 * @io_shared; true if GPIO is shared
166 * @io_restrict: I/O restriction setting
167 * @polarity: GPIO polarity
171 u16 pins[ACPI_GPIO_MAX_PINS];
174 enum acpi_gpio_type type;
175 enum acpi_gpio_pull pull;
176 char resource[ACPI_PATH_MAX];
179 u16 interrupt_debounce_timeout;
183 u16 output_drive_strength;
185 enum acpi_gpio_io_restrict io_restrict;
186 enum acpi_gpio_polarity polarity;
189 /* ACPI Descriptors for Serial Bus interfaces */
190 #define ACPI_SERIAL_BUS_TYPE_I2C 1
191 #define ACPI_SERIAL_BUS_TYPE_SPI 2
192 #define ACPI_I2C_SERIAL_BUS_REVISION_ID 1 /* TODO: upgrade to 2 */
193 #define ACPI_I2C_TYPE_SPECIFIC_REVISION_ID 1
194 #define ACPI_SPI_SERIAL_BUS_REVISION_ID 1
195 #define ACPI_SPI_TYPE_SPECIFIC_REVISION_ID 1
198 * struct acpi_i2c - representation of an ACPI I2C device
200 * @address: 7-bit or 10-bit I2C address
201 * @mode_10bit: Which address size is used
202 * @speed: Bus speed in Hz
203 * @resource: Resource name for the I2C controller
207 enum i2c_address_mode mode_10bit;
208 enum i2c_speed_rate speed;
209 const char *resource;
213 * struct acpi_spi - representation of an ACPI SPI device
215 * @device_select: Chip select used by this device (typically 0)
216 * @device_select_polarity: Polarity for the device
217 * @wire_mode: Number of wires used for SPI
218 * @speed: Bus speed in Hz
219 * @data_bit_length: Word length for SPI (typically 8)
220 * @clock_phase: Clock phase to capture data
221 * @clock_polarity: Bus polarity
222 * @resource: Resource name for the SPI controller
226 enum spi_polarity device_select_polarity;
227 enum spi_wire_mode wire_mode;
230 enum spi_clock_phase clock_phase;
231 enum spi_polarity clock_polarity;
232 const char *resource;
236 * acpi_device_path() - Get the full path to an ACPI device
238 * This gets the full path in the form XXXX.YYYY.ZZZZ where XXXX is the root
239 * and ZZZZ is the device. All parent devices are added to the path.
241 * @dev: Device to check
242 * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
243 * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
244 * @return 0 if OK, -ve on error
246 int acpi_device_path(const struct udevice *dev, char *buf, int maxlen);
249 * acpi_device_scope() - Get the scope of an ACPI device
251 * This gets the scope which is the full path of the parent device, as per
252 * acpi_device_path().
254 * @dev: Device to check
255 * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
256 * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
257 * @return 0 if OK, -EINVAL if the device has no parent, other -ve on other
260 int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen);
263 * acpi_device_status() - Get the status of a device
265 * This currently just returns ACPI_DSTATUS_ALL_ON. It does not support
266 * inactive or hidden devices.
268 * @dev: Device to check
269 * @return device status, as ACPI_DSTATUS_...
271 enum acpi_dev_status acpi_device_status(const struct udevice *dev);
274 * acpi_device_write_interrupt_irq() - Write an interrupt descriptor
276 * This writes an ACPI interrupt descriptor for the given interrupt, converting
279 * @ctx: ACPI context pointer
280 * @req_irq: Interrupt to output
281 * @return IRQ pin number if OK, -ve on error
283 int acpi_device_write_interrupt_irq(struct acpi_ctx *ctx,
284 const struct irq *req_irq);
287 * acpi_device_write_gpio() - Write GpioIo() or GpioInt() descriptor
289 * @gpio: GPIO information to write
290 * @return GPIO pin number of first GPIO if OK, -ve on error
292 int acpi_device_write_gpio(struct acpi_ctx *ctx, const struct acpi_gpio *gpio);
295 * acpi_device_write_gpio_desc() - Write a GPIO to ACPI
297 * This creates a GPIO descriptor for a GPIO, including information ACPI needs
300 * @ctx: ACPI context pointer
301 * @desc: GPIO to write
302 * @return 0 if OK, -ve on error
304 int acpi_device_write_gpio_desc(struct acpi_ctx *ctx,
305 const struct gpio_desc *desc);
308 * acpi_device_write_interrupt_or_gpio() - Write interrupt or GPIO to ACPI
310 * This reads an interrupt from the device tree "interrupts-extended" property,
311 * if available. If not it reads the first GPIO with the name @prop.
313 * If an interrupt is found, an ACPI interrupt descriptor is written to the ACPI
314 * output. If not, but if a GPIO is found, a GPIO descriptor is written.
316 * @return irq or GPIO pin number if OK, -ve if neither an interrupt nor a GPIO
317 * could be found, or some other error occurred
319 int acpi_device_write_interrupt_or_gpio(struct acpi_ctx *ctx,
320 struct udevice *dev, const char *prop);
323 * acpi_device_write_i2c_dev() - Write an I2C device to ACPI
325 * This creates a I2cSerialBus descriptor for an I2C device, including
326 * information ACPI needs to use it.
328 * @ctx: ACPI context pointer
329 * @dev: I2C device to write
330 * @return I2C address of device if OK, -ve on error
332 int acpi_device_write_i2c_dev(struct acpi_ctx *ctx, const struct udevice *dev);
335 * acpi_device_write_spi_dev() - Write a SPI device to ACPI
337 * This writes a serial bus descriptor for the SPI device so that ACPI can use
340 * @ctx: ACPI context pointer
341 * @dev: SPI device to write
342 * @return 0 if OK, -ve on error
344 int acpi_device_write_spi_dev(struct acpi_ctx *ctx, const struct udevice *dev);
347 * acpi_device_add_power_res() - Add a basic PowerResource block for a device
349 * This includes GPIOs to control enable, reset and stop operation of the
350 * device. Each GPIO is optional, but at least one must be provided.
351 * This can be applied to any device that has power control, so is fairly
354 * Reset - Put the device into / take the device out of reset.
355 * Enable - Enable / disable power to device.
356 * Stop - Stop / start operation of device.
358 * @ctx: ACPI context pointer
359 * @tx_state_val: Mask to use to toggle the TX state on the GPIO pin, e,g.
361 * @dw0_read: Name to use to read dw0, e.g. "\\_SB.GPC0"
362 * @dw0_write: Name to use to read dw0, e.g. "\\_SB.SPC0"
363 * @reset_gpio: GPIO used to take device out of reset or to put it into reset
364 * @reset_delay_ms: Delay to be inserted after device is taken out of reset
366 * @reset_off_delay_ms: Delay to be inserted after device is put into reset
367 * (_OFF method delay)
368 * @enable_gpio: GPIO used to enable device
369 * @enable_delay_ms: Delay to be inserted after device is enabled
370 * @enable_off_delay_ms: Delay to be inserted after device is disabled
371 * (_OFF method delay)
372 * @stop_gpio: GPIO used to stop operation of device
373 * @stop_delay_ms: Delay to be inserted after disabling stop (_ON method delay)
374 * @stop_off_delay_ms: Delay to be inserted after enabling stop.
375 * (_OFF method delay)
377 * @return 0 if OK, -ve if at least one GPIO is not provided
379 int acpi_device_add_power_res(struct acpi_ctx *ctx, u32 tx_state_val,
380 const char *dw0_read, const char *dw0_write,
381 const struct gpio_desc *reset_gpio,
382 uint reset_delay_ms, uint reset_off_delay_ms,
383 const struct gpio_desc *enable_gpio,
384 uint enable_delay_ms, uint enable_off_delay_ms,
385 const struct gpio_desc *stop_gpio,
386 uint stop_delay_ms, uint stop_off_delay_ms);
389 * acpi_device_infer_name() - Infer the name from its uclass or parent
391 * Many ACPI devices have a standard name that can be inferred from the uclass
392 * they are in, or the uclass of their parent. These rules are implemented in
393 * this function. It attempts to produce a name for a device based on these
396 * NOTE: This currently supports only x86 devices. Feel free to enhance it for
397 * other architectures as needed.
399 * @dev: Device to check
400 * @out_name: Place to put the name (must hold ACPI_NAME_MAX bytes)
401 * @return 0 if a name was found, -ENOENT if not found, -ENXIO if the device
402 * sequence number could not be determined
404 int acpi_device_infer_name(const struct udevice *dev, char *out_name);