blob: f46daed4c2f7e1f3e8afb802f8f55c9d11ea4ae6 [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>
Felix Held6443ad42020-11-30 18:18:35 +01008#include <amdblocks/aoac.h>
Felix Held0ad97332021-01-12 23:29:30 +01009#include <amdblocks/uart.h>
Martin Roth5c354b92019-04-22 14:55:16 -060010#include <soc/southbridge.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060011#include <soc/gpio.h>
Felix Held9412b3e2020-06-18 15:54:43 +020012#include <soc/uart.h>
Felix Held2e800032020-09-12 01:28:46 +020013#include <types.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060014
15static 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 Roth5c354b92019-04-22 14:55:16 -060036
Felix Held83951652020-09-11 14:53:03 +020037uintptr_t get_uart_base(unsigned int idx)
Martin Roth5c354b92019-04-22 14:55:16 -060038{
Felix Held83951652020-09-11 14:53:03 +020039 if (idx >= ARRAY_SIZE(uart_info))
Martin Roth5c354b92019-04-22 14:55:16 -060040 return 0;
41
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060042 return uart_info[idx].base;
43}
44
Raul E Rangel4f5936b2020-06-11 16:27:49 -060045void clear_uart_legacy_config(void)
46{
Rob Barnes28cb14b2020-01-30 10:54:28 -070047 write16((void *)FCH_LEGACY_UART_DECODE, 0);
48}
49
Felix Held83951652020-09-11 14:53:03 +020050void set_uart_config(unsigned int idx)
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060051{
Felix Held83951652020-09-11 14:53:03 +020052 if (idx >= ARRAY_SIZE(uart_info))
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060053 return;
54
55 program_gpios(uart_info[idx].mux, 2);
Martin Roth5c354b92019-04-22 14:55:16 -060056}
57
Furquan Shaikhb07e2622020-06-03 16:50:32 -070058static 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 Rangel34fb9392020-06-11 16:57:23 -060074/* Even though this is called enable, it gets called for both enabled and disabled devices. */
75static void uart_enable(struct device *dev)
76{
Felix Held26170732020-09-12 01:30:25 +020077 unsigned int dev_id;
Raul E Rangel34fb9392020-06-11 16:57:23 -060078
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. */
106static 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 Shaikhb07e2622020-06-03 16:50:32 -0700115struct 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 Rangel34fb9392020-06-11 16:57:23 -0600120 .enable = uart_enable,
121 .acpi_fill_ssdt = uart_inject_ssdt,
Furquan Shaikhb07e2622020-06-03 16:50:32 -0700122};