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