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> |
Felix Held | 7255966 | 2021-01-13 03:37:21 +0100 | [diff] [blame] | 6 | #include <device/device.h> |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 7 | #include <device/mmio.h> |
Marshall Dawson | c0b8d0d | 2019-06-20 10:29:29 -0600 | [diff] [blame] | 8 | #include <amdblocks/gpio_banks.h> |
Felix Held | 6443ad4 | 2020-11-30 18:18:35 +0100 | [diff] [blame] | 9 | #include <amdblocks/aoac.h> |
Felix Held | 0ad9733 | 2021-01-12 23:29:30 +0100 | [diff] [blame] | 10 | #include <amdblocks/uart.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 | |
| 56 | program_gpios(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 | |
| 106 | /* This gets called for both enabled and disabled devices. */ |
| 107 | static void uart_inject_ssdt(const struct device *dev) |
| 108 | { |
| 109 | acpigen_write_scope(acpi_device_path(dev)); |
| 110 | |
| 111 | acpigen_write_STA(acpi_device_status(dev)); |
| 112 | |
| 113 | acpigen_pop_len(); /* Scope */ |
| 114 | } |
| 115 | |
Furquan Shaikh | b07e262 | 2020-06-03 16:50:32 -0700 | [diff] [blame] | 116 | struct device_operations picasso_uart_mmio_ops = { |
| 117 | .read_resources = noop_read_resources, |
| 118 | .set_resources = noop_set_resources, |
| 119 | .scan_bus = scan_static_bus, |
| 120 | .acpi_name = uart_acpi_name, |
Raul E Rangel | 34fb939 | 2020-06-11 16:57:23 -0600 | [diff] [blame] | 121 | .enable = uart_enable, |
| 122 | .acpi_fill_ssdt = uart_inject_ssdt, |
Furquan Shaikh | b07e262 | 2020-06-03 16:50:32 -0700 | [diff] [blame] | 123 | }; |