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