blob: 82904de39b3b4694721008f355cd7bc5e28b56a0 [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Laurie61680272014-05-05 12:42:35 -05003
4#include <cbmem.h>
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>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020010#include <device/mmio.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070011#include <soc/adsp.h>
12#include <soc/device_nvs.h>
13#include <soc/iobp.h>
14#include <soc/nvs.h>
15#include <soc/pch.h>
16#include <soc/ramstage.h>
17#include <soc/rcba.h>
18#include <soc/intel/broadwell/chip.h>
Duncan Laurie61680272014-05-05 12:42:35 -050019
20static void adsp_init(struct device *dev)
21{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +030022 config_t *config = config_of(dev);
Duncan Laurie61680272014-05-05 12:42:35 -050023 struct resource *bar0, *bar1;
24 u32 tmp32;
25
26 /* Ensure memory and bus master are enabled */
27 tmp32 = pci_read_config32(dev, PCI_COMMAND);
28 tmp32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
29 pci_write_config32(dev, PCI_COMMAND, tmp32);
30
31 /* Find BAR0 and BAR1 */
32 bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
33 if (!bar0)
34 return;
35 bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
36 if (!bar1)
37 return;
38
39 /*
40 * Set LTR value in DSP shim LTR control register to 3ms
41 * SNOOP_REQ[13]=1b SNOOP_SCALE[12:10]=100b (1ms) SNOOP_VAL[9:0]=3h
42 */
43 tmp32 = pch_is_wpt() ? ADSP_SHIM_BASE_WPT : ADSP_SHIM_BASE_LPT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080044 write32(res2mmio(bar0, tmp32 + ADSP_SHIM_LTRC, 0),
45 ADSP_SHIM_LTRC_VALUE);
Duncan Laurie61680272014-05-05 12:42:35 -050046
47 /* Program VDRTCTL2 D19:F0:A8[31:0] = 0x00000fff */
48 pci_write_config32(dev, ADSP_PCI_VDRTCTL2, ADSP_VDRTCTL2_VALUE);
49
50 /* Program ADSP IOBP VDLDAT1 to 0x040100 */
51 pch_iobp_write(ADSP_IOBP_VDLDAT1, ADSP_VDLDAT1_VALUE);
52
53 /* Set D3 Power Gating Enable in D19:F0:A0 based on PCH type */
54 tmp32 = pci_read_config32(dev, ADSP_PCI_VDRTCTL0);
Duncan Lauried9f95072014-10-01 13:47:20 -070055 if (pch_is_wpt()) {
56 if (config->adsp_d3_pg_enable) {
57 tmp32 &= ~ADSP_VDRTCTL0_D3PGD_WPT;
58 if (config->adsp_sram_pg_enable)
59 tmp32 &= ~ADSP_VDRTCTL0_D3SRAMPGD_WPT;
60 else
61 tmp32 |= ADSP_VDRTCTL0_D3SRAMPGD_WPT;
Duncan Laurie3ed4d392014-07-31 10:41:56 -070062 } else {
Duncan Lauried9f95072014-10-01 13:47:20 -070063 tmp32 |= ADSP_VDRTCTL0_D3PGD_WPT;
Duncan Laurie3ed4d392014-07-31 10:41:56 -070064 }
Duncan Laurie61680272014-05-05 12:42:35 -050065 } else {
Duncan Lauried9f95072014-10-01 13:47:20 -070066 if (config->adsp_d3_pg_enable) {
Duncan Laurie3ed4d392014-07-31 10:41:56 -070067 tmp32 &= ~ADSP_VDRTCTL0_D3PGD_LPT;
Duncan Lauried9f95072014-10-01 13:47:20 -070068 if (config->adsp_sram_pg_enable)
69 tmp32 &= ~ADSP_VDRTCTL0_D3SRAMPGD_LPT;
70 else
71 tmp32 |= ADSP_VDRTCTL0_D3SRAMPGD_LPT;
72 } else {
73 tmp32 |= ADSP_VDRTCTL0_D3PGD_LPT;
Duncan Laurie3ed4d392014-07-31 10:41:56 -070074 }
Duncan Laurie61680272014-05-05 12:42:35 -050075 }
76 pci_write_config32(dev, ADSP_PCI_VDRTCTL0, tmp32);
77
78 /* Set PSF Snoop to SA, RCBA+0x3350[10]=1b */
79 RCBA32_OR(0x3350, (1 << 10));
80
81 /* Set DSP IOBP PMCTL 0x1e0=0x3f */
82 pch_iobp_write(ADSP_IOBP_PMCTL, ADSP_PMCTL_VALUE);
83
84 if (config->sio_acpi_mode) {
85 /* Configure for ACPI mode */
86 global_nvs_t *gnvs;
87
88 printk(BIOS_INFO, "ADSP: Enable ACPI Mode IRQ3\n");
89
90 /* Find ACPI NVS to update BARs */
91 gnvs = (global_nvs_t *)cbmem_find(CBMEM_ID_ACPI_GNVS);
92 if (!gnvs) {
93 printk(BIOS_ERR, "Unable to locate Global NVS\n");
94 return;
95 }
96
97 /* Save BAR0 and BAR1 to ACPI NVS */
98 gnvs->dev.bar0[SIO_NVS_ADSP] = (u32)bar0->base;
99 gnvs->dev.bar1[SIO_NVS_ADSP] = (u32)bar1->base;
100 gnvs->dev.enable[SIO_NVS_ADSP] = 1;
101
102 /* Set PCI Config Disable Bit */
103 pch_iobp_update(ADSP_IOBP_PCICFGCTL, ~0, ADSP_PCICFGCTL_PCICD);
104
105 /* Set interrupt de-assert/assert opcode override to IRQ3 */
106 pch_iobp_write(ADSP_IOBP_VDLDAT2, ADSP_IOBP_ACPI_IRQ3);
107
108 /* Enable IRQ3 in RCBA */
109 RCBA32_OR(ACPIIRQEN, ADSP_ACPI_IRQEN);
110
111 /* Set ACPI Interrupt Enable Bit */
112 pch_iobp_update(ADSP_IOBP_PCICFGCTL, ~ADSP_PCICFGCTL_SPCBAD,
113 ADSP_PCICFGCTL_ACPIIE);
114
115 /* Put ADSP in D3hot */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800116 tmp32 = read32(res2mmio(bar1, PCH_PCS, 0));
Duncan Laurie61680272014-05-05 12:42:35 -0500117 tmp32 |= PCH_PCS_PS_D3HOT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800118 write32(res2mmio(bar1, PCH_PCS, 0), tmp32);
Duncan Laurie61680272014-05-05 12:42:35 -0500119 } else {
120 printk(BIOS_INFO, "ADSP: Enable PCI Mode IRQ23\n");
121
122 /* Configure for PCI mode */
123 pci_write_config32(dev, PCI_INTERRUPT_LINE, ADSP_PCI_IRQ);
124
125 /* Clear ACPI Interrupt Enable Bit */
126 pch_iobp_update(ADSP_IOBP_PCICFGCTL,
127 ~(ADSP_PCICFGCTL_SPCBAD | ADSP_PCICFGCTL_ACPIIE), 0);
128 }
129}
130
131static struct device_operations adsp_ops = {
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100132 .read_resources = pci_dev_read_resources,
133 .set_resources = pci_dev_set_resources,
134 .enable_resources = pci_dev_enable_resources,
135 .init = adsp_init,
Duncan Laurie61680272014-05-05 12:42:35 -0500136 .ops_pci = &broadwell_pci_ops,
137};
138
139static const unsigned short pci_device_ids[] = {
140 0x9c36, /* LynxPoint */
141 0x9cb6, /* WildcatPoint */
142 0
143};
144
145static const struct pci_driver pch_adsp __pci_driver = {
146 .ops = &adsp_ops,
147 .vendor = PCI_VENDOR_ID_INTEL,
148 .devices = pci_device_ids,
149};