blob: b214ade9770080da70e3356ff0f76ebd61870b17 [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;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030095
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030096 /* Enable port 80 LPC decode in pci function 3 configuration space. */
Elyes HAOUAS2f58a002020-04-22 16:07:39 +020097 const pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030098 byte = pci_read_config8(dev, 0x4a);
99 byte |= 1 << 5; /* enable port 80 */
100 pci_write_config8(dev, 0x4a, byte);
101}
102
Dave Frodinf364fc72015-03-13 08:22:17 -0600103void hudson_lpc_decode(void)
104{
Michał Żygowski8cee45c2019-11-23 18:03:46 +0100105 u32 tmp;
Dave Frodinf364fc72015-03-13 08:22:17 -0600106
Kyösti Mälkkia244d5e2019-12-09 08:08:58 +0200107 /* Enable LPC controller */
108 pm_write8(0xec, pm_read8(0xec) | 0x01);
109
Elyes HAOUAS2f58a002020-04-22 16:07:39 +0200110 const pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
Michał Żygowski8cee45c2019-11-23 18:03:46 +0100111 /* 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 Frodinf364fc72015-03-13 08:22:17 -0600119
120 pci_write_config32(dev, LPC_IO_PORT_DECODE_ENABLE, tmp);
121}
122
Marc Jonesf962aa52017-03-22 18:47:49 +0800123static 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 HAOUAS2f58a002020-04-22 16:07:39 +0200135 const pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
Marc Jonesf962aa52017-03-22 18:47:49 +0800136 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 HAOUASb0f19882018-06-09 11:59:00 +0200145 } else { /* 512 */
Marc Jonesf962aa52017-03-22 18:47:49 +0800146 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 */
167static void lpc_wideio_window(uint16_t base, uint16_t size)
168{
Elyes HAOUAS2f58a002020-04-22 16:07:39 +0200169 const pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
Marc Jonesf962aa52017-03-22 18:47:49 +0800170 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
198void lpc_wideio_512_window(uint16_t base)
199{
200 assert(IS_ALIGNED(base, 512));
201 lpc_wideio_window(base, 512);
202}
203
204void lpc_wideio_16_window(uint16_t base)
205{
206 assert(IS_ALIGNED(base, 16));
207 lpc_wideio_window(base, 16);
208}
209
Piotr Króldcd2f172016-05-27 12:04:13 +0200210void hudson_clk_output_48Mhz(void)
211{
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600212 u32 ctrl;
Piotr Króldcd2f172016-05-27 12:04:13 +0200213
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ł Żygowski287ce5f2019-12-01 17:41:23 +0100218 ctrl = misc_read32(FCH_MISC_REG40);
Piotr Króldcd2f172016-05-27 12:04:13 +0200219
220 /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600221 ctrl &= (u32)~(1<<2);
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100222 misc_write32(FCH_MISC_REG40, ctrl);
Piotr Króldcd2f172016-05-27 12:04:13 +0200223}
224
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700225static uintptr_t hudson_spibase(void)
226{
227 /* Make sure the base address is predictable */
Elyes HAOUAS2f58a002020-04-22 16:07:39 +0200228 const pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700229
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
241void hudson_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm)
242{
243 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700244 write16((void *)(base + SPI100_SPEED_CONFIG),
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700245 (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 Spiegelbd48b232018-11-02 08:25:00 -0700249 write16((void *)(base + SPI100_ENABLE), SPI_USE_SPI100);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700250}
251
252void hudson_disable_4dw_burst(void)
253{
254 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700255 write16((void *)(base + SPI100_HOST_PREF_CONFIG),
256 read16((void *)(base + SPI100_HOST_PREF_CONFIG))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700257 & ~SPI_RD4DW_EN_HOST);
258}
259
260/* Hudson 1-3 only. For Hudson 1, call with fast=1 */
261void hudson_set_readspeed(u16 norm, u16 fast)
262{
263 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700264 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 Dawson91dea4a2017-02-10 16:03:54 -0700269}
270
271void hudson_read_mode(u32 mode)
272{
273 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700274 write32((void *)(base + SPI_CNTRL0),
275 (read32((void *)(base + SPI_CNTRL0))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700276 & ~SPI_READ_MODE_MASK) | mode);
277}
278
Marc Jones6fcaaef2017-04-20 16:48:42 -0600279void hudson_tpm_decode_spi(void)
280{
Elyes HAOUAS2f58a002020-04-22 16:07:39 +0200281 const pci_devfn_t dev = PCI_DEV(0, 0x14, 3); /* LPC device */
Marc Jones6fcaaef2017-04-20 16:48:42 -0600282
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älkkie8b4da22014-10-21 18:22:32 +0300288#endif