blob: 54c5567b40ffa27a7fefa2fcc95bd12024511d85 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2014 Google Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <console/console.h>
22#include <delay.h>
23#include <arch/io.h>
24#include <device/device.h>
25#include <device/pci.h>
26#include <device/pci_def.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070027#include <soc/iobp.h>
28#include <soc/pch.h>
29#include <soc/pci_devs.h>
30#include <soc/ramstage.h>
31#include <soc/rcba.h>
32#include <soc/serialio.h>
33#include <soc/spi.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070034
35u8 pch_revision(void)
36{
37 return pci_read_config8(PCH_DEV_LPC, PCI_REVISION_ID);
38}
39
40u16 pch_type(void)
41{
42 return pci_read_config16(PCH_DEV_LPC, PCI_DEVICE_ID);
43}
44
45/* Return 1 if PCH type is WildcatPoint */
46int pch_is_wpt(void)
47{
48 return ((pch_type() & 0xfff0) == 0x9cc0) ? 1 : 0;
49}
50
51/* Return 1 if PCH type is WildcatPoint ULX */
52int pch_is_wpt_ulx(void)
53{
54 u16 lpcid = pch_type();
55
56 switch (lpcid) {
57 case PCH_WPT_BDW_Y_SAMPLE:
58 case PCH_WPT_BDW_Y_PREMIUM:
59 case PCH_WPT_BDW_Y_BASE:
60 return 1;
61 }
62
63 return 0;
64}
65
66u32 pch_read_soft_strap(int id)
67{
68 u32 fdoc;
69
70 fdoc = SPIBAR32(SPIBAR_FDOC);
71 fdoc &= ~0x00007ffc;
72 SPIBAR32(SPIBAR_FDOC) = fdoc;
73
74 fdoc |= 0x00004000;
75 fdoc |= id * 4;
76 SPIBAR32(SPIBAR_FDOC) = fdoc;
77
78 return SPIBAR32(SPIBAR_FDOD);
79}
80
81#ifndef __PRE_RAM__
82
83/* Put device in D3Hot Power State */
84static void pch_enable_d3hot(device_t dev)
85{
86 u32 reg32 = pci_read_config32(dev, PCH_PCS);
87 reg32 |= PCH_PCS_PS_D3HOT;
88 pci_write_config32(dev, PCH_PCS, reg32);
89}
90
Martin Rothde7ed6f2014-12-07 14:58:18 -070091/* Set bit in Function Disable register to hide this device */
Duncan Lauriec88c54c2014-04-30 16:36:13 -070092void pch_disable_devfn(device_t dev)
93{
94 switch (dev->path.pci.devfn) {
Duncan Laurie61680272014-05-05 12:42:35 -050095 case PCH_DEVFN_ADSP: /* Audio DSP */
Duncan Lauriec88c54c2014-04-30 16:36:13 -070096 RCBA32_OR(FD, PCH_DISABLE_ADSPD);
97 break;
Duncan Laurie61680272014-05-05 12:42:35 -050098 case PCH_DEVFN_XHCI: /* XHCI */
Duncan Lauriec88c54c2014-04-30 16:36:13 -070099 RCBA32_OR(FD, PCH_DISABLE_XHCI);
100 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500101 case PCH_DEVFN_SDMA: /* DMA */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700102 pch_enable_d3hot(dev);
103 pch_iobp_update(SIO_IOBP_FUNCDIS0, ~0UL, SIO_IOBP_FUNCDIS_DIS);
104 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500105 case PCH_DEVFN_I2C0: /* I2C0 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700106 pch_enable_d3hot(dev);
107 pch_iobp_update(SIO_IOBP_FUNCDIS1, ~0UL, SIO_IOBP_FUNCDIS_DIS);
108 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500109 case PCH_DEVFN_I2C1: /* I2C1 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700110 pch_enable_d3hot(dev);
111 pch_iobp_update(SIO_IOBP_FUNCDIS2, ~0UL, SIO_IOBP_FUNCDIS_DIS);
112 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500113 case PCH_DEVFN_SPI0: /* SPI0 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700114 pch_enable_d3hot(dev);
115 pch_iobp_update(SIO_IOBP_FUNCDIS3, ~0UL, SIO_IOBP_FUNCDIS_DIS);
116 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500117 case PCH_DEVFN_SPI1: /* SPI1 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700118 pch_enable_d3hot(dev);
119 pch_iobp_update(SIO_IOBP_FUNCDIS4, ~0UL, SIO_IOBP_FUNCDIS_DIS);
120 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500121 case PCH_DEVFN_UART0: /* UART0 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700122 pch_enable_d3hot(dev);
123 pch_iobp_update(SIO_IOBP_FUNCDIS5, ~0UL, SIO_IOBP_FUNCDIS_DIS);
124 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500125 case PCH_DEVFN_UART1: /* UART1 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700126 pch_enable_d3hot(dev);
127 pch_iobp_update(SIO_IOBP_FUNCDIS6, ~0UL, SIO_IOBP_FUNCDIS_DIS);
128 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500129 case PCH_DEVFN_ME: /* MEI #1 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700130 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
131 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500132 case PCH_DEVFN_ME_2: /* MEI #2 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700133 RCBA32_OR(FD2, PCH_DISABLE_MEI2);
134 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500135 case PCH_DEVFN_ME_IDER: /* IDE-R */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700136 RCBA32_OR(FD2, PCH_DISABLE_IDER);
137 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500138 case PCH_DEVFN_ME_KT: /* KT */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700139 RCBA32_OR(FD2, PCH_DISABLE_KT);
140 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500141 case PCH_DEVFN_SDIO: /* SDIO */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700142 pch_enable_d3hot(dev);
143 pch_iobp_update(SIO_IOBP_FUNCDIS7, ~0UL, SIO_IOBP_FUNCDIS_DIS);
144 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500145 case PCH_DEVFN_GBE: /* Gigabit Ethernet */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700146 RCBA32_OR(BUC, PCH_DISABLE_GBE);
147 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500148 case PCH_DEVFN_HDA: /* HD Audio Controller */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700149 RCBA32_OR(FD, PCH_DISABLE_HD_AUDIO);
150 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500151 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 0): /* PCI Express Root Port 1 */
152 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 1): /* PCI Express Root Port 2 */
153 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 2): /* PCI Express Root Port 3 */
154 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 3): /* PCI Express Root Port 4 */
155 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 4): /* PCI Express Root Port 5 */
156 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 5): /* PCI Express Root Port 6 */
157 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 6): /* PCI Express Root Port 7 */
158 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 7): /* PCI Express Root Port 8 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700159 RCBA32_OR(FD, PCH_DISABLE_PCIE(PCI_FUNC(dev->path.pci.devfn)));
160 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500161 case PCH_DEVFN_EHCI: /* EHCI #1 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700162 RCBA32_OR(FD, PCH_DISABLE_EHCI1);
163 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500164 case PCH_DEVFN_LPC: /* LPC */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700165 RCBA32_OR(FD, PCH_DISABLE_LPC);
166 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500167 case PCH_DEVFN_SATA: /* SATA #1 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700168 RCBA32_OR(FD, PCH_DISABLE_SATA1);
169 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500170 case PCH_DEVFN_SMBUS: /* SMBUS */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700171 RCBA32_OR(FD, PCH_DISABLE_SMBUS);
172 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500173 case PCH_DEVFN_SATA2: /* SATA #2 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700174 RCBA32_OR(FD, PCH_DISABLE_SATA2);
175 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500176 case PCH_DEVFN_THERMAL: /* Thermal Subsystem */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700177 RCBA32_OR(FD, PCH_DISABLE_THERMAL);
178 break;
179 }
180}
181
182void broadwell_pch_enable_dev(device_t dev)
183{
184 u32 reg32;
185
Duncan Laurie61680272014-05-05 12:42:35 -0500186 /* These devices need special enable/disable handling */
187 switch (PCI_SLOT(dev->path.pci.devfn)) {
188 case PCH_DEV_SLOT_PCIE:
189 case PCH_DEV_SLOT_EHCI:
190 case PCH_DEV_SLOT_HDA:
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700191 return;
Duncan Laurie61680272014-05-05 12:42:35 -0500192 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700193
194 if (!dev->enabled) {
195 printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev));
196
197 /* Ensure memory, io, and bus master are all disabled */
198 reg32 = pci_read_config32(dev, PCI_COMMAND);
199 reg32 &= ~(PCI_COMMAND_MASTER |
200 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
201 pci_write_config32(dev, PCI_COMMAND, reg32);
202
203 /* Disable this device if possible */
204 pch_disable_devfn(dev);
205 } else {
206 /* Enable SERR */
207 reg32 = pci_read_config32(dev, PCI_COMMAND);
208 reg32 |= PCI_COMMAND_SERR;
209 pci_write_config32(dev, PCI_COMMAND, reg32);
210 }
211}
212
213#endif