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 | |
Raul E Rangel | 34fb939 | 2020-06-11 16:57:23 -0600 | [diff] [blame] | 3 | #include <console/console.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 4 | #include <commonlib/helpers.h> |
Felix Held | 7255966 | 2021-01-13 03:37:21 +0100 | [diff] [blame] | 5 | #include <device/device.h> |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 6 | #include <device/mmio.h> |
Felix Held | dea4e0f | 2021-09-22 20:05:53 +0200 | [diff] [blame] | 7 | #include <amdblocks/gpio.h> |
Felix Held | 6443ad4 | 2020-11-30 18:18:35 +0100 | [diff] [blame] | 8 | #include <amdblocks/aoac.h> |
Felix Held | 0ad9733 | 2021-01-12 23:29:30 +0100 | [diff] [blame] | 9 | #include <amdblocks/uart.h> |
Felix Held | 038ed9e | 2021-06-15 16:24:10 +0200 | [diff] [blame] | 10 | #include <soc/aoac_defs.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 11 | #include <soc/southbridge.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 12 | #include <soc/gpio.h> |
Felix Held | 9412b3e | 2020-06-18 15:54:43 +0200 | [diff] [blame] | 13 | #include <soc/uart.h> |
Felix Held | 2e80003 | 2020-09-12 01:28:46 +0200 | [diff] [blame] | 14 | #include <types.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 15 | |
Felix Held | f377713 | 2021-01-14 00:58:53 +0100 | [diff] [blame] | 16 | static const struct { |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 17 | uintptr_t base; |
| 18 | struct soc_amd_gpio mux[2]; |
| 19 | } uart_info[] = { |
| 20 | [0] = { APU_UART0_BASE, { |
| 21 | PAD_NF(GPIO_138, UART0_TXD, PULL_NONE), |
| 22 | PAD_NF(GPIO_136, UART0_RXD, PULL_NONE), |
| 23 | } }, |
| 24 | [1] = { APU_UART1_BASE, { |
| 25 | PAD_NF(GPIO_143, UART1_TXD, PULL_NONE), |
| 26 | PAD_NF(GPIO_141, UART1_RXD, PULL_NONE), |
| 27 | } }, |
| 28 | [2] = { APU_UART2_BASE, { |
| 29 | PAD_NF(GPIO_137, UART2_TXD, PULL_NONE), |
| 30 | PAD_NF(GPIO_135, UART2_RXD, PULL_NONE), |
| 31 | } }, |
| 32 | [3] = { APU_UART3_BASE, { |
| 33 | PAD_NF(GPIO_140, UART3_TXD, PULL_NONE), |
| 34 | PAD_NF(GPIO_142, UART3_RXD, PULL_NONE), |
| 35 | } }, |
| 36 | }; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 37 | |
Felix Held | 8395165 | 2020-09-11 14:53:03 +0200 | [diff] [blame] | 38 | uintptr_t get_uart_base(unsigned int idx) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 39 | { |
Felix Held | 8395165 | 2020-09-11 14:53:03 +0200 | [diff] [blame] | 40 | if (idx >= ARRAY_SIZE(uart_info)) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 41 | return 0; |
| 42 | |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 43 | return uart_info[idx].base; |
| 44 | } |
| 45 | |
Raul E Rangel | 4f5936b | 2020-06-11 16:27:49 -0600 | [diff] [blame] | 46 | void clear_uart_legacy_config(void) |
| 47 | { |
Rob Barnes | 28cb14b | 2020-01-30 10:54:28 -0700 | [diff] [blame] | 48 | write16((void *)FCH_LEGACY_UART_DECODE, 0); |
| 49 | } |
| 50 | |
Felix Held | 8395165 | 2020-09-11 14:53:03 +0200 | [diff] [blame] | 51 | void set_uart_config(unsigned int idx) |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 52 | { |
Felix Held | 8395165 | 2020-09-11 14:53:03 +0200 | [diff] [blame] | 53 | if (idx >= ARRAY_SIZE(uart_info)) |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 54 | return; |
| 55 | |
Felix Held | 7011fa1 | 2021-09-22 16:36:12 +0200 | [diff] [blame] | 56 | gpio_configure_pads(uart_info[idx].mux, 2); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 57 | } |
| 58 | |
Furquan Shaikh | b07e262 | 2020-06-03 16:50:32 -0700 | [diff] [blame] | 59 | static const char *uart_acpi_name(const struct device *dev) |
| 60 | { |
| 61 | switch (dev->path.mmio.addr) { |
| 62 | case APU_UART0_BASE: |
| 63 | return "FUR0"; |
| 64 | case APU_UART1_BASE: |
| 65 | return "FUR1"; |
| 66 | case APU_UART2_BASE: |
| 67 | return "FUR2"; |
| 68 | case APU_UART3_BASE: |
| 69 | return "FUR3"; |
| 70 | default: |
| 71 | return NULL; |
| 72 | } |
| 73 | } |
| 74 | |
Raul E Rangel | 34fb939 | 2020-06-11 16:57:23 -0600 | [diff] [blame] | 75 | /* Even though this is called enable, it gets called for both enabled and disabled devices. */ |
| 76 | static void uart_enable(struct device *dev) |
| 77 | { |
Felix Held | 2617073 | 2020-09-12 01:30:25 +0200 | [diff] [blame] | 78 | unsigned int dev_id; |
Raul E Rangel | 34fb939 | 2020-06-11 16:57:23 -0600 | [diff] [blame] | 79 | |
| 80 | switch (dev->path.mmio.addr) { |
| 81 | case APU_UART0_BASE: |
| 82 | dev_id = FCH_AOAC_DEV_UART0; |
| 83 | break; |
| 84 | case APU_UART1_BASE: |
| 85 | dev_id = FCH_AOAC_DEV_UART1; |
| 86 | break; |
| 87 | case APU_UART2_BASE: |
| 88 | dev_id = FCH_AOAC_DEV_UART2; |
| 89 | break; |
| 90 | case APU_UART3_BASE: |
| 91 | dev_id = FCH_AOAC_DEV_UART3; |
| 92 | break; |
| 93 | default: |
| 94 | printk(BIOS_ERR, "%s: Unknown device: %s\n", __func__, dev_path(dev)); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | if (dev->enabled) { |
| 99 | power_on_aoac_device(dev_id); |
| 100 | wait_for_aoac_enabled(dev_id); |
| 101 | } else { |
| 102 | power_off_aoac_device(dev_id); |
| 103 | } |
| 104 | } |
| 105 | |
Felix Held | ad6f87d | 2021-10-12 23:35:48 +0200 | [diff] [blame] | 106 | static void uart_read_resources(struct device *dev) |
| 107 | { |
| 108 | mmio_resource(dev, 0, dev->path.mmio.addr / KiB, 4); |
| 109 | } |
| 110 | |
Furquan Shaikh | b07e262 | 2020-06-03 16:50:32 -0700 | [diff] [blame] | 111 | struct device_operations picasso_uart_mmio_ops = { |
Felix Held | ad6f87d | 2021-10-12 23:35:48 +0200 | [diff] [blame] | 112 | .read_resources = uart_read_resources, |
Furquan Shaikh | b07e262 | 2020-06-03 16:50:32 -0700 | [diff] [blame] | 113 | .set_resources = noop_set_resources, |
| 114 | .scan_bus = scan_static_bus, |
| 115 | .acpi_name = uart_acpi_name, |
Raul E Rangel | 34fb939 | 2020-06-11 16:57:23 -0600 | [diff] [blame] | 116 | .enable = uart_enable, |
| 117 | .acpi_fill_ssdt = uart_inject_ssdt, |
Furquan Shaikh | b07e262 | 2020-06-03 16:50:32 -0700 | [diff] [blame] | 118 | }; |