blob: 545642f60893a6400c62b3d6ca5288ba9426e9b8 [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy77ff0b12015-05-05 15:07:29 -07002
Elyes HAOUAS92f46aa2020-09-15 08:42:17 +02003#include <arch/io.h>
Frans Hendriks4e0ec592019-06-06 10:07:17 +02004#include <bootblock_common.h>
5#include <build.h>
6#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02007#include <device/pci_ops.h>
Frans Hendriks0948b362020-11-19 15:13:02 +01008#include <fsp/util.h>
Frans Hendriks4e0ec592019-06-06 10:07:17 +02009#include <pc80/mc146818rtc.h>
Frans Hendriks4e0ec592019-06-06 10:07:17 +020010#include <soc/gpio.h>
11#include <soc/iomap.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070012#include <soc/iosf.h>
Frans Hendriks4e0ec592019-06-06 10:07:17 +020013#include <soc/lpc.h>
Kyösti Mälkki44f1af22019-11-06 08:56:18 +020014#include <soc/msr.h>
Frans Hendriks4e0ec592019-06-06 10:07:17 +020015#include <soc/pm.h>
16#include <soc/spi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070017
Frans Hendriks4e0ec592019-06-06 10:07:17 +020018asmlinkage void bootblock_c_entry(uint64_t base_timestamp)
Lee Leahy77ff0b12015-05-05 15:07:29 -070019{
Frans Hendriks4e0ec592019-06-06 10:07:17 +020020 /* Call lib/bootblock.c main */
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030021 bootblock_main_with_basetime(base_timestamp);
Lee Leahy77ff0b12015-05-05 15:07:29 -070022}
23
Frans Hendriks4e0ec592019-06-06 10:07:17 +020024static void program_base_addresses(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -070025{
Frans Hendriks4e0ec592019-06-06 10:07:17 +020026 uint32_t reg;
27 const uint32_t lpc_dev = PCI_DEV(0, LPC_DEV, LPC_FUNC);
Lee Leahy77ff0b12015-05-05 15:07:29 -070028
Frans Hendriks4e0ec592019-06-06 10:07:17 +020029 /* Memory Mapped IO registers. */
30 reg = PMC_BASE_ADDRESS | 2;
31 pci_write_config32(lpc_dev, PBASE, reg);
32 reg = IO_BASE_ADDRESS | 2;
33 pci_write_config32(lpc_dev, IOBASE, reg);
34 reg = ILB_BASE_ADDRESS | 2;
35 pci_write_config32(lpc_dev, IBASE, reg);
36 reg = SPI_BASE_ADDRESS | 2;
37 pci_write_config32(lpc_dev, SBASE, reg);
38 reg = MPHY_BASE_ADDRESS | 2;
39 pci_write_config32(lpc_dev, MPBASE, reg);
40 reg = PUNIT_BASE_ADDRESS | 2;
41 pci_write_config32(lpc_dev, PUBASE, reg);
42 reg = RCBA_BASE_ADDRESS | 1;
43 pci_write_config32(lpc_dev, RCBA, reg);
Lee Leahy77ff0b12015-05-05 15:07:29 -070044
Frans Hendriks4e0ec592019-06-06 10:07:17 +020045 /* IO Port Registers. */
46 reg = ACPI_BASE_ADDRESS | 2;
47 pci_write_config32(lpc_dev, ABASE, reg);
48 reg = GPIO_BASE_ADDRESS | 2;
49 pci_write_config32(lpc_dev, GBASE, reg);
50}
51
52static void tco_disable(void)
53{
54 uint32_t reg;
55
56 reg = inl(ACPI_BASE_ADDRESS + TCO1_CNT);
57 reg |= TCO_TMR_HALT;
58 outl(reg, ACPI_BASE_ADDRESS + TCO1_CNT);
59}
60
61static void spi_init(void)
62{
63 void *scs = (void *)(SPI_BASE_ADDRESS + SCS);
64 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
65 uint32_t reg;
66
67 /* Disable generating SMI when setting WPD bit. */
68 write32(scs, read32(scs) & ~SMIWPEN);
69 /*
70 * Enable caching and prefetching in the SPI controller. Disable
71 * the SMM-only BIOS write and set WPD bit.
72 */
73 reg = (read32(bcr) & ~SRC_MASK) | SRC_CACHE_PREFETCH | BCR_WPD;
74 reg &= ~EISS;
75 write32(bcr, reg);
76}
77
78static void soc_rtc_init(void)
79{
80 int rtc_failed = rtc_failure();
81
82 if (rtc_failed) {
Angel Ponsaee7ab22020-03-19 00:31:58 +010083 printk(BIOS_ERR, "RTC Failure detected. Resetting date to %x/%x/%x%x\n",
84 COREBOOT_BUILD_MONTH_BCD, COREBOOT_BUILD_DAY_BCD, 0x20,
Frans Hendriks4e0ec592019-06-06 10:07:17 +020085 COREBOOT_BUILD_YEAR_BCD);
86 }
87
88 cmos_init(rtc_failed);
Lee Leahy77ff0b12015-05-05 15:07:29 -070089}
90
91static void setup_mmconfig(void)
92{
93 uint32_t reg;
94
Lee Leahy32471722015-04-20 15:20:28 -070095 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +010096 * Set up the MMCONF range. The register lives in the BUNIT. The IO variant of the
97 * config access needs to be used initially to properly configure as the IOSF access
98 * registers live in PCI config space.
Lee Leahy32471722015-04-20 15:20:28 -070099 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700100 reg = 0;
101 /* Clear the extended register. */
102 pci_io_write_config32(IOSF_PCI_DEV, MCRX_REG, reg);
Shelley Chen4e9bb332021-10-20 15:43:45 -0700103 reg = CONFIG_ECAM_MMCONF_BASE_ADDRESS | 1;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700104 pci_io_write_config32(IOSF_PCI_DEV, MDR_REG, reg);
105 reg = IOSF_OPCODE(IOSF_OP_WRITE_BUNIT) | IOSF_PORT(IOSF_PORT_BUNIT) |
106 IOSF_REG(BUNIT_MMCONF_REG) | IOSF_BYTE_EN;
107 pci_io_write_config32(IOSF_PCI_DEV, MCR_REG, reg);
108}
109
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200110void bootblock_soc_early_init(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700111{
Angel Ponsaee7ab22020-03-19 00:31:58 +0100112 /* Allow memory-mapped PCI config access */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700113 setup_mmconfig();
114
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200115 /* Early chipset initialization */
116 program_base_addresses();
117 tco_disable();
118}
119void bootblock_soc_init(void)
120{
Frans Hendriks0948b362020-11-19 15:13:02 +0100121 report_fsp_output();
122
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200123 /* Continue chipset initialization */
124 soc_rtc_init();
125 set_max_freq();
126 spi_init();
127
128 lpc_init();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700129}