Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 4 | #include <device/mmio.h> |
Marshall Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 5 | #include <bootstate.h> |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 6 | #include <cpu/x86/smm.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 7 | #include <device/device.h> |
| 8 | #include <device/pci.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 9 | #include <device/pci_ops.h> |
| 10 | #include <cbmem.h> |
Richard Spiegel | 2bbc3dc | 2017-12-06 16:14:58 -0700 | [diff] [blame] | 11 | #include <amdblocks/amd_pci_util.h> |
Richard Spiegel | 7108107 | 2018-07-26 10:51:38 -0700 | [diff] [blame] | 12 | #include <amdblocks/agesawrapper.h> |
Nico Huber | 73c1119 | 2018-10-06 18:20:47 +0200 | [diff] [blame] | 13 | #include <amdblocks/reset.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 14 | #include <amdblocks/acpimmio.h> |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 15 | #include <amdblocks/lpc.h> |
Marshall Dawson | 4ee83b2 | 2019-05-03 11:44:22 -0600 | [diff] [blame] | 16 | #include <amdblocks/acpi.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 17 | #include <soc/southbridge.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 18 | #include <soc/smi.h> |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 19 | #include <soc/amd_pci_int_defs.h> |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 20 | #include <delay.h> |
| 21 | #include <soc/pci_devs.h> |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 22 | #include <agesa_headers.h> |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 23 | #include <soc/nvs.h> |
Elyes HAOUAS | 27d02d8 | 2019-05-15 21:11:39 +0200 | [diff] [blame] | 24 | #include <types.h> |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 25 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 26 | /* |
| 27 | * Table of devices that need their AOAC registers enabled and waited |
| 28 | * upon (usually about .55 milliseconds). Instead of individual delays |
| 29 | * waiting for each device to become available, a single delay will be |
Richard Spiegel | 6dfbb59 | 2018-03-15 15:45:44 -0700 | [diff] [blame] | 30 | * executed. |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 31 | */ |
Elyes HAOUAS | 68ec3eb | 2019-06-22 09:21:18 +0200 | [diff] [blame] | 32 | static const struct stoneyridge_aoac aoac_devs[] = { |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 33 | { (FCH_AOAC_D3_CONTROL_UART0 + CONFIG_UART_FOR_CONSOLE * 2), |
| 34 | (FCH_AOAC_D3_STATE_UART0 + CONFIG_UART_FOR_CONSOLE * 2) }, |
| 35 | { FCH_AOAC_D3_CONTROL_AMBA, FCH_AOAC_D3_STATE_AMBA }, |
| 36 | { FCH_AOAC_D3_CONTROL_I2C0, FCH_AOAC_D3_STATE_I2C0 }, |
| 37 | { FCH_AOAC_D3_CONTROL_I2C1, FCH_AOAC_D3_STATE_I2C1 }, |
| 38 | { FCH_AOAC_D3_CONTROL_I2C2, FCH_AOAC_D3_STATE_I2C2 }, |
| 39 | { FCH_AOAC_D3_CONTROL_I2C3, FCH_AOAC_D3_STATE_I2C3 } |
| 40 | }; |
| 41 | |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 42 | static int is_sata_config(void) |
| 43 | { |
Richard Spiegel | bdd272a | 2018-10-16 13:53:05 -0700 | [diff] [blame] | 44 | return !((SataNativeIde == CONFIG_STONEYRIDGE_SATA_MODE) |
| 45 | || (SataLegacyIde == CONFIG_STONEYRIDGE_SATA_MODE)); |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Richard Spiegel | 7ea8e02 | 2018-01-16 14:40:10 -0700 | [diff] [blame] | 48 | static inline int sb_sata_enable(void) |
| 49 | { |
| 50 | /* True if IDE or AHCI. */ |
Richard Spiegel | bdd272a | 2018-10-16 13:53:05 -0700 | [diff] [blame] | 51 | return (SataNativeIde == CONFIG_STONEYRIDGE_SATA_MODE) || |
| 52 | (SataAhci == CONFIG_STONEYRIDGE_SATA_MODE); |
Richard Spiegel | 7ea8e02 | 2018-01-16 14:40:10 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static inline int sb_ide_enable(void) |
| 56 | { |
| 57 | /* True if IDE or LEGACY IDE. */ |
Richard Spiegel | bdd272a | 2018-10-16 13:53:05 -0700 | [diff] [blame] | 58 | return (SataNativeIde == CONFIG_STONEYRIDGE_SATA_MODE) || |
| 59 | (SataLegacyIde == CONFIG_STONEYRIDGE_SATA_MODE); |
Richard Spiegel | 7ea8e02 | 2018-01-16 14:40:10 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 62 | void SetFchResetParams(FCH_RESET_INTERFACE *params) |
| 63 | { |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 64 | const struct device *dev = pcidev_path_on_root(SATA_DEVFN); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 65 | params->Xhci0Enable = CONFIG(STONEYRIDGE_XHCI_ENABLE); |
Richard Spiegel | bb18b43 | 2018-08-03 10:37:28 -0700 | [diff] [blame] | 66 | if (dev && dev->enabled) { |
| 67 | params->SataEnable = sb_sata_enable(); |
| 68 | params->IdeEnable = sb_ide_enable(); |
| 69 | } else { |
| 70 | params->SataEnable = FALSE; |
| 71 | params->IdeEnable = FALSE; |
| 72 | } |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void SetFchEnvParams(FCH_INTERFACE *params) |
| 76 | { |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 77 | const struct device *dev = pcidev_path_on_root(SATA_DEVFN); |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 78 | params->AzaliaController = AzEnable; |
| 79 | params->SataClass = CONFIG_STONEYRIDGE_SATA_MODE; |
Richard Spiegel | bb18b43 | 2018-08-03 10:37:28 -0700 | [diff] [blame] | 80 | if (dev && dev->enabled) { |
| 81 | params->SataEnable = is_sata_config(); |
| 82 | params->IdeEnable = !params->SataEnable; |
| 83 | params->SataIdeMode = (CONFIG_STONEYRIDGE_SATA_MODE == |
| 84 | SataLegacyIde); |
| 85 | } else { |
| 86 | params->SataEnable = FALSE; |
| 87 | params->IdeEnable = FALSE; |
| 88 | params->SataIdeMode = FALSE; |
| 89 | } |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void SetFchMidParams(FCH_INTERFACE *params) |
| 93 | { |
| 94 | SetFchEnvParams(params); |
| 95 | } |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 96 | |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 97 | /* |
| 98 | * 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] | 99 | * provides a visible association with the index, therefore helping |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 100 | * maintainability of table. If a new index/name is defined in |
| 101 | * amd_pci_int_defs.h, just add the pair at the end of this table. |
| 102 | * Order is not important. |
| 103 | */ |
Elyes HAOUAS | 68ec3eb | 2019-06-22 09:21:18 +0200 | [diff] [blame] | 104 | static const struct irq_idx_name irq_association[] = { |
Richard Spiegel | e89d444 | 2017-12-08 07:52:42 -0700 | [diff] [blame] | 105 | { PIRQ_A, "INTA#" }, |
| 106 | { PIRQ_B, "INTB#" }, |
| 107 | { PIRQ_C, "INTC#" }, |
| 108 | { PIRQ_D, "INTD#" }, |
| 109 | { PIRQ_E, "INTE#" }, |
| 110 | { PIRQ_F, "INTF#" }, |
| 111 | { PIRQ_G, "INTG#" }, |
| 112 | { PIRQ_H, "INTH#" }, |
| 113 | { PIRQ_MISC, "Misc" }, |
| 114 | { PIRQ_MISC0, "Misc0" }, |
| 115 | { PIRQ_MISC1, "Misc1" }, |
| 116 | { PIRQ_MISC2, "Misc2" }, |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 117 | { PIRQ_SIRQA, "Ser IRQ INTA" }, |
| 118 | { PIRQ_SIRQB, "Ser IRQ INTB" }, |
| 119 | { PIRQ_SIRQC, "Ser IRQ INTC" }, |
| 120 | { PIRQ_SIRQD, "Ser IRQ INTD" }, |
Richard Spiegel | e89d444 | 2017-12-08 07:52:42 -0700 | [diff] [blame] | 121 | { PIRQ_SCI, "SCI" }, |
| 122 | { PIRQ_SMBUS, "SMBUS" }, |
| 123 | { PIRQ_ASF, "ASF" }, |
| 124 | { PIRQ_HDA, "HDA" }, |
| 125 | { PIRQ_FC, "FC" }, |
| 126 | { PIRQ_PMON, "PerMon" }, |
| 127 | { PIRQ_SD, "SD" }, |
| 128 | { PIRQ_SDIO, "SDIOt" }, |
Richard Spiegel | e89d444 | 2017-12-08 07:52:42 -0700 | [diff] [blame] | 129 | { PIRQ_EHCI, "EHCI" }, |
| 130 | { PIRQ_XHCI, "XHCI" }, |
| 131 | { PIRQ_SATA, "SATA" }, |
| 132 | { PIRQ_GPIO, "GPIO" }, |
| 133 | { PIRQ_I2C0, "I2C0" }, |
| 134 | { PIRQ_I2C1, "I2C1" }, |
| 135 | { PIRQ_I2C2, "I2C2" }, |
| 136 | { PIRQ_I2C3, "I2C3" }, |
| 137 | { PIRQ_UART0, "UART0" }, |
| 138 | { PIRQ_UART1, "UART1" }, |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | const struct irq_idx_name *sb_get_apic_reg_association(size_t *size) |
| 142 | { |
| 143 | *size = ARRAY_SIZE(irq_association); |
| 144 | return irq_association; |
| 145 | } |
| 146 | |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 147 | static void power_on_aoac_device(int aoac_device_control_register) |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 148 | { |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 149 | uint8_t byte; |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 150 | |
| 151 | /* Power on the UART and AMBA devices */ |
Marshall Dawson | b435d44 | 2019-05-01 21:17:20 -0600 | [diff] [blame] | 152 | byte = aoac_read8(aoac_device_control_register); |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 153 | byte |= FCH_AOAC_PWR_ON_DEV; |
Marshall Dawson | b435d44 | 2019-05-01 21:17:20 -0600 | [diff] [blame] | 154 | aoac_write8(aoac_device_control_register, byte); |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 155 | } |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 156 | |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 157 | static bool is_aoac_device_enabled(int aoac_device_status_register) |
| 158 | { |
| 159 | uint8_t byte; |
Marshall Dawson | b435d44 | 2019-05-01 21:17:20 -0600 | [diff] [blame] | 160 | |
| 161 | byte = aoac_read8(aoac_device_status_register); |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 162 | byte &= (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE); |
| 163 | if (byte == (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE)) |
| 164 | return true; |
| 165 | else |
| 166 | return false; |
| 167 | } |
| 168 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 169 | void enable_aoac_devices(void) |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 170 | { |
| 171 | bool status; |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 172 | int i; |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 173 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 174 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 175 | power_on_aoac_device(aoac_devs[i].enable); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 176 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 177 | /* Wait for AOAC devices to indicate power and clock OK */ |
| 178 | do { |
| 179 | udelay(100); |
| 180 | status = true; |
| 181 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 182 | status &= is_aoac_device_enabled(aoac_devs[i].status); |
| 183 | } while (!status); |
| 184 | } |
| 185 | |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 186 | static void sb_enable_lpc(void) |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 187 | { |
| 188 | u8 byte; |
| 189 | |
| 190 | /* Enable LPC controller */ |
Marshall Dawson | 939bfcc | 2019-05-05 15:39:40 -0600 | [diff] [blame] | 191 | byte = pm_io_read8(PM_LPC_GATING); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 192 | byte |= PM_LPC_ENABLE; |
Marshall Dawson | 939bfcc | 2019-05-05 15:39:40 -0600 | [diff] [blame] | 193 | pm_io_write8(PM_LPC_GATING, byte); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 196 | static void sb_lpc_decode(void) |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 197 | { |
| 198 | u32 tmp = 0; |
| 199 | |
| 200 | /* Enable I/O decode to LPC bus */ |
| 201 | tmp = DECODE_ENABLE_PARALLEL_PORT0 | DECODE_ENABLE_PARALLEL_PORT2 |
| 202 | | DECODE_ENABLE_PARALLEL_PORT4 | DECODE_ENABLE_SERIAL_PORT0 |
| 203 | | DECODE_ENABLE_SERIAL_PORT1 | DECODE_ENABLE_SERIAL_PORT2 |
| 204 | | DECODE_ENABLE_SERIAL_PORT3 | DECODE_ENABLE_SERIAL_PORT4 |
| 205 | | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT6 |
| 206 | | DECODE_ENABLE_SERIAL_PORT7 | DECODE_ENABLE_AUDIO_PORT0 |
| 207 | | DECODE_ENABLE_AUDIO_PORT1 | DECODE_ENABLE_AUDIO_PORT2 |
| 208 | | DECODE_ENABLE_AUDIO_PORT3 | DECODE_ENABLE_MSS_PORT2 |
| 209 | | DECODE_ENABLE_MSS_PORT3 | DECODE_ENABLE_FDC_PORT0 |
| 210 | | DECODE_ENABLE_FDC_PORT1 | DECODE_ENABLE_GAME_PORT |
| 211 | | DECODE_ENABLE_KBC_PORT | DECODE_ENABLE_ACPIUC_PORT |
| 212 | | DECODE_ENABLE_ADLIB_PORT; |
| 213 | |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 214 | /* Decode SIOs at 2E/2F and 4E/4F */ |
| 215 | if (CONFIG(STONEYRIDGE_LEGACY_FREE)) |
| 216 | tmp |= DECODE_ALTERNATE_SIO_ENABLE | DECODE_SIO_ENABLE; |
| 217 | |
| 218 | lpc_enable_decode(tmp); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Raul E Rangel | 5b05823 | 2018-06-28 16:31:45 -0600 | [diff] [blame] | 221 | static void sb_enable_cf9_io(void) |
| 222 | { |
| 223 | uint32_t reg = pm_read32(PM_DECODE_EN); |
| 224 | |
| 225 | pm_write32(PM_DECODE_EN, reg | CF9_IO_EN); |
| 226 | } |
| 227 | |
Raul E Rangel | 9abc3fe | 2018-06-28 16:31:45 -0600 | [diff] [blame] | 228 | static void sb_enable_legacy_io(void) |
| 229 | { |
| 230 | uint32_t reg = pm_read32(PM_DECODE_EN); |
| 231 | |
| 232 | pm_write32(PM_DECODE_EN, reg | LEGACY_IO_EN); |
| 233 | } |
| 234 | |
Richard Spiegel | c93d4ab | 2019-02-12 19:17:02 -0700 | [diff] [blame] | 235 | void sb_clk_output_48Mhz(u32 osc) |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 236 | { |
| 237 | u32 ctrl; |
| 238 | |
| 239 | /* |
Richard Spiegel | c93d4ab | 2019-02-12 19:17:02 -0700 | [diff] [blame] | 240 | * Clear the disable for OSCOUT1 (signal typically named XnnM_25M_48M) |
| 241 | * or OSCOUT2 (USBCLK/25M_48M_OSC). The frequency defaults to 48MHz. |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 242 | */ |
Marshall Dawson | b4b9efc | 2019-05-01 17:33:42 -0600 | [diff] [blame] | 243 | ctrl = misc_read32(MISC_CLK_CNTL1); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 244 | |
Richard Spiegel | c93d4ab | 2019-02-12 19:17:02 -0700 | [diff] [blame] | 245 | switch (osc) { |
| 246 | case 1: |
| 247 | ctrl &= ~OSCOUT1_CLK_OUTPUT_ENB; |
| 248 | break; |
| 249 | case 2: |
| 250 | ctrl &= ~OSCOUT2_CLK_OUTPUT_ENB; |
| 251 | break; |
| 252 | default: |
| 253 | return; /* do nothing if invalid */ |
| 254 | } |
Marshall Dawson | b4b9efc | 2019-05-01 17:33:42 -0600 | [diff] [blame] | 255 | misc_write32(MISC_CLK_CNTL1, ctrl); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Marshall Dawson | eceaa97 | 2019-05-05 18:35:12 -0600 | [diff] [blame] | 258 | static uintptr_t sb_init_spi_base(void) |
| 259 | { |
| 260 | uintptr_t base; |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 261 | |
| 262 | /* Make sure the base address is predictable */ |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 263 | base = lpc_get_spibase(); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 264 | |
Marshall Dawson | eceaa97 | 2019-05-05 18:35:12 -0600 | [diff] [blame] | 265 | if (base) |
| 266 | return base; |
| 267 | |
Furquan Shaikh | d82c7d2 | 2020-05-09 17:18:48 -0700 | [diff] [blame^] | 268 | lpc_set_spibase(SPI_BASE_ADDRESS); |
| 269 | lpc_enable_spi_rom(SPI_ROM_ENABLE); |
| 270 | |
Marshall Dawson | eceaa97 | 2019-05-05 18:35:12 -0600 | [diff] [blame] | 271 | return SPI_BASE_ADDRESS; |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void sb_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm) |
| 275 | { |
Marshall Dawson | eceaa97 | 2019-05-05 18:35:12 -0600 | [diff] [blame] | 276 | uintptr_t base = sb_init_spi_base(); |
Richard Spiegel | 9f25e9d | 2018-10-29 08:01:53 -0700 | [diff] [blame] | 277 | write16((void *)(base + SPI100_SPEED_CONFIG), |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 278 | (norm << SPI_NORM_SPEED_NEW_SH) | |
| 279 | (fast << SPI_FAST_SPEED_NEW_SH) | |
| 280 | (alt << SPI_ALT_SPEED_NEW_SH) | |
| 281 | (tpm << SPI_TPM_SPEED_NEW_SH)); |
Richard Spiegel | 9f25e9d | 2018-10-29 08:01:53 -0700 | [diff] [blame] | 282 | write16((void *)(base + SPI100_ENABLE), SPI_USE_SPI100); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void sb_disable_4dw_burst(void) |
| 286 | { |
Marshall Dawson | eceaa97 | 2019-05-05 18:35:12 -0600 | [diff] [blame] | 287 | uintptr_t base = sb_init_spi_base(); |
Richard Spiegel | 9f25e9d | 2018-10-29 08:01:53 -0700 | [diff] [blame] | 288 | write16((void *)(base + SPI100_HOST_PREF_CONFIG), |
| 289 | read16((void *)(base + SPI100_HOST_PREF_CONFIG)) |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 290 | & ~SPI_RD4DW_EN_HOST); |
| 291 | } |
| 292 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 293 | void sb_read_mode(u32 mode) |
| 294 | { |
Marshall Dawson | eceaa97 | 2019-05-05 18:35:12 -0600 | [diff] [blame] | 295 | uintptr_t base = sb_init_spi_base(); |
Richard Spiegel | 9f25e9d | 2018-10-29 08:01:53 -0700 | [diff] [blame] | 296 | write32((void *)(base + SPI_CNTRL0), |
| 297 | (read32((void *)(base + SPI_CNTRL0)) |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 298 | & ~SPI_READ_MODE_MASK) | mode); |
| 299 | } |
| 300 | |
Raul E Rangel | 7905341 | 2018-08-06 10:40:02 -0600 | [diff] [blame] | 301 | static void setup_spread_spectrum(int *reboot) |
Raul E Rangel | 6b0fc80 | 2018-08-02 15:56:34 -0600 | [diff] [blame] | 302 | { |
| 303 | uint16_t rstcfg = pm_read16(PWR_RESET_CFG); |
| 304 | |
| 305 | rstcfg &= ~TOGGLE_ALL_PWR_GOOD; |
| 306 | pm_write16(PWR_RESET_CFG, rstcfg); |
| 307 | |
| 308 | uint32_t cntl1 = misc_read32(MISC_CLK_CNTL1); |
| 309 | |
| 310 | if (cntl1 & CG1PLL_FBDIV_TEST) { |
| 311 | printk(BIOS_DEBUG, "Spread spectrum is ready\n"); |
| 312 | misc_write32(MISC_CGPLL_CONFIG1, |
| 313 | misc_read32(MISC_CGPLL_CONFIG1) | |
| 314 | CG1PLL_SPREAD_SPECTRUM_ENABLE); |
| 315 | |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | printk(BIOS_DEBUG, "Setting up spread spectrum\n"); |
| 320 | |
| 321 | uint32_t cfg6 = misc_read32(MISC_CGPLL_CONFIG6); |
| 322 | cfg6 &= ~CG1PLL_LF_MODE_MASK; |
Marshall Dawson | ecce847 | 2018-10-05 15:41:03 -0600 | [diff] [blame] | 323 | cfg6 |= (0x0f8 << CG1PLL_LF_MODE_SHIFT) & CG1PLL_LF_MODE_MASK; |
Raul E Rangel | 6b0fc80 | 2018-08-02 15:56:34 -0600 | [diff] [blame] | 324 | misc_write32(MISC_CGPLL_CONFIG6, cfg6); |
| 325 | |
| 326 | uint32_t cfg3 = misc_read32(MISC_CGPLL_CONFIG3); |
| 327 | cfg3 &= ~CG1PLL_REFDIV_MASK; |
| 328 | cfg3 |= (0x003 << CG1PLL_REFDIV_SHIFT) & CG1PLL_REFDIV_MASK; |
| 329 | cfg3 &= ~CG1PLL_FBDIV_MASK; |
Marshall Dawson | ecce847 | 2018-10-05 15:41:03 -0600 | [diff] [blame] | 330 | cfg3 |= (0x04b << CG1PLL_FBDIV_SHIFT) & CG1PLL_FBDIV_MASK; |
Raul E Rangel | 6b0fc80 | 2018-08-02 15:56:34 -0600 | [diff] [blame] | 331 | misc_write32(MISC_CGPLL_CONFIG3, cfg3); |
| 332 | |
| 333 | uint32_t cfg5 = misc_read32(MISC_CGPLL_CONFIG5); |
Marshall Dawson | edba21e | 2018-10-05 19:01:52 -0600 | [diff] [blame] | 334 | cfg5 &= ~SS_AMOUNT_NFRAC_SLIP_MASK; |
| 335 | cfg5 |= (0x2 << SS_AMOUNT_NFRAC_SLIP_SHIFT) & SS_AMOUNT_NFRAC_SLIP_MASK; |
Raul E Rangel | 6b0fc80 | 2018-08-02 15:56:34 -0600 | [diff] [blame] | 336 | misc_write32(MISC_CGPLL_CONFIG5, cfg5); |
| 337 | |
| 338 | uint32_t cfg4 = misc_read32(MISC_CGPLL_CONFIG4); |
Marshall Dawson | edba21e | 2018-10-05 19:01:52 -0600 | [diff] [blame] | 339 | cfg4 &= ~SS_AMOUNT_DSFRAC_MASK; |
| 340 | cfg4 |= (0xd000 << SS_AMOUNT_DSFRAC_SHIFT) & SS_AMOUNT_DSFRAC_MASK; |
| 341 | cfg4 &= ~SS_STEP_SIZE_DSFRAC_MASK; |
| 342 | cfg4 |= (0x02d5 << SS_STEP_SIZE_DSFRAC_SHIFT) |
| 343 | & SS_STEP_SIZE_DSFRAC_MASK; |
Raul E Rangel | 6b0fc80 | 2018-08-02 15:56:34 -0600 | [diff] [blame] | 344 | misc_write32(MISC_CGPLL_CONFIG4, cfg4); |
| 345 | |
| 346 | rstcfg |= TOGGLE_ALL_PWR_GOOD; |
| 347 | pm_write16(PWR_RESET_CFG, rstcfg); |
| 348 | |
| 349 | cntl1 |= CG1PLL_FBDIV_TEST; |
| 350 | misc_write32(MISC_CLK_CNTL1, cntl1); |
| 351 | |
Raul E Rangel | 7905341 | 2018-08-06 10:40:02 -0600 | [diff] [blame] | 352 | *reboot = 1; |
| 353 | } |
| 354 | |
| 355 | static void setup_misc(int *reboot) |
| 356 | { |
| 357 | /* Undocumented register */ |
| 358 | uint32_t reg = misc_read32(0x50); |
| 359 | if (!(reg & BIT(16))) { |
| 360 | reg |= BIT(16); |
| 361 | |
| 362 | misc_write32(0x50, reg); |
| 363 | *reboot = 1; |
| 364 | } |
Raul E Rangel | 6b0fc80 | 2018-08-02 15:56:34 -0600 | [diff] [blame] | 365 | } |
| 366 | |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 367 | static void fch_smbus_init(void) |
| 368 | { |
Aaron Durbin | 5c0ef70 | 2020-01-28 10:56:46 -0700 | [diff] [blame] | 369 | /* 400 kHz smbus speed. */ |
| 370 | const uint8_t smbus_speed = (66000000 / (400000 * 4)); |
| 371 | |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 372 | pm_write8(SMB_ASF_IO_BASE, SMB_BASE_ADDR >> 8); |
Aaron Durbin | 5c0ef70 | 2020-01-28 10:56:46 -0700 | [diff] [blame] | 373 | smbus_write8(SMBTIMING, smbus_speed); |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 374 | /* Clear all SMBUS status bits */ |
Marshall Dawson | 753c225 | 2019-05-05 14:08:59 -0600 | [diff] [blame] | 375 | smbus_write8(SMBHSTSTAT, SMBHST_STAT_CLEAR); |
| 376 | smbus_write8(SMBSLVSTAT, SMBSLV_STAT_CLEAR); |
| 377 | asf_write8(SMBHSTSTAT, SMBHST_STAT_CLEAR); |
| 378 | asf_write8(SMBSLVSTAT, SMBSLV_STAT_CLEAR); |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Raul E Rangel | d820f4b8 | 2018-08-13 10:39:03 -0600 | [diff] [blame] | 381 | /* Before console init */ |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 382 | void bootblock_fch_early_init(void) |
| 383 | { |
Raul E Rangel | 7905341 | 2018-08-06 10:40:02 -0600 | [diff] [blame] | 384 | int reboot = 0; |
| 385 | |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 386 | lpc_enable_rom(); |
| 387 | sb_enable_lpc(); |
| 388 | lpc_enable_port80(); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 389 | sb_lpc_decode(); |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 390 | lpc_enable_spi_prefetch(); |
Marshall Dawson | eceaa97 | 2019-05-05 18:35:12 -0600 | [diff] [blame] | 391 | sb_init_spi_base(); |
Marc Jones | cfb1680 | 2018-04-20 16:27:41 -0600 | [diff] [blame] | 392 | sb_disable_4dw_burst(); /* Must be disabled on CZ(ST) */ |
Michał Żygowski | 73a544d | 2019-11-24 14:16:34 +0100 | [diff] [blame] | 393 | enable_acpimmio_decode_pm04(); |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 394 | fch_smbus_init(); |
Raul E Rangel | 5b05823 | 2018-06-28 16:31:45 -0600 | [diff] [blame] | 395 | sb_enable_cf9_io(); |
Raul E Rangel | 7905341 | 2018-08-06 10:40:02 -0600 | [diff] [blame] | 396 | setup_spread_spectrum(&reboot); |
| 397 | setup_misc(&reboot); |
| 398 | |
| 399 | if (reboot) |
Nico Huber | 73c1119 | 2018-10-06 18:20:47 +0200 | [diff] [blame] | 400 | warm_reset(); |
Raul E Rangel | 7905341 | 2018-08-06 10:40:02 -0600 | [diff] [blame] | 401 | |
Raul E Rangel | 9abc3fe | 2018-06-28 16:31:45 -0600 | [diff] [blame] | 402 | sb_enable_legacy_io(); |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 403 | enable_aoac_devices(); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Edward Hill | cc68034 | 2018-08-10 16:20:02 -0600 | [diff] [blame] | 406 | static void print_num_status_bits(int num_bits, uint32_t status, |
| 407 | const char *const bit_names[]) |
| 408 | { |
| 409 | int i; |
| 410 | |
| 411 | if (!status) |
| 412 | return; |
| 413 | |
| 414 | for (i = num_bits - 1; i >= 0; i--) { |
| 415 | if (status & (1 << i)) { |
| 416 | if (bit_names[i]) |
| 417 | printk(BIOS_DEBUG, "%s ", bit_names[i]); |
| 418 | else |
| 419 | printk(BIOS_DEBUG, "BIT%d ", i); |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | static void sb_print_pmxc0_status(void) |
| 425 | { |
| 426 | /* PMxC0 S5/Reset Status shows the source of previous reset. */ |
| 427 | uint32_t pmxc0_status = pm_read32(PM_RST_STATUS); |
| 428 | |
Edward Hill | 917b400 | 2018-10-02 14:17:19 -0600 | [diff] [blame] | 429 | static const char *const pmxc0_status_bits[32] = { |
Edward Hill | cc68034 | 2018-08-10 16:20:02 -0600 | [diff] [blame] | 430 | [0] = "ThermalTrip", |
| 431 | [1] = "FourSecondPwrBtn", |
| 432 | [2] = "Shutdown", |
| 433 | [3] = "ThermalTripFromTemp", |
| 434 | [4] = "RemotePowerDownFromASF", |
| 435 | [5] = "ShutDownFan0", |
| 436 | [16] = "UserRst", |
| 437 | [17] = "SoftPciRst", |
| 438 | [18] = "DoInit", |
| 439 | [19] = "DoReset", |
| 440 | [20] = "DoFullReset", |
| 441 | [21] = "SleepReset", |
| 442 | [22] = "KbReset", |
| 443 | [23] = "LtReset", |
| 444 | [24] = "FailBootRst", |
| 445 | [25] = "WatchdogIssueReset", |
| 446 | [26] = "RemoteResetFromASF", |
| 447 | [27] = "SyncFlood", |
| 448 | [28] = "HangReset", |
| 449 | [29] = "EcWatchdogRst", |
Edward Hill | cc68034 | 2018-08-10 16:20:02 -0600 | [diff] [blame] | 450 | }; |
| 451 | |
Edward Hill | 917b400 | 2018-10-02 14:17:19 -0600 | [diff] [blame] | 452 | printk(BIOS_DEBUG, "PMxC0 STATUS: 0x%x ", pmxc0_status); |
Edward Hill | cc68034 | 2018-08-10 16:20:02 -0600 | [diff] [blame] | 453 | print_num_status_bits(ARRAY_SIZE(pmxc0_status_bits), pmxc0_status, |
| 454 | pmxc0_status_bits); |
Edward Hill | 917b400 | 2018-10-02 14:17:19 -0600 | [diff] [blame] | 455 | printk(BIOS_DEBUG, "\n"); |
Edward Hill | cc68034 | 2018-08-10 16:20:02 -0600 | [diff] [blame] | 456 | } |
| 457 | |
Raul E Rangel | d820f4b8 | 2018-08-13 10:39:03 -0600 | [diff] [blame] | 458 | /* After console init */ |
Edward Hill | cc68034 | 2018-08-10 16:20:02 -0600 | [diff] [blame] | 459 | void bootblock_fch_init(void) |
| 460 | { |
| 461 | sb_print_pmxc0_status(); |
| 462 | } |
Raul E Rangel | d820f4b8 | 2018-08-13 10:39:03 -0600 | [diff] [blame] | 463 | |
Elyes HAOUAS | c5ad267 | 2018-12-05 10:58:34 +0100 | [diff] [blame] | 464 | void sb_enable(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 465 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 466 | printk(BIOS_DEBUG, "%s\n", __func__); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 467 | } |
| 468 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 469 | static void sb_init_acpi_ports(void) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 470 | { |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame] | 471 | u32 reg; |
| 472 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 473 | /* We use some of these ports in SMM regardless of whether or not |
| 474 | * ACPI tables are generated. Enable these ports indiscriminately. |
| 475 | */ |
| 476 | |
| 477 | pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK); |
| 478 | pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK); |
| 479 | pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK); |
| 480 | pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK); |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 481 | /* CpuControl is in \_SB.CP00, 6 bytes */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 482 | pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL); |
| 483 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 484 | if (CONFIG(HAVE_SMI_HANDLER)) { |
Marshall Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 485 | /* APMC - SMI Command Port */ |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 486 | pm_write16(PM_ACPI_SMI_CMD, APM_CNT); |
Marshall Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 487 | configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI); |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame] | 488 | |
| 489 | /* SMI on SlpTyp requires sending SMI before completion |
| 490 | * response of the I/O write. The BKDG also specifies |
| 491 | * clearing ForceStpClkRetry for SMI trapping. |
| 492 | */ |
| 493 | reg = pm_read32(PM_PCI_CTRL); |
| 494 | reg |= FORCE_SLPSTATE_RETRY; |
| 495 | reg &= ~FORCE_STPCLK_RETRY; |
| 496 | pm_write32(PM_PCI_CTRL, reg); |
| 497 | |
| 498 | /* Disable SlpTyp feature */ |
| 499 | reg = pm_read8(PM_RST_CTRL1); |
| 500 | reg &= ~SLPTYPE_CONTROL_EN; |
| 501 | pm_write8(PM_RST_CTRL1, reg); |
| 502 | |
| 503 | configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 504 | } else { |
| 505 | pm_write16(PM_ACPI_SMI_CMD, 0); |
| 506 | } |
| 507 | |
Marshall Dawson | 5e2e74f | 2017-11-10 09:59:56 -0700 | [diff] [blame] | 508 | /* Decode ACPI registers and enable standard features */ |
| 509 | pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD | |
| 510 | PM_ACPI_GLOBAL_EN | |
| 511 | PM_ACPI_RTC_EN_EN | |
| 512 | PM_ACPI_TIMER_EN_EN); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 513 | } |
| 514 | |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 515 | static int get_index_bit(uint32_t value, uint16_t limit) |
| 516 | { |
| 517 | uint16_t i; |
| 518 | uint32_t t; |
| 519 | |
Richard Spiegel | ef73cb8 | 2018-06-19 07:40:18 -0700 | [diff] [blame] | 520 | if (limit >= TOTAL_BITS(uint32_t)) |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 521 | return -1; |
| 522 | |
| 523 | /* get a mask of valid bits. Ex limit = 3, set bits 0-2 */ |
| 524 | t = (1 << limit) - 1; |
| 525 | if ((value & t) == 0) |
| 526 | return -1; |
| 527 | t = 1; |
| 528 | for (i = 0; i < limit; i++) { |
| 529 | if (value & t) |
| 530 | break; |
| 531 | t <<= 1; |
| 532 | } |
| 533 | return i; |
| 534 | } |
| 535 | |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 536 | static void set_nvs_sws(void *unused) |
| 537 | { |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 538 | struct soc_power_reg *sws; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 539 | struct global_nvs_t *gnvs; |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 540 | int index; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 541 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 542 | sws = cbmem_find(CBMEM_ID_POWER_STATE); |
| 543 | if (sws == NULL) |
| 544 | return; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 545 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 546 | if (gnvs == NULL) |
| 547 | return; |
| 548 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 549 | index = get_index_bit(sws->pm1_sts & sws->pm1_en, PM1_LIMIT); |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 550 | if (index < 0) |
| 551 | gnvs->pm1i = ~0ULL; |
| 552 | else |
| 553 | gnvs->pm1i = index; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 554 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 555 | index = get_index_bit(sws->gpe0_sts & sws->gpe0_en, GPE0_LIMIT); |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 556 | if (index < 0) |
| 557 | gnvs->gpei = ~0ULL; |
| 558 | else |
| 559 | gnvs->gpei = index; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, set_nvs_sws, NULL); |
| 563 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 564 | void southbridge_init(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 565 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 566 | sb_init_acpi_ports(); |
Marshall Dawson | 4ee83b2 | 2019-05-03 11:44:22 -0600 | [diff] [blame] | 567 | acpi_clear_pm1_status(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 568 | } |
| 569 | |
Marshall Dawson | 1d9a46b | 2018-09-26 16:23:41 -0600 | [diff] [blame] | 570 | static void set_sb_final_nvs(void) |
| 571 | { |
| 572 | uintptr_t amdfw_rom; |
| 573 | uintptr_t xhci_fw; |
| 574 | uintptr_t fwaddr; |
| 575 | size_t fwsize; |
Richard Spiegel | 41baf0c | 2018-10-22 13:57:18 -0700 | [diff] [blame] | 576 | const struct device *sd, *sata; |
Marshall Dawson | 1d9a46b | 2018-09-26 16:23:41 -0600 | [diff] [blame] | 577 | |
| 578 | struct global_nvs_t *gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 579 | if (gnvs == NULL) |
| 580 | return; |
| 581 | |
| 582 | gnvs->aoac.ic0e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_I2C0); |
| 583 | gnvs->aoac.ic1e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_I2C1); |
| 584 | gnvs->aoac.ic2e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_I2C2); |
| 585 | gnvs->aoac.ic3e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_I2C3); |
| 586 | gnvs->aoac.ut0e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_UART0); |
| 587 | gnvs->aoac.ut1e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_UART1); |
| 588 | gnvs->aoac.ehce = is_aoac_device_enabled(FCH_AOAC_D3_STATE_USB2); |
| 589 | gnvs->aoac.xhce = is_aoac_device_enabled(FCH_AOAC_D3_STATE_USB3); |
| 590 | /* Rely on these being in sync with devicetree */ |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 591 | sd = pcidev_path_on_root(SD_DEVFN); |
Marshall Dawson | 6d3b7e6 | 2019-04-18 17:01:01 -0600 | [diff] [blame] | 592 | gnvs->aoac.sd_e = sd && sd->enabled ? 1 : 0; |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 593 | sata = pcidev_path_on_root(SATA_DEVFN); |
Marshall Dawson | 6d3b7e6 | 2019-04-18 17:01:01 -0600 | [diff] [blame] | 594 | gnvs->aoac.st_e = sata && sata->enabled ? 1 : 0; |
Marshall Dawson | 1d9a46b | 2018-09-26 16:23:41 -0600 | [diff] [blame] | 595 | gnvs->aoac.espi = 1; |
| 596 | |
| 597 | amdfw_rom = 0x20000 - (0x80000 << CONFIG_AMD_FWM_POSITION_INDEX); |
| 598 | xhci_fw = read32((void *)(amdfw_rom + XHCI_FW_SIG_OFFSET)); |
| 599 | |
| 600 | fwaddr = 2 + read16((void *)(xhci_fw + XHCI_FW_ADDR_OFFSET |
| 601 | + XHCI_FW_BOOTRAM_SIZE)); |
| 602 | fwsize = read16((void *)(xhci_fw + XHCI_FW_SIZE_OFFSET |
| 603 | + XHCI_FW_BOOTRAM_SIZE)); |
| 604 | gnvs->fw00 = 0; |
| 605 | gnvs->fw01 = ((32 * KiB) << 16) + 0; |
| 606 | gnvs->fw02 = fwaddr + XHCI_FW_BOOTRAM_SIZE; |
| 607 | gnvs->fw03 = fwsize << 16; |
| 608 | |
Marshall Dawson | 1d9a46b | 2018-09-26 16:23:41 -0600 | [diff] [blame] | 609 | gnvs->eh10 = pci_read_config32(SOC_EHCI1_DEV, PCI_BASE_ADDRESS_0) |
| 610 | & ~PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
| 611 | } |
| 612 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 613 | void southbridge_final(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 614 | { |
Richard Spiegel | 6a38914 | 2018-03-05 14:28:10 -0700 | [diff] [blame] | 615 | uint8_t restored_power = PM_S5_AT_POWER_RECOVERY; |
| 616 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 617 | if (CONFIG(MAINBOARD_POWER_RESTORE)) |
Richard Spiegel | 6a38914 | 2018-03-05 14:28:10 -0700 | [diff] [blame] | 618 | restored_power = PM_RESTORE_S0_IF_PREV_S0; |
| 619 | pm_write8(PM_RTC_SHADOW, restored_power); |
Marshall Dawson | 1d9a46b | 2018-09-26 16:23:41 -0600 | [diff] [blame] | 620 | |
| 621 | set_sb_final_nvs(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 622 | } |
Marshall Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 623 | |
| 624 | /* |
| 625 | * Update the PCI devices with a valid IRQ number |
| 626 | * that is set in the mainboard PCI_IRQ structures. |
| 627 | */ |
| 628 | static void set_pci_irqs(void *unused) |
| 629 | { |
| 630 | /* Write PCI_INTR regs 0xC00/0xC01 */ |
| 631 | write_pci_int_table(); |
| 632 | |
| 633 | /* Write IRQs for all devicetree enabled devices */ |
| 634 | write_pci_cfg_irqs(); |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * Hook this function into the PCI state machine |
| 639 | * on entry into BS_DEV_ENABLE. |
| 640 | */ |
| 641 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL); |