summaryrefslogtreecommitdiff
path: root/src/ec/clevo/it5570e/acpi/hid.asl
blob: 945e28580d460391bb5108991a8ef7640c30f3b3 (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
/* SPDX-License-Identifier: GPL-2.0-only */

/* Minimal implementation of HID event filter device for airplane hotkey support */

Device (HIDD)
{
	Name (_HID, "INTC1051")

	Name (HRDY, 0)
	Name (HBSY, 0)
	Name (HIDX, 0)

	/*
	 * Workaround:
	 * There was a bug in Linux' HID driver, making evaluation of function 2 fail.
	 * The driver falls back to legacy mode and evaluates integers instead of _DSM.
	 * A bugfix for this was merged to mainline and stable but not LTS-branches. Thus,
	 * let's keep this for some time.
	 * https://lore.kernel.org/r/66f813f5bcc724a0f6dd5adefe6a9728dbe509e3.camel@mniewoehner.de
	 */
	Name (HDMM, 0)

	Method (_STA)
	{
		Return (0x0f)
	}

	Method (_DSM, 4, Serialized)
	{
		If (Arg0 == ToUUID ("eeec56b3-4442-408f-a792-4edd4d758054"))
		{
			If (Arg1 == 1) /* Revision 1 */
			{
				Printf ("HIDD: _DSM called, fn=%o", ToDecimalString(Arg2))

				Switch (ToInteger (Arg2))
				{
					Case (0)
					{
						/* Supported functions: 0, 2, 3, 4, 7 */
						Return (Buffer () {0x9d, 0x00})
					}
					Case (2)
					{
						/* Simple mode */
						Return (0)
					}
					Case (3)
					{
						/* Driver status */
						HRDY = DeRefOf (Arg3[0])
					}
					Case (4)
					{
						/* HID driver calls this to get event */
						HBSY = 0
						Return (HIDX)
					}
					Case (7)
					{
						/* Only airplane mode button implemented */
						Return (1 << 1)
					}
				}
			}
		}

		Return (Buffer () {0})
	}

	/*
	 * HID Platform Event Method
	 * Called to trigger HID event.
	 */
	Method (HPEM, 1, Serialized)
	{
		Printf ("HIDD: HPEM called, event=%o", ToHexString (Arg0))

		If (!HRDY)
		{
			Printf ("HIDD: HID driver not ready. Ignoring event.")
		}

		HBSY = 1
		HIDX = Arg0

		Notify (HIDD, 0xc0)

		/* Wait max. 1 second for HID driver */
		Local0 = 0
		While ((Local0 < 250) && HBSY)
		{
			Sleep (4)
			Local0++
		}

		If (HBSY)
		{
			Printf ("HIDD: HPEM timeout")

			HBSY = 0
			HIDX = 0

			Return (1) /* Timeout */
		}

		Return (0)
	}
}