summaryrefslogtreecommitdiff
path: root/src/ec/google/wilco/acpi/event.asl
blob: 4a3394feec399b3d36c5b099ad605f2c2242c742 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * This file is part of the coreboot project.
 *
 * Copyright 2018 Google LLC
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of
 * the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

/* ACPI_POWER_RECORD */
Name (ECPR, 0)

Method (ECQP, 0, Serialized)
{
	Local0 = R (APWR)
	Local1 = Local0 ^ ECPR
	ECPR = Local0

	If (EBIT (APAC, Local1)) {
		Printf ("AC Power Status Changed")
		Notify (AC, 0x80)
	}

	If (EBIT (APB1, Local1)) {
		If (EBIT (APB1, Local0)) {
			Printf ("BAT0 Inserted")
			Notify (BAT0, 0x81)
		} Else {
			Printf ("BAT0 Removed")
			Notify (BAT0, 0x80)
			Notify (BAT0, 0x81)
		}
	}

	If (EBIT (APC1, Local1)) {
		Printf ("BAT0 Status Change")
		Notify (BAT0, 0x80)
	}
}

/* Handle events in PmEv1 */
Method (ECQ1, 1, Serialized)
{
	/* Power button pressed */
	If (EBIT (E1PB, Arg0)) {
		Printf ("Power Button Event")
		/* Do not notify \_SB.PWRB here to prevent double event */
	}

	/* LID state changed */
	If (EBIT (E1LD, Arg0)) {
		Printf ("Lid State Changed")
		Notify (^LID, 0x80)
	}

	/* Power Event */
	If (EBIT (E1PW, Arg0)) {
		Printf ("Power Event")
		ECQP ()
	}

	/* Sleep Button */
	If (EBIT (E1SB, Arg0)) {
		Printf ("Sleep Button")
	}
}

/* Handle events in PmEv2 */
Method (ECQ2, 1, Serialized)
{
	Printf ("EVT2: %o", Arg0)

	If (EBIT (E2QS, Arg0)) {
		Printf ("QS EVENT")
		Notify (^WLCO, 0x90)
	}
}

/* Handle events in PmEv3 */
Method (ECQ3, 1, Serialized)
{
	Printf ("EVT3: %o", Arg0)

#ifdef EC_ENABLE_DPTF
	/* Theraml Events */
	If (EBIT (E3TH, Arg0)) {
		^PATX ()
	}
#endif
}

/* Handle events in PmEv4 */
Method (ECQ4, 1, Serialized)
{
	Printf ("EVT4: %o", Arg0)
}

/* Process all events */
Method (_Q66, 0, Serialized)
{
	Local0 = R (EVT1)
	If (Local0) {
		ECQ1 (Local0)
	}

	Local0 = R (EVT2)
	If (Local0) {
		ECQ2 (Local0)
	}

	Local0 = R (EVT3)
	If (Local0) {
		ECQ3 (Local0)
	}

	Local0 = R (EVT4)
	If (Local0) {
		ECQ4 (Local0)
	}
}

/* Get Event Buffer */
Method (QSET, 0, Serialized)
{
	/* Get count of event bytes */
	Local0 = R (QSEC)
	Name (QBUF, Buffer (Local0) {})

	/* Fill QS event buffer with Local0 bytes */
	For (Local1 = 0, Local1 < Local0, Local1++) {
		QBUF[Local1] = R (QSEB)
	}

	Printf ("QS = %o", QBUF)
	Return (QBUF)
}