Debian Codegraph @

src/ec/google/wilco/acpi/ec.asl

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 Name (RD, 0)
4 Name (WR, 1)
5
6 Device (EC0)
7 {
8 Name (_HID, EisaId ("PNP0C09"))
9 Name (_UID, 1)
10 Name (_GPE, EC_SCI_GPI)
11 Name (_STA, 0xf)
12 Name (DBUG, 0)
13 Name (ISSX, 0) /* Is the EC in S0ix mode? */
14 Name (UCEP, 0) /* Is there a pending UCSI event? */
15
16 Name (_CRS, ResourceTemplate() {
17 IO (Decode16,
18 CONFIG_EC_BASE_ACPI_DATA,
19 CONFIG_EC_BASE_ACPI_DATA,
20 4, 4)
21 IO (Decode16,
22 CONFIG_EC_BASE_ACPI_COMMAND,
23 CONFIG_EC_BASE_ACPI_COMMAND,
24 4, 4)
25 })
26
27 /* Handle registration of EmbeddedControl region */
28 Name (EREG, 0)
29 OperationRegion (ERAM, EmbeddedControl, 0, 0xff)
30 Method (_REG, 2)
31 {
32 If (Arg1 != 1) {
33 Return ()
34 }
35
36 /* Indicate region is registered */
37 EREG = Arg1
38
39 /* Store initial value for power status */
40 ECPR = R (PWSR)
41
42 /* Indicate to EC that OS is ready for queries */
43 W (ERDY, Arg1)
44
45 /* Indicate that the OS supports S0ix */
46 W (CSOS, 1)
47
48 /* Tell EC to stop emulating PS/2 mouse */
49 W (PS2M, 0)
50
51 /* Enable DPTF support if enabled in devicetree */
52 If (\DPTE == 1) {
53 W (DWST, Arg1)
54 }
55
56 /* Initialize UCSI */
57 \_SB.UCSI.INIT ()
58
59 // Initialize LID switch state
60 \LIDS = R (P1LC)
61 }
62
63 /*
64 * Find bitmask for field
65 * Arg0 = EC field structure
66 * Arg1 = Value
67 */
68 Method (EBIT, 2, NotSerialized)
69 {
70 Local0 = DeRefOf (Arg0[1]) /* Mask */
71 Local1 = Arg1 & Local0
72 FindSetRightBit (Local0, Local2)
73 If (Local2) {
74 Local1 >>= Local2 - 1
75 }
76 Return (Local1)
77 }
78
79 /*
80 * READ or WRITE from EC region
81 * Arg0 = EC field structure
82 * Arg1 = Value to write
83 */
84 Method (ECRW, 2, Serialized, 2)
85 {
86 If (!EREG) {
87 Return (0)
88 }
89
90 Local0 = DeRefOf (Arg0[0]) /* Byte offset */
91 Local1 = DeRefOf (Arg0[1]) /* Mask */
92 Local2 = DeRefOf (Arg0[2]) /* Read/Write */
93
94 OperationRegion (ERAM, EmbeddedControl, Local0, 2)
95 Field (ERAM, ByteAcc, Lock, WriteAsZeros)
96 {
97 BYT1, 8,
98 BYT2, 8,
99 }
100
101 If (Local2 == RD) {
102 /* Read first byte */
103 Local3 = BYT1
104
105 /* Read second byte if needed */
106 FindSetLeftBit (Local1, Local4)
107 If (Local4 > 8) {
108 Local4 = BYT2
109 Local4 <<= 8
110 Local3 |= Local4
111 }
112
113 Local5 = EBIT (Arg0, Local3)
114 If (DBUG) {
115 Printf ("ECRD %o = %o", Local0, Local5)
116 }
117 Return (Local5)
118 } ElseIf (Local2 == WR) {
119 /* Write byte */
120 If (DBUG) {
121 Printf ("ECWR %o = %o", Local0, Arg1)
122 }
123 BYT1 = Arg1
124 }
125 Return (0)
126 }
127
128 /*
129 * Read a field from EC
130 * Arg0 = EC field structure
131 */
132 Method (R, 1, Serialized, 2)
133 {
134 /* Set read operation */
135 Arg0[2] = RD
136 Return (ECRW (Arg0, 0))
137 }
138
139 /*
140 * Write value to a field from EC
141 * Arg0 = EC field structure
142 * Arg1 = Value to write
143 */
144 Method (W, 2, Serialized, 2)
145 {
146 /* Set write operation */
147 Arg0[2] = WR
148 Return (ECRW (Arg0, Arg1))
149 }
150
151 /*
152 * Tell EC that the OS is entering or exiting S0ix
153 */
154 Method (S0IX, 1, Serialized)
155 {
156 ^ISSX = Arg0 /* Update S0ix state. */
157
158 If (Arg0) {
159 Printf ("EC Enter S0ix")
160 W (CSEX, 1)
161
162 /*
163 * Read back from EC RAM after enabling S0ix
164 * to prevent EC from aborting S0ix entry.
165 */
166 R (EVT1)
167 } Else {
168 Printf ("EC Exit S0ix")
169 W (CSEX, 0)
170
171 /* If UCSI event happened during S0ix send it now. */
172 If (^UCEP == 1) {
173 ^_Q79 ()
174 }
175 }
176 }
177
178 #include "ec_dev.asl"
179 #include "ec_ram.asl"
180 #include "ac.asl"
181 #include "battery.asl"
182 #include "event.asl"
183 #include "lid.asl"
184 #include "platform.asl"
185 #include "vbtn.asl"
186 #include "ucsi.asl"
187 #ifdef EC_ENABLE_DPTF
188 #include "dptf.asl"
189 #endif
190 #ifdef EC_ENABLE_PRIVACY
191 #include "privacy.asl"
192 #endif
193 }