blob: 5763a5b17cbfeaa85e07a9791f65a9f41cf490c1 [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 <console/console.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -06004#include <commonlib/helpers.h>
Felix Held72559662021-01-13 03:37:21 +01005#include <device/device.h>
Julius Werner55009af2019-12-02 22:03:27 -08006#include <device/mmio.h>
Felix Helddea4e0f2021-09-22 20:05:53 +02007#include <amdblocks/gpio.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>
Felix Held038ed9e2021-06-15 16:24:10 +020010#include <soc/aoac_defs.h>
Martin Roth5c354b92019-04-22 14:55:16 -060011#include <soc/southbridge.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060012#include <soc/gpio.h>
Felix Held9412b3e2020-06-18 15:54:43 +020013#include <soc/uart.h>
Felix Held2e800032020-09-12 01:28:46 +020014#include <types.h>
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060015
Felix Heldf3777132021-01-14 00:58:53 +010016static const struct {
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060017 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 Roth5c354b92019-04-22 14:55:16 -060037
Felix Held83951652020-09-11 14:53:03 +020038uintptr_t get_uart_base(unsigned int idx)
Martin Roth5c354b92019-04-22 14:55:16 -060039{
Felix Held83951652020-09-11 14:53:03 +020040 if (idx >= ARRAY_SIZE(uart_info))
Martin Roth5c354b92019-04-22 14:55:16 -060041 return 0;
42
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060043 return uart_info[idx].base;
44}
45
Raul E Rangel4f5936b2020-06-11 16:27:49 -060046void clear_uart_legacy_config(void)
47{
Rob Barnes28cb14b2020-01-30 10:54:28 -070048 write16((void *)FCH_LEGACY_UART_DECODE, 0);
49}
50
Felix Held83951652020-09-11 14:53:03 +020051void set_uart_config(unsigned int idx)
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060052{
Felix Held83951652020-09-11 14:53:03 +020053 if (idx >= ARRAY_SIZE(uart_info))
Marshall Dawsonc0b8d0d2019-06-20 10:29:29 -060054 return;
55
Felix Held7011fa12021-09-22 16:36:12 +020056 gpio_configure_pads(uart_info[idx].mux, 2);
Martin Roth5c354b92019-04-22 14:55:16 -060057}
58
Furquan Shaikhb07e2622020-06-03 16:50:32 -070059static 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 Rangel34fb9392020-06-11 16:57:23 -060075/* Even though this is called enable, it gets called for both enabled and disabled devices. */
76static void uart_enable(struct device *dev)
77{
Felix Held26170732020-09-12 01:30:25 +020078 unsigned int dev_id;
Raul E Rangel34fb9392020-06-11 16:57:23 -060079
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
Felix Heldad6f87d2021-10-12 23:35:48 +0200106static void uart_read_resources(struct device *dev)
107{
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300108 mmio_resource_kb(dev, 0, dev->path.mmio.addr / KiB, 4);
Felix Heldad6f87d2021-10-12 23:35:48 +0200109}
110
Furquan Shaikhb07e2622020-06-03 16:50:32 -0700111struct device_operations picasso_uart_mmio_ops = {
Felix Heldad6f87d2021-10-12 23:35:48 +0200112 .read_resources = uart_read_resources,
Furquan Shaikhb07e2622020-06-03 16:50:32 -0700113 .set_resources = noop_set_resources,
114 .scan_bus = scan_static_bus,
115 .acpi_name = uart_acpi_name,
Raul E Rangel34fb9392020-06-11 16:57:23 -0600116 .enable = uart_enable,
117 .acpi_fill_ssdt = uart_inject_ssdt,
Furquan Shaikhb07e2622020-06-03 16:50:32 -0700118};