Debian Codegraph @

src/soc/intel/snowridge/bootblock/early_uart_init.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <device/pci_def.h>
4 #include <device/pci_ops.h>
5 #include <soc/pci_devs.h>
6 #include <stdint.h>
7
8 #include "../common/uart8250mem.h"
9 #include "bootblock.h"
10
11 static void pci_early_hsuart_device_enable(uint8_t func, uint16_t io_base)
12 {
13 register uint16_t cmd_stat_reg;
14
15 pci_or_config32(PCH_DEV_UART(func), UART_IOBA, io_base);
16
17 /**
18 * Enable memory/io space and allow to initiate a transaction as a master.
19 */
20 cmd_stat_reg = pci_read_config16(PCH_DEV_UART(func), PCI_COMMAND);
21 cmd_stat_reg |= PCI_COMMAND_MASTER | PCI_COMMAND_IO;
22
23 #if CONFIG_CONSOLE_UART_BASE_ADDRESS != 0
24 /* Decode MMIO at MEMBA (BAR1). */
25 pci_write_config32(PCH_DEV_UART(func), UART_MEMBA,
26 CONFIG_CONSOLE_UART_BASE_ADDRESS + SIZE_OF_HSUART_RES * func);
27 cmd_stat_reg |= PCI_COMMAND_MEMORY;
28 #endif
29
30 pci_write_config16(PCH_DEV_UART(func), PCI_COMMAND, cmd_stat_reg);
31
32 #if CONFIG_TTYS0_BAUD > 115200
33 #if CONFIG_CONSOLE_UART_BASE_ADDRESS && CONFIG(ECAM_MMCONF_SUPPORT)
34 #define UCMR_OFFSET 0x34
35 /**
36 * Change UART baseclock to 24 x 1.8432MHz -> 44.2368MHz, use
37 * `HIGH_SPEED_CLK_MULT` (24) times faster base clock.
38 */
39 write32p(CONFIG_CONSOLE_UART_BASE_ADDRESS + UCMR_OFFSET,
40 read32p(CONFIG_CONSOLE_UART_BASE_ADDRESS + UCMR_OFFSET) * HIGH_SPEED_CLK_MULT);
41 #else
42 #error MMIO access is required for baudrates above 115200.
43 #endif
44 #endif
45 }
46
47 void early_uart_init(void)
48 {
49 static const uint16_t legacy_uart_io_port_tab[] = {0x3F8, 0x2F8, 0x3E8, 0x2E8};
50 register int i;
51
52 for (i = SNOWRIDGE_UARTS_TO_INIT - 1; i >= 0; --i) {
53 pci_early_hsuart_device_enable(i, legacy_uart_io_port_tab[i]);
54 }
55 }