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