blob: 2ef19792333653660d11bd19107aea56cdc1faaa [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>
Felix Held2e800032020-09-12 01:28:46 +020012#include <types.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060013
14static const struct _uart_info {
15 uintptr_t base;
16 struct soc_amd_gpio mux[2];
17} uart_info[] = {
18 [0] = { APU_UART0_BASE, {
19 PAD_NF(GPIO_138, UART0_TXD, PULL_NONE),
20 PAD_NF(GPIO_136, UART0_RXD, PULL_NONE),
21 } },
22 [1] = { APU_UART1_BASE, {
23 PAD_NF(GPIO_143, UART1_TXD, PULL_NONE),
24 PAD_NF(GPIO_141, UART1_RXD, PULL_NONE),
25 } },
26 [2] = { APU_UART2_BASE, {
27 PAD_NF(GPIO_137, UART2_TXD, PULL_NONE),
28 PAD_NF(GPIO_135, UART2_RXD, PULL_NONE),
29 } },
30 [3] = { APU_UART3_BASE, {
31 PAD_NF(GPIO_140, UART3_TXD, PULL_NONE),
32 PAD_NF(GPIO_142, UART3_RXD, PULL_NONE),
33 } },
34};
Martin Roth5c354b92019-04-22 14:55:16 -060035
Felix Held83951652020-09-11 14:53:03 +020036uintptr_t get_uart_base(unsigned int idx)
Martin Roth5c354b92019-04-22 14:55:16 -060037{
Felix Held83951652020-09-11 14:53:03 +020038 if (idx >= ARRAY_SIZE(uart_info))
Martin Roth5c354b92019-04-22 14:55:16 -060039 return 0;
40
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060041 return uart_info[idx].base;
42}
43
Raul E Rangel4f5936b2020-06-11 16:27:49 -060044void clear_uart_legacy_config(void)
45{
46 write16((void *)FCH_UART_LEGACY_DECODE, 0);
47}
48
Felix Held83951652020-09-11 14:53:03 +020049void set_uart_config(unsigned int idx)
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060050{
51 uint32_t uart_ctrl;
52 uint16_t uart_leg;
53
Felix Held83951652020-09-11 14:53:03 +020054 if (idx >= ARRAY_SIZE(uart_info))
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060055 return;
56
57 program_gpios(uart_info[idx].mux, 2);
58
59 if (CONFIG(PICASSO_UART_1_8MZ)) {
60 uart_ctrl = sm_pci_read32(SMB_UART_CONFIG);
61 uart_ctrl |= 1 << (SMB_UART_1_8M_SHIFT + idx);
62 sm_pci_write32(SMB_UART_CONFIG, uart_ctrl);
63 }
64
65 if (CONFIG(PICASSO_UART_LEGACY) && idx != 3) {
66 /* Force 3F8 if idx=0, 2F8 if idx=1, 3E8 if idx=2 */
67
68 /* TODO: make clearer once PPR is updated */
69 uart_leg = (idx << 8) | (idx << 10) | (idx << 12) | (idx << 14);
70 if (idx == 0)
71 uart_leg |= 1 << FCH_LEGACY_3F8_SH;
72 else if (idx == 1)
73 uart_leg |= 1 << FCH_LEGACY_2F8_SH;
74 else if (idx == 2)
75 uart_leg |= 1 << FCH_LEGACY_3E8_SH;
76
77 write16((void *)FCH_UART_LEGACY_DECODE, uart_leg);
78 }
Martin Roth5c354b92019-04-22 14:55:16 -060079}
80
Furquan Shaikhb07e2622020-06-03 16:50:32 -070081static const char *uart_acpi_name(const struct device *dev)
82{
83 switch (dev->path.mmio.addr) {
84 case APU_UART0_BASE:
85 return "FUR0";
86 case APU_UART1_BASE:
87 return "FUR1";
88 case APU_UART2_BASE:
89 return "FUR2";
90 case APU_UART3_BASE:
91 return "FUR3";
92 default:
93 return NULL;
94 }
95}
96
Raul E Rangel34fb9392020-06-11 16:57:23 -060097/* Even though this is called enable, it gets called for both enabled and disabled devices. */
98static void uart_enable(struct device *dev)
99{
Felix Held26170732020-09-12 01:30:25 +0200100 unsigned int dev_id;
Raul E Rangel34fb9392020-06-11 16:57:23 -0600101
102 switch (dev->path.mmio.addr) {
103 case APU_UART0_BASE:
104 dev_id = FCH_AOAC_DEV_UART0;
105 break;
106 case APU_UART1_BASE:
107 dev_id = FCH_AOAC_DEV_UART1;
108 break;
109 case APU_UART2_BASE:
110 dev_id = FCH_AOAC_DEV_UART2;
111 break;
112 case APU_UART3_BASE:
113 dev_id = FCH_AOAC_DEV_UART3;
114 break;
115 default:
116 printk(BIOS_ERR, "%s: Unknown device: %s\n", __func__, dev_path(dev));
117 return;
118 }
119
120 if (dev->enabled) {
121 power_on_aoac_device(dev_id);
122 wait_for_aoac_enabled(dev_id);
123 } else {
124 power_off_aoac_device(dev_id);
125 }
126}
127
128/* This gets called for both enabled and disabled devices. */
129static void uart_inject_ssdt(const struct device *dev)
130{
131 acpigen_write_scope(acpi_device_path(dev));
132
133 acpigen_write_STA(acpi_device_status(dev));
134
135 acpigen_pop_len(); /* Scope */
136}
137
Furquan Shaikhb07e2622020-06-03 16:50:32 -0700138struct device_operations picasso_uart_mmio_ops = {
139 .read_resources = noop_read_resources,
140 .set_resources = noop_set_resources,
141 .scan_bus = scan_static_bus,
142 .acpi_name = uart_acpi_name,
Raul E Rangel34fb9392020-06-11 16:57:23 -0600143 .enable = uart_enable,
144 .acpi_fill_ssdt = uart_inject_ssdt,
Furquan Shaikhb07e2622020-06-03 16:50:32 -0700145};