Angel Pons | c3f58f6 | 2020-04-05 15:46:41 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 2 | |
Kyösti Mälkki | de64078 | 2019-12-03 07:30:26 +0200 | [diff] [blame] | 3 | #include <arch/bootblock.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 5 | #include <soc/iosf.h> |
Arthur Heymans | 179da7f | 2019-11-15 12:51:51 +0100 | [diff] [blame] | 6 | #include <soc/iomap.h> |
| 7 | #include <soc/gpio.h> |
| 8 | #include <soc/lpc.h> |
| 9 | #include <soc/spi.h> |
| 10 | #include <soc/pmc.h> |
Aaron Durbin | ba170b47 | 2013-09-23 14:15:42 -0500 | [diff] [blame] | 11 | |
Aaron Durbin | c0270aa | 2013-10-04 11:15:48 -0500 | [diff] [blame] | 12 | static void setup_mmconfig(void) |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 13 | { |
| 14 | uint32_t reg; |
| 15 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 16 | /* 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 Durbin | c0270aa | 2013-10-04 11:15:48 -0500 | [diff] [blame] | 29 | |
Arthur Heymans | 179da7f | 2019-11-15 12:51:51 +0100 | [diff] [blame] | 30 | static 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 | |
| 58 | static 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 | |
| 75 | static 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 | |
| 84 | static 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. */ |
| 99 | void bootblock_early_northbridge_init(void) |
Aaron Durbin | c0270aa | 2013-10-04 11:15:48 -0500 | [diff] [blame] | 100 | { |
| 101 | /* Allow memory-mapped PCI config access. */ |
| 102 | setup_mmconfig(); |
| 103 | |
Arthur Heymans | 179da7f | 2019-11-15 12:51:51 +0100 | [diff] [blame] | 104 | 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 Durbin | c0270aa | 2013-10-04 11:15:48 -0500 | [diff] [blame] | 112 | } |