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