blob: 08dbd5538f7a9fac331d957d95ff3a4f8ebf3466 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass4a56f102015-01-27 22:13:47 -07002/*
3 * Copyright (C) 2015 Google, Inc
Simon Glass4a56f102015-01-27 22:13:47 -07004 */
5
6#include <common.h>
7#include <errno.h>
8#include <asm/io.h>
9
10#define PCI_DEV_CONFIG(segbus, dev, fn) ( \
11 (((segbus) & 0xfff) << 20) | \
12 (((dev) & 0x1f) << 15) | \
13 (((fn) & 0x07) << 12))
14
15/* Platform Controller Unit */
16#define LPC_DEV 0x1f
17#define LPC_FUNC 0
18
19/* Enable UART */
20#define UART_CONT 0x80
21
22/* SCORE Pad definitions */
23#define UART_RXD_PAD 82
24#define UART_TXD_PAD 83
25
26/* Pad base: PAD_CONF0[n]= PAD_BASE + 16 * n */
27#define GPSCORE_PAD_BASE (IO_BASE_ADDRESS + IO_BASE_OFFSET_GPSCORE)
28
29/* IO Memory */
30#define IO_BASE_ADDRESS 0xfed0c000
31#define IO_BASE_OFFSET_GPSCORE 0x0000
32#define IO_BASE_OFFSET_GPNCORE 0x1000
33#define IO_BASE_OFFSET_GPSSUS 0x2000
34#define IO_BASE_SIZE 0x4000
35
36static inline unsigned int score_pconf0(int pad_num)
37{
38 return GPSCORE_PAD_BASE + pad_num * 16;
39}
40
41static void score_select_func(int pad, int func)
42{
43 uint32_t reg;
44 uint32_t pconf0_addr = score_pconf0(pad);
45
46 reg = readl(pconf0_addr);
47 reg &= ~0x7;
48 reg |= func & 0x7;
49 writel(reg, pconf0_addr);
50}
51
Simon Glass240d06d2015-03-05 12:25:15 -070052static void x86_pci_write_config32(int dev, unsigned int where, u32 value)
Simon Glass4a56f102015-01-27 22:13:47 -070053{
54 unsigned long addr;
55
56 addr = CONFIG_PCIE_ECAM_BASE | dev | (where & ~3);
57 writel(value, addr);
58}
59
60/* This can be called after memory-mapped PCI is working */
Stefan Roesea377b7c2016-01-19 14:24:12 +010061int setup_internal_uart(int enable)
Simon Glass4a56f102015-01-27 22:13:47 -070062{
Stefan Roesea377b7c2016-01-19 14:24:12 +010063 /* Enable or disable the legacy UART hardware */
Simon Glass240d06d2015-03-05 12:25:15 -070064 x86_pci_write_config32(PCI_DEV_CONFIG(0, LPC_DEV, LPC_FUNC), UART_CONT,
Stefan Roesea377b7c2016-01-19 14:24:12 +010065 enable);
66
67 /* All done for the disable part, so just return */
68 if (!enable)
69 return 0;
Simon Glass4a56f102015-01-27 22:13:47 -070070
71 /*
72 * Set up the pads to the UART function. This allows the signals to
73 * leave the chip
74 */
75 score_select_func(UART_RXD_PAD, 1);
76 score_select_func(UART_TXD_PAD, 1);
77
78 /* TODO(sjg@chromium.org): Call debug_uart_init() */
79
80 return 0;
81}
Bin Meng273d0ec2017-06-01 03:41:13 -070082
83void board_debug_uart_init(void)
84{
85 setup_internal_uart(1);
86}