blob: 897f9c4ee355f894058d53551060e1328eeca1d0 [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Laurie61680272014-05-05 12:42:35 -05002
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +03003#include <acpi/acpi_gnvs.h>
Duncan Laurie61680272014-05-05 12:42:35 -05004#include <console/console.h>
5#include <device/device.h>
6#include <device/pci.h>
7#include <device/pci_ids.h>
8#include <device/pci_ops.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02009#include <device/mmio.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070010#include <soc/adsp.h>
11#include <soc/device_nvs.h>
12#include <soc/iobp.h>
13#include <soc/nvs.h>
14#include <soc/pch.h>
15#include <soc/ramstage.h>
16#include <soc/rcba.h>
17#include <soc/intel/broadwell/chip.h>
Duncan Laurie61680272014-05-05 12:42:35 -050018
19static void adsp_init(struct device *dev)
20{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +030021 config_t *config = config_of(dev);
Duncan Laurie61680272014-05-05 12:42:35 -050022 struct resource *bar0, *bar1;
23 u32 tmp32;
24
25 /* Ensure memory and bus master are enabled */
Elyes HAOUASb887adf2020-04-29 10:42:34 +020026 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Duncan Laurie61680272014-05-05 12:42:35 -050027
28 /* Find BAR0 and BAR1 */
29 bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
30 if (!bar0)
31 return;
32 bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
33 if (!bar1)
34 return;
35
36 /*
37 * Set LTR value in DSP shim LTR control register to 3ms
38 * SNOOP_REQ[13]=1b SNOOP_SCALE[12:10]=100b (1ms) SNOOP_VAL[9:0]=3h
39 */
40 tmp32 = pch_is_wpt() ? ADSP_SHIM_BASE_WPT : ADSP_SHIM_BASE_LPT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080041 write32(res2mmio(bar0, tmp32 + ADSP_SHIM_LTRC, 0),
42 ADSP_SHIM_LTRC_VALUE);
Duncan Laurie61680272014-05-05 12:42:35 -050043
44 /* Program VDRTCTL2 D19:F0:A8[31:0] = 0x00000fff */
45 pci_write_config32(dev, ADSP_PCI_VDRTCTL2, ADSP_VDRTCTL2_VALUE);
46
47 /* Program ADSP IOBP VDLDAT1 to 0x040100 */
48 pch_iobp_write(ADSP_IOBP_VDLDAT1, ADSP_VDLDAT1_VALUE);
49
50 /* Set D3 Power Gating Enable in D19:F0:A0 based on PCH type */
51 tmp32 = pci_read_config32(dev, ADSP_PCI_VDRTCTL0);
Duncan Lauried9f95072014-10-01 13:47:20 -070052 if (pch_is_wpt()) {
53 if (config->adsp_d3_pg_enable) {
54 tmp32 &= ~ADSP_VDRTCTL0_D3PGD_WPT;
55 if (config->adsp_sram_pg_enable)
56 tmp32 &= ~ADSP_VDRTCTL0_D3SRAMPGD_WPT;
57 else
58 tmp32 |= ADSP_VDRTCTL0_D3SRAMPGD_WPT;
Duncan Laurie3ed4d392014-07-31 10:41:56 -070059 } else {
Duncan Lauried9f95072014-10-01 13:47:20 -070060 tmp32 |= ADSP_VDRTCTL0_D3PGD_WPT;
Duncan Laurie3ed4d392014-07-31 10:41:56 -070061 }
Duncan Laurie61680272014-05-05 12:42:35 -050062 } else {
Duncan Lauried9f95072014-10-01 13:47:20 -070063 if (config->adsp_d3_pg_enable) {
Duncan Laurie3ed4d392014-07-31 10:41:56 -070064 tmp32 &= ~ADSP_VDRTCTL0_D3PGD_LPT;
Duncan Lauried9f95072014-10-01 13:47:20 -070065 if (config->adsp_sram_pg_enable)
66 tmp32 &= ~ADSP_VDRTCTL0_D3SRAMPGD_LPT;
67 else
68 tmp32 |= ADSP_VDRTCTL0_D3SRAMPGD_LPT;
69 } else {
70 tmp32 |= ADSP_VDRTCTL0_D3PGD_LPT;
Duncan Laurie3ed4d392014-07-31 10:41:56 -070071 }
Duncan Laurie61680272014-05-05 12:42:35 -050072 }
73 pci_write_config32(dev, ADSP_PCI_VDRTCTL0, tmp32);
74
75 /* Set PSF Snoop to SA, RCBA+0x3350[10]=1b */
76 RCBA32_OR(0x3350, (1 << 10));
77
78 /* Set DSP IOBP PMCTL 0x1e0=0x3f */
79 pch_iobp_write(ADSP_IOBP_PMCTL, ADSP_PMCTL_VALUE);
80
81 if (config->sio_acpi_mode) {
82 /* Configure for ACPI mode */
83 global_nvs_t *gnvs;
84
85 printk(BIOS_INFO, "ADSP: Enable ACPI Mode IRQ3\n");
86
87 /* Find ACPI NVS to update BARs */
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +030088 gnvs = acpi_get_gnvs();
89 if (!gnvs)
Duncan Laurie61680272014-05-05 12:42:35 -050090 return;
Duncan Laurie61680272014-05-05 12:42:35 -050091
92 /* Save BAR0 and BAR1 to ACPI NVS */
93 gnvs->dev.bar0[SIO_NVS_ADSP] = (u32)bar0->base;
94 gnvs->dev.bar1[SIO_NVS_ADSP] = (u32)bar1->base;
95 gnvs->dev.enable[SIO_NVS_ADSP] = 1;
96
97 /* Set PCI Config Disable Bit */
98 pch_iobp_update(ADSP_IOBP_PCICFGCTL, ~0, ADSP_PCICFGCTL_PCICD);
99
100 /* Set interrupt de-assert/assert opcode override to IRQ3 */
101 pch_iobp_write(ADSP_IOBP_VDLDAT2, ADSP_IOBP_ACPI_IRQ3);
102
103 /* Enable IRQ3 in RCBA */
104 RCBA32_OR(ACPIIRQEN, ADSP_ACPI_IRQEN);
105
106 /* Set ACPI Interrupt Enable Bit */
107 pch_iobp_update(ADSP_IOBP_PCICFGCTL, ~ADSP_PCICFGCTL_SPCBAD,
108 ADSP_PCICFGCTL_ACPIIE);
109
110 /* Put ADSP in D3hot */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800111 tmp32 = read32(res2mmio(bar1, PCH_PCS, 0));
Duncan Laurie61680272014-05-05 12:42:35 -0500112 tmp32 |= PCH_PCS_PS_D3HOT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800113 write32(res2mmio(bar1, PCH_PCS, 0), tmp32);
Duncan Laurie61680272014-05-05 12:42:35 -0500114 } else {
115 printk(BIOS_INFO, "ADSP: Enable PCI Mode IRQ23\n");
116
117 /* Configure for PCI mode */
Elyes HAOUASfac28932020-05-03 08:30:09 +0200118 pci_write_config8(dev, PCI_INTERRUPT_LINE, ADSP_PCI_IRQ);
Duncan Laurie61680272014-05-05 12:42:35 -0500119
120 /* Clear ACPI Interrupt Enable Bit */
121 pch_iobp_update(ADSP_IOBP_PCICFGCTL,
122 ~(ADSP_PCICFGCTL_SPCBAD | ADSP_PCICFGCTL_ACPIIE), 0);
123 }
124}
125
126static struct device_operations adsp_ops = {
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100127 .read_resources = pci_dev_read_resources,
128 .set_resources = pci_dev_set_resources,
129 .enable_resources = pci_dev_enable_resources,
130 .init = adsp_init,
Duncan Laurie61680272014-05-05 12:42:35 -0500131 .ops_pci = &broadwell_pci_ops,
132};
133
134static const unsigned short pci_device_ids[] = {
135 0x9c36, /* LynxPoint */
136 0x9cb6, /* WildcatPoint */
137 0
138};
139
140static const struct pci_driver pch_adsp __pci_driver = {
141 .ops = &adsp_ops,
142 .vendor = PCI_VENDOR_ID_INTEL,
143 .devices = pci_device_ids,
144};