blob: 8b28d28d13663163ffa6cd15ea98a6f6775b0a95 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng68a070b2017-08-15 22:41:58 -07002/*
3 * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
Bin Meng68a070b2017-08-15 22:41:58 -07004 */
5
Bin Meng68a070b2017-08-15 22:41:58 -07006#include <asm/io.h>
7
8#define PCI_DEV_CONFIG(segbus, dev, fn) ( \
9 (((segbus) & 0xfff) << 20) | \
10 (((dev) & 0x1f) << 15) | \
11 (((fn) & 0x07) << 12))
12
13/* Platform Controller Unit */
14#define LPC_DEV 0x1f
15#define LPC_FUNC 0
16
17/* Enable UART */
18#define UART_CONT 0x80
19
20/* UART PAD definitions */
21#define UART_RXD_COMMUITY 1
22#define UART_TXD_COMMUITY 1
23#define UART_RXD_FAMILY 4
24#define UART_TXD_FAMILY 4
25#define UART_RXD_PAD 2
26#define UART_TXD_PAD 7
27#define UART_RXD_FUNC 3
28#define UART_TXD_FUNC 3
29
30/* IO Memory */
31#define IO_BASE_ADDRESS 0xfed80000
32
33static inline uint32_t gpio_pconf0(int community, int family, int pad)
34{
35 return IO_BASE_ADDRESS + community * 0x8000 + 0x4400 +
36 family * 0x400 + pad * 8;
37}
38
39static void gpio_select_func(int community, int family, int pad, int func)
40{
41 uint32_t pconf0_addr = gpio_pconf0(community, family, pad);
42
43 clrsetbits_le32(pconf0_addr, 0xf << 16, func << 16);
44}
45
46static void x86_pci_write_config32(int dev, unsigned int where, u32 value)
47{
48 unsigned long addr;
49
50 addr = CONFIG_PCIE_ECAM_BASE | dev | (where & ~3);
51 writel(value, addr);
52}
53
54/* This can be called after memory-mapped PCI is working */
55int setup_internal_uart(int enable)
56{
57 /* Enable or disable the legacy UART hardware */
58 x86_pci_write_config32(PCI_DEV_CONFIG(0, LPC_DEV, LPC_FUNC), UART_CONT,
59 enable);
60
61 /* All done for the disable part, so just return */
62 if (!enable)
63 return 0;
64
65 /*
66 * Set up the pads to the UART function. This allows the signals to
67 * leave the chip
68 */
69 gpio_select_func(UART_RXD_COMMUITY, UART_RXD_FAMILY,
70 UART_RXD_PAD, UART_RXD_FUNC);
71 gpio_select_func(UART_TXD_COMMUITY, UART_TXD_FAMILY,
72 UART_TXD_PAD, UART_TXD_FUNC);
73
74 return 0;
75}
76
77void board_debug_uart_init(void)
78{
79 setup_internal_uart(1);
80}