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