blob: 89bdd4ed0a0d267896ec411f25ebbac081339ae7 [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
Akshu Agrawal42d4a572019-12-16 15:13:17 +053018static void acp_update32(uintptr_t bar, uint32_t reg, uint32_t and_mask, uint32_t or_mask)
19{
20 uint32_t val;
21
22 val = read32((void *)(bar + reg));
23 val &= ~and_mask;
24 val |= or_mask;
25 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);
48 acp_update32(bar, ACP_PME_EN, PME_EN_MASK, !!cfg->acpi_pme_enable);
49
Marshall Dawson3edc9e22019-08-16 08:45:20 -060050 if (cfg->acp_pin_cfg == I2S_PINS_I2S_TDM)
51 sb_clk_output_48Mhz(); /* Internal connection to I2S */
52}
53
Furquan Shaikh0d787a12020-06-18 22:20:52 -070054static const char *acp_acpi_name(const struct device *dev)
55{
56 return "ACPD";
57}
58
Furquan Shaikh583ba8b2020-06-30 23:51:24 -070059#define AMD_I2S_ACPI_NAME "I2SM"
60#define AMD_I2S_ACPI_HID "AMDI5682"
61#define AMD_I2S_ACPI_DESC "I2S machine driver"
62
63static void acp_fill_i2s_machine_dev(const struct device *dev)
64{
65 const char *scope = acpi_device_path(dev);
66 const struct soc_amd_picasso_config *cfg = config_of_soc();
67 const struct acpi_gpio *dmic_select_gpio = &cfg->dmic_select_gpio;
68 struct acpi_dp *dsd;
69
70 if (dmic_select_gpio->pin_count == 0)
71 return;
72
73 acpigen_write_scope(scope); /* Scope */
74 acpigen_write_device(AMD_I2S_ACPI_NAME); /* Device */
75 acpigen_write_name_string("_HID", AMD_I2S_ACPI_HID);
76 acpigen_write_name_integer("_UID", 1);
77 acpigen_write_name_string("_DDN", AMD_I2S_ACPI_DESC);
78
79 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
80
81 /* Resources */
82 acpigen_write_name("_CRS");
83 acpigen_write_resourcetemplate_header();
84 acpi_device_write_gpio(dmic_select_gpio);
85 acpigen_write_resourcetemplate_footer();
86
87 dsd = acpi_dp_new_table("_DSD");
88 /*
89 * This GPIO is used to select DMIC0 or DMIC1 by the kernel driver. It does not
90 * really have a polarity since low and high control the selection of DMIC and
91 * hence does not have an active polarity.
92 * Kernel driver does not use the polarity field and instead treats the GPIO
93 * selection as follows:
94 * Set low (0) = Select DMIC0
95 * Set high (1) = Select DMIC1
96 */
97 acpi_dp_add_gpio(dsd, "dmic-gpios", acpi_device_path_join(dev, AMD_I2S_ACPI_NAME),
98 0, /* Index = 0 (There is a single GPIO entry in _CRS). */
99 0, /* Pin = 0 (There is a single pin in the GPIO resource). */
100 0); /* Active low = 0 (Kernel driver does not use active polarity). */
101 acpi_dp_write(dsd);
102
103 acpigen_pop_len(); /* Device */
104 acpigen_pop_len(); /* Scope */
105}
106
107static void acp_fill_ssdt(const struct device *dev)
108{
109 acpi_device_write_pci_dev(dev);
110 acp_fill_i2s_machine_dev(dev);
111}
112
Marshall Dawson3edc9e22019-08-16 08:45:20 -0600113static struct device_operations acp_ops = {
114 .read_resources = pci_dev_read_resources,
115 .set_resources = pci_dev_set_resources,
Aaron Durbina6e3b5a2020-06-09 07:56:43 -0600116 .enable_resources = pci_dev_enable_resources,
117 .init = init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200118 .ops_pci = &pci_dev_ops_pci,
Furquan Shaikhde4baff2020-07-16 13:26:44 -0700119 .scan_bus = scan_static_bus,
Furquan Shaikh0d787a12020-06-18 22:20:52 -0700120 .acpi_name = acp_acpi_name,
Furquan Shaikh583ba8b2020-06-30 23:51:24 -0700121 .acpi_fill_ssdt = acp_fill_ssdt,
Marshall Dawson3edc9e22019-08-16 08:45:20 -0600122};
123
124static const struct pci_driver acp_driver __pci_driver = {
125 .ops = &acp_ops,
126 .vendor = PCI_VENDOR_ID_AMD,
Furquan Shaikha1cd7eb2020-04-15 23:58:22 -0700127 .device = PCI_DEVICE_ID_AMD_FAM17H_ACP,
Marshall Dawson3edc9e22019-08-16 08:45:20 -0600128};