summaryrefslogtreecommitdiff
path: root/src/ec/clevo/it5570e/acpi/ec.asl
blob: a4b282c4cc99099dde85f062d6b95a8519161f9b (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* SPDX-License-Identifier: GPL-2.0-only */

#include <ec/clevo/it5570e/commands.h>

#define EC_DATA_IO	0x62
#define EC_SC_IO	0x66

Device (EC0)
{
	Name (_HID, "PNP0C09")
	Name (_GPE, EC_GPE_SCI)

	Name (_CRS, ResourceTemplate ()
	{
		IO (Decode16, 0x62, 0x62, 0, 1)
		IO (Decode16, 0x66, 0x66, 0, 1)
	})

	#include <ec/acpi/ec.asl>

	OperationRegion (PMS0, SystemMemory, 0xfe001b1c, 4)
	Field (PMS0, DWordAcc, NoLock, Preserve)
	{
		    , 15,
		GS0E,  1, /* Global SLP_S0# enable */
	}

	#include "ec_ram.asl"

	External (SFCV, MethodObj) /* Generated in SSDT */

	Method (INIT)
	{
		Printf ("EC: INIT")

		ECOS  = 2	/* ACPI with driver */
		BLCT  = 1	/* Enable ACPI brightness control */
		CAMK  = 1	/* Enable camera hotkey */

		SFCV ()		/* Apply custom fan curve */

		PNOT ()
	}

	Method (_INI)
	{
		Printf ("EC: _INI")

		INIT ()
	}

	/* Send FCMD */
	Method (SFCC, 1, Serialized)
	{
		FCMD = Arg0
		SEND_EC_COMMAND(0)

		/* EC sets FCMD = 0x00 on completion (FCMD = 0xfa on some commands) */
		Local0 = 50
		While (Local0--)
		{
			Stall (1)
			If (FCMD == 0x00 || FCMD == 0xfa)
			{
				Printf("EC: FCMD 0x%o completed after %o ms",
				       ToHexString(Arg0), ToDecimalString(50 - Local0))
				Return (1)
			}
		}
		Printf("EC: FCMD 0x%o timed out", ToHexString(Arg0))
		Return (0)
	}

	/*
	 * Method called from _PTS prior to system sleep state entry
	 */
	Method (PTS, 1, Serialized)
	{
		Printf ("EC: PTS: Arg0=%o", ToDecimalString(Arg0))

		WFNO = 0	/* Clear wake cause */
	}

	/*
	 * Method called from _WAK prior to system sleep state wakeup
	 */
	Method (WAK, 1, Serialized)
	{
		Printf ("EC: WAK: Arg0=%o, WFNO=%o", ToDecimalString(Arg0), ToHexString (WFNO))

		INIT ()

		/* update battery */
		Notify (\_SB.BAT0, 0x00) /* bus check */
		Notify (\_SB.BAT0, 0x80) /* state change */
		Notify (\_SB.BAT0, 0x81) /* information change */

		/* update AC */
		Notify (\_SB.AC, 0x00) /* bus check */
		Notify (\_SB.AC, 0x80) /* state change */

		If (Arg0 == 0x03 || Arg0 == 0x04) {
			Notify (\_SB.PWRB, 0x02) /* Wake */
		}
	}

	/*
	 * Display On/Off Notifications
	 * Called from \_SB.PEPD._DSM
	 */
	Name (KBLV, 0)
	Method (EDSX, 1, Serialized)
	{
		Printf ("EC: PEP display hook, state=%o", ToDecimalString (Arg0))

		If (S5FG)
		{
			Return ()
		}

		/* Display off */
		If (!Arg0)
		{
			/* Store current keyboard backlight level */
			FDAT = FDAT_KBLED_WHITE_GET_LEVEL
			SFCC (FCMD_KLED)
			KBLV = FBUF

			/* Turn off keyboard backlight */
			FDAT = FDAT_KBLED_WHITE_SET_LEVEL
			FBUF = 0x00
			SFCC (FCMD_KLED)
		}

		/* Display on */
		Else
		{
			/* Restore keyboard backlight level */
			FDAT = FDAT_KBLED_WHITE_SET_LEVEL
			FBUF = KBLV
			SFCC (FCMD_KLED)
		}
	}

	/*
	 * S0ix Entry/Exit Notifications
	 * Called from \_SB.PEPD._DSM
	 */
	Method (S0IX, 1, Serialized)
	{
		If (S5FG)
		{
			Return ()
		}

		Printf ("EC: S0ix change, state=%o", ToDecimalString (Arg0))

		/* S0ix entry */
		If (Arg0)
		{
			MSFG = 1	/* Notify EC */
		}

		/* S0ix exit */
		Else
		{
			GS0E = 0	/* Block SLP_S0# assertion during wakeup */
			MSFG = 0	/* Notfiy EC */
			Sleep (150)	/* wait for EC to become ready */
			SFCV ()		/* Apply custom fan curve */
			GS0E = 1	/* Unblock SLP_S0# */
		}
	}

	#include "ec_queries.asl"
}