aboutsummaryrefslogtreecommitdiff
path: root/src/soc/amd/common/acpi/gpio_bank_lib.asl
blob: 8640cc114d37268b0ede6ab3ddd66f5e8d25d147 (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
177
178
179
180
181
182
183
184
/* SPDX-License-Identifier: GPL-2.0-only */

#include <soc/iomap.h>

#define GPIO_INPUT_SHIFT	16
#define GPIO_INPUT_VALUE	(1 << GPIO_INPUT_SHIFT)
#define GPIO_OUTPUT_SHIFT	22
#define GPIO_OUTPUT_VALUE	(1 << GPIO_OUTPUT_SHIFT)

/* Get pin control MMIO address */
Method (GPAD, 0x1)
{
	/* Arg0 - GPIO pin number */
	Return ((Arg0 * 4) + ACPIMMIO_GPIO0_BASE)
}

/* Read pin control dword */
Method (GPRD, 0x1, Serialized)
{
	/* Arg0 - GPIO pin control MMIO address */
	Local0 = Arg0
	OperationRegion (GPDW, SystemMemory, Local0, 4)
	Field (GPDW, AnyAcc, NoLock, Preserve) {
		TEMP, 32
	}
	Return (TEMP)
}

/* Write pin control dword */
Method (GPWR, 0x2, Serialized)
{
	/* Arg0 - GPIO pin control MMIO address */
	/* Arg1 - Value for control register */
	Local0 = Arg0
	OperationRegion (GPDW, SystemMemory, Local0, 4)
	Field (GPDW, AnyAcc, NoLock, Preserve) {
		TEMP,32
	}
	TEMP = Arg1
}

Method (GPGB, 0x2)
{
	/*
	 * Returns the desired byte
	 * Arg0 - GPIO pin control MMIO address
	 * Arg1 - Desired byte (0 through 3)
	 */
	Local2 = Arg1 * 8
	Return ((GPRD (Arg0) >> Local2) & 0x000000FF)
}

Method (GPSB, 0x3)
{
	/*
	 * Reads dword, replace byte, write back dword
	 * Arg0 - GPIO pin control MMIO address
	 * Arg1 - Desired byte (0 through 3)
	 * Arg2 - Value
	 */
	Local2 = Arg1 * 8
	Local3 = (GPRD(Arg0) >> Local2) & 0xFFFFFF00
	Local4 = ((Arg2 & 0x000000FF) | Local3) << Local2
	GPWR (Arg0, Local4)
}

/* Read pin control byte 0 */
Method (GPR0, 0x1)
{
	/* Arg0 - GPIO pin control MMIO address */
	Return (GPGB(Arg0, 0))
}

/* Read pin control byte 1 */
Method (GPR1, 0x1)
{
	/* Arg0 - GPIO pin control MMIO address */
	Return (GPGB(Arg0, 1))
}

/* Read pin control byte 2 */
Method (GPR2, 0x1)
{
	/* Arg0 - GPIO pin control MMIO address */
	Return (GPGB(Arg0, 2))
}

/* Read pin control byte 3 */
Method (GPR3, 0x1)
{
	Return (GPGB(Arg0, 3))
}

/* Write pin control byte 0 */
Method (GPW0, 0x2)
{
	/* Arg0 - GPIO pin control MMIO address */
	/* Arg1 - Value for control register */
	GPSB (Arg0, 0, Arg1)
}

/* Write pin control byte 1 */
Method (GPW1, 0x2)
{
	/* Arg0 - GPIO pin control MMIO address */
	/* Arg1 - Value for control register */
	GPSB (Arg0, 1, Arg1)
}

/* Write pin control byte 2 */
Method (GPW2, 0x2)
{
	/* Arg0 - GPIO pin control MMIO address */
	/* Arg1 - Value for control register */
	GPSB (Arg0, 2, Arg1)
}

/* Write pin control byte 3 */
Method (GPW3, 0x2)
{
	/* Arg0 - GPIO pin control MMIO address */
	/* Arg1 - Value for control register */
	GPSB (Arg0, 3, Arg1)
}

/*
 * Set GPIO Output Value
 * Arg0 - GPIO Number
 */
Method (STXS, 1, Serialized)
{
	OperationRegion (GPDW, SystemMemory, GPAD (Arg0), 4)
	Field (GPDW, AnyAcc, NoLock, Preserve)
	{
		VAL0, 32
	}
	VAL0 |= GPIO_OUTPUT_VALUE
}

/*
 * Clear GPIO Output Value
 * Arg0 - GPIO Number
 */
Method (CTXS, 1, Serialized)
{
	OperationRegion (GPDW, SystemMemory, GPAD (Arg0), 4)
	Field (GPDW, AnyAcc, NoLock, Preserve)
	{
		VAL0, 32
	}
	VAL0 &= ~GPIO_OUTPUT_VALUE
}

/*
 * Get GPIO Input Value
 * Arg0 - GPIO Number
 */
Method (GRXS, 1, Serialized)
{
	OperationRegion (GPDW, SystemMemory, GPAD (Arg0), 4)
	Field (GPDW, AnyAcc, NoLock, Preserve)
	{
		VAL0, 32
	}
	Local0 = (GPIO_INPUT_VALUE & VAL0) >> GPIO_INPUT_SHIFT

	Return (Local0)
}

/*
 * Get GPIO Output Value
 * Arg0 - GPIO Number
 */
Method (GTXS, 1, Serialized)
{
	OperationRegion (GPDW, SystemMemory, GPAD (Arg0), 4)
	Field (GPDW, AnyAcc, NoLock, Preserve)
	{
		VAL0, 32
	}
	Local0 = (GPIO_OUTPUT_VALUE & VAL0) >> GPIO_OUTPUT_SHIFT

	Return (Local0)
}