coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
uart_init.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/io.h>
4 #include <arch/mmio.h>
5 #include <assert.h>
6 #include <console/uart.h>
7 #include <device/pci_def.h>
8 #include <device/pci_ops.h>
12 #include <types.h>
13 
15 {
16  switch (CONFIG_UART_FOR_CONSOLE) {
17  case 0: return PCI_DEV(0, 0x15, 5);
18  case 1: return PCI_DEV(0, 0x15, 6);
19  default: return dead_code_t(pci_devfn_t);
20  }
21 }
22 
23 /* TODO: Figure out if all steps are actually necessary */
25 {
26  const pci_devfn_t dev = get_uart_pci_device();
27 
28  /* Program IOBP GPIODF */
29  pch_iobp_update(SIO_IOBP_GPIODF, ~0x131f, 0x131f);
30 
31  /* Program IOBP CB000180h[5:0] = 111111b (undefined register) */
32  pch_iobp_update(0xcb000180, ~0x0000003f, 0x0000003f);
33 
34  /* Set and enable MMIO BAR */
35  pci_write_config32(dev, PCI_BASE_ADDRESS_0, CONFIG_CONSOLE_UART_BASE_ADDRESS);
37 
38  void *const bar = (void *)(uintptr_t)CONFIG_CONSOLE_UART_BASE_ADDRESS;
39 
40  /* Initialize LTR */
43 
44  /* Take UART out of reset */
46 
47  /* Set M and N divisor inputs and enable clock */
48  uint32_t ppr_clock = 0;
49  ppr_clock |= SIO_REG_PPR_CLOCK_EN;
50  ppr_clock |= SIO_REG_PPR_CLOCK_UPDATE;
51  ppr_clock |= SIO_REG_PPR_CLOCK_N_DIV << 16;
52  ppr_clock |= SIO_REG_PPR_CLOCK_M_DIV << 1;
53  write32(bar + SIO_REG_PPR_CLOCK, ppr_clock);
54 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
#define dead_code_t(type)
Definition: assert.h:92
#define SIO_REG_PPR_RST_ASSERT
Definition: serialio.h:60
#define SIO_REG_PPR_RST
Definition: serialio.h:59
#define SIO_REG_PPR_CLOCK_EN
Definition: serialio.h:55
#define SIO_REG_PPR_GEN_LTR_MODE_MASK
Definition: serialio.h:62
#define SIO_REG_PPR_GEN
Definition: serialio.h:61
#define SIO_REG_PPR_CLOCK_UPDATE
Definition: serialio.h:56
#define SIO_REG_PPR_CLOCK_M_DIV
Definition: serialio.h:57
#define SIO_IOBP_GPIODF
Definition: serialio.h:12
#define SIO_REG_PPR_CLOCK
Definition: serialio.h:54
#define SIO_REG_PPR_CLOCK_N_DIV
Definition: serialio.h:58
#define setbits32(addr, set)
Definition: mmio.h:21
#define clrbits32(addr, clear)
Definition: mmio.h:26
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline void pci_or_config16(const struct device *dev, u16 reg, u16 ormask)
Definition: pci_ops.h:180
#define PCI_COMMAND_MEMORY
Definition: pci_def.h:12
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_COMMAND
Definition: pci_def.h:10
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
u32 pci_devfn_t
Definition: pci_type.h:8
void pch_iobp_update(u32 address, u32 andvalue, u32 orvalue)
Definition: pch.c:86
unsigned int uint32_t
Definition: stdint.h:14
unsigned long uintptr_t
Definition: stdint.h:21
static pci_devfn_t get_uart_pci_device(void)
Definition: uart_init.c:14
void uart_bootblock_init(void)
Definition: uart_init.c:24