Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 3 | |
| 4 | #include <console/uart.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 5 | #include <commonlib/helpers.h> |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 6 | #include <device/mmio.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 7 | #include <amdblocks/gpio_banks.h> |
| 8 | #include <amdblocks/acpimmio.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 9 | #include <soc/southbridge.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 10 | #include <soc/gpio.h> |
| 11 | |
| 12 | static 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 Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 33 | |
| 34 | uintptr_t uart_platform_base(int idx) |
| 35 | { |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 36 | if (idx < 0 || idx > ARRAY_SIZE(uart_info)) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 37 | return 0; |
| 38 | |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 39 | return uart_info[idx].base; |
| 40 | } |
| 41 | |
| 42 | void 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 Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | unsigned int uart_platform_refclk(void) |
| 75 | { |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 76 | return CONFIG(PICASSO_UART_48MZ) ? 48000000 : 115200 * 16; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 77 | } |