blob: 54e7261d3b9cbda507a97da13b88f670f65069c2 [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
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050016 /* Set up the MMCONF range. The register lives in the BUNIT. The
17 * IO variant of the config access needs to be used initially to
18 * properly configure as the IOSF access registers live in PCI
19 * config space. */
20 reg = 0;
21 /* Clear the extended register. */
22 pci_io_write_config32(IOSF_PCI_DEV, MCRX_REG, reg);
23 reg = CONFIG_MMCONF_BASE_ADDRESS | 1;
24 pci_io_write_config32(IOSF_PCI_DEV, MDR_REG, reg);
25 reg = IOSF_OPCODE(IOSF_OP_WRITE_BUNIT) | IOSF_PORT(IOSF_PORT_BUNIT) |
26 IOSF_REG(BUNIT_MMCONF_REG) | IOSF_BYTE_EN;
27 pci_io_write_config32(IOSF_PCI_DEV, MCR_REG, reg);
28}
Aaron Durbinc0270aa2013-10-04 11:15:48 -050029
Arthur Heymans179da7f2019-11-15 12:51:51 +010030static void program_base_addresses(void)
31{
32 uint32_t reg;
33 const uint32_t lpc_dev = PCI_DEV(0, LPC_DEV, LPC_FUNC);
34
35 /* Memory Mapped IO registers. */
36 reg = PMC_BASE_ADDRESS | 2;
37 pci_write_config32(lpc_dev, PBASE, reg);
38 reg = IO_BASE_ADDRESS | 2;
39 pci_write_config32(lpc_dev, IOBASE, reg);
40 reg = ILB_BASE_ADDRESS | 2;
41 pci_write_config32(lpc_dev, IBASE, reg);
42 reg = SPI_BASE_ADDRESS | 2;
43 pci_write_config32(lpc_dev, SBASE, reg);
44 reg = MPHY_BASE_ADDRESS | 2;
45 pci_write_config32(lpc_dev, MPBASE, reg);
46 reg = PUNIT_BASE_ADDRESS | 2;
47 pci_write_config32(lpc_dev, PUBASE, reg);
48 reg = RCBA_BASE_ADDRESS | 1;
49 pci_write_config32(lpc_dev, RCBA, reg);
50
51 /* IO Port Registers. */
52 reg = ACPI_BASE_ADDRESS | 2;
53 pci_write_config32(lpc_dev, ABASE, reg);
54 reg = GPIO_BASE_ADDRESS | 2;
55 pci_write_config32(lpc_dev, GBASE, reg);
56}
57
58static void spi_init(void)
59{
60 u32 *scs = (u32 *)(SPI_BASE_ADDRESS + SCS);
61 u32 *bcr = (u32 *)(SPI_BASE_ADDRESS + BCR);
62 uint32_t reg;
63
64 /* Disable generating SMI when setting WPD bit. */
65 write32(scs, read32(scs) & ~SMIWPEN);
66 /*
67 * Enable caching and prefetching in the SPI controller. Disable
68 * the SMM-only BIOS write and set WPD bit.
69 */
70 reg = (read32(bcr) & ~SRC_MASK) | SRC_CACHE_PREFETCH | BCR_WPD;
71 reg &= ~EISS;
72 write32(bcr, reg);
73}
74
75static void tco_disable(void)
76{
77 uint32_t reg;
78
79 reg = inl(ACPI_BASE_ADDRESS + TCO1_CNT);
80 reg |= TCO_TMR_HALT;
81 outl(reg, ACPI_BASE_ADDRESS + TCO1_CNT);
82}
83
84static void byt_config_com1_and_enable(void)
85{
86 uint32_t reg;
87
88 /* Enable the UART hardware for COM1. */
89 reg = 1;
90 pci_write_config32(PCI_DEV(0, LPC_DEV, 0), UART_CONT, reg);
91
92 /* Set up the pads to select the UART function */
93 score_select_func(UART_RXD_PAD, 1);
94 score_select_func(UART_TXD_PAD, 1);
95}
96
97/* The distinction between nb/sb/cpu is not applicable here so
98 just pick the one that is called first. */
99void bootblock_early_northbridge_init(void)
Aaron Durbinc0270aa2013-10-04 11:15:48 -0500100{
101 /* Allow memory-mapped PCI config access. */
102 setup_mmconfig();
103
Arthur Heymans179da7f2019-11-15 12:51:51 +0100104 program_base_addresses();
105
106 tco_disable();
107
108 if (CONFIG(ENABLE_BUILTIN_COM1))
109 byt_config_com1_and_enable();
110
111 spi_init();
Aaron Durbinc0270aa2013-10-04 11:15:48 -0500112}