blob: a8b25cf6505773296f1a34a3b182f7e586b2b974 [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.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070015 */
16
17#include <console/console.h>
18#include <delay.h>
19#include <arch/io.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_def.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070023#include <soc/iobp.h>
24#include <soc/pch.h>
25#include <soc/pci_devs.h>
26#include <soc/ramstage.h>
27#include <soc/rcba.h>
28#include <soc/serialio.h>
29#include <soc/spi.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070030
31u8 pch_revision(void)
32{
33 return pci_read_config8(PCH_DEV_LPC, PCI_REVISION_ID);
34}
35
36u16 pch_type(void)
37{
38 return pci_read_config16(PCH_DEV_LPC, PCI_DEVICE_ID);
39}
40
41/* Return 1 if PCH type is WildcatPoint */
42int pch_is_wpt(void)
43{
44 return ((pch_type() & 0xfff0) == 0x9cc0) ? 1 : 0;
45}
46
47/* Return 1 if PCH type is WildcatPoint ULX */
48int pch_is_wpt_ulx(void)
49{
50 u16 lpcid = pch_type();
51
52 switch (lpcid) {
53 case PCH_WPT_BDW_Y_SAMPLE:
54 case PCH_WPT_BDW_Y_PREMIUM:
55 case PCH_WPT_BDW_Y_BASE:
56 return 1;
57 }
58
59 return 0;
60}
61
62u32 pch_read_soft_strap(int id)
63{
64 u32 fdoc;
65
66 fdoc = SPIBAR32(SPIBAR_FDOC);
67 fdoc &= ~0x00007ffc;
68 SPIBAR32(SPIBAR_FDOC) = fdoc;
69
70 fdoc |= 0x00004000;
71 fdoc |= id * 4;
72 SPIBAR32(SPIBAR_FDOC) = fdoc;
73
74 return SPIBAR32(SPIBAR_FDOD);
75}
76
77#ifndef __PRE_RAM__
78
79/* Put device in D3Hot Power State */
80static void pch_enable_d3hot(device_t dev)
81{
82 u32 reg32 = pci_read_config32(dev, PCH_PCS);
83 reg32 |= PCH_PCS_PS_D3HOT;
84 pci_write_config32(dev, PCH_PCS, reg32);
85}
86
Wenkai Duaec24422014-10-15 11:19:16 -070087/* RCBA function disable and posting read to flush the transaction */
88static void rcba_function_disable(u32 reg, u32 bit)
89{
90 RCBA32_OR(reg, bit);
91 RCBA32(reg);
92}
93
Martin Rothde7ed6f2014-12-07 14:58:18 -070094/* Set bit in Function Disable register to hide this device */
Duncan Lauriec88c54c2014-04-30 16:36:13 -070095void pch_disable_devfn(device_t dev)
96{
97 switch (dev->path.pci.devfn) {
Duncan Laurie61680272014-05-05 12:42:35 -050098 case PCH_DEVFN_ADSP: /* Audio DSP */
Wenkai Duaec24422014-10-15 11:19:16 -070099 rcba_function_disable(FD, PCH_DISABLE_ADSPD);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700100 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500101 case PCH_DEVFN_XHCI: /* XHCI */
Wenkai Duaec24422014-10-15 11:19:16 -0700102 rcba_function_disable(FD, PCH_DISABLE_XHCI);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700103 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500104 case PCH_DEVFN_SDMA: /* DMA */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700105 pch_enable_d3hot(dev);
106 pch_iobp_update(SIO_IOBP_FUNCDIS0, ~0UL, SIO_IOBP_FUNCDIS_DIS);
107 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500108 case PCH_DEVFN_I2C0: /* I2C0 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700109 pch_enable_d3hot(dev);
110 pch_iobp_update(SIO_IOBP_FUNCDIS1, ~0UL, SIO_IOBP_FUNCDIS_DIS);
111 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500112 case PCH_DEVFN_I2C1: /* I2C1 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700113 pch_enable_d3hot(dev);
114 pch_iobp_update(SIO_IOBP_FUNCDIS2, ~0UL, SIO_IOBP_FUNCDIS_DIS);
115 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500116 case PCH_DEVFN_SPI0: /* SPI0 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700117 pch_enable_d3hot(dev);
118 pch_iobp_update(SIO_IOBP_FUNCDIS3, ~0UL, SIO_IOBP_FUNCDIS_DIS);
119 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500120 case PCH_DEVFN_SPI1: /* SPI1 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700121 pch_enable_d3hot(dev);
122 pch_iobp_update(SIO_IOBP_FUNCDIS4, ~0UL, SIO_IOBP_FUNCDIS_DIS);
123 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500124 case PCH_DEVFN_UART0: /* UART0 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700125 pch_enable_d3hot(dev);
126 pch_iobp_update(SIO_IOBP_FUNCDIS5, ~0UL, SIO_IOBP_FUNCDIS_DIS);
127 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500128 case PCH_DEVFN_UART1: /* UART1 */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700129 pch_enable_d3hot(dev);
130 pch_iobp_update(SIO_IOBP_FUNCDIS6, ~0UL, SIO_IOBP_FUNCDIS_DIS);
131 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500132 case PCH_DEVFN_ME: /* MEI #1 */
Wenkai Duaec24422014-10-15 11:19:16 -0700133 rcba_function_disable(FD2, PCH_DISABLE_MEI1);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700134 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500135 case PCH_DEVFN_ME_2: /* MEI #2 */
Wenkai Duaec24422014-10-15 11:19:16 -0700136 rcba_function_disable(FD2, PCH_DISABLE_MEI2);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700137 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500138 case PCH_DEVFN_ME_IDER: /* IDE-R */
Wenkai Duaec24422014-10-15 11:19:16 -0700139 rcba_function_disable(FD2, PCH_DISABLE_IDER);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700140 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500141 case PCH_DEVFN_ME_KT: /* KT */
Wenkai Duaec24422014-10-15 11:19:16 -0700142 rcba_function_disable(FD2, PCH_DISABLE_KT);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700143 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500144 case PCH_DEVFN_SDIO: /* SDIO */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700145 pch_enable_d3hot(dev);
146 pch_iobp_update(SIO_IOBP_FUNCDIS7, ~0UL, SIO_IOBP_FUNCDIS_DIS);
147 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500148 case PCH_DEVFN_GBE: /* Gigabit Ethernet */
Wenkai Duaec24422014-10-15 11:19:16 -0700149 rcba_function_disable(BUC, PCH_DISABLE_GBE);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700150 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500151 case PCH_DEVFN_HDA: /* HD Audio Controller */
Wenkai Duaec24422014-10-15 11:19:16 -0700152 rcba_function_disable(FD, PCH_DISABLE_HD_AUDIO);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700153 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500154 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 0): /* PCI Express Root Port 1 */
155 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 1): /* PCI Express Root Port 2 */
156 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 2): /* PCI Express Root Port 3 */
157 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 3): /* PCI Express Root Port 4 */
158 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 4): /* PCI Express Root Port 5 */
159 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 5): /* PCI Express Root Port 6 */
160 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 6): /* PCI Express Root Port 7 */
161 case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 7): /* PCI Express Root Port 8 */
Wenkai Duaec24422014-10-15 11:19:16 -0700162 rcba_function_disable(FD,
163 PCH_DISABLE_PCIE(PCI_FUNC(dev->path.pci.devfn)));
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700164 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500165 case PCH_DEVFN_EHCI: /* EHCI #1 */
Wenkai Duaec24422014-10-15 11:19:16 -0700166 rcba_function_disable(FD, PCH_DISABLE_EHCI1);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700167 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500168 case PCH_DEVFN_LPC: /* LPC */
Wenkai Duaec24422014-10-15 11:19:16 -0700169 rcba_function_disable(FD, PCH_DISABLE_LPC);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700170 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500171 case PCH_DEVFN_SATA: /* SATA #1 */
Wenkai Duaec24422014-10-15 11:19:16 -0700172 rcba_function_disable(FD, PCH_DISABLE_SATA1);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700173 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500174 case PCH_DEVFN_SMBUS: /* SMBUS */
Wenkai Duaec24422014-10-15 11:19:16 -0700175 rcba_function_disable(FD, PCH_DISABLE_SMBUS);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700176 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500177 case PCH_DEVFN_SATA2: /* SATA #2 */
Wenkai Duaec24422014-10-15 11:19:16 -0700178 rcba_function_disable(FD, PCH_DISABLE_SATA2);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700179 break;
Duncan Laurie61680272014-05-05 12:42:35 -0500180 case PCH_DEVFN_THERMAL: /* Thermal Subsystem */
Wenkai Duaec24422014-10-15 11:19:16 -0700181 rcba_function_disable(FD, PCH_DISABLE_THERMAL);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700182 break;
183 }
184}
185
186void broadwell_pch_enable_dev(device_t dev)
187{
188 u32 reg32;
189
Duncan Laurie61680272014-05-05 12:42:35 -0500190 /* These devices need special enable/disable handling */
191 switch (PCI_SLOT(dev->path.pci.devfn)) {
192 case PCH_DEV_SLOT_PCIE:
193 case PCH_DEV_SLOT_EHCI:
194 case PCH_DEV_SLOT_HDA:
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700195 return;
Duncan Laurie61680272014-05-05 12:42:35 -0500196 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700197
198 if (!dev->enabled) {
199 printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev));
200
201 /* Ensure memory, io, and bus master are all disabled */
202 reg32 = pci_read_config32(dev, PCI_COMMAND);
203 reg32 &= ~(PCI_COMMAND_MASTER |
204 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
205 pci_write_config32(dev, PCI_COMMAND, reg32);
206
207 /* Disable this device if possible */
208 pch_disable_devfn(dev);
209 } else {
210 /* Enable SERR */
211 reg32 = pci_read_config32(dev, PCI_COMMAND);
212 reg32 |= PCI_COMMAND_SERR;
213 pci_write_config32(dev, PCI_COMMAND, reg32);
214 }
215}
216
217#endif