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