blob: 822c48a119780718db28a91e215f643128948a18 [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>
Marshall Dawson3edc9e22019-08-16 08:45:20 -06005#include <console/console.h>
6#include <device/device.h>
7#include <device/pci.h>
8#include <device/pci_ids.h>
9#include <device/pci_ops.h>
10#include "chip.h"
Raul E Rangel4c7e0d72020-05-07 15:14:09 -060011#include <soc/acp.h>
Marshall Dawson3edc9e22019-08-16 08:45:20 -060012#include <soc/acpi.h>
13#include <soc/pci_devs.h>
Marshall Dawson3edc9e22019-08-16 08:45:20 -060014#include <soc/southbridge.h>
15#include <amdblocks/acpimmio.h>
16#include <commonlib/helpers.h>
17
Felix Held349a1452021-04-20 00:38:32 +020018static void acp_update32(uintptr_t bar, uint32_t reg, uint32_t clear, uint32_t set)
Akshu Agrawal42d4a572019-12-16 15:13:17 +053019{
20 uint32_t val;
21
22 val = read32((void *)(bar + reg));
Felix Held349a1452021-04-20 00:38:32 +020023 val &= ~clear;
24 val |= set;
Akshu Agrawal42d4a572019-12-16 15:13:17 +053025 write32((void *)(bar + reg), val);
26}
27
Aaron Durbina6e3b5a2020-06-09 07:56:43 -060028static void init(struct device *dev)
Marshall Dawson3edc9e22019-08-16 08:45:20 -060029{
30 const struct soc_amd_picasso_config *cfg;
Marshall Dawson3edc9e22019-08-16 08:45:20 -060031 struct resource *res;
32 uintptr_t bar;
33
Marshall Dawson3edc9e22019-08-16 08:45:20 -060034 /* Set the proper I2S_PIN_CONFIG state */
Felix Held71800902020-06-17 19:59:53 +020035 cfg = config_of_soc();
Marshall Dawson3edc9e22019-08-16 08:45:20 -060036
37 res = dev->resource_list;
38 if (!res || !res->base) {
39 printk(BIOS_ERR, "Error, unable to configure pin in %s\n", __func__);
40 return;
41 }
42
43 bar = (uintptr_t)res->base;
Furquan Shaikh28980fd2020-07-15 23:19:41 -070044 acp_update32(bar, ACP_I2S_PIN_CONFIG, PIN_CONFIG_MASK, cfg->acp_pin_cfg);
Marshall Dawson3edc9e22019-08-16 08:45:20 -060045
Akshu Agrawal42d4a572019-12-16 15:13:17 +053046 /* Enable ACP_PME_EN and ACP_I2S_WAKE_EN for I2S_WAKE event */
47 acp_update32(bar, ACP_I2S_WAKE_EN, WAKE_EN_MASK, !!cfg->acp_i2s_wake_enable);
Felix Held828a36e2020-09-11 21:45:20 +020048 acp_update32(bar, ACP_PME_EN, PME_EN_MASK, !!cfg->acp_pme_enable);
Marshall Dawson3edc9e22019-08-16 08:45:20 -060049}
50
Furquan Shaikh0d787a12020-06-18 22:20:52 -070051static const char *acp_acpi_name(const struct device *dev)
52{
53 return "ACPD";
54}
55
Marshall Dawson3edc9e22019-08-16 08:45:20 -060056static struct device_operations acp_ops = {
57 .read_resources = pci_dev_read_resources,
58 .set_resources = pci_dev_set_resources,
Aaron Durbina6e3b5a2020-06-09 07:56:43 -060059 .enable_resources = pci_dev_enable_resources,
60 .init = init,
Angel Pons1fc0edd2020-05-31 00:03:28 +020061 .ops_pci = &pci_dev_ops_pci,
Furquan Shaikhde4baff2020-07-16 13:26:44 -070062 .scan_bus = scan_static_bus,
Furquan Shaikh0d787a12020-06-18 22:20:52 -070063 .acpi_name = acp_acpi_name,
Furquan Shaikh0fba23b2020-07-16 13:52:14 -070064 .acpi_fill_ssdt = acpi_device_write_pci_dev,
Marshall Dawson3edc9e22019-08-16 08:45:20 -060065};
66
67static const struct pci_driver acp_driver __pci_driver = {
68 .ops = &acp_ops,
69 .vendor = PCI_VENDOR_ID_AMD,
Furquan Shaikha1cd7eb2020-04-15 23:58:22 -070070 .device = PCI_DEVICE_ID_AMD_FAM17H_ACP,
Marshall Dawson3edc9e22019-08-16 08:45:20 -060071};