blob: 465a44e2b6e0bfbd58e56316ef458d1dee597bee [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marshall Dawson3edc9e22019-08-16 08:45:20 -06002
Furquan Shaikh583ba8b2020-06-30 23:51:24 -07003#include <acpi/acpi_device.h>
4#include <acpi/acpigen.h>
Karthikeyan Ramasubramanian4520aa22021-04-23 11:42:19 -06005#include <amdblocks/acp.h>
6#include <amdblocks/acpimmio.h>
7#include <amdblocks/chip.h>
Marshall Dawson3edc9e22019-08-16 08:45:20 -06008#include <console/console.h>
9#include <device/device.h>
Felix Helde5d3b4e2021-04-20 00:39:55 +020010#include <device/mmio.h>
Marshall Dawson3edc9e22019-08-16 08:45:20 -060011#include <device/pci.h>
12#include <device/pci_ids.h>
13#include <device/pci_ops.h>
Marshall Dawson3edc9e22019-08-16 08:45:20 -060014#include <commonlib/helpers.h>
15
Karthikeyan Ramasubramanian4520aa22021-04-23 11:42:19 -060016/* ACP registers and associated fields */
17#define ACP_I2S_PIN_CONFIG 0x1400 /* HDA, Soundwire, I2S */
18#define PIN_CONFIG_MASK (7 << 0)
19#define ACP_I2S_WAKE_EN 0x1414
20#define WAKE_EN_MASK (1 << 0)
21#define ACP_PME_EN 0x1418
22#define PME_EN_MASK (1 << 0)
23
Felix Held349a1452021-04-20 00:38:32 +020024static void acp_update32(uintptr_t bar, uint32_t reg, uint32_t clear, uint32_t set)
Akshu Agrawal42d4a572019-12-16 15:13:17 +053025{
Felix Helde5d3b4e2021-04-20 00:39:55 +020026 clrsetbits32((void *)(bar + reg), clear, set);
Akshu Agrawal42d4a572019-12-16 15:13:17 +053027}
28
Aaron Durbina6e3b5a2020-06-09 07:56:43 -060029static void init(struct device *dev)
Marshall Dawson3edc9e22019-08-16 08:45:20 -060030{
Karthikeyan Ramasubramanian4520aa22021-04-23 11:42:19 -060031 const struct soc_amd_common_config *cfg = soc_get_common_config();
Marshall Dawson3edc9e22019-08-16 08:45:20 -060032 struct resource *res;
33 uintptr_t bar;
34
Marshall Dawson3edc9e22019-08-16 08:45:20 -060035 res = dev->resource_list;
36 if (!res || !res->base) {
37 printk(BIOS_ERR, "Error, unable to configure pin in %s\n", __func__);
38 return;
39 }
40
Karthikeyan Ramasubramanian4520aa22021-04-23 11:42:19 -060041 /* Set the proper I2S_PIN_CONFIG state */
Marshall Dawson3edc9e22019-08-16 08:45:20 -060042 bar = (uintptr_t)res->base;
Karthikeyan Ramasubramanian4520aa22021-04-23 11:42:19 -060043 acp_update32(bar, ACP_I2S_PIN_CONFIG, PIN_CONFIG_MASK, cfg->acp_config.acp_pin_cfg);
Marshall Dawson3edc9e22019-08-16 08:45:20 -060044
Akshu Agrawal42d4a572019-12-16 15:13:17 +053045 /* Enable ACP_PME_EN and ACP_I2S_WAKE_EN for I2S_WAKE event */
Karthikeyan Ramasubramanian4520aa22021-04-23 11:42:19 -060046 acp_update32(bar, ACP_I2S_WAKE_EN, WAKE_EN_MASK, !!cfg->acp_config.acp_i2s_wake_enable);
47 acp_update32(bar, ACP_PME_EN, PME_EN_MASK, !!cfg->acp_config.acp_pme_enable);
Marshall Dawson3edc9e22019-08-16 08:45:20 -060048}
49
Furquan Shaikh0d787a12020-06-18 22:20:52 -070050static const char *acp_acpi_name(const struct device *dev)
51{
52 return "ACPD";
53}
54
Karthikeyan Ramasubramanian4ce48b32021-05-27 16:25:28 -060055static void acp_fill_wov_method(const struct device *dev)
56{
57 const struct soc_amd_common_config *cfg = soc_get_common_config();
58 const char *scope = acpi_device_path(dev);
59
60 if (!cfg->acp_config.dmic_present || !scope)
61 return;
62
63 /* For ACP DMIC hardware runtime detection on the platform, _WOV method is populated. */
64 acpigen_write_scope(scope); /* Scope */
65 acpigen_write_method("_WOV", 0);
66 acpigen_write_return_integer(1);
67 acpigen_write_method_end();
68 acpigen_write_scope_end();
69}
70
71static void acp_fill_ssdt(const struct device *dev)
72{
73 acpi_device_write_pci_dev(dev);
74 acp_fill_wov_method(dev);
75}
76
Marshall Dawson3edc9e22019-08-16 08:45:20 -060077static struct device_operations acp_ops = {
78 .read_resources = pci_dev_read_resources,
79 .set_resources = pci_dev_set_resources,
Aaron Durbina6e3b5a2020-06-09 07:56:43 -060080 .enable_resources = pci_dev_enable_resources,
81 .init = init,
Angel Pons1fc0edd2020-05-31 00:03:28 +020082 .ops_pci = &pci_dev_ops_pci,
Furquan Shaikhde4baff2020-07-16 13:26:44 -070083 .scan_bus = scan_static_bus,
Furquan Shaikh0d787a12020-06-18 22:20:52 -070084 .acpi_name = acp_acpi_name,
Karthikeyan Ramasubramanian4ce48b32021-05-27 16:25:28 -060085 .acpi_fill_ssdt = acp_fill_ssdt,
Marshall Dawson3edc9e22019-08-16 08:45:20 -060086};
87
88static const struct pci_driver acp_driver __pci_driver = {
89 .ops = &acp_ops,
90 .vendor = PCI_VENDOR_ID_AMD,
Furquan Shaikha1cd7eb2020-04-15 23:58:22 -070091 .device = PCI_DEVICE_ID_AMD_FAM17H_ACP,
Marshall Dawson3edc9e22019-08-16 08:45:20 -060092};