Angel Pons | ba38f37 | 2020-04-05 15:46:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 2 | |
Elyes HAOUAS | 92f46aa | 2020-09-15 08:42:17 +0200 | [diff] [blame] | 3 | #include <arch/io.h> |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 4 | #include <bootblock_common.h> |
| 5 | #include <build.h> |
| 6 | #include <console/console.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 7 | #include <device/pci_ops.h> |
Frans Hendriks | 0948b36 | 2020-11-19 15:13:02 +0100 | [diff] [blame] | 8 | #include <fsp/util.h> |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 9 | #include <pc80/mc146818rtc.h> |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 10 | #include <soc/gpio.h> |
| 11 | #include <soc/iomap.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 12 | #include <soc/iosf.h> |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 13 | #include <soc/lpc.h> |
Kyösti Mälkki | 44f1af2 | 2019-11-06 08:56:18 +0200 | [diff] [blame] | 14 | #include <soc/msr.h> |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 15 | #include <soc/pm.h> |
| 16 | #include <soc/spi.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 17 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 18 | asmlinkage void bootblock_c_entry(uint64_t base_timestamp) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 19 | { |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 20 | /* Call lib/bootblock.c main */ |
Kyösti Mälkki | 101ef0b | 2019-08-18 06:58:42 +0300 | [diff] [blame] | 21 | bootblock_main_with_basetime(base_timestamp); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 24 | static void program_base_addresses(void) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 25 | { |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 26 | uint32_t reg; |
| 27 | const uint32_t lpc_dev = PCI_DEV(0, LPC_DEV, LPC_FUNC); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 28 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 29 | /* 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 Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 44 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 45 | /* 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 | |
| 52 | static 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 | |
| 61 | static 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 | |
| 78 | static void soc_rtc_init(void) |
| 79 | { |
| 80 | int rtc_failed = rtc_failure(); |
| 81 | |
| 82 | if (rtc_failed) { |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 83 | 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 Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 85 | COREBOOT_BUILD_YEAR_BCD); |
| 86 | } |
| 87 | |
| 88 | cmos_init(rtc_failed); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void setup_mmconfig(void) |
| 92 | { |
| 93 | uint32_t reg; |
| 94 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 95 | /* |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 96 | * 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 Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 99 | */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 100 | reg = 0; |
| 101 | /* Clear the extended register. */ |
| 102 | pci_io_write_config32(IOSF_PCI_DEV, MCRX_REG, reg); |
Shelley Chen | 4e9bb33 | 2021-10-20 15:43:45 -0700 | [diff] [blame^] | 103 | reg = CONFIG_ECAM_MMCONF_BASE_ADDRESS | 1; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 104 | 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 Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 110 | void bootblock_soc_early_init(void) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 111 | { |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 112 | /* Allow memory-mapped PCI config access */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 113 | setup_mmconfig(); |
| 114 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 115 | /* Early chipset initialization */ |
| 116 | program_base_addresses(); |
| 117 | tco_disable(); |
| 118 | } |
| 119 | void bootblock_soc_init(void) |
| 120 | { |
Frans Hendriks | 0948b36 | 2020-11-19 15:13:02 +0100 | [diff] [blame] | 121 | report_fsp_output(); |
| 122 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 123 | /* Continue chipset initialization */ |
| 124 | soc_rtc_init(); |
| 125 | set_max_freq(); |
| 126 | spi_init(); |
| 127 | |
| 128 | lpc_init(); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 129 | } |