blob: c4023cc84abc2765f5aef2564aaea7294a15bc34 [file] [log] [blame]
Duncan Laurie61680272014-05-05 12:42:35 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Duncan Laurie61680272014-05-05 12:42:35 -050014 */
15
16#include <cbmem.h>
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <device/pci_ops.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020022#include <device/mmio.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070023#include <soc/adsp.h>
24#include <soc/device_nvs.h>
25#include <soc/iobp.h>
26#include <soc/nvs.h>
27#include <soc/pch.h>
28#include <soc/ramstage.h>
29#include <soc/rcba.h>
30#include <soc/intel/broadwell/chip.h>
Duncan Laurie61680272014-05-05 12:42:35 -050031
32static void adsp_init(struct device *dev)
33{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +030034 config_t *config = config_of(dev);
Duncan Laurie61680272014-05-05 12:42:35 -050035 struct resource *bar0, *bar1;
36 u32 tmp32;
37
38 /* Ensure memory and bus master are enabled */
39 tmp32 = pci_read_config32(dev, PCI_COMMAND);
40 tmp32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
41 pci_write_config32(dev, PCI_COMMAND, tmp32);
42
43 /* Find BAR0 and BAR1 */
44 bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
45 if (!bar0)
46 return;
47 bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
48 if (!bar1)
49 return;
50
51 /*
52 * Set LTR value in DSP shim LTR control register to 3ms
53 * SNOOP_REQ[13]=1b SNOOP_SCALE[12:10]=100b (1ms) SNOOP_VAL[9:0]=3h
54 */
55 tmp32 = pch_is_wpt() ? ADSP_SHIM_BASE_WPT : ADSP_SHIM_BASE_LPT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080056 write32(res2mmio(bar0, tmp32 + ADSP_SHIM_LTRC, 0),
57 ADSP_SHIM_LTRC_VALUE);
Duncan Laurie61680272014-05-05 12:42:35 -050058
59 /* Program VDRTCTL2 D19:F0:A8[31:0] = 0x00000fff */
60 pci_write_config32(dev, ADSP_PCI_VDRTCTL2, ADSP_VDRTCTL2_VALUE);
61
62 /* Program ADSP IOBP VDLDAT1 to 0x040100 */
63 pch_iobp_write(ADSP_IOBP_VDLDAT1, ADSP_VDLDAT1_VALUE);
64
65 /* Set D3 Power Gating Enable in D19:F0:A0 based on PCH type */
66 tmp32 = pci_read_config32(dev, ADSP_PCI_VDRTCTL0);
Duncan Lauried9f95072014-10-01 13:47:20 -070067 if (pch_is_wpt()) {
68 if (config->adsp_d3_pg_enable) {
69 tmp32 &= ~ADSP_VDRTCTL0_D3PGD_WPT;
70 if (config->adsp_sram_pg_enable)
71 tmp32 &= ~ADSP_VDRTCTL0_D3SRAMPGD_WPT;
72 else
73 tmp32 |= ADSP_VDRTCTL0_D3SRAMPGD_WPT;
Duncan Laurie3ed4d392014-07-31 10:41:56 -070074 } else {
Duncan Lauried9f95072014-10-01 13:47:20 -070075 tmp32 |= ADSP_VDRTCTL0_D3PGD_WPT;
Duncan Laurie3ed4d392014-07-31 10:41:56 -070076 }
Duncan Laurie61680272014-05-05 12:42:35 -050077 } else {
Duncan Lauried9f95072014-10-01 13:47:20 -070078 if (config->adsp_d3_pg_enable) {
Duncan Laurie3ed4d392014-07-31 10:41:56 -070079 tmp32 &= ~ADSP_VDRTCTL0_D3PGD_LPT;
Duncan Lauried9f95072014-10-01 13:47:20 -070080 if (config->adsp_sram_pg_enable)
81 tmp32 &= ~ADSP_VDRTCTL0_D3SRAMPGD_LPT;
82 else
83 tmp32 |= ADSP_VDRTCTL0_D3SRAMPGD_LPT;
84 } else {
85 tmp32 |= ADSP_VDRTCTL0_D3PGD_LPT;
Duncan Laurie3ed4d392014-07-31 10:41:56 -070086 }
Duncan Laurie61680272014-05-05 12:42:35 -050087 }
88 pci_write_config32(dev, ADSP_PCI_VDRTCTL0, tmp32);
89
90 /* Set PSF Snoop to SA, RCBA+0x3350[10]=1b */
91 RCBA32_OR(0x3350, (1 << 10));
92
93 /* Set DSP IOBP PMCTL 0x1e0=0x3f */
94 pch_iobp_write(ADSP_IOBP_PMCTL, ADSP_PMCTL_VALUE);
95
96 if (config->sio_acpi_mode) {
97 /* Configure for ACPI mode */
98 global_nvs_t *gnvs;
99
100 printk(BIOS_INFO, "ADSP: Enable ACPI Mode IRQ3\n");
101
102 /* Find ACPI NVS to update BARs */
103 gnvs = (global_nvs_t *)cbmem_find(CBMEM_ID_ACPI_GNVS);
104 if (!gnvs) {
105 printk(BIOS_ERR, "Unable to locate Global NVS\n");
106 return;
107 }
108
109 /* Save BAR0 and BAR1 to ACPI NVS */
110 gnvs->dev.bar0[SIO_NVS_ADSP] = (u32)bar0->base;
111 gnvs->dev.bar1[SIO_NVS_ADSP] = (u32)bar1->base;
112 gnvs->dev.enable[SIO_NVS_ADSP] = 1;
113
114 /* Set PCI Config Disable Bit */
115 pch_iobp_update(ADSP_IOBP_PCICFGCTL, ~0, ADSP_PCICFGCTL_PCICD);
116
117 /* Set interrupt de-assert/assert opcode override to IRQ3 */
118 pch_iobp_write(ADSP_IOBP_VDLDAT2, ADSP_IOBP_ACPI_IRQ3);
119
120 /* Enable IRQ3 in RCBA */
121 RCBA32_OR(ACPIIRQEN, ADSP_ACPI_IRQEN);
122
123 /* Set ACPI Interrupt Enable Bit */
124 pch_iobp_update(ADSP_IOBP_PCICFGCTL, ~ADSP_PCICFGCTL_SPCBAD,
125 ADSP_PCICFGCTL_ACPIIE);
126
127 /* Put ADSP in D3hot */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800128 tmp32 = read32(res2mmio(bar1, PCH_PCS, 0));
Duncan Laurie61680272014-05-05 12:42:35 -0500129 tmp32 |= PCH_PCS_PS_D3HOT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800130 write32(res2mmio(bar1, PCH_PCS, 0), tmp32);
Duncan Laurie61680272014-05-05 12:42:35 -0500131 } else {
132 printk(BIOS_INFO, "ADSP: Enable PCI Mode IRQ23\n");
133
134 /* Configure for PCI mode */
135 pci_write_config32(dev, PCI_INTERRUPT_LINE, ADSP_PCI_IRQ);
136
137 /* Clear ACPI Interrupt Enable Bit */
138 pch_iobp_update(ADSP_IOBP_PCICFGCTL,
139 ~(ADSP_PCICFGCTL_SPCBAD | ADSP_PCICFGCTL_ACPIIE), 0);
140 }
141}
142
143static struct device_operations adsp_ops = {
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100144 .read_resources = pci_dev_read_resources,
145 .set_resources = pci_dev_set_resources,
146 .enable_resources = pci_dev_enable_resources,
147 .init = adsp_init,
Duncan Laurie61680272014-05-05 12:42:35 -0500148 .ops_pci = &broadwell_pci_ops,
149};
150
151static const unsigned short pci_device_ids[] = {
152 0x9c36, /* LynxPoint */
153 0x9cb6, /* WildcatPoint */
154 0
155};
156
157static const struct pci_driver pch_adsp __pci_driver = {
158 .ops = &adsp_ops,
159 .vendor = PCI_VENDOR_ID_INTEL,
160 .devices = pci_device_ids,
161};