summaryrefslogtreecommitdiffstats
path: root/src/soc/amd/common/acpi/gpio_bank_lib.asl
blob: eba263e58ae7438fe396e1eb36c387171a342f9f (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
/* SPDX-License-Identifier: GPL-2.0-only */

#include <amdblocks/acpimmio_map.h>
#include <amdblocks/gpio_defs.h>
#include <soc/iomap.h>

/* 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
}

/*
 * 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_PIN_STS & VAL0) >> GPIO_PIN_STS_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)
}