blob: d1ae21cec4f8cdaf1fcdf16625add3a00d876c7b [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>
Felix Helde5d3b4e2021-04-20 00:39:55 +02007#include <device/mmio.h>
Marshall Dawson3edc9e22019-08-16 08:45:20 -06008#include <device/pci.h>
9#include <device/pci_ids.h>
10#include <device/pci_ops.h>
11#include "chip.h"
Raul E Rangel4c7e0d72020-05-07 15:14:09 -060012#include <soc/acp.h>
Marshall Dawson3edc9e22019-08-16 08:45:20 -060013#include <soc/acpi.h>
14#include <soc/pci_devs.h>
Marshall Dawson3edc9e22019-08-16 08:45:20 -060015#include <soc/southbridge.h>
16#include <amdblocks/acpimmio.h>
17#include <commonlib/helpers.h>
18
Felix Held349a1452021-04-20 00:38:32 +020019static void acp_update32(uintptr_t bar, uint32_t reg, uint32_t clear, uint32_t set)
Akshu Agrawal42d4a572019-12-16 15:13:17 +053020{
Felix Helde5d3b4e2021-04-20 00:39:55 +020021 clrsetbits32((void *)(bar + reg), clear, set);
Akshu Agrawal42d4a572019-12-16 15:13:17 +053022}
23
Aaron Durbina6e3b5a2020-06-09 07:56:43 -060024static void init(struct device *dev)
Marshall Dawson3edc9e22019-08-16 08:45:20 -060025{
26 const struct soc_amd_picasso_config *cfg;
Marshall Dawson3edc9e22019-08-16 08:45:20 -060027 struct resource *res;
28 uintptr_t bar;
29
Marshall Dawson3edc9e22019-08-16 08:45:20 -060030 /* Set the proper I2S_PIN_CONFIG state */
Felix Held71800902020-06-17 19:59:53 +020031 cfg = config_of_soc();
Marshall Dawson3edc9e22019-08-16 08:45:20 -060032
33 res = dev->resource_list;
34 if (!res || !res->base) {
35 printk(BIOS_ERR, "Error, unable to configure pin in %s\n", __func__);
36 return;
37 }
38
39 bar = (uintptr_t)res->base;
Furquan Shaikh28980fd2020-07-15 23:19:41 -070040 acp_update32(bar, ACP_I2S_PIN_CONFIG, PIN_CONFIG_MASK, cfg->acp_pin_cfg);
Marshall Dawson3edc9e22019-08-16 08:45:20 -060041
Akshu Agrawal42d4a572019-12-16 15:13:17 +053042 /* Enable ACP_PME_EN and ACP_I2S_WAKE_EN for I2S_WAKE event */
43 acp_update32(bar, ACP_I2S_WAKE_EN, WAKE_EN_MASK, !!cfg->acp_i2s_wake_enable);
Felix Held828a36e2020-09-11 21:45:20 +020044 acp_update32(bar, ACP_PME_EN, PME_EN_MASK, !!cfg->acp_pme_enable);
Marshall Dawson3edc9e22019-08-16 08:45:20 -060045}
46
Furquan Shaikh0d787a12020-06-18 22:20:52 -070047static const char *acp_acpi_name(const struct device *dev)
48{
49 return "ACPD";
50}
51
Marshall Dawson3edc9e22019-08-16 08:45:20 -060052static struct device_operations acp_ops = {
53 .read_resources = pci_dev_read_resources,
54 .set_resources = pci_dev_set_resources,
Aaron Durbina6e3b5a2020-06-09 07:56:43 -060055 .enable_resources = pci_dev_enable_resources,
56 .init = init,
Angel Pons1fc0edd2020-05-31 00:03:28 +020057 .ops_pci = &pci_dev_ops_pci,
Furquan Shaikhde4baff2020-07-16 13:26:44 -070058 .scan_bus = scan_static_bus,
Furquan Shaikh0d787a12020-06-18 22:20:52 -070059 .acpi_name = acp_acpi_name,
Furquan Shaikh0fba23b2020-07-16 13:52:14 -070060 .acpi_fill_ssdt = acpi_device_write_pci_dev,
Marshall Dawson3edc9e22019-08-16 08:45:20 -060061};
62
63static const struct pci_driver acp_driver __pci_driver = {
64 .ops = &acp_ops,
65 .vendor = PCI_VENDOR_ID_AMD,
Furquan Shaikha1cd7eb2020-04-15 23:58:22 -070066 .device = PCI_DEVICE_ID_AMD_FAM17H_ACP,
Marshall Dawson3edc9e22019-08-16 08:45:20 -060067};