Angel Pons | 210a008 | 2020-04-02 23:48:24 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * The mainboard must define a PNOT method to handle power |
| 5 | * state notifications and Notify CPU device objects to |
| 6 | * re-evaluate their _PPC and _CST tables. |
| 7 | */ |
| 8 | |
Christian Walter | be3979c | 2019-12-18 15:07:59 +0100 | [diff] [blame] | 9 | External (\_SB.CP00._PPC, IntObj) |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 10 | |
| 11 | Device (EC0) |
| 12 | { |
| 13 | Name (_HID, EISAID ("PNP0C09")) |
| 14 | Name (_UID, 1) |
Felix Singer | e2c105e | 2021-12-30 02:55:21 +0100 | [diff] [blame] | 15 | Name (_GPE, EC_SCI_GPI + 16) // GPE for Runtime SCI |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 16 | |
| 17 | OperationRegion (ERAM, EmbeddedControl, 0x00, 0xff) |
| 18 | Field (ERAM, ByteAcc, Lock, Preserve) |
| 19 | { |
| 20 | // EC Name Space Configuration |
| 21 | |
| 22 | Offset(0x40), |
| 23 | BDC0, 16, // Batt Design Capacity ; 40h, 41h |
| 24 | BDV0, 16, // Batt Design Voltage ; 42h, 43h |
| 25 | BFC0, 16, // Batt Last Full Charge Capacity ; 44h, 45h |
| 26 | BPC0, 16, // Batt Current ; 46h, 47h |
| 27 | BRC0, 16, // Batt Remaining Capacity ; 48h, 49h |
| 28 | BPV0, 16, // Batt Present Voltage ; 4Ah, 4Bh |
| 29 | BCG0, 16, // Batt Charge current ; 4Ch, 4Dh |
| 30 | BACV, 16, // Batt Charging Voltage ; 4Eh, 4Fh |
| 31 | BTM0, 16, // Batt Battery Temp ; 50h, 51h |
| 32 | BSN0, 16, // Batt Serial Number ; 52h, 53h |
| 33 | BPCT, 16, // Batt Percentage of full charge ; 54h, 55h |
| 34 | BSSB, 16, // BATT Battery Status SMB ; 56h, 57h |
| 35 | CYC0, 16, // Batt Cycle Counter ; 58h, 59h |
| 36 | BMD0, 16, // Manufacture Date ; 5Ah, 5Bh |
| 37 | // Batt Day ; BIT[4:0] (Day) |
| 38 | // Batt Month ; BIT[9:5] (Month) |
| 39 | // Batt Year ; BIT[15:10] (Year) |
| 40 | |
| 41 | |
| 42 | Offset(0x60), |
| 43 | BCHM, 32, // Battery Chemistry ; 60h - 64h |
| 44 | BATD, 56, // Battery Device name ; 64h - 6Ah |
| 45 | |
| 46 | Offset(0x70), |
| 47 | ADPT, 1, // AC Adapter Status for OS ; 70h.0 |
| 48 | ADPN, 1, // AC Adapter H/W status ; 70h.1 |
| 49 | BTIN, 1, // Battery Present ; 70h.2 |
| 50 | BTBD, 1, // Battery Malfunction ; 70h.3 |
| 51 | ACMD, 1, // ACPI Mode ; 70h.4 |
| 52 | , 1, // Reserved ; 70h.5 |
Martin Roth | e18e642 | 2017-06-03 20:03:18 -0600 | [diff] [blame] | 53 | SSBS, 1, // 1=Standard BIOS, 0=coreboot ; 70h.6 |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 54 | PSTH, 1, // Passive Thermal Policy ; 70h.7 |
| 55 | BST0, 8, // Battery Status ; 71h |
| 56 | // Bit0 : Discharging |
| 57 | // Bit1 : Charging |
| 58 | // Bit2 : Discharging and Critical Low |
| 59 | // Bit3-7 : Reserved |
| 60 | LIDF, 1, // Lid is open ; 72h.0 |
| 61 | GPRC, 1, // Recovery GPI Status ; 72h.1 |
| 62 | , 6, // Reserved ; 72h.2-7 |
| 63 | TPLD, 1, // TouchPad LED Activation ; 73h.0 |
| 64 | TPST, 1, // Touchpad LED Status ; 73h.1 |
| 65 | , 6, // Reserved ; 73h.2-7 |
| 66 | |
| 67 | Offset(0x78), |
| 68 | CTMP, 8, // Current CPU Temperature ; 78h |
| 69 | SKTB, 8, // GPU Temperature ; 79h |
| 70 | LTM1, 8, // Local Temp 1 ; 7Ah |
| 71 | LTM2, 8, // Local Temp 2 ; 7Bh |
| 72 | FTCH, 16, // Fan Tachometer value ; 7Ch - 7Dh |
| 73 | FDBG, 16, // Fan Debug - Override Fan Tach value ; 7Eh - 7Fh |
| 74 | , 1, // Reserved ; 80h.0 |
| 75 | KBID, 1, // 0=EN KBD, 1=JP KBD ; 80h.1 |
| 76 | , 6, // Reserved ; 80h.2-7 |
| 77 | NPST, 8, // Number of P-State level ; 81h |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 78 | MPST, 8, // Maximum P-State ; 82h |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 79 | KWAK, 1, // Keyboard WAKE(0=Disable,1=Enable) ; 83h.0 |
| 80 | TWAK, 1, // TouchPad WAKE(0=Disable,1=Enable) ; 83h.1 |
| 81 | , 1, // Reserved ; 83h.2 |
| 82 | LWAK, 1, // LAN Wake Enable (0=Disable, 1=Enable); 83h.3 |
| 83 | RWAK, 1, // RTC Wake Enable(0=DIsable,1=Enable) ; 83h.4 |
| 84 | , 3, // Reserved ; 83h.5-7 |
| 85 | KBEV, 1, // Keyboard Wake Event ; 84h.0 |
| 86 | TPEV, 1, // TouchPad Wake Event ; 84h.1 |
| 87 | LDEV, 1, // Lid Wake Event ; 84h.2 |
| 88 | , 4, // Reserved ; 84h.3-6 |
| 89 | PBEV, 1, // Power Button Wake Event ; 84h.7 |
| 90 | |
| 91 | ECCD, 8, // EC Code State ; 85h |
| 92 | ROFW, 8, // RO FW Reason ID ; 86h |
| 93 | |
| 94 | Offset(0xBA), |
| 95 | FWVR, 48, // EC Firmware Version ; BAh-BFh |
| 96 | |
| 97 | Offset(0xC0), |
| 98 | SMPR, 8, // SMBus protocol register ; C0h |
| 99 | SMST, 8, // SMBus status register ; C1h |
| 100 | SMAD, 8, // SMBus address register ; C2h |
| 101 | SMCM, 8, // SMBus command register ; C3h |
| 102 | SMD0, 0x100, // SMBus data regs (32) ; C4h - E3h |
| 103 | BCNT, 8, // SMBus Block Count ; E4h |
| 104 | } |
| 105 | |
Martin Roth | 8b954f5 | 2015-11-23 10:35:11 -0700 | [diff] [blame] | 106 | Method (_CRS, 0, Serialized) |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 107 | { |
| 108 | Name (ECMD, ResourceTemplate() |
| 109 | { |
| 110 | IO (Decode16, 0x62, 0x62, 0, 1) |
| 111 | IO (Decode16, 0x66, 0x66, 0, 1) |
| 112 | }) |
| 113 | Return (ECMD) |
| 114 | } |
| 115 | |
| 116 | Method(_STA) |
| 117 | { |
| 118 | Return(0x0F) |
| 119 | } |
| 120 | |
| 121 | |
| 122 | Method (_REG, 2, NotSerialized) |
| 123 | { |
| 124 | // Initialize AC power state |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 125 | \PWRS = ADPT |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 126 | |
| 127 | // Initialize LID switch state |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 128 | \LIDS = LIDF |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 129 | |
| 130 | // Force a read of CPU temperature |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 131 | Local0 = CTMP |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 132 | |
Martin Roth | d890b45 | 2015-12-10 08:04:44 -0700 | [diff] [blame] | 133 | // Use Local0 to avoid iasl warning: Method Local is set but never used |
Felix Singer | 35e65a8 | 2022-12-16 07:11:17 +0100 | [diff] [blame] | 134 | Local0 &= Ones |
Martin Roth | d890b45 | 2015-12-10 08:04:44 -0700 | [diff] [blame] | 135 | |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 136 | // Find and program number of P-States |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 137 | MPST = SizeOf (\_SB.CP00._PSS) |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 138 | Printf ("Programming number of P-states: %o", MPST) |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 139 | |
| 140 | // Find and program the current P-State |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 141 | NPST = \_SB.CP00._PPC |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 142 | Printf ("Programming Current P-state: %o", NPST) |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* |
| 146 | * EC Query Responses |
| 147 | * |
| 148 | * Lid Status Change 06h |
| 149 | * Wifi Button Event (F12) 07h |
| 150 | * TZ Event Update CPU Temp 08h |
| 151 | * CPU P-State Down 0Eh |
| 152 | * CPU P-State UP 0Fh |
| 153 | |
| 154 | * AC plug in 10h |
| 155 | * AC removed 11h |
| 156 | * Battery Plugged in 12h |
| 157 | * Battery Removed 13h |
| 158 | * Battery State Change 14h |
| 159 | */ |
| 160 | |
| 161 | // Wifi Button Event |
| 162 | Method (_Q07) |
| 163 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 164 | Printf ("Wifi Button Event 0x07") |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | // Thermal Event |
| 168 | Method (_Q08) |
| 169 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 170 | Printf ("Thermal Event 0x08") |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 171 | Notify(\_TZ.THRM, 0x80) |
| 172 | } |
| 173 | |
| 174 | // Pstate Down |
| 175 | Method (_Q0E) |
| 176 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 177 | Printf ("Pstate Event 0x0E") |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 178 | |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 179 | Local0 = \_SB.CP00._PPC |
Felix Singer | ae2d14b | 2021-12-30 00:23:46 +0100 | [diff] [blame] | 180 | Local1 = PPCM - 1 |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 181 | |
Felix Singer | d5d4b44 | 2022-01-02 01:32:42 +0100 | [diff] [blame] | 182 | If(Local0 < Local1) { |
Felix Singer | 70f59e2 | 2021-12-31 14:02:52 +0100 | [diff] [blame] | 183 | Local0++ |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 184 | \PPCN () |
| 185 | } |
| 186 | |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 187 | NPST = Local0 |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // Pstate Up |
| 191 | Method (_Q0F) |
| 192 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 193 | Printf ("Pstate Event 0x0F") |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 194 | Local0 = \_SB.CP00._PPC |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 195 | |
| 196 | If(Local0) { |
Felix Singer | 9f8ce8f | 2021-12-31 14:16:58 +0100 | [diff] [blame] | 197 | Local0-- |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 198 | \PPCN () |
| 199 | } |
| 200 | |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 201 | NPST = Local0 |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | // AC Power Connected |
| 205 | Method (_Q10, 0, NotSerialized) |
| 206 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 207 | Printf ("AC Insertion Event 0x10") |
Felix Singer | ca4b587 | 2022-12-26 08:17:06 +0100 | [diff] [blame^] | 208 | \PWRS = 1 |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 209 | Notify (AC, 0x80) |
| 210 | Notify (BATX, 0x80) |
| 211 | \PNOT () |
| 212 | } |
| 213 | |
| 214 | // AC Power Removed |
| 215 | Method (_Q11, 0, NotSerialized) |
| 216 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 217 | Printf ("AC Detach Event 0x11") |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 218 | \PWRS = Zero |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 219 | Notify (AC, 0x80) |
| 220 | Notify (BATX, 0x80) |
| 221 | \PNOT () |
| 222 | } |
| 223 | |
| 224 | // Battery State Change - Attach Event |
| 225 | Method (_Q12, 0, NotSerialized) |
| 226 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 227 | Printf ("Battery Insertion Event 0x12") |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 228 | |
| 229 | Notify (BATX, 0x81) |
| 230 | Notify (BATX, 0x80) |
| 231 | \PNOT () |
| 232 | } |
| 233 | |
| 234 | // Battery State Change - Detach Event |
| 235 | Method (_Q13, 0, NotSerialized) |
| 236 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 237 | Printf ("Battery Detach Event 0x13") |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 238 | |
| 239 | Notify (BATX, 0x81) |
| 240 | Notify (BATX, 0x80) |
| 241 | \PNOT () |
| 242 | } |
| 243 | |
| 244 | |
| 245 | // Battery State Change Event |
| 246 | Method (_Q14, 0, NotSerialized) |
| 247 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 248 | Printf ("Battery State Change Event 0x14") |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 249 | |
| 250 | Notify (BATX, 0x80) |
| 251 | } |
| 252 | |
| 253 | // Lid Switch Event |
| 254 | Method (_Q06) |
| 255 | { |
Felix Singer | 58e6789 | 2021-12-27 07:17:19 +0100 | [diff] [blame] | 256 | Printf ("Lid Switch Event 0x06") |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 257 | sleep(20) |
Felix Singer | 612801d | 2022-12-12 04:56:53 +0100 | [diff] [blame] | 258 | \LIDS = LIDF |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 259 | Notify (\_SB.LID0, 0x80) |
| 260 | } |
| 261 | |
| 262 | #include "ac.asl" |
| 263 | #include "battery.asl" |
| 264 | } |