Debian Codegraph @

src/ec/starlabs/merlin/acpi/ec.asl

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 Scope (\_SB.PCI0.LPCB)
4 {
5 #include "cmos.asl"
6
7 Device (EC)
8 {
9 Name (_HID, EisaId ("PNP0C09"))
10 Name (_UID, 0x01)
11 Name (_GPE, CONFIG_EC_GPE_SCI)
12 Name (ECAV, 0x00)
13 Name (ECTK, 0x01)
14 Mutex (ECMT, 0x00)
15
16 Name (BFFR, ResourceTemplate()
17 {
18 IO(Decode16, 0x0062, 0x0062, 0x00, 0x01)
19 IO(Decode16, 0x0066, 0x0066, 0x00, 0x01)
20 })
21
22 Method (_CRS, 0, Serialized)
23 {
24 Return (BFFR)
25 }
26
27 Method (_STA, 0, NotSerialized)
28 {
29 \LIDS = 0x03
30 Return (0x0F)
31 }
32
33 OperationRegion (SIPR, SystemIO, 0xB2, 0x1)
34 Field (SIPR, ByteAcc, Lock, Preserve) {
35 SMB2, 8
36 }
37
38 #include "emem.asl"
39
40 // ECRD (Embedded Controller Read Method)
41 //
42 // Handle all commands sent to EC by BIOS
43 //
44 // Arguments:
45 // Arg0 = Object to Read
46 //
47 // Return Value:
48 // Read Value
49 //
50 Method (ECRD, 1, Serialized, 0, IntObj, FieldUnitObj)
51 {
52 //
53 // Check for ECDT support, set ECAV to 1 if ECDT is supported by OS
54 // Only check once at beginning since ECAV might be clear later in certain conditions
55 //
56 If (ECTK) {
57 If (_REV >= 0x02) {
58 ECAV = 0x01
59 }
60 ECTK = 0x00 // Clear flag for checking once only
61 }
62
63 Local0 = Acquire (ECMT, 1000) // Save Acquired Result
64 If (Local0 == 0x00) // Check for Mutex Acquisition
65 {
66 If (ECAV) {
67 Local1 = DerefOf (Arg0) // Execute Read from EC
68 Release (ECMT)
69 Return (Local1)
70 } Else {
71 Release (ECMT)
72 }
73 }
74 Return (0) // Return in case Arg0 doesn't exist
75 }
76
77 // ECWR (Embedded Controller Write Method)
78 //
79 // Handle all commands sent to EC by BIOS
80 //
81 // Arguments:
82 // Arg0 = Value to Write
83 // Arg1 = Object to Write to
84 //
85 // Return Value:
86 // None
87 //
88 Method (ECWR, 2, Serialized,,,{IntObj, FieldUnitObj})
89 {
90 Local0 = Acquire (ECMT, 1000) // Save Acquired Result
91 If (Local0 == 0x00) // Check for Mutex Acquisition
92 {
93 If (ECAV) {
94 Arg1 = Arg0 // Execute Write to EC
95 Local1 = 0x00
96 While (1) {
97 If (Arg0 == DerefOf (Arg1)) {
98 Break
99 }
100 Sleep (1)
101 Arg1 = Arg0
102 Local1 += 1
103 If (Local1 == 0x03) {
104 Break
105 }
106 }
107 }
108 Release (ECMT)
109 }
110 }
111
112 #include "ac.asl"
113 #if CONFIG(SYSTEM_TYPE_LAPTOP) || CONFIG(SYSTEM_TYPE_DETACHABLE)
114 #include "battery.asl"
115 #include "lid.asl"
116 #endif
117 #if !CONFIG(EC_STARLABS_MERLIN)
118 #include "events.asl"
119 #endif
120 #if CONFIG(SYSTEM_TYPE_DETACHABLE)
121 #include "dock.asl"
122 #endif
123
124 Method (_REG, 2, NotSerialized)
125 {
126 If ((Arg0 == 0x03) && (Arg1 == 0x01))
127 {
128 // Load EC Driver
129 ECAV = 0x01
130
131 // Initialise the Lid State
132 \LIDS = ECRD(RefOf(LSTE))
133
134 // Initialise the OS State
135 ECWR(0x01, RefOf(OSFG))
136
137 // Initialise the Power State
138 PWRS = (ECRD (RefOf(ECPS)) & 0x01)
139
140 // Inform the platform code
141 PNOT()
142 }
143 }
144 }
145 }