blob: 46f12e7646c82672ba2e383823b56b598fa6eef1 [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
Arthur Heymans179da7f2019-11-15 12:51:51 +010012static void program_base_addresses(void)
13{
14 uint32_t reg;
15 const uint32_t lpc_dev = PCI_DEV(0, LPC_DEV, LPC_FUNC);
16
17 /* Memory Mapped IO registers. */
18 reg = PMC_BASE_ADDRESS | 2;
19 pci_write_config32(lpc_dev, PBASE, reg);
20 reg = IO_BASE_ADDRESS | 2;
21 pci_write_config32(lpc_dev, IOBASE, reg);
22 reg = ILB_BASE_ADDRESS | 2;
23 pci_write_config32(lpc_dev, IBASE, reg);
24 reg = SPI_BASE_ADDRESS | 2;
25 pci_write_config32(lpc_dev, SBASE, reg);
26 reg = MPHY_BASE_ADDRESS | 2;
27 pci_write_config32(lpc_dev, MPBASE, reg);
28 reg = PUNIT_BASE_ADDRESS | 2;
29 pci_write_config32(lpc_dev, PUBASE, reg);
30 reg = RCBA_BASE_ADDRESS | 1;
31 pci_write_config32(lpc_dev, RCBA, reg);
32
33 /* IO Port Registers. */
34 reg = ACPI_BASE_ADDRESS | 2;
35 pci_write_config32(lpc_dev, ABASE, reg);
36 reg = GPIO_BASE_ADDRESS | 2;
37 pci_write_config32(lpc_dev, GBASE, reg);
38}
39
Angel Pons0ee86f02020-07-07 17:30:06 +020040static void tco_disable(void)
41{
42 uint32_t reg;
43
44 reg = inl(ACPI_BASE_ADDRESS + TCO1_CNT);
45 reg |= TCO_TMR_HALT;
46 outl(reg, ACPI_BASE_ADDRESS + TCO1_CNT);
47}
48
Arthur Heymans179da7f2019-11-15 12:51:51 +010049static void spi_init(void)
50{
Angel Ponse80d17f2020-07-07 17:25:38 +020051 void *scs = (void *)(SPI_BASE_ADDRESS + SCS);
52 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
Arthur Heymans179da7f2019-11-15 12:51:51 +010053 uint32_t reg;
54
55 /* Disable generating SMI when setting WPD bit. */
56 write32(scs, read32(scs) & ~SMIWPEN);
57 /*
58 * Enable caching and prefetching in the SPI controller. Disable
59 * the SMM-only BIOS write and set WPD bit.
60 */
61 reg = (read32(bcr) & ~SRC_MASK) | SRC_CACHE_PREFETCH | BCR_WPD;
62 reg &= ~EISS;
63 write32(bcr, reg);
64}
65
Arthur Heymans179da7f2019-11-15 12:51:51 +010066static void byt_config_com1_and_enable(void)
67{
68 uint32_t reg;
69
70 /* Enable the UART hardware for COM1. */
71 reg = 1;
72 pci_write_config32(PCI_DEV(0, LPC_DEV, 0), UART_CONT, reg);
73
74 /* Set up the pads to select the UART function */
75 score_select_func(UART_RXD_PAD, 1);
76 score_select_func(UART_TXD_PAD, 1);
77}
78
Angel Pons0ee86f02020-07-07 17:30:06 +020079static void setup_mmconfig(void)
80{
81 uint32_t reg;
82
83 /*
84 * Set up the MMCONF range. The register lives in the BUNIT. The IO variant of the
85 * config access needs to be used initially to properly configure as the IOSF access
86 * registers live in PCI config space.
87 */
88 reg = 0;
89 /* Clear the extended register. */
90 pci_io_write_config32(IOSF_PCI_DEV, MCRX_REG, reg);
91 reg = CONFIG_MMCONF_BASE_ADDRESS | 1;
92 pci_io_write_config32(IOSF_PCI_DEV, MDR_REG, reg);
93 reg = IOSF_OPCODE(IOSF_OP_WRITE_BUNIT) | IOSF_PORT(IOSF_PORT_BUNIT) |
94 IOSF_REG(BUNIT_MMCONF_REG) | IOSF_BYTE_EN;
95 pci_io_write_config32(IOSF_PCI_DEV, MCR_REG, reg);
96}
97
Arthur Heymans179da7f2019-11-15 12:51:51 +010098/* 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}