Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 3 | |
| 4 | #ifndef _HUDSON_EARLY_SETUP_C_ |
| 5 | #define _HUDSON_EARLY_SETUP_C_ |
| 6 | |
Marc Jones | f962aa5 | 2017-03-22 18:47:49 +0800 | [diff] [blame] | 7 | #include <assert.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 8 | #include <stdint.h> |
Michał Żygowski | 287ce5f | 2019-12-01 17:41:23 +0100 | [diff] [blame] | 9 | #include <amdblocks/acpimmio.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 10 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 11 | #include <device/pci_ops.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 12 | #include <console/console.h> |
Kyösti Mälkki | a244d5e | 2019-12-09 08:08:58 +0200 | [diff] [blame] | 13 | #include <amdblocks/acpimmio.h> |
Elyes HAOUAS | eb789f0 | 2018-10-27 16:40:25 +0200 | [diff] [blame] | 14 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 15 | #include "hudson.h" |
Dave Frodin | f364fc7 | 2015-03-13 08:22:17 -0600 | [diff] [blame] | 16 | #include "pci_devs.h" |
Piotr Król | dcd2f17 | 2016-05-27 12:04:13 +0200 | [diff] [blame] | 17 | #include <Fch/Fch.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 18 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 19 | #if CONFIG(HUDSON_UART) |
Zheng Bao | 2286138 | 2015-11-21 12:19:22 +0800 | [diff] [blame] | 20 | |
| 21 | #include <cpu/x86/msr.h> |
| 22 | #include <delay.h> |
Zheng Bao | 2286138 | 2015-11-21 12:19:22 +0800 | [diff] [blame] | 23 | |
| 24 | void configure_hudson_uart(void) |
| 25 | { |
Zheng Bao | 2286138 | 2015-11-21 12:19:22 +0800 | [diff] [blame] | 26 | u8 byte; |
| 27 | |
Michał Żygowski | 287ce5f | 2019-12-01 17:41:23 +0100 | [diff] [blame] | 28 | byte = aoac_read8(FCH_AOAC_REG56 + |
| 29 | CONFIG_UART_FOR_CONSOLE * sizeof(u16))); |
Zheng Bao | 2286138 | 2015-11-21 12:19:22 +0800 | [diff] [blame] | 30 | byte |= 1 << 3; |
Michał Żygowski | 287ce5f | 2019-12-01 17:41:23 +0100 | [diff] [blame] | 31 | aoac_write8(FCH_AOAC_REG56 + CONFIG_UART_FOR_CONSOLE * sizeof(u16)), |
| 32 | byte); |
| 33 | |
| 34 | aoac_write8(FCH_AOAC_REG62, aoac_read8(FCH_AOAC_REG62) | (1 << 3)); |
| 35 | iomux_write8(0x89, 0); /* UART0_RTS_L_EGPIO137 */ |
| 36 | iomux_write8(0x8a, 0); /* UART0_TXD_EGPIO138 */ |
| 37 | iomux_write8(0x8e, 0); /* UART1_RTS_L_EGPIO142 */ |
| 38 | iomux_write8(0x8f, 0); /* UART1_TXD_EGPIO143 */ |
Zheng Bao | 2286138 | 2015-11-21 12:19:22 +0800 | [diff] [blame] | 39 | |
| 40 | udelay(2000); |
Richard Spiegel | bd48b23 | 2018-11-02 08:25:00 -0700 | [diff] [blame] | 41 | write8((void *)(0xFEDC6000 + 0x2000 * CONFIG_UART_FOR_CONSOLE + 0x88), |
| 42 | 0x01); /* reset UART */ |
Zheng Bao | 2286138 | 2015-11-21 12:19:22 +0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | #endif |
| 46 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 47 | void hudson_pci_port80(void) |
| 48 | { |
| 49 | u8 byte; |
Antonello Dettori | 1ac9728 | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 50 | pci_devfn_t dev; |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 51 | |
| 52 | /* P2P Bridge */ |
| 53 | dev = PCI_DEV(0, 0x14, 4); |
| 54 | |
| 55 | /* Chip Control: Enable subtractive decoding */ |
| 56 | byte = pci_read_config8(dev, 0x40); |
| 57 | byte |= 1 << 5; |
| 58 | pci_write_config8(dev, 0x40, byte); |
| 59 | |
| 60 | /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */ |
| 61 | byte = pci_read_config8(dev, 0x4B); |
| 62 | byte |= 1 << 7; |
| 63 | pci_write_config8(dev, 0x4B, byte); |
| 64 | |
| 65 | /* The same IO Base and IO Limit here is meaningful because we set the |
| 66 | * bridge to be subtractive. During early setup stage, we have to make |
| 67 | * sure that data can go through port 0x80. |
| 68 | */ |
| 69 | /* IO Base: 0xf000 */ |
| 70 | byte = pci_read_config8(dev, 0x1C); |
| 71 | byte |= 0xF << 4; |
| 72 | pci_write_config8(dev, 0x1C, byte); |
| 73 | |
| 74 | /* IO Limit: 0xf000 */ |
| 75 | byte = pci_read_config8(dev, 0x1D); |
| 76 | byte |= 0xF << 4; |
| 77 | pci_write_config8(dev, 0x1D, byte); |
| 78 | |
| 79 | /* PCI Command: Enable IO response */ |
| 80 | byte = pci_read_config8(dev, 0x04); |
| 81 | byte |= 1 << 0; |
| 82 | pci_write_config8(dev, 0x04, byte); |
| 83 | |
| 84 | /* LPC controller */ |
| 85 | dev = PCI_DEV(0, 0x14, 3); |
| 86 | |
| 87 | byte = pci_read_config8(dev, 0x4A); |
| 88 | byte &= ~(1 << 5); /* disable lpc port 80 */ |
| 89 | pci_write_config8(dev, 0x4A, byte); |
| 90 | } |
| 91 | |
| 92 | void hudson_lpc_port80(void) |
| 93 | { |
| 94 | u8 byte; |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 95 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 96 | /* Enable port 80 LPC decode in pci function 3 configuration space. */ |
Elyes HAOUAS | 2f58a00 | 2020-04-22 16:07:39 +0200 | [diff] [blame^] | 97 | const pci_devfn_t dev = PCI_DEV(0, 0x14, 3); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 98 | byte = pci_read_config8(dev, 0x4a); |
| 99 | byte |= 1 << 5; /* enable port 80 */ |
| 100 | pci_write_config8(dev, 0x4a, byte); |
| 101 | } |
| 102 | |
Dave Frodin | f364fc7 | 2015-03-13 08:22:17 -0600 | [diff] [blame] | 103 | void hudson_lpc_decode(void) |
| 104 | { |
Michał Żygowski | 8cee45c | 2019-11-23 18:03:46 +0100 | [diff] [blame] | 105 | u32 tmp; |
Dave Frodin | f364fc7 | 2015-03-13 08:22:17 -0600 | [diff] [blame] | 106 | |
Kyösti Mälkki | a244d5e | 2019-12-09 08:08:58 +0200 | [diff] [blame] | 107 | /* Enable LPC controller */ |
| 108 | pm_write8(0xec, pm_read8(0xec) | 0x01); |
| 109 | |
Elyes HAOUAS | 2f58a00 | 2020-04-22 16:07:39 +0200 | [diff] [blame^] | 110 | const pci_devfn_t dev = PCI_DEV(0, 0x14, 3); |
Michał Żygowski | 8cee45c | 2019-11-23 18:03:46 +0100 | [diff] [blame] | 111 | /* Serial port numeration on Hudson: |
| 112 | * PORT0 - 0x3f8 |
| 113 | * PORT1 - 0x2f8 |
| 114 | * PORT5 - 0x2e8 |
| 115 | * PORT7 - 0x3e8 |
| 116 | */ |
| 117 | tmp = DECODE_ENABLE_SERIAL_PORT0 | DECODE_ENABLE_SERIAL_PORT1 |
| 118 | | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT7; |
Dave Frodin | f364fc7 | 2015-03-13 08:22:17 -0600 | [diff] [blame] | 119 | |
| 120 | pci_write_config32(dev, LPC_IO_PORT_DECODE_ENABLE, tmp); |
| 121 | } |
| 122 | |
Marc Jones | f962aa5 | 2017-03-22 18:47:49 +0800 | [diff] [blame] | 123 | static void enable_wideio(uint8_t port, uint16_t size) |
| 124 | { |
| 125 | uint32_t wideio_enable[] = { |
| 126 | LPC_WIDEIO0_ENABLE, |
| 127 | LPC_WIDEIO1_ENABLE, |
| 128 | LPC_WIDEIO2_ENABLE |
| 129 | }; |
| 130 | uint32_t alt_wideio_enable[] = { |
| 131 | LPC_ALT_WIDEIO0_ENABLE, |
| 132 | LPC_ALT_WIDEIO1_ENABLE, |
| 133 | LPC_ALT_WIDEIO2_ENABLE |
| 134 | }; |
Elyes HAOUAS | 2f58a00 | 2020-04-22 16:07:39 +0200 | [diff] [blame^] | 135 | const pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC); |
Marc Jones | f962aa5 | 2017-03-22 18:47:49 +0800 | [diff] [blame] | 136 | uint32_t tmp; |
| 137 | |
| 138 | /* Only allow port 0-2 */ |
| 139 | assert(port <= ARRAY_SIZE(wideio_enable)); |
| 140 | |
| 141 | if (size == 16) { |
| 142 | tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE); |
| 143 | tmp |= alt_wideio_enable[port]; |
| 144 | pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp); |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 145 | } else { /* 512 */ |
Marc Jones | f962aa5 | 2017-03-22 18:47:49 +0800 | [diff] [blame] | 146 | tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE); |
| 147 | tmp &= ~alt_wideio_enable[port]; |
| 148 | pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp); |
| 149 | } |
| 150 | |
| 151 | /* Enable the range */ |
| 152 | tmp = pci_read_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE); |
| 153 | tmp |= wideio_enable[port]; |
| 154 | pci_write_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE, tmp); |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * lpc_wideio_window() may be called any point in romstage, but take |
| 159 | * care that AGESA doesn't overwrite the range this function used. |
| 160 | * The function checks if there is an empty range and if all ranges are |
| 161 | * used the function throws an assert. The function doesn't check for a |
| 162 | * duplicate range, for ranges that can be merged into a single |
| 163 | * range, or ranges that overlap. |
| 164 | * |
| 165 | * The developer is expected to ensure that there are no conflicts. |
| 166 | */ |
| 167 | static void lpc_wideio_window(uint16_t base, uint16_t size) |
| 168 | { |
Elyes HAOUAS | 2f58a00 | 2020-04-22 16:07:39 +0200 | [diff] [blame^] | 169 | const pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC); |
Marc Jones | f962aa5 | 2017-03-22 18:47:49 +0800 | [diff] [blame] | 170 | u32 tmp; |
| 171 | |
| 172 | /* Support 512 or 16 bytes per range */ |
| 173 | assert(size == 512 || size == 16); |
| 174 | |
| 175 | /* Find and open Base Register and program it */ |
| 176 | tmp = pci_read_config32(dev, LPC_WIDEIO_GENERIC_PORT); |
| 177 | |
| 178 | if ((tmp & 0xFFFF) == 0) { /* WIDEIO0 */ |
| 179 | tmp |= base; |
| 180 | pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp); |
| 181 | enable_wideio(0, size); |
| 182 | } else if ((tmp & 0xFFFF0000) == 0) { /* WIDEIO1 */ |
| 183 | tmp |= (base << 16); |
| 184 | pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp); |
| 185 | enable_wideio(1, size); |
| 186 | } else { /* Check WIDEIO2 register */ |
| 187 | tmp = pci_read_config32(dev, LPC_WIDEIO2_GENERIC_PORT); |
| 188 | if ((tmp & 0xFFFF) == 0) { /* WIDEIO2 */ |
| 189 | tmp |= base; |
| 190 | pci_write_config32(dev, LPC_WIDEIO2_GENERIC_PORT, tmp); |
| 191 | enable_wideio(2, size); |
| 192 | } else { /* All WIDEIO locations used*/ |
| 193 | assert(0); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | void lpc_wideio_512_window(uint16_t base) |
| 199 | { |
| 200 | assert(IS_ALIGNED(base, 512)); |
| 201 | lpc_wideio_window(base, 512); |
| 202 | } |
| 203 | |
| 204 | void lpc_wideio_16_window(uint16_t base) |
| 205 | { |
| 206 | assert(IS_ALIGNED(base, 16)); |
| 207 | lpc_wideio_window(base, 16); |
| 208 | } |
| 209 | |
Piotr Król | dcd2f17 | 2016-05-27 12:04:13 +0200 | [diff] [blame] | 210 | void hudson_clk_output_48Mhz(void) |
| 211 | { |
Marshall Dawson | 0bf3f55 | 2017-07-13 12:06:25 -0600 | [diff] [blame] | 212 | u32 ctrl; |
Piotr Król | dcd2f17 | 2016-05-27 12:04:13 +0200 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so |
| 216 | * 48Mhz will be on ball AP13 (FT3b package) |
| 217 | */ |
Michał Żygowski | 287ce5f | 2019-12-01 17:41:23 +0100 | [diff] [blame] | 218 | ctrl = misc_read32(FCH_MISC_REG40); |
Piotr Król | dcd2f17 | 2016-05-27 12:04:13 +0200 | [diff] [blame] | 219 | |
| 220 | /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */ |
Marshall Dawson | 0bf3f55 | 2017-07-13 12:06:25 -0600 | [diff] [blame] | 221 | ctrl &= (u32)~(1<<2); |
Michał Żygowski | 287ce5f | 2019-12-01 17:41:23 +0100 | [diff] [blame] | 222 | misc_write32(FCH_MISC_REG40, ctrl); |
Piotr Król | dcd2f17 | 2016-05-27 12:04:13 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Marshall Dawson | 91dea4a | 2017-02-10 16:03:54 -0700 | [diff] [blame] | 225 | static uintptr_t hudson_spibase(void) |
| 226 | { |
| 227 | /* Make sure the base address is predictable */ |
Elyes HAOUAS | 2f58a00 | 2020-04-22 16:07:39 +0200 | [diff] [blame^] | 228 | const pci_devfn_t dev = PCI_DEV(0, 0x14, 3); |
Marshall Dawson | 91dea4a | 2017-02-10 16:03:54 -0700 | [diff] [blame] | 229 | |
| 230 | u32 base = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER) |
| 231 | & 0xfffffff0; |
| 232 | if (!base){ |
| 233 | base = SPI_BASE_ADDRESS; |
| 234 | pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, base |
| 235 | | SPI_ROM_ENABLE); |
| 236 | /* PCI_COMMAND_MEMORY is read-only and enabled. */ |
| 237 | } |
| 238 | return (uintptr_t)base; |
| 239 | } |
| 240 | |
| 241 | void hudson_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm) |
| 242 | { |
| 243 | uintptr_t base = hudson_spibase(); |
Richard Spiegel | bd48b23 | 2018-11-02 08:25:00 -0700 | [diff] [blame] | 244 | write16((void *)(base + SPI100_SPEED_CONFIG), |
Marshall Dawson | 91dea4a | 2017-02-10 16:03:54 -0700 | [diff] [blame] | 245 | (norm << SPI_NORM_SPEED_NEW_SH) | |
| 246 | (fast << SPI_FAST_SPEED_NEW_SH) | |
| 247 | (alt << SPI_ALT_SPEED_NEW_SH) | |
| 248 | (tpm << SPI_TPM_SPEED_NEW_SH)); |
Richard Spiegel | bd48b23 | 2018-11-02 08:25:00 -0700 | [diff] [blame] | 249 | write16((void *)(base + SPI100_ENABLE), SPI_USE_SPI100); |
Marshall Dawson | 91dea4a | 2017-02-10 16:03:54 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void hudson_disable_4dw_burst(void) |
| 253 | { |
| 254 | uintptr_t base = hudson_spibase(); |
Richard Spiegel | bd48b23 | 2018-11-02 08:25:00 -0700 | [diff] [blame] | 255 | write16((void *)(base + SPI100_HOST_PREF_CONFIG), |
| 256 | read16((void *)(base + SPI100_HOST_PREF_CONFIG)) |
Marshall Dawson | 91dea4a | 2017-02-10 16:03:54 -0700 | [diff] [blame] | 257 | & ~SPI_RD4DW_EN_HOST); |
| 258 | } |
| 259 | |
| 260 | /* Hudson 1-3 only. For Hudson 1, call with fast=1 */ |
| 261 | void hudson_set_readspeed(u16 norm, u16 fast) |
| 262 | { |
| 263 | uintptr_t base = hudson_spibase(); |
Richard Spiegel | bd48b23 | 2018-11-02 08:25:00 -0700 | [diff] [blame] | 264 | write16((void *)(base + SPI_CNTRL1), |
| 265 | (read16((void *)(base + SPI_CNTRL1)) |
| 266 | & ~SPI_CNTRL1_SPEED_MASK) |
| 267 | | (norm << SPI_NORM_SPEED_SH) |
| 268 | | (fast << SPI_FAST_SPEED_SH)); |
Marshall Dawson | 91dea4a | 2017-02-10 16:03:54 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void hudson_read_mode(u32 mode) |
| 272 | { |
| 273 | uintptr_t base = hudson_spibase(); |
Richard Spiegel | bd48b23 | 2018-11-02 08:25:00 -0700 | [diff] [blame] | 274 | write32((void *)(base + SPI_CNTRL0), |
| 275 | (read32((void *)(base + SPI_CNTRL0)) |
Marshall Dawson | 91dea4a | 2017-02-10 16:03:54 -0700 | [diff] [blame] | 276 | & ~SPI_READ_MODE_MASK) | mode); |
| 277 | } |
| 278 | |
Marc Jones | 6fcaaef | 2017-04-20 16:48:42 -0600 | [diff] [blame] | 279 | void hudson_tpm_decode_spi(void) |
| 280 | { |
Elyes HAOUAS | 2f58a00 | 2020-04-22 16:07:39 +0200 | [diff] [blame^] | 281 | const pci_devfn_t dev = PCI_DEV(0, 0x14, 3); /* LPC device */ |
Marc Jones | 6fcaaef | 2017-04-20 16:48:42 -0600 | [diff] [blame] | 282 | |
| 283 | u32 spibase = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER); |
| 284 | pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, spibase |
| 285 | | ROUTE_TPM_2_SPI); |
| 286 | } |
| 287 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 288 | #endif |