Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 2 | |
Furquan Shaikh | 583ba8b | 2020-06-30 23:51:24 -0700 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpigen.h> |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 5 | #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 Rangel | 4c7e0d7 | 2020-05-07 15:14:09 -0600 | [diff] [blame] | 11 | #include <soc/acp.h> |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 12 | #include <soc/acpi.h> |
| 13 | #include <soc/pci_devs.h> |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 14 | #include <soc/southbridge.h> |
| 15 | #include <amdblocks/acpimmio.h> |
| 16 | #include <commonlib/helpers.h> |
| 17 | |
Akshu Agrawal | 42d4a57 | 2019-12-16 15:13:17 +0530 | [diff] [blame] | 18 | static 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 Durbin | a6e3b5a | 2020-06-09 07:56:43 -0600 | [diff] [blame] | 28 | static void init(struct device *dev) |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 29 | { |
| 30 | const struct soc_amd_picasso_config *cfg; |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 31 | struct resource *res; |
| 32 | uintptr_t bar; |
| 33 | |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 34 | /* Set the proper I2S_PIN_CONFIG state */ |
Felix Held | 7180090 | 2020-06-17 19:59:53 +0200 | [diff] [blame] | 35 | cfg = config_of_soc(); |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 36 | |
| 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 Shaikh | 28980fd | 2020-07-15 23:19:41 -0700 | [diff] [blame] | 44 | acp_update32(bar, ACP_I2S_PIN_CONFIG, PIN_CONFIG_MASK, cfg->acp_pin_cfg); |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 45 | |
Akshu Agrawal | 42d4a57 | 2019-12-16 15:13:17 +0530 | [diff] [blame] | 46 | /* 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 Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 50 | if (cfg->acp_pin_cfg == I2S_PINS_I2S_TDM) |
| 51 | sb_clk_output_48Mhz(); /* Internal connection to I2S */ |
| 52 | } |
| 53 | |
Furquan Shaikh | 0d787a1 | 2020-06-18 22:20:52 -0700 | [diff] [blame] | 54 | static const char *acp_acpi_name(const struct device *dev) |
| 55 | { |
| 56 | return "ACPD"; |
| 57 | } |
| 58 | |
Furquan Shaikh | 583ba8b | 2020-06-30 23:51:24 -0700 | [diff] [blame] | 59 | #define AMD_I2S_ACPI_NAME "I2SM" |
| 60 | #define AMD_I2S_ACPI_HID "AMDI5682" |
| 61 | #define AMD_I2S_ACPI_DESC "I2S machine driver" |
| 62 | |
| 63 | static 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 | |
| 107 | static 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 Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 113 | static struct device_operations acp_ops = { |
| 114 | .read_resources = pci_dev_read_resources, |
| 115 | .set_resources = pci_dev_set_resources, |
Aaron Durbin | a6e3b5a | 2020-06-09 07:56:43 -0600 | [diff] [blame] | 116 | .enable_resources = pci_dev_enable_resources, |
| 117 | .init = init, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 118 | .ops_pci = &pci_dev_ops_pci, |
Furquan Shaikh | de4baff | 2020-07-16 13:26:44 -0700 | [diff] [blame^] | 119 | .scan_bus = scan_static_bus, |
Furquan Shaikh | 0d787a1 | 2020-06-18 22:20:52 -0700 | [diff] [blame] | 120 | .acpi_name = acp_acpi_name, |
Furquan Shaikh | 583ba8b | 2020-06-30 23:51:24 -0700 | [diff] [blame] | 121 | .acpi_fill_ssdt = acp_fill_ssdt, |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | static const struct pci_driver acp_driver __pci_driver = { |
| 125 | .ops = &acp_ops, |
| 126 | .vendor = PCI_VENDOR_ID_AMD, |
Furquan Shaikh | a1cd7eb | 2020-04-15 23:58:22 -0700 | [diff] [blame] | 127 | .device = PCI_DEVICE_ID_AMD_FAM17H_ACP, |
Marshall Dawson | 3edc9e2 | 2019-08-16 08:45:20 -0600 | [diff] [blame] | 128 | }; |