Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 2 | |
| 3 | #include <console/uart.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 4 | #include <commonlib/helpers.h> |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 5 | #include <device/mmio.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 6 | #include <amdblocks/gpio_banks.h> |
| 7 | #include <amdblocks/acpimmio.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 8 | #include <soc/southbridge.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 9 | #include <soc/gpio.h> |
| 10 | |
| 11 | static const struct _uart_info { |
| 12 | uintptr_t base; |
| 13 | struct soc_amd_gpio mux[2]; |
| 14 | } uart_info[] = { |
| 15 | [0] = { APU_UART0_BASE, { |
| 16 | PAD_NF(GPIO_138, UART0_TXD, PULL_NONE), |
| 17 | PAD_NF(GPIO_136, UART0_RXD, PULL_NONE), |
| 18 | } }, |
| 19 | [1] = { APU_UART1_BASE, { |
| 20 | PAD_NF(GPIO_143, UART1_TXD, PULL_NONE), |
| 21 | PAD_NF(GPIO_141, UART1_RXD, PULL_NONE), |
| 22 | } }, |
| 23 | [2] = { APU_UART2_BASE, { |
| 24 | PAD_NF(GPIO_137, UART2_TXD, PULL_NONE), |
| 25 | PAD_NF(GPIO_135, UART2_RXD, PULL_NONE), |
| 26 | } }, |
| 27 | [3] = { APU_UART3_BASE, { |
| 28 | PAD_NF(GPIO_140, UART3_TXD, PULL_NONE), |
| 29 | PAD_NF(GPIO_142, UART3_RXD, PULL_NONE), |
| 30 | } }, |
| 31 | }; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 32 | |
Furquan Shaikh | ca481ee | 2020-06-13 00:16:26 -0700 | [diff] [blame] | 33 | /* |
Felix Held | 097e449 | 2020-06-16 15:35:20 +0200 | [diff] [blame] | 34 | * Don't provide uart_platform_base and uart_platform_refclk functions if PICASSO_CONSOLE_UART |
Furquan Shaikh | ca481ee | 2020-06-13 00:16:26 -0700 | [diff] [blame] | 35 | * isn't selected. Those two functions are used by the console UART driver and need to be |
| 36 | * provided exactly once and only by the UART that is used for console. |
| 37 | * |
| 38 | * TODO: Replace the #if block by factoring out the two functions into a different compilation |
| 39 | * unit. |
| 40 | */ |
Felix Held | 097e449 | 2020-06-16 15:35:20 +0200 | [diff] [blame] | 41 | #if CONFIG(PICASSO_CONSOLE_UART) |
Furquan Shaikh | ca481ee | 2020-06-13 00:16:26 -0700 | [diff] [blame] | 42 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 43 | uintptr_t uart_platform_base(int idx) |
| 44 | { |
Felix Held | efd23d9 | 2020-06-10 19:39:51 +0200 | [diff] [blame] | 45 | if (idx < 0 || idx >= ARRAY_SIZE(uart_info)) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 46 | return 0; |
| 47 | |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 48 | return uart_info[idx].base; |
| 49 | } |
| 50 | |
Furquan Shaikh | ca481ee | 2020-06-13 00:16:26 -0700 | [diff] [blame] | 51 | unsigned int uart_platform_refclk(void) |
| 52 | { |
| 53 | return CONFIG(PICASSO_UART_48MZ) ? 48000000 : 115200 * 16; |
| 54 | } |
| 55 | |
Felix Held | 097e449 | 2020-06-16 15:35:20 +0200 | [diff] [blame] | 56 | #endif /* PICASSO_CONSOLE_UART */ |
Furquan Shaikh | ca481ee | 2020-06-13 00:16:26 -0700 | [diff] [blame] | 57 | |
Raul E Rangel | 4f5936b | 2020-06-11 16:27:49 -0600 | [diff] [blame] | 58 | void clear_uart_legacy_config(void) |
| 59 | { |
| 60 | write16((void *)FCH_UART_LEGACY_DECODE, 0); |
| 61 | } |
| 62 | |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 63 | void set_uart_config(int idx) |
| 64 | { |
| 65 | uint32_t uart_ctrl; |
| 66 | uint16_t uart_leg; |
| 67 | |
Felix Held | efd23d9 | 2020-06-10 19:39:51 +0200 | [diff] [blame] | 68 | if (idx < 0 || idx >= ARRAY_SIZE(uart_info)) |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 69 | return; |
| 70 | |
| 71 | program_gpios(uart_info[idx].mux, 2); |
| 72 | |
| 73 | if (CONFIG(PICASSO_UART_1_8MZ)) { |
| 74 | uart_ctrl = sm_pci_read32(SMB_UART_CONFIG); |
| 75 | uart_ctrl |= 1 << (SMB_UART_1_8M_SHIFT + idx); |
| 76 | sm_pci_write32(SMB_UART_CONFIG, uart_ctrl); |
| 77 | } |
| 78 | |
| 79 | if (CONFIG(PICASSO_UART_LEGACY) && idx != 3) { |
| 80 | /* Force 3F8 if idx=0, 2F8 if idx=1, 3E8 if idx=2 */ |
| 81 | |
| 82 | /* TODO: make clearer once PPR is updated */ |
| 83 | uart_leg = (idx << 8) | (idx << 10) | (idx << 12) | (idx << 14); |
| 84 | if (idx == 0) |
| 85 | uart_leg |= 1 << FCH_LEGACY_3F8_SH; |
| 86 | else if (idx == 1) |
| 87 | uart_leg |= 1 << FCH_LEGACY_2F8_SH; |
| 88 | else if (idx == 2) |
| 89 | uart_leg |= 1 << FCH_LEGACY_3E8_SH; |
| 90 | |
| 91 | write16((void *)FCH_UART_LEGACY_DECODE, uart_leg); |
| 92 | } |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 93 | } |
| 94 | |
Furquan Shaikh | b07e262 | 2020-06-03 16:50:32 -0700 | [diff] [blame] | 95 | static const char *uart_acpi_name(const struct device *dev) |
| 96 | { |
| 97 | switch (dev->path.mmio.addr) { |
| 98 | case APU_UART0_BASE: |
| 99 | return "FUR0"; |
| 100 | case APU_UART1_BASE: |
| 101 | return "FUR1"; |
| 102 | case APU_UART2_BASE: |
| 103 | return "FUR2"; |
| 104 | case APU_UART3_BASE: |
| 105 | return "FUR3"; |
| 106 | default: |
| 107 | return NULL; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | struct device_operations picasso_uart_mmio_ops = { |
| 112 | .read_resources = noop_read_resources, |
| 113 | .set_resources = noop_set_resources, |
| 114 | .scan_bus = scan_static_bus, |
| 115 | .acpi_name = uart_acpi_name, |
| 116 | }; |