blob: e72fede54cec8c9f081e4eb1db8927408ea387b1 [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/**
96 * acpi_device_path() - Get the full path to an ACPI device
97 *
98 * This gets the full path in the form XXXX.YYYY.ZZZZ where XXXX is the root
99 * and ZZZZ is the device. All parent devices are added to the path.
100 *
101 * @dev: Device to check
102 * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
103 * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
104 * @return 0 if OK, -ve on error
105 */
106int acpi_device_path(const struct udevice *dev, char *buf, int maxlen);
107
108/**
109 * acpi_device_scope() - Get the scope of an ACPI device
110 *
111 * This gets the scope which is the full path of the parent device, as per
112 * acpi_device_path().
113 *
114 * @dev: Device to check
115 * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
116 * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
117 * @return 0 if OK, -EINVAL if the device has no parent, other -ve on other
118 * error
119 */
120int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen);
121
Simon Glass8965cc92020-07-07 13:11:40 -0600122/**
123 * acpi_device_status() - Get the status of a device
124 *
125 * This currently just returns ACPI_DSTATUS_ALL_ON. It does not support
126 * inactive or hidden devices.
127 *
128 * @dev: Device to check
129 * @return device status, as ACPI_DSTATUS_...
130 */
131enum acpi_dev_status acpi_device_status(const struct udevice *dev);
132
Simon Glass3d39c132020-07-07 13:11:43 -0600133/**
134 * acpi_device_write_interrupt_irq() - Write an interrupt descriptor
135 *
136 * This writes an ACPI interrupt descriptor for the given interrupt, converting
137 * fields as needed.
138 *
139 * @ctx: ACPI context pointer
140 * @req_irq: Interrupt to output
141 * @return IRQ pin number if OK, -ve on error
142 */
143int acpi_device_write_interrupt_irq(struct acpi_ctx *ctx,
144 const struct irq *req_irq);
145
Simon Glassebb2e832020-07-07 13:11:39 -0600146#endif