blob: 0e3646bb5c0d7f6cdbd4d8aae14331718649d7ff [file] [log] [blame]
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
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.
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030014 */
15
16#ifndef _HUDSON_EARLY_SETUP_C_
17#define _HUDSON_EARLY_SETUP_C_
18
Marc Jonesf962aa52017-03-22 18:47:49 +080019#include <assert.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030020#include <stdint.h>
21#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020022#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020023#include <device/pci_ops.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030024#include <console/console.h>
Kyösti Mälkkia244d5e2019-12-09 08:08:58 +020025#include <amdblocks/acpimmio.h>
Elyes HAOUASeb789f02018-10-27 16:40:25 +020026
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030027#include "hudson.h"
Dave Frodinf364fc72015-03-13 08:22:17 -060028#include "pci_devs.h"
Piotr Króldcd2f172016-05-27 12:04:13 +020029#include <Fch/Fch.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030030
Julius Wernercd49cce2019-03-05 16:53:33 -080031#if CONFIG(HUDSON_UART)
Zheng Bao22861382015-11-21 12:19:22 +080032
33#include <cpu/x86/msr.h>
34#include <delay.h>
Zheng Bao22861382015-11-21 12:19:22 +080035
36void configure_hudson_uart(void)
37{
Zheng Bao22861382015-11-21 12:19:22 +080038 u8 byte;
39
Richard Spiegelbd48b232018-11-02 08:25:00 -070040 byte = read8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG56 +
Marshall Dawson500d81a2018-12-05 17:30:44 -070041 CONFIG_UART_FOR_CONSOLE * sizeof(u16)));
Zheng Bao22861382015-11-21 12:19:22 +080042 byte |= 1 << 3;
Richard Spiegelbd48b232018-11-02 08:25:00 -070043 write8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG56 +
Marshall Dawson500d81a2018-12-05 17:30:44 -070044 CONFIG_UART_FOR_CONSOLE * sizeof(u16)), byte);
Richard Spiegelbd48b232018-11-02 08:25:00 -070045 byte = read8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG62));
Zheng Bao22861382015-11-21 12:19:22 +080046 byte |= 1 << 3;
Richard Spiegelbd48b232018-11-02 08:25:00 -070047 write8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG62), byte);
Zheng Bao22861382015-11-21 12:19:22 +080048 write8((void *)FCH_IOMUXx89_UART0_RTS_L_EGPIO137, 0);
49 write8((void *)FCH_IOMUXx8A_UART0_TXD_EGPIO138, 0);
50 write8((void *)FCH_IOMUXx8E_UART1_RTS_L_EGPIO142, 0);
51 write8((void *)FCH_IOMUXx8F_UART1_TXD_EGPIO143, 0);
52
53 udelay(2000);
Richard Spiegelbd48b232018-11-02 08:25:00 -070054 write8((void *)(0xFEDC6000 + 0x2000 * CONFIG_UART_FOR_CONSOLE + 0x88),
55 0x01); /* reset UART */
Zheng Bao22861382015-11-21 12:19:22 +080056}
57
58#endif
59
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030060void hudson_pci_port80(void)
61{
62 u8 byte;
Antonello Dettori1ac97282016-09-03 10:45:33 +020063 pci_devfn_t dev;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030064
65 /* P2P Bridge */
66 dev = PCI_DEV(0, 0x14, 4);
67
68 /* Chip Control: Enable subtractive decoding */
69 byte = pci_read_config8(dev, 0x40);
70 byte |= 1 << 5;
71 pci_write_config8(dev, 0x40, byte);
72
73 /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
74 byte = pci_read_config8(dev, 0x4B);
75 byte |= 1 << 7;
76 pci_write_config8(dev, 0x4B, byte);
77
78 /* The same IO Base and IO Limit here is meaningful because we set the
79 * bridge to be subtractive. During early setup stage, we have to make
80 * sure that data can go through port 0x80.
81 */
82 /* IO Base: 0xf000 */
83 byte = pci_read_config8(dev, 0x1C);
84 byte |= 0xF << 4;
85 pci_write_config8(dev, 0x1C, byte);
86
87 /* IO Limit: 0xf000 */
88 byte = pci_read_config8(dev, 0x1D);
89 byte |= 0xF << 4;
90 pci_write_config8(dev, 0x1D, byte);
91
92 /* PCI Command: Enable IO response */
93 byte = pci_read_config8(dev, 0x04);
94 byte |= 1 << 0;
95 pci_write_config8(dev, 0x04, byte);
96
97 /* LPC controller */
98 dev = PCI_DEV(0, 0x14, 3);
99
100 byte = pci_read_config8(dev, 0x4A);
101 byte &= ~(1 << 5); /* disable lpc port 80 */
102 pci_write_config8(dev, 0x4A, byte);
103}
104
105void hudson_lpc_port80(void)
106{
107 u8 byte;
Antonello Dettori1ac97282016-09-03 10:45:33 +0200108 pci_devfn_t dev;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300109
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300110 /* Enable port 80 LPC decode in pci function 3 configuration space. */
111 dev = PCI_DEV(0, 0x14, 3);
112 byte = pci_read_config8(dev, 0x4a);
113 byte |= 1 << 5; /* enable port 80 */
114 pci_write_config8(dev, 0x4a, byte);
115}
116
Dave Frodinf364fc72015-03-13 08:22:17 -0600117void hudson_lpc_decode(void)
118{
Antonello Dettori1ac97282016-09-03 10:45:33 +0200119 pci_devfn_t dev;
Michał Żygowski8cee45c2019-11-23 18:03:46 +0100120 u32 tmp;
Dave Frodinf364fc72015-03-13 08:22:17 -0600121
Kyösti Mälkkia244d5e2019-12-09 08:08:58 +0200122 /* Enable LPC controller */
123 pm_write8(0xec, pm_read8(0xec) | 0x01);
124
Michał Żygowski8cee45c2019-11-23 18:03:46 +0100125 dev = PCI_DEV(0, 0x14, 3);
126 /* Serial port numeration on Hudson:
127 * PORT0 - 0x3f8
128 * PORT1 - 0x2f8
129 * PORT5 - 0x2e8
130 * PORT7 - 0x3e8
131 */
132 tmp = DECODE_ENABLE_SERIAL_PORT0 | DECODE_ENABLE_SERIAL_PORT1
133 | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT7;
Dave Frodinf364fc72015-03-13 08:22:17 -0600134
135 pci_write_config32(dev, LPC_IO_PORT_DECODE_ENABLE, tmp);
136}
137
Marc Jonesf962aa52017-03-22 18:47:49 +0800138static void enable_wideio(uint8_t port, uint16_t size)
139{
140 uint32_t wideio_enable[] = {
141 LPC_WIDEIO0_ENABLE,
142 LPC_WIDEIO1_ENABLE,
143 LPC_WIDEIO2_ENABLE
144 };
145 uint32_t alt_wideio_enable[] = {
146 LPC_ALT_WIDEIO0_ENABLE,
147 LPC_ALT_WIDEIO1_ENABLE,
148 LPC_ALT_WIDEIO2_ENABLE
149 };
150 pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
151 uint32_t tmp;
152
153 /* Only allow port 0-2 */
154 assert(port <= ARRAY_SIZE(wideio_enable));
155
156 if (size == 16) {
157 tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE);
158 tmp |= alt_wideio_enable[port];
159 pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp);
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200160 } else { /* 512 */
Marc Jonesf962aa52017-03-22 18:47:49 +0800161 tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE);
162 tmp &= ~alt_wideio_enable[port];
163 pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp);
164 }
165
166 /* Enable the range */
167 tmp = pci_read_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE);
168 tmp |= wideio_enable[port];
169 pci_write_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE, tmp);
170}
171
172/*
173 * lpc_wideio_window() may be called any point in romstage, but take
174 * care that AGESA doesn't overwrite the range this function used.
175 * The function checks if there is an empty range and if all ranges are
176 * used the function throws an assert. The function doesn't check for a
177 * duplicate range, for ranges that can be merged into a single
178 * range, or ranges that overlap.
179 *
180 * The developer is expected to ensure that there are no conflicts.
181 */
182static void lpc_wideio_window(uint16_t base, uint16_t size)
183{
184 pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
185 u32 tmp;
186
187 /* Support 512 or 16 bytes per range */
188 assert(size == 512 || size == 16);
189
190 /* Find and open Base Register and program it */
191 tmp = pci_read_config32(dev, LPC_WIDEIO_GENERIC_PORT);
192
193 if ((tmp & 0xFFFF) == 0) { /* WIDEIO0 */
194 tmp |= base;
195 pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp);
196 enable_wideio(0, size);
197 } else if ((tmp & 0xFFFF0000) == 0) { /* WIDEIO1 */
198 tmp |= (base << 16);
199 pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp);
200 enable_wideio(1, size);
201 } else { /* Check WIDEIO2 register */
202 tmp = pci_read_config32(dev, LPC_WIDEIO2_GENERIC_PORT);
203 if ((tmp & 0xFFFF) == 0) { /* WIDEIO2 */
204 tmp |= base;
205 pci_write_config32(dev, LPC_WIDEIO2_GENERIC_PORT, tmp);
206 enable_wideio(2, size);
207 } else { /* All WIDEIO locations used*/
208 assert(0);
209 }
210 }
211}
212
213void lpc_wideio_512_window(uint16_t base)
214{
215 assert(IS_ALIGNED(base, 512));
216 lpc_wideio_window(base, 512);
217}
218
219void lpc_wideio_16_window(uint16_t base)
220{
221 assert(IS_ALIGNED(base, 16));
222 lpc_wideio_window(base, 16);
223}
224
Piotr Króldcd2f172016-05-27 12:04:13 +0200225void hudson_clk_output_48Mhz(void)
226{
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600227 u32 ctrl;
Piotr Króldcd2f172016-05-27 12:04:13 +0200228
229 /*
230 * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so
231 * 48Mhz will be on ball AP13 (FT3b package)
232 */
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600233 ctrl = read32((void *)(ACPI_MMIO_BASE + MISC_BASE + FCH_MISC_REG40));
Piotr Króldcd2f172016-05-27 12:04:13 +0200234
235 /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600236 ctrl &= (u32)~(1<<2);
237 write32((void *)(ACPI_MMIO_BASE + MISC_BASE + FCH_MISC_REG40), ctrl);
Piotr Króldcd2f172016-05-27 12:04:13 +0200238}
239
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700240static uintptr_t hudson_spibase(void)
241{
242 /* Make sure the base address is predictable */
Elyes HAOUASd9ef5462018-05-19 17:08:23 +0200243 pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700244
245 u32 base = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER)
246 & 0xfffffff0;
247 if (!base){
248 base = SPI_BASE_ADDRESS;
249 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, base
250 | SPI_ROM_ENABLE);
251 /* PCI_COMMAND_MEMORY is read-only and enabled. */
252 }
253 return (uintptr_t)base;
254}
255
256void hudson_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm)
257{
258 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700259 write16((void *)(base + SPI100_SPEED_CONFIG),
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700260 (norm << SPI_NORM_SPEED_NEW_SH) |
261 (fast << SPI_FAST_SPEED_NEW_SH) |
262 (alt << SPI_ALT_SPEED_NEW_SH) |
263 (tpm << SPI_TPM_SPEED_NEW_SH));
Richard Spiegelbd48b232018-11-02 08:25:00 -0700264 write16((void *)(base + SPI100_ENABLE), SPI_USE_SPI100);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700265}
266
267void hudson_disable_4dw_burst(void)
268{
269 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700270 write16((void *)(base + SPI100_HOST_PREF_CONFIG),
271 read16((void *)(base + SPI100_HOST_PREF_CONFIG))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700272 & ~SPI_RD4DW_EN_HOST);
273}
274
275/* Hudson 1-3 only. For Hudson 1, call with fast=1 */
276void hudson_set_readspeed(u16 norm, u16 fast)
277{
278 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700279 write16((void *)(base + SPI_CNTRL1),
280 (read16((void *)(base + SPI_CNTRL1))
281 & ~SPI_CNTRL1_SPEED_MASK)
282 | (norm << SPI_NORM_SPEED_SH)
283 | (fast << SPI_FAST_SPEED_SH));
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700284}
285
286void hudson_read_mode(u32 mode)
287{
288 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700289 write32((void *)(base + SPI_CNTRL0),
290 (read32((void *)(base + SPI_CNTRL0))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700291 & ~SPI_READ_MODE_MASK) | mode);
292}
293
Marc Jones6fcaaef2017-04-20 16:48:42 -0600294void hudson_tpm_decode_spi(void)
295{
Elyes HAOUASd9ef5462018-05-19 17:08:23 +0200296 pci_devfn_t dev = PCI_DEV(0, 0x14, 3); /* LPC device */
Marc Jones6fcaaef2017-04-20 16:48:42 -0600297
298 u32 spibase = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER);
299 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, spibase
300 | ROUTE_TPM_2_SPI);
301}
302
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300303#endif