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