| .. | .. |
|---|
| 12 | 12 | #include <linux/slab.h> |
|---|
| 13 | 13 | #include <linux/module.h> |
|---|
| 14 | 14 | #include <linux/acpi.h> |
|---|
| 15 | +#include <linux/reset.h> |
|---|
| 15 | 16 | |
|---|
| 16 | 17 | #include "xhci.h" |
|---|
| 17 | 18 | #include "xhci-trace.h" |
|---|
| 19 | +#include "xhci-pci.h" |
|---|
| 18 | 20 | |
|---|
| 19 | 21 | #define SSIC_PORT_NUM 2 |
|---|
| 20 | 22 | #define SSIC_PORT_CFG2 0x880c |
|---|
| .. | .. |
|---|
| 44 | 46 | #define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8 |
|---|
| 45 | 47 | #define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8 |
|---|
| 46 | 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 |
|---|
| 47 | 58 | #define PCI_DEVICE_ID_INTEL_CML_XHCI 0xa3af |
|---|
| 59 | +#define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI 0x9a13 |
|---|
| 60 | +#define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI 0x1138 |
|---|
| 61 | +#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI 0x51ed |
|---|
| 62 | +#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI 0x54ed |
|---|
| 48 | 63 | |
|---|
| 49 | 64 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9 |
|---|
| 50 | 65 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba |
|---|
| 51 | 66 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb |
|---|
| 52 | 67 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc |
|---|
| 68 | + |
|---|
| 53 | 69 | #define PCI_DEVICE_ID_ASMEDIA_1042_XHCI 0x1042 |
|---|
| 54 | 70 | #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142 |
|---|
| 55 | 71 | #define PCI_DEVICE_ID_ASMEDIA_1142_XHCI 0x1242 |
|---|
| .. | .. |
|---|
| 85 | 101 | |
|---|
| 86 | 102 | static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) |
|---|
| 87 | 103 | { |
|---|
| 88 | | - struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 104 | + struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 105 | + struct xhci_driver_data *driver_data; |
|---|
| 106 | + const struct pci_device_id *id; |
|---|
| 107 | + |
|---|
| 108 | + id = pci_match_id(pdev->driver->id_table, pdev); |
|---|
| 109 | + |
|---|
| 110 | + if (id && id->driver_data) { |
|---|
| 111 | + driver_data = (struct xhci_driver_data *)id->driver_data; |
|---|
| 112 | + xhci->quirks |= driver_data->quirks; |
|---|
| 113 | + } |
|---|
| 89 | 114 | |
|---|
| 90 | 115 | /* Look for vendor-specific quirks */ |
|---|
| 91 | 116 | if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && |
|---|
| .. | .. |
|---|
| 135 | 160 | xhci->quirks |= XHCI_AMD_0x96_HOST; |
|---|
| 136 | 161 | |
|---|
| 137 | 162 | /* AMD PLL quirk */ |
|---|
| 138 | | - if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info()) |
|---|
| 163 | + if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_quirk_pll_check()) |
|---|
| 139 | 164 | xhci->quirks |= XHCI_AMD_PLL_FIX; |
|---|
| 140 | 165 | |
|---|
| 141 | 166 | if (pdev->vendor == PCI_VENDOR_ID_AMD && |
|---|
| .. | .. |
|---|
| 217 | 242 | pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI)) |
|---|
| 218 | 243 | xhci->quirks |= XHCI_MISSING_CAS; |
|---|
| 219 | 244 | |
|---|
| 245 | + if (pdev->vendor == PCI_VENDOR_ID_INTEL && |
|---|
| 246 | + (pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI || |
|---|
| 247 | + pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI)) |
|---|
| 248 | + xhci->quirks |= XHCI_RESET_TO_DEFAULT; |
|---|
| 249 | + |
|---|
| 250 | + if (pdev->vendor == PCI_VENDOR_ID_INTEL && |
|---|
| 251 | + (pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI || |
|---|
| 252 | + pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI || |
|---|
| 253 | + pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI || |
|---|
| 254 | + pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI || |
|---|
| 255 | + pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI || |
|---|
| 256 | + pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI || |
|---|
| 257 | + pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI || |
|---|
| 258 | + pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI || |
|---|
| 259 | + pdev->device == PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI || |
|---|
| 260 | + pdev->device == PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI || |
|---|
| 261 | + pdev->device == PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI)) |
|---|
| 262 | + xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; |
|---|
| 263 | + |
|---|
| 220 | 264 | if (pdev->vendor == PCI_VENDOR_ID_ETRON && |
|---|
| 221 | 265 | pdev->device == PCI_DEVICE_ID_EJ168) { |
|---|
| 222 | 266 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
|---|
| .. | .. |
|---|
| 241 | 285 | pdev->device == 0x3432) |
|---|
| 242 | 286 | xhci->quirks |= XHCI_BROKEN_STREAMS; |
|---|
| 243 | 287 | |
|---|
| 288 | + if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483) { |
|---|
| 289 | + xhci->quirks |= XHCI_LPM_SUPPORT; |
|---|
| 290 | + xhci->quirks |= XHCI_EP_CTX_BROKEN_DCS; |
|---|
| 291 | + } |
|---|
| 292 | + |
|---|
| 244 | 293 | if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && |
|---|
| 245 | | - pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI) |
|---|
| 294 | + pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI) { |
|---|
| 295 | + /* |
|---|
| 296 | + * try to tame the ASMedia 1042 controller which reports 0.96 |
|---|
| 297 | + * but appears to behave more like 1.0 |
|---|
| 298 | + */ |
|---|
| 299 | + xhci->quirks |= XHCI_SPURIOUS_SUCCESS; |
|---|
| 246 | 300 | xhci->quirks |= XHCI_BROKEN_STREAMS; |
|---|
| 301 | + } |
|---|
| 247 | 302 | if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && |
|---|
| 248 | 303 | pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI) { |
|---|
| 249 | 304 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
|---|
| .. | .. |
|---|
| 266 | 321 | pdev->vendor == PCI_VENDOR_ID_CAVIUM) && |
|---|
| 267 | 322 | pdev->device == 0x9026) |
|---|
| 268 | 323 | xhci->quirks |= XHCI_RESET_PLL_ON_DISCONNECT; |
|---|
| 324 | + |
|---|
| 325 | + if (pdev->vendor == PCI_VENDOR_ID_AMD && |
|---|
| 326 | + (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2 || |
|---|
| 327 | + pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4)) |
|---|
| 328 | + xhci->quirks |= XHCI_NO_SOFT_RETRY; |
|---|
| 329 | + |
|---|
| 330 | + if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN) { |
|---|
| 331 | + xhci->quirks |= XHCI_ZHAOXIN_HOST; |
|---|
| 332 | + |
|---|
| 333 | + if (pdev->device == 0x9202) { |
|---|
| 334 | + xhci->quirks |= XHCI_RESET_ON_RESUME; |
|---|
| 335 | + xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH; |
|---|
| 336 | + } |
|---|
| 337 | + |
|---|
| 338 | + if (pdev->device == 0x9203) |
|---|
| 339 | + xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH; |
|---|
| 340 | + } |
|---|
| 341 | + |
|---|
| 342 | + /* xHC spec requires PCI devices to support D3hot and D3cold */ |
|---|
| 343 | + if (xhci->hci_version >= 0x120) |
|---|
| 344 | + xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; |
|---|
| 269 | 345 | |
|---|
| 270 | 346 | if (xhci->quirks & XHCI_RESET_ON_RESUME) |
|---|
| 271 | 347 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, |
|---|
| .. | .. |
|---|
| 326 | 402 | { |
|---|
| 327 | 403 | int retval; |
|---|
| 328 | 404 | struct xhci_hcd *xhci; |
|---|
| 329 | | - struct hc_driver *driver; |
|---|
| 330 | 405 | struct usb_hcd *hcd; |
|---|
| 406 | + struct xhci_driver_data *driver_data; |
|---|
| 407 | + struct reset_control *reset; |
|---|
| 331 | 408 | |
|---|
| 332 | | - driver = (struct hc_driver *)id->driver_data; |
|---|
| 409 | + driver_data = (struct xhci_driver_data *)id->driver_data; |
|---|
| 410 | + if (driver_data && driver_data->quirks & XHCI_RENESAS_FW_QUIRK) { |
|---|
| 411 | + retval = renesas_xhci_check_request_fw(dev, id); |
|---|
| 412 | + if (retval) |
|---|
| 413 | + return retval; |
|---|
| 414 | + } |
|---|
| 415 | + |
|---|
| 416 | + reset = devm_reset_control_get_optional_exclusive(&dev->dev, NULL); |
|---|
| 417 | + if (IS_ERR(reset)) |
|---|
| 418 | + return PTR_ERR(reset); |
|---|
| 419 | + reset_control_reset(reset); |
|---|
| 333 | 420 | |
|---|
| 334 | 421 | /* Prevent runtime suspending between USB-2 and USB-3 initialization */ |
|---|
| 335 | 422 | pm_runtime_get_noresume(&dev->dev); |
|---|
| .. | .. |
|---|
| 340 | 427 | * to say USB 2.0, but I'm not sure what the implications would be in |
|---|
| 341 | 428 | * the other parts of the HCD code. |
|---|
| 342 | 429 | */ |
|---|
| 343 | | - retval = usb_hcd_pci_probe(dev, id); |
|---|
| 430 | + retval = usb_hcd_pci_probe(dev, id, &xhci_pci_hc_driver); |
|---|
| 344 | 431 | |
|---|
| 345 | 432 | if (retval) |
|---|
| 346 | 433 | goto put_runtime_pm; |
|---|
| .. | .. |
|---|
| 348 | 435 | /* USB 2.0 roothub is stored in the PCI device now. */ |
|---|
| 349 | 436 | hcd = dev_get_drvdata(&dev->dev); |
|---|
| 350 | 437 | xhci = hcd_to_xhci(hcd); |
|---|
| 351 | | - xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev, |
|---|
| 352 | | - pci_name(dev), hcd); |
|---|
| 438 | + xhci->reset = reset; |
|---|
| 439 | + xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev, |
|---|
| 440 | + pci_name(dev), hcd); |
|---|
| 353 | 441 | if (!xhci->shared_hcd) { |
|---|
| 354 | 442 | retval = -ENOMEM; |
|---|
| 355 | 443 | goto dealloc_usb2_hcd; |
|---|
| .. | .. |
|---|
| 372 | 460 | /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */ |
|---|
| 373 | 461 | pm_runtime_put_noidle(&dev->dev); |
|---|
| 374 | 462 | |
|---|
| 463 | + if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW) |
|---|
| 464 | + pm_runtime_allow(&dev->dev); |
|---|
| 465 | + |
|---|
| 466 | + dma_set_max_seg_size(&dev->dev, UINT_MAX); |
|---|
| 467 | + |
|---|
| 375 | 468 | return 0; |
|---|
| 376 | 469 | |
|---|
| 377 | 470 | put_usb3_hcd: |
|---|
| .. | .. |
|---|
| 388 | 481 | struct xhci_hcd *xhci; |
|---|
| 389 | 482 | |
|---|
| 390 | 483 | xhci = hcd_to_xhci(pci_get_drvdata(dev)); |
|---|
| 484 | + if (xhci->quirks & XHCI_RENESAS_FW_QUIRK) |
|---|
| 485 | + renesas_xhci_pci_exit(dev); |
|---|
| 486 | + |
|---|
| 391 | 487 | xhci->xhc_state |= XHCI_STATE_REMOVING; |
|---|
| 488 | + |
|---|
| 489 | + if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW) |
|---|
| 490 | + pm_runtime_forbid(&dev->dev); |
|---|
| 491 | + |
|---|
| 392 | 492 | if (xhci->shared_hcd) { |
|---|
| 393 | 493 | usb_remove_hcd(xhci->shared_hcd); |
|---|
| 394 | 494 | usb_put_hcd(xhci->shared_hcd); |
|---|
| .. | .. |
|---|
| 501 | 601 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); |
|---|
| 502 | 602 | int retval = 0; |
|---|
| 503 | 603 | |
|---|
| 604 | + reset_control_reset(xhci->reset); |
|---|
| 605 | + |
|---|
| 504 | 606 | /* The BIOS on systems with the Intel Panther Point chipset may or may |
|---|
| 505 | 607 | * not support xHCI natively. That means that during system resume, it |
|---|
| 506 | 608 | * may switch the ports back to EHCI so that users can use their |
|---|
| .. | .. |
|---|
| 547 | 649 | |
|---|
| 548 | 650 | /*-------------------------------------------------------------------------*/ |
|---|
| 549 | 651 | |
|---|
| 652 | +static const struct xhci_driver_data reneses_data = { |
|---|
| 653 | + .quirks = XHCI_RENESAS_FW_QUIRK, |
|---|
| 654 | + .firmware = "renesas_usb_fw.mem", |
|---|
| 655 | +}; |
|---|
| 656 | + |
|---|
| 550 | 657 | /* PCI driver selection metadata; PCI hotplugging uses this */ |
|---|
| 551 | | -static const struct pci_device_id pci_ids[] = { { |
|---|
| 658 | +static const struct pci_device_id pci_ids[] = { |
|---|
| 659 | + { PCI_DEVICE(0x1912, 0x0014), |
|---|
| 660 | + .driver_data = (unsigned long)&reneses_data, |
|---|
| 661 | + }, |
|---|
| 662 | + { PCI_DEVICE(0x1912, 0x0015), |
|---|
| 663 | + .driver_data = (unsigned long)&reneses_data, |
|---|
| 664 | + }, |
|---|
| 552 | 665 | /* handle any USB 3.0 xHCI controller */ |
|---|
| 553 | | - PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0), |
|---|
| 554 | | - .driver_data = (unsigned long) &xhci_pci_hc_driver, |
|---|
| 666 | + { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0), |
|---|
| 555 | 667 | }, |
|---|
| 556 | 668 | { /* end: all zeroes */ } |
|---|
| 557 | 669 | }; |
|---|
| 558 | 670 | MODULE_DEVICE_TABLE(pci, pci_ids); |
|---|
| 559 | 671 | |
|---|
| 672 | +/* |
|---|
| 673 | + * Without CONFIG_USB_XHCI_PCI_RENESAS renesas_xhci_check_request_fw() won't |
|---|
| 674 | + * load firmware, so don't encumber the xhci-pci driver with it. |
|---|
| 675 | + */ |
|---|
| 676 | +#if IS_ENABLED(CONFIG_USB_XHCI_PCI_RENESAS) |
|---|
| 677 | +MODULE_FIRMWARE("renesas_usb_fw.mem"); |
|---|
| 678 | +#endif |
|---|
| 679 | + |
|---|
| 560 | 680 | /* pci driver glue; this is a "new style" PCI driver module */ |
|---|
| 561 | 681 | static struct pci_driver xhci_pci_driver = { |
|---|
| 562 | | - .name = (char *) hcd_name, |
|---|
| 682 | + .name = hcd_name, |
|---|
| 563 | 683 | .id_table = pci_ids, |
|---|
| 564 | 684 | |
|---|
| 565 | 685 | .probe = xhci_pci_probe, |
|---|