Angel Pons | ba38f37 | 2020-04-05 15:46:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 3 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Kyösti Mälkki | 5daa1d3 | 2020-06-14 12:01:58 +0300 | [diff] [blame] | 5 | #include <acpi/acpi_gnvs.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/pci.h> |
| 9 | #include <device/pci_ids.h> |
| 10 | #include <reg_script.h> |
| 11 | |
| 12 | #include <soc/iomap.h> |
| 13 | #include <soc/iosf.h> |
| 14 | #include <soc/lpc.h> |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 15 | #include <soc/device_nvs.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 16 | #include <soc/pattrs.h> |
| 17 | #include <soc/pci_devs.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 18 | #include <soc/pm.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 19 | #include <soc/ramstage.h> |
| 20 | #include "chip.h" |
| 21 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 22 | /* |
| 23 | * The LPE audio devices needs 1MiB of memory reserved aligned to a 512MiB |
| 24 | * address. Just take 1MiB @ 512MiB. |
| 25 | */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 26 | #define FIRMWARE_PHYS_BASE (512 << 20) |
Matt DeVillier | 83ef07a | 2018-01-21 16:37:24 -0600 | [diff] [blame] | 27 | #define FIRMWARE_PHYS_LENGTH (2 << 20) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 28 | #define FIRMWARE_PCI_REG_BASE 0xa8 |
| 29 | #define FIRMWARE_PCI_REG_LENGTH 0xac |
| 30 | #define FIRMWARE_REG_BASE_C0 0x144000 |
| 31 | #define FIRMWARE_REG_LENGTH_C0 (FIRMWARE_REG_BASE_C0 + 4) |
| 32 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 33 | static void assign_device_nvs(struct device *dev, u32 *field, |
| 34 | unsigned int index) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 35 | { |
| 36 | struct resource *res; |
| 37 | |
Angel Pons | c1bfbe0 | 2021-11-03 13:18:53 +0100 | [diff] [blame] | 38 | res = probe_resource(dev, index); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 39 | if (res) |
| 40 | *field = res->base; |
| 41 | } |
| 42 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 43 | static void lpe_enable_acpi_mode(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 44 | { |
| 45 | static const struct reg_script ops[] = { |
| 46 | /* Disable PCI interrupt, enable Memory and Bus Master */ |
Elyes HAOUAS | 066e61f | 2020-04-29 10:28:20 +0200 | [diff] [blame] | 47 | REG_PCI_OR16(PCI_COMMAND, |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 48 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INT_DISABLE), |
| 49 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 50 | /* Enable ACPI mode */ |
| 51 | REG_IOSF_OR(IOSF_PORT_0x58, LPE_PCICFGCTR1, |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 52 | LPE_PCICFGCTR1_PCI_CFG_DIS | LPE_PCICFGCTR1_ACPI_INT_EN), |
| 53 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 54 | REG_SCRIPT_END |
| 55 | }; |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 56 | struct device_nvs *dev_nvs = acpi_get_device_nvs(); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 57 | |
| 58 | /* Save BAR0, BAR1, and firmware base to ACPI NVS */ |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 59 | assign_device_nvs(dev, &dev_nvs->lpe_bar0, PCI_BASE_ADDRESS_0); |
| 60 | assign_device_nvs(dev, &dev_nvs->lpe_bar1, PCI_BASE_ADDRESS_2); |
| 61 | assign_device_nvs(dev, &dev_nvs->lpe_fw, FIRMWARE_PCI_REG_BASE); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 62 | |
| 63 | /* Device is enabled in ACPI mode */ |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 64 | dev_nvs->lpe_en = 1; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 65 | |
| 66 | /* Put device in ACPI mode */ |
| 67 | reg_script_run_on_dev(dev, ops); |
| 68 | } |
| 69 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 70 | static void setup_codec_clock(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 71 | { |
| 72 | uint32_t reg; |
| 73 | u32 *clk_reg; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 74 | struct soc_intel_braswell_config *config; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 75 | const char *freq_str; |
| 76 | |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame] | 77 | config = config_of(dev); |
fdurairx | aff502e | 2015-08-21 15:36:53 -0700 | [diff] [blame] | 78 | switch (config->lpe_codec_clk_src) { |
| 79 | case LPE_CLK_SRC_XTAL: |
| 80 | /* XTAL driven bit2=0 */ |
| 81 | freq_str = "19.2MHz External Crystal"; |
| 82 | reg = CLK_SRC_XTAL; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 83 | break; |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 84 | |
fdurairx | aff502e | 2015-08-21 15:36:53 -0700 | [diff] [blame] | 85 | case LPE_CLK_SRC_PLL: |
| 86 | /* PLL driven bit2=1 */ |
| 87 | freq_str = "19.2MHz PLL"; |
| 88 | reg = CLK_SRC_PLL; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 89 | break; |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 90 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 91 | default: |
fdurairx | aff502e | 2015-08-21 15:36:53 -0700 | [diff] [blame] | 92 | reg = CLK_SRC_XTAL; |
| 93 | printk(BIOS_DEBUG, "LPE codec clock default to using Crystal\n"); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 94 | return; |
| 95 | } |
| 96 | |
| 97 | /* Default to always running. */ |
| 98 | reg |= CLK_CTL_ON; |
| 99 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 100 | printk(BIOS_DEBUG, "LPE Audio codec clock set to %sMHz.\n", freq_str); |
| 101 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 102 | clk_reg = (u32 *)(PMC_BASE_ADDRESS + PLT_CLK_CTL_0); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 103 | |
| 104 | write32(clk_reg, (read32(clk_reg) & ~0x7) | reg); |
| 105 | } |
| 106 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 107 | static void lpe_stash_firmware_info(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 108 | { |
| 109 | struct resource *res; |
| 110 | struct resource *mmio; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 111 | |
Angel Pons | c1bfbe0 | 2021-11-03 13:18:53 +0100 | [diff] [blame] | 112 | res = probe_resource(dev, FIRMWARE_PCI_REG_BASE); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 113 | if (res == NULL) { |
| 114 | printk(BIOS_DEBUG, "LPE Firmware memory not found.\n"); |
| 115 | return; |
| 116 | } |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 117 | printk(BIOS_DEBUG, "LPE FW Resource: 0x%08x\n", (u32)res->base); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 118 | |
| 119 | /* Continue using old way of informing firmware address / size. */ |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 120 | pci_write_config32(dev, FIRMWARE_PCI_REG_BASE, res->base); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 121 | pci_write_config32(dev, FIRMWARE_PCI_REG_LENGTH, res->size); |
| 122 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 123 | /* Also put the address in MMIO space like on C0 BTM */ |
| 124 | mmio = find_resource(dev, PCI_BASE_ADDRESS_0); |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 125 | write32((void *)(uintptr_t)(mmio->base + FIRMWARE_REG_BASE_C0), res->base); |
| 126 | write32((void *)(uintptr_t)(mmio->base + FIRMWARE_REG_LENGTH_C0), res->size); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 129 | static void lpe_init(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 130 | { |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame] | 131 | struct soc_intel_braswell_config *config = config_of(dev); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 132 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 133 | lpe_stash_firmware_info(dev); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 134 | setup_codec_clock(dev); |
| 135 | |
| 136 | if (config->lpe_acpi_mode) |
| 137 | lpe_enable_acpi_mode(dev); |
| 138 | } |
| 139 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 140 | static void lpe_read_resources(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 141 | { |
Matt DeVillier | 5d6ab45 | 2018-01-17 19:39:52 -0600 | [diff] [blame] | 142 | struct resource *res; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 143 | pci_dev_read_resources(dev); |
| 144 | |
Matt DeVillier | 5d6ab45 | 2018-01-17 19:39:52 -0600 | [diff] [blame] | 145 | /* |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 146 | * Allocate the BAR1 resource at index 2 to fulfill the Windows driver |
Matt DeVillier | 5d6ab45 | 2018-01-17 19:39:52 -0600 | [diff] [blame] | 147 | * interface requirements even though the PCI device has only one BAR |
| 148 | */ |
| 149 | res = new_resource(dev, PCI_BASE_ADDRESS_2); |
| 150 | res->base = 0; |
| 151 | res->size = 0x1000; |
| 152 | res->limit = 0xffffffff; |
| 153 | res->gran = 12; |
| 154 | res->align = 12; |
| 155 | res->flags = IORESOURCE_MEM; |
| 156 | |
Arthur Heymans | 43169fe | 2023-07-05 11:49:59 +0200 | [diff] [blame^] | 157 | reserved_ram_range(dev, FIRMWARE_PCI_REG_BASE, FIRMWARE_PHYS_BASE, |
| 158 | FIRMWARE_PHYS_LENGTH); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 161 | static void lpe_set_resources(struct device *dev) |
Matt DeVillier | 5d6ab45 | 2018-01-17 19:39:52 -0600 | [diff] [blame] | 162 | { |
| 163 | struct resource *res; |
| 164 | |
Angel Pons | c1bfbe0 | 2021-11-03 13:18:53 +0100 | [diff] [blame] | 165 | res = probe_resource(dev, PCI_BASE_ADDRESS_2); |
Matt DeVillier | 5d6ab45 | 2018-01-17 19:39:52 -0600 | [diff] [blame] | 166 | if (res != NULL) |
| 167 | res->flags |= IORESOURCE_STORED; |
| 168 | |
| 169 | pci_dev_set_resources(dev); |
| 170 | } |
| 171 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 172 | static const struct device_operations device_ops = { |
| 173 | .read_resources = lpe_read_resources, |
Matt DeVillier | 5d6ab45 | 2018-01-17 19:39:52 -0600 | [diff] [blame] | 174 | .set_resources = lpe_set_resources, |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 175 | .enable_resources = pci_dev_enable_resources, |
| 176 | .init = lpe_init, |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 177 | .ops_pci = &soc_pci_ops, |
| 178 | }; |
| 179 | |
| 180 | static const struct pci_driver southcluster __pci_driver = { |
| 181 | .ops = &device_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 182 | .vendor = PCI_VID_INTEL, |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 183 | .device = LPE_DEVID, |
| 184 | }; |