Debian Codegraph @

src/ec/google/chromeec/acpi/ec.asl

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
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
9 // DTT Power Participant Device Notification
10 #define POWER_STATE_CHANGE_NOTIFICATION 0x81
11 // DTT OEM variables change notification
12 #define EC_OEM_VARIABLE_DATA_MASK 0x7
13 #define INT3400_ODVP_CHANGED 0x88
14
15 #define ACPI_NOTIFY_CROS_EC_MKBP 0x80
16 #define ACPI_NOTIFY_CROS_EC_PANIC 0xB0
17
18 // Mainboard specific throttle handler
19 #ifdef DPTF_ENABLE_CHARGER
20 External (\_SB.DPTF.TCHG, DeviceObj)
21 #endif
22 /* Enable DPTC interface with AMD ALIB */
23 #if CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC)
24 External(\_SB.DPTC, MethodObj)
25 #endif
26
27 External (\_SB.DPTF.TPWR, DeviceObj)
28
29 #ifdef DPTF_ENABLE_OEM_VARIABLES
30 External (\_SB.DPTF.ODVP, MethodObj)
31 External (\_SB.DPTF.ODGT, MethodObj)
32 External (\_SB.DPTF.ODUP, MethodObj)
33 #endif
34
35 Device (EC0)
36 {
37 Name (_HID, EISAID ("PNP0C09"))
38 Name (_UID, 1)
39 Name (_GPE, EC_SCI_GPI)
40 Name (TOFS, EC_TEMP_SENSOR_OFFSET)
41 Name (TNCA, EC_TEMP_SENSOR_NOT_CALIBRATED)
42 Name (TNOP, EC_TEMP_SENSOR_NOT_POWERED)
43 Name (TBAD, EC_TEMP_SENSOR_ERROR)
44 Name (TNPR, EC_TEMP_SENSOR_NOT_PRESENT)
45 Name (DWRN, 15) // Battery capacity warning at 15%
46 Name (DLOW, 10) // Battery capacity low at 10%
47
48 OperationRegion (ERAM, EmbeddedControl, 0x00, EC_ACPI_MEM_MAPPED_BEGIN)
49 Field (ERAM, ByteAcc, Lock, Preserve)
50 {
51 RAMV, 8, // EC RAM Version
52 TSTB, 8, // Test Byte
53 TSTC, 8, // Complement of Test Byte
54 KBLV, 8, // Keyboard Backlight value
55 FAND, 8, // Set Fan Duty Cycle
56 PATI, 8, // Programmable Auxiliary Trip Sensor ID
57 PATT, 8, // Programmable Auxiliary Trip Threshold
58 PATC, 8, // Programmable Auxiliary Trip Commit
59 CHGL, 8, // Charger Current Limit
60 TBMD, 1, // Tablet mode
61 DDPN, 3, // Device DPTF Profile Number
62 STTB, 1, // Switch thermal table by body detection status
63 // DFUD must be 0 for the other 31 values to be valid
64 Offset (0x0a),
65 DFUD, 1, // Device Features Undefined
66 FLSH, 1, // Flash commands present
67 PFAN, 1, // PWM Fan control present
68 KBLE, 1, // Keyboard Backlight present
69 LTBR, 1, // Lightbar present
70 LEDC, 1, // LED control
71 MTNS, 1, // Motion sensors present
72 KEYB, 1, // EC is keyboard controller
73 PSTR, 1, // Persistent storage
74 P80P, 1, // EC serves I/O Port 80h
75 THRM, 1, // EC supports thermal management
76 SBKL, 1, // Screen backlight switch present
77 WIFI, 1, // WIFI switch present
78 HOST, 1, // EC monitors host events (eg SCI, SMI)
79 GPIO, 1, // EC provides GPIO commands
80 I2CB, 1, // EC provides I2C controller access
81 CHRG, 1, // EC provides commands for charger control
82 BATT, 1, // Simply Battery support
83 SBAT, 1, // Smart Battery support
84 HANG, 1, // EC can detect host hang
85 PMUI, 1, // Power Information
86 DSEC, 1, // another EC exists downstream
87 UPDC, 1, // supports USB Power Delivery
88 UMUX, 1, // supports USB Mux
89 MSFF, 1, // Motion Sense has FIFO
90 TVST, 1, // supports temporary secure vstore
91 TCMV, 1, // USB Type C Muxing is virtual (host assisted)
92 RTCD, 1, // EC provides an RTC device
93 FPRD, 1, // EC provides a fingerprint reader device
94 TPAD, 1, // EC provides a touchpad device
95 RWSG, 1, // EC has RWSIG task enabled
96 DEVE, 1, // EC supports device events
97 // make sure we're within our space envelope
98 Offset (0x0e),
99 Offset (0x12),
100 BTID, 8, // Battery index that host wants to read
101 USPP, 8, // USB Port Power
102 RFWU, 8, // Retimer Firmware Update
103 PBOK, 8, // Power source change count from dptf
104 BSRF, 8, // Battery string readout FIFO
105 }
106
107 #if CONFIG(EC_GOOGLE_CHROMEEC_ACPI_MEMMAP)
108 OperationRegion (EMEM, EmbeddedControl,
109 EC_ACPI_MEM_MAPPED_BEGIN, EC_ACPI_MEM_MAPPED_SIZE)
110 Field (EMEM, ByteAcc, Lock, Preserve)
111 #elif CONFIG(EC_GOOGLE_CHROMEEC_LPC_GENERIC_MEMORY_RANGE)
112 OperationRegion (EMEM, SystemMemory, \_SB.PCI0.LPCB.GLGM() + 0x100, EC_MEMMAP_SIZE)
113 Field (EMEM, ByteAcc, NoLock, Preserve)
114 #else
115 OperationRegion (EMEM, SystemIO, EC_LPC_ADDR_MEMMAP, EC_MEMMAP_SIZE)
116 Field (EMEM, ByteAcc, NoLock, Preserve)
117 #endif
118 {
119 #include "emem.asl"
120 }
121
122 #ifdef EC_ENABLE_LID_SWITCH
123 /* LID Switch */
124 Device (LID0)
125 {
126 Name (_HID, EisaId ("PNP0C0D"))
127 Method (_LID, 0)
128 {
129 Return (^^LIDS)
130 }
131
132 #ifdef EC_ENABLE_WAKE_PIN
133 Name (_PRW, Package () { EC_ENABLE_WAKE_PIN, 0x5 })
134 #endif
135 }
136 #endif /* EC_ENABLE_LID_SWITCH */
137
138 Method (TINS, 1, Serialized)
139 {
140 Switch (ToInteger (Arg0))
141 {
142 Case (0) { Return (TIN0) }
143 Case (1) { Return (TIN1) }
144 Case (2) { Return (TIN2) }
145 Case (3) { Return (TIN3) }
146 Case (4) { Return (TIN4) }
147 Case (5) { Return (TIN5) }
148 Case (6) { Return (TIN6) }
149 Case (7) { Return (TIN7) }
150 Case (8) { Return (TIN8) }
151 Case (9) { Return (TIN9) }
152 Default { Return (TIN0) }
153 }
154 }
155
156 Method (_CRS, 0, Serialized)
157 {
158 Name (ECMD, ResourceTemplate()
159 {
160 IO (Decode16,
161 EC_LPC_ADDR_ACPI_DATA,
162 EC_LPC_ADDR_ACPI_DATA,
163 0, 1)
164 IO (Decode16,
165 EC_LPC_ADDR_ACPI_CMD,
166 EC_LPC_ADDR_ACPI_CMD,
167 0, 1)
168 })
169 Return (ECMD)
170 }
171
172 Method (_REG, 2, NotSerialized)
173 {
174 // Initialize AC power state
175 \PWRS = ACEX
176 /*
177 * Call PNOT (Platform Notify) to inform platform code
178 * about the current AC/battery state. This handles all cases,
179 * the battery transitioning into and out of having critically
180 * low charge.
181 * PWRS isn't valid before this point.
182 */
183 \PNOT ()
184
185 #ifndef EC_ENABLE_LID_SWITCH
186 // Initialize LID switch state
187 \LIDS = LIDS
188 #endif
189
190 #if CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC)
191 /*
192 * Per the device mode (clamshell or tablet) to initialize
193 * the thermal setting on OS startup.
194 */
195 If (CondRefOf (\_SB.DPTC)) {
196 \_SB.DPTC()
197 }
198 #endif
199
200 #ifdef DPTF_FEATURE_DYNAMIC_THERMAL_TABLE_SWITCH
201 \_SB.DPTF.ODUP(0, STTB)
202 Notify (\_SB.DPTF, INT3400_ODVP_CHANGED)
203 #endif
204 }
205
206 /* Read requested temperature and check against EC error values */
207 Method (TSRD, 1, Serialized)
208 {
209 Local0 = \_SB.PCI0.LPCB.EC0.TINS (Arg0)
210
211 /* Check for sensor not calibrated */
212 If (Local0 == \_SB.PCI0.LPCB.EC0.TNCA) {
213 Return (0)
214 }
215
216 /* Check for sensor not present */
217 If (Local0 == \_SB.PCI0.LPCB.EC0.TNPR) {
218 Return (0)
219 }
220
221 /* Check for sensor not powered */
222 If (Local0 == \_SB.PCI0.LPCB.EC0.TNOP) {
223 Return (0)
224 }
225
226 /* Check for sensor bad reading */
227 If (Local0 == \_SB.PCI0.LPCB.EC0.TBAD) {
228 Return (0)
229 }
230
231 /* Adjust by offset to get Kelvin */
232 Local0 += \_SB.PCI0.LPCB.EC0.TOFS
233
234 /* Convert to 1/10 Kelvin */
235 Local0 *= 10
236
237 Return (Local0)
238 }
239
240 // Lid Closed Event
241 Method (_Q01, 0, NotSerialized)
242 {
243 Printf ("EC: LID CLOSE")
244 #if CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC)
245 If (CondRefOf (\_SB.DPTC)) {
246 \_SB.DPTC()
247 }
248 #endif
249 #ifdef EC_ENABLE_LID_SWITCH
250 Notify (LID0, 0x80)
251 #else
252 \LIDS = LIDS
253 #endif
254 }
255
256 // Lid Open Event
257 Method (_Q02, 0, NotSerialized)
258 {
259 Printf ("EC: LID OPEN")
260 #if CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC)
261 If (CondRefOf (\_SB.DPTC)) {
262 \_SB.DPTC()
263 }
264 #endif
265 Notify (CREC, 0x2)
266 #ifdef EC_ENABLE_LID_SWITCH
267 Notify (LID0, 0x80)
268 #else
269 \LIDS = LIDS
270 #endif
271 }
272
273 // Power Button
274 Method (_Q03, 0, NotSerialized)
275 {
276 Printf ("EC: POWER BUTTON")
277 }
278
279 // AC Connected
280 Method (_Q04, 0, NotSerialized)
281 {
282 Printf ("EC: AC CONNECTED")
283 \PWRS = ACEX
284 Notify (AC, 0x80)
285 #ifdef DPTF_ENABLE_CHARGER
286 If (CondRefOf (\_SB.DPTF.TCHG)) {
287 Notify (\_SB.DPTF.TCHG, 0x80)
288 }
289 #endif
290 /*
291 * Call PNOT (Platform Notify) to inform platform code
292 * about the current battery state. This handles all cases,
293 * the battery transitioning into and out of having critically
294 * low charge.
295 */
296 \PNOT ()
297 }
298
299 // AC Disconnected
300 Method (_Q05, 0, NotSerialized)
301 {
302 Printf ("EC: AC DISCONNECTED")
303 \PWRS = ACEX
304 Notify (AC, 0x80)
305 #ifdef DPTF_ENABLE_CHARGER
306 If (CondRefOf (\_SB.DPTF.TCHG)) {
307 Notify (\_SB.DPTF.TCHG, 0x80)
308 }
309 #endif
310 /*
311 * Call PNOT (Platform Notify) to inform platform code
312 * about the current battery state. This handles all cases,
313 * the battery transitioning into and out of having critically
314 * low charge.
315 */
316 \PNOT ()
317 }
318
319 // Battery Low Event
320 Method (_Q06, 0, NotSerialized)
321 {
322 Printf ("EC: BATTERY LOW")
323 Notify (BAT0, 0x80)
324 }
325
326 // Battery Critical Event
327 Method (_Q07, 0, NotSerialized)
328 {
329 Printf ("EC: BATTERY CRITICAL")
330 Notify (BAT0, 0x80)
331 }
332
333 // Battery Info Event
334 Method (_Q08, 0, NotSerialized)
335 {
336 Printf ("EC: BATTERY INFO")
337 Notify (BAT0, 0x81)
338 #ifdef EC_ENABLE_SECOND_BATTERY_DEVICE
339 If (CondRefOf (BAT1)) {
340 Notify (BAT1, 0x81)
341 }
342 #endif
343 }
344
345 // Thermal Overload Event
346 Method (_Q0A, 0, NotSerialized)
347 {
348 Printf ("EC: THERMAL OVERLOAD")
349 Notify (\_TZ, 0x80)
350 }
351
352 // Thermal Event
353 Method (_Q0B, 0, NotSerialized)
354 {
355 Printf ("EC: THERMAL")
356 Notify (\_TZ, 0x80)
357 }
358
359 // Key Pressed
360 Method (_Q0D, 0, NotSerialized)
361 {
362 Printf ("EC: KEY PRESSED")
363 Notify (CREC, 0x2)
364 }
365
366 // Thermal Shutdown Imminent
367 Method (_Q10, 0, NotSerialized)
368 {
369 Printf ("EC: THERMAL SHUTDOWN")
370 Notify (\_TZ, 0x80)
371 }
372
373 // Battery Shutdown Imminent
374 Method (_Q11, 0, NotSerialized)
375 {
376 Printf ("EC: BATTERY SHUTDOWN")
377 Notify (BAT0, 0x80)
378 }
379
380 // Throttle Start
381 Method (_Q12, 0, NotSerialized)
382 {
383 #ifdef EC_ENABLE_THROTTLING_HANDLER
384 Printf ("EC: THROTTLE START")
385 \_TZ.THRT (1)
386 #endif
387 }
388
389 // Throttle Stop
390 Method (_Q13, 0, NotSerialized)
391 {
392 #ifdef EC_ENABLE_THROTTLING_HANDLER
393 Printf ("EC: THROTTLE STOP")
394 \_TZ.THRT (0)
395 #endif
396 }
397
398 #ifdef EC_ENABLE_PD_MCU_DEVICE
399 // PD event
400 Method (_Q16, 0, NotSerialized)
401 {
402 Printf ("EC: GOT PD EVENT")
403 Notify (\_SB.PCI0.LPCB.EC0.CREC.ECPD, 0x80)
404 If (CondRefOf (\_SB.DPTF.TPWR)) {
405 Notify (\_SB.DPTF.TPWR, POWER_STATE_CHANGE_NOTIFICATION)
406 }
407 }
408 #endif
409
410 // Battery Status
411 Method (_Q17, 0, NotSerialized)
412 {
413 Printf ("EC: BATTERY STATUS")
414 Notify (BAT0, 0x80)
415 #ifdef EC_ENABLE_SECOND_BATTERY_DEVICE
416 If (CondRefOf (BAT1)) {
417 Notify (BAT1, 0x80)
418 }
419 #endif
420
421 /*
422 * Call PNOT (Platform Notify) to inform platform code
423 * about the current battery state. This handles all cases,
424 * the battery transitioning into and out of having critically
425 * low charge.
426 */
427 \PNOT ()
428 }
429
430 // EC Panic
431 Method (_Q18, 0, NotSerialized)
432 {
433 Printf ("EC: PANIC")
434 Notify (CREC, ACPI_NOTIFY_CROS_EC_PANIC)
435 }
436
437 // MKBP interrupt.
438 Method (_Q1B, 0, NotSerialized)
439 {
440 Printf ("EC: MKBP")
441 Notify (CREC, ACPI_NOTIFY_CROS_EC_MKBP)
442 }
443
444 #ifdef EC_ENABLE_PD_MCU_DEVICE
445 // USB MUX Interrupt
446 Method (_Q1C, 0, NotSerialized)
447 {
448 Printf ("EC: USB MUX")
449 Notify (\_SB.PCI0.LPCB.EC0.CREC.ECPD, 0x80)
450 }
451 #endif
452
453 // TABLET mode switch Event
454 Method (_Q1D, 0, NotSerialized)
455 {
456 Printf ("EC: TABLET mode switch Event")
457 Notify (CREC, 0x2)
458 #ifdef EC_ENABLE_MULTIPLE_DPTF_PROFILES
459 \_SB.DPTF.TPET()
460 #endif
461 #ifdef EC_ENABLE_TBMC_DEVICE
462 Notify (^CREC.TBMC, 0x80)
463 #endif
464 #if CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC)
465 If (CondRefOf (\_SB.DPTC)) {
466 \_SB.DPTC()
467 }
468 #endif
469 }
470
471 // Body Detect Change Event
472 Method (_Q21, 0, NotSerialized)
473 {
474 Printf ("EC: Body Detect Change Event")
475 #if CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC)
476 If (CondRefOf (\_SB.DPTC)) {
477 \_SB.DPTC()
478 }
479 #endif
480
481 #ifdef DPTF_FEATURE_DYNAMIC_THERMAL_TABLE_SWITCH
482 \_SB.DPTF.ODUP(0, STTB)
483 Notify (\_SB.DPTF, INT3400_ODVP_CHANGED)
484 #endif
485 }
486
487 /*
488 * Dynamic Platform Thermal Framework support
489 */
490
491 /* Mutex for EC PAT interface */
492 Mutex (PATM, 1)
493
494 /*
495 * Set Aux Trip Point 0
496 * Arg0 = Temp Sensor ID
497 * Arg1 = Value to set
498 */
499 Method (PAT0, 2, Serialized)
500 {
501 If (Acquire (^PATM, 1000)) {
502 Return (0)
503 }
504
505 /* Set sensor ID */
506 ^PATI = ToInteger (Arg0)
507
508 /* Temperature is passed in 1/10 Kelvin */
509 Local1 = ToInteger (Arg1) / 10
510
511 /* Adjust by EC temperature offset */
512 ^PATT = Local1 - ^TOFS
513
514 /* Set commit value with SELECT=0 and ENABLE=1 */
515 ^PATC = 0x02
516
517 Release (^PATM)
518 Return (1)
519 }
520
521 /*
522 * Set Aux Trip Point 1
523 * Arg0 = Temp Sensor ID
524 * Arg1 = Value to set
525 */
526 Method (PAT1, 2, Serialized)
527 {
528 If (Acquire (^PATM, 1000)) {
529 Return (0)
530 }
531
532 /* Set sensor ID */
533 ^PATI = ToInteger (Arg0)
534
535 /* Temperature is passed in 1/10 Kelvin */
536 Local1 = ToInteger (Arg1) / 10
537
538 /* Adjust by EC temperature offset */
539 ^PATT = Local1 - ^TOFS
540
541 /* Set commit value with SELECT=1 and ENABLE=1 */
542 ^PATC = 0x03
543
544 Release (^PATM)
545 Return (1)
546 }
547
548 /* Disable Aux Trip Points
549 * Arg0 = Temp Sensor ID
550 */
551 Method (PATD, 1, Serialized)
552 {
553 If (Acquire (^PATM, 1000)) {
554 Return (0)
555 }
556
557 ^PATI = ToInteger (Arg0)
558 ^PATT = 0x00
559
560 /* Disable PAT0 */
561 ^PATC = 0x00
562
563 /* Disable PAT1 */
564 ^PATC = 0x01
565
566 Release (^PATM)
567 Return (1)
568 }
569
570 /*
571 * Thermal Threshold Event
572 */
573 Method (_Q09, 0, NotSerialized)
574 {
575
576 #if CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC)
577 If (CondRefOf (\_SB.DPTC)) {
578 \_SB.DPTC()
579 }
580 #endif
581 If (!Acquire (^PATM, 1000)) {
582 /* Read sensor ID for event */
583 Local0 = ^PATI
584
585 /* When sensor ID returns 0xFF then no more events */
586 While (Local0 != EC_TEMP_SENSOR_NOT_PRESENT)
587 {
588 #ifdef HAVE_THERM_EVENT_HANDLER
589 \_SB.DPTF.TEVT (Local0)
590 #endif
591
592 /* Keep reaading sensor ID for event */
593 Local0 = ^PATI
594 }
595
596 Release (^PATM)
597 }
598 }
599
600 /*
601 * Set Charger Current Limit
602 * Arg0 = Current Limit in 64mA steps
603 */
604 Method (CHGS, 1, Serialized)
605 {
606 ^CHGL = ToInteger (Arg0)
607 }
608
609 /*
610 * Disable Charger Current Limit
611 */
612 Method (CHGD, 0, Serialized)
613 {
614 ^CHGL = 0xFF
615 }
616
617 /* Read current Tablet mode */
618 Method (RCTM, 0, NotSerialized)
619 {
620 Return (^TBMD)
621 }
622
623 #ifdef EC_ENABLE_MULTIPLE_DPTF_PROFILES
624 /* Read current Device DPTF Profile Number */
625 Method (RCDP, 0, NotSerialized)
626 {
627 /*
628 * DDPN = 0 is reserved for backwards compatibility.
629 * If DDPN == 0 use TBMD to load appropriate DPTF table.
630 */
631 If (^DDPN == 0) {
632 Return (^TBMD)
633 } Else {
634 Local0 = ^DDPN - 1
635 Return (Local0)
636 }
637 }
638 #endif
639 #if CONFIG(EC_GOOGLE_CHROMEEC_ACPI_USB_PORT_POWER)
640 /*
641 * Enable USB Port Power
642 * Arg0 = USB port ID
643 */
644 Method (UPPS, 1, Serialized)
645 {
646 USPP |= 1 << Arg0
647 }
648
649 /*
650 * Disable USB Port Power
651 * Arg0 = USB port ID
652 */
653 Method (UPPC, 1, Serialized)
654 {
655 USPP &= ~(1 << Arg0)
656 }
657 #endif
658
659 #include "ac.asl"
660 #include "battery.asl"
661 #include "cros_ec.asl"
662
663 #ifdef EC_ENABLE_ALS_DEVICE
664 #include "als.asl"
665 #endif
666
667 #ifdef EC_ENABLE_KEYBOARD_BACKLIGHT
668 #include "keyboard_backlight.asl"
669 #endif
670 }