blob: d892333ca1c84c81c1ed81ec01b0e52090b82389 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Martin Roth5c354b92019-04-22 14:55:16 -06002
Raul E Rangel34fb9392020-06-11 16:57:23 -06003#include <acpi/acpigen.h>
Raul E Rangel34fb9392020-06-11 16:57:23 -06004#include <console/console.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -06005#include <commonlib/helpers.h>
Julius Werner55009af2019-12-02 22:03:27 -08006#include <device/mmio.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -06007#include <amdblocks/gpio_banks.h>
8#include <amdblocks/acpimmio.h>
Martin Roth5c354b92019-04-22 14:55:16 -06009#include <soc/southbridge.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060010#include <soc/gpio.h>
Felix Held9412b3e2020-06-18 15:54:43 +020011#include <soc/uart.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060012
13static const struct _uart_info {
14 uintptr_t base;
15 struct soc_amd_gpio mux[2];
16} uart_info[] = {
17 [0] = { APU_UART0_BASE, {
18 PAD_NF(GPIO_138, UART0_TXD, PULL_NONE),
19 PAD_NF(GPIO_136, UART0_RXD, PULL_NONE),
20 } },
21 [1] = { APU_UART1_BASE, {
22 PAD_NF(GPIO_143, UART1_TXD, PULL_NONE),
23 PAD_NF(GPIO_141, UART1_RXD, PULL_NONE),
24 } },
25 [2] = { APU_UART2_BASE, {
26 PAD_NF(GPIO_137, UART2_TXD, PULL_NONE),
27 PAD_NF(GPIO_135, UART2_RXD, PULL_NONE),
28 } },
29 [3] = { APU_UART3_BASE, {
30 PAD_NF(GPIO_140, UART3_TXD, PULL_NONE),
31 PAD_NF(GPIO_142, UART3_RXD, PULL_NONE),
32 } },
33};
Martin Roth5c354b92019-04-22 14:55:16 -060034
Felix Held9412b3e2020-06-18 15:54:43 +020035uintptr_t get_uart_base(int idx)
Martin Roth5c354b92019-04-22 14:55:16 -060036{
Felix Heldefd23d92020-06-10 19:39:51 +020037 if (idx < 0 || idx >= ARRAY_SIZE(uart_info))
Martin Roth5c354b92019-04-22 14:55:16 -060038 return 0;
39
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060040 return uart_info[idx].base;
41}
42
Raul E Rangel4f5936b2020-06-11 16:27:49 -060043void clear_uart_legacy_config(void)
44{
45 write16((void *)FCH_UART_LEGACY_DECODE, 0);
46}
47
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060048void set_uart_config(int idx)
49{
50 uint32_t uart_ctrl;
51 uint16_t uart_leg;
52
Felix Heldefd23d92020-06-10 19:39:51 +020053 if (idx < 0 || idx >= ARRAY_SIZE(uart_info))
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060054 return;
55
56 program_gpios(uart_info[idx].mux, 2);
57
58 if (CONFIG(PICASSO_UART_1_8MZ)) {
59 uart_ctrl = sm_pci_read32(SMB_UART_CONFIG);
60 uart_ctrl |= 1 << (SMB_UART_1_8M_SHIFT + idx);
61 sm_pci_write32(SMB_UART_CONFIG, uart_ctrl);
62 }
63
64 if (CONFIG(PICASSO_UART_LEGACY) && idx != 3) {
65 /* Force 3F8 if idx=0, 2F8 if idx=1, 3E8 if idx=2 */
66
67 /* TODO: make clearer once PPR is updated */
68 uart_leg = (idx << 8) | (idx << 10) | (idx << 12) | (idx << 14);
69 if (idx == 0)
70 uart_leg |= 1 << FCH_LEGACY_3F8_SH;
71 else if (idx == 1)
72 uart_leg |= 1 << FCH_LEGACY_2F8_SH;
73 else if (idx == 2)
74 uart_leg |= 1 << FCH_LEGACY_3E8_SH;
75
76 write16((void *)FCH_UART_LEGACY_DECODE, uart_leg);
77 }
Martin Roth5c354b92019-04-22 14:55:16 -060078}
79
Furquan Shaikhb07e2622020-06-03 16:50:32 -070080static const char *uart_acpi_name(const struct device *dev)
81{
82 switch (dev->path.mmio.addr) {
83 case APU_UART0_BASE:
84 return "FUR0";
85 case APU_UART1_BASE:
86 return "FUR1";
87 case APU_UART2_BASE:
88 return "FUR2";
89 case APU_UART3_BASE:
90 return "FUR3";
91 default:
92 return NULL;
93 }
94}
95
Raul E Rangel34fb9392020-06-11 16:57:23 -060096/* Even though this is called enable, it gets called for both enabled and disabled devices. */
97static void uart_enable(struct device *dev)
98{
99 int dev_id;
100
101 switch (dev->path.mmio.addr) {
102 case APU_UART0_BASE:
103 dev_id = FCH_AOAC_DEV_UART0;
104 break;
105 case APU_UART1_BASE:
106 dev_id = FCH_AOAC_DEV_UART1;
107 break;
108 case APU_UART2_BASE:
109 dev_id = FCH_AOAC_DEV_UART2;
110 break;
111 case APU_UART3_BASE:
112 dev_id = FCH_AOAC_DEV_UART3;
113 break;
114 default:
115 printk(BIOS_ERR, "%s: Unknown device: %s\n", __func__, dev_path(dev));
116 return;
117 }
118
119 if (dev->enabled) {
120 power_on_aoac_device(dev_id);
121 wait_for_aoac_enabled(dev_id);
122 } else {
123 power_off_aoac_device(dev_id);
124 }
125}
126
127/* This gets called for both enabled and disabled devices. */
128static void uart_inject_ssdt(const struct device *dev)
129{
130 acpigen_write_scope(acpi_device_path(dev));
131
132 acpigen_write_STA(acpi_device_status(dev));
133
134 acpigen_pop_len(); /* Scope */
135}
136
Furquan Shaikhb07e2622020-06-03 16:50:32 -0700137struct device_operations picasso_uart_mmio_ops = {
138 .read_resources = noop_read_resources,
139 .set_resources = noop_set_resources,
140 .scan_bus = scan_static_bus,
141 .acpi_name = uart_acpi_name,
Raul E Rangel34fb9392020-06-11 16:57:23 -0600142 .enable = uart_enable,
143 .acpi_fill_ssdt = uart_inject_ssdt,
Furquan Shaikhb07e2622020-06-03 16:50:32 -0700144};