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> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame^] | 20 | #include <device/pci_ops.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pci_def.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 24 | #include <soc/iobp.h> |
| 25 | #include <soc/pch.h> |
| 26 | #include <soc/pci_devs.h> |
| 27 | #include <soc/ramstage.h> |
| 28 | #include <soc/rcba.h> |
| 29 | #include <soc/serialio.h> |
| 30 | #include <soc/spi.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 31 | |
| 32 | u8 pch_revision(void) |
| 33 | { |
| 34 | return pci_read_config8(PCH_DEV_LPC, PCI_REVISION_ID); |
| 35 | } |
| 36 | |
| 37 | u16 pch_type(void) |
| 38 | { |
| 39 | return pci_read_config16(PCH_DEV_LPC, PCI_DEVICE_ID); |
| 40 | } |
| 41 | |
| 42 | /* Return 1 if PCH type is WildcatPoint */ |
| 43 | int pch_is_wpt(void) |
| 44 | { |
| 45 | return ((pch_type() & 0xfff0) == 0x9cc0) ? 1 : 0; |
| 46 | } |
| 47 | |
| 48 | /* Return 1 if PCH type is WildcatPoint ULX */ |
| 49 | int pch_is_wpt_ulx(void) |
| 50 | { |
| 51 | u16 lpcid = pch_type(); |
| 52 | |
| 53 | switch (lpcid) { |
| 54 | case PCH_WPT_BDW_Y_SAMPLE: |
| 55 | case PCH_WPT_BDW_Y_PREMIUM: |
| 56 | case PCH_WPT_BDW_Y_BASE: |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | u32 pch_read_soft_strap(int id) |
| 64 | { |
| 65 | u32 fdoc; |
| 66 | |
| 67 | fdoc = SPIBAR32(SPIBAR_FDOC); |
| 68 | fdoc &= ~0x00007ffc; |
| 69 | SPIBAR32(SPIBAR_FDOC) = fdoc; |
| 70 | |
| 71 | fdoc |= 0x00004000; |
| 72 | fdoc |= id * 4; |
| 73 | SPIBAR32(SPIBAR_FDOC) = fdoc; |
| 74 | |
| 75 | return SPIBAR32(SPIBAR_FDOD); |
| 76 | } |
| 77 | |
| 78 | #ifndef __PRE_RAM__ |
| 79 | |
| 80 | /* Put device in D3Hot Power State */ |
Elyes HAOUAS | 4658a98 | 2018-09-20 08:46:35 +0200 | [diff] [blame] | 81 | static void pch_enable_d3hot(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 82 | { |
| 83 | u32 reg32 = pci_read_config32(dev, PCH_PCS); |
| 84 | reg32 |= PCH_PCS_PS_D3HOT; |
| 85 | pci_write_config32(dev, PCH_PCS, reg32); |
| 86 | } |
| 87 | |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 88 | /* RCBA function disable and posting read to flush the transaction */ |
| 89 | static void rcba_function_disable(u32 reg, u32 bit) |
| 90 | { |
| 91 | RCBA32_OR(reg, bit); |
| 92 | RCBA32(reg); |
| 93 | } |
| 94 | |
Martin Roth | de7ed6f | 2014-12-07 14:58:18 -0700 | [diff] [blame] | 95 | /* Set bit in Function Disable register to hide this device */ |
Elyes HAOUAS | 4658a98 | 2018-09-20 08:46:35 +0200 | [diff] [blame] | 96 | void pch_disable_devfn(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 97 | { |
| 98 | switch (dev->path.pci.devfn) { |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 99 | case PCH_DEVFN_ADSP: /* Audio DSP */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 100 | rcba_function_disable(FD, PCH_DISABLE_ADSPD); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 101 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 102 | case PCH_DEVFN_XHCI: /* XHCI */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 103 | rcba_function_disable(FD, PCH_DISABLE_XHCI); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 104 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 105 | case PCH_DEVFN_SDMA: /* DMA */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 106 | pch_enable_d3hot(dev); |
| 107 | pch_iobp_update(SIO_IOBP_FUNCDIS0, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 108 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 109 | case PCH_DEVFN_I2C0: /* I2C0 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 110 | pch_enable_d3hot(dev); |
| 111 | pch_iobp_update(SIO_IOBP_FUNCDIS1, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 112 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 113 | case PCH_DEVFN_I2C1: /* I2C1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 114 | pch_enable_d3hot(dev); |
| 115 | pch_iobp_update(SIO_IOBP_FUNCDIS2, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 116 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 117 | case PCH_DEVFN_SPI0: /* SPI0 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 118 | pch_enable_d3hot(dev); |
| 119 | pch_iobp_update(SIO_IOBP_FUNCDIS3, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 120 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 121 | case PCH_DEVFN_SPI1: /* SPI1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 122 | pch_enable_d3hot(dev); |
| 123 | pch_iobp_update(SIO_IOBP_FUNCDIS4, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 124 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 125 | case PCH_DEVFN_UART0: /* UART0 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 126 | pch_enable_d3hot(dev); |
| 127 | pch_iobp_update(SIO_IOBP_FUNCDIS5, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 128 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 129 | case PCH_DEVFN_UART1: /* UART1 */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 130 | pch_enable_d3hot(dev); |
| 131 | pch_iobp_update(SIO_IOBP_FUNCDIS6, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 132 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 133 | case PCH_DEVFN_ME: /* MEI #1 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 134 | rcba_function_disable(FD2, PCH_DISABLE_MEI1); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 135 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 136 | case PCH_DEVFN_ME_2: /* MEI #2 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 137 | rcba_function_disable(FD2, PCH_DISABLE_MEI2); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 138 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 139 | case PCH_DEVFN_ME_IDER: /* IDE-R */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 140 | rcba_function_disable(FD2, PCH_DISABLE_IDER); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 141 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 142 | case PCH_DEVFN_ME_KT: /* KT */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 143 | rcba_function_disable(FD2, PCH_DISABLE_KT); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 144 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 145 | case PCH_DEVFN_SDIO: /* SDIO */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 146 | pch_enable_d3hot(dev); |
| 147 | pch_iobp_update(SIO_IOBP_FUNCDIS7, ~0UL, SIO_IOBP_FUNCDIS_DIS); |
| 148 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 149 | case PCH_DEVFN_GBE: /* Gigabit Ethernet */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 150 | rcba_function_disable(BUC, PCH_DISABLE_GBE); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 151 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 152 | case PCH_DEVFN_HDA: /* HD Audio Controller */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 153 | rcba_function_disable(FD, PCH_DISABLE_HD_AUDIO); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 154 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 155 | case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 0): /* PCI Express Root Port 1 */ |
| 156 | case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 1): /* PCI Express Root Port 2 */ |
| 157 | case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 2): /* PCI Express Root Port 3 */ |
| 158 | case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 3): /* PCI Express Root Port 4 */ |
| 159 | case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 4): /* PCI Express Root Port 5 */ |
| 160 | case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 5): /* PCI Express Root Port 6 */ |
| 161 | case PCI_DEVFN(PCH_DEV_SLOT_PCIE, 6): /* PCI Express Root Port 7 */ |
| 162 | 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] | 163 | rcba_function_disable(FD, |
| 164 | PCH_DISABLE_PCIE(PCI_FUNC(dev->path.pci.devfn))); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 165 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 166 | case PCH_DEVFN_EHCI: /* EHCI #1 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 167 | rcba_function_disable(FD, PCH_DISABLE_EHCI1); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 168 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 169 | case PCH_DEVFN_LPC: /* LPC */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 170 | rcba_function_disable(FD, PCH_DISABLE_LPC); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 171 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 172 | case PCH_DEVFN_SATA: /* SATA #1 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 173 | rcba_function_disable(FD, PCH_DISABLE_SATA1); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 174 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 175 | case PCH_DEVFN_SMBUS: /* SMBUS */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 176 | rcba_function_disable(FD, PCH_DISABLE_SMBUS); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 177 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 178 | case PCH_DEVFN_SATA2: /* SATA #2 */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 179 | rcba_function_disable(FD, PCH_DISABLE_SATA2); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 180 | break; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 181 | case PCH_DEVFN_THERMAL: /* Thermal Subsystem */ |
Wenkai Du | aec2442 | 2014-10-15 11:19:16 -0700 | [diff] [blame] | 182 | rcba_function_disable(FD, PCH_DISABLE_THERMAL); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
Elyes HAOUAS | 4658a98 | 2018-09-20 08:46:35 +0200 | [diff] [blame] | 187 | void broadwell_pch_enable_dev(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 188 | { |
| 189 | u32 reg32; |
| 190 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 191 | /* These devices need special enable/disable handling */ |
| 192 | switch (PCI_SLOT(dev->path.pci.devfn)) { |
| 193 | case PCH_DEV_SLOT_PCIE: |
| 194 | case PCH_DEV_SLOT_EHCI: |
| 195 | case PCH_DEV_SLOT_HDA: |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 196 | return; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 197 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 198 | |
| 199 | if (!dev->enabled) { |
| 200 | printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev)); |
| 201 | |
| 202 | /* Ensure memory, io, and bus master are all disabled */ |
| 203 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 204 | reg32 &= ~(PCI_COMMAND_MASTER | |
| 205 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 206 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 207 | |
| 208 | /* Disable this device if possible */ |
| 209 | pch_disable_devfn(dev); |
| 210 | } else { |
| 211 | /* Enable SERR */ |
| 212 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 213 | reg32 |= PCI_COMMAND_SERR; |
| 214 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | #endif |