blob: b858b0cd8dc701b56acd739e3730b99573c98cf2 [file] [log] [blame]
Angel Pons210a0082020-04-02 23:48:24 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Lauriea802be22018-10-15 15:01:15 -07002
3Device (EC0)
4{
5 Name (_HID, EisaId ("PNP0C09"))
6 Name (_UID, 1)
7 Name (_GPE, EC_SCI_GPI)
8 Name (_STA, 0xf)
Duncan Laurie4c14ca82018-11-20 17:27:47 -08009 Name (DBUG, Zero)
Duncan Laurie3cd3cb62020-06-09 15:13:15 -070010 Name (ISSX, Zero) /* Is the EC in S0ix mode? */
11 Name (UCEP, Zero) /* Is there a pending UCSI event? */
Duncan Lauriea802be22018-10-15 15:01:15 -070012
13 Name (_CRS, ResourceTemplate() {
14 IO (Decode16,
15 CONFIG_EC_BASE_ACPI_DATA,
16 CONFIG_EC_BASE_ACPI_DATA,
17 4, 4)
18 IO (Decode16,
19 CONFIG_EC_BASE_ACPI_COMMAND,
20 CONFIG_EC_BASE_ACPI_COMMAND,
21 4, 4)
22 })
23
24 /* Handle registration of EmbeddedControl region */
25 Name (EREG, Zero)
26 OperationRegion (ERAM, EmbeddedControl, 0, 0xff)
27 Method (_REG, 2)
28 {
29 /* Indicate region is registered */
30 EREG = Arg1
31
32 /* Store initial value for power status */
Duncan Lauriea213ed62019-02-21 17:38:03 -080033 ECPR = R (PWSR)
Duncan Lauriea802be22018-10-15 15:01:15 -070034
35 /* Indicate to EC that OS is ready for queries */
Duncan Laurie4c14ca82018-11-20 17:27:47 -080036 W (ERDY, Arg1)
Duncan Lauriea802be22018-10-15 15:01:15 -070037
Duncan Laurie286a0ab2019-01-25 10:28:03 -080038 /* Indicate that the OS supports S0ix */
Felix Singerca4b5872022-12-26 08:17:06 +010039 W (CSOS, 1)
Duncan Laurie286a0ab2019-01-25 10:28:03 -080040
Duncan Lauriea802be22018-10-15 15:01:15 -070041 /* Tell EC to stop emulating PS/2 mouse */
42 W (PS2M, Zero)
Duncan Laurie98d7de72018-11-20 17:30:47 -080043
44 /* Enable DPTF support if enabled in devicetree */
Felix Singerca4b5872022-12-26 08:17:06 +010045 If (\DPTE == 1) {
Duncan Laurie98d7de72018-11-20 17:30:47 -080046 W (DWST, Arg1)
47 }
Duncan Lauriec145e542019-04-18 16:37:50 -070048
49 /* Initialize UCSI */
50 ^UCSI.INIT ()
Eric Lai5ddce582020-03-13 17:42:03 +080051
52 // Initialize LID switch state
Elyes HAOUAS2a08ca72020-10-06 18:05:05 +020053 \LIDS = R (P1LC)
Duncan Lauriea802be22018-10-15 15:01:15 -070054 }
55
56 /*
57 * Find bitmask for field
58 * Arg0 = EC field structure
59 * Arg1 = Value
60 */
61 Method (EBIT, 2, NotSerialized)
62 {
63 Local0 = DeRefOf (Arg0[1]) /* Mask */
64 Local1 = Arg1 & Local0
65 FindSetRightBit (Local0, Local2)
66 If (Local2) {
67 Local1 >>= Local2 - 1
68 }
69 Return (Local1)
70 }
71
72 /*
73 * READ or WRITE from EC region
74 * Arg0 = EC field structure
75 * Arg1 = Value to write
76 */
Duncan Laurie4c14ca82018-11-20 17:27:47 -080077 Method (ECRW, 2, Serialized, 2)
Duncan Lauriea802be22018-10-15 15:01:15 -070078 {
79 If (!EREG) {
80 Return (Zero)
81 }
82
83 Local0 = DeRefOf (Arg0[0]) /* Byte offset */
84 Local1 = DeRefOf (Arg0[1]) /* Mask */
85 Local2 = DeRefOf (Arg0[2]) /* Read/Write */
86
87 OperationRegion (ERAM, EmbeddedControl, Local0, 2)
88 Field (ERAM, ByteAcc, Lock, WriteAsZeros)
89 {
90 BYT1, 8,
91 BYT2, 8,
92 }
93
94 If (Local2 == RD) {
95 /* Read first byte */
96 Local3 = BYT1
97
98 /* Read second byte if needed */
99 FindSetLeftBit (Local1, Local4)
100 If (Local4 > 8) {
101 Local4 = BYT2
102 Local4 <<= 8
103 Local3 |= Local4
104 }
105
106 Local5 = EBIT (Arg0, Local3)
Duncan Laurie4c14ca82018-11-20 17:27:47 -0800107 If (DBUG) {
108 Printf ("ECRD %o = %o", Local0, Local5)
109 }
Duncan Lauriea802be22018-10-15 15:01:15 -0700110 Return (Local5)
111 } ElseIf (Local2 == WR) {
112 /* Write byte */
Duncan Laurie4c14ca82018-11-20 17:27:47 -0800113 If (DBUG) {
114 Printf ("ECWR %o = %o", Local0, Arg1)
115 }
Duncan Lauriea802be22018-10-15 15:01:15 -0700116 BYT1 = Arg1
117 }
118 Return (Zero)
119 }
120
121 /*
122 * Read a field from EC
123 * Arg0 = EC field structure
124 */
Duncan Laurie4c14ca82018-11-20 17:27:47 -0800125 Method (R, 1, Serialized, 2)
Duncan Lauriea802be22018-10-15 15:01:15 -0700126 {
127 Return (ECRW (Arg0, Zero))
128 }
129
130 /*
131 * Write value to a field from EC
132 * Arg0 = EC field structure
133 * Arg1 = Value to write
134 */
Duncan Laurie4c14ca82018-11-20 17:27:47 -0800135 Method (W, 2, Serialized, 2)
Duncan Lauriea802be22018-10-15 15:01:15 -0700136 {
137 Return (ECRW (Arg0, Arg1))
138 }
139
Duncan Laurie286a0ab2019-01-25 10:28:03 -0800140 /*
141 * Tell EC that the OS is entering or exiting S0ix
142 */
143 Method (S0IX, 1, Serialized)
144 {
Duncan Laurie3cd3cb62020-06-09 15:13:15 -0700145 ^ISSX = Arg0 /* Update S0ix state. */
146
Duncan Laurie286a0ab2019-01-25 10:28:03 -0800147 If (Arg0) {
148 Printf ("EC Enter S0ix")
Felix Singerca4b5872022-12-26 08:17:06 +0100149 W (CSEX, 1)
Duncan Laurie6ff848a2019-06-13 11:07:04 -0700150
151 /*
152 * Read back from EC RAM after enabling S0ix
153 * to prevent EC from aborting S0ix entry.
154 */
155 R (EVT1)
Duncan Laurie286a0ab2019-01-25 10:28:03 -0800156 } Else {
157 Printf ("EC Exit S0ix")
158 W (CSEX, Zero)
Duncan Laurie3cd3cb62020-06-09 15:13:15 -0700159
160 /* If UCSI event happened during S0ix send it now. */
Felix Singerca4b5872022-12-26 08:17:06 +0100161 If (^UCEP == 1) {
Duncan Laurie3cd3cb62020-06-09 15:13:15 -0700162 ^_Q79 ()
163 }
Duncan Laurie286a0ab2019-01-25 10:28:03 -0800164 }
165 }
166
Duncan Lauriea802be22018-10-15 15:01:15 -0700167 #include "ec_dev.asl"
168 #include "ec_ram.asl"
Duncan Laurie4af38d42018-10-15 15:10:21 -0700169 #include "ac.asl"
170 #include "battery.asl"
Duncan Lauriee52840a2018-10-15 15:19:18 -0700171 #include "event.asl"
Duncan Lauriea802be22018-10-15 15:01:15 -0700172 #include "lid.asl"
173 #include "platform.asl"
Duncan Laurie4a2558b2019-02-01 11:44:14 -0800174 #include "vbtn.asl"
Duncan Lauriec145e542019-04-18 16:37:50 -0700175 #include "ucsi.asl"
Duncan Lauriebfb001d2018-12-04 10:13:25 -0800176#ifdef EC_ENABLE_DPTF
Duncan Laurie98d7de72018-11-20 17:30:47 -0800177 #include "dptf.asl"
Duncan Lauriebfb001d2018-12-04 10:13:25 -0800178#endif
Mathew Kingc650e132019-10-14 11:59:41 -0600179#ifdef EC_ENABLE_PRIVACY
180 #include "privacy.asl"
181#endif
Duncan Lauriea802be22018-10-15 15:01:15 -0700182}