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