blob: 62f42cd4d6e38614da295e2d0531eff393ed87e2 [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>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Julius Werner18ea2d32014-10-07 16:42:17 -07005#include <soc/iosf.h>
Arthur Heymans179da7f2019-11-15 12:51:51 +01006#include <soc/iomap.h>
7#include <soc/gpio.h>
8#include <soc/lpc.h>
9#include <soc/spi.h>
Angel Ponsb5320b22020-07-07 18:27:30 +020010#include <soc/pm.h>
Aaron Durbinba170b472013-09-23 14:15:42 -050011
Aaron Durbinc0270aa2013-10-04 11:15:48 -050012static void setup_mmconfig(void)
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050013{
14 uint32_t reg;
15
Angel Pons26b49cc2020-07-07 17:17:51 +020016 /*
17 * Set up the MMCONF range. The register lives in the BUNIT. The IO variant of the
18 * config access needs to be used initially to properly configure as the IOSF access
19 * registers live in PCI config space.
20 */
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050021 reg = 0;
22 /* Clear the extended register. */
23 pci_io_write_config32(IOSF_PCI_DEV, MCRX_REG, reg);
24 reg = CONFIG_MMCONF_BASE_ADDRESS | 1;
25 pci_io_write_config32(IOSF_PCI_DEV, MDR_REG, reg);
26 reg = IOSF_OPCODE(IOSF_OP_WRITE_BUNIT) | IOSF_PORT(IOSF_PORT_BUNIT) |
27 IOSF_REG(BUNIT_MMCONF_REG) | IOSF_BYTE_EN;
28 pci_io_write_config32(IOSF_PCI_DEV, MCR_REG, reg);
29}
Aaron Durbinc0270aa2013-10-04 11:15:48 -050030
Arthur Heymans179da7f2019-11-15 12:51:51 +010031static void program_base_addresses(void)
32{
33 uint32_t reg;
34 const uint32_t lpc_dev = PCI_DEV(0, LPC_DEV, LPC_FUNC);
35
36 /* Memory Mapped IO registers. */
37 reg = PMC_BASE_ADDRESS | 2;
38 pci_write_config32(lpc_dev, PBASE, reg);
39 reg = IO_BASE_ADDRESS | 2;
40 pci_write_config32(lpc_dev, IOBASE, reg);
41 reg = ILB_BASE_ADDRESS | 2;
42 pci_write_config32(lpc_dev, IBASE, reg);
43 reg = SPI_BASE_ADDRESS | 2;
44 pci_write_config32(lpc_dev, SBASE, reg);
45 reg = MPHY_BASE_ADDRESS | 2;
46 pci_write_config32(lpc_dev, MPBASE, reg);
47 reg = PUNIT_BASE_ADDRESS | 2;
48 pci_write_config32(lpc_dev, PUBASE, reg);
49 reg = RCBA_BASE_ADDRESS | 1;
50 pci_write_config32(lpc_dev, RCBA, reg);
51
52 /* IO Port Registers. */
53 reg = ACPI_BASE_ADDRESS | 2;
54 pci_write_config32(lpc_dev, ABASE, reg);
55 reg = GPIO_BASE_ADDRESS | 2;
56 pci_write_config32(lpc_dev, GBASE, reg);
57}
58
59static void spi_init(void)
60{
Angel Ponse80d17f2020-07-07 17:25:38 +020061 void *scs = (void *)(SPI_BASE_ADDRESS + SCS);
62 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
Arthur Heymans179da7f2019-11-15 12:51:51 +010063 uint32_t reg;
64
65 /* Disable generating SMI when setting WPD bit. */
66 write32(scs, read32(scs) & ~SMIWPEN);
67 /*
68 * Enable caching and prefetching in the SPI controller. Disable
69 * the SMM-only BIOS write and set WPD bit.
70 */
71 reg = (read32(bcr) & ~SRC_MASK) | SRC_CACHE_PREFETCH | BCR_WPD;
72 reg &= ~EISS;
73 write32(bcr, reg);
74}
75
76static void tco_disable(void)
77{
78 uint32_t reg;
79
80 reg = inl(ACPI_BASE_ADDRESS + TCO1_CNT);
81 reg |= TCO_TMR_HALT;
82 outl(reg, ACPI_BASE_ADDRESS + TCO1_CNT);
83}
84
85static void byt_config_com1_and_enable(void)
86{
87 uint32_t reg;
88
89 /* Enable the UART hardware for COM1. */
90 reg = 1;
91 pci_write_config32(PCI_DEV(0, LPC_DEV, 0), UART_CONT, reg);
92
93 /* Set up the pads to select the UART function */
94 score_select_func(UART_RXD_PAD, 1);
95 score_select_func(UART_TXD_PAD, 1);
96}
97
98/* The distinction between nb/sb/cpu is not applicable here so
99 just pick the one that is called first. */
100void bootblock_early_northbridge_init(void)
Aaron Durbinc0270aa2013-10-04 11:15:48 -0500101{
Angel Pons26b49cc2020-07-07 17:17:51 +0200102 /* Allow memory-mapped PCI config access */
Aaron Durbinc0270aa2013-10-04 11:15:48 -0500103 setup_mmconfig();
104
Angel Pons26b49cc2020-07-07 17:17:51 +0200105 /* Early chipset initialization */
Arthur Heymans179da7f2019-11-15 12:51:51 +0100106 program_base_addresses();
Arthur Heymans179da7f2019-11-15 12:51:51 +0100107 tco_disable();
108
109 if (CONFIG(ENABLE_BUILTIN_COM1))
110 byt_config_com1_and_enable();
111
112 spi_init();
Aaron Durbinc0270aa2013-10-04 11:15:48 -0500113}