Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * 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 | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 17 | #include <delay.h> |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
| 21 | #include <arch/io.h> |
| 22 | #include "pch.h" |
| 23 | |
Stefan Reinauer | 6dbbe2e | 2013-10-17 17:00:26 -0700 | [diff] [blame] | 24 | typedef struct southbridge_intel_lynxpoint_config config_t; |
| 25 | |
Elyes HAOUAS | 1dcd8db | 2018-12-05 10:59:42 +0100 | [diff] [blame] | 26 | #ifdef __SIMPLE_DEVICE__ |
| 27 | static u8 *usb_xhci_mem_base(pci_devfn_t dev) |
| 28 | #else |
| 29 | static u8 *usb_xhci_mem_base(struct device *dev) |
| 30 | #endif |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 31 | { |
| 32 | u32 mem_base = pci_read_config32(dev, PCI_BASE_ADDRESS_0); |
| 33 | |
| 34 | /* Check if the controller is disabled or not present */ |
| 35 | if (mem_base == 0 || mem_base == 0xffffffff) |
| 36 | return 0; |
| 37 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 38 | return (u8 *)(mem_base & ~0xf); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Elyes HAOUAS | 1dcd8db | 2018-12-05 10:59:42 +0100 | [diff] [blame] | 41 | #ifdef __SIMPLE_DEVICE__ |
| 42 | static int usb_xhci_port_count_usb3(pci_devfn_t dev) |
| 43 | #else |
| 44 | static int usb_xhci_port_count_usb3(struct device *dev) |
| 45 | #endif |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 46 | { |
| 47 | if (pch_is_lp()) { |
| 48 | /* LynxPoint-LP has 4 SS ports */ |
| 49 | return 4; |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 50 | } |
Elyes HAOUAS | 54f9424 | 2018-10-25 10:57:39 +0200 | [diff] [blame] | 51 | /* LynxPoint-H can have 0, 2, 4, or 6 SS ports */ |
| 52 | u8 *mem_base = usb_xhci_mem_base(dev); |
| 53 | u32 fus = read32(mem_base + XHCI_USB3FUS); |
| 54 | fus >>= XHCI_USB3FUS_SS_SHIFT; |
| 55 | fus &= XHCI_USB3FUS_SS_MASK; |
| 56 | switch (fus) { |
| 57 | case 3: return 0; |
| 58 | case 2: return 2; |
| 59 | case 1: return 4; |
| 60 | case 0: |
| 61 | default: return 6; |
| 62 | } |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 65 | static void usb_xhci_reset_status_usb3(u8 *mem_base, int port) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 66 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 67 | u8 *portsc = mem_base + XHCI_USB3_PORTSC(port); |
Duncan Laurie | 0bf1dea | 2013-08-13 13:32:28 -0700 | [diff] [blame] | 68 | u32 status = read32(portsc); |
| 69 | /* Do not set Port Enabled/Disabled field */ |
| 70 | status &= ~XHCI_USB3_PORTSC_PED; |
| 71 | /* Clear all change status bits */ |
| 72 | status |= XHCI_USB3_PORTSC_CHST; |
| 73 | write32(portsc, status); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 76 | static void usb_xhci_reset_port_usb3(u8 *mem_base, int port) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 77 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 78 | u8 *portsc = mem_base + XHCI_USB3_PORTSC(port); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 79 | write32(portsc, read32(portsc) | XHCI_USB3_PORTSC_WPR); |
| 80 | } |
| 81 | |
| 82 | #define XHCI_RESET_DELAY_US 1000 /* 1ms */ |
| 83 | #define XHCI_RESET_TIMEOUT 100 /* 100ms */ |
| 84 | |
| 85 | /* |
| 86 | * 1) Wait until port is done polling |
| 87 | * 2) If port is disconnected |
| 88 | * a) Issue warm port reset |
| 89 | * b) Poll for warm reset complete |
| 90 | * c) Write 1 to port change status bits |
| 91 | */ |
Elyes HAOUAS | 1dcd8db | 2018-12-05 10:59:42 +0100 | [diff] [blame] | 92 | #ifdef __SIMPLE_DEVICE__ |
| 93 | static void usb_xhci_reset_usb3(pci_devfn_t dev, int all) |
| 94 | #else |
| 95 | static void usb_xhci_reset_usb3(struct device *dev, int all) |
| 96 | #endif |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 97 | { |
| 98 | u32 status, port_disabled; |
| 99 | int timeout, port; |
| 100 | int port_count = usb_xhci_port_count_usb3(dev); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 101 | u8 *mem_base = usb_xhci_mem_base(dev); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 102 | |
| 103 | if (!mem_base || !port_count) |
| 104 | return; |
| 105 | |
| 106 | /* Get mask of disabled ports */ |
| 107 | port_disabled = pci_read_config32(dev, XHCI_USB3PDO); |
| 108 | |
| 109 | /* Wait until all enabled ports are done polling */ |
| 110 | for (timeout = XHCI_RESET_TIMEOUT; timeout; timeout--) { |
| 111 | int complete = 1; |
| 112 | for (port = 0; port < port_count; port++) { |
| 113 | /* Skip disabled ports */ |
| 114 | if (port_disabled & (1 << port)) |
| 115 | continue; |
| 116 | /* Read port link status field */ |
| 117 | status = read32(mem_base + XHCI_USB3_PORTSC(port)); |
| 118 | status &= XHCI_USB3_PORTSC_PLS; |
| 119 | if (status == XHCI_PLSR_POLLING) |
| 120 | complete = 0; |
| 121 | } |
| 122 | /* Exit if all ports not polling */ |
| 123 | if (complete) |
| 124 | break; |
| 125 | udelay(XHCI_RESET_DELAY_US); |
| 126 | } |
| 127 | |
| 128 | /* Reset all requested ports */ |
| 129 | for (port = 0; port < port_count; port++) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 130 | u8 *portsc = mem_base + XHCI_USB3_PORTSC(port); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 131 | /* Skip disabled ports */ |
| 132 | if (port_disabled & (1 << port)) |
| 133 | continue; |
| 134 | status = read32(portsc) & XHCI_USB3_PORTSC_PLS; |
| 135 | /* Reset all or only disconnected ports */ |
Duncan Laurie | 32d2e2b | 2013-09-25 14:08:32 -0700 | [diff] [blame] | 136 | if (all || (status == XHCI_PLSR_RXDETECT || |
| 137 | status == XHCI_PLSR_POLLING)) |
Duncan Laurie | 16a0f5c | 2013-09-25 14:08:16 -0700 | [diff] [blame] | 138 | usb_xhci_reset_port_usb3(mem_base, port); |
| 139 | else |
| 140 | port_disabled |= 1 << port; |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* Wait for warm reset complete on all reset ports */ |
| 144 | for (timeout = XHCI_RESET_TIMEOUT; timeout; timeout--) { |
| 145 | int complete = 1; |
| 146 | for (port = 0; port < port_count; port++) { |
| 147 | /* Only check ports that were reset */ |
| 148 | if (port_disabled & (1 << port)) |
| 149 | continue; |
| 150 | /* Check if warm reset is complete */ |
| 151 | status = read32(mem_base + XHCI_USB3_PORTSC(port)); |
| 152 | if (!(status & XHCI_USB3_PORTSC_WRC)) |
| 153 | complete = 0; |
| 154 | } |
| 155 | /* Check for warm reset complete in any port */ |
| 156 | if (complete) |
| 157 | break; |
| 158 | udelay(XHCI_RESET_DELAY_US); |
| 159 | } |
| 160 | |
| 161 | /* Clear port change status bits */ |
| 162 | for (port = 0; port < port_count; port++) |
| 163 | usb_xhci_reset_status_usb3(mem_base, port); |
| 164 | } |
| 165 | |
Duncan Laurie | 32d2e2b | 2013-09-25 14:08:32 -0700 | [diff] [blame] | 166 | #ifdef __SMM__ |
| 167 | |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 168 | /* Handler for XHCI controller on entry to S3/S4/S5 */ |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 169 | void usb_xhci_sleep_prepare(pci_devfn_t dev, u8 slp_typ) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 170 | { |
| 171 | u16 reg16; |
| 172 | u32 reg32; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 173 | u8 *mem_base = usb_xhci_mem_base(dev); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 174 | |
Aaron Durbin | da5f509 | 2016-07-13 23:23:16 -0500 | [diff] [blame] | 175 | if (!mem_base || slp_typ < ACPI_S3) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 176 | return; |
| 177 | |
| 178 | if (pch_is_lp()) { |
| 179 | /* Set D0 state */ |
| 180 | reg16 = pci_read_config16(dev, XHCI_PWR_CTL_STS); |
| 181 | reg16 &= ~PWR_CTL_SET_MASK; |
| 182 | reg16 |= PWR_CTL_SET_D0; |
| 183 | pci_write_config16(dev, XHCI_PWR_CTL_STS, reg16); |
| 184 | |
| 185 | /* Clear PCI 0xB0[14:13] */ |
| 186 | reg32 = pci_read_config32(dev, 0xb0); |
| 187 | reg32 &= ~((1 << 14) | (1 << 13)); |
| 188 | pci_write_config32(dev, 0xb0, reg32); |
| 189 | |
| 190 | /* Clear MMIO 0x816c[14,2] */ |
| 191 | reg32 = read32(mem_base + 0x816c); |
| 192 | reg32 &= ~((1 << 14) | (1 << 2)); |
| 193 | write32(mem_base + 0x816c, reg32); |
| 194 | |
Duncan Laurie | 0bf1dea | 2013-08-13 13:32:28 -0700 | [diff] [blame] | 195 | /* Reset disconnected USB3 ports */ |
Duncan Laurie | 16a0f5c | 2013-09-25 14:08:16 -0700 | [diff] [blame] | 196 | usb_xhci_reset_usb3(dev, 0); |
Duncan Laurie | 0bf1dea | 2013-08-13 13:32:28 -0700 | [diff] [blame] | 197 | |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 198 | /* Set MMIO 0x80e0[15] */ |
| 199 | reg32 = read32(mem_base + 0x80e0); |
| 200 | reg32 |= (1 << 15); |
| 201 | write32(mem_base + 0x80e0, reg32); |
| 202 | } |
| 203 | |
| 204 | /* Set D3Hot state and enable PME */ |
| 205 | pci_or_config16(dev, XHCI_PWR_CTL_STS, PWR_CTL_SET_D3); |
Duncan Laurie | 0bf1dea | 2013-08-13 13:32:28 -0700 | [diff] [blame] | 206 | pci_or_config16(dev, XHCI_PWR_CTL_STS, PWR_CTL_STATUS_PME); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 207 | pci_or_config16(dev, XHCI_PWR_CTL_STS, PWR_CTL_ENABLE_PME); |
| 208 | } |
| 209 | |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 210 | /* Route all ports to XHCI controller */ |
| 211 | void usb_xhci_route_all(void) |
| 212 | { |
| 213 | u32 port_mask, route; |
| 214 | u16 reg16; |
| 215 | |
| 216 | /* Skip if EHCI is already disabled */ |
| 217 | if (RCBA32(FD) & PCH_DISABLE_EHCI1) |
| 218 | return; |
| 219 | |
| 220 | /* Set D0 state */ |
| 221 | reg16 = pci_read_config16(PCH_XHCI_DEV, XHCI_PWR_CTL_STS); |
| 222 | reg16 &= ~PWR_CTL_SET_MASK; |
| 223 | reg16 |= PWR_CTL_SET_D0; |
| 224 | pci_write_config16(PCH_XHCI_DEV, XHCI_PWR_CTL_STS, reg16); |
| 225 | |
| 226 | /* Set USB3 superspeed enable */ |
| 227 | port_mask = pci_read_config32(PCH_XHCI_DEV, XHCI_USB3PRM); |
| 228 | route = pci_read_config32(PCH_XHCI_DEV, XHCI_USB3PR); |
| 229 | route &= ~XHCI_USB3PR_SSEN; |
| 230 | route |= XHCI_USB3PR_SSEN & port_mask; |
| 231 | pci_write_config32(PCH_XHCI_DEV, XHCI_USB3PR, route); |
| 232 | |
| 233 | /* Route USB2 ports to XHCI controller */ |
| 234 | port_mask = pci_read_config32(PCH_XHCI_DEV, XHCI_USB2PRM); |
| 235 | route = pci_read_config32(PCH_XHCI_DEV, XHCI_USB2PR); |
| 236 | route &= ~XHCI_USB2PR_HCSEL; |
| 237 | route |= XHCI_USB2PR_HCSEL & port_mask; |
| 238 | pci_write_config32(PCH_XHCI_DEV, XHCI_USB2PR, route); |
| 239 | |
| 240 | /* Disable EHCI controller */ |
| 241 | usb_ehci_disable(PCH_EHCI1_DEV); |
| 242 | |
| 243 | /* LynxPoint-H has a second EHCI controller */ |
| 244 | if (!pch_is_lp()) |
| 245 | usb_ehci_disable(PCH_EHCI2_DEV); |
| 246 | |
| 247 | /* Reset and clear port change status */ |
Duncan Laurie | 16a0f5c | 2013-09-25 14:08:16 -0700 | [diff] [blame] | 248 | usb_xhci_reset_usb3(PCH_XHCI_DEV, 1); |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 251 | #else /* !__SMM__ */ |
| 252 | |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 253 | static void usb_xhci_clock_gating(struct device *dev) |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 254 | { |
| 255 | u32 reg32; |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 256 | u16 reg16; |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 257 | |
| 258 | /* IOBP 0xE5004001[7:6] = 11b */ |
| 259 | pch_iobp_update(0xe5004001, ~0, (1 << 7)|(1 << 6)); |
| 260 | |
| 261 | reg32 = pci_read_config32(dev, 0x40); |
| 262 | reg32 &= ~(1 << 23); /* unsupported request */ |
| 263 | |
| 264 | if (pch_is_lp()) { |
| 265 | /* D20:F0:40h[18,17,8] = 111b */ |
| 266 | reg32 |= (1 << 18) | (1 << 17) | (1 << 8); |
| 267 | /* D20:F0:40h[21,20,19] = 110b to enable XHCI Idle L1 */ |
| 268 | reg32 &= ~(1 << 19); |
| 269 | reg32 |= (1 << 21) | (1 << 20); |
| 270 | } else { |
| 271 | /* D20:F0:40h[21,20,18,17,8] = 11111b */ |
| 272 | reg32 |= (1 << 21)|(1 << 20)|(1 << 18)|(1 << 17)|(1 << 8); |
| 273 | } |
| 274 | |
| 275 | /* Avoid writing upper byte as it is write-once */ |
| 276 | pci_write_config16(dev, 0x40, (u16)(reg32 & 0xffff)); |
| 277 | pci_write_config8(dev, 0x40 + 2, (u8)((reg32 >> 16) & 0xff)); |
| 278 | |
| 279 | /* D20:F0:44h[9,7,3] = 111b */ |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 280 | reg16 = pci_read_config16(dev, 0x44); |
| 281 | reg16 |= (1 << 9) | (1 << 7) | (1 << 3); |
| 282 | pci_write_config16(dev, 0x44, reg16); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 283 | |
| 284 | reg32 = pci_read_config32(dev, 0xa0); |
| 285 | if (pch_is_lp()) { |
| 286 | /* D20:F0:A0h[18] = 1 */ |
| 287 | reg32 |= (1 << 18); |
| 288 | } else { |
| 289 | /* D20:F0:A0h[6] = 1 */ |
| 290 | reg32 |= (1 << 6); |
| 291 | } |
| 292 | pci_write_config32(dev, 0xa0, reg32); |
| 293 | |
| 294 | /* D20:F0:A4h[13] = 0 */ |
| 295 | reg32 = pci_read_config32(dev, 0xa4); |
| 296 | reg32 &= ~(1 << 13); |
| 297 | pci_write_config32(dev, 0xa4, reg32); |
| 298 | } |
| 299 | |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 300 | static void usb_xhci_init(struct device *dev) |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 301 | { |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 302 | u32 reg32; |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 303 | u16 reg16; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 304 | u8 *mem_base = usb_xhci_mem_base(dev); |
Stefan Reinauer | 6dbbe2e | 2013-10-17 17:00:26 -0700 | [diff] [blame] | 305 | config_t *config = dev->chip_info; |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 306 | |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 307 | /* D20:F0:74h[1:0] = 00b (set D0 state) */ |
| 308 | reg16 = pci_read_config16(dev, XHCI_PWR_CTL_STS); |
| 309 | reg16 &= ~PWR_CTL_SET_MASK; |
| 310 | reg16 |= PWR_CTL_SET_D0; |
| 311 | pci_write_config16(dev, XHCI_PWR_CTL_STS, reg16); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 312 | |
| 313 | /* Enable clock gating first */ |
| 314 | usb_xhci_clock_gating(dev); |
| 315 | |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 316 | reg32 = read32(mem_base + 0x8144); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 317 | if (pch_is_lp()) { |
| 318 | /* XHCIBAR + 8144h[8,7,6] = 111b */ |
| 319 | reg32 |= (1 << 8) | (1 << 7) | (1 << 6); |
| 320 | } else { |
| 321 | /* XHCIBAR + 8144h[8,7,6] = 100b */ |
| 322 | reg32 &= ~((1 << 7) | (1 << 6)); |
| 323 | reg32 |= (1 << 8); |
| 324 | } |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 325 | write32(mem_base + 0x8144, reg32); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 326 | |
| 327 | if (pch_is_lp()) { |
Duncan Laurie | 527b03a | 2013-08-28 09:53:50 -0700 | [diff] [blame] | 328 | /* XHCIBAR + 816Ch[19:0] = 000e0038h */ |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 329 | reg32 = read32(mem_base + 0x816c); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 330 | reg32 &= ~0x000fffff; |
Duncan Laurie | 527b03a | 2013-08-28 09:53:50 -0700 | [diff] [blame] | 331 | reg32 |= 0x000e0038; |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 332 | write32(mem_base + 0x816c, reg32); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 333 | |
| 334 | /* D20:F0:B0h[17,14,13] = 100b */ |
| 335 | reg32 = pci_read_config32(dev, 0xb0); |
| 336 | reg32 &= ~((1 << 14) | (1 << 13)); |
| 337 | reg32 |= (1 << 17); |
| 338 | pci_write_config32(dev, 0xb0, reg32); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | reg32 = pci_read_config32(dev, 0x50); |
| 342 | if (pch_is_lp()) { |
| 343 | /* D20:F0:50h[28:0] = 0FCE2E5Fh */ |
| 344 | reg32 &= ~0x1fffffff; |
| 345 | reg32 |= 0x0fce2e5f; |
| 346 | } else { |
| 347 | /* D20:F0:50h[26:0] = 07886E9Fh */ |
| 348 | reg32 &= ~0x07ffffff; |
| 349 | reg32 |= 0x07886e9f; |
| 350 | } |
| 351 | pci_write_config32(dev, 0x50, reg32); |
| 352 | |
| 353 | /* D20:F0:44h[31] = 1 (Access Control Bit) */ |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 354 | reg32 = pci_read_config32(dev, 0x44); |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 355 | reg32 |= (1UL << 31); |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 356 | pci_write_config32(dev, 0x44, reg32); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 357 | |
| 358 | /* D20:F0:40h[31,23] = 10b (OC Configuration Done) */ |
| 359 | reg32 = pci_read_config32(dev, 0x40); |
| 360 | reg32 &= ~(1 << 23); /* unsupported request */ |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 361 | reg32 |= (1UL << 31); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 362 | pci_write_config32(dev, 0x40, reg32); |
Duncan Laurie | 32d2e2b | 2013-09-25 14:08:32 -0700 | [diff] [blame] | 363 | |
| 364 | if (acpi_is_wakeup_s3()) { |
| 365 | /* Reset ports that are disabled or |
| 366 | * polling before returning to the OS. */ |
| 367 | usb_xhci_reset_usb3(dev, 0); |
Stefan Reinauer | 6dbbe2e | 2013-10-17 17:00:26 -0700 | [diff] [blame] | 368 | } else if (config->xhci_default) { |
| 369 | /* Route all ports to XHCI */ |
| 370 | outb(0xca, 0xb2); |
Duncan Laurie | 32d2e2b | 2013-09-25 14:08:32 -0700 | [diff] [blame] | 371 | } |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 374 | static void usb_xhci_set_subsystem(struct device *dev, unsigned int vendor, |
| 375 | unsigned int device) |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 376 | { |
| 377 | if (!vendor || !device) { |
| 378 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 379 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 380 | } else { |
| 381 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 382 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | static struct pci_operations lops_pci = { |
| 387 | .set_subsystem = &usb_xhci_set_subsystem, |
| 388 | }; |
| 389 | |
| 390 | static struct device_operations usb_xhci_ops = { |
| 391 | .read_resources = pci_dev_read_resources, |
| 392 | .set_resources = pci_dev_set_resources, |
| 393 | .enable_resources = pci_dev_enable_resources, |
| 394 | .init = usb_xhci_init, |
| 395 | .ops_pci = &lops_pci, |
| 396 | }; |
| 397 | |
| 398 | static const unsigned short pci_device_ids[] = { 0x8c31, /* LynxPoint-H */ |
| 399 | 0x9c31, /* LynxPoint-LP */ |
| 400 | 0 }; |
| 401 | |
| 402 | static const struct pci_driver pch_usb_xhci __pci_driver = { |
| 403 | .ops = &usb_xhci_ops, |
| 404 | .vendor = PCI_VENDOR_ID_INTEL, |
| 405 | .devices = pci_device_ids, |
| 406 | }; |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 407 | #endif /* !__SMM__ */ |