Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <console/uart.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 16 | #include <commonlib/helpers.h> |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 17 | #include <device/mmio.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 18 | #include <amdblocks/gpio_banks.h> |
| 19 | #include <amdblocks/acpimmio.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 20 | #include <soc/southbridge.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 21 | #include <soc/gpio.h> |
| 22 | |
| 23 | static const struct _uart_info { |
| 24 | uintptr_t base; |
| 25 | struct soc_amd_gpio mux[2]; |
| 26 | } uart_info[] = { |
| 27 | [0] = { APU_UART0_BASE, { |
| 28 | PAD_NF(GPIO_138, UART0_TXD, PULL_NONE), |
| 29 | PAD_NF(GPIO_136, UART0_RXD, PULL_NONE), |
| 30 | } }, |
| 31 | [1] = { APU_UART1_BASE, { |
| 32 | PAD_NF(GPIO_143, UART1_TXD, PULL_NONE), |
| 33 | PAD_NF(GPIO_141, UART1_RXD, PULL_NONE), |
| 34 | } }, |
| 35 | [2] = { APU_UART2_BASE, { |
| 36 | PAD_NF(GPIO_137, UART2_TXD, PULL_NONE), |
| 37 | PAD_NF(GPIO_135, UART2_RXD, PULL_NONE), |
| 38 | } }, |
| 39 | [3] = { APU_UART3_BASE, { |
| 40 | PAD_NF(GPIO_140, UART3_TXD, PULL_NONE), |
| 41 | PAD_NF(GPIO_142, UART3_RXD, PULL_NONE), |
| 42 | } }, |
| 43 | }; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 44 | |
| 45 | uintptr_t uart_platform_base(int idx) |
| 46 | { |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 47 | if (idx < 0 || idx > ARRAY_SIZE(uart_info)) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 48 | return 0; |
| 49 | |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 50 | return uart_info[idx].base; |
| 51 | } |
| 52 | |
| 53 | void set_uart_config(int idx) |
| 54 | { |
| 55 | uint32_t uart_ctrl; |
| 56 | uint16_t uart_leg; |
| 57 | |
| 58 | if (idx < 0 || idx > ARRAY_SIZE(uart_info)) |
| 59 | return; |
| 60 | |
| 61 | program_gpios(uart_info[idx].mux, 2); |
| 62 | |
| 63 | if (CONFIG(PICASSO_UART_1_8MZ)) { |
| 64 | uart_ctrl = sm_pci_read32(SMB_UART_CONFIG); |
| 65 | uart_ctrl |= 1 << (SMB_UART_1_8M_SHIFT + idx); |
| 66 | sm_pci_write32(SMB_UART_CONFIG, uart_ctrl); |
| 67 | } |
| 68 | |
| 69 | if (CONFIG(PICASSO_UART_LEGACY) && idx != 3) { |
| 70 | /* Force 3F8 if idx=0, 2F8 if idx=1, 3E8 if idx=2 */ |
| 71 | |
| 72 | /* TODO: make clearer once PPR is updated */ |
| 73 | uart_leg = (idx << 8) | (idx << 10) | (idx << 12) | (idx << 14); |
| 74 | if (idx == 0) |
| 75 | uart_leg |= 1 << FCH_LEGACY_3F8_SH; |
| 76 | else if (idx == 1) |
| 77 | uart_leg |= 1 << FCH_LEGACY_2F8_SH; |
| 78 | else if (idx == 2) |
| 79 | uart_leg |= 1 << FCH_LEGACY_3E8_SH; |
| 80 | |
| 81 | write16((void *)FCH_UART_LEGACY_DECODE, uart_leg); |
| 82 | } |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | unsigned int uart_platform_refclk(void) |
| 86 | { |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 87 | return CONFIG(PICASSO_UART_48MZ) ? 48000000 : 115200 * 16; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 88 | } |