blob: b4dcd8f7f5d14c2f9cef69a79db101109e6211f9 [file] [log] [blame]
Marc Jones24484842017-05-04 21:17:45 -06001/*
2 * This file is part of the coreboot project.
3 *
Richard Spiegel376dc822017-12-01 08:24:26 -07004 * Copyright (C) 2010-2017 Advanced Micro Devices, Inc.
Marc Jones24484842017-05-04 21:17:45 -06005 *
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.
14 */
15
16#include <console/console.h>
17
18#include <arch/io.h>
Marshall Dawson8a906df2017-06-13 14:19:02 -060019#include <bootstate.h>
Marshall Dawsone9b862e2017-09-22 15:14:46 -060020#include <cpu/x86/smm.h>
Marc Jones24484842017-05-04 21:17:45 -060021#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
24#include <device/pci_ops.h>
25#include <cbmem.h>
Richard Spiegel2bbc3dc2017-12-06 16:14:58 -070026#include <amdblocks/amd_pci_util.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060027#include <soc/southbridge.h>
Marc Jones24484842017-05-04 21:17:45 -060028#include <soc/smi.h>
Richard Spiegel376dc822017-12-01 08:24:26 -070029#include <soc/amd_pci_int_defs.h>
Marc Jones24484842017-05-04 21:17:45 -060030#include <fchec.h>
Richard Spiegelbec44f22017-11-24 07:41:29 -070031#include <delay.h>
32#include <soc/pci_devs.h>
Marshall Dawson2942db62017-12-14 10:00:27 -070033#include <agesa_headers.h>
34
Richard Spiegel0e0e93c2018-03-13 10:19:51 -070035/*
36 * Table of devices that need their AOAC registers enabled and waited
37 * upon (usually about .55 milliseconds). Instead of individual delays
38 * waiting for each device to become available, a single delay will be
39 * executed at configure_stoneyridge_uart(). All other devices need only
40 * to verify if their AOAC is already enabled, and do a minimal delay
41 * if needed.
42 */
43const static struct stoneyridge_aoac aoac_devs[] = {
44 { (FCH_AOAC_D3_CONTROL_UART0 + CONFIG_UART_FOR_CONSOLE * 2),
45 (FCH_AOAC_D3_STATE_UART0 + CONFIG_UART_FOR_CONSOLE * 2) },
46 { FCH_AOAC_D3_CONTROL_AMBA, FCH_AOAC_D3_STATE_AMBA },
47 { FCH_AOAC_D3_CONTROL_I2C0, FCH_AOAC_D3_STATE_I2C0 },
48 { FCH_AOAC_D3_CONTROL_I2C1, FCH_AOAC_D3_STATE_I2C1 },
49 { FCH_AOAC_D3_CONTROL_I2C2, FCH_AOAC_D3_STATE_I2C2 },
50 { FCH_AOAC_D3_CONTROL_I2C3, FCH_AOAC_D3_STATE_I2C3 }
51};
52
Marshall Dawson2942db62017-12-14 10:00:27 -070053static int is_sata_config(void)
54{
55 return !((CONFIG_STONEYRIDGE_SATA_MODE == SataNativeIde)
56 || (CONFIG_STONEYRIDGE_SATA_MODE == SataLegacyIde));
57}
58
Richard Spiegel7ea8e022018-01-16 14:40:10 -070059static inline int sb_sata_enable(void)
60{
61 /* True if IDE or AHCI. */
62 return (CONFIG_STONEYRIDGE_SATA_MODE == SataNativeIde) ||
63 (CONFIG_STONEYRIDGE_SATA_MODE == SataAhci);
64}
65
66static inline int sb_ide_enable(void)
67{
68 /* True if IDE or LEGACY IDE. */
69 return (CONFIG_STONEYRIDGE_SATA_MODE == SataNativeIde) ||
70 (CONFIG_STONEYRIDGE_SATA_MODE == SataLegacyIde);
71}
72
Marshall Dawson2942db62017-12-14 10:00:27 -070073void SetFchResetParams(FCH_RESET_INTERFACE *params)
74{
75 params->Xhci0Enable = IS_ENABLED(CONFIG_STONEYRIDGE_XHCI_ENABLE);
Richard Spiegela318d282018-01-16 13:25:40 -070076 params->SataEnable = sb_sata_enable();
77 params->IdeEnable = sb_ide_enable();
Marshall Dawson2942db62017-12-14 10:00:27 -070078}
79
80void SetFchEnvParams(FCH_INTERFACE *params)
81{
82 params->AzaliaController = AzEnable;
83 params->SataClass = CONFIG_STONEYRIDGE_SATA_MODE;
84 params->SataEnable = is_sata_config();
85 params->IdeEnable = !params->SataEnable;
86 params->SataIdeMode = (CONFIG_STONEYRIDGE_SATA_MODE == SataLegacyIde);
87}
88
89void SetFchMidParams(FCH_INTERFACE *params)
90{
91 SetFchEnvParams(params);
92}
Marc Jones24484842017-05-04 21:17:45 -060093
Richard Spiegel376dc822017-12-01 08:24:26 -070094/*
95 * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010096 * provides a visible association with the index, therefore helping
Richard Spiegel376dc822017-12-01 08:24:26 -070097 * maintainability of table. If a new index/name is defined in
98 * amd_pci_int_defs.h, just add the pair at the end of this table.
99 * Order is not important.
100 */
101const static struct irq_idx_name irq_association[] = {
Richard Spiegele89d4442017-12-08 07:52:42 -0700102 { PIRQ_A, "INTA#" },
103 { PIRQ_B, "INTB#" },
104 { PIRQ_C, "INTC#" },
105 { PIRQ_D, "INTD#" },
106 { PIRQ_E, "INTE#" },
107 { PIRQ_F, "INTF#" },
108 { PIRQ_G, "INTG#" },
109 { PIRQ_H, "INTH#" },
110 { PIRQ_MISC, "Misc" },
111 { PIRQ_MISC0, "Misc0" },
112 { PIRQ_MISC1, "Misc1" },
113 { PIRQ_MISC2, "Misc2" },
Richard Spiegel376dc822017-12-01 08:24:26 -0700114 { PIRQ_SIRQA, "Ser IRQ INTA" },
115 { PIRQ_SIRQB, "Ser IRQ INTB" },
116 { PIRQ_SIRQC, "Ser IRQ INTC" },
117 { PIRQ_SIRQD, "Ser IRQ INTD" },
Richard Spiegele89d4442017-12-08 07:52:42 -0700118 { PIRQ_SCI, "SCI" },
119 { PIRQ_SMBUS, "SMBUS" },
120 { PIRQ_ASF, "ASF" },
121 { PIRQ_HDA, "HDA" },
122 { PIRQ_FC, "FC" },
123 { PIRQ_PMON, "PerMon" },
124 { PIRQ_SD, "SD" },
125 { PIRQ_SDIO, "SDIOt" },
126 { PIRQ_IMC0, "IMC INT0" },
127 { PIRQ_IMC1, "IMC INT1" },
128 { PIRQ_IMC2, "IMC INT2" },
129 { PIRQ_IMC3, "IMC INT3" },
130 { PIRQ_IMC4, "IMC INT4" },
131 { PIRQ_IMC5, "IMC INT5" },
132 { PIRQ_EHCI, "EHCI" },
133 { PIRQ_XHCI, "XHCI" },
134 { PIRQ_SATA, "SATA" },
135 { PIRQ_GPIO, "GPIO" },
136 { PIRQ_I2C0, "I2C0" },
137 { PIRQ_I2C1, "I2C1" },
138 { PIRQ_I2C2, "I2C2" },
139 { PIRQ_I2C3, "I2C3" },
140 { PIRQ_UART0, "UART0" },
141 { PIRQ_UART1, "UART1" },
Richard Spiegel376dc822017-12-01 08:24:26 -0700142};
143
Richard Spiegelebf3aa82017-11-24 07:47:42 -0700144/*
145 * Structure to simplify code obtaining the total of used wide IO
146 * registers and the size assigned to each.
147 */
148static struct wide_io_ioport_and_bits {
149 uint32_t enable;
150 uint16_t port;
151 uint8_t alt;
152} wio_io_en[TOTAL_WIDEIO_PORTS] = {
153 {
154 LPC_WIDEIO0_ENABLE,
155 LPC_WIDEIO_GENERIC_PORT,
156 LPC_ALT_WIDEIO0_ENABLE
157 },
158 {
159 LPC_WIDEIO1_ENABLE,
160 LPC_WIDEIO1_GENERIC_PORT,
161 LPC_ALT_WIDEIO1_ENABLE
162 },
163 {
164 LPC_WIDEIO2_ENABLE,
165 LPC_WIDEIO2_GENERIC_PORT,
166 LPC_ALT_WIDEIO2_ENABLE
167 }
168};
169
Richard Spiegel376dc822017-12-01 08:24:26 -0700170const struct irq_idx_name *sb_get_apic_reg_association(size_t *size)
171{
172 *size = ARRAY_SIZE(irq_association);
173 return irq_association;
174}
175
Justin TerAvest3fe3f042018-02-14 19:10:15 -0700176void sb_program_gpios(const struct soc_amd_stoneyridge_gpio *gpio_ptr,
177 size_t size)
Richard Spiegele539c852017-12-25 18:25:58 -0700178{
179 void *tmp_ptr;
Richard Spiegele539c852017-12-25 18:25:58 -0700180 uint8_t control, mux, index;
181
Richard Spiegele539c852017-12-25 18:25:58 -0700182 for (index = 0; index < size; index++) {
183 mux = gpio_ptr[index].function;
184 control = gpio_ptr[index].control;
185 tmp_ptr = (void *)(gpio_ptr[index].gpio + AMD_GPIO_MUX);
186 write8(tmp_ptr, mux & AMD_GPIO_MUX_MASK);
187
188 /*
189 * Get the address of AMD_GPIO_CONTROL (dword) relative
190 * to the desired pin and program bits 16-23.
191 */
192 tmp_ptr = (void *)(gpio_ptr[index].gpio * sizeof(uint32_t) +
193 AMD_GPIO_CONTROL + 2);
194 write8(tmp_ptr, control);
195 }
Richard Spiegele539c852017-12-25 18:25:58 -0700196}
197
Richard Spiegelebf3aa82017-11-24 07:47:42 -0700198/**
199 * @brief Find the size of a particular wide IO
200 *
201 * @param index = index of desired wide IO
202 *
203 * @return size of desired wide IO
204 */
205uint16_t sb_wideio_size(int index)
206{
207 uint32_t enable_register;
208 uint16_t size = 0;
209 uint8_t alternate_register;
210
211 if (index >= TOTAL_WIDEIO_PORTS)
212 return size;
213 enable_register = pci_read_config32(SOC_LPC_DEV,
214 LPC_IO_OR_MEM_DECODE_ENABLE);
215 alternate_register = pci_read_config8(SOC_LPC_DEV,
216 LPC_ALT_WIDEIO_RANGE_ENABLE);
217 if (enable_register & wio_io_en[index].enable)
218 size = (alternate_register & wio_io_en[index].alt) ?
219 16 : 512;
220 return size;
221}
222
223/**
224 * @brief Identify if any LPC wide IO is covering the IO range
225 *
226 * @param start = start of IO range
227 * @param size = size of IO range
228 *
229 * @return Index of wide IO covering the range or error
230 */
231int sb_find_wideio_range(uint16_t start, uint16_t size)
232{
233 uint32_t enable_register;
234 int i, index = WIDEIO_RANGE_ERROR;
235 uint16_t end, current_size, start_wideio, end_wideio;
236
237 end = start + size;
238 enable_register = pci_read_config32(SOC_LPC_DEV,
239 LPC_IO_OR_MEM_DECODE_ENABLE);
240 for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) {
241 current_size = sb_wideio_size(i);
242 if (current_size == 0)
243 continue;
244 start_wideio = pci_read_config16(SOC_LPC_DEV,
245 wio_io_en[i].port);
246 end_wideio = start_wideio + current_size;
247 if ((start >= start_wideio) && (end <= end_wideio)) {
248 index = i;
249 break;
250 }
251 }
252 return index;
253}
254
255/**
256 * @brief Program a LPC wide IO to support an IO range
257 *
258 * @param start = start of range to be routed through wide IO
259 * @param size = size of range to be routed through wide IO
260 *
261 * @return Index of wide IO register used or error
262 */
263int sb_set_wideio_range(uint16_t start, uint16_t size)
264{
265 int i, index = WIDEIO_RANGE_ERROR;
266 uint32_t enable_register;
267 uint8_t alternate_register;
268
269 enable_register = pci_read_config32(SOC_LPC_DEV,
270 LPC_IO_OR_MEM_DECODE_ENABLE);
271 alternate_register = pci_read_config8(SOC_LPC_DEV,
272 LPC_ALT_WIDEIO_RANGE_ENABLE);
273 for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) {
274 if (enable_register & wio_io_en[i].enable)
275 continue;
276 index = i;
277 pci_write_config16(SOC_LPC_DEV, wio_io_en[i].port, start);
278 enable_register |= wio_io_en[i].enable;
279 pci_write_config32(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE,
280 enable_register);
281 if (size <= 16)
282 alternate_register |= wio_io_en[i].alt;
283 else
284 alternate_register &= ~wio_io_en[i].alt;
285 pci_write_config8(SOC_LPC_DEV,
286 LPC_ALT_WIDEIO_RANGE_ENABLE,
287 alternate_register);
288 break;
289 }
290 return index;
291}
292
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600293static void power_on_aoac_device(int aoac_device_control_register)
Richard Spiegelbec44f22017-11-24 07:41:29 -0700294{
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600295 uint8_t byte;
296 uint8_t *register_pointer = (uint8_t *)(uintptr_t)AOAC_MMIO_BASE
297 + aoac_device_control_register;
Richard Spiegelbec44f22017-11-24 07:41:29 -0700298
299 /* Power on the UART and AMBA devices */
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600300 byte = read8(register_pointer);
301 byte |= FCH_AOAC_PWR_ON_DEV;
302 write8(register_pointer, byte);
303}
Richard Spiegelbec44f22017-11-24 07:41:29 -0700304
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600305static bool is_aoac_device_enabled(int aoac_device_status_register)
306{
307 uint8_t byte;
308 byte = read8((uint8_t *)(uintptr_t)AOAC_MMIO_BASE
309 + aoac_device_status_register);
310 byte &= (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE);
311 if (byte == (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE))
312 return true;
313 else
314 return false;
315}
316
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700317void enable_aoac_devices(void)
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600318{
319 bool status;
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700320 int i;
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600321
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700322 for (i = 0; i < ARRAY_SIZE(aoac_devs); i++)
323 power_on_aoac_device(aoac_devs[i].enable);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700324
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700325 /* Wait for AOAC devices to indicate power and clock OK */
326 do {
327 udelay(100);
328 status = true;
329 for (i = 0; i < ARRAY_SIZE(aoac_devs); i++)
330 status &= is_aoac_device_enabled(aoac_devs[i].status);
331 } while (!status);
332}
333
334void configure_stoneyridge_uart(void)
335{
Richard Spiegelbec44f22017-11-24 07:41:29 -0700336 /* Set the GPIO mux to UART */
337 write8((void *)FCH_IOMUXx89_UART0_RTS_L_EGPIO137, 0);
338 write8((void *)FCH_IOMUXx8A_UART0_TXD_EGPIO138, 0);
339 write8((void *)FCH_IOMUXx8E_UART1_RTS_L_EGPIO142, 0);
340 write8((void *)FCH_IOMUXx8F_UART1_TXD_EGPIO143, 0);
Garrett Kirkendall8da81da2018-03-07 09:00:05 -0600341}
342
Richard Spiegelbec44f22017-11-24 07:41:29 -0700343void sb_pci_port80(void)
344{
345 u8 byte;
346
347 byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH);
348 byte &= ~DECODE_IO_PORT_ENABLE4_H; /* disable lpc port 80 */
349 pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte);
350}
351
352void sb_lpc_port80(void)
353{
354 u8 byte;
355
356 /* Enable LPC controller */
357 outb(PM_LPC_GATING, PM_INDEX);
358 byte = inb(PM_DATA);
359 byte |= PM_LPC_ENABLE;
360 outb(PM_LPC_GATING, PM_INDEX);
361 outb(byte, PM_DATA);
362
363 /* Enable port 80 LPC decode in pci function 3 configuration space. */
364 byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH);
365 byte |= DECODE_IO_PORT_ENABLE4_H; /* enable port 80 */
366 pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte);
367}
368
369void sb_lpc_decode(void)
370{
371 u32 tmp = 0;
372
373 /* Enable I/O decode to LPC bus */
374 tmp = DECODE_ENABLE_PARALLEL_PORT0 | DECODE_ENABLE_PARALLEL_PORT2
375 | DECODE_ENABLE_PARALLEL_PORT4 | DECODE_ENABLE_SERIAL_PORT0
376 | DECODE_ENABLE_SERIAL_PORT1 | DECODE_ENABLE_SERIAL_PORT2
377 | DECODE_ENABLE_SERIAL_PORT3 | DECODE_ENABLE_SERIAL_PORT4
378 | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT6
379 | DECODE_ENABLE_SERIAL_PORT7 | DECODE_ENABLE_AUDIO_PORT0
380 | DECODE_ENABLE_AUDIO_PORT1 | DECODE_ENABLE_AUDIO_PORT2
381 | DECODE_ENABLE_AUDIO_PORT3 | DECODE_ENABLE_MSS_PORT2
382 | DECODE_ENABLE_MSS_PORT3 | DECODE_ENABLE_FDC_PORT0
383 | DECODE_ENABLE_FDC_PORT1 | DECODE_ENABLE_GAME_PORT
384 | DECODE_ENABLE_KBC_PORT | DECODE_ENABLE_ACPIUC_PORT
385 | DECODE_ENABLE_ADLIB_PORT;
386
387 pci_write_config32(SOC_LPC_DEV, LPC_IO_PORT_DECODE_ENABLE, tmp);
388}
389
Garrett Kirkendall9858bd22018-03-07 15:38:14 -0600390void sb_acpi_mmio_decode(void)
391{
392 uint8_t byte;
393
394 /* Enable ACPI MMIO range 0xfed80000 - 0xfed81fff */
395 outb(PM_ISA_CONTROL, PM_INDEX);
396 byte = inb(PM_DATA);
397 byte |= MMIO_EN;
398 outb(PM_ISA_CONTROL, PM_INDEX);
399 outb(byte, PM_DATA);
400}
401
Richard Spiegelbec44f22017-11-24 07:41:29 -0700402void sb_clk_output_48Mhz(void)
403{
404 u32 ctrl;
Garrett Kirkendalld2558302018-03-06 09:05:20 -0600405 u32 *misc_clk_cntl_1_ptr = (u32 *)(uintptr_t)(MISC_MMIO_BASE
406 + MISC_MISC_CLK_CNTL_1);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700407
408 /*
409 * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so
410 * 48Mhz will be on ball AP13 (FT3b package)
411 */
Garrett Kirkendalld2558302018-03-06 09:05:20 -0600412 ctrl = read32(misc_clk_cntl_1_ptr);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700413
414 /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */
Garrett Kirkendalld2558302018-03-06 09:05:20 -0600415 ctrl &= ~OSCOUT1_CLK_OUTPUT_ENB;
416 write32(misc_clk_cntl_1_ptr, ctrl);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700417}
418
419static uintptr_t sb_spibase(void)
420{
421 u32 base, enables;
422
423 /* Make sure the base address is predictable */
424 base = pci_read_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER);
425 enables = base & 0xf;
426 base &= ~0x3f;
427
428 if (!base) {
429 base = SPI_BASE_ADDRESS;
430 pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER,
431 base | enables | SPI_ROM_ENABLE);
432 /* PCI_COMMAND_MEMORY is read-only and enabled. */
433 }
434 return (uintptr_t)base;
435}
436
437void sb_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm)
438{
439 uintptr_t base = sb_spibase();
440 write16((void *)base + SPI100_SPEED_CONFIG,
441 (norm << SPI_NORM_SPEED_NEW_SH) |
442 (fast << SPI_FAST_SPEED_NEW_SH) |
443 (alt << SPI_ALT_SPEED_NEW_SH) |
444 (tpm << SPI_TPM_SPEED_NEW_SH));
445 write16((void *)base + SPI100_ENABLE, SPI_USE_SPI100);
446}
447
448void sb_disable_4dw_burst(void)
449{
450 uintptr_t base = sb_spibase();
451 write16((void *)base + SPI100_HOST_PREF_CONFIG,
452 read16((void *)base + SPI100_HOST_PREF_CONFIG)
453 & ~SPI_RD4DW_EN_HOST);
454}
455
456void sb_set_readspeed(u16 norm, u16 fast)
457{
458 uintptr_t base = sb_spibase();
459 write16((void *)base + SPI_CNTRL1, (read16((void *)base + SPI_CNTRL1)
460 & ~SPI_CNTRL1_SPEED_MASK)
461 | (norm << SPI_NORM_SPEED_SH)
462 | (fast << SPI_FAST_SPEED_SH));
463}
464
465void sb_read_mode(u32 mode)
466{
467 uintptr_t base = sb_spibase();
468 write32((void *)base + SPI_CNTRL0,
469 (read32((void *)base + SPI_CNTRL0)
470 & ~SPI_READ_MODE_MASK) | mode);
471}
472
Garrett Kirkendall65753062018-03-07 16:12:11 -0600473/*
474 * Enable FCH to decode TPM associated Memory and IO regions
475 *
476 * Enable decoding of TPM cycles defined in TPM 1.2 spec
477 * Enable decoding of legacy TPM addresses: IO addresses 0x7f-
478 * 0x7e and 0xef-0xee.
479 * This function should be called if TPM is connected in any way to the FCH and
480 * conforms to the regions decoded.
481 * Absent any other routing configuration the TPM cycles will be claimed by the
482 * LPC bus
483 */
484void sb_tpm_decode(void)
485{
486 u32 value;
487
488 value = pci_read_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE);
489 value |= TPM_12_EN | TPM_LEGACY_EN;
490 pci_write_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE, value);
491}
492
493/*
494 * Enable FCH to decode TPM associated Memory and IO regions to SPI
495 *
496 * This should be used if TPM is connected to SPI bus.
497 * Assumes SPI address space is already configured via a call to sb_spibase().
498 */
Richard Spiegelbec44f22017-11-24 07:41:29 -0700499void sb_tpm_decode_spi(void)
500{
Garrett Kirkendall65753062018-03-07 16:12:11 -0600501 /* Enable TPM decoding to FCH */
502 sb_tpm_decode();
503
504 /* Route TPM accesses to SPI */
Richard Spiegelbec44f22017-11-24 07:41:29 -0700505 u32 spibase = pci_read_config32(SOC_LPC_DEV,
506 SPIROM_BASE_ADDRESS_REGISTER);
507 pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER, spibase
508 | ROUTE_TPM_2_SPI);
509}
510
511/*
512 * Enable 4MB (LPC) ROM access at 0xFFC00000 - 0xFFFFFFFF.
513 *
514 * Hardware should enable LPC ROM by pin straps. This function does not
515 * handle the theoretically possible PCI ROM, FWH, or SPI ROM configurations.
516 *
517 * The southbridge power-on default is to map 512K ROM space.
518 *
519 */
520void sb_enable_rom(void)
521{
522 u8 reg8;
523
524 /*
525 * Decode variable LPC ROM address ranges 1 and 2.
526 * Bits 3-4 are not defined in any publicly available datasheet
527 */
528 reg8 = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE);
529 reg8 |= (1 << 3) | (1 << 4);
530 pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE, reg8);
531
532 /*
533 * LPC ROM address range 1:
534 * Enable LPC ROM range mirroring start at 0x000e(0000).
535 */
536 pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_START, 0x000e);
537
538 /* Enable LPC ROM range mirroring end at 0x000f(ffff). */
539 pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_END, 0x000f);
540
541 /*
542 * LPC ROM address range 2:
543 *
544 * Enable LPC ROM range start at:
545 * 0xfff8(0000): 512KB
546 * 0xfff0(0000): 1MB
547 * 0xffe0(0000): 2MB
548 * 0xffc0(0000): 4MB
549 */
550 pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_START, 0x10000
551 - (CONFIG_COREBOOT_ROMSIZE_KB >> 6));
552
553 /* Enable LPC ROM range end at 0xffff(ffff). */
554 pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_END, 0xffff);
555}
556
557void bootblock_fch_early_init(void)
558{
559 sb_enable_rom();
560 sb_lpc_port80();
561 sb_lpc_decode();
Garrett Kirkendalle7513e0d2018-03-14 12:01:36 -0500562 sb_acpi_mmio_decode();
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700563 enable_aoac_devices();
Richard Spiegelbec44f22017-11-24 07:41:29 -0700564}
565
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600566void sb_enable(device_t dev)
Marc Jones24484842017-05-04 21:17:45 -0600567{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600568 printk(BIOS_DEBUG, "%s\n", __func__);
Marc Jones24484842017-05-04 21:17:45 -0600569}
570
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600571static void sb_init_acpi_ports(void)
Marc Jones24484842017-05-04 21:17:45 -0600572{
Marshall Dawson91b80412017-09-27 16:44:40 -0600573 u32 reg;
574
Marc Jones24484842017-05-04 21:17:45 -0600575 /* We use some of these ports in SMM regardless of whether or not
576 * ACPI tables are generated. Enable these ports indiscriminately.
577 */
578
579 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
580 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
581 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
582 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
583 /* CpuControl is in \_PR.CP00, 6 bytes */
584 pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL);
585
586 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) {
Marshall Dawsona05fdcb2017-09-27 15:01:37 -0600587 /* APMC - SMI Command Port */
Marshall Dawsone9b862e2017-09-22 15:14:46 -0600588 pm_write16(PM_ACPI_SMI_CMD, APM_CNT);
Marshall Dawsona05fdcb2017-09-27 15:01:37 -0600589 configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI);
Marshall Dawson91b80412017-09-27 16:44:40 -0600590
591 /* SMI on SlpTyp requires sending SMI before completion
592 * response of the I/O write. The BKDG also specifies
593 * clearing ForceStpClkRetry for SMI trapping.
594 */
595 reg = pm_read32(PM_PCI_CTRL);
596 reg |= FORCE_SLPSTATE_RETRY;
597 reg &= ~FORCE_STPCLK_RETRY;
598 pm_write32(PM_PCI_CTRL, reg);
599
600 /* Disable SlpTyp feature */
601 reg = pm_read8(PM_RST_CTRL1);
602 reg &= ~SLPTYPE_CONTROL_EN;
603 pm_write8(PM_RST_CTRL1, reg);
604
605 configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI);
Marc Jones24484842017-05-04 21:17:45 -0600606 } else {
607 pm_write16(PM_ACPI_SMI_CMD, 0);
608 }
609
Marshall Dawson5e2e74f2017-11-10 09:59:56 -0700610 /* Decode ACPI registers and enable standard features */
611 pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD |
612 PM_ACPI_GLOBAL_EN |
613 PM_ACPI_RTC_EN_EN |
614 PM_ACPI_TIMER_EN_EN);
Marc Jones24484842017-05-04 21:17:45 -0600615}
616
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600617void southbridge_init(void *chip_info)
Marc Jones24484842017-05-04 21:17:45 -0600618{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600619 sb_init_acpi_ports();
Marc Jones24484842017-05-04 21:17:45 -0600620}
621
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600622void southbridge_final(void *chip_info)
Marc Jones24484842017-05-04 21:17:45 -0600623{
Richard Spiegel6a389142018-03-05 14:28:10 -0700624 uint8_t restored_power = PM_S5_AT_POWER_RECOVERY;
625
Richard Spiegel38f19402017-09-29 11:39:46 -0700626 if (IS_ENABLED(CONFIG_STONEYRIDGE_IMC_FWM)) {
627 agesawrapper_fchecfancontrolservice();
628 if (!IS_ENABLED(CONFIG_ACPI_ENABLE_THERMAL_ZONE))
629 enable_imc_thermal_zone();
630 }
Richard Spiegel6a389142018-03-05 14:28:10 -0700631 if (IS_ENABLED(CONFIG_MAINBOARD_POWER_RESTORE))
632 restored_power = PM_RESTORE_S0_IF_PREV_S0;
633 pm_write8(PM_RTC_SHADOW, restored_power);
Marc Jones24484842017-05-04 21:17:45 -0600634}
Marshall Dawson8a906df2017-06-13 14:19:02 -0600635
636/*
637 * Update the PCI devices with a valid IRQ number
638 * that is set in the mainboard PCI_IRQ structures.
639 */
640static void set_pci_irqs(void *unused)
641{
642 /* Write PCI_INTR regs 0xC00/0xC01 */
643 write_pci_int_table();
644
645 /* Write IRQs for all devicetree enabled devices */
646 write_pci_cfg_irqs();
647}
648
649/*
650 * Hook this function into the PCI state machine
651 * on entry into BS_DEV_ENABLE.
652 */
653BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);