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