blob: 126a85c5daa72a10349fbca83f21316ad747669a [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03003
4#ifndef _HUDSON_EARLY_SETUP_C_
5#define _HUDSON_EARLY_SETUP_C_
6
Marc Jonesf962aa52017-03-22 18:47:49 +08007#include <assert.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03008#include <stdint.h>
Michał Żygowski287ce5f2019-12-01 17:41:23 +01009#include <amdblocks/acpimmio.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020010#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020011#include <device/pci_ops.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030012#include <console/console.h>
Kyösti Mälkkia244d5e2019-12-09 08:08:58 +020013#include <amdblocks/acpimmio.h>
Elyes HAOUASeb789f02018-10-27 16:40:25 +020014
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030015#include "hudson.h"
Dave Frodinf364fc72015-03-13 08:22:17 -060016#include "pci_devs.h"
Piotr Króldcd2f172016-05-27 12:04:13 +020017#include <Fch/Fch.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030018
Julius Wernercd49cce2019-03-05 16:53:33 -080019#if CONFIG(HUDSON_UART)
Zheng Bao22861382015-11-21 12:19:22 +080020
21#include <cpu/x86/msr.h>
22#include <delay.h>
Zheng Bao22861382015-11-21 12:19:22 +080023
24void configure_hudson_uart(void)
25{
Zheng Bao22861382015-11-21 12:19:22 +080026 u8 byte;
27
Michał Żygowski287ce5f2019-12-01 17:41:23 +010028 byte = aoac_read8(FCH_AOAC_REG56 +
29 CONFIG_UART_FOR_CONSOLE * sizeof(u16)));
Zheng Bao22861382015-11-21 12:19:22 +080030 byte |= 1 << 3;
Michał Żygowski287ce5f2019-12-01 17:41:23 +010031 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 Bao22861382015-11-21 12:19:22 +080039
40 udelay(2000);
Richard Spiegelbd48b232018-11-02 08:25:00 -070041 write8((void *)(0xFEDC6000 + 0x2000 * CONFIG_UART_FOR_CONSOLE + 0x88),
42 0x01); /* reset UART */
Zheng Bao22861382015-11-21 12:19:22 +080043}
44
45#endif
46
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030047void hudson_pci_port80(void)
48{
49 u8 byte;
Antonello Dettori1ac97282016-09-03 10:45:33 +020050 pci_devfn_t dev;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030051
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
92void hudson_lpc_port80(void)
93{
94 u8 byte;
Antonello Dettori1ac97282016-09-03 10:45:33 +020095 pci_devfn_t dev;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030096
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030097 /* Enable port 80 LPC decode in pci function 3 configuration space. */
98 dev = PCI_DEV(0, 0x14, 3);
99 byte = pci_read_config8(dev, 0x4a);
100 byte |= 1 << 5; /* enable port 80 */
101 pci_write_config8(dev, 0x4a, byte);
102}
103
Dave Frodinf364fc72015-03-13 08:22:17 -0600104void hudson_lpc_decode(void)
105{
Antonello Dettori1ac97282016-09-03 10:45:33 +0200106 pci_devfn_t dev;
Michał Żygowski8cee45c2019-11-23 18:03:46 +0100107 u32 tmp;
Dave Frodinf364fc72015-03-13 08:22:17 -0600108
Kyösti Mälkkia244d5e2019-12-09 08:08:58 +0200109 /* Enable LPC controller */
110 pm_write8(0xec, pm_read8(0xec) | 0x01);
111
Michał Żygowski8cee45c2019-11-23 18:03:46 +0100112 dev = PCI_DEV(0, 0x14, 3);
113 /* Serial port numeration on Hudson:
114 * PORT0 - 0x3f8
115 * PORT1 - 0x2f8
116 * PORT5 - 0x2e8
117 * PORT7 - 0x3e8
118 */
119 tmp = DECODE_ENABLE_SERIAL_PORT0 | DECODE_ENABLE_SERIAL_PORT1
120 | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT7;
Dave Frodinf364fc72015-03-13 08:22:17 -0600121
122 pci_write_config32(dev, LPC_IO_PORT_DECODE_ENABLE, tmp);
123}
124
Marc Jonesf962aa52017-03-22 18:47:49 +0800125static void enable_wideio(uint8_t port, uint16_t size)
126{
127 uint32_t wideio_enable[] = {
128 LPC_WIDEIO0_ENABLE,
129 LPC_WIDEIO1_ENABLE,
130 LPC_WIDEIO2_ENABLE
131 };
132 uint32_t alt_wideio_enable[] = {
133 LPC_ALT_WIDEIO0_ENABLE,
134 LPC_ALT_WIDEIO1_ENABLE,
135 LPC_ALT_WIDEIO2_ENABLE
136 };
137 pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
138 uint32_t tmp;
139
140 /* Only allow port 0-2 */
141 assert(port <= ARRAY_SIZE(wideio_enable));
142
143 if (size == 16) {
144 tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE);
145 tmp |= alt_wideio_enable[port];
146 pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp);
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200147 } else { /* 512 */
Marc Jonesf962aa52017-03-22 18:47:49 +0800148 tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE);
149 tmp &= ~alt_wideio_enable[port];
150 pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp);
151 }
152
153 /* Enable the range */
154 tmp = pci_read_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE);
155 tmp |= wideio_enable[port];
156 pci_write_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE, tmp);
157}
158
159/*
160 * lpc_wideio_window() may be called any point in romstage, but take
161 * care that AGESA doesn't overwrite the range this function used.
162 * The function checks if there is an empty range and if all ranges are
163 * used the function throws an assert. The function doesn't check for a
164 * duplicate range, for ranges that can be merged into a single
165 * range, or ranges that overlap.
166 *
167 * The developer is expected to ensure that there are no conflicts.
168 */
169static void lpc_wideio_window(uint16_t base, uint16_t size)
170{
171 pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
172 u32 tmp;
173
174 /* Support 512 or 16 bytes per range */
175 assert(size == 512 || size == 16);
176
177 /* Find and open Base Register and program it */
178 tmp = pci_read_config32(dev, LPC_WIDEIO_GENERIC_PORT);
179
180 if ((tmp & 0xFFFF) == 0) { /* WIDEIO0 */
181 tmp |= base;
182 pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp);
183 enable_wideio(0, size);
184 } else if ((tmp & 0xFFFF0000) == 0) { /* WIDEIO1 */
185 tmp |= (base << 16);
186 pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp);
187 enable_wideio(1, size);
188 } else { /* Check WIDEIO2 register */
189 tmp = pci_read_config32(dev, LPC_WIDEIO2_GENERIC_PORT);
190 if ((tmp & 0xFFFF) == 0) { /* WIDEIO2 */
191 tmp |= base;
192 pci_write_config32(dev, LPC_WIDEIO2_GENERIC_PORT, tmp);
193 enable_wideio(2, size);
194 } else { /* All WIDEIO locations used*/
195 assert(0);
196 }
197 }
198}
199
200void lpc_wideio_512_window(uint16_t base)
201{
202 assert(IS_ALIGNED(base, 512));
203 lpc_wideio_window(base, 512);
204}
205
206void lpc_wideio_16_window(uint16_t base)
207{
208 assert(IS_ALIGNED(base, 16));
209 lpc_wideio_window(base, 16);
210}
211
Piotr Króldcd2f172016-05-27 12:04:13 +0200212void hudson_clk_output_48Mhz(void)
213{
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600214 u32 ctrl;
Piotr Króldcd2f172016-05-27 12:04:13 +0200215
216 /*
217 * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so
218 * 48Mhz will be on ball AP13 (FT3b package)
219 */
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100220 ctrl = misc_read32(FCH_MISC_REG40);
Piotr Króldcd2f172016-05-27 12:04:13 +0200221
222 /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600223 ctrl &= (u32)~(1<<2);
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100224 misc_write32(FCH_MISC_REG40, ctrl);
Piotr Króldcd2f172016-05-27 12:04:13 +0200225}
226
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700227static uintptr_t hudson_spibase(void)
228{
229 /* Make sure the base address is predictable */
Elyes HAOUASd9ef5462018-05-19 17:08:23 +0200230 pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700231
232 u32 base = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER)
233 & 0xfffffff0;
234 if (!base){
235 base = SPI_BASE_ADDRESS;
236 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, base
237 | SPI_ROM_ENABLE);
238 /* PCI_COMMAND_MEMORY is read-only and enabled. */
239 }
240 return (uintptr_t)base;
241}
242
243void hudson_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm)
244{
245 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700246 write16((void *)(base + SPI100_SPEED_CONFIG),
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700247 (norm << SPI_NORM_SPEED_NEW_SH) |
248 (fast << SPI_FAST_SPEED_NEW_SH) |
249 (alt << SPI_ALT_SPEED_NEW_SH) |
250 (tpm << SPI_TPM_SPEED_NEW_SH));
Richard Spiegelbd48b232018-11-02 08:25:00 -0700251 write16((void *)(base + SPI100_ENABLE), SPI_USE_SPI100);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700252}
253
254void hudson_disable_4dw_burst(void)
255{
256 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700257 write16((void *)(base + SPI100_HOST_PREF_CONFIG),
258 read16((void *)(base + SPI100_HOST_PREF_CONFIG))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700259 & ~SPI_RD4DW_EN_HOST);
260}
261
262/* Hudson 1-3 only. For Hudson 1, call with fast=1 */
263void hudson_set_readspeed(u16 norm, u16 fast)
264{
265 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700266 write16((void *)(base + SPI_CNTRL1),
267 (read16((void *)(base + SPI_CNTRL1))
268 & ~SPI_CNTRL1_SPEED_MASK)
269 | (norm << SPI_NORM_SPEED_SH)
270 | (fast << SPI_FAST_SPEED_SH));
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700271}
272
273void hudson_read_mode(u32 mode)
274{
275 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700276 write32((void *)(base + SPI_CNTRL0),
277 (read32((void *)(base + SPI_CNTRL0))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700278 & ~SPI_READ_MODE_MASK) | mode);
279}
280
Marc Jones6fcaaef2017-04-20 16:48:42 -0600281void hudson_tpm_decode_spi(void)
282{
Elyes HAOUASd9ef5462018-05-19 17:08:23 +0200283 pci_devfn_t dev = PCI_DEV(0, 0x14, 3); /* LPC device */
Marc Jones6fcaaef2017-04-20 16:48:42 -0600284
285 u32 spibase = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER);
286 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, spibase
287 | ROUTE_TPM_2_SPI);
288}
289
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300290#endif