blob: 14bb5e29c3d9a7cfc0c1a87d8e04e27436c73300 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03002
3#ifndef _HUDSON_EARLY_SETUP_C_
4#define _HUDSON_EARLY_SETUP_C_
5
Marc Jonesf962aa52017-03-22 18:47:49 +08006#include <assert.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03007#include <stdint.h>
Michał Żygowski287ce5f2019-12-01 17:41:23 +01008#include <amdblocks/acpimmio.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02009#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020010#include <device/pci_ops.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030011#include <console/console.h>
Elyes HAOUASeb789f02018-10-27 16:40:25 +020012
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030013#include "hudson.h"
Dave Frodinf364fc72015-03-13 08:22:17 -060014#include "pci_devs.h"
Piotr Króldcd2f172016-05-27 12:04:13 +020015#include <Fch/Fch.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030016
Julius Wernercd49cce2019-03-05 16:53:33 -080017#if CONFIG(HUDSON_UART)
Zheng Bao22861382015-11-21 12:19:22 +080018
Zheng Bao22861382015-11-21 12:19:22 +080019#include <delay.h>
Zheng Bao22861382015-11-21 12:19:22 +080020
21void configure_hudson_uart(void)
22{
Zheng Bao22861382015-11-21 12:19:22 +080023 u8 byte;
24
Michał Żygowski287ce5f2019-12-01 17:41:23 +010025 byte = aoac_read8(FCH_AOAC_REG56 +
26 CONFIG_UART_FOR_CONSOLE * sizeof(u16)));
Zheng Bao22861382015-11-21 12:19:22 +080027 byte |= 1 << 3;
Michał Żygowski287ce5f2019-12-01 17:41:23 +010028 aoac_write8(FCH_AOAC_REG56 + CONFIG_UART_FOR_CONSOLE * sizeof(u16)),
29 byte);
30
31 aoac_write8(FCH_AOAC_REG62, aoac_read8(FCH_AOAC_REG62) | (1 << 3));
32 iomux_write8(0x89, 0); /* UART0_RTS_L_EGPIO137 */
33 iomux_write8(0x8a, 0); /* UART0_TXD_EGPIO138 */
34 iomux_write8(0x8e, 0); /* UART1_RTS_L_EGPIO142 */
35 iomux_write8(0x8f, 0); /* UART1_TXD_EGPIO143 */
Zheng Bao22861382015-11-21 12:19:22 +080036
37 udelay(2000);
Richard Spiegelbd48b232018-11-02 08:25:00 -070038 write8((void *)(0xFEDC6000 + 0x2000 * CONFIG_UART_FOR_CONSOLE + 0x88),
39 0x01); /* reset UART */
Zheng Bao22861382015-11-21 12:19:22 +080040}
41
42#endif
43
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030044void hudson_pci_port80(void)
45{
46 u8 byte;
Antonello Dettori1ac97282016-09-03 10:45:33 +020047 pci_devfn_t dev;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030048
49 /* P2P Bridge */
50 dev = PCI_DEV(0, 0x14, 4);
51
52 /* Chip Control: Enable subtractive decoding */
53 byte = pci_read_config8(dev, 0x40);
54 byte |= 1 << 5;
55 pci_write_config8(dev, 0x40, byte);
56
57 /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
58 byte = pci_read_config8(dev, 0x4B);
59 byte |= 1 << 7;
60 pci_write_config8(dev, 0x4B, byte);
61
62 /* The same IO Base and IO Limit here is meaningful because we set the
63 * bridge to be subtractive. During early setup stage, we have to make
64 * sure that data can go through port 0x80.
65 */
66 /* IO Base: 0xf000 */
67 byte = pci_read_config8(dev, 0x1C);
68 byte |= 0xF << 4;
69 pci_write_config8(dev, 0x1C, byte);
70
71 /* IO Limit: 0xf000 */
72 byte = pci_read_config8(dev, 0x1D);
73 byte |= 0xF << 4;
74 pci_write_config8(dev, 0x1D, byte);
75
76 /* PCI Command: Enable IO response */
77 byte = pci_read_config8(dev, 0x04);
78 byte |= 1 << 0;
79 pci_write_config8(dev, 0x04, byte);
80
81 /* LPC controller */
82 dev = PCI_DEV(0, 0x14, 3);
83
84 byte = pci_read_config8(dev, 0x4A);
85 byte &= ~(1 << 5); /* disable lpc port 80 */
86 pci_write_config8(dev, 0x4A, byte);
87}
88
89void hudson_lpc_port80(void)
90{
91 u8 byte;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030092
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030093 /* Enable port 80 LPC decode in pci function 3 configuration space. */
Elyes HAOUAS2f58a002020-04-22 16:07:39 +020094 const pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030095 byte = pci_read_config8(dev, 0x4a);
96 byte |= 1 << 5; /* enable port 80 */
97 pci_write_config8(dev, 0x4a, byte);
98}
99
Dave Frodinf364fc72015-03-13 08:22:17 -0600100void hudson_lpc_decode(void)
101{
Michał Żygowski8cee45c2019-11-23 18:03:46 +0100102 u32 tmp;
Dave Frodinf364fc72015-03-13 08:22:17 -0600103
Kyösti Mälkkia244d5e2019-12-09 08:08:58 +0200104 /* Enable LPC controller */
105 pm_write8(0xec, pm_read8(0xec) | 0x01);
106
Elyes HAOUAS2f58a002020-04-22 16:07:39 +0200107 const pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
Michał Żygowski8cee45c2019-11-23 18:03:46 +0100108 /* Serial port numeration on Hudson:
109 * PORT0 - 0x3f8
110 * PORT1 - 0x2f8
111 * PORT5 - 0x2e8
112 * PORT7 - 0x3e8
113 */
114 tmp = DECODE_ENABLE_SERIAL_PORT0 | DECODE_ENABLE_SERIAL_PORT1
115 | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT7;
Dave Frodinf364fc72015-03-13 08:22:17 -0600116
117 pci_write_config32(dev, LPC_IO_PORT_DECODE_ENABLE, tmp);
118}
119
Marc Jonesf962aa52017-03-22 18:47:49 +0800120static void enable_wideio(uint8_t port, uint16_t size)
121{
122 uint32_t wideio_enable[] = {
123 LPC_WIDEIO0_ENABLE,
124 LPC_WIDEIO1_ENABLE,
125 LPC_WIDEIO2_ENABLE
126 };
127 uint32_t alt_wideio_enable[] = {
128 LPC_ALT_WIDEIO0_ENABLE,
129 LPC_ALT_WIDEIO1_ENABLE,
130 LPC_ALT_WIDEIO2_ENABLE
131 };
Elyes HAOUAS2f58a002020-04-22 16:07:39 +0200132 const pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
Marc Jonesf962aa52017-03-22 18:47:49 +0800133 uint32_t tmp;
134
135 /* Only allow port 0-2 */
136 assert(port <= ARRAY_SIZE(wideio_enable));
137
138 if (size == 16) {
139 tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE);
140 tmp |= alt_wideio_enable[port];
141 pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp);
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200142 } else { /* 512 */
Marc Jonesf962aa52017-03-22 18:47:49 +0800143 tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE);
144 tmp &= ~alt_wideio_enable[port];
145 pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp);
146 }
147
148 /* Enable the range */
149 tmp = pci_read_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE);
150 tmp |= wideio_enable[port];
151 pci_write_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE, tmp);
152}
153
154/*
155 * lpc_wideio_window() may be called any point in romstage, but take
156 * care that AGESA doesn't overwrite the range this function used.
157 * The function checks if there is an empty range and if all ranges are
158 * used the function throws an assert. The function doesn't check for a
159 * duplicate range, for ranges that can be merged into a single
160 * range, or ranges that overlap.
161 *
162 * The developer is expected to ensure that there are no conflicts.
163 */
164static void lpc_wideio_window(uint16_t base, uint16_t size)
165{
Elyes HAOUAS2f58a002020-04-22 16:07:39 +0200166 const pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
Marc Jonesf962aa52017-03-22 18:47:49 +0800167 u32 tmp;
168
169 /* Support 512 or 16 bytes per range */
170 assert(size == 512 || size == 16);
171
172 /* Find and open Base Register and program it */
173 tmp = pci_read_config32(dev, LPC_WIDEIO_GENERIC_PORT);
174
175 if ((tmp & 0xFFFF) == 0) { /* WIDEIO0 */
176 tmp |= base;
177 pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp);
178 enable_wideio(0, size);
179 } else if ((tmp & 0xFFFF0000) == 0) { /* WIDEIO1 */
180 tmp |= (base << 16);
181 pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp);
182 enable_wideio(1, size);
183 } else { /* Check WIDEIO2 register */
184 tmp = pci_read_config32(dev, LPC_WIDEIO2_GENERIC_PORT);
185 if ((tmp & 0xFFFF) == 0) { /* WIDEIO2 */
186 tmp |= base;
187 pci_write_config32(dev, LPC_WIDEIO2_GENERIC_PORT, tmp);
188 enable_wideio(2, size);
189 } else { /* All WIDEIO locations used*/
190 assert(0);
191 }
192 }
193}
194
195void lpc_wideio_512_window(uint16_t base)
196{
197 assert(IS_ALIGNED(base, 512));
198 lpc_wideio_window(base, 512);
199}
200
201void lpc_wideio_16_window(uint16_t base)
202{
203 assert(IS_ALIGNED(base, 16));
204 lpc_wideio_window(base, 16);
205}
206
Piotr Króldcd2f172016-05-27 12:04:13 +0200207void hudson_clk_output_48Mhz(void)
208{
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600209 u32 ctrl;
Piotr Króldcd2f172016-05-27 12:04:13 +0200210
211 /*
212 * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so
213 * 48Mhz will be on ball AP13 (FT3b package)
214 */
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100215 ctrl = misc_read32(FCH_MISC_REG40);
Piotr Króldcd2f172016-05-27 12:04:13 +0200216
217 /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600218 ctrl &= (u32)~(1<<2);
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100219 misc_write32(FCH_MISC_REG40, ctrl);
Piotr Króldcd2f172016-05-27 12:04:13 +0200220}
221
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700222static uintptr_t hudson_spibase(void)
223{
224 /* Make sure the base address is predictable */
Elyes HAOUAS2f58a002020-04-22 16:07:39 +0200225 const pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700226
227 u32 base = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER)
228 & 0xfffffff0;
229 if (!base){
230 base = SPI_BASE_ADDRESS;
231 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, base
232 | SPI_ROM_ENABLE);
233 /* PCI_COMMAND_MEMORY is read-only and enabled. */
234 }
235 return (uintptr_t)base;
236}
237
238void hudson_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm)
239{
240 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700241 write16((void *)(base + SPI100_SPEED_CONFIG),
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700242 (norm << SPI_NORM_SPEED_NEW_SH) |
243 (fast << SPI_FAST_SPEED_NEW_SH) |
244 (alt << SPI_ALT_SPEED_NEW_SH) |
245 (tpm << SPI_TPM_SPEED_NEW_SH));
Richard Spiegelbd48b232018-11-02 08:25:00 -0700246 write16((void *)(base + SPI100_ENABLE), SPI_USE_SPI100);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700247}
248
249void hudson_disable_4dw_burst(void)
250{
251 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700252 write16((void *)(base + SPI100_HOST_PREF_CONFIG),
253 read16((void *)(base + SPI100_HOST_PREF_CONFIG))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700254 & ~SPI_RD4DW_EN_HOST);
255}
256
257/* Hudson 1-3 only. For Hudson 1, call with fast=1 */
258void hudson_set_readspeed(u16 norm, u16 fast)
259{
260 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700261 write16((void *)(base + SPI_CNTRL1),
262 (read16((void *)(base + SPI_CNTRL1))
263 & ~SPI_CNTRL1_SPEED_MASK)
264 | (norm << SPI_NORM_SPEED_SH)
265 | (fast << SPI_FAST_SPEED_SH));
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700266}
267
268void hudson_read_mode(u32 mode)
269{
270 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700271 write32((void *)(base + SPI_CNTRL0),
272 (read32((void *)(base + SPI_CNTRL0))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700273 & ~SPI_READ_MODE_MASK) | mode);
274}
275
Marc Jones6fcaaef2017-04-20 16:48:42 -0600276void hudson_tpm_decode_spi(void)
277{
Elyes HAOUAS2f58a002020-04-22 16:07:39 +0200278 const pci_devfn_t dev = PCI_DEV(0, 0x14, 3); /* LPC device */
Marc Jones6fcaaef2017-04-20 16:48:42 -0600279
280 u32 spibase = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER);
281 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, spibase
282 | ROUTE_TPM_2_SPI);
283}
284
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300285#endif