blob: 0637c04894a4264c7b35b598557d5a093a9f4928 [file] [log] [blame]
Nico Huberae7c9682013-05-23 18:13:23 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 secunet Security Networks AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef SUPERIO_ACPI_PNP_DEFS_ASL
21#define SUPERIO_ACPI_PNP_DEFS_ASL
22
23#define _SUPERIO_ID(name, ldn) name ## ldn
24#define SUPERIO_ID(name, ldn) _SUPERIO_ID(name, ldn)
25
26#define STRINGIFY(x) #x
27#define EXPAND_AND_STRINGIFY(x) STRINGIFY(x)
28#define SUPERIO_UID(name, ldn) \
29 EXPAND_AND_STRINGIFY(SUPERIO_CHIP_NAME-SUPERIO_ID(name, ldn))
30#define SUPERIO_NAME(name) EXPAND_AND_STRINGIFY(SUPERIO_CHIP_NAME name)
31
32/* Some longer identifiers for readability */
33#define PNP_ADDR_REG ADDR
34#define PNP_DATA_REG DATA
35#define PNP_LOGICAL_DEVICE LDN
36#define PNP_DEVICE_ACTIVE ACTR
37#define PNP_IO0_HIGH_BYTE IO0H
38#define PNP_IO0_LOW_BYTE IO0L
39#define PNP_IO1_HIGH_BYTE IO1H
40#define PNP_IO1_LOW_BYTE IO1L
41#define PNP_IRQ0 IRQ0
42#define PNP_IRQ1 IRQ1
43#define PNP_DMA0 DMA0
44
45#define CONFIG_MODE_MUTEX CMMX
46#define ENTER_CONFIG_MODE ENCM
47#define EXIT_CONFIG_MODE EXCM
48#define SWITCH_LDN SWLD
49#define PNP_NO_LDN_CHANGE 0xff
50
51/* Values for ACPI's _STA method */
52#define DEVICE_NOT_PRESENT 0x00
53#define DEVICE_PRESENT_ACTIVE 0x0f
54#define DEVICE_PRESENT_INACTIVE 0x0d
55
56
57/* ================== Generic Method bodies ================= */
58
59#define PNP_GENERIC_STA(LDN) \
60 ENTER_CONFIG_MODE (LDN)\
61 If (PNP_DEVICE_ACTIVE) {\
62 Store (DEVICE_PRESENT_ACTIVE, Local0)\
63 }\
64 Else\
65 {\
66 Store (DEVICE_PRESENT_INACTIVE, Local0)\
67 }\
68 EXIT_CONFIG_MODE ()\
69 Return (Local0)\
70
71#define PNP_GENERIC_DIS(LDN) \
72 ENTER_CONFIG_MODE (LDN)\
73 Store (Zero, PNP_DEVICE_ACTIVE)\
74 EXIT_CONFIG_MODE ()\
75
76
77/*
78 * Current power state (returns the chip's state)
79 */
80#define PNP_DEFAULT_PSC \
81 Store(^^_PSC (), Local0)\
82 Return (Local0)
83
84/*
85 * Current power state (returns the chip's state, if it's in
86 * power saving mode, 1 if this LDN is in power saving mode,
87 * 0 else)
88 *
89 * PM_REG Identifier of a register which powers down the device
90 * PM_LDN The logical device number to access the PM_REG
91 * bit
92 */
Nico Huberdd94fa92013-07-01 16:29:16 +020093#define PNP_GENERIC_PSC(PM_REG, PM_VAL, PM_LDN) \
Nico Huberae7c9682013-05-23 18:13:23 +020094 Store(^^_PSC (), Local0)\
95 If (Local0) { Return (Local0) }\
96 ENTER_CONFIG_MODE (PM_LDN)\
97 Store (PM_REG, Local0)\
98 EXIT_CONFIG_MODE ()\
Nico Huberdd94fa92013-07-01 16:29:16 +020099 If (LEqual(Local0, PM_VAL)) { Return (1) }\
Nico Huberae7c9682013-05-23 18:13:23 +0200100 Else { Return (0) }\
101
102/* Disable power saving mode */
Nico Huberdd94fa92013-07-01 16:29:16 +0200103#define PNP_GENERIC_PS0(PM_REG, PM_VAL, PM_LDN) \
Nico Huberae7c9682013-05-23 18:13:23 +0200104 ENTER_CONFIG_MODE (PM_LDN)\
Nico Huberdd94fa92013-07-01 16:29:16 +0200105 Store (Not(PM_VAL), PM_REG)\
Nico Huberae7c9682013-05-23 18:13:23 +0200106 EXIT_CONFIG_MODE ()
107
108/* Enable power saving mode */
Nico Huberdd94fa92013-07-01 16:29:16 +0200109#define PNP_GENERIC_PS1(PM_REG, PM_VAL, PM_LDN) \
Nico Huberae7c9682013-05-23 18:13:23 +0200110 ENTER_CONFIG_MODE (PM_LDN)\
Nico Huberdd94fa92013-07-01 16:29:16 +0200111 Store (PM_VAL, PM_REG)\
Nico Huberae7c9682013-05-23 18:13:23 +0200112 EXIT_CONFIG_MODE ()
113
114
115/* ==================== Resource helpers ==================== */
116
117#define PNP_READ_IO(IO_FROM, RESOURCE_TEMPLATE, IO_TAG) \
118 CreateWordField (RESOURCE_TEMPLATE, IO_TAG._MIN, IO_TAG##I)\
119 CreateWordField (RESOURCE_TEMPLATE, IO_TAG._MAX, IO_TAG##A)\
120 Or (ShiftLeft (IO_FROM##_HIGH_BYTE, 8), IO_FROM##_LOW_BYTE, Local0)\
121 Store (Local0, IO_TAG##I)\
122 Store (Local0, IO_TAG##A)
123
124#define PNP_READ_IRQ(IRQ_FROM, RESOURCE_TEMPLATE, IRQ_TAG) \
125 CreateWordField (RESOURCE_TEMPLATE, IRQ_TAG._INT, IRQ_TAG##W)\
126 ShiftLeft (One, IRQ_FROM, IRQ_TAG##W)
127
128#define PNP_READ_DMA(DMA_FROM, RESOURCE_TEMPLATE, DMA_TAG) \
129 CreateWordField (RESOURCE_TEMPLATE, DMA_TAG._DMA, DMA_TAG##W)\
130 ShiftLeft (One, DMA_FROM, DMA_TAG##W)
131
132#define PNP_WRITE_IO(IO_TO, RESOURCE, IO_TAG) \
133 CreateWordField (RESOURCE, IO_TAG._MIN, IO_TAG##I)\
134 Store (And(IO_TAG##I, 0xff), IO_TO##_LOW_BYTE)\
135 Store (ShiftRight(IO_TAG##I, 8), IO_TO##_HIGH_BYTE)
136
137#define PNP_WRITE_IRQ(IRQ_TO, RESOURCE, IRQ_TAG) \
138 CreateWordField (RESOURCE, IRQ_TAG._INT, IRQ_TAG##W)\
139 Subtract (FindSetLeftBit (IRQ_TAG##W), 1, IRQ_TO)
140
141#define PNP_WRITE_DMA(DMA_TO, RESOURCE, DMA_TAG) \
142 CreateWordField (RESOURCE, DMA_TAG._DMA, DMA_TAG##W)\
143 Subtract (FindSetLeftBit (DMA_TAG##W), 1, DMA_TO)
144
145#endif