summaryrefslogtreecommitdiff
path: root/src/mainboard/google/brox/acpi/utility.asl
blob: 49f3dca8e930d839ed5ebf66d4e4af7fd0ec8afe (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
/* SPDX-License-Identifier: GPL-2.0-or-later */

/*
 * Poll a GPIO until it goes to the specified state
 * Arg0 == GPIO #
 * Arg1 == state (0 or 1)
 * Arg2 == timeout in ms
 */
Method (GPPL, 3, Serialized)
{
	Local0 = 0
	Local1 = Arg2 * 10
	While (Local0 < Local1)
	{
		If (\_SB.PCI0.GRXS (Arg0) == Arg1) {
			Return (0)
		} Else {
			Local0++
		}
		Stall (100)
	}

	If (Local0 == Arg2) {
		Printf("[ERROR] GPPL for %o timed out", Arg0)
	}

	Return (0xFF)
}

/* Convert from 32-bit integer to 4-byte buffer (little-endian) */
Method (ITOB, 1)
{
	Local0 = Buffer(4) { 0, 0, 0, 0 }
	Local0[0] = Arg0 & 0xFF
	Local0[1] = (Arg0 >> 8) & 0xFF
	Local0[2] = (Arg0 >> 16) & 0xFF
	Local0[3] = (Arg0 >> 24) & 0xFF
	Return (Local0)
}

/* Convert from 64-bit integer to 8-byte buffer (little-endian) */
Method (LTOB, 1)
{
	Local0 = Buffer(8) { 0, 0, 0, 0, 0, 0, 0, 0 }
	Local0[0] = Arg0 & 0xFF
	Local0[1] = (Arg0 >> 8) & 0xFF
	Local0[2] = (Arg0 >> 16) & 0xFF
	Local0[3] = (Arg0 >> 24) & 0xFF
	Local0[4] = (Arg0 >> 32) & 0xFF
	Local0[5] = (Arg0 >> 40) & 0xFF
	Local0[6] = (Arg0 >> 48) & 0xFF
	Local0[7] = (Arg0 >> 56) & 0xFF
	Return (Local0)
}