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> |
Richard Spiegel | 2bbc3dc | 2017-12-06 16:14:58 -0700 | [diff] [blame] | 26 | #include <amdblocks/amd_pci_util.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 27 | #include <soc/southbridge.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 28 | #include <soc/smi.h> |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 29 | #include <soc/amd_pci_int_defs.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 30 | #include <fchec.h> |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 31 | #include <delay.h> |
| 32 | #include <soc/pci_devs.h> |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 33 | #include <agesa_headers.h> |
| 34 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame^] | 35 | /* |
| 36 | * Table of devices that need their AOAC registers enabled and waited |
| 37 | * upon (usually about .55 milliseconds). Instead of individual delays |
| 38 | * waiting for each device to become available, a single delay will be |
| 39 | * executed at configure_stoneyridge_uart(). All other devices need only |
| 40 | * to verify if their AOAC is already enabled, and do a minimal delay |
| 41 | * if needed. |
| 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 | |
Justin TerAvest | 3fe3f04 | 2018-02-14 19:10:15 -0700 | [diff] [blame] | 176 | void sb_program_gpios(const struct soc_amd_stoneyridge_gpio *gpio_ptr, |
| 177 | size_t size) |
Richard Spiegel | e539c85 | 2017-12-25 18:25:58 -0700 | [diff] [blame] | 178 | { |
| 179 | void *tmp_ptr; |
Richard Spiegel | e539c85 | 2017-12-25 18:25:58 -0700 | [diff] [blame] | 180 | uint8_t control, mux, index; |
| 181 | |
Richard Spiegel | e539c85 | 2017-12-25 18:25:58 -0700 | [diff] [blame] | 182 | for (index = 0; index < size; index++) { |
| 183 | mux = gpio_ptr[index].function; |
| 184 | control = gpio_ptr[index].control; |
| 185 | tmp_ptr = (void *)(gpio_ptr[index].gpio + AMD_GPIO_MUX); |
| 186 | write8(tmp_ptr, mux & AMD_GPIO_MUX_MASK); |
| 187 | |
| 188 | /* |
| 189 | * Get the address of AMD_GPIO_CONTROL (dword) relative |
| 190 | * to the desired pin and program bits 16-23. |
| 191 | */ |
| 192 | tmp_ptr = (void *)(gpio_ptr[index].gpio * sizeof(uint32_t) + |
| 193 | AMD_GPIO_CONTROL + 2); |
| 194 | write8(tmp_ptr, control); |
| 195 | } |
Richard Spiegel | e539c85 | 2017-12-25 18:25:58 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Richard Spiegel | ebf3aa8 | 2017-11-24 07:47:42 -0700 | [diff] [blame] | 198 | /** |
| 199 | * @brief Find the size of a particular wide IO |
| 200 | * |
| 201 | * @param index = index of desired wide IO |
| 202 | * |
| 203 | * @return size of desired wide IO |
| 204 | */ |
| 205 | uint16_t sb_wideio_size(int index) |
| 206 | { |
| 207 | uint32_t enable_register; |
| 208 | uint16_t size = 0; |
| 209 | uint8_t alternate_register; |
| 210 | |
| 211 | if (index >= TOTAL_WIDEIO_PORTS) |
| 212 | return size; |
| 213 | enable_register = pci_read_config32(SOC_LPC_DEV, |
| 214 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 215 | alternate_register = pci_read_config8(SOC_LPC_DEV, |
| 216 | LPC_ALT_WIDEIO_RANGE_ENABLE); |
| 217 | if (enable_register & wio_io_en[index].enable) |
| 218 | size = (alternate_register & wio_io_en[index].alt) ? |
| 219 | 16 : 512; |
| 220 | return size; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * @brief Identify if any LPC wide IO is covering the IO range |
| 225 | * |
| 226 | * @param start = start of IO range |
| 227 | * @param size = size of IO range |
| 228 | * |
| 229 | * @return Index of wide IO covering the range or error |
| 230 | */ |
| 231 | int sb_find_wideio_range(uint16_t start, uint16_t size) |
| 232 | { |
| 233 | uint32_t enable_register; |
| 234 | int i, index = WIDEIO_RANGE_ERROR; |
| 235 | uint16_t end, current_size, start_wideio, end_wideio; |
| 236 | |
| 237 | end = start + size; |
| 238 | enable_register = pci_read_config32(SOC_LPC_DEV, |
| 239 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 240 | for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) { |
| 241 | current_size = sb_wideio_size(i); |
| 242 | if (current_size == 0) |
| 243 | continue; |
| 244 | start_wideio = pci_read_config16(SOC_LPC_DEV, |
| 245 | wio_io_en[i].port); |
| 246 | end_wideio = start_wideio + current_size; |
| 247 | if ((start >= start_wideio) && (end <= end_wideio)) { |
| 248 | index = i; |
| 249 | break; |
| 250 | } |
| 251 | } |
| 252 | return index; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * @brief Program a LPC wide IO to support an IO range |
| 257 | * |
| 258 | * @param start = start of range to be routed through wide IO |
| 259 | * @param size = size of range to be routed through wide IO |
| 260 | * |
| 261 | * @return Index of wide IO register used or error |
| 262 | */ |
| 263 | int sb_set_wideio_range(uint16_t start, uint16_t size) |
| 264 | { |
| 265 | int i, index = WIDEIO_RANGE_ERROR; |
| 266 | uint32_t enable_register; |
| 267 | uint8_t alternate_register; |
| 268 | |
| 269 | enable_register = pci_read_config32(SOC_LPC_DEV, |
| 270 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 271 | alternate_register = pci_read_config8(SOC_LPC_DEV, |
| 272 | LPC_ALT_WIDEIO_RANGE_ENABLE); |
| 273 | for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) { |
| 274 | if (enable_register & wio_io_en[i].enable) |
| 275 | continue; |
| 276 | index = i; |
| 277 | pci_write_config16(SOC_LPC_DEV, wio_io_en[i].port, start); |
| 278 | enable_register |= wio_io_en[i].enable; |
| 279 | pci_write_config32(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE, |
| 280 | enable_register); |
| 281 | if (size <= 16) |
| 282 | alternate_register |= wio_io_en[i].alt; |
| 283 | else |
| 284 | alternate_register &= ~wio_io_en[i].alt; |
| 285 | pci_write_config8(SOC_LPC_DEV, |
| 286 | LPC_ALT_WIDEIO_RANGE_ENABLE, |
| 287 | alternate_register); |
| 288 | break; |
| 289 | } |
| 290 | return index; |
| 291 | } |
| 292 | |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 293 | static void power_on_aoac_device(int aoac_device_control_register) |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 294 | { |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 295 | uint8_t byte; |
| 296 | uint8_t *register_pointer = (uint8_t *)(uintptr_t)AOAC_MMIO_BASE |
| 297 | + aoac_device_control_register; |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 298 | |
| 299 | /* Power on the UART and AMBA devices */ |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 300 | byte = read8(register_pointer); |
| 301 | byte |= FCH_AOAC_PWR_ON_DEV; |
| 302 | write8(register_pointer, byte); |
| 303 | } |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 304 | |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 305 | static bool is_aoac_device_enabled(int aoac_device_status_register) |
| 306 | { |
| 307 | uint8_t byte; |
| 308 | byte = read8((uint8_t *)(uintptr_t)AOAC_MMIO_BASE |
| 309 | + aoac_device_status_register); |
| 310 | byte &= (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE); |
| 311 | if (byte == (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE)) |
| 312 | return true; |
| 313 | else |
| 314 | return false; |
| 315 | } |
| 316 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame^] | 317 | void enable_aoac_devices(void) |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 318 | { |
| 319 | bool status; |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame^] | 320 | int i; |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 321 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame^] | 322 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 323 | power_on_aoac_device(aoac_devs[i].enable); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 324 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame^] | 325 | /* Wait for AOAC devices to indicate power and clock OK */ |
| 326 | do { |
| 327 | udelay(100); |
| 328 | status = true; |
| 329 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 330 | status &= is_aoac_device_enabled(aoac_devs[i].status); |
| 331 | } while (!status); |
| 332 | } |
| 333 | |
| 334 | void configure_stoneyridge_uart(void) |
| 335 | { |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 336 | /* Set the GPIO mux to UART */ |
| 337 | write8((void *)FCH_IOMUXx89_UART0_RTS_L_EGPIO137, 0); |
| 338 | write8((void *)FCH_IOMUXx8A_UART0_TXD_EGPIO138, 0); |
| 339 | write8((void *)FCH_IOMUXx8E_UART1_RTS_L_EGPIO142, 0); |
| 340 | write8((void *)FCH_IOMUXx8F_UART1_TXD_EGPIO143, 0); |
Garrett Kirkendall | 8da81da | 2018-03-07 09:00:05 -0600 | [diff] [blame] | 341 | } |
| 342 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 343 | void sb_pci_port80(void) |
| 344 | { |
| 345 | u8 byte; |
| 346 | |
| 347 | byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH); |
| 348 | byte &= ~DECODE_IO_PORT_ENABLE4_H; /* disable lpc port 80 */ |
| 349 | pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte); |
| 350 | } |
| 351 | |
| 352 | void sb_lpc_port80(void) |
| 353 | { |
| 354 | u8 byte; |
| 355 | |
| 356 | /* Enable LPC controller */ |
| 357 | outb(PM_LPC_GATING, PM_INDEX); |
| 358 | byte = inb(PM_DATA); |
| 359 | byte |= PM_LPC_ENABLE; |
| 360 | outb(PM_LPC_GATING, PM_INDEX); |
| 361 | outb(byte, PM_DATA); |
| 362 | |
| 363 | /* Enable port 80 LPC decode in pci function 3 configuration space. */ |
| 364 | byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH); |
| 365 | byte |= DECODE_IO_PORT_ENABLE4_H; /* enable port 80 */ |
| 366 | pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte); |
| 367 | } |
| 368 | |
| 369 | void sb_lpc_decode(void) |
| 370 | { |
| 371 | u32 tmp = 0; |
| 372 | |
| 373 | /* Enable I/O decode to LPC bus */ |
| 374 | tmp = DECODE_ENABLE_PARALLEL_PORT0 | DECODE_ENABLE_PARALLEL_PORT2 |
| 375 | | DECODE_ENABLE_PARALLEL_PORT4 | DECODE_ENABLE_SERIAL_PORT0 |
| 376 | | DECODE_ENABLE_SERIAL_PORT1 | DECODE_ENABLE_SERIAL_PORT2 |
| 377 | | DECODE_ENABLE_SERIAL_PORT3 | DECODE_ENABLE_SERIAL_PORT4 |
| 378 | | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT6 |
| 379 | | DECODE_ENABLE_SERIAL_PORT7 | DECODE_ENABLE_AUDIO_PORT0 |
| 380 | | DECODE_ENABLE_AUDIO_PORT1 | DECODE_ENABLE_AUDIO_PORT2 |
| 381 | | DECODE_ENABLE_AUDIO_PORT3 | DECODE_ENABLE_MSS_PORT2 |
| 382 | | DECODE_ENABLE_MSS_PORT3 | DECODE_ENABLE_FDC_PORT0 |
| 383 | | DECODE_ENABLE_FDC_PORT1 | DECODE_ENABLE_GAME_PORT |
| 384 | | DECODE_ENABLE_KBC_PORT | DECODE_ENABLE_ACPIUC_PORT |
| 385 | | DECODE_ENABLE_ADLIB_PORT; |
| 386 | |
| 387 | pci_write_config32(SOC_LPC_DEV, LPC_IO_PORT_DECODE_ENABLE, tmp); |
| 388 | } |
| 389 | |
Garrett Kirkendall | 9858bd2 | 2018-03-07 15:38:14 -0600 | [diff] [blame] | 390 | void sb_acpi_mmio_decode(void) |
| 391 | { |
| 392 | uint8_t byte; |
| 393 | |
| 394 | /* Enable ACPI MMIO range 0xfed80000 - 0xfed81fff */ |
| 395 | outb(PM_ISA_CONTROL, PM_INDEX); |
| 396 | byte = inb(PM_DATA); |
| 397 | byte |= MMIO_EN; |
| 398 | outb(PM_ISA_CONTROL, PM_INDEX); |
| 399 | outb(byte, PM_DATA); |
| 400 | } |
| 401 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 402 | void sb_clk_output_48Mhz(void) |
| 403 | { |
| 404 | u32 ctrl; |
Garrett Kirkendall | d255830 | 2018-03-06 09:05:20 -0600 | [diff] [blame] | 405 | u32 *misc_clk_cntl_1_ptr = (u32 *)(uintptr_t)(MISC_MMIO_BASE |
| 406 | + MISC_MISC_CLK_CNTL_1); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 407 | |
| 408 | /* |
| 409 | * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so |
| 410 | * 48Mhz will be on ball AP13 (FT3b package) |
| 411 | */ |
Garrett Kirkendall | d255830 | 2018-03-06 09:05:20 -0600 | [diff] [blame] | 412 | ctrl = read32(misc_clk_cntl_1_ptr); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 413 | |
| 414 | /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */ |
Garrett Kirkendall | d255830 | 2018-03-06 09:05:20 -0600 | [diff] [blame] | 415 | ctrl &= ~OSCOUT1_CLK_OUTPUT_ENB; |
| 416 | write32(misc_clk_cntl_1_ptr, ctrl); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static uintptr_t sb_spibase(void) |
| 420 | { |
| 421 | u32 base, enables; |
| 422 | |
| 423 | /* Make sure the base address is predictable */ |
| 424 | base = pci_read_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER); |
| 425 | enables = base & 0xf; |
| 426 | base &= ~0x3f; |
| 427 | |
| 428 | if (!base) { |
| 429 | base = SPI_BASE_ADDRESS; |
| 430 | pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER, |
| 431 | base | enables | SPI_ROM_ENABLE); |
| 432 | /* PCI_COMMAND_MEMORY is read-only and enabled. */ |
| 433 | } |
| 434 | return (uintptr_t)base; |
| 435 | } |
| 436 | |
| 437 | void sb_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm) |
| 438 | { |
| 439 | uintptr_t base = sb_spibase(); |
| 440 | write16((void *)base + SPI100_SPEED_CONFIG, |
| 441 | (norm << SPI_NORM_SPEED_NEW_SH) | |
| 442 | (fast << SPI_FAST_SPEED_NEW_SH) | |
| 443 | (alt << SPI_ALT_SPEED_NEW_SH) | |
| 444 | (tpm << SPI_TPM_SPEED_NEW_SH)); |
| 445 | write16((void *)base + SPI100_ENABLE, SPI_USE_SPI100); |
| 446 | } |
| 447 | |
| 448 | void sb_disable_4dw_burst(void) |
| 449 | { |
| 450 | uintptr_t base = sb_spibase(); |
| 451 | write16((void *)base + SPI100_HOST_PREF_CONFIG, |
| 452 | read16((void *)base + SPI100_HOST_PREF_CONFIG) |
| 453 | & ~SPI_RD4DW_EN_HOST); |
| 454 | } |
| 455 | |
| 456 | void sb_set_readspeed(u16 norm, u16 fast) |
| 457 | { |
| 458 | uintptr_t base = sb_spibase(); |
| 459 | write16((void *)base + SPI_CNTRL1, (read16((void *)base + SPI_CNTRL1) |
| 460 | & ~SPI_CNTRL1_SPEED_MASK) |
| 461 | | (norm << SPI_NORM_SPEED_SH) |
| 462 | | (fast << SPI_FAST_SPEED_SH)); |
| 463 | } |
| 464 | |
| 465 | void sb_read_mode(u32 mode) |
| 466 | { |
| 467 | uintptr_t base = sb_spibase(); |
| 468 | write32((void *)base + SPI_CNTRL0, |
| 469 | (read32((void *)base + SPI_CNTRL0) |
| 470 | & ~SPI_READ_MODE_MASK) | mode); |
| 471 | } |
| 472 | |
Garrett Kirkendall | 6575306 | 2018-03-07 16:12:11 -0600 | [diff] [blame] | 473 | /* |
| 474 | * Enable FCH to decode TPM associated Memory and IO regions |
| 475 | * |
| 476 | * Enable decoding of TPM cycles defined in TPM 1.2 spec |
| 477 | * Enable decoding of legacy TPM addresses: IO addresses 0x7f- |
| 478 | * 0x7e and 0xef-0xee. |
| 479 | * This function should be called if TPM is connected in any way to the FCH and |
| 480 | * conforms to the regions decoded. |
| 481 | * Absent any other routing configuration the TPM cycles will be claimed by the |
| 482 | * LPC bus |
| 483 | */ |
| 484 | void sb_tpm_decode(void) |
| 485 | { |
| 486 | u32 value; |
| 487 | |
| 488 | value = pci_read_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE); |
| 489 | value |= TPM_12_EN | TPM_LEGACY_EN; |
| 490 | pci_write_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE, value); |
| 491 | } |
| 492 | |
| 493 | /* |
| 494 | * Enable FCH to decode TPM associated Memory and IO regions to SPI |
| 495 | * |
| 496 | * This should be used if TPM is connected to SPI bus. |
| 497 | * Assumes SPI address space is already configured via a call to sb_spibase(). |
| 498 | */ |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 499 | void sb_tpm_decode_spi(void) |
| 500 | { |
Garrett Kirkendall | 6575306 | 2018-03-07 16:12:11 -0600 | [diff] [blame] | 501 | /* Enable TPM decoding to FCH */ |
| 502 | sb_tpm_decode(); |
| 503 | |
| 504 | /* Route TPM accesses to SPI */ |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 505 | u32 spibase = pci_read_config32(SOC_LPC_DEV, |
| 506 | SPIROM_BASE_ADDRESS_REGISTER); |
| 507 | pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER, spibase |
| 508 | | ROUTE_TPM_2_SPI); |
| 509 | } |
| 510 | |
| 511 | /* |
| 512 | * Enable 4MB (LPC) ROM access at 0xFFC00000 - 0xFFFFFFFF. |
| 513 | * |
| 514 | * Hardware should enable LPC ROM by pin straps. This function does not |
| 515 | * handle the theoretically possible PCI ROM, FWH, or SPI ROM configurations. |
| 516 | * |
| 517 | * The southbridge power-on default is to map 512K ROM space. |
| 518 | * |
| 519 | */ |
| 520 | void sb_enable_rom(void) |
| 521 | { |
| 522 | u8 reg8; |
| 523 | |
| 524 | /* |
| 525 | * Decode variable LPC ROM address ranges 1 and 2. |
| 526 | * Bits 3-4 are not defined in any publicly available datasheet |
| 527 | */ |
| 528 | reg8 = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE); |
| 529 | reg8 |= (1 << 3) | (1 << 4); |
| 530 | pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE, reg8); |
| 531 | |
| 532 | /* |
| 533 | * LPC ROM address range 1: |
| 534 | * Enable LPC ROM range mirroring start at 0x000e(0000). |
| 535 | */ |
| 536 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_START, 0x000e); |
| 537 | |
| 538 | /* Enable LPC ROM range mirroring end at 0x000f(ffff). */ |
| 539 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_END, 0x000f); |
| 540 | |
| 541 | /* |
| 542 | * LPC ROM address range 2: |
| 543 | * |
| 544 | * Enable LPC ROM range start at: |
| 545 | * 0xfff8(0000): 512KB |
| 546 | * 0xfff0(0000): 1MB |
| 547 | * 0xffe0(0000): 2MB |
| 548 | * 0xffc0(0000): 4MB |
| 549 | */ |
| 550 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_START, 0x10000 |
| 551 | - (CONFIG_COREBOOT_ROMSIZE_KB >> 6)); |
| 552 | |
| 553 | /* Enable LPC ROM range end at 0xffff(ffff). */ |
| 554 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_END, 0xffff); |
| 555 | } |
| 556 | |
| 557 | void bootblock_fch_early_init(void) |
| 558 | { |
| 559 | sb_enable_rom(); |
| 560 | sb_lpc_port80(); |
| 561 | sb_lpc_decode(); |
Garrett Kirkendall | e7513e0d | 2018-03-14 12:01:36 -0500 | [diff] [blame] | 562 | sb_acpi_mmio_decode(); |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame^] | 563 | enable_aoac_devices(); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 566 | void sb_enable(device_t dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 567 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 568 | printk(BIOS_DEBUG, "%s\n", __func__); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 569 | } |
| 570 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 571 | static void sb_init_acpi_ports(void) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 572 | { |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame] | 573 | u32 reg; |
| 574 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 575 | /* We use some of these ports in SMM regardless of whether or not |
| 576 | * ACPI tables are generated. Enable these ports indiscriminately. |
| 577 | */ |
| 578 | |
| 579 | pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK); |
| 580 | pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK); |
| 581 | pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK); |
| 582 | pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK); |
| 583 | /* CpuControl is in \_PR.CP00, 6 bytes */ |
| 584 | pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL); |
| 585 | |
| 586 | if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) { |
Marshall Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 587 | /* APMC - SMI Command Port */ |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 588 | pm_write16(PM_ACPI_SMI_CMD, APM_CNT); |
Marshall Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 589 | configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI); |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame] | 590 | |
| 591 | /* SMI on SlpTyp requires sending SMI before completion |
| 592 | * response of the I/O write. The BKDG also specifies |
| 593 | * clearing ForceStpClkRetry for SMI trapping. |
| 594 | */ |
| 595 | reg = pm_read32(PM_PCI_CTRL); |
| 596 | reg |= FORCE_SLPSTATE_RETRY; |
| 597 | reg &= ~FORCE_STPCLK_RETRY; |
| 598 | pm_write32(PM_PCI_CTRL, reg); |
| 599 | |
| 600 | /* Disable SlpTyp feature */ |
| 601 | reg = pm_read8(PM_RST_CTRL1); |
| 602 | reg &= ~SLPTYPE_CONTROL_EN; |
| 603 | pm_write8(PM_RST_CTRL1, reg); |
| 604 | |
| 605 | configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 606 | } else { |
| 607 | pm_write16(PM_ACPI_SMI_CMD, 0); |
| 608 | } |
| 609 | |
Marshall Dawson | 5e2e74f | 2017-11-10 09:59:56 -0700 | [diff] [blame] | 610 | /* Decode ACPI registers and enable standard features */ |
| 611 | pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD | |
| 612 | PM_ACPI_GLOBAL_EN | |
| 613 | PM_ACPI_RTC_EN_EN | |
| 614 | PM_ACPI_TIMER_EN_EN); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 615 | } |
| 616 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 617 | void southbridge_init(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 618 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 619 | sb_init_acpi_ports(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 620 | } |
| 621 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 622 | void southbridge_final(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 623 | { |
Richard Spiegel | 6a38914 | 2018-03-05 14:28:10 -0700 | [diff] [blame] | 624 | uint8_t restored_power = PM_S5_AT_POWER_RECOVERY; |
| 625 | |
Richard Spiegel | 38f1940 | 2017-09-29 11:39:46 -0700 | [diff] [blame] | 626 | if (IS_ENABLED(CONFIG_STONEYRIDGE_IMC_FWM)) { |
| 627 | agesawrapper_fchecfancontrolservice(); |
| 628 | if (!IS_ENABLED(CONFIG_ACPI_ENABLE_THERMAL_ZONE)) |
| 629 | enable_imc_thermal_zone(); |
| 630 | } |
Richard Spiegel | 6a38914 | 2018-03-05 14:28:10 -0700 | [diff] [blame] | 631 | if (IS_ENABLED(CONFIG_MAINBOARD_POWER_RESTORE)) |
| 632 | restored_power = PM_RESTORE_S0_IF_PREV_S0; |
| 633 | pm_write8(PM_RTC_SHADOW, restored_power); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 634 | } |
Marshall Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 635 | |
| 636 | /* |
| 637 | * Update the PCI devices with a valid IRQ number |
| 638 | * that is set in the mainboard PCI_IRQ structures. |
| 639 | */ |
| 640 | static void set_pci_irqs(void *unused) |
| 641 | { |
| 642 | /* Write PCI_INTR regs 0xC00/0xC01 */ |
| 643 | write_pci_int_table(); |
| 644 | |
| 645 | /* Write IRQs for all devicetree enabled devices */ |
| 646 | write_pci_cfg_irqs(); |
| 647 | } |
| 648 | |
| 649 | /* |
| 650 | * Hook this function into the PCI state machine |
| 651 | * on entry into BS_DEV_ENABLE. |
| 652 | */ |
| 653 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL); |