blob: 14a43c18bfe67fed9a6d5eae8b3db14f4b58f5d3 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Martin Roth5c354b92019-04-22 14:55:16 -06003
4#include <console/uart.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -06005#include <commonlib/helpers.h>
Julius Werner55009af2019-12-02 22:03:27 -08006#include <device/mmio.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -06007#include <amdblocks/gpio_banks.h>
8#include <amdblocks/acpimmio.h>
Martin Roth5c354b92019-04-22 14:55:16 -06009#include <soc/southbridge.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060010#include <soc/gpio.h>
11
12static const struct _uart_info {
13 uintptr_t base;
14 struct soc_amd_gpio mux[2];
15} uart_info[] = {
16 [0] = { APU_UART0_BASE, {
17 PAD_NF(GPIO_138, UART0_TXD, PULL_NONE),
18 PAD_NF(GPIO_136, UART0_RXD, PULL_NONE),
19 } },
20 [1] = { APU_UART1_BASE, {
21 PAD_NF(GPIO_143, UART1_TXD, PULL_NONE),
22 PAD_NF(GPIO_141, UART1_RXD, PULL_NONE),
23 } },
24 [2] = { APU_UART2_BASE, {
25 PAD_NF(GPIO_137, UART2_TXD, PULL_NONE),
26 PAD_NF(GPIO_135, UART2_RXD, PULL_NONE),
27 } },
28 [3] = { APU_UART3_BASE, {
29 PAD_NF(GPIO_140, UART3_TXD, PULL_NONE),
30 PAD_NF(GPIO_142, UART3_RXD, PULL_NONE),
31 } },
32};
Martin Roth5c354b92019-04-22 14:55:16 -060033
34uintptr_t uart_platform_base(int idx)
35{
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060036 if (idx < 0 || idx > ARRAY_SIZE(uart_info))
Martin Roth5c354b92019-04-22 14:55:16 -060037 return 0;
38
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060039 return uart_info[idx].base;
40}
41
42void set_uart_config(int idx)
43{
44 uint32_t uart_ctrl;
45 uint16_t uart_leg;
46
47 if (idx < 0 || idx > ARRAY_SIZE(uart_info))
48 return;
49
50 program_gpios(uart_info[idx].mux, 2);
51
52 if (CONFIG(PICASSO_UART_1_8MZ)) {
53 uart_ctrl = sm_pci_read32(SMB_UART_CONFIG);
54 uart_ctrl |= 1 << (SMB_UART_1_8M_SHIFT + idx);
55 sm_pci_write32(SMB_UART_CONFIG, uart_ctrl);
56 }
57
58 if (CONFIG(PICASSO_UART_LEGACY) && idx != 3) {
59 /* Force 3F8 if idx=0, 2F8 if idx=1, 3E8 if idx=2 */
60
61 /* TODO: make clearer once PPR is updated */
62 uart_leg = (idx << 8) | (idx << 10) | (idx << 12) | (idx << 14);
63 if (idx == 0)
64 uart_leg |= 1 << FCH_LEGACY_3F8_SH;
65 else if (idx == 1)
66 uart_leg |= 1 << FCH_LEGACY_2F8_SH;
67 else if (idx == 2)
68 uart_leg |= 1 << FCH_LEGACY_3E8_SH;
69
70 write16((void *)FCH_UART_LEGACY_DECODE, uart_leg);
71 }
Martin Roth5c354b92019-04-22 14:55:16 -060072}
73
74unsigned int uart_platform_refclk(void)
75{
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060076 return CONFIG(PICASSO_UART_48MZ) ? 48000000 : 115200 * 16;
Martin Roth5c354b92019-04-22 14:55:16 -060077}