• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* SPDX-License-Identifier: GPL-2.0-only */
2
3Device (EC0)
4{
5	Name (_HID, EisaId ("PNP0C09") /* Embedded Controller Device */)
6	Name (_GPE, 0x50 /* GPP_E16 */)  // _GPE: General Purpose Events
7	Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource Settings
8	{
9		IO (Decode16,
10			0x0062,             // Range Minimum
11			0x0062,             // Range Maximum
12			0x00,               // Alignment
13			0x01,               // Length
14			)
15		IO (Decode16,
16			0x0066,             // Range Minimum
17			0x0066,             // Range Maximum
18			0x00,               // Alignment
19			0x01,               // Length
20			)
21	})
22
23	#include "acpi/ec_ram.asl"
24
25	Name (ECOK, 0)
26	Method (_REG, 2, Serialized)  // _REG: Region Availability
27	{
28		Printf ("EC: _REG %o %o", ToHexString(Arg0), ToHexString(Arg1))
29		If ((Arg0 == 0x03) && (Arg1 == 1)) {
30			// Enable hardware touchpad lock, airplane mode, and keyboard backlight keys
31			ECOS = 1
32
33			// Enable software display brightness keys
34			WINF = 1
35
36			// Set current AC state
37			^^^^AC.ACFG = ADP
38			// Update battery information and status
39			^^^^BAT0.UPBI()
40			^^^^BAT0.UPBS()
41
42			// Notify of changes
43			Notify(^^^^AC, 0)
44			Notify(^^^^BAT0, 0)
45
46			PNOT ()
47
48			// EC is now available
49			ECOK = Arg1
50
51			// Reset System76 Device
52			^^^^S76D.RSET()
53		}
54	}
55
56	Name (S3OS, 0)
57	Method (PTS, 1, Serialized) {
58		Printf ("EC: PTS: %o", ToHexString(Arg0))
59		If (ECOK) {
60			// Save ECOS during sleep
61			S3OS = ECOS
62
63			// Clear wake cause
64			WFNO = 0
65		}
66	}
67
68	Method (WAK, 1, Serialized) {
69		Printf ("EC: WAK: %o", ToHexString(Arg0))
70		If (ECOK) {
71			// Restore ECOS after sleep
72			ECOS = S3OS
73
74			// Set current AC state
75			^^^^AC.ACFG = ADP
76
77			// Update battery information and status
78			^^^^BAT0.UPBI()
79			^^^^BAT0.UPBS()
80
81			// Notify of changes
82			Notify(^^^^AC, 0)
83			Notify(^^^^BAT0, 0)
84
85			// Reset System76 Device
86			^^^^S76D.RSET()
87		}
88	}
89
90	Method (_Q0A, 0, NotSerialized) // Touchpad Toggle
91	{
92		Printf ("EC: Touchpad Toggle")
93	}
94
95	Method (_Q0B, 0, NotSerialized) // Screen Toggle
96	{
97		Printf ("EC: Screen Toggle")
98	}
99
100	Method (_Q0C, 0, NotSerialized)  // Mute
101	{
102		Printf ("EC: Mute")
103	}
104
105	Method (_Q0D, 0, NotSerialized) // Keyboard Backlight
106	{
107		Printf ("EC: Keyboard Backlight")
108	}
109
110	Method (_Q0E, 0, NotSerialized) // Volume Down
111	{
112		Printf ("EC: Volume Down")
113	}
114
115	Method (_Q0F, 0, NotSerialized) // Volume Up
116	{
117		Printf ("EC: Volume Up")
118	}
119
120	Method (_Q10, 0, NotSerialized) // Switch Video Mode
121	{
122		Printf ("EC: Switch Video Mode")
123	}
124
125	Method (_Q11, 0, NotSerialized) // Brightness Down
126	{
127		Printf ("EC: Brightness Down")
128		if (^^^^HIDD.HRDY) {
129			^^^^HIDD.HPEM (20)
130		}
131	}
132
133	Method (_Q12, 0, NotSerialized) // Brightness Up
134	{
135		Printf ("EC: Brightness Up")
136		if (^^^^HIDD.HRDY) {
137			^^^^HIDD.HPEM (19)
138		}
139	}
140
141	Method (_Q13, 0, NotSerialized) // Camera Toggle
142	{
143		Printf ("EC: Camera Toggle")
144	}
145
146	Method (_Q14, 0, NotSerialized) // Airplane Mode
147	{
148		Printf ("EC: Airplane Mode")
149		if (^^^^HIDD.HRDY) {
150			^^^^HIDD.HPEM (8)
151		}
152		// TODO: hardware airplane mode
153	}
154
155	Method (_Q15, 0, NotSerialized) // Suspend Button
156	{
157		Printf ("EC: Suspend Button")
158		Notify (SLPB, 0x80)
159	}
160
161	Method (_Q16, 0, NotSerialized) // AC Detect
162	{
163		Printf ("EC: AC Detect")
164		^^^^AC.ACFG = ADP
165		Notify (AC, 0x80) // Status Change
166		If (BAT0)
167		{
168			Notify (^^^^BAT0, 0x81) // Information Change
169			Notify (^^^^BAT0, 0x80) // Status Change
170		}
171	}
172
173	Method (_Q17, 0, NotSerialized)  // BAT0 Update
174	{
175		Printf ("EC: BAT0 Update (17)")
176		Notify (^^^^BAT0, 0x81) // Information Change
177	}
178
179	Method (_Q19, 0, NotSerialized)  // BAT0 Update
180	{
181		Printf ("EC: BAT0 Update (19)")
182		Notify (^^^^BAT0, 0x81) // Information Change
183	}
184
185	Method (_Q1B, 0, NotSerialized) // Lid Close
186	{
187		Printf ("EC: Lid Close")
188		Notify (LID0, 0x80)
189	}
190
191	Method (_Q1C, 0, NotSerialized) // Thermal Trip
192	{
193		Printf ("EC: Thermal Trip")
194		/* TODO
195		Notify (\_TZ.TZ0, 0x81) // Thermal Trip Point Change
196		Notify (\_TZ.TZ0, 0x80) // Thermal Status Change
197		*/
198	}
199
200	Method (_Q1D, 0, NotSerialized) // Power Button
201	{
202		Printf ("EC: Power Button")
203		Notify (PWRB, 0x80)
204	}
205
206	Method (_Q50, 0, NotSerialized) // Other Events
207	{
208		Local0 = OEM4
209		If (Local0 == 0x8A) {
210			Printf ("EC: White Keyboard Backlight")
211			Notify (^^^^S76D, 0x80)
212		} ElseIf (Local0 == 0x9F) {
213			Printf ("EC: Color Keyboard Toggle")
214			Notify (^^^^S76D, 0x81)
215		} ElseIf (Local0 == 0x81) {
216			Printf ("EC: Color Keyboard Down")
217			Notify (^^^^S76D, 0x82)
218		} ElseIf (Local0 == 0x82) {
219			Printf ("EC: Color Keyboard Up")
220			Notify (^^^^S76D, 0x83)
221		} ElseIf (Local0 == 0x80) {
222			Printf ("EC: Color Keyboard Color Change")
223			Notify (^^^^S76D, 0x84)
224		} Else {
225			Printf ("EC: Other: %o", ToHexString(Local0))
226		}
227	}
228}
229