Felix Held | 8a3d4d5 | 2021-01-13 03:06:21 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Felix Held | 2e4fa0c | 2021-01-13 03:16:03 +0100 | [diff] [blame] | 3 | #include <amdblocks/aoac.h> |
Felix Held | dea4e0f | 2021-09-22 20:05:53 +0200 | [diff] [blame] | 4 | #include <amdblocks/gpio.h> |
Felix Held | 8a3d4d5 | 2021-01-13 03:06:21 +0100 | [diff] [blame] | 5 | #include <amdblocks/uart.h> |
| 6 | #include <commonlib/helpers.h> |
Felix Held | 2e4fa0c | 2021-01-13 03:16:03 +0100 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | #include <device/device.h> |
Felix Held | 8a3d4d5 | 2021-01-13 03:06:21 +0100 | [diff] [blame] | 9 | #include <device/mmio.h> |
Felix Held | 117823e | 2021-06-15 16:33:29 +0200 | [diff] [blame] | 10 | #include <soc/aoac_defs.h> |
Felix Held | 8a3d4d5 | 2021-01-13 03:06:21 +0100 | [diff] [blame] | 11 | #include <soc/gpio.h> |
| 12 | #include <soc/southbridge.h> |
| 13 | #include <soc/uart.h> |
| 14 | #include <types.h> |
| 15 | |
Felix Held | f377713 | 2021-01-14 00:58:53 +0100 | [diff] [blame] | 16 | static const struct { |
Felix Held | 8a3d4d5 | 2021-01-13 03:06:21 +0100 | [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_143, UART0_TXD, PULL_NONE), |
| 22 | PAD_NF(GPIO_141, UART0_RXD, PULL_NONE), |
| 23 | } }, |
| 24 | [1] = { APU_UART1_BASE, { |
| 25 | PAD_NF(GPIO_140, UART1_TXD, PULL_NONE), |
| 26 | PAD_NF(GPIO_142, UART1_RXD, PULL_NONE), |
| 27 | } }, |
| 28 | }; |
| 29 | |
| 30 | uintptr_t get_uart_base(unsigned int idx) |
| 31 | { |
| 32 | if (idx >= ARRAY_SIZE(uart_info)) |
| 33 | return 0; |
| 34 | |
| 35 | return uart_info[idx].base; |
| 36 | } |
| 37 | |
| 38 | void clear_uart_legacy_config(void) |
| 39 | { |
| 40 | write16((void *)FCH_LEGACY_UART_DECODE, 0); |
| 41 | } |
| 42 | |
| 43 | void set_uart_config(unsigned int idx) |
| 44 | { |
| 45 | if (idx >= ARRAY_SIZE(uart_info)) |
| 46 | return; |
| 47 | |
Felix Held | 7011fa1 | 2021-09-22 16:36:12 +0200 | [diff] [blame] | 48 | gpio_configure_pads(uart_info[idx].mux, 2); |
Felix Held | 8a3d4d5 | 2021-01-13 03:06:21 +0100 | [diff] [blame] | 49 | } |
Felix Held | 2e4fa0c | 2021-01-13 03:16:03 +0100 | [diff] [blame] | 50 | |
Felix Held | 63d2008 | 2021-02-16 01:35:27 +0100 | [diff] [blame] | 51 | static const char *uart_acpi_name(const struct device *dev) |
| 52 | { |
| 53 | switch (dev->path.mmio.addr) { |
| 54 | case APU_UART0_BASE: |
| 55 | return "FUR0"; |
| 56 | case APU_UART1_BASE: |
| 57 | return "FUR1"; |
| 58 | default: |
| 59 | return NULL; |
| 60 | } |
| 61 | } |
| 62 | |
Felix Held | 2e4fa0c | 2021-01-13 03:16:03 +0100 | [diff] [blame] | 63 | /* Even though this is called enable, it gets called for both enabled and disabled devices. */ |
| 64 | static void uart_enable(struct device *dev) |
| 65 | { |
| 66 | unsigned int dev_id; |
| 67 | |
| 68 | switch (dev->path.mmio.addr) { |
| 69 | case APU_UART0_BASE: |
| 70 | dev_id = FCH_AOAC_DEV_UART0; |
| 71 | break; |
| 72 | case APU_UART1_BASE: |
| 73 | dev_id = FCH_AOAC_DEV_UART1; |
| 74 | break; |
| 75 | default: |
| 76 | printk(BIOS_ERR, "%s: Unknown device: %s\n", __func__, dev_path(dev)); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if (dev->enabled) { |
| 81 | power_on_aoac_device(dev_id); |
| 82 | wait_for_aoac_enabled(dev_id); |
| 83 | } else { |
| 84 | power_off_aoac_device(dev_id); |
| 85 | } |
| 86 | } |
| 87 | |
Felix Held | ad6f87d | 2021-10-12 23:35:48 +0200 | [diff] [blame] | 88 | static void uart_read_resources(struct device *dev) |
| 89 | { |
| 90 | mmio_resource(dev, 0, dev->path.mmio.addr / KiB, 4); |
| 91 | } |
| 92 | |
Felix Held | 2e4fa0c | 2021-01-13 03:16:03 +0100 | [diff] [blame] | 93 | struct device_operations cezanne_uart_mmio_ops = { |
Felix Held | ad6f87d | 2021-10-12 23:35:48 +0200 | [diff] [blame] | 94 | .read_resources = uart_read_resources, |
Felix Held | 2e4fa0c | 2021-01-13 03:16:03 +0100 | [diff] [blame] | 95 | .set_resources = noop_set_resources, |
| 96 | .scan_bus = scan_static_bus, |
| 97 | .enable = uart_enable, |
Felix Held | 63d2008 | 2021-02-16 01:35:27 +0100 | [diff] [blame] | 98 | .acpi_name = uart_acpi_name, |
| 99 | .acpi_fill_ssdt = uart_inject_ssdt, |
Felix Held | 2e4fa0c | 2021-01-13 03:16:03 +0100 | [diff] [blame] | 100 | }; |