Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2013 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. |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <arch/io.h> |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 19 | #include <arch/acpi.h> |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 20 | #include <bootstate.h> |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 21 | #include <cbmem.h> |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 22 | #include <console/console.h> |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 23 | #include <cpu/x86/smm.h> |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 24 | #include <device/device.h> |
| 25 | #include <device/pci.h> |
| 26 | #include <device/pci_ids.h> |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 27 | #include <pc80/mc146818rtc.h> |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 28 | #include <drivers/uart/uart8250reg.h> |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 29 | |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 30 | #include <soc/iomap.h> |
| 31 | #include <soc/irq.h> |
| 32 | #include <soc/lpc.h> |
| 33 | #include <soc/nvs.h> |
| 34 | #include <soc/pci_devs.h> |
| 35 | #include <soc/pmc.h> |
| 36 | #include <soc/ramstage.h> |
| 37 | #include <soc/spi.h> |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 38 | #include "chip.h" |
Vladimir Serbinenko | 7fb149d | 2014-10-08 22:56:27 +0200 | [diff] [blame] | 39 | #include <arch/acpi.h> |
| 40 | #include <arch/acpigen.h> |
| 41 | #include <cpu/cpu.h> |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 42 | |
| 43 | static inline void |
| 44 | add_mmio_resource(device_t dev, int i, unsigned long addr, unsigned long size) |
| 45 | { |
| 46 | mmio_resource(dev, i, addr >> 10, size >> 10); |
| 47 | } |
| 48 | |
| 49 | static void sc_add_mmio_resources(device_t dev) |
| 50 | { |
Duncan Laurie | 7fbe20b | 2013-11-04 17:00:22 -0800 | [diff] [blame] | 51 | add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE); |
| 52 | add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE); |
| 53 | add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE); |
| 54 | add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE); |
| 55 | add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE); |
| 56 | add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE); |
| 57 | add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE); |
| 58 | add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE); |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* Default IO range claimed by the LPC device. The upper bound is exclusive. */ |
| 62 | #define LPC_DEFAULT_IO_RANGE_LOWER 0 |
| 63 | #define LPC_DEFAULT_IO_RANGE_UPPER 0x1000 |
| 64 | |
| 65 | static inline int io_range_in_default(int base, int size) |
| 66 | { |
| 67 | /* Does it start above the range? */ |
| 68 | if (base >= LPC_DEFAULT_IO_RANGE_UPPER) |
| 69 | return 0; |
| 70 | |
| 71 | /* Is it entirely contained? */ |
| 72 | if (base >= LPC_DEFAULT_IO_RANGE_LOWER && |
| 73 | (base + size) < LPC_DEFAULT_IO_RANGE_UPPER) |
| 74 | return 1; |
| 75 | |
| 76 | /* This will return not in range for partial overlaps. */ |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Note: this function assumes there is no overlap with the default LPC device's |
| 82 | * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER. |
| 83 | */ |
| 84 | static void sc_add_io_resource(device_t dev, int base, int size, int index) |
| 85 | { |
| 86 | struct resource *res; |
| 87 | |
| 88 | if (io_range_in_default(base, size)) |
| 89 | return; |
| 90 | |
| 91 | res = new_resource(dev, index); |
| 92 | res->base = base; |
| 93 | res->size = size; |
| 94 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 95 | } |
| 96 | |
| 97 | static void sc_add_io_resources(device_t dev) |
| 98 | { |
| 99 | struct resource *res; |
| 100 | |
| 101 | /* Add the default claimed IO range for the LPC device. */ |
| 102 | res = new_resource(dev, 0); |
| 103 | res->base = LPC_DEFAULT_IO_RANGE_LOWER; |
| 104 | res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER; |
| 105 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 106 | |
| 107 | /* GPIO */ |
| 108 | sc_add_io_resource(dev, GPIO_BASE_ADDRESS, 256, GBASE); |
| 109 | |
| 110 | /* ACPI */ |
| 111 | sc_add_io_resource(dev, ACPI_BASE_ADDRESS, 128, ABASE); |
| 112 | } |
| 113 | |
| 114 | static void sc_read_resources(device_t dev) |
| 115 | { |
| 116 | /* Get the normal PCI resources of this device. */ |
| 117 | pci_dev_read_resources(dev); |
| 118 | |
| 119 | /* Add non-standard MMIO resources. */ |
| 120 | sc_add_mmio_resources(dev); |
| 121 | |
| 122 | /* Add IO resources. */ |
| 123 | sc_add_io_resources(dev); |
| 124 | } |
| 125 | |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 126 | static void sc_rtc_init(void) |
| 127 | { |
| 128 | uint32_t gen_pmcon1; |
| 129 | int rtc_fail; |
| 130 | struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE); |
| 131 | |
| 132 | if (ps != NULL) { |
| 133 | gen_pmcon1 = ps->gen_pmcon1; |
| 134 | } else { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 135 | gen_pmcon1 = read32((u32 *)(PMC_BASE_ADDRESS + GEN_PMCON1)); |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | rtc_fail = !!(gen_pmcon1 & RPS); |
| 139 | |
| 140 | if (rtc_fail) { |
| 141 | printk(BIOS_DEBUG, "RTC failure.\n"); |
| 142 | } |
| 143 | |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 144 | cmos_init(rtc_fail); |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 147 | /* |
| 148 | * The UART hardware loses power while in suspend. Because of this the kernel |
| 149 | * can hang because it doesn't re-initialize serial ports it is using for |
| 150 | * consoles at resume time. The following function configures the UART |
| 151 | * if the hardware is enabled though it may not be the correct baud rate |
| 152 | * or configuration. This is definitely a hack, but it helps the kernel |
| 153 | * along. |
| 154 | */ |
| 155 | static void com1_configure_resume(device_t dev) |
| 156 | { |
| 157 | const uint16_t port = 0x3f8; |
| 158 | |
Martin Roth | 99a3bba | 2014-12-07 14:57:26 -0700 | [diff] [blame] | 159 | /* Is the UART I/O port enabled? */ |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 160 | if (!(pci_read_config32(dev, UART_CONT) & 1)) |
| 161 | return; |
| 162 | |
| 163 | /* Disable interrupts */ |
| 164 | outb(0x0, port + UART8250_IER); |
| 165 | |
| 166 | /* Enable FIFOs */ |
| 167 | outb(UART8250_FCR_FIFO_EN, port + UART8250_FCR); |
| 168 | |
| 169 | /* assert DTR and RTS so the other end is happy */ |
| 170 | outb(UART8250_MCR_DTR | UART8250_MCR_RTS, port + UART8250_MCR); |
| 171 | |
| 172 | /* DLAB on */ |
| 173 | outb(UART8250_LCR_DLAB | 3, port + UART8250_LCR); |
| 174 | |
| 175 | /* Set Baud Rate Divisor. 1 ==> 115200 Baud */ |
| 176 | outb(1, port + UART8250_DLL); |
| 177 | outb(0, port + UART8250_DLM); |
| 178 | |
| 179 | /* Set to 3 for 8N1 */ |
| 180 | outb(3, port + UART8250_LCR); |
| 181 | } |
| 182 | |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 183 | static void sc_init(device_t dev) |
| 184 | { |
| 185 | int i; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 186 | u8 *pr_base = (u8 *)(ILB_BASE_ADDRESS + 0x08); |
Alexander Couzens | 316170e | 2015-11-24 09:46:18 +0100 | [diff] [blame] | 187 | u16 *ir_base = (u16 *)(ILB_BASE_ADDRESS + 0x20); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 188 | u32 *gen_pmcon1 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON1); |
| 189 | u32 *actl = (u32 *)(ILB_BASE_ADDRESS + ACTL); |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 190 | const struct baytrail_irq_route *ir = &global_baytrail_irq_route; |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 191 | struct soc_intel_baytrail_config *config = dev->chip_info; |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 192 | |
| 193 | /* Set up the PIRQ PIC routing based on static config. */ |
| 194 | for (i = 0; i < NUM_PIRQS; i++) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 195 | write8(pr_base + i, ir->pic[i]); |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 196 | } |
| 197 | /* Set up the per device PIRQ routing base on static config. */ |
| 198 | for (i = 0; i < NUM_IR_DEVS; i++) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 199 | write16(ir_base + i, ir->pcidev[i]); |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 200 | } |
Aaron Durbin | 1af3663 | 2013-11-07 10:42:16 -0600 | [diff] [blame] | 201 | |
| 202 | /* Route SCI to IRQ9 */ |
| 203 | write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9); |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 204 | |
| 205 | sc_rtc_init(); |
| 206 | |
| 207 | if (config->disable_slp_x_stretch_sus_fail) { |
| 208 | printk(BIOS_DEBUG, "Disabling slp_x stretching.\n"); |
| 209 | write32(gen_pmcon1, |
| 210 | read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP); |
| 211 | } else { |
| 212 | write32(gen_pmcon1, |
| 213 | read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP); |
| 214 | } |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 215 | |
Kyösti Mälkki | 9e94dbf | 2015-01-08 20:03:18 +0200 | [diff] [blame] | 216 | if (acpi_is_wakeup_s3()) |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 217 | com1_configure_resume(dev); |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 218 | } |
| 219 | |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 220 | /* |
| 221 | * Common code for the south cluster devices. |
| 222 | */ |
| 223 | |
Martin Roth | 99a3bba | 2014-12-07 14:57:26 -0700 | [diff] [blame] | 224 | /* Set bit in function disable register to hide this device. */ |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 225 | static void sc_disable_devfn(device_t dev) |
| 226 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 227 | u32 *func_dis = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS); |
| 228 | u32 *func_dis2 = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS2); |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 229 | uint32_t mask = 0; |
| 230 | uint32_t mask2 = 0; |
| 231 | |
| 232 | switch (dev->path.pci.devfn) { |
| 233 | case PCI_DEVFN(SDIO_DEV, SDIO_FUNC): |
| 234 | mask |= SDIO_DIS; |
| 235 | break; |
| 236 | case PCI_DEVFN(SD_DEV, SD_FUNC): |
| 237 | mask |= SD_DIS; |
| 238 | break; |
| 239 | case PCI_DEVFN(SATA_DEV, SATA_FUNC): |
| 240 | mask |= SATA_DIS; |
| 241 | break; |
| 242 | case PCI_DEVFN(XHCI_DEV, XHCI_FUNC): |
| 243 | mask |= XHCI_DIS; |
| 244 | /* Disable super speed PHY when XHCI is not available. */ |
| 245 | mask2 |= USH_SS_PHY_DIS; |
| 246 | break; |
| 247 | case PCI_DEVFN(LPE_DEV, LPE_FUNC): |
| 248 | mask |= LPE_DIS; |
| 249 | break; |
| 250 | case PCI_DEVFN(MMC_DEV, MMC_FUNC): |
| 251 | mask |= MMC_DIS; |
| 252 | break; |
| 253 | case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC): |
| 254 | mask |= SIO_DMA1_DIS; |
| 255 | break; |
| 256 | case PCI_DEVFN(I2C1_DEV, I2C1_FUNC): |
| 257 | mask |= I2C1_DIS; |
| 258 | break; |
| 259 | case PCI_DEVFN(I2C2_DEV, I2C2_FUNC): |
| 260 | mask |= I2C1_DIS; |
| 261 | break; |
| 262 | case PCI_DEVFN(I2C3_DEV, I2C3_FUNC): |
| 263 | mask |= I2C3_DIS; |
| 264 | break; |
| 265 | case PCI_DEVFN(I2C4_DEV, I2C4_FUNC): |
| 266 | mask |= I2C4_DIS; |
| 267 | break; |
| 268 | case PCI_DEVFN(I2C5_DEV, I2C5_FUNC): |
| 269 | mask |= I2C5_DIS; |
| 270 | break; |
| 271 | case PCI_DEVFN(I2C6_DEV, I2C6_FUNC): |
| 272 | mask |= I2C6_DIS; |
| 273 | break; |
| 274 | case PCI_DEVFN(I2C7_DEV, I2C7_FUNC): |
| 275 | mask |= I2C7_DIS; |
| 276 | break; |
| 277 | case PCI_DEVFN(TXE_DEV, TXE_FUNC): |
| 278 | mask |= TXE_DIS; |
| 279 | break; |
| 280 | case PCI_DEVFN(HDA_DEV, HDA_FUNC): |
| 281 | mask |= HDA_DIS; |
| 282 | break; |
| 283 | case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC): |
| 284 | mask |= PCIE_PORT1_DIS; |
| 285 | break; |
| 286 | case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC): |
| 287 | mask |= PCIE_PORT2_DIS; |
| 288 | break; |
| 289 | case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC): |
| 290 | mask |= PCIE_PORT3_DIS; |
| 291 | break; |
| 292 | case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC): |
| 293 | mask |= PCIE_PORT4_DIS; |
| 294 | break; |
| 295 | case PCI_DEVFN(EHCI_DEV, EHCI_FUNC): |
| 296 | mask |= EHCI_DIS; |
| 297 | break; |
| 298 | case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC): |
| 299 | mask |= SIO_DMA2_DIS; |
| 300 | break; |
| 301 | case PCI_DEVFN(PWM1_DEV, PWM1_FUNC): |
| 302 | mask |= PWM1_DIS; |
| 303 | break; |
| 304 | case PCI_DEVFN(PWM2_DEV, PWM2_FUNC): |
| 305 | mask |= PWM2_DIS; |
| 306 | break; |
| 307 | case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC): |
| 308 | mask |= HSUART1_DIS; |
| 309 | break; |
| 310 | case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC): |
| 311 | mask |= HSUART2_DIS; |
| 312 | break; |
| 313 | case PCI_DEVFN(SPI_DEV, SPI_FUNC): |
| 314 | mask |= SPI_DIS; |
| 315 | break; |
| 316 | case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC): |
| 317 | mask2 |= SMBUS_DIS; |
| 318 | break; |
| 319 | } |
| 320 | |
| 321 | if (mask != 0) { |
| 322 | write32(func_dis, read32(func_dis) | mask); |
| 323 | /* Ensure posted write hits. */ |
| 324 | read32(func_dis); |
| 325 | } |
| 326 | |
| 327 | if (mask2 != 0) { |
| 328 | write32(func_dis2, read32(func_dis2) | mask2); |
| 329 | /* Ensure posted write hits. */ |
| 330 | read32(func_dis2); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | static inline void set_d3hot_bits(device_t dev, int offset) |
| 335 | { |
| 336 | uint32_t reg8; |
| 337 | printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset); |
| 338 | reg8 = pci_read_config8(dev, offset + 4); |
| 339 | reg8 |= 0x3; |
| 340 | pci_write_config8(dev, offset + 4, reg8); |
| 341 | } |
| 342 | |
Aaron Durbin | 46ab8cd | 2013-10-30 17:07:46 -0500 | [diff] [blame] | 343 | /* Parts of the audio subsystem are powered by the HDA device. Therefore, one |
| 344 | * cannot put HDA into D3Hot. Instead perform this workaround to make some of |
| 345 | * the audio paths work for LPE audio. */ |
| 346 | static void hda_work_around(device_t dev) |
| 347 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 348 | u32 *gctl = (u32 *)(TEMP_BASE_ADDRESS + 0x8); |
Aaron Durbin | 46ab8cd | 2013-10-30 17:07:46 -0500 | [diff] [blame] | 349 | |
| 350 | /* Need to set magic register 0x43 to 0xd7 in config space. */ |
| 351 | pci_write_config8(dev, 0x43, 0xd7); |
| 352 | |
| 353 | /* Need to set bit 0 of GCTL to take the device out of reset. However, |
| 354 | * that requires setting up the 64-bit BAR. */ |
| 355 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS); |
| 356 | pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0); |
| 357 | pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY); |
| 358 | write32(gctl, read32(gctl) | 0x1); |
| 359 | pci_write_config8(dev, PCI_COMMAND, 0); |
| 360 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0); |
| 361 | } |
| 362 | |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 363 | static int place_device_in_d3hot(device_t dev) |
| 364 | { |
| 365 | unsigned offset; |
| 366 | |
Aaron Durbin | 46ab8cd | 2013-10-30 17:07:46 -0500 | [diff] [blame] | 367 | /* Parts of the HDA block are used for LPE audio as well. |
| 368 | * Therefore assume the HDA will never be put into D3Hot. */ |
| 369 | if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) { |
| 370 | hda_work_around(dev); |
| 371 | return 0; |
| 372 | } |
| 373 | |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 374 | offset = pci_find_capability(dev, PCI_CAP_ID_PM); |
| 375 | |
| 376 | if (offset != 0) { |
| 377 | set_d3hot_bits(dev, offset); |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | /* For some reason some of the devices don't have the capability |
| 382 | * pointer set correctly. Work around this by hard coding the offset. */ |
| 383 | switch (dev->path.pci.devfn) { |
| 384 | case PCI_DEVFN(SDIO_DEV, SDIO_FUNC): |
| 385 | offset = 0x80; |
| 386 | break; |
| 387 | case PCI_DEVFN(SD_DEV, SD_FUNC): |
| 388 | offset = 0x80; |
| 389 | break; |
| 390 | case PCI_DEVFN(MMC_DEV, MMC_FUNC): |
| 391 | offset = 0x80; |
| 392 | break; |
| 393 | case PCI_DEVFN(LPE_DEV, LPE_FUNC): |
| 394 | offset = 0x80; |
| 395 | break; |
| 396 | case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC): |
| 397 | offset = 0x80; |
| 398 | break; |
| 399 | case PCI_DEVFN(I2C1_DEV, I2C1_FUNC): |
| 400 | offset = 0x80; |
| 401 | break; |
| 402 | case PCI_DEVFN(I2C2_DEV, I2C2_FUNC): |
| 403 | offset = 0x80; |
| 404 | break; |
| 405 | case PCI_DEVFN(I2C3_DEV, I2C3_FUNC): |
| 406 | offset = 0x80; |
| 407 | break; |
| 408 | case PCI_DEVFN(I2C4_DEV, I2C4_FUNC): |
| 409 | offset = 0x80; |
| 410 | break; |
| 411 | case PCI_DEVFN(I2C5_DEV, I2C5_FUNC): |
| 412 | offset = 0x80; |
| 413 | break; |
| 414 | case PCI_DEVFN(I2C6_DEV, I2C6_FUNC): |
| 415 | offset = 0x80; |
| 416 | break; |
| 417 | case PCI_DEVFN(I2C7_DEV, I2C7_FUNC): |
| 418 | offset = 0x80; |
| 419 | break; |
| 420 | case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC): |
| 421 | offset = 0x80; |
| 422 | break; |
| 423 | case PCI_DEVFN(PWM1_DEV, PWM1_FUNC): |
| 424 | offset = 0x80; |
| 425 | break; |
| 426 | case PCI_DEVFN(PWM2_DEV, PWM2_FUNC): |
| 427 | offset = 0x80; |
| 428 | break; |
| 429 | case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC): |
| 430 | offset = 0x80; |
| 431 | break; |
| 432 | case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC): |
| 433 | offset = 0x80; |
| 434 | break; |
| 435 | case PCI_DEVFN(SPI_DEV, SPI_FUNC): |
| 436 | offset = 0x80; |
| 437 | break; |
| 438 | case PCI_DEVFN(SATA_DEV, SATA_FUNC): |
| 439 | offset = 0x70; |
| 440 | break; |
| 441 | case PCI_DEVFN(XHCI_DEV, XHCI_FUNC): |
| 442 | offset = 0x70; |
| 443 | break; |
| 444 | case PCI_DEVFN(EHCI_DEV, EHCI_FUNC): |
| 445 | offset = 0x70; |
| 446 | break; |
| 447 | case PCI_DEVFN(HDA_DEV, HDA_FUNC): |
| 448 | offset = 0x50; |
| 449 | break; |
| 450 | case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC): |
| 451 | offset = 0x50; |
| 452 | break; |
| 453 | case PCI_DEVFN(TXE_DEV, TXE_FUNC): |
Aaron Durbin | 1eae3ee | 2013-10-30 17:08:59 -0500 | [diff] [blame] | 454 | /* TXE cannot be placed in D3Hot. */ |
| 455 | return 0; |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 456 | case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC): |
| 457 | offset = 0xa0; |
| 458 | break; |
| 459 | case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC): |
| 460 | offset = 0xa0; |
| 461 | break; |
| 462 | case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC): |
| 463 | offset = 0xa0; |
| 464 | break; |
| 465 | case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC): |
| 466 | offset = 0xa0; |
| 467 | break; |
| 468 | } |
| 469 | |
| 470 | if (offset != 0) { |
| 471 | set_d3hot_bits(dev, offset); |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | return -1; |
| 476 | } |
| 477 | |
| 478 | /* Common PCI device function disable. */ |
| 479 | void southcluster_enable_dev(device_t dev) |
| 480 | { |
| 481 | uint32_t reg32; |
| 482 | |
| 483 | if (!dev->enabled) { |
| 484 | int slot = PCI_SLOT(dev->path.pci.devfn); |
| 485 | int func = PCI_FUNC(dev->path.pci.devfn); |
| 486 | printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n", |
| 487 | dev_path(dev), slot, func); |
| 488 | |
| 489 | /* Ensure memory, io, and bus master are all disabled */ |
| 490 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 491 | reg32 &= ~(PCI_COMMAND_MASTER | |
| 492 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 493 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 494 | |
| 495 | /* Place device in D3Hot */ |
| 496 | if (place_device_in_d3hot(dev) < 0) { |
| 497 | printk(BIOS_WARNING, |
| 498 | "Could not place %02x.%01x into D3Hot. " |
| 499 | "Keeping device visible.\n", slot, func); |
| 500 | return; |
| 501 | } |
| 502 | /* Disable this device if possible */ |
| 503 | sc_disable_devfn(dev); |
| 504 | } else { |
| 505 | /* Enable SERR */ |
| 506 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 507 | reg32 |= PCI_COMMAND_SERR; |
| 508 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 509 | } |
| 510 | } |
| 511 | |
Alexander Couzens | a90dad1 | 2015-04-12 21:49:46 +0200 | [diff] [blame] | 512 | static void southcluster_inject_dsdt(device_t device) |
Vladimir Serbinenko | 7fb149d | 2014-10-08 22:56:27 +0200 | [diff] [blame] | 513 | { |
| 514 | global_nvs_t *gnvs; |
| 515 | |
| 516 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 517 | if (!gnvs) { |
| 518 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof (*gnvs)); |
| 519 | if (gnvs) |
| 520 | memset(gnvs, 0, sizeof(*gnvs)); |
| 521 | } |
| 522 | |
| 523 | if (gnvs) { |
| 524 | acpi_create_gnvs(gnvs); |
| 525 | acpi_save_gnvs((unsigned long)gnvs); |
| 526 | /* And tell SMI about it */ |
| 527 | smm_setup_structures(gnvs, NULL, NULL); |
| 528 | |
| 529 | /* Add it to DSDT. */ |
| 530 | acpigen_write_scope("\\"); |
| 531 | acpigen_write_name_dword("NVSA", (u32) gnvs); |
| 532 | acpigen_pop_len(); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 537 | static struct device_operations device_ops = { |
| 538 | .read_resources = sc_read_resources, |
| 539 | .set_resources = pci_dev_set_resources, |
Vladimir Serbinenko | 7fb149d | 2014-10-08 22:56:27 +0200 | [diff] [blame] | 540 | .acpi_inject_dsdt_generator = southcluster_inject_dsdt, |
| 541 | .write_acpi_tables = acpi_write_hpet, |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 542 | .enable_resources = NULL, |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 543 | .init = sc_init, |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 544 | .enable = southcluster_enable_dev, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 545 | .scan_bus = scan_lpc_bus, |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 546 | .ops_pci = &soc_pci_ops, |
| 547 | }; |
| 548 | |
| 549 | static const struct pci_driver southcluster __pci_driver = { |
| 550 | .ops = &device_ops, |
| 551 | .vendor = PCI_VENDOR_ID_INTEL, |
| 552 | .device = LPC_DEVID, |
| 553 | }; |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 554 | |
| 555 | int __attribute__((weak)) mainboard_get_spi_config(struct spi_config *cfg) |
| 556 | { |
| 557 | return -1; |
| 558 | } |
| 559 | |
| 560 | static void finalize_chipset(void *unused) |
| 561 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 562 | u32 *bcr = (u32 *)(SPI_BASE_ADDRESS + BCR); |
| 563 | u32 *gcs = (u32 *)(RCBA_BASE_ADDRESS + GCS); |
| 564 | u32 *gen_pmcon2 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON2); |
| 565 | u32 *etr = (u32 *)(PMC_BASE_ADDRESS + ETR); |
| 566 | u8 *spi = (u8 *)SPI_BASE_ADDRESS; |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 567 | struct spi_config cfg; |
| 568 | |
| 569 | /* Set the lock enable on the BIOS control register. */ |
| 570 | write32(bcr, read32(bcr) | BCR_LE); |
| 571 | |
| 572 | /* Set BIOS lock down bit controlling boot block size and swapping. */ |
| 573 | write32(gcs, read32(gcs) | BILD); |
| 574 | |
| 575 | /* Lock sleep stretching policy and set SMI lock. */ |
| 576 | write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK); |
| 577 | |
| 578 | /* Set the CF9 lock. */ |
| 579 | write32(etr, read32(etr) | CF9LOCK); |
| 580 | |
| 581 | if (mainboard_get_spi_config(&cfg) < 0) { |
| 582 | printk(BIOS_DEBUG, "No SPI lockdown configuration.\n"); |
| 583 | } else { |
| 584 | write16(spi + PREOP, cfg.preop); |
| 585 | write16(spi + OPTYPE, cfg.optype); |
| 586 | write32(spi + OPMENU0, cfg.opmenu[0]); |
| 587 | write32(spi + OPMENU1, cfg.opmenu[1]); |
| 588 | write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN); |
| 589 | write32(spi + UVSCC, cfg.uvscc); |
| 590 | write32(spi + LVSCC, cfg.lvscc | VCL); |
| 591 | } |
| 592 | |
| 593 | printk(BIOS_DEBUG, "Finalizing SMM.\n"); |
| 594 | outb(APM_CNT_FINALIZE, APM_CNT); |
| 595 | } |
| 596 | |
Aaron Durbin | 9ef9d85 | 2015-03-16 17:30:09 -0500 | [diff] [blame] | 597 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL); |
| 598 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, finalize_chipset, NULL); |