Debian Codegraph @

src/mainboard/purism/librem_jsl/acpi/ec.asl

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 Device (EC0)
4 {
5 Name (_HID, EisaId ("PNP0C09"))
6 Name (_UID, 0)
7 Name (_GPE, EC_GPE_SWI)
8
9 Name (ECOK, Zero)
10
11 Name (_CRS, ResourceTemplate () {
12 IO (Decode16, 0x62, 0x62, 0, 1)
13 IO (Decode16, 0x66, 0x66, 0, 1)
14 })
15
16 Method (_STA, 0, NotSerialized) // _STA: Status
17 {
18 Return (0x0F)
19 }
20
21 OperationRegion (ERAM, EmbeddedControl, Zero, 0xFF)
22 Field (ERAM, ByteAcc, Lock, Preserve)
23 {
24 Offset (0x7F),
25 LSTE, 1, /* lid state */
26 , 7,
27 ACEX, 1, /* AC adapter present */
28 BTEX, 1, /* battery present */
29 , 6,
30 Offset (0x84),
31 BTDC, 16, /* battery design capacity - mAh */
32 BTFV, 16, /* battery last full voltage - mV */
33 BTFC, 16, /* battery last full capacity - mAh */
34 Offset (0x8C),
35 BTST, 3, /* battery state */
36 , 5,
37 BTCR, 16, /* battery present current - mA */
38 BTRC, 16, /* battery remaining capacity - mAh */
39 BTVT, 16, /* battery present voltage - mV */
40 Offset (0xA3),
41 DSPO, 8, /* Display off - write 1 to power off display */
42 BCST, 8, /* battery charge start threshold - % */
43 BCET, 8, /* battery charge end threshold - % */
44 }
45
46 #include "button.asl"
47 #include "ac.asl"
48 #include "battery.asl"
49 #include "vbtn.asl"
50
51 Method (PTS, 1, Serialized) {
52 Printf ("EC: PTS: %o", ToHexString(Arg0))
53 If (ECOK) {
54 // Power off display
55 DSPO = One
56 }
57 }
58
59 Method (WAK, 1, Serialized) {
60 Printf ("EC: WAK: %o", ToHexString(Arg0))
61 If (ECOK) {
62 DSPO = Zero
63 ^AC.ACEX = ACEX
64 Notify(BAT0, Zero)
65 Notify(AC, Zero)
66 }
67 }
68
69 Method (_Q54, 0, NotSerialized) // Power button press
70 {
71 Printf ("EC: _Q54: power button press")
72 Notify (PWRB, 0x80)
73 }
74
75 Method (_Q0A, 0, NotSerialized) // Charger plugged or unplugged
76 {
77 Printf ("EC: _Q0A: charger state changed")
78 If (ECOK) {
79 ^AC.ACEX = ACEX
80 }
81 Notify(BAT0, 0x81) // Information change
82 Notify(AC, 0x80) // Status change
83 }
84
85 Method (_Q0B, 0, NotSerialized) // Battery status change
86 {
87 Printf ("EC: _Q0B: battery state changed")
88 Notify(BAT0, 0x81) // Information change
89 Notify(BAT0, 0x80) // Status change
90 }
91
92 /* There is a lid/cover sensor, but it is not reliable with a soft cover. */
93 Method (_Q0C, 0, NotSerialized) // Cover closed
94 {
95 Printf ("EC: _Q0C: cover closed")
96 }
97
98 Method (_Q0D, 0, NotSerialized) // Cover opened
99 {
100 Printf ("EC: _Q0D: cover opened")
101 }
102
103 Method (_REG, 2, Serialized) // _REG: Region Availability
104 {
105 Printf ("EC: _REG: %o, %o", Arg0, Arg1)
106 If ((Arg0 == 0x03) && (Arg1 == One)) {
107 // EC is now available
108 ECOK = One
109
110 // Set current AC and battery state
111 ^AC.ACEX = ACEX
112 ^BAT0.BTEX = BTEX
113
114 // Notify of changes
115 Notify(AC, Zero)
116 Notify(BAT0, Zero)
117
118 Printf ("EC is ready; BTEX=%o, ACEX=%o", BTEX, ACEX)
119 }
120 }
121 }