Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 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> |
| 27 | #include <broadwell/iobp.h> |
| 28 | #include <broadwell/pch.h> |
| 29 | #include <broadwell/pci_devs.h> |
| 30 | #include <broadwell/ramstage.h> |
| 31 | #include <broadwell/rcba.h> |
| 32 | #include <broadwell/serialio.h> |
| 33 | #include <broadwell/spi.h> |
| 34 | |
| 35 | u8 pch_revision(void) |
| 36 | { |
| 37 | return pci_read_config8(PCH_DEV_LPC, PCI_REVISION_ID); |
| 38 | } |
| 39 | |
| 40 | u16 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 */ |
| 46 | int pch_is_wpt(void) |
| 47 | { |
| 48 | return ((pch_type() & 0xfff0) == 0x9cc0) ? 1 : 0; |
| 49 | } |
| 50 | |
| 51 | /* Return 1 if PCH type is WildcatPoint ULX */ |
| 52 | int 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 | |
| 66 | u32 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 */ |
| 84 | static 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 | |
| 91 | /* Set bit in Function Disble register to hide this device */ |
| 92 | void pch_disable_devfn(device_t dev) |
| 93 | { |
| 94 | switch (dev->path.pci.devfn) { |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 95 | case PCH_DEVFN_ADSP: /* Audio DSP */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 96 | RCBA32_OR(FD, PCH_DISABLE_ADSPD); |
| 97 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 98 | case PCH_DEVFN_XHCI: /* XHCI */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 99 | RCBA32_OR(FD, PCH_DISABLE_XHCI); |
| 100 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 101 | case PCH_DEVFN_SDMA: /* DMA */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 102 | pch_enable_d3hot(dev); |
| 103 | pch_iobp_update(SIO_IOBP_FUNCDIS0, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 104 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 105 | case PCH_DEVFN_I2C0: /* I2C0 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 106 | pch_enable_d3hot(dev); |
| 107 | pch_iobp_update(SIO_IOBP_FUNCDIS1, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 108 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 109 | case PCH_DEVFN_I2C1: /* I2C1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 110 | pch_enable_d3hot(dev); |
| 111 | pch_iobp_update(SIO_IOBP_FUNCDIS2, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 112 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 113 | case PCH_DEVFN_SPI0: /* SPI0 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 114 | pch_enable_d3hot(dev); |
| 115 | pch_iobp_update(SIO_IOBP_FUNCDIS3, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 116 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 117 | case PCH_DEVFN_SPI1: /* SPI1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 118 | pch_enable_d3hot(dev); |
| 119 | pch_iobp_update(SIO_IOBP_FUNCDIS4, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 120 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 121 | case PCH_DEVFN_UART0: /* UART0 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 122 | pch_enable_d3hot(dev); |
| 123 | pch_iobp_update(SIO_IOBP_FUNCDIS5, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 124 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 125 | case PCH_DEVFN_UART1: /* UART1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 126 | pch_enable_d3hot(dev); |
| 127 | pch_iobp_update(SIO_IOBP_FUNCDIS6, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 128 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 129 | case PCH_DEVFN_ME: /* MEI #1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 130 | RCBA32_OR(FD2, PCH_DISABLE_MEI1); |
| 131 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 132 | case PCH_DEVFN_ME_2: /* MEI #2 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 133 | RCBA32_OR(FD2, PCH_DISABLE_MEI2); |
| 134 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 135 | case PCH_DEVFN_ME_IDER: /* IDE-R */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 136 | RCBA32_OR(FD2, PCH_DISABLE_IDER); |
| 137 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 138 | case PCH_DEVFN_ME_KT: /* KT */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 139 | RCBA32_OR(FD2, PCH_DISABLE_KT); |
| 140 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 141 | case PCH_DEVFN_SDIO: /* SDIO */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 142 | pch_enable_d3hot(dev); |
| 143 | pch_iobp_update(SIO_IOBP_FUNCDIS7, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 144 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 145 | case PCH_DEVFN_GBE: /* Gigabit Ethernet */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 146 | RCBA32_OR(BUC, PCH_DISABLE_GBE); |
| 147 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 148 | case PCH_DEVFN_HDA: /* HD Audio Controller */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 149 | RCBA32_OR(FD, PCH_DISABLE_HD_AUDIO); |
| 150 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 151 | 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 Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 159 | RCBA32_OR(FD, PCH_DISABLE_PCIE(PCI_FUNC(dev->path.pci.devfn))); |
| 160 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 161 | case PCH_DEVFN_EHCI: /* EHCI #1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 162 | RCBA32_OR(FD, PCH_DISABLE_EHCI1); |
| 163 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 164 | case PCH_DEVFN_LPC: /* LPC */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 165 | RCBA32_OR(FD, PCH_DISABLE_LPC); |
| 166 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 167 | case PCH_DEVFN_SATA: /* SATA #1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 168 | RCBA32_OR(FD, PCH_DISABLE_SATA1); |
| 169 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 170 | case PCH_DEVFN_SMBUS: /* SMBUS */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 171 | RCBA32_OR(FD, PCH_DISABLE_SMBUS); |
| 172 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 173 | case PCH_DEVFN_SATA2: /* SATA #2 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 174 | RCBA32_OR(FD, PCH_DISABLE_SATA2); |
| 175 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 176 | case PCH_DEVFN_THERMAL: /* Thermal Subsystem */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 177 | RCBA32_OR(FD, PCH_DISABLE_THERMAL); |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | void broadwell_pch_enable_dev(device_t dev) |
| 183 | { |
| 184 | u32 reg32; |
| 185 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 186 | /* 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 Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 191 | return; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 192 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 193 | |
| 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 |