Nico Huber | ae7c968 | 2013-05-23 18:13:23 +0200 | [diff] [blame] | 1 | /* |
| 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. |
Nico Huber | ae7c968 | 2013-05-23 18:13:23 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef SUPERIO_ACPI_PNP_DEFS_ASL |
| 17 | #define SUPERIO_ACPI_PNP_DEFS_ASL |
| 18 | |
| 19 | #define _SUPERIO_ID(name, ldn) name ## ldn |
| 20 | #define SUPERIO_ID(name, ldn) _SUPERIO_ID(name, ldn) |
| 21 | |
| 22 | #define STRINGIFY(x) #x |
| 23 | #define EXPAND_AND_STRINGIFY(x) STRINGIFY(x) |
| 24 | #define SUPERIO_UID(name, ldn) \ |
| 25 | EXPAND_AND_STRINGIFY(SUPERIO_CHIP_NAME-SUPERIO_ID(name, ldn)) |
| 26 | #define SUPERIO_NAME(name) EXPAND_AND_STRINGIFY(SUPERIO_CHIP_NAME name) |
| 27 | |
| 28 | /* Some longer identifiers for readability */ |
| 29 | #define PNP_ADDR_REG ADDR |
| 30 | #define PNP_DATA_REG DATA |
| 31 | #define PNP_LOGICAL_DEVICE LDN |
| 32 | #define PNP_DEVICE_ACTIVE ACTR |
| 33 | #define PNP_IO0_HIGH_BYTE IO0H |
| 34 | #define PNP_IO0_LOW_BYTE IO0L |
| 35 | #define PNP_IO1_HIGH_BYTE IO1H |
| 36 | #define PNP_IO1_LOW_BYTE IO1L |
| 37 | #define PNP_IRQ0 IRQ0 |
| 38 | #define PNP_IRQ1 IRQ1 |
| 39 | #define PNP_DMA0 DMA0 |
| 40 | |
| 41 | #define CONFIG_MODE_MUTEX CMMX |
| 42 | #define ENTER_CONFIG_MODE ENCM |
| 43 | #define EXIT_CONFIG_MODE EXCM |
| 44 | #define SWITCH_LDN SWLD |
| 45 | #define PNP_NO_LDN_CHANGE 0xff |
| 46 | |
| 47 | /* Values for ACPI's _STA method */ |
| 48 | #define DEVICE_NOT_PRESENT 0x00 |
| 49 | #define DEVICE_PRESENT_ACTIVE 0x0f |
| 50 | #define DEVICE_PRESENT_INACTIVE 0x0d |
| 51 | |
| 52 | |
| 53 | /* ================== Generic Method bodies ================= */ |
| 54 | |
| 55 | #define PNP_GENERIC_STA(LDN) \ |
| 56 | ENTER_CONFIG_MODE (LDN)\ |
| 57 | If (PNP_DEVICE_ACTIVE) {\ |
| 58 | Store (DEVICE_PRESENT_ACTIVE, Local0)\ |
| 59 | }\ |
| 60 | Else\ |
| 61 | {\ |
| 62 | Store (DEVICE_PRESENT_INACTIVE, Local0)\ |
| 63 | }\ |
| 64 | EXIT_CONFIG_MODE ()\ |
| 65 | Return (Local0)\ |
| 66 | |
| 67 | #define PNP_GENERIC_DIS(LDN) \ |
| 68 | ENTER_CONFIG_MODE (LDN)\ |
| 69 | Store (Zero, PNP_DEVICE_ACTIVE)\ |
| 70 | EXIT_CONFIG_MODE ()\ |
| 71 | |
| 72 | |
| 73 | /* |
| 74 | * Current power state (returns the chip's state) |
| 75 | */ |
| 76 | #define PNP_DEFAULT_PSC \ |
| 77 | Store(^^_PSC (), Local0)\ |
| 78 | Return (Local0) |
| 79 | |
| 80 | /* |
| 81 | * Current power state (returns the chip's state, if it's in |
| 82 | * power saving mode, 1 if this LDN is in power saving mode, |
| 83 | * 0 else) |
| 84 | * |
| 85 | * PM_REG Identifier of a register which powers down the device |
| 86 | * PM_LDN The logical device number to access the PM_REG |
| 87 | * bit |
| 88 | */ |
Nico Huber | dd94fa9 | 2013-07-01 16:29:16 +0200 | [diff] [blame] | 89 | #define PNP_GENERIC_PSC(PM_REG, PM_VAL, PM_LDN) \ |
Nico Huber | ae7c968 | 2013-05-23 18:13:23 +0200 | [diff] [blame] | 90 | Store(^^_PSC (), Local0)\ |
| 91 | If (Local0) { Return (Local0) }\ |
| 92 | ENTER_CONFIG_MODE (PM_LDN)\ |
| 93 | Store (PM_REG, Local0)\ |
| 94 | EXIT_CONFIG_MODE ()\ |
Nico Huber | dd94fa9 | 2013-07-01 16:29:16 +0200 | [diff] [blame] | 95 | If (LEqual(Local0, PM_VAL)) { Return (1) }\ |
Nico Huber | ae7c968 | 2013-05-23 18:13:23 +0200 | [diff] [blame] | 96 | Else { Return (0) }\ |
| 97 | |
| 98 | /* Disable power saving mode */ |
Nico Huber | dd94fa9 | 2013-07-01 16:29:16 +0200 | [diff] [blame] | 99 | #define PNP_GENERIC_PS0(PM_REG, PM_VAL, PM_LDN) \ |
Nico Huber | ae7c968 | 2013-05-23 18:13:23 +0200 | [diff] [blame] | 100 | ENTER_CONFIG_MODE (PM_LDN)\ |
Nico Huber | dd94fa9 | 2013-07-01 16:29:16 +0200 | [diff] [blame] | 101 | Store (Not(PM_VAL), PM_REG)\ |
Nico Huber | ae7c968 | 2013-05-23 18:13:23 +0200 | [diff] [blame] | 102 | EXIT_CONFIG_MODE () |
| 103 | |
| 104 | /* Enable power saving mode */ |
Nico Huber | dd94fa9 | 2013-07-01 16:29:16 +0200 | [diff] [blame] | 105 | #define PNP_GENERIC_PS1(PM_REG, PM_VAL, PM_LDN) \ |
Nico Huber | ae7c968 | 2013-05-23 18:13:23 +0200 | [diff] [blame] | 106 | ENTER_CONFIG_MODE (PM_LDN)\ |
Nico Huber | dd94fa9 | 2013-07-01 16:29:16 +0200 | [diff] [blame] | 107 | Store (PM_VAL, PM_REG)\ |
Nico Huber | ae7c968 | 2013-05-23 18:13:23 +0200 | [diff] [blame] | 108 | EXIT_CONFIG_MODE () |
| 109 | |
| 110 | |
| 111 | /* ==================== Resource helpers ==================== */ |
| 112 | |
| 113 | #define PNP_READ_IO(IO_FROM, RESOURCE_TEMPLATE, IO_TAG) \ |
| 114 | CreateWordField (RESOURCE_TEMPLATE, IO_TAG._MIN, IO_TAG##I)\ |
| 115 | CreateWordField (RESOURCE_TEMPLATE, IO_TAG._MAX, IO_TAG##A)\ |
| 116 | Or (ShiftLeft (IO_FROM##_HIGH_BYTE, 8), IO_FROM##_LOW_BYTE, Local0)\ |
| 117 | Store (Local0, IO_TAG##I)\ |
| 118 | Store (Local0, IO_TAG##A) |
| 119 | |
| 120 | #define PNP_READ_IRQ(IRQ_FROM, RESOURCE_TEMPLATE, IRQ_TAG) \ |
| 121 | CreateWordField (RESOURCE_TEMPLATE, IRQ_TAG._INT, IRQ_TAG##W)\ |
| 122 | ShiftLeft (One, IRQ_FROM, IRQ_TAG##W) |
| 123 | |
| 124 | #define PNP_READ_DMA(DMA_FROM, RESOURCE_TEMPLATE, DMA_TAG) \ |
| 125 | CreateWordField (RESOURCE_TEMPLATE, DMA_TAG._DMA, DMA_TAG##W)\ |
| 126 | ShiftLeft (One, DMA_FROM, DMA_TAG##W) |
| 127 | |
| 128 | #define PNP_WRITE_IO(IO_TO, RESOURCE, IO_TAG) \ |
| 129 | CreateWordField (RESOURCE, IO_TAG._MIN, IO_TAG##I)\ |
| 130 | Store (And(IO_TAG##I, 0xff), IO_TO##_LOW_BYTE)\ |
| 131 | Store (ShiftRight(IO_TAG##I, 8), IO_TO##_HIGH_BYTE) |
| 132 | |
| 133 | #define PNP_WRITE_IRQ(IRQ_TO, RESOURCE, IRQ_TAG) \ |
| 134 | CreateWordField (RESOURCE, IRQ_TAG._INT, IRQ_TAG##W)\ |
| 135 | Subtract (FindSetLeftBit (IRQ_TAG##W), 1, IRQ_TO) |
| 136 | |
| 137 | #define PNP_WRITE_DMA(DMA_TO, RESOURCE, DMA_TAG) \ |
| 138 | CreateWordField (RESOURCE, DMA_TAG._DMA, DMA_TAG##W)\ |
| 139 | Subtract (FindSetLeftBit (DMA_TAG##W), 1, DMA_TO) |
| 140 | |
| 141 | #endif |