blob: 0bed6ad17ecbfd7a49552e398b8be4bd2545c346 [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älkkif1b58b72019-03-01 13:43:02 +020022#include <device/pci_ops.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030023#include <arch/acpi.h>
24#include <console/console.h>
25#include <reset.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030026#include "hudson.h"
Dave Frodinf364fc72015-03-13 08:22:17 -060027#include "pci_devs.h"
Piotr Króldcd2f172016-05-27 12:04:13 +020028#include <Fch/Fch.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030029
Zheng Bao22861382015-11-21 12:19:22 +080030#if IS_ENABLED(CONFIG_HUDSON_UART)
31
32#include <cpu/x86/msr.h>
33#include <delay.h>
Zheng Bao22861382015-11-21 12:19:22 +080034
35void configure_hudson_uart(void)
36{
Zheng Bao22861382015-11-21 12:19:22 +080037 u8 byte;
38
Richard Spiegelbd48b232018-11-02 08:25:00 -070039 byte = read8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG56 +
Marshall Dawson500d81a2018-12-05 17:30:44 -070040 CONFIG_UART_FOR_CONSOLE * sizeof(u16)));
Zheng Bao22861382015-11-21 12:19:22 +080041 byte |= 1 << 3;
Richard Spiegelbd48b232018-11-02 08:25:00 -070042 write8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG56 +
Marshall Dawson500d81a2018-12-05 17:30:44 -070043 CONFIG_UART_FOR_CONSOLE * sizeof(u16)), byte);
Richard Spiegelbd48b232018-11-02 08:25:00 -070044 byte = read8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG62));
Zheng Bao22861382015-11-21 12:19:22 +080045 byte |= 1 << 3;
Richard Spiegelbd48b232018-11-02 08:25:00 -070046 write8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG62), byte);
Zheng Bao22861382015-11-21 12:19:22 +080047 write8((void *)FCH_IOMUXx89_UART0_RTS_L_EGPIO137, 0);
48 write8((void *)FCH_IOMUXx8A_UART0_TXD_EGPIO138, 0);
49 write8((void *)FCH_IOMUXx8E_UART1_RTS_L_EGPIO142, 0);
50 write8((void *)FCH_IOMUXx8F_UART1_TXD_EGPIO143, 0);
51
52 udelay(2000);
Richard Spiegelbd48b232018-11-02 08:25:00 -070053 write8((void *)(0xFEDC6000 + 0x2000 * CONFIG_UART_FOR_CONSOLE + 0x88),
54 0x01); /* reset UART */
Zheng Bao22861382015-11-21 12:19:22 +080055}
56
57#endif
58
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030059void hudson_pci_port80(void)
60{
61 u8 byte;
Antonello Dettori1ac97282016-09-03 10:45:33 +020062 pci_devfn_t dev;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030063
64 /* P2P Bridge */
65 dev = PCI_DEV(0, 0x14, 4);
66
67 /* Chip Control: Enable subtractive decoding */
68 byte = pci_read_config8(dev, 0x40);
69 byte |= 1 << 5;
70 pci_write_config8(dev, 0x40, byte);
71
72 /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
73 byte = pci_read_config8(dev, 0x4B);
74 byte |= 1 << 7;
75 pci_write_config8(dev, 0x4B, byte);
76
77 /* The same IO Base and IO Limit here is meaningful because we set the
78 * bridge to be subtractive. During early setup stage, we have to make
79 * sure that data can go through port 0x80.
80 */
81 /* IO Base: 0xf000 */
82 byte = pci_read_config8(dev, 0x1C);
83 byte |= 0xF << 4;
84 pci_write_config8(dev, 0x1C, byte);
85
86 /* IO Limit: 0xf000 */
87 byte = pci_read_config8(dev, 0x1D);
88 byte |= 0xF << 4;
89 pci_write_config8(dev, 0x1D, byte);
90
91 /* PCI Command: Enable IO response */
92 byte = pci_read_config8(dev, 0x04);
93 byte |= 1 << 0;
94 pci_write_config8(dev, 0x04, byte);
95
96 /* LPC controller */
97 dev = PCI_DEV(0, 0x14, 3);
98
99 byte = pci_read_config8(dev, 0x4A);
100 byte &= ~(1 << 5); /* disable lpc port 80 */
101 pci_write_config8(dev, 0x4A, byte);
102}
103
104void hudson_lpc_port80(void)
105{
106 u8 byte;
Antonello Dettori1ac97282016-09-03 10:45:33 +0200107 pci_devfn_t dev;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300108
109 /* Enable LPC controller */
110 outb(0xEC, 0xCD6);
111 byte = inb(0xCD7);
112 byte |= 1;
113 outb(0xEC, 0xCD6);
114 outb(byte, 0xCD7);
115
116 /* Enable port 80 LPC decode in pci function 3 configuration space. */
117 dev = PCI_DEV(0, 0x14, 3);
118 byte = pci_read_config8(dev, 0x4a);
119 byte |= 1 << 5; /* enable port 80 */
120 pci_write_config8(dev, 0x4a, byte);
121}
122
Dave Frodinf364fc72015-03-13 08:22:17 -0600123void hudson_lpc_decode(void)
124{
Antonello Dettori1ac97282016-09-03 10:45:33 +0200125 pci_devfn_t dev;
Dave Frodinf364fc72015-03-13 08:22:17 -0600126 u32 tmp = 0;
127
128 /* Enable I/O decode to LPC bus */
129 dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
130 tmp = DECODE_ENABLE_PARALLEL_PORT0 | DECODE_ENABLE_PARALLEL_PORT2
131 | DECODE_ENABLE_PARALLEL_PORT4 | DECODE_ENABLE_SERIAL_PORT0
132 | DECODE_ENABLE_SERIAL_PORT1 | DECODE_ENABLE_SERIAL_PORT2
133 | DECODE_ENABLE_SERIAL_PORT3 | DECODE_ENABLE_SERIAL_PORT4
134 | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT6
135 | DECODE_ENABLE_SERIAL_PORT7 | DECODE_ENABLE_AUDIO_PORT0
136 | DECODE_ENABLE_AUDIO_PORT1 | DECODE_ENABLE_AUDIO_PORT2
137 | DECODE_ENABLE_AUDIO_PORT3 | DECODE_ENABLE_MSS_PORT2
138 | DECODE_ENABLE_MSS_PORT3 | DECODE_ENABLE_FDC_PORT0
139 | DECODE_ENABLE_FDC_PORT1 | DECODE_ENABLE_GAME_PORT
140 | DECODE_ENABLE_KBC_PORT | DECODE_ENABLE_ACPIUC_PORT
141 | DECODE_ENABLE_ADLIB_PORT;
142
143 pci_write_config32(dev, LPC_IO_PORT_DECODE_ENABLE, tmp);
144}
145
Marc Jonesf962aa52017-03-22 18:47:49 +0800146static void enable_wideio(uint8_t port, uint16_t size)
147{
148 uint32_t wideio_enable[] = {
149 LPC_WIDEIO0_ENABLE,
150 LPC_WIDEIO1_ENABLE,
151 LPC_WIDEIO2_ENABLE
152 };
153 uint32_t alt_wideio_enable[] = {
154 LPC_ALT_WIDEIO0_ENABLE,
155 LPC_ALT_WIDEIO1_ENABLE,
156 LPC_ALT_WIDEIO2_ENABLE
157 };
158 pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
159 uint32_t tmp;
160
161 /* Only allow port 0-2 */
162 assert(port <= ARRAY_SIZE(wideio_enable));
163
164 if (size == 16) {
165 tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE);
166 tmp |= alt_wideio_enable[port];
167 pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp);
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200168 } else { /* 512 */
Marc Jonesf962aa52017-03-22 18:47:49 +0800169 tmp = pci_read_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE);
170 tmp &= ~alt_wideio_enable[port];
171 pci_write_config32(dev, LPC_ALT_WIDEIO_RANGE_ENABLE, tmp);
172 }
173
174 /* Enable the range */
175 tmp = pci_read_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE);
176 tmp |= wideio_enable[port];
177 pci_write_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE, tmp);
178}
179
180/*
181 * lpc_wideio_window() may be called any point in romstage, but take
182 * care that AGESA doesn't overwrite the range this function used.
183 * The function checks if there is an empty range and if all ranges are
184 * used the function throws an assert. The function doesn't check for a
185 * duplicate range, for ranges that can be merged into a single
186 * range, or ranges that overlap.
187 *
188 * The developer is expected to ensure that there are no conflicts.
189 */
190static void lpc_wideio_window(uint16_t base, uint16_t size)
191{
192 pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
193 u32 tmp;
194
195 /* Support 512 or 16 bytes per range */
196 assert(size == 512 || size == 16);
197
198 /* Find and open Base Register and program it */
199 tmp = pci_read_config32(dev, LPC_WIDEIO_GENERIC_PORT);
200
201 if ((tmp & 0xFFFF) == 0) { /* WIDEIO0 */
202 tmp |= base;
203 pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp);
204 enable_wideio(0, size);
205 } else if ((tmp & 0xFFFF0000) == 0) { /* WIDEIO1 */
206 tmp |= (base << 16);
207 pci_write_config32(dev, LPC_WIDEIO_GENERIC_PORT, tmp);
208 enable_wideio(1, size);
209 } else { /* Check WIDEIO2 register */
210 tmp = pci_read_config32(dev, LPC_WIDEIO2_GENERIC_PORT);
211 if ((tmp & 0xFFFF) == 0) { /* WIDEIO2 */
212 tmp |= base;
213 pci_write_config32(dev, LPC_WIDEIO2_GENERIC_PORT, tmp);
214 enable_wideio(2, size);
215 } else { /* All WIDEIO locations used*/
216 assert(0);
217 }
218 }
219}
220
221void lpc_wideio_512_window(uint16_t base)
222{
223 assert(IS_ALIGNED(base, 512));
224 lpc_wideio_window(base, 512);
225}
226
227void lpc_wideio_16_window(uint16_t base)
228{
229 assert(IS_ALIGNED(base, 16));
230 lpc_wideio_window(base, 16);
231}
232
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300233int s3_save_nvram_early(u32 dword, int size, int nvram_pos)
234{
235 int i;
236 printk(BIOS_DEBUG, "Writing %x of size %d to nvram pos: %d\n", dword, size, nvram_pos);
237
Elyes HAOUASc021ffe2016-09-18 19:18:56 +0200238 for (i = 0; i < size; i++) {
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300239 outb(nvram_pos, BIOSRAM_INDEX);
Elyes HAOUASa342f392018-10-17 10:56:26 +0200240 outb((dword >> (8 * i)) & 0xff, BIOSRAM_DATA);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300241 nvram_pos++;
242 }
243
244 return nvram_pos;
245}
246
247int s3_load_nvram_early(int size, u32 *old_dword, int nvram_pos)
248{
249 u32 data = *old_dword;
250 int i;
Elyes HAOUASc021ffe2016-09-18 19:18:56 +0200251 for (i = 0; i < size; i++) {
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300252 outb(nvram_pos, BIOSRAM_INDEX);
253 data &= ~(0xff << (i * 8));
254 data |= inb(BIOSRAM_DATA) << (i *8);
255 nvram_pos++;
256 }
257 *old_dword = data;
258 printk(BIOS_DEBUG, "Loading %x of size %d to nvram pos:%d\n", *old_dword, size,
259 nvram_pos-size);
260 return nvram_pos;
261}
262
Piotr Króldcd2f172016-05-27 12:04:13 +0200263void hudson_clk_output_48Mhz(void)
264{
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600265 u32 ctrl;
Piotr Króldcd2f172016-05-27 12:04:13 +0200266
267 /*
268 * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so
269 * 48Mhz will be on ball AP13 (FT3b package)
270 */
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600271 ctrl = read32((void *)(ACPI_MMIO_BASE + MISC_BASE + FCH_MISC_REG40));
Piotr Króldcd2f172016-05-27 12:04:13 +0200272
273 /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */
Marshall Dawson0bf3f552017-07-13 12:06:25 -0600274 ctrl &= (u32)~(1<<2);
275 write32((void *)(ACPI_MMIO_BASE + MISC_BASE + FCH_MISC_REG40), ctrl);
Piotr Króldcd2f172016-05-27 12:04:13 +0200276}
277
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700278static uintptr_t hudson_spibase(void)
279{
280 /* Make sure the base address is predictable */
Elyes HAOUASd9ef5462018-05-19 17:08:23 +0200281 pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700282
283 u32 base = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER)
284 & 0xfffffff0;
285 if (!base){
286 base = SPI_BASE_ADDRESS;
287 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, base
288 | SPI_ROM_ENABLE);
289 /* PCI_COMMAND_MEMORY is read-only and enabled. */
290 }
291 return (uintptr_t)base;
292}
293
294void hudson_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm)
295{
296 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700297 write16((void *)(base + SPI100_SPEED_CONFIG),
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700298 (norm << SPI_NORM_SPEED_NEW_SH) |
299 (fast << SPI_FAST_SPEED_NEW_SH) |
300 (alt << SPI_ALT_SPEED_NEW_SH) |
301 (tpm << SPI_TPM_SPEED_NEW_SH));
Richard Spiegelbd48b232018-11-02 08:25:00 -0700302 write16((void *)(base + SPI100_ENABLE), SPI_USE_SPI100);
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700303}
304
305void hudson_disable_4dw_burst(void)
306{
307 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700308 write16((void *)(base + SPI100_HOST_PREF_CONFIG),
309 read16((void *)(base + SPI100_HOST_PREF_CONFIG))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700310 & ~SPI_RD4DW_EN_HOST);
311}
312
313/* Hudson 1-3 only. For Hudson 1, call with fast=1 */
314void hudson_set_readspeed(u16 norm, u16 fast)
315{
316 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700317 write16((void *)(base + SPI_CNTRL1),
318 (read16((void *)(base + SPI_CNTRL1))
319 & ~SPI_CNTRL1_SPEED_MASK)
320 | (norm << SPI_NORM_SPEED_SH)
321 | (fast << SPI_FAST_SPEED_SH));
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700322}
323
324void hudson_read_mode(u32 mode)
325{
326 uintptr_t base = hudson_spibase();
Richard Spiegelbd48b232018-11-02 08:25:00 -0700327 write32((void *)(base + SPI_CNTRL0),
328 (read32((void *)(base + SPI_CNTRL0))
Marshall Dawson91dea4a2017-02-10 16:03:54 -0700329 & ~SPI_READ_MODE_MASK) | mode);
330}
331
Marc Jones6fcaaef2017-04-20 16:48:42 -0600332void hudson_tpm_decode_spi(void)
333{
Elyes HAOUASd9ef5462018-05-19 17:08:23 +0200334 pci_devfn_t dev = PCI_DEV(0, 0x14, 3); /* LPC device */
Marc Jones6fcaaef2017-04-20 16:48:42 -0600335
336 u32 spibase = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER);
337 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, spibase
338 | ROUTE_TPM_2_SPI);
339}
340
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300341#endif