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