Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
| 4 | #include <acpi/acpi_device.h> |
| 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/pci_ids.h> |
| 8 | #include <device/pci_ops.h> |
| 9 | #include <device/pci.h> |
| 10 | #include <intelblocks/pmc.h> |
| 11 | #include <intelblocks/pmc_ipc.h> |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 12 | #include <intelblocks/pcie_rp.h> |
| 13 | #include <soc/iomap.h> |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 14 | #include "chip.h" |
| 15 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 16 | /* PCIe Root Port registers for link status and L23 control. */ |
| 17 | #define PCH_PCIE_CFG_LSTS 0x52 /* Link Status Register */ |
| 18 | #define PCH_PCIE_CFG_SPR 0xe0 /* Scratchpad */ |
| 19 | #define PCH_PCIE_CFG_RPPGEN 0xe2 /* Root Port Power Gating Enable */ |
| 20 | #define PCH_PCIE_CFG_LCAP_PN 0x4f /* Root Port Number */ |
| 21 | |
| 22 | /* ACPI register names corresponding to PCIe root port registers. */ |
| 23 | #define ACPI_REG_PCI_LINK_ACTIVE "LASX" /* Link active status */ |
| 24 | #define ACPI_REG_PCI_L23_RDY_ENTRY "L23E" /* L23_Rdy Entry Request */ |
| 25 | #define ACPI_REG_PCI_L23_RDY_DETECT "L23R" /* L23_Rdy Detect Transition */ |
| 26 | #define ACPI_REG_PCI_L23_SAVE_STATE "NCB7" /* Scratch bit to save L23 state */ |
| 27 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 28 | /* ACPI path to the mutex that protects accesses to PMC ModPhy power gating registers */ |
| 29 | #define RTD3_MUTEX_PATH "\\_SB.PCI0.R3MX" |
| 30 | |
Kane Chen | fa77ac9 | 2023-07-06 16:05:42 +0800 | [diff] [blame] | 31 | /* ACPI path to control PCIE CLK by P2SB */ |
| 32 | #define RTD3_PCIE_CLK_ENABLE_PATH "\\_SB.PCI0.SPCO" |
| 33 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 34 | enum modphy_pg_state { |
| 35 | PG_DISABLE = 0, |
| 36 | PG_ENABLE = 1, |
| 37 | }; |
| 38 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 39 | /* Called from _ON to get PCIe link back to active state. */ |
| 40 | static void pcie_rtd3_acpi_l23_exit(void) |
| 41 | { |
| 42 | /* Skip if port is not in L2/L3. */ |
| 43 | acpigen_write_if_lequal_namestr_int(ACPI_REG_PCI_L23_SAVE_STATE, 1); |
| 44 | |
| 45 | /* Initiate L2/L3 Ready To Detect transition. */ |
| 46 | acpigen_write_store_int_to_namestr(1, ACPI_REG_PCI_L23_RDY_DETECT); |
| 47 | |
| 48 | /* Wait for transition to detect. */ |
| 49 | acpigen_write_delay_until_namestr_int(320, ACPI_REG_PCI_L23_RDY_DETECT, 0); |
| 50 | |
| 51 | acpigen_write_store_int_to_namestr(0, ACPI_REG_PCI_L23_SAVE_STATE); |
| 52 | |
| 53 | /* Once in detect, wait for link active. */ |
| 54 | acpigen_write_delay_until_namestr_int(128, ACPI_REG_PCI_LINK_ACTIVE, 1); |
| 55 | |
| 56 | acpigen_pop_len(); /* If */ |
| 57 | } |
| 58 | |
| 59 | /* Called from _OFF to put PCIe link into L2/L3 state. */ |
| 60 | static void pcie_rtd3_acpi_l23_entry(void) |
| 61 | { |
| 62 | /* Initiate L2/L3 Entry request. */ |
| 63 | acpigen_write_store_int_to_namestr(1, ACPI_REG_PCI_L23_RDY_ENTRY); |
| 64 | |
| 65 | /* Wait for L2/L3 Entry request to clear. */ |
| 66 | acpigen_write_delay_until_namestr_int(128, ACPI_REG_PCI_L23_RDY_ENTRY, 0); |
| 67 | |
| 68 | acpigen_write_store_int_to_namestr(1, ACPI_REG_PCI_L23_SAVE_STATE); |
| 69 | } |
| 70 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 71 | /* Called from _ON/_OFF to disable/enable ModPHY power gating */ |
| 72 | static void pcie_rtd3_enable_modphy_pg(unsigned int pcie_rp, enum modphy_pg_state state) |
| 73 | { |
| 74 | /* Enter the critical section */ |
| 75 | acpigen_emit_ext_op(ACQUIRE_OP); |
| 76 | acpigen_emit_namestring(RTD3_MUTEX_PATH); |
| 77 | acpigen_emit_word(ACPI_MUTEX_NO_TIMEOUT); |
| 78 | |
| 79 | acpigen_write_store_int_to_namestr(state, "EMPG"); |
| 80 | acpigen_write_delay_until_namestr_int(100, "AMPG", state); |
| 81 | |
| 82 | /* Exit the critical section */ |
| 83 | acpigen_emit_ext_op(RELEASE_OP); |
| 84 | acpigen_emit_namestring(RTD3_MUTEX_PATH); |
| 85 | } |
| 86 | |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 87 | /* Method to enter L2/L3 */ |
| 88 | static void pcie_rtd3_acpi_method_dl23(void) |
| 89 | { |
| 90 | acpigen_write_method_serialized("DL23", 0); |
| 91 | pcie_rtd3_acpi_l23_entry(); |
| 92 | acpigen_pop_len(); /* Method */ |
| 93 | } |
| 94 | |
| 95 | /* Method to exit L2/L3 */ |
| 96 | static void pcie_rtd3_acpi_method_l23d(void) |
| 97 | { |
| 98 | acpigen_write_method_serialized("L23D", 0); |
| 99 | pcie_rtd3_acpi_l23_exit(); |
| 100 | acpigen_pop_len(); /* Method */ |
| 101 | } |
| 102 | |
| 103 | /* Method to disable PCH modPHY power gating */ |
| 104 | static void pcie_rtd3_acpi_method_pds0(unsigned int pcie_rp) |
| 105 | { |
| 106 | acpigen_write_method_serialized("PSD0", 0); |
| 107 | pcie_rtd3_enable_modphy_pg(pcie_rp, PG_DISABLE); |
| 108 | acpigen_pop_len(); /* Method */ |
| 109 | } |
| 110 | |
| 111 | /* Method to enable/disable the source clock */ |
| 112 | static void pcie_rtd3_acpi_method_srck(unsigned int pcie_rp, |
| 113 | const struct soc_intel_common_block_pcie_rtd3_config *config) |
| 114 | { |
| 115 | acpigen_write_method_serialized("SRCK", 1); |
| 116 | |
| 117 | if (config->srcclk_pin >= 0) { |
| 118 | acpigen_write_if_lequal_op_op(ARG0_OP, 0); |
| 119 | pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, false); |
| 120 | acpigen_write_else(); |
| 121 | pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, true); |
| 122 | acpigen_pop_len(); /* If */ |
| 123 | } |
| 124 | acpigen_pop_len(); /* Method */ |
| 125 | } |
| 126 | |
Kane Chen | fa77ac9 | 2023-07-06 16:05:42 +0800 | [diff] [blame] | 127 | /* Method to enable/disable pcie clock by p2sb*/ |
| 128 | static void p2sb_acpi_set_pci_clock(u8 srcclk_pin, bool enable) |
| 129 | { |
| 130 | acpigen_write_if_cond_ref_of(RTD3_PCIE_CLK_ENABLE_PATH); |
| 131 | acpigen_emit_namestring(RTD3_PCIE_CLK_ENABLE_PATH); |
| 132 | acpigen_write_integer(srcclk_pin); |
| 133 | acpigen_write_integer(enable); |
| 134 | acpigen_write_if_end(); |
| 135 | } |
| 136 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 137 | static void |
| 138 | pcie_rtd3_acpi_method_on(unsigned int pcie_rp, |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 139 | const struct soc_intel_common_block_pcie_rtd3_config *config, |
Kane Chen | 11be556 | 2022-11-03 23:18:44 +0800 | [diff] [blame] | 140 | enum pcie_rp_type rp_type, |
| 141 | const struct device *dev) |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 142 | { |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame^] | 143 | const struct device *parent = dev->upstream->dev; |
Kane Chen | 11be556 | 2022-11-03 23:18:44 +0800 | [diff] [blame] | 144 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 145 | acpigen_write_method_serialized("_ON", 0); |
| 146 | |
Cliff Huang | 0539962 | 2023-02-04 21:20:08 -0800 | [diff] [blame] | 147 | /* When this feature is enabled, ONSK indicates if the previous _OFF was |
| 148 | * skipped. If so, since the device was not in Off state, and the current |
| 149 | * _ON can be skipped as well. |
| 150 | */ |
| 151 | if (config->skip_on_off_support) |
| 152 | acpigen_write_if_lequal_namestr_int("ONSK", 0); |
| 153 | |
Kane Chen | 11be556 | 2022-11-03 23:18:44 +0800 | [diff] [blame] | 154 | /* The _STA returns current power status of device, so we can skip _ON |
| 155 | * if _STA returns 1 |
| 156 | * Example: |
| 157 | * Local0 = \_SB.PCI0.RP01.RTD3._STA () |
| 158 | * If ((Local0 == One)) |
| 159 | * { |
| 160 | * Return (One) |
| 161 | * } |
| 162 | */ |
| 163 | acpigen_write_store(); |
| 164 | acpigen_emit_namestring(acpi_device_path_join(parent, "RTD3._STA")); |
| 165 | acpigen_emit_byte(LOCAL0_OP); |
| 166 | acpigen_write_if_lequal_op_int(LOCAL0_OP, ONE_OP); |
| 167 | acpigen_write_return_op(ONE_OP); |
| 168 | acpigen_write_if_end(); |
| 169 | |
Cliff Huang | 69564f3 | 2023-03-02 10:03:32 -0800 | [diff] [blame] | 170 | if (config->use_rp_mutex) |
| 171 | acpigen_write_acquire(acpi_device_path_join(parent, RP_MUTEX_NAME), |
| 172 | ACPI_MUTEX_NO_TIMEOUT); |
| 173 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 174 | /* Disable modPHY power gating for PCH RPs. */ |
| 175 | if (rp_type == PCIE_RP_PCH) |
| 176 | pcie_rtd3_enable_modphy_pg(pcie_rp, PG_DISABLE); |
| 177 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 178 | /* Assert enable GPIO to turn on device power. */ |
| 179 | if (config->enable_gpio.pin_count) { |
| 180 | acpigen_enable_tx_gpio(&config->enable_gpio); |
| 181 | if (config->enable_delay_ms) |
| 182 | acpigen_write_sleep(config->enable_delay_ms); |
| 183 | } |
| 184 | |
Kane Chen | fa77ac9 | 2023-07-06 16:05:42 +0800 | [diff] [blame] | 185 | /* Enable SRCCLK for this root port if pin is defined. */ |
| 186 | if (config->srcclk_pin >= 0) { |
| 187 | if (CONFIG(PCIE_CLOCK_CONTROL_THROUGH_P2SB)) |
| 188 | p2sb_acpi_set_pci_clock(config->srcclk_pin, true); |
| 189 | else |
| 190 | pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, true); |
| 191 | } |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 192 | |
| 193 | /* De-assert reset GPIO to bring device out of reset. */ |
| 194 | if (config->reset_gpio.pin_count) { |
| 195 | acpigen_disable_tx_gpio(&config->reset_gpio); |
| 196 | if (config->reset_delay_ms) |
| 197 | acpigen_write_sleep(config->reset_delay_ms); |
| 198 | } |
| 199 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 200 | /* Trigger L23 ready exit flow unless disabled by config. */ |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 201 | if (!config->disable_l23) |
| 202 | pcie_rtd3_acpi_l23_exit(); |
| 203 | |
Cliff Huang | 69564f3 | 2023-03-02 10:03:32 -0800 | [diff] [blame] | 204 | if (config->use_rp_mutex) |
| 205 | acpigen_write_release(acpi_device_path_join(parent, RP_MUTEX_NAME)); |
| 206 | |
Cliff Huang | d1a7416 | 2022-01-21 14:54:32 -0800 | [diff] [blame] | 207 | if (config->skip_on_off_support) { |
| 208 | /* If current _ON is skipped, ONSK is decremented so that _ON will be |
| 209 | * executed normally until _OFF is skipped again. |
| 210 | */ |
| 211 | acpigen_write_else(); |
| 212 | acpigen_emit_byte(DECREMENT_OP); |
| 213 | acpigen_emit_namestring("ONSK"); |
| 214 | |
| 215 | acpigen_pop_len(); /* Else */ |
| 216 | } |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 217 | acpigen_pop_len(); /* Method */ |
| 218 | } |
| 219 | |
| 220 | static void |
| 221 | pcie_rtd3_acpi_method_off(int pcie_rp, |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 222 | const struct soc_intel_common_block_pcie_rtd3_config *config, |
Cliff Huang | 69564f3 | 2023-03-02 10:03:32 -0800 | [diff] [blame] | 223 | enum pcie_rp_type rp_type, |
| 224 | const struct device *dev) |
| 225 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 226 | { |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame^] | 227 | const struct device *parent = dev->upstream->dev; |
Cliff Huang | 69564f3 | 2023-03-02 10:03:32 -0800 | [diff] [blame] | 228 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 229 | acpigen_write_method_serialized("_OFF", 0); |
| 230 | |
Cliff Huang | d1a7416 | 2022-01-21 14:54:32 -0800 | [diff] [blame] | 231 | /* When this feature is enabled, ONSK is checked to see if the device |
| 232 | * wants _OFF to be skipped for once. ONSK is normally incremented in the |
| 233 | * device method, such as reset _RST, which is invoked during driver reload. |
| 234 | * In such case, _OFF needs to be avoided at the end of driver removal. |
| 235 | */ |
| 236 | if (config->skip_on_off_support) |
| 237 | acpigen_write_if_lequal_namestr_int("OFSK", 0); |
| 238 | |
Cliff Huang | 69564f3 | 2023-03-02 10:03:32 -0800 | [diff] [blame] | 239 | if (config->use_rp_mutex) |
| 240 | acpigen_write_acquire(acpi_device_path_join(parent, RP_MUTEX_NAME), |
| 241 | ACPI_MUTEX_NO_TIMEOUT); |
| 242 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 243 | /* Trigger L23 ready entry flow unless disabled by config. */ |
| 244 | if (!config->disable_l23) |
| 245 | pcie_rtd3_acpi_l23_entry(); |
| 246 | |
| 247 | /* Assert reset GPIO to place device into reset. */ |
| 248 | if (config->reset_gpio.pin_count) { |
| 249 | acpigen_enable_tx_gpio(&config->reset_gpio); |
| 250 | if (config->reset_off_delay_ms) |
| 251 | acpigen_write_sleep(config->reset_off_delay_ms); |
| 252 | } |
| 253 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 254 | /* Enable modPHY power gating for PCH RPs */ |
| 255 | if (rp_type == PCIE_RP_PCH) |
| 256 | pcie_rtd3_enable_modphy_pg(pcie_rp, PG_ENABLE); |
| 257 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 258 | /* Disable SRCCLK for this root port if pin is defined. */ |
Kane Chen | fa77ac9 | 2023-07-06 16:05:42 +0800 | [diff] [blame] | 259 | if (config->srcclk_pin >= 0) { |
| 260 | if (CONFIG(PCIE_CLOCK_CONTROL_THROUGH_P2SB)) |
| 261 | p2sb_acpi_set_pci_clock(config->srcclk_pin, false); |
| 262 | else |
| 263 | pmc_ipc_acpi_set_pci_clock(pcie_rp, config->srcclk_pin, false); |
| 264 | } |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 265 | |
| 266 | /* De-assert enable GPIO to turn off device power. */ |
| 267 | if (config->enable_gpio.pin_count) { |
| 268 | acpigen_disable_tx_gpio(&config->enable_gpio); |
| 269 | if (config->enable_off_delay_ms) |
| 270 | acpigen_write_sleep(config->enable_off_delay_ms); |
| 271 | } |
| 272 | |
Cliff Huang | 69564f3 | 2023-03-02 10:03:32 -0800 | [diff] [blame] | 273 | if (config->use_rp_mutex) |
| 274 | acpigen_write_release(acpi_device_path_join(parent, RP_MUTEX_NAME)); |
| 275 | |
Cliff Huang | d1a7416 | 2022-01-21 14:54:32 -0800 | [diff] [blame] | 276 | if (config->skip_on_off_support) { |
| 277 | /* If current _OFF is skipped, ONSK is incremented so that the |
| 278 | * following _ON will also be skipped. In addition, OFSK is decremented |
| 279 | * so that next _OFF will be executed normally until the device method |
| 280 | * increments OFSK again. |
| 281 | */ |
| 282 | acpigen_write_else(); |
| 283 | /* OFSK-- */ |
| 284 | acpigen_emit_byte(DECREMENT_OP); |
| 285 | acpigen_emit_namestring("OFSK"); |
| 286 | /* ONSK++ */ |
| 287 | acpigen_emit_byte(INCREMENT_OP); |
| 288 | acpigen_emit_namestring("ONSK"); |
| 289 | |
| 290 | acpigen_pop_len(); /* Else */ |
| 291 | } |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 292 | acpigen_pop_len(); /* Method */ |
| 293 | } |
| 294 | |
| 295 | static void |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 296 | pcie_rtd3_acpi_method_status(const struct soc_intel_common_block_pcie_rtd3_config *config) |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 297 | { |
| 298 | const struct acpi_gpio *gpio; |
| 299 | |
| 300 | acpigen_write_method("_STA", 0); |
Cliff Huang | 9a5a963 | 2023-01-24 17:05:17 -0800 | [diff] [blame] | 301 | /* |
| 302 | * Depending on the board configuration we use either the "enable" or |
| 303 | * the "reset" pin to detect the status of the device. The logic for |
| 304 | * each pin is detailed below. |
| 305 | * |
| 306 | * 1. For the "enable" pin: |
| 307 | * | polarity | tx value | get_tx_gpio() | State | |
| 308 | * |-------------+----------+---------------+-------| |
| 309 | * | active high | 0 | 0 | 0 | |
| 310 | * | active high | 1 | 1(active) | 1 | |
| 311 | * | active low | 0 | 1(active) | 1 | |
| 312 | * | active low | 1 | 0 | 0 | |
| 313 | * |
| 314 | * 2. For the "reset" pin: |
| 315 | * | polarity | tx value | get_tx_gpio() | State | |
| 316 | * |-------------+----------+---------------+-------| |
| 317 | * | active high | 0 | 0 | 1 | |
| 318 | * | active high | 1 | 1(active) | 0 | |
| 319 | * | active low | 0 | 1(active) | 0 | |
| 320 | * | active low | 1 | 0 | 1 | |
| 321 | */ |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 322 | |
| 323 | /* Use enable GPIO for status if provided, otherwise use reset GPIO. */ |
Cliff Huang | 9a5a963 | 2023-01-24 17:05:17 -0800 | [diff] [blame] | 324 | if (config->enable_gpio.pin_count) { |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 325 | gpio = &config->enable_gpio; |
Cliff Huang | 9a5a963 | 2023-01-24 17:05:17 -0800 | [diff] [blame] | 326 | /* Read current GPIO state into Local0. */ |
| 327 | acpigen_get_tx_gpio(gpio); |
| 328 | } else { |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 329 | gpio = &config->reset_gpio; |
Cliff Huang | 9a5a963 | 2023-01-24 17:05:17 -0800 | [diff] [blame] | 330 | /* Read current GPIO state into Local0. */ |
| 331 | acpigen_get_tx_gpio(gpio); |
| 332 | acpigen_write_not(LOCAL0_OP, LOCAL0_OP); |
| 333 | } |
| 334 | acpigen_write_return_op(LOCAL0_OP); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 335 | acpigen_pop_len(); /* Method */ |
| 336 | } |
| 337 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 338 | static void write_modphy_opregion(unsigned int pcie_rp) |
| 339 | { |
| 340 | /* The register containing the Power Gate enable sequence bits is at |
| 341 | PCH_PWRM_BASE + 0x10D0, and the bits to check for sequence completion are at |
| 342 | PCH_PWRM_BASE + 0x10D4. */ |
| 343 | const struct opregion opregion = OPREGION("PMCP", SYSTEMMEMORY, |
| 344 | PCH_PWRM_BASE_ADDRESS + 0x1000, 0xff); |
| 345 | const struct fieldlist fieldlist[] = { |
| 346 | FIELDLIST_OFFSET(0xD0), |
| 347 | FIELDLIST_RESERVED(pcie_rp), |
| 348 | FIELDLIST_NAMESTR("EMPG", 1), /* Enable ModPHY Power Gate */ |
| 349 | FIELDLIST_OFFSET(0xD4), |
| 350 | FIELDLIST_RESERVED(pcie_rp), |
| 351 | FIELDLIST_NAMESTR("AMPG", 1), /* Is ModPHY Power Gate active? */ |
| 352 | }; |
| 353 | |
| 354 | acpigen_write_opregion(&opregion); |
| 355 | acpigen_write_field("PMCP", fieldlist, ARRAY_SIZE(fieldlist), |
| 356 | FIELD_DWORDACC | FIELD_NOLOCK | FIELD_PRESERVE); |
| 357 | } |
| 358 | |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 359 | static int get_pcie_rp_pmc_idx(enum pcie_rp_type rp_type, const struct device *dev) |
| 360 | { |
| 361 | int idx = -1; |
| 362 | |
| 363 | switch (rp_type) { |
| 364 | case PCIE_RP_PCH: |
| 365 | /* Read port number of root port that this device is attached to. */ |
| 366 | idx = pci_read_config8(dev, PCH_PCIE_CFG_LCAP_PN); |
| 367 | |
| 368 | /* Port number is 1-based, PMC IPC method expects 0-based. */ |
| 369 | idx--; |
| 370 | break; |
| 371 | case PCIE_RP_CPU: |
| 372 | /* CPU RPs are indexed by their "virtual wire index" to the PCH */ |
| 373 | idx = soc_get_cpu_rp_vw_idx(dev); |
| 374 | break; |
| 375 | default: |
| 376 | break; |
| 377 | } |
| 378 | |
| 379 | return idx; |
| 380 | } |
| 381 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 382 | static void pcie_rtd3_acpi_fill_ssdt(const struct device *dev) |
| 383 | { |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 384 | static bool mutex_created = false; |
| 385 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 386 | const struct soc_intel_common_block_pcie_rtd3_config *config = config_of(dev); |
| 387 | static const char *const power_res_states[] = {"_PR0"}; |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame^] | 388 | const struct device *parent = dev->upstream->dev; |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 389 | const char *scope = acpi_device_path(parent); |
| 390 | const struct opregion opregion = OPREGION("PXCS", PCI_CONFIG, 0, 0xff); |
| 391 | const struct fieldlist fieldlist[] = { |
| 392 | FIELDLIST_OFFSET(PCH_PCIE_CFG_LSTS), |
| 393 | FIELDLIST_RESERVED(13), |
| 394 | FIELDLIST_NAMESTR(ACPI_REG_PCI_LINK_ACTIVE, 1), |
| 395 | FIELDLIST_OFFSET(PCH_PCIE_CFG_SPR), |
| 396 | FIELDLIST_RESERVED(7), |
| 397 | FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_SAVE_STATE, 1), |
| 398 | FIELDLIST_OFFSET(PCH_PCIE_CFG_RPPGEN), |
| 399 | FIELDLIST_RESERVED(2), |
| 400 | FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_RDY_ENTRY, 1), |
| 401 | FIELDLIST_NAMESTR(ACPI_REG_PCI_L23_RDY_DETECT, 1), |
| 402 | }; |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 403 | int pcie_rp; |
Kapil Porwal | 65bcb57 | 2022-11-28 18:53:40 +0530 | [diff] [blame] | 404 | struct acpi_dp *dsd; |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 405 | |
| 406 | if (!is_dev_enabled(parent)) { |
| 407 | printk(BIOS_ERR, "%s: root port not enabled\n", __func__); |
| 408 | return; |
| 409 | } |
| 410 | if (!scope) { |
| 411 | printk(BIOS_ERR, "%s: root port scope not found\n", __func__); |
| 412 | return; |
| 413 | } |
| 414 | if (!config->enable_gpio.pin_count && !config->reset_gpio.pin_count) { |
| 415 | printk(BIOS_ERR, "%s: Enable and/or Reset GPIO required for %s.\n", |
| 416 | __func__, scope); |
| 417 | return; |
| 418 | } |
Rizwan Qureshi | a979460 | 2021-04-08 20:31:47 +0530 | [diff] [blame] | 419 | if (config->srcclk_pin > CONFIG_MAX_PCIE_CLOCK_SRC) { |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 420 | printk(BIOS_ERR, "%s: Invalid clock pin %u for %s.\n", __func__, |
| 421 | config->srcclk_pin, scope); |
| 422 | return; |
| 423 | } |
| 424 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 425 | const enum pcie_rp_type rp_type = soc_get_pcie_rp_type(parent); |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 426 | pcie_rp = get_pcie_rp_pmc_idx(rp_type, parent); |
Tim Wawrzynczak | b3cd55b | 2022-01-20 14:06:29 -0700 | [diff] [blame] | 427 | if (pcie_rp < 0) { |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 428 | printk(BIOS_ERR, "%s: Unknown PCIe root port\n", __func__); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 429 | return; |
| 430 | } |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 431 | if (config->disable_l23) { |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 432 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) { |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 433 | printk(BIOS_ERR, "%s: Can not export L23 methods\n", __func__); |
| 434 | return; |
| 435 | } |
| 436 | } |
| 437 | if (rp_type != PCIE_RP_PCH) { |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 438 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0) { |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 439 | printk(BIOS_ERR, "%s: Can not export PSD0 method\n", __func__); |
| 440 | return; |
| 441 | } |
| 442 | } |
Cliff Huang | 8fbdefc | 2023-03-21 21:51:30 -0700 | [diff] [blame] | 443 | if (config->srcclk_pin == -1) { |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 444 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK) { |
Cliff Huang | 8fbdefc | 2023-03-21 21:51:30 -0700 | [diff] [blame] | 445 | printk(BIOS_ERR, "%s: Can not export SRCK method since clock source gating is not enabled\n", |
| 446 | __func__); |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 447 | return; |
| 448 | } |
| 449 | } |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 450 | |
| 451 | printk(BIOS_INFO, "%s: Enable RTD3 for %s (%s)\n", scope, dev_path(parent), |
| 452 | config->desc ?: dev->chip_ops->name); |
| 453 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 454 | /* Create a mutex for exclusive access to the PMC registers. */ |
| 455 | if (rp_type == PCIE_RP_PCH && !mutex_created) { |
| 456 | acpigen_write_scope("\\_SB.PCI0"); |
| 457 | acpigen_write_mutex("R3MX", 0); |
| 458 | acpigen_write_scope_end(); |
| 459 | mutex_created = true; |
| 460 | } |
| 461 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 462 | /* The RTD3 power resource is added to the root port, not the device. */ |
| 463 | acpigen_write_scope(scope); |
| 464 | |
Cliff Huang | 69564f3 | 2023-03-02 10:03:32 -0800 | [diff] [blame] | 465 | if (config->use_rp_mutex) |
| 466 | acpigen_write_mutex(RP_MUTEX_NAME, 0); |
| 467 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 468 | if (config->desc) |
| 469 | acpigen_write_name_string("_DDN", config->desc); |
| 470 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 471 | /* Create OpRegions for MMIO accesses. */ |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 472 | acpigen_write_opregion(&opregion); |
| 473 | acpigen_write_field("PXCS", fieldlist, ARRAY_SIZE(fieldlist), |
| 474 | FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE); |
| 475 | |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 476 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_L23) { |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 477 | pcie_rtd3_acpi_method_dl23(); |
| 478 | pcie_rtd3_acpi_method_l23d(); |
| 479 | } |
| 480 | |
Tim Wawrzynczak | 32f883e | 2021-12-02 16:19:47 -0700 | [diff] [blame] | 481 | /* Create the OpRegion to access the ModPHY PG registers (PCH RPs only) */ |
| 482 | if (rp_type == PCIE_RP_PCH) |
| 483 | write_modphy_opregion(pcie_rp); |
| 484 | |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 485 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_PSD0) |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 486 | pcie_rtd3_acpi_method_pds0(pcie_rp); |
| 487 | |
Angel Pons | d85319a | 2022-02-13 13:35:20 +0100 | [diff] [blame] | 488 | if (config->ext_pm_support & ACPI_PCIE_RP_EMIT_SRCK) |
Cliff Huang | 4bc9ac7 | 2022-01-21 00:23:15 -0800 | [diff] [blame] | 489 | pcie_rtd3_acpi_method_srck(pcie_rp, config); |
| 490 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 491 | /* ACPI Power Resource for controlling the attached device power. */ |
| 492 | acpigen_write_power_res("RTD3", 0, 0, power_res_states, ARRAY_SIZE(power_res_states)); |
Cliff Huang | d1a7416 | 2022-01-21 14:54:32 -0800 | [diff] [blame] | 493 | |
| 494 | if (config->skip_on_off_support) { |
| 495 | /* OFSK: 0 = _OFF Method will be executed normally when called; |
| 496 | * >1 = _OFF will be skipped. |
| 497 | * _OFF Method to decrement OFSK and increment ONSK if the |
| 498 | * current execution is skipped. |
| 499 | * ONSK: 0 = _ON Method will be executed normally when called; |
| 500 | * >1 = _ONF will be skipped. |
| 501 | * _ON Method to decrement ONSK if the current execution is |
| 502 | * skipped. |
| 503 | */ |
| 504 | acpigen_write_name_integer("ONSK", 0); |
| 505 | acpigen_write_name_integer("OFSK", 0); |
| 506 | } |
| 507 | |
Tim Wawrzynczak | b6a15a7 | 2021-12-08 10:43:56 -0700 | [diff] [blame] | 508 | pcie_rtd3_acpi_method_status(config); |
Kane Chen | 11be556 | 2022-11-03 23:18:44 +0800 | [diff] [blame] | 509 | pcie_rtd3_acpi_method_on(pcie_rp, config, rp_type, dev); |
Cliff Huang | 69564f3 | 2023-03-02 10:03:32 -0800 | [diff] [blame] | 510 | pcie_rtd3_acpi_method_off(pcie_rp, config, rp_type, dev); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 511 | acpigen_pop_len(); /* PowerResource */ |
| 512 | |
| 513 | /* Indicate to the OS that device supports hotplug in D3. */ |
| 514 | dsd = acpi_dp_new_table("_DSD"); |
Kapil Porwal | 65bcb57 | 2022-11-28 18:53:40 +0530 | [diff] [blame] | 515 | acpi_device_add_hotplug_support_in_d3(dsd); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 516 | |
| 517 | /* Indicate to the OS if the device provides an External facing port. */ |
Kapil Porwal | 65bcb57 | 2022-11-28 18:53:40 +0530 | [diff] [blame] | 518 | if (config->add_acpi_external_facing_port) |
| 519 | acpi_device_add_external_facing_port(dsd); |
Kapil Porwal | d7eacd7 | 2022-11-28 11:03:38 +0530 | [diff] [blame] | 520 | |
| 521 | /* Indicate to the OS if the device has DMA property. */ |
| 522 | if (config->add_acpi_dma_property) |
| 523 | acpi_device_add_dma_property(dsd); |
| 524 | |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 525 | acpi_dp_write(dsd); |
| 526 | |
| 527 | /* |
| 528 | * Check the sibling device on the root port to see if it is storage class and add the |
| 529 | * property for the OS to enable storage D3, or allow it to be enabled by config. |
| 530 | */ |
| 531 | if (config->is_storage |
| 532 | || (dev->sibling && (dev->sibling->class >> 16) == PCI_BASE_CLASS_STORAGE)) { |
| 533 | acpigen_write_device(acpi_device_name(dev)); |
| 534 | acpigen_write_ADR(0); |
| 535 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
Sean Rhodes | 648ff92 | 2023-04-13 13:25:14 +0100 | [diff] [blame] | 536 | if (CONFIG(D3COLD_SUPPORT)) |
| 537 | acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_COLD); |
| 538 | else |
| 539 | acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_HOT); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 540 | |
Kapil Porwal | 65bcb57 | 2022-11-28 18:53:40 +0530 | [diff] [blame] | 541 | acpi_device_add_storage_d3_enable(NULL); |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 542 | |
| 543 | acpigen_pop_len(); /* Device */ |
| 544 | |
| 545 | printk(BIOS_INFO, "%s: Added StorageD3Enable property\n", scope); |
| 546 | } |
| 547 | |
| 548 | acpigen_pop_len(); /* Scope */ |
| 549 | } |
| 550 | |
| 551 | static const char *pcie_rtd3_acpi_name(const struct device *dev) |
| 552 | { |
| 553 | /* Attached device name must be "PXSX" for the Linux Kernel to recognize it. */ |
| 554 | return "PXSX"; |
| 555 | } |
| 556 | |
| 557 | static struct device_operations pcie_rtd3_ops = { |
| 558 | .read_resources = noop_read_resources, |
| 559 | .set_resources = noop_set_resources, |
| 560 | .acpi_fill_ssdt = pcie_rtd3_acpi_fill_ssdt, |
| 561 | .acpi_name = pcie_rtd3_acpi_name, |
| 562 | }; |
| 563 | |
| 564 | static void pcie_rtd3_acpi_enable(struct device *dev) |
| 565 | { |
| 566 | dev->ops = &pcie_rtd3_ops; |
| 567 | } |
| 568 | |
| 569 | struct chip_operations soc_intel_common_block_pcie_rtd3_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 570 | .name = "Intel PCIe Runtime D3", |
Duncan Laurie | 64bc26a | 2020-10-10 00:15:28 +0000 | [diff] [blame] | 571 | .enable_dev = pcie_rtd3_acpi_enable |
| 572 | }; |