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. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | */ |
| 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 Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 23 | #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 Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 30 | |
| 31 | u8 pch_revision(void) |
| 32 | { |
| 33 | return pci_read_config8(PCH_DEV_LPC, PCI_REVISION_ID); |
| 34 | } |
| 35 | |
| 36 | u16 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 */ |
| 42 | int pch_is_wpt(void) |
| 43 | { |
| 44 | return ((pch_type() & 0xfff0) == 0x9cc0) ? 1 : 0; |
| 45 | } |
| 46 | |
| 47 | /* Return 1 if PCH type is WildcatPoint ULX */ |
| 48 | int 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 | |
| 62 | u32 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 */ |
Elyes HAOUAS | 4658a98 | 2018-09-20 08:46:35 +0200 | [diff] [blame] | 80 | static void pch_enable_d3hot(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 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 Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 87 | /* RCBA function disable and posting read to flush the transaction */ |
| 88 | static void rcba_function_disable(u32 reg, u32 bit) |
| 89 | { |
| 90 | RCBA32_OR(reg, bit); |
| 91 | RCBA32(reg); |
| 92 | } |
| 93 | |
Martin Roth | de7ed6f | 2014-12-07 14:58:18 -0700 | [diff] [blame] | 94 | /* Set bit in Function Disable register to hide this device */ |
Elyes HAOUAS | 4658a98 | 2018-09-20 08:46:35 +0200 | [diff] [blame] | 95 | void pch_disable_devfn(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 96 | { |
| 97 | switch (dev->path.pci.devfn) { |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 98 | case PCH_DEVFN_ADSP: /* Audio DSP */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 99 | rcba_function_disable(FD, PCH_DISABLE_ADSPD); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 100 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 101 | case PCH_DEVFN_XHCI: /* XHCI */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 102 | rcba_function_disable(FD, PCH_DISABLE_XHCI); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 103 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 104 | case PCH_DEVFN_SDMA: /* DMA */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 105 | pch_enable_d3hot(dev); |
| 106 | pch_iobp_update(SIO_IOBP_FUNCDIS0, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 107 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 108 | case PCH_DEVFN_I2C0: /* I2C0 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 109 | pch_enable_d3hot(dev); |
| 110 | pch_iobp_update(SIO_IOBP_FUNCDIS1, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 111 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 112 | case PCH_DEVFN_I2C1: /* I2C1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 113 | pch_enable_d3hot(dev); |
| 114 | pch_iobp_update(SIO_IOBP_FUNCDIS2, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 115 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 116 | case PCH_DEVFN_SPI0: /* SPI0 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 117 | pch_enable_d3hot(dev); |
| 118 | pch_iobp_update(SIO_IOBP_FUNCDIS3, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 119 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 120 | case PCH_DEVFN_SPI1: /* SPI1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 121 | pch_enable_d3hot(dev); |
| 122 | pch_iobp_update(SIO_IOBP_FUNCDIS4, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 123 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 124 | case PCH_DEVFN_UART0: /* UART0 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 125 | pch_enable_d3hot(dev); |
| 126 | pch_iobp_update(SIO_IOBP_FUNCDIS5, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 127 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 128 | case PCH_DEVFN_UART1: /* UART1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 129 | pch_enable_d3hot(dev); |
| 130 | pch_iobp_update(SIO_IOBP_FUNCDIS6, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 131 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 132 | case PCH_DEVFN_ME: /* MEI #1 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 133 | rcba_function_disable(FD2, PCH_DISABLE_MEI1); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 134 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 135 | case PCH_DEVFN_ME_2: /* MEI #2 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 136 | rcba_function_disable(FD2, PCH_DISABLE_MEI2); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 137 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 138 | case PCH_DEVFN_ME_IDER: /* IDE-R */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 139 | rcba_function_disable(FD2, PCH_DISABLE_IDER); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 140 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 141 | case PCH_DEVFN_ME_KT: /* KT */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 142 | rcba_function_disable(FD2, PCH_DISABLE_KT); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 143 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 144 | case PCH_DEVFN_SDIO: /* SDIO */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 145 | pch_enable_d3hot(dev); |
| 146 | pch_iobp_update(SIO_IOBP_FUNCDIS7, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 147 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 148 | case PCH_DEVFN_GBE: /* Gigabit Ethernet */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 149 | rcba_function_disable(BUC, PCH_DISABLE_GBE); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 150 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 151 | case PCH_DEVFN_HDA: /* HD Audio Controller */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 152 | rcba_function_disable(FD, PCH_DISABLE_HD_AUDIO); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 153 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 154 | 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 Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 162 | rcba_function_disable(FD, |
| 163 | PCH_DISABLE_PCIE(PCI_FUNC(dev->path.pci.devfn))); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 164 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 165 | case PCH_DEVFN_EHCI: /* EHCI #1 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 166 | rcba_function_disable(FD, PCH_DISABLE_EHCI1); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 167 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 168 | case PCH_DEVFN_LPC: /* LPC */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 169 | rcba_function_disable(FD, PCH_DISABLE_LPC); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 170 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 171 | case PCH_DEVFN_SATA: /* SATA #1 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 172 | rcba_function_disable(FD, PCH_DISABLE_SATA1); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 173 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 174 | case PCH_DEVFN_SMBUS: /* SMBUS */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 175 | rcba_function_disable(FD, PCH_DISABLE_SMBUS); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 176 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 177 | case PCH_DEVFN_SATA2: /* SATA #2 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 178 | rcba_function_disable(FD, PCH_DISABLE_SATA2); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 179 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 180 | case PCH_DEVFN_THERMAL: /* Thermal Subsystem */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 181 | rcba_function_disable(FD, PCH_DISABLE_THERMAL); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 182 | break; |
| 183 | } |
| 184 | } |
| 185 | |
Elyes HAOUAS | 4658a98 | 2018-09-20 08:46:35 +0200 | [diff] [blame] | 186 | void broadwell_pch_enable_dev(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 187 | { |
| 188 | u32 reg32; |
| 189 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 190 | /* 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 Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 195 | return; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 196 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 197 | |
| 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 |