blob: 3f07a6b4396fea9d857336b1e15924405daa51f0 [file] [log] [blame]
Angel Ponsc3f58f62020-04-05 15:46:41 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -05002
Kyösti Mälkkide640782019-12-03 07:30:26 +02003#include <arch/bootblock.h>
Elyes HAOUAS92f46aa2020-09-15 08:42:17 +02004#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Julius Werner18ea2d32014-10-07 16:42:17 -07006#include <soc/iosf.h>
Arthur Heymans179da7f2019-11-15 12:51:51 +01007#include <soc/iomap.h>
8#include <soc/gpio.h>
9#include <soc/lpc.h>
10#include <soc/spi.h>
Angel Ponsb5320b22020-07-07 18:27:30 +020011#include <soc/pm.h>
Aaron Durbinba170b472013-09-23 14:15:42 -050012
Arthur Heymans179da7f2019-11-15 12:51:51 +010013static void program_base_addresses(void)
14{
15 uint32_t reg;
16 const uint32_t lpc_dev = PCI_DEV(0, LPC_DEV, LPC_FUNC);
17
18 /* Memory Mapped IO registers. */
19 reg = PMC_BASE_ADDRESS | 2;
20 pci_write_config32(lpc_dev, PBASE, reg);
21 reg = IO_BASE_ADDRESS | 2;
22 pci_write_config32(lpc_dev, IOBASE, reg);
23 reg = ILB_BASE_ADDRESS | 2;
24 pci_write_config32(lpc_dev, IBASE, reg);
25 reg = SPI_BASE_ADDRESS | 2;
26 pci_write_config32(lpc_dev, SBASE, reg);
27 reg = MPHY_BASE_ADDRESS | 2;
28 pci_write_config32(lpc_dev, MPBASE, reg);
29 reg = PUNIT_BASE_ADDRESS | 2;
30 pci_write_config32(lpc_dev, PUBASE, reg);
31 reg = RCBA_BASE_ADDRESS | 1;
32 pci_write_config32(lpc_dev, RCBA, reg);
33
34 /* IO Port Registers. */
35 reg = ACPI_BASE_ADDRESS | 2;
36 pci_write_config32(lpc_dev, ABASE, reg);
37 reg = GPIO_BASE_ADDRESS | 2;
38 pci_write_config32(lpc_dev, GBASE, reg);
39}
40
Angel Pons0ee86f02020-07-07 17:30:06 +020041static void tco_disable(void)
42{
43 uint32_t reg;
44
45 reg = inl(ACPI_BASE_ADDRESS + TCO1_CNT);
46 reg |= TCO_TMR_HALT;
47 outl(reg, ACPI_BASE_ADDRESS + TCO1_CNT);
48}
49
Arthur Heymans179da7f2019-11-15 12:51:51 +010050static void spi_init(void)
51{
Angel Ponse80d17f2020-07-07 17:25:38 +020052 void *scs = (void *)(SPI_BASE_ADDRESS + SCS);
53 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
Arthur Heymans179da7f2019-11-15 12:51:51 +010054 uint32_t reg;
55
56 /* Disable generating SMI when setting WPD bit. */
57 write32(scs, read32(scs) & ~SMIWPEN);
58 /*
59 * Enable caching and prefetching in the SPI controller. Disable
60 * the SMM-only BIOS write and set WPD bit.
61 */
62 reg = (read32(bcr) & ~SRC_MASK) | SRC_CACHE_PREFETCH | BCR_WPD;
63 reg &= ~EISS;
64 write32(bcr, reg);
65}
66
Arthur Heymans179da7f2019-11-15 12:51:51 +010067static void byt_config_com1_and_enable(void)
68{
69 uint32_t reg;
70
71 /* Enable the UART hardware for COM1. */
72 reg = 1;
73 pci_write_config32(PCI_DEV(0, LPC_DEV, 0), UART_CONT, reg);
74
75 /* Set up the pads to select the UART function */
76 score_select_func(UART_RXD_PAD, 1);
77 score_select_func(UART_TXD_PAD, 1);
78}
79
Angel Pons0ee86f02020-07-07 17:30:06 +020080static void setup_mmconfig(void)
81{
82 uint32_t reg;
83
84 /*
85 * Set up the MMCONF range. The register lives in the BUNIT. The IO variant of the
86 * config access needs to be used initially to properly configure as the IOSF access
87 * registers live in PCI config space.
88 */
89 reg = 0;
90 /* Clear the extended register. */
91 pci_io_write_config32(IOSF_PCI_DEV, MCRX_REG, reg);
Shelley Chen4e9bb332021-10-20 15:43:45 -070092 reg = CONFIG_ECAM_MMCONF_BASE_ADDRESS | 1;
Angel Pons0ee86f02020-07-07 17:30:06 +020093 pci_io_write_config32(IOSF_PCI_DEV, MDR_REG, reg);
94 reg = IOSF_OPCODE(IOSF_OP_WRITE_BUNIT) | IOSF_PORT(IOSF_PORT_BUNIT) |
95 IOSF_REG(BUNIT_MMCONF_REG) | IOSF_BYTE_EN;
96 pci_io_write_config32(IOSF_PCI_DEV, MCR_REG, reg);
97}
98
Arthur Heymans179da7f2019-11-15 12:51:51 +010099/* The distinction between nb/sb/cpu is not applicable here so
100 just pick the one that is called first. */
101void bootblock_early_northbridge_init(void)
Aaron Durbinc0270aa2013-10-04 11:15:48 -0500102{
Angel Pons26b49cc2020-07-07 17:17:51 +0200103 /* Allow memory-mapped PCI config access */
Aaron Durbinc0270aa2013-10-04 11:15:48 -0500104 setup_mmconfig();
105
Angel Pons26b49cc2020-07-07 17:17:51 +0200106 /* Early chipset initialization */
Arthur Heymans179da7f2019-11-15 12:51:51 +0100107 program_base_addresses();
Arthur Heymans179da7f2019-11-15 12:51:51 +0100108 tco_disable();
109
110 if (CONFIG(ENABLE_BUILTIN_COM1))
111 byt_config_com1_and_enable();
112
113 spi_init();
Aaron Durbinc0270aa2013-10-04 11:15:48 -0500114}