Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 4 | * Copyright (C) 2010-2017 Advanced Micro Devices, Inc. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 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 | |
| 16 | #include <console/console.h> |
| 17 | |
| 18 | #include <arch/io.h> |
Marshall Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 19 | #include <bootstate.h> |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 20 | #include <cpu/x86/smm.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pci_ids.h> |
| 24 | #include <device/pci_ops.h> |
| 25 | #include <cbmem.h> |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 26 | #include <elog.h> |
Richard Spiegel | 2bbc3dc | 2017-12-06 16:14:58 -0700 | [diff] [blame] | 27 | #include <amdblocks/amd_pci_util.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 28 | #include <soc/southbridge.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 29 | #include <soc/smi.h> |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 30 | #include <soc/amd_pci_int_defs.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 31 | #include <fchec.h> |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 32 | #include <delay.h> |
| 33 | #include <soc/pci_devs.h> |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 34 | #include <agesa_headers.h> |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 35 | #include <soc/nvs.h> |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 36 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 37 | /* |
| 38 | * Table of devices that need their AOAC registers enabled and waited |
| 39 | * upon (usually about .55 milliseconds). Instead of individual delays |
| 40 | * waiting for each device to become available, a single delay will be |
Richard Spiegel | 6dfbb59 | 2018-03-15 15:45:44 -0700 | [diff] [blame] | 41 | * executed. |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 42 | */ |
| 43 | const static struct stoneyridge_aoac aoac_devs[] = { |
| 44 | { (FCH_AOAC_D3_CONTROL_UART0 + CONFIG_UART_FOR_CONSOLE * 2), |
| 45 | (FCH_AOAC_D3_STATE_UART0 + CONFIG_UART_FOR_CONSOLE * 2) }, |
| 46 | { FCH_AOAC_D3_CONTROL_AMBA, FCH_AOAC_D3_STATE_AMBA }, |
| 47 | { FCH_AOAC_D3_CONTROL_I2C0, FCH_AOAC_D3_STATE_I2C0 }, |
| 48 | { FCH_AOAC_D3_CONTROL_I2C1, FCH_AOAC_D3_STATE_I2C1 }, |
| 49 | { FCH_AOAC_D3_CONTROL_I2C2, FCH_AOAC_D3_STATE_I2C2 }, |
| 50 | { FCH_AOAC_D3_CONTROL_I2C3, FCH_AOAC_D3_STATE_I2C3 } |
| 51 | }; |
| 52 | |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 53 | static int is_sata_config(void) |
| 54 | { |
| 55 | return !((CONFIG_STONEYRIDGE_SATA_MODE == SataNativeIde) |
| 56 | || (CONFIG_STONEYRIDGE_SATA_MODE == SataLegacyIde)); |
| 57 | } |
| 58 | |
Richard Spiegel | 7ea8e02 | 2018-01-16 14:40:10 -0700 | [diff] [blame] | 59 | static inline int sb_sata_enable(void) |
| 60 | { |
| 61 | /* True if IDE or AHCI. */ |
| 62 | return (CONFIG_STONEYRIDGE_SATA_MODE == SataNativeIde) || |
| 63 | (CONFIG_STONEYRIDGE_SATA_MODE == SataAhci); |
| 64 | } |
| 65 | |
| 66 | static inline int sb_ide_enable(void) |
| 67 | { |
| 68 | /* True if IDE or LEGACY IDE. */ |
| 69 | return (CONFIG_STONEYRIDGE_SATA_MODE == SataNativeIde) || |
| 70 | (CONFIG_STONEYRIDGE_SATA_MODE == SataLegacyIde); |
| 71 | } |
| 72 | |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 73 | void SetFchResetParams(FCH_RESET_INTERFACE *params) |
| 74 | { |
| 75 | params->Xhci0Enable = IS_ENABLED(CONFIG_STONEYRIDGE_XHCI_ENABLE); |
Richard Spiegel | a318d28 | 2018-01-16 13:25:40 -0700 | [diff] [blame] | 76 | params->SataEnable = sb_sata_enable(); |
| 77 | params->IdeEnable = sb_ide_enable(); |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void SetFchEnvParams(FCH_INTERFACE *params) |
| 81 | { |
| 82 | params->AzaliaController = AzEnable; |
| 83 | params->SataClass = CONFIG_STONEYRIDGE_SATA_MODE; |
| 84 | params->SataEnable = is_sata_config(); |
| 85 | params->IdeEnable = !params->SataEnable; |
| 86 | params->SataIdeMode = (CONFIG_STONEYRIDGE_SATA_MODE == SataLegacyIde); |
| 87 | } |
| 88 | |
| 89 | void SetFchMidParams(FCH_INTERFACE *params) |
| 90 | { |
| 91 | SetFchEnvParams(params); |
| 92 | } |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 93 | |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 94 | /* |
| 95 | * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME |
Jonathan Neuschäfer | 5268b76 | 2018-02-12 12:24:25 +0100 | [diff] [blame] | 96 | * provides a visible association with the index, therefore helping |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 97 | * maintainability of table. If a new index/name is defined in |
| 98 | * amd_pci_int_defs.h, just add the pair at the end of this table. |
| 99 | * Order is not important. |
| 100 | */ |
| 101 | const static struct irq_idx_name irq_association[] = { |
Richard Spiegel | e89d444 | 2017-12-08 07:52:42 -0700 | [diff] [blame] | 102 | { PIRQ_A, "INTA#" }, |
| 103 | { PIRQ_B, "INTB#" }, |
| 104 | { PIRQ_C, "INTC#" }, |
| 105 | { PIRQ_D, "INTD#" }, |
| 106 | { PIRQ_E, "INTE#" }, |
| 107 | { PIRQ_F, "INTF#" }, |
| 108 | { PIRQ_G, "INTG#" }, |
| 109 | { PIRQ_H, "INTH#" }, |
| 110 | { PIRQ_MISC, "Misc" }, |
| 111 | { PIRQ_MISC0, "Misc0" }, |
| 112 | { PIRQ_MISC1, "Misc1" }, |
| 113 | { PIRQ_MISC2, "Misc2" }, |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 114 | { PIRQ_SIRQA, "Ser IRQ INTA" }, |
| 115 | { PIRQ_SIRQB, "Ser IRQ INTB" }, |
| 116 | { PIRQ_SIRQC, "Ser IRQ INTC" }, |
| 117 | { PIRQ_SIRQD, "Ser IRQ INTD" }, |
Richard Spiegel | e89d444 | 2017-12-08 07:52:42 -0700 | [diff] [blame] | 118 | { PIRQ_SCI, "SCI" }, |
| 119 | { PIRQ_SMBUS, "SMBUS" }, |
| 120 | { PIRQ_ASF, "ASF" }, |
| 121 | { PIRQ_HDA, "HDA" }, |
| 122 | { PIRQ_FC, "FC" }, |
| 123 | { PIRQ_PMON, "PerMon" }, |
| 124 | { PIRQ_SD, "SD" }, |
| 125 | { PIRQ_SDIO, "SDIOt" }, |
| 126 | { PIRQ_IMC0, "IMC INT0" }, |
| 127 | { PIRQ_IMC1, "IMC INT1" }, |
| 128 | { PIRQ_IMC2, "IMC INT2" }, |
| 129 | { PIRQ_IMC3, "IMC INT3" }, |
| 130 | { PIRQ_IMC4, "IMC INT4" }, |
| 131 | { PIRQ_IMC5, "IMC INT5" }, |
| 132 | { PIRQ_EHCI, "EHCI" }, |
| 133 | { PIRQ_XHCI, "XHCI" }, |
| 134 | { PIRQ_SATA, "SATA" }, |
| 135 | { PIRQ_GPIO, "GPIO" }, |
| 136 | { PIRQ_I2C0, "I2C0" }, |
| 137 | { PIRQ_I2C1, "I2C1" }, |
| 138 | { PIRQ_I2C2, "I2C2" }, |
| 139 | { PIRQ_I2C3, "I2C3" }, |
| 140 | { PIRQ_UART0, "UART0" }, |
| 141 | { PIRQ_UART1, "UART1" }, |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
Richard Spiegel | ebf3aa8 | 2017-11-24 07:47:42 -0700 | [diff] [blame] | 144 | /* |
| 145 | * Structure to simplify code obtaining the total of used wide IO |
| 146 | * registers and the size assigned to each. |
| 147 | */ |
| 148 | static struct wide_io_ioport_and_bits { |
| 149 | uint32_t enable; |
| 150 | uint16_t port; |
| 151 | uint8_t alt; |
| 152 | } wio_io_en[TOTAL_WIDEIO_PORTS] = { |
| 153 | { |
| 154 | LPC_WIDEIO0_ENABLE, |
| 155 | LPC_WIDEIO_GENERIC_PORT, |
| 156 | LPC_ALT_WIDEIO0_ENABLE |
| 157 | }, |
| 158 | { |
| 159 | LPC_WIDEIO1_ENABLE, |
| 160 | LPC_WIDEIO1_GENERIC_PORT, |
| 161 | LPC_ALT_WIDEIO1_ENABLE |
| 162 | }, |
| 163 | { |
| 164 | LPC_WIDEIO2_ENABLE, |
| 165 | LPC_WIDEIO2_GENERIC_PORT, |
| 166 | LPC_ALT_WIDEIO2_ENABLE |
| 167 | } |
| 168 | }; |
| 169 | |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 170 | const struct irq_idx_name *sb_get_apic_reg_association(size_t *size) |
| 171 | { |
| 172 | *size = ARRAY_SIZE(irq_association); |
| 173 | return irq_association; |
| 174 | } |
| 175 | |
Richard Spiegel | ebf3aa8 | 2017-11-24 07:47:42 -0700 | [diff] [blame] | 176 | /** |
| 177 | * @brief Find the size of a particular wide IO |
| 178 | * |
| 179 | * @param index = index of desired wide IO |
| 180 | * |
| 181 | * @return size of desired wide IO |
| 182 | */ |
| 183 | uint16_t sb_wideio_size(int index) |
| 184 | { |
| 185 | uint32_t enable_register; |
| 186 | uint16_t size = 0; |
| 187 | uint8_t alternate_register; |
| 188 | |
| 189 | if (index >= TOTAL_WIDEIO_PORTS) |
| 190 | return size; |
| 191 | enable_register = pci_read_config32(SOC_LPC_DEV, |
| 192 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 193 | alternate_register = pci_read_config8(SOC_LPC_DEV, |
| 194 | LPC_ALT_WIDEIO_RANGE_ENABLE); |
| 195 | if (enable_register & wio_io_en[index].enable) |
| 196 | size = (alternate_register & wio_io_en[index].alt) ? |
| 197 | 16 : 512; |
| 198 | return size; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * @brief Identify if any LPC wide IO is covering the IO range |
| 203 | * |
| 204 | * @param start = start of IO range |
| 205 | * @param size = size of IO range |
| 206 | * |
| 207 | * @return Index of wide IO covering the range or error |
| 208 | */ |
| 209 | int sb_find_wideio_range(uint16_t start, uint16_t size) |
| 210 | { |
| 211 | uint32_t enable_register; |
| 212 | int i, index = WIDEIO_RANGE_ERROR; |
| 213 | uint16_t end, current_size, start_wideio, end_wideio; |
| 214 | |
| 215 | end = start + size; |
| 216 | enable_register = pci_read_config32(SOC_LPC_DEV, |
| 217 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 218 | for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) { |
| 219 | current_size = sb_wideio_size(i); |
| 220 | if (current_size == 0) |
| 221 | continue; |
| 222 | start_wideio = pci_read_config16(SOC_LPC_DEV, |
| 223 | wio_io_en[i].port); |
| 224 | end_wideio = start_wideio + current_size; |
| 225 | if ((start >= start_wideio) && (end <= end_wideio)) { |
| 226 | index = i; |
| 227 | break; |
| 228 | } |
| 229 | } |
| 230 | return index; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @brief Program a LPC wide IO to support an IO range |
| 235 | * |
| 236 | * @param start = start of range to be routed through wide IO |
| 237 | * @param size = size of range to be routed through wide IO |
| 238 | * |
| 239 | * @return Index of wide IO register used or error |
| 240 | */ |
| 241 | int sb_set_wideio_range(uint16_t start, uint16_t size) |
| 242 | { |
| 243 | int i, index = WIDEIO_RANGE_ERROR; |
| 244 | uint32_t enable_register; |
| 245 | uint8_t alternate_register; |
| 246 | |
| 247 | enable_register = pci_read_config32(SOC_LPC_DEV, |
| 248 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 249 | alternate_register = pci_read_config8(SOC_LPC_DEV, |
| 250 | LPC_ALT_WIDEIO_RANGE_ENABLE); |
| 251 | for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) { |
| 252 | if (enable_register & wio_io_en[i].enable) |
| 253 | continue; |
| 254 | index = i; |
| 255 | pci_write_config16(SOC_LPC_DEV, wio_io_en[i].port, start); |
| 256 | enable_register |= wio_io_en[i].enable; |
| 257 | pci_write_config32(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE, |
| 258 | enable_register); |
| 259 | if (size <= 16) |
| 260 | alternate_register |= wio_io_en[i].alt; |
| 261 | else |
| 262 | alternate_register &= ~wio_io_en[i].alt; |
| 263 | pci_write_config8(SOC_LPC_DEV, |
| 264 | LPC_ALT_WIDEIO_RANGE_ENABLE, |
| 265 | alternate_register); |
| 266 | break; |
| 267 | } |
| 268 | return index; |
| 269 | } |
| 270 | |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 271 | static void power_on_aoac_device(int aoac_device_control_register) |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 272 | { |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 273 | uint8_t byte; |
| 274 | uint8_t *register_pointer = (uint8_t *)(uintptr_t)AOAC_MMIO_BASE |
| 275 | + aoac_device_control_register; |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 276 | |
| 277 | /* Power on the UART and AMBA devices */ |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 278 | byte = read8(register_pointer); |
| 279 | byte |= FCH_AOAC_PWR_ON_DEV; |
| 280 | write8(register_pointer, byte); |
| 281 | } |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 282 | |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 283 | static bool is_aoac_device_enabled(int aoac_device_status_register) |
| 284 | { |
| 285 | uint8_t byte; |
| 286 | byte = read8((uint8_t *)(uintptr_t)AOAC_MMIO_BASE |
| 287 | + aoac_device_status_register); |
| 288 | byte &= (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE); |
| 289 | if (byte == (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE)) |
| 290 | return true; |
| 291 | else |
| 292 | return false; |
| 293 | } |
| 294 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 295 | void enable_aoac_devices(void) |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 296 | { |
| 297 | bool status; |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 298 | int i; |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 299 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 300 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 301 | power_on_aoac_device(aoac_devs[i].enable); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 302 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 303 | /* Wait for AOAC devices to indicate power and clock OK */ |
| 304 | do { |
| 305 | udelay(100); |
| 306 | status = true; |
| 307 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 308 | status &= is_aoac_device_enabled(aoac_devs[i].status); |
| 309 | } while (!status); |
| 310 | } |
| 311 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 312 | void sb_pci_port80(void) |
| 313 | { |
| 314 | u8 byte; |
| 315 | |
| 316 | byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH); |
| 317 | byte &= ~DECODE_IO_PORT_ENABLE4_H; /* disable lpc port 80 */ |
| 318 | pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte); |
| 319 | } |
| 320 | |
| 321 | void sb_lpc_port80(void) |
| 322 | { |
| 323 | u8 byte; |
| 324 | |
| 325 | /* Enable LPC controller */ |
| 326 | outb(PM_LPC_GATING, PM_INDEX); |
| 327 | byte = inb(PM_DATA); |
| 328 | byte |= PM_LPC_ENABLE; |
| 329 | outb(PM_LPC_GATING, PM_INDEX); |
| 330 | outb(byte, PM_DATA); |
| 331 | |
| 332 | /* Enable port 80 LPC decode in pci function 3 configuration space. */ |
| 333 | byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH); |
| 334 | byte |= DECODE_IO_PORT_ENABLE4_H; /* enable port 80 */ |
| 335 | pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte); |
| 336 | } |
| 337 | |
| 338 | void sb_lpc_decode(void) |
| 339 | { |
| 340 | u32 tmp = 0; |
| 341 | |
| 342 | /* Enable I/O decode to LPC bus */ |
| 343 | tmp = DECODE_ENABLE_PARALLEL_PORT0 | DECODE_ENABLE_PARALLEL_PORT2 |
| 344 | | DECODE_ENABLE_PARALLEL_PORT4 | DECODE_ENABLE_SERIAL_PORT0 |
| 345 | | DECODE_ENABLE_SERIAL_PORT1 | DECODE_ENABLE_SERIAL_PORT2 |
| 346 | | DECODE_ENABLE_SERIAL_PORT3 | DECODE_ENABLE_SERIAL_PORT4 |
| 347 | | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT6 |
| 348 | | DECODE_ENABLE_SERIAL_PORT7 | DECODE_ENABLE_AUDIO_PORT0 |
| 349 | | DECODE_ENABLE_AUDIO_PORT1 | DECODE_ENABLE_AUDIO_PORT2 |
| 350 | | DECODE_ENABLE_AUDIO_PORT3 | DECODE_ENABLE_MSS_PORT2 |
| 351 | | DECODE_ENABLE_MSS_PORT3 | DECODE_ENABLE_FDC_PORT0 |
| 352 | | DECODE_ENABLE_FDC_PORT1 | DECODE_ENABLE_GAME_PORT |
| 353 | | DECODE_ENABLE_KBC_PORT | DECODE_ENABLE_ACPIUC_PORT |
| 354 | | DECODE_ENABLE_ADLIB_PORT; |
| 355 | |
| 356 | pci_write_config32(SOC_LPC_DEV, LPC_IO_PORT_DECODE_ENABLE, tmp); |
| 357 | } |
| 358 | |
Garrett Kirkendall | 9858bd2 | 2018-03-07 15:38:14 -0600 | [diff] [blame] | 359 | void sb_acpi_mmio_decode(void) |
| 360 | { |
| 361 | uint8_t byte; |
| 362 | |
| 363 | /* Enable ACPI MMIO range 0xfed80000 - 0xfed81fff */ |
| 364 | outb(PM_ISA_CONTROL, PM_INDEX); |
| 365 | byte = inb(PM_DATA); |
| 366 | byte |= MMIO_EN; |
| 367 | outb(PM_ISA_CONTROL, PM_INDEX); |
| 368 | outb(byte, PM_DATA); |
| 369 | } |
| 370 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 371 | void sb_clk_output_48Mhz(void) |
| 372 | { |
| 373 | u32 ctrl; |
Garrett Kirkendall | d255830 | 2018-03-06 09:05:20 -0600 | [diff] [blame] | 374 | u32 *misc_clk_cntl_1_ptr = (u32 *)(uintptr_t)(MISC_MMIO_BASE |
| 375 | + MISC_MISC_CLK_CNTL_1); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 376 | |
| 377 | /* |
| 378 | * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so |
| 379 | * 48Mhz will be on ball AP13 (FT3b package) |
| 380 | */ |
Garrett Kirkendall | d255830 | 2018-03-06 09:05:20 -0600 | [diff] [blame] | 381 | ctrl = read32(misc_clk_cntl_1_ptr); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 382 | |
| 383 | /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */ |
Garrett Kirkendall | d255830 | 2018-03-06 09:05:20 -0600 | [diff] [blame] | 384 | ctrl &= ~OSCOUT1_CLK_OUTPUT_ENB; |
| 385 | write32(misc_clk_cntl_1_ptr, ctrl); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | static uintptr_t sb_spibase(void) |
| 389 | { |
| 390 | u32 base, enables; |
| 391 | |
| 392 | /* Make sure the base address is predictable */ |
| 393 | base = pci_read_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER); |
| 394 | enables = base & 0xf; |
| 395 | base &= ~0x3f; |
| 396 | |
| 397 | if (!base) { |
| 398 | base = SPI_BASE_ADDRESS; |
| 399 | pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER, |
| 400 | base | enables | SPI_ROM_ENABLE); |
| 401 | /* PCI_COMMAND_MEMORY is read-only and enabled. */ |
| 402 | } |
| 403 | return (uintptr_t)base; |
| 404 | } |
| 405 | |
| 406 | void sb_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm) |
| 407 | { |
| 408 | uintptr_t base = sb_spibase(); |
| 409 | write16((void *)base + SPI100_SPEED_CONFIG, |
| 410 | (norm << SPI_NORM_SPEED_NEW_SH) | |
| 411 | (fast << SPI_FAST_SPEED_NEW_SH) | |
| 412 | (alt << SPI_ALT_SPEED_NEW_SH) | |
| 413 | (tpm << SPI_TPM_SPEED_NEW_SH)); |
| 414 | write16((void *)base + SPI100_ENABLE, SPI_USE_SPI100); |
| 415 | } |
| 416 | |
| 417 | void sb_disable_4dw_burst(void) |
| 418 | { |
| 419 | uintptr_t base = sb_spibase(); |
| 420 | write16((void *)base + SPI100_HOST_PREF_CONFIG, |
| 421 | read16((void *)base + SPI100_HOST_PREF_CONFIG) |
| 422 | & ~SPI_RD4DW_EN_HOST); |
| 423 | } |
| 424 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 425 | void sb_read_mode(u32 mode) |
| 426 | { |
| 427 | uintptr_t base = sb_spibase(); |
| 428 | write32((void *)base + SPI_CNTRL0, |
| 429 | (read32((void *)base + SPI_CNTRL0) |
| 430 | & ~SPI_READ_MODE_MASK) | mode); |
| 431 | } |
| 432 | |
Garrett Kirkendall | 6575306 | 2018-03-07 16:12:11 -0600 | [diff] [blame] | 433 | /* |
| 434 | * Enable FCH to decode TPM associated Memory and IO regions |
| 435 | * |
| 436 | * Enable decoding of TPM cycles defined in TPM 1.2 spec |
| 437 | * Enable decoding of legacy TPM addresses: IO addresses 0x7f- |
| 438 | * 0x7e and 0xef-0xee. |
| 439 | * This function should be called if TPM is connected in any way to the FCH and |
| 440 | * conforms to the regions decoded. |
| 441 | * Absent any other routing configuration the TPM cycles will be claimed by the |
| 442 | * LPC bus |
| 443 | */ |
| 444 | void sb_tpm_decode(void) |
| 445 | { |
| 446 | u32 value; |
| 447 | |
| 448 | value = pci_read_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE); |
| 449 | value |= TPM_12_EN | TPM_LEGACY_EN; |
| 450 | pci_write_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE, value); |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * Enable FCH to decode TPM associated Memory and IO regions to SPI |
| 455 | * |
| 456 | * This should be used if TPM is connected to SPI bus. |
| 457 | * Assumes SPI address space is already configured via a call to sb_spibase(). |
| 458 | */ |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 459 | void sb_tpm_decode_spi(void) |
| 460 | { |
Garrett Kirkendall | 6575306 | 2018-03-07 16:12:11 -0600 | [diff] [blame] | 461 | /* Enable TPM decoding to FCH */ |
| 462 | sb_tpm_decode(); |
| 463 | |
| 464 | /* Route TPM accesses to SPI */ |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 465 | u32 spibase = pci_read_config32(SOC_LPC_DEV, |
| 466 | SPIROM_BASE_ADDRESS_REGISTER); |
| 467 | pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER, spibase |
| 468 | | ROUTE_TPM_2_SPI); |
| 469 | } |
| 470 | |
| 471 | /* |
| 472 | * Enable 4MB (LPC) ROM access at 0xFFC00000 - 0xFFFFFFFF. |
| 473 | * |
| 474 | * Hardware should enable LPC ROM by pin straps. This function does not |
| 475 | * handle the theoretically possible PCI ROM, FWH, or SPI ROM configurations. |
| 476 | * |
| 477 | * The southbridge power-on default is to map 512K ROM space. |
| 478 | * |
| 479 | */ |
| 480 | void sb_enable_rom(void) |
| 481 | { |
| 482 | u8 reg8; |
| 483 | |
| 484 | /* |
| 485 | * Decode variable LPC ROM address ranges 1 and 2. |
| 486 | * Bits 3-4 are not defined in any publicly available datasheet |
| 487 | */ |
| 488 | reg8 = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE); |
| 489 | reg8 |= (1 << 3) | (1 << 4); |
| 490 | pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE, reg8); |
| 491 | |
| 492 | /* |
| 493 | * LPC ROM address range 1: |
| 494 | * Enable LPC ROM range mirroring start at 0x000e(0000). |
| 495 | */ |
| 496 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_START, 0x000e); |
| 497 | |
| 498 | /* Enable LPC ROM range mirroring end at 0x000f(ffff). */ |
| 499 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_END, 0x000f); |
| 500 | |
| 501 | /* |
| 502 | * LPC ROM address range 2: |
| 503 | * |
| 504 | * Enable LPC ROM range start at: |
| 505 | * 0xfff8(0000): 512KB |
| 506 | * 0xfff0(0000): 1MB |
| 507 | * 0xffe0(0000): 2MB |
| 508 | * 0xffc0(0000): 4MB |
| 509 | */ |
| 510 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_START, 0x10000 |
| 511 | - (CONFIG_COREBOOT_ROMSIZE_KB >> 6)); |
| 512 | |
| 513 | /* Enable LPC ROM range end at 0xffff(ffff). */ |
| 514 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_END, 0xffff); |
| 515 | } |
| 516 | |
Marc Jones | cfb1680 | 2018-04-20 16:27:41 -0600 | [diff] [blame] | 517 | static void sb_lpc_early_setup(void) |
| 518 | { |
| 519 | uint32_t dword; |
| 520 | |
| 521 | /* Enable SPI prefetch */ |
| 522 | dword = pci_read_config32(SOC_LPC_DEV, LPC_ROM_DMA_EC_HOST_CONTROL); |
| 523 | dword |= SPI_FROM_HOST_PREFETCH_EN | SPI_FROM_USB_PREFETCH_EN; |
| 524 | pci_write_config32(SOC_LPC_DEV, LPC_ROM_DMA_EC_HOST_CONTROL, dword); |
| 525 | |
| 526 | if (IS_ENABLED(CONFIG_STONEYRIDGE_LEGACY_FREE)) { |
| 527 | /* Decode SIOs at 2E/2F and 4E/4F */ |
| 528 | dword = pci_read_config32(SOC_LPC_DEV, |
| 529 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 530 | dword |= DECODE_ALTERNATE_SIO_ENABLE | DECODE_SIO_ENABLE; |
| 531 | pci_write_config32(SOC_LPC_DEV, |
| 532 | LPC_IO_OR_MEM_DECODE_ENABLE, dword); |
| 533 | } |
| 534 | } |
| 535 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 536 | void bootblock_fch_early_init(void) |
| 537 | { |
| 538 | sb_enable_rom(); |
| 539 | sb_lpc_port80(); |
| 540 | sb_lpc_decode(); |
Marc Jones | cfb1680 | 2018-04-20 16:27:41 -0600 | [diff] [blame] | 541 | sb_lpc_early_setup(); |
Garrett Kirkendall | 64294eb | 2018-03-16 13:00:46 -0500 | [diff] [blame] | 542 | sb_spibase(); |
Marc Jones | cfb1680 | 2018-04-20 16:27:41 -0600 | [diff] [blame] | 543 | sb_disable_4dw_burst(); /* Must be disabled on CZ(ST) */ |
Garrett Kirkendall | e7513e0d | 2018-03-14 12:01:36 -0500 | [diff] [blame] | 544 | sb_acpi_mmio_decode(); |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 545 | enable_aoac_devices(); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 548 | void sb_enable(device_t dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 549 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 550 | printk(BIOS_DEBUG, "%s\n", __func__); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 551 | } |
| 552 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 553 | static void sb_init_acpi_ports(void) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 554 | { |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame] | 555 | u32 reg; |
| 556 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 557 | /* We use some of these ports in SMM regardless of whether or not |
| 558 | * ACPI tables are generated. Enable these ports indiscriminately. |
| 559 | */ |
| 560 | |
| 561 | pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK); |
| 562 | pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK); |
| 563 | pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK); |
| 564 | pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK); |
| 565 | /* CpuControl is in \_PR.CP00, 6 bytes */ |
| 566 | pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL); |
| 567 | |
| 568 | if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) { |
Marshall Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 569 | /* APMC - SMI Command Port */ |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 570 | pm_write16(PM_ACPI_SMI_CMD, APM_CNT); |
Marshall Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 571 | configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI); |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame] | 572 | |
| 573 | /* SMI on SlpTyp requires sending SMI before completion |
| 574 | * response of the I/O write. The BKDG also specifies |
| 575 | * clearing ForceStpClkRetry for SMI trapping. |
| 576 | */ |
| 577 | reg = pm_read32(PM_PCI_CTRL); |
| 578 | reg |= FORCE_SLPSTATE_RETRY; |
| 579 | reg &= ~FORCE_STPCLK_RETRY; |
| 580 | pm_write32(PM_PCI_CTRL, reg); |
| 581 | |
| 582 | /* Disable SlpTyp feature */ |
| 583 | reg = pm_read8(PM_RST_CTRL1); |
| 584 | reg &= ~SLPTYPE_CONTROL_EN; |
| 585 | pm_write8(PM_RST_CTRL1, reg); |
| 586 | |
| 587 | configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 588 | } else { |
| 589 | pm_write16(PM_ACPI_SMI_CMD, 0); |
| 590 | } |
| 591 | |
Marshall Dawson | 5e2e74f | 2017-11-10 09:59:56 -0700 | [diff] [blame] | 592 | /* Decode ACPI registers and enable standard features */ |
| 593 | pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD | |
| 594 | PM_ACPI_GLOBAL_EN | |
| 595 | PM_ACPI_RTC_EN_EN | |
| 596 | PM_ACPI_TIMER_EN_EN); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 597 | } |
| 598 | |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 599 | static void print_num_status_bits(int num_bits, uint32_t status, |
| 600 | const char *const bit_names[]) |
| 601 | { |
| 602 | int i; |
| 603 | |
| 604 | if (!status) |
| 605 | return; |
| 606 | |
| 607 | for (i = num_bits - 1; i >= 0; i--) { |
| 608 | if (status & (1 << i)) { |
| 609 | if (bit_names[i]) |
| 610 | printk(BIOS_DEBUG, "%s ", bit_names[i]); |
| 611 | else |
| 612 | printk(BIOS_DEBUG, "BIT%d ", i); |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | static uint16_t reset_pm1_status(void) |
| 618 | { |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 619 | uint16_t pm1_sts = inw(ACPI_PM1_STS); |
| 620 | outw(pm1_sts, ACPI_PM1_STS); |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 621 | return pm1_sts; |
| 622 | } |
| 623 | |
| 624 | static uint16_t print_pm1_status(uint16_t pm1_sts) |
| 625 | { |
| 626 | static const char *const pm1_sts_bits[] = { |
| 627 | [0] = "TMROF", |
| 628 | [4] = "BMSTATUS", |
| 629 | [5] = "GBL", |
| 630 | [8] = "PWRBTN", |
| 631 | [10] = "RTC", |
| 632 | [14] = "PCIEXPWAK", |
| 633 | [15] = "WAK", |
| 634 | }; |
| 635 | |
| 636 | if (!pm1_sts) |
| 637 | return 0; |
| 638 | |
| 639 | printk(BIOS_SPEW, "PM1_STS: "); |
| 640 | print_num_status_bits(ARRAY_SIZE(pm1_sts_bits), pm1_sts, pm1_sts_bits); |
| 641 | printk(BIOS_SPEW, "\n"); |
| 642 | |
| 643 | return pm1_sts; |
| 644 | } |
| 645 | |
| 646 | static void sb_log_pm1_status(uint16_t pm1_sts) |
| 647 | { |
| 648 | if (!IS_ENABLED(CONFIG_ELOG)) |
| 649 | return; |
| 650 | |
Daniel Kurtz | b6fdd22 | 2018-05-24 15:52:45 -0600 | [diff] [blame] | 651 | if (pm1_sts & WAK_STS) |
| 652 | elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, |
| 653 | acpi_is_wakeup_s3() ? ACPI_S3 : ACPI_S5); |
| 654 | |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 655 | if (pm1_sts & PWRBTN_STS) |
| 656 | elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0); |
| 657 | |
| 658 | if (pm1_sts & RTC_STS) |
| 659 | elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0); |
| 660 | |
| 661 | if (pm1_sts & PCIEXPWAK_STS) |
| 662 | elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0); |
| 663 | } |
| 664 | |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 665 | static void sb_save_sws(uint16_t pm1_status) |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 666 | { |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 667 | struct soc_power_reg *sws; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 668 | uint32_t reg32; |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 669 | uint16_t reg16; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 670 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 671 | sws = cbmem_add(CBMEM_ID_POWER_STATE, sizeof(struct soc_power_reg)); |
| 672 | if (sws == NULL) |
| 673 | return; |
| 674 | sws->pm1_sts = pm1_status; |
| 675 | sws->pm1_en = inw(ACPI_PM1_EN); |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 676 | reg32 = inl(ACPI_GPE0_STS); |
| 677 | outl(ACPI_GPE0_STS, reg32); |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 678 | sws->gpe0_sts = reg32; |
| 679 | sws->gpe0_en = inl(ACPI_GPE0_EN); |
| 680 | reg16 = inw(ACPI_PM1_CNT_BLK); |
| 681 | reg16 &= SLP_TYP; |
| 682 | sws->wake_from = reg16 >> SLP_TYP_SHIFT; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 685 | static void sb_clear_pm1_status(void) |
| 686 | { |
| 687 | uint16_t pm1_sts = reset_pm1_status(); |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 688 | |
| 689 | sb_save_sws(pm1_sts); |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 690 | sb_log_pm1_status(pm1_sts); |
| 691 | print_pm1_status(pm1_sts); |
| 692 | } |
| 693 | |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 694 | static int get_index_bit(uint32_t value, uint16_t limit) |
| 695 | { |
| 696 | uint16_t i; |
| 697 | uint32_t t; |
| 698 | |
Richard Spiegel | ef73cb8 | 2018-06-19 07:40:18 -0700 | [diff] [blame^] | 699 | if (limit >= TOTAL_BITS(uint32_t)) |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 700 | return -1; |
| 701 | |
| 702 | /* get a mask of valid bits. Ex limit = 3, set bits 0-2 */ |
| 703 | t = (1 << limit) - 1; |
| 704 | if ((value & t) == 0) |
| 705 | return -1; |
| 706 | t = 1; |
| 707 | for (i = 0; i < limit; i++) { |
| 708 | if (value & t) |
| 709 | break; |
| 710 | t <<= 1; |
| 711 | } |
| 712 | return i; |
| 713 | } |
| 714 | |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 715 | static void set_nvs_sws(void *unused) |
| 716 | { |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 717 | struct soc_power_reg *sws; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 718 | struct global_nvs_t *gnvs; |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 719 | int index; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 720 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 721 | sws = cbmem_find(CBMEM_ID_POWER_STATE); |
| 722 | if (sws == NULL) |
| 723 | return; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 724 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 725 | if (gnvs == NULL) |
| 726 | return; |
| 727 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 728 | index = get_index_bit(sws->pm1_sts & sws->pm1_en, PM1_LIMIT); |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 729 | if (index < 0) |
| 730 | gnvs->pm1i = ~0ULL; |
| 731 | else |
| 732 | gnvs->pm1i = index; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 733 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 734 | index = get_index_bit(sws->gpe0_sts & sws->gpe0_en, GPE0_LIMIT); |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 735 | if (index < 0) |
| 736 | gnvs->gpei = ~0ULL; |
| 737 | else |
| 738 | gnvs->gpei = index; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, set_nvs_sws, NULL); |
| 742 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 743 | void southbridge_init(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 744 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 745 | sb_init_acpi_ports(); |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 746 | sb_clear_pm1_status(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 747 | } |
| 748 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 749 | void southbridge_final(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 750 | { |
Richard Spiegel | 6a38914 | 2018-03-05 14:28:10 -0700 | [diff] [blame] | 751 | uint8_t restored_power = PM_S5_AT_POWER_RECOVERY; |
| 752 | |
Richard Spiegel | 38f1940 | 2017-09-29 11:39:46 -0700 | [diff] [blame] | 753 | if (IS_ENABLED(CONFIG_STONEYRIDGE_IMC_FWM)) { |
| 754 | agesawrapper_fchecfancontrolservice(); |
| 755 | if (!IS_ENABLED(CONFIG_ACPI_ENABLE_THERMAL_ZONE)) |
| 756 | enable_imc_thermal_zone(); |
| 757 | } |
Richard Spiegel | 6a38914 | 2018-03-05 14:28:10 -0700 | [diff] [blame] | 758 | if (IS_ENABLED(CONFIG_MAINBOARD_POWER_RESTORE)) |
| 759 | restored_power = PM_RESTORE_S0_IF_PREV_S0; |
| 760 | pm_write8(PM_RTC_SHADOW, restored_power); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 761 | } |
Marshall Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 762 | |
| 763 | /* |
| 764 | * Update the PCI devices with a valid IRQ number |
| 765 | * that is set in the mainboard PCI_IRQ structures. |
| 766 | */ |
| 767 | static void set_pci_irqs(void *unused) |
| 768 | { |
| 769 | /* Write PCI_INTR regs 0xC00/0xC01 */ |
| 770 | write_pci_int_table(); |
| 771 | |
| 772 | /* Write IRQs for all devicetree enabled devices */ |
| 773 | write_pci_cfg_irqs(); |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Hook this function into the PCI state machine |
| 778 | * on entry into BS_DEV_ENABLE. |
| 779 | */ |
| 780 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL); |