b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * xHCI host controller driver PCI Bus Glue. |
| 4 | * |
| 5 | * Copyright (C) 2008 Intel Corp. |
| 6 | * |
| 7 | * Author: Sarah Sharp |
| 8 | * Some code borrowed from the Linux EHCI driver. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/pci.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/acpi.h> |
| 15 | |
| 16 | #include "xhci.h" |
| 17 | #include "xhci-trace.h" |
| 18 | #include "xhci-pci.h" |
| 19 | |
| 20 | #define SSIC_PORT_NUM 2 |
| 21 | #define SSIC_PORT_CFG2 0x880c |
| 22 | #define SSIC_PORT_CFG2_OFFSET 0x30 |
| 23 | #define PROG_DONE (1 << 30) |
| 24 | #define SSIC_PORT_UNUSED (1 << 31) |
| 25 | #define SPARSE_DISABLE_BIT 17 |
| 26 | #define SPARSE_CNTL_ENABLE 0xC12C |
| 27 | |
| 28 | /* Device for a quirk */ |
| 29 | #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73 |
| 30 | #define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000 |
| 31 | #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1009 0x1009 |
| 32 | #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1100 0x1100 |
| 33 | #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400 |
| 34 | |
| 35 | #define PCI_VENDOR_ID_ETRON 0x1b6f |
| 36 | #define PCI_DEVICE_ID_EJ168 0x7023 |
| 37 | #define PCI_DEVICE_ID_EJ188 0x7052 |
| 38 | |
| 39 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31 |
| 40 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 |
| 41 | #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI 0x9cb1 |
| 42 | #define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5 |
| 43 | #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f |
| 44 | #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI 0x9d2f |
| 45 | #define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI 0x0aa8 |
| 46 | #define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8 |
| 47 | #define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8 |
| 48 | #define PCI_DEVICE_ID_INTEL_DNV_XHCI 0x19d0 |
| 49 | #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI 0x15b5 |
| 50 | #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI 0x15b6 |
| 51 | #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI 0x15c1 |
| 52 | #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI 0x15db |
| 53 | #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI 0x15d4 |
| 54 | #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI 0x15e9 |
| 55 | #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI 0x15ec |
| 56 | #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI 0x15f0 |
| 57 | #define PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI 0x8a13 |
| 58 | #define PCI_DEVICE_ID_INTEL_CML_XHCI 0xa3af |
| 59 | |
| 60 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9 |
| 61 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba |
| 62 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb |
| 63 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc |
| 64 | #define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_1 0x161a |
| 65 | #define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_2 0x161b |
| 66 | #define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_3 0x161d |
| 67 | #define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_4 0x161e |
| 68 | #define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_5 0x15d6 |
| 69 | #define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_6 0x15d7 |
| 70 | #define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_7 0x161c |
| 71 | #define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_8 0x161f |
| 72 | |
| 73 | #define PCI_DEVICE_ID_ASMEDIA_1042_XHCI 0x1042 |
| 74 | #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142 |
| 75 | #define PCI_DEVICE_ID_ASMEDIA_1142_XHCI 0x1242 |
| 76 | #define PCI_DEVICE_ID_ASMEDIA_2142_XHCI 0x2142 |
| 77 | #define PCI_DEVICE_ID_ASMEDIA_3042_XHCI 0x3042 |
| 78 | #define PCI_DEVICE_ID_ASMEDIA_3242_XHCI 0x3242 |
| 79 | |
| 80 | static const char hcd_name[] = "xhci_hcd"; |
| 81 | |
| 82 | static struct hc_driver __read_mostly xhci_pci_hc_driver; |
| 83 | static int xhci_pci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, |
| 84 | struct usb_tt *tt, gfp_t mem_flags); |
| 85 | |
| 86 | static const struct xhci_driver_overrides xhci_pci_overrides __initconst = { |
| 87 | .reset = xhci_pci_setup, |
| 88 | .update_hub_device = xhci_pci_update_hub_device, |
| 89 | }; |
| 90 | |
| 91 | /* called after powerup, by probe or system-pm "wakeup" */ |
| 92 | static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev) |
| 93 | { |
| 94 | /* |
| 95 | * TODO: Implement finding debug ports later. |
| 96 | * TODO: see if there are any quirks that need to be added to handle |
| 97 | * new extended capabilities. |
| 98 | */ |
| 99 | |
| 100 | /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */ |
| 101 | if (!pci_set_mwi(pdev)) |
| 102 | xhci_dbg(xhci, "MWI active\n"); |
| 103 | |
| 104 | xhci_dbg(xhci, "Finished xhci_pci_reinit\n"); |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) |
| 109 | { |
| 110 | struct pci_dev *pdev = to_pci_dev(dev); |
| 111 | |
| 112 | /* Look for vendor-specific quirks */ |
| 113 | if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && |
| 114 | (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK || |
| 115 | pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1400)) { |
| 116 | if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK && |
| 117 | pdev->revision == 0x0) { |
| 118 | xhci->quirks |= XHCI_RESET_EP_QUIRK; |
| 119 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, |
| 120 | "QUIRK: Fresco Logic xHC needs configure" |
| 121 | " endpoint cmd after reset endpoint"); |
| 122 | } |
| 123 | if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK && |
| 124 | pdev->revision == 0x4) { |
| 125 | xhci->quirks |= XHCI_SLOW_SUSPEND; |
| 126 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, |
| 127 | "QUIRK: Fresco Logic xHC revision %u" |
| 128 | "must be suspended extra slowly", |
| 129 | pdev->revision); |
| 130 | } |
| 131 | if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK) |
| 132 | xhci->quirks |= XHCI_BROKEN_STREAMS; |
| 133 | /* Fresco Logic confirms: all revisions of this chip do not |
| 134 | * support MSI, even though some of them claim to in their PCI |
| 135 | * capabilities. |
| 136 | */ |
| 137 | xhci->quirks |= XHCI_BROKEN_MSI; |
| 138 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, |
| 139 | "QUIRK: Fresco Logic revision %u " |
| 140 | "has broken MSI implementation", |
| 141 | pdev->revision); |
| 142 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
| 143 | } |
| 144 | |
| 145 | if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && |
| 146 | pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1009) |
| 147 | xhci->quirks |= XHCI_BROKEN_STREAMS; |
| 148 | |
| 149 | if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && |
| 150 | pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1100) |
| 151 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
| 152 | |
| 153 | if (pdev->vendor == PCI_VENDOR_ID_NEC) |
| 154 | xhci->quirks |= XHCI_NEC_HOST; |
| 155 | |
| 156 | if (pdev->vendor == PCI_VENDOR_ID_AMD && xhci->hci_version == 0x96) |
| 157 | xhci->quirks |= XHCI_AMD_0x96_HOST; |
| 158 | |
| 159 | /* AMD PLL quirk */ |
| 160 | if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_quirk_pll_check()) |
| 161 | xhci->quirks |= XHCI_AMD_PLL_FIX; |
| 162 | |
| 163 | if (pdev->vendor == PCI_VENDOR_ID_AMD && |
| 164 | (pdev->device == 0x145c || |
| 165 | pdev->device == 0x15e0 || |
| 166 | pdev->device == 0x15e1 || |
| 167 | pdev->device == 0x43bb)) |
| 168 | xhci->quirks |= XHCI_SUSPEND_DELAY; |
| 169 | |
| 170 | if (pdev->vendor == PCI_VENDOR_ID_AMD && |
| 171 | (pdev->device == 0x15e0 || pdev->device == 0x15e1)) |
| 172 | xhci->quirks |= XHCI_SNPS_BROKEN_SUSPEND; |
| 173 | |
| 174 | if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x15e5) { |
| 175 | xhci->quirks |= XHCI_DISABLE_SPARSE; |
| 176 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
| 177 | } |
| 178 | |
| 179 | if (pdev->vendor == PCI_VENDOR_ID_AMD) |
| 180 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
| 181 | |
| 182 | if ((pdev->vendor == PCI_VENDOR_ID_AMD) && |
| 183 | ((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) || |
| 184 | (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) || |
| 185 | (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2) || |
| 186 | (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_1))) |
| 187 | xhci->quirks |= XHCI_U2_DISABLE_WAKE; |
| 188 | |
| 189 | if (pdev->vendor == PCI_VENDOR_ID_INTEL) { |
| 190 | xhci->quirks |= XHCI_LPM_SUPPORT; |
| 191 | xhci->quirks |= XHCI_INTEL_HOST; |
| 192 | xhci->quirks |= XHCI_AVOID_BEI; |
| 193 | } |
| 194 | if (pdev->vendor == PCI_VENDOR_ID_INTEL && |
| 195 | pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) { |
| 196 | xhci->quirks |= XHCI_EP_LIMIT_QUIRK; |
| 197 | xhci->limit_active_eps = 64; |
| 198 | xhci->quirks |= XHCI_SW_BW_CHECKING; |
| 199 | /* |
| 200 | * PPT desktop boards DH77EB and DH77DF will power back on after |
| 201 | * a few seconds of being shutdown. The fix for this is to |
| 202 | * switch the ports from xHCI to EHCI on shutdown. We can't use |
| 203 | * DMI information to find those particular boards (since each |
| 204 | * vendor will change the board name), so we have to key off all |
| 205 | * PPT chipsets. |
| 206 | */ |
| 207 | xhci->quirks |= XHCI_SPURIOUS_REBOOT; |
| 208 | } |
| 209 | if (pdev->vendor == PCI_VENDOR_ID_INTEL && |
| 210 | (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI || |
| 211 | pdev->device == PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI)) { |
| 212 | xhci->quirks |= XHCI_SPURIOUS_REBOOT; |
| 213 | xhci->quirks |= XHCI_SPURIOUS_WAKEUP; |
| 214 | } |
| 215 | if (pdev->vendor == PCI_VENDOR_ID_INTEL && |
| 216 | (pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI || |
| 217 | pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI || |
| 218 | pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI || |
| 219 | pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI || |
| 220 | pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI || |
| 221 | pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI || |
| 222 | pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI || |
| 223 | pdev->device == PCI_DEVICE_ID_INTEL_CML_XHCI)) { |
| 224 | xhci->quirks |= XHCI_PME_STUCK_QUIRK; |
| 225 | } |
| 226 | if (pdev->vendor == PCI_VENDOR_ID_INTEL && |
| 227 | pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI) |
| 228 | xhci->quirks |= XHCI_SSIC_PORT_UNUSED; |
| 229 | if (pdev->vendor == PCI_VENDOR_ID_INTEL && |
| 230 | (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI || |
| 231 | pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI || |
| 232 | pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI)) |
| 233 | xhci->quirks |= XHCI_INTEL_USB_ROLE_SW; |
| 234 | if (pdev->vendor == PCI_VENDOR_ID_INTEL && |
| 235 | (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI || |
| 236 | pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI || |
| 237 | pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI || |
| 238 | pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI || |
| 239 | pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI)) |
| 240 | xhci->quirks |= XHCI_MISSING_CAS; |
| 241 | |
| 242 | if (pdev->vendor == PCI_VENDOR_ID_INTEL && |
| 243 | (pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI || |
| 244 | pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI || |
| 245 | pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI || |
| 246 | pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI || |
| 247 | pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI || |
| 248 | pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI || |
| 249 | pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI || |
| 250 | pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI || |
| 251 | pdev->device == PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI)) |
| 252 | xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; |
| 253 | |
| 254 | if (pdev->vendor == PCI_VENDOR_ID_ETRON && |
| 255 | pdev->device == PCI_DEVICE_ID_EJ168) { |
| 256 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
| 257 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
| 258 | xhci->quirks |= XHCI_BROKEN_STREAMS; |
| 259 | } |
| 260 | if (pdev->vendor == PCI_VENDOR_ID_ETRON && |
| 261 | pdev->device == PCI_DEVICE_ID_EJ188) { |
| 262 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
| 263 | xhci->quirks |= XHCI_BROKEN_STREAMS; |
| 264 | } |
| 265 | |
| 266 | if (pdev->vendor == PCI_VENDOR_ID_RENESAS && |
| 267 | pdev->device == 0x0014) { |
| 268 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
| 269 | xhci->quirks |= XHCI_ZERO_64B_REGS; |
| 270 | } |
| 271 | if (pdev->vendor == PCI_VENDOR_ID_RENESAS && |
| 272 | pdev->device == 0x0015) { |
| 273 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
| 274 | xhci->quirks |= XHCI_ZERO_64B_REGS; |
| 275 | } |
| 276 | if (pdev->vendor == PCI_VENDOR_ID_VIA) |
| 277 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
| 278 | |
| 279 | /* See https://bugzilla.kernel.org/show_bug.cgi?id=79511 */ |
| 280 | if (pdev->vendor == PCI_VENDOR_ID_VIA && |
| 281 | pdev->device == 0x3432) |
| 282 | xhci->quirks |= XHCI_BROKEN_STREAMS; |
| 283 | |
| 284 | if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && |
| 285 | pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI) { |
| 286 | /* |
| 287 | * try to tame the ASMedia 1042 controller which reports 0.96 |
| 288 | * but appears to behave more like 1.0 |
| 289 | */ |
| 290 | xhci->quirks |= XHCI_SPURIOUS_SUCCESS; |
| 291 | xhci->quirks |= XHCI_BROKEN_STREAMS; |
| 292 | } |
| 293 | if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && |
| 294 | pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI) { |
| 295 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
| 296 | xhci->quirks |= XHCI_NO_64BIT_SUPPORT; |
| 297 | } |
| 298 | if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && |
| 299 | (pdev->device == PCI_DEVICE_ID_ASMEDIA_1142_XHCI || |
| 300 | pdev->device == PCI_DEVICE_ID_ASMEDIA_2142_XHCI || |
| 301 | pdev->device == PCI_DEVICE_ID_ASMEDIA_3242_XHCI)) |
| 302 | xhci->quirks |= XHCI_NO_64BIT_SUPPORT; |
| 303 | |
| 304 | if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && |
| 305 | pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI) |
| 306 | xhci->quirks |= XHCI_ASMEDIA_MODIFY_FLOWCONTROL; |
| 307 | |
| 308 | if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && |
| 309 | pdev->device == PCI_DEVICE_ID_ASMEDIA_3042_XHCI) |
| 310 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
| 311 | |
| 312 | if (pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241) |
| 313 | xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_7; |
| 314 | |
| 315 | if ((pdev->vendor == PCI_VENDOR_ID_BROADCOM || |
| 316 | pdev->vendor == PCI_VENDOR_ID_CAVIUM) && |
| 317 | pdev->device == 0x9026) |
| 318 | xhci->quirks |= XHCI_RESET_PLL_ON_DISCONNECT; |
| 319 | |
| 320 | if (pdev->vendor == PCI_VENDOR_ID_AMD && |
| 321 | (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2 || |
| 322 | pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4)) |
| 323 | xhci->quirks |= XHCI_NO_SOFT_RETRY; |
| 324 | |
| 325 | if (pdev->vendor == PCI_VENDOR_ID_AMD && |
| 326 | (pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_1 || |
| 327 | pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_2 || |
| 328 | pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_3 || |
| 329 | pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_4 || |
| 330 | pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_5 || |
| 331 | pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_6 || |
| 332 | pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_7 || |
| 333 | pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_8)) |
| 334 | xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; |
| 335 | |
| 336 | if (xhci->quirks & XHCI_RESET_ON_RESUME) |
| 337 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, |
| 338 | "QUIRK: Resetting on resume"); |
| 339 | } |
| 340 | |
| 341 | #ifdef CONFIG_ACPI |
| 342 | static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev) |
| 343 | { |
| 344 | static const guid_t intel_dsm_guid = |
| 345 | GUID_INIT(0xac340cb7, 0xe901, 0x45bf, |
| 346 | 0xb7, 0xe6, 0x2b, 0x34, 0xec, 0x93, 0x1e, 0x23); |
| 347 | union acpi_object *obj; |
| 348 | |
| 349 | obj = acpi_evaluate_dsm(ACPI_HANDLE(&dev->dev), &intel_dsm_guid, 3, 1, |
| 350 | NULL); |
| 351 | ACPI_FREE(obj); |
| 352 | } |
| 353 | |
| 354 | static void xhci_find_lpm_incapable_ports(struct usb_hcd *hcd, struct usb_device *hdev) |
| 355 | { |
| 356 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 357 | struct xhci_hub *rhub = &xhci->usb3_rhub; |
| 358 | int ret; |
| 359 | int i; |
| 360 | |
| 361 | /* This is not the usb3 roothub we are looking for */ |
| 362 | if (hcd != rhub->hcd) |
| 363 | return; |
| 364 | |
| 365 | if (hdev->maxchild > rhub->num_ports) { |
| 366 | dev_err(&hdev->dev, "USB3 roothub port number mismatch\n"); |
| 367 | return; |
| 368 | } |
| 369 | |
| 370 | for (i = 0; i < hdev->maxchild; i++) { |
| 371 | ret = usb_acpi_port_lpm_incapable(hdev, i); |
| 372 | |
| 373 | dev_dbg(&hdev->dev, "port-%d disable U1/U2 _DSM: %d\n", i + 1, ret); |
| 374 | |
| 375 | if (ret >= 0) { |
| 376 | rhub->ports[i]->lpm_incapable = ret; |
| 377 | continue; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | #else |
| 383 | static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev) { } |
| 384 | static void xhci_find_lpm_incapable_ports(struct usb_hcd *hcd, struct usb_device *hdev) { } |
| 385 | #endif /* CONFIG_ACPI */ |
| 386 | |
| 387 | /* called during probe() after chip reset completes */ |
| 388 | int xhci_pci_setup(struct usb_hcd *hcd) |
| 389 | { |
| 390 | struct xhci_hcd *xhci; |
| 391 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); |
| 392 | int retval; |
| 393 | |
| 394 | xhci = hcd_to_xhci(hcd); |
| 395 | if (!xhci->sbrn) |
| 396 | pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); |
| 397 | |
| 398 | /* imod_interval is the interrupt moderation value in nanoseconds. */ |
| 399 | xhci->imod_interval = 40000; |
| 400 | |
| 401 | retval = xhci_gen_setup(hcd, xhci_pci_quirks); |
| 402 | if (retval) |
| 403 | return retval; |
| 404 | |
| 405 | if (!usb_hcd_is_primary_hcd(hcd)) |
| 406 | return 0; |
| 407 | |
| 408 | if (xhci->quirks & XHCI_PME_STUCK_QUIRK) |
| 409 | xhci_pme_acpi_rtd3_enable(pdev); |
| 410 | |
| 411 | xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); |
| 412 | |
| 413 | /* Find any debug ports */ |
| 414 | return xhci_pci_reinit(xhci, pdev); |
| 415 | } |
| 416 | EXPORT_SYMBOL_GPL(xhci_pci_setup); |
| 417 | |
| 418 | static int xhci_pci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, |
| 419 | struct usb_tt *tt, gfp_t mem_flags) |
| 420 | { |
| 421 | /* Check if acpi claims some USB3 roothub ports are lpm incapable */ |
| 422 | if (!hdev->parent) |
| 423 | xhci_find_lpm_incapable_ports(hcd, hdev); |
| 424 | |
| 425 | return xhci_update_hub_device(hcd, hdev, tt, mem_flags); |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * We need to register our own PCI probe function (instead of the USB core's |
| 430 | * function) in order to create a second roothub under xHCI. |
| 431 | */ |
| 432 | int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) |
| 433 | { |
| 434 | int retval; |
| 435 | struct xhci_hcd *xhci; |
| 436 | struct hc_driver *driver; |
| 437 | struct usb_hcd *hcd; |
| 438 | |
| 439 | driver = (struct hc_driver *)id->driver_data; |
| 440 | |
| 441 | /* Prevent runtime suspending between USB-2 and USB-3 initialization */ |
| 442 | pm_runtime_get_noresume(&dev->dev); |
| 443 | |
| 444 | /* Register the USB 2.0 roothub. |
| 445 | * FIXME: USB core must know to register the USB 2.0 roothub first. |
| 446 | * This is sort of silly, because we could just set the HCD driver flags |
| 447 | * to say USB 2.0, but I'm not sure what the implications would be in |
| 448 | * the other parts of the HCD code. |
| 449 | */ |
| 450 | retval = usb_hcd_pci_probe(dev, id); |
| 451 | |
| 452 | if (retval) |
| 453 | goto put_runtime_pm; |
| 454 | |
| 455 | /* USB 2.0 roothub is stored in the PCI device now. */ |
| 456 | hcd = dev_get_drvdata(&dev->dev); |
| 457 | xhci = hcd_to_xhci(hcd); |
| 458 | xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev, |
| 459 | pci_name(dev), hcd); |
| 460 | if (!xhci->shared_hcd) { |
| 461 | retval = -ENOMEM; |
| 462 | goto dealloc_usb2_hcd; |
| 463 | } |
| 464 | |
| 465 | retval = xhci_ext_cap_init(xhci); |
| 466 | if (retval) |
| 467 | goto put_usb3_hcd; |
| 468 | |
| 469 | retval = usb_add_hcd(xhci->shared_hcd, dev->irq, |
| 470 | IRQF_SHARED); |
| 471 | if (retval) |
| 472 | goto put_usb3_hcd; |
| 473 | /* Roothub already marked as USB 3.0 speed */ |
| 474 | |
| 475 | if (!(xhci->quirks & XHCI_BROKEN_STREAMS) && |
| 476 | HCC_MAX_PSA(xhci->hcc_params) >= 4) |
| 477 | xhci->shared_hcd->can_do_streams = 1; |
| 478 | |
| 479 | /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */ |
| 480 | pm_runtime_put_noidle(&dev->dev); |
| 481 | |
| 482 | if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW) |
| 483 | pm_runtime_allow(&dev->dev); |
| 484 | |
| 485 | dma_set_max_seg_size(&dev->dev, UINT_MAX); |
| 486 | |
| 487 | return 0; |
| 488 | |
| 489 | put_usb3_hcd: |
| 490 | usb_put_hcd(xhci->shared_hcd); |
| 491 | dealloc_usb2_hcd: |
| 492 | usb_hcd_pci_remove(dev); |
| 493 | put_runtime_pm: |
| 494 | pm_runtime_put_noidle(&dev->dev); |
| 495 | return retval; |
| 496 | } |
| 497 | EXPORT_SYMBOL_GPL(xhci_pci_probe); |
| 498 | |
| 499 | void xhci_pci_remove(struct pci_dev *dev) |
| 500 | { |
| 501 | struct xhci_hcd *xhci; |
| 502 | |
| 503 | xhci = hcd_to_xhci(pci_get_drvdata(dev)); |
| 504 | xhci->xhc_state |= XHCI_STATE_REMOVING; |
| 505 | |
| 506 | if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW) |
| 507 | pm_runtime_forbid(&dev->dev); |
| 508 | |
| 509 | if (xhci->shared_hcd) { |
| 510 | usb_remove_hcd(xhci->shared_hcd); |
| 511 | usb_put_hcd(xhci->shared_hcd); |
| 512 | xhci->shared_hcd = NULL; |
| 513 | } |
| 514 | |
| 515 | /* Workaround for spurious wakeups at shutdown with HSW */ |
| 516 | if (xhci->quirks & XHCI_SPURIOUS_WAKEUP) |
| 517 | pci_set_power_state(dev, PCI_D3hot); |
| 518 | |
| 519 | usb_hcd_pci_remove(dev); |
| 520 | } |
| 521 | EXPORT_SYMBOL_GPL(xhci_pci_remove); |
| 522 | |
| 523 | #ifdef CONFIG_PM |
| 524 | /* |
| 525 | * In some Intel xHCI controllers, in order to get D3 working, |
| 526 | * through a vendor specific SSIC CONFIG register at offset 0x883c, |
| 527 | * SSIC PORT need to be marked as "unused" before putting xHCI |
| 528 | * into D3. After D3 exit, the SSIC port need to be marked as "used". |
| 529 | * Without this change, xHCI might not enter D3 state. |
| 530 | */ |
| 531 | static void xhci_ssic_port_unused_quirk(struct usb_hcd *hcd, bool suspend) |
| 532 | { |
| 533 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 534 | u32 val; |
| 535 | void __iomem *reg; |
| 536 | int i; |
| 537 | |
| 538 | for (i = 0; i < SSIC_PORT_NUM; i++) { |
| 539 | reg = (void __iomem *) xhci->cap_regs + |
| 540 | SSIC_PORT_CFG2 + |
| 541 | i * SSIC_PORT_CFG2_OFFSET; |
| 542 | |
| 543 | /* Notify SSIC that SSIC profile programming is not done. */ |
| 544 | val = readl(reg) & ~PROG_DONE; |
| 545 | writel(val, reg); |
| 546 | |
| 547 | /* Mark SSIC port as unused(suspend) or used(resume) */ |
| 548 | val = readl(reg); |
| 549 | if (suspend) |
| 550 | val |= SSIC_PORT_UNUSED; |
| 551 | else |
| 552 | val &= ~SSIC_PORT_UNUSED; |
| 553 | writel(val, reg); |
| 554 | |
| 555 | /* Notify SSIC that SSIC profile programming is done */ |
| 556 | val = readl(reg) | PROG_DONE; |
| 557 | writel(val, reg); |
| 558 | readl(reg); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * Make sure PME works on some Intel xHCI controllers by writing 1 to clear |
| 564 | * the Internal PME flag bit in vendor specific PMCTRL register at offset 0x80a4 |
| 565 | */ |
| 566 | static void xhci_pme_quirk(struct usb_hcd *hcd) |
| 567 | { |
| 568 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 569 | void __iomem *reg; |
| 570 | u32 val; |
| 571 | |
| 572 | reg = (void __iomem *) xhci->cap_regs + 0x80a4; |
| 573 | val = readl(reg); |
| 574 | writel(val | BIT(28), reg); |
| 575 | readl(reg); |
| 576 | } |
| 577 | |
| 578 | static void xhci_sparse_control_quirk(struct usb_hcd *hcd) |
| 579 | { |
| 580 | u32 reg; |
| 581 | |
| 582 | reg = readl(hcd->regs + SPARSE_CNTL_ENABLE); |
| 583 | reg &= ~BIT(SPARSE_DISABLE_BIT); |
| 584 | writel(reg, hcd->regs + SPARSE_CNTL_ENABLE); |
| 585 | } |
| 586 | |
| 587 | int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) |
| 588 | { |
| 589 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 590 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); |
| 591 | int ret; |
| 592 | |
| 593 | /* |
| 594 | * Systems with the TI redriver that loses port status change events |
| 595 | * need to have the registers polled during D3, so avoid D3cold. |
| 596 | */ |
| 597 | if (xhci->quirks & XHCI_COMP_MODE_QUIRK) |
| 598 | pci_d3cold_disable(pdev); |
| 599 | |
| 600 | if (xhci->quirks & XHCI_PME_STUCK_QUIRK) |
| 601 | xhci_pme_quirk(hcd); |
| 602 | |
| 603 | if (xhci->quirks & XHCI_SSIC_PORT_UNUSED) |
| 604 | xhci_ssic_port_unused_quirk(hcd, true); |
| 605 | |
| 606 | if (xhci->quirks & XHCI_DISABLE_SPARSE) |
| 607 | xhci_sparse_control_quirk(hcd); |
| 608 | |
| 609 | ret = xhci_suspend(xhci, do_wakeup); |
| 610 | if (ret && (xhci->quirks & XHCI_SSIC_PORT_UNUSED)) |
| 611 | xhci_ssic_port_unused_quirk(hcd, false); |
| 612 | |
| 613 | return ret; |
| 614 | } |
| 615 | EXPORT_SYMBOL_GPL(xhci_pci_suspend); |
| 616 | |
| 617 | int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) |
| 618 | { |
| 619 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 620 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); |
| 621 | int retval = 0; |
| 622 | |
| 623 | /* The BIOS on systems with the Intel Panther Point chipset may or may |
| 624 | * not support xHCI natively. That means that during system resume, it |
| 625 | * may switch the ports back to EHCI so that users can use their |
| 626 | * keyboard to select a kernel from GRUB after resume from hibernate. |
| 627 | * |
| 628 | * The BIOS is supposed to remember whether the OS had xHCI ports |
| 629 | * enabled before resume, and switch the ports back to xHCI when the |
| 630 | * BIOS/OS semaphore is written, but we all know we can't trust BIOS |
| 631 | * writers. |
| 632 | * |
| 633 | * Unconditionally switch the ports back to xHCI after a system resume. |
| 634 | * It should not matter whether the EHCI or xHCI controller is |
| 635 | * resumed first. It's enough to do the switchover in xHCI because |
| 636 | * USB core won't notice anything as the hub driver doesn't start |
| 637 | * running again until after all the devices (including both EHCI and |
| 638 | * xHCI host controllers) have been resumed. |
| 639 | */ |
| 640 | |
| 641 | if (pdev->vendor == PCI_VENDOR_ID_INTEL) |
| 642 | usb_enable_intel_xhci_ports(pdev); |
| 643 | |
| 644 | if (xhci->quirks & XHCI_SSIC_PORT_UNUSED) |
| 645 | xhci_ssic_port_unused_quirk(hcd, false); |
| 646 | |
| 647 | if (xhci->quirks & XHCI_PME_STUCK_QUIRK) |
| 648 | xhci_pme_quirk(hcd); |
| 649 | |
| 650 | retval = xhci_resume(xhci, hibernated); |
| 651 | return retval; |
| 652 | } |
| 653 | |
| 654 | static void xhci_pci_shutdown(struct usb_hcd *hcd) |
| 655 | { |
| 656 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 657 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); |
| 658 | |
| 659 | xhci_shutdown(hcd); |
| 660 | |
| 661 | /* Yet another workaround for spurious wakeups at shutdown with HSW */ |
| 662 | if (xhci->quirks & XHCI_SPURIOUS_WAKEUP) |
| 663 | pci_set_power_state(pdev, PCI_D3hot); |
| 664 | } |
| 665 | EXPORT_SYMBOL_GPL(xhci_pci_resume); |
| 666 | #endif /* CONFIG_PM */ |
| 667 | |
| 668 | /*-------------------------------------------------------------------------*/ |
| 669 | |
| 670 | /* PCI driver selection metadata; PCI hotplugging uses this */ |
| 671 | static const struct pci_device_id pci_ids[] = { { |
| 672 | /* handle any USB 3.0 xHCI controller */ |
| 673 | PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0), |
| 674 | .driver_data = (unsigned long) &xhci_pci_hc_driver, |
| 675 | }, |
| 676 | { /* end: all zeroes */ } |
| 677 | }; |
| 678 | MODULE_DEVICE_TABLE(pci, pci_ids); |
| 679 | |
| 680 | /* pci driver glue; this is a "new style" PCI driver module */ |
| 681 | static struct pci_driver xhci_pci_driver = { |
| 682 | .name = (char *) hcd_name, |
| 683 | .id_table = pci_ids, |
| 684 | |
| 685 | .probe = xhci_pci_probe, |
| 686 | .remove = xhci_pci_remove, |
| 687 | /* suspend and resume implemented later */ |
| 688 | |
| 689 | .shutdown = usb_hcd_pci_shutdown, |
| 690 | #ifdef CONFIG_PM |
| 691 | .driver = { |
| 692 | .pm = &usb_hcd_pci_pm_ops |
| 693 | }, |
| 694 | #endif |
| 695 | }; |
| 696 | |
| 697 | static int __init xhci_pci_init(void) |
| 698 | { |
| 699 | xhci_init_driver(&xhci_pci_hc_driver, &xhci_pci_overrides); |
| 700 | #ifdef CONFIG_PM |
| 701 | xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend; |
| 702 | xhci_pci_hc_driver.pci_resume = xhci_pci_resume; |
| 703 | xhci_pci_hc_driver.shutdown = xhci_pci_shutdown; |
| 704 | #endif |
| 705 | return pci_register_driver(&xhci_pci_driver); |
| 706 | } |
| 707 | module_init(xhci_pci_init); |
| 708 | |
| 709 | static void __exit xhci_pci_exit(void) |
| 710 | { |
| 711 | pci_unregister_driver(&xhci_pci_driver); |
| 712 | } |
| 713 | module_exit(xhci_pci_exit); |
| 714 | |
| 715 | MODULE_DESCRIPTION("xHCI PCI Host Controller Driver"); |
| 716 | MODULE_LICENSE("GPL"); |