hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/drivers/usb/host/xhci-pci.c
....@@ -12,9 +12,11 @@
1212 #include <linux/slab.h>
1313 #include <linux/module.h>
1414 #include <linux/acpi.h>
15
+#include <linux/reset.h>
1516
1617 #include "xhci.h"
1718 #include "xhci-trace.h"
19
+#include "xhci-pci.h"
1820
1921 #define SSIC_PORT_NUM 2
2022 #define SSIC_PORT_CFG2 0x880c
....@@ -44,12 +46,26 @@
4446 #define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8
4547 #define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8
4648 #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
4758 #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
4863
4964 #define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9
5065 #define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba
5166 #define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb
5267 #define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc
68
+
5369 #define PCI_DEVICE_ID_ASMEDIA_1042_XHCI 0x1042
5470 #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142
5571 #define PCI_DEVICE_ID_ASMEDIA_1142_XHCI 0x1242
....@@ -85,7 +101,16 @@
85101
86102 static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
87103 {
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
+ }
89114
90115 /* Look for vendor-specific quirks */
91116 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
....@@ -135,7 +160,7 @@
135160 xhci->quirks |= XHCI_AMD_0x96_HOST;
136161
137162 /* 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())
139164 xhci->quirks |= XHCI_AMD_PLL_FIX;
140165
141166 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
....@@ -217,6 +242,25 @@
217242 pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI))
218243 xhci->quirks |= XHCI_MISSING_CAS;
219244
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
+
220264 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
221265 pdev->device == PCI_DEVICE_ID_EJ168) {
222266 xhci->quirks |= XHCI_RESET_ON_RESUME;
....@@ -241,9 +285,20 @@
241285 pdev->device == 0x3432)
242286 xhci->quirks |= XHCI_BROKEN_STREAMS;
243287
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
+
244293 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;
246300 xhci->quirks |= XHCI_BROKEN_STREAMS;
301
+ }
247302 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
248303 pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI) {
249304 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
....@@ -266,6 +321,15 @@
266321 pdev->vendor == PCI_VENDOR_ID_CAVIUM) &&
267322 pdev->device == 0x9026)
268323 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
+ /* xHC spec requires PCI devices to support D3hot and D3cold */
331
+ if (xhci->hci_version >= 0x120)
332
+ xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
269333
270334 if (xhci->quirks & XHCI_RESET_ON_RESUME)
271335 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
....@@ -326,10 +390,21 @@
326390 {
327391 int retval;
328392 struct xhci_hcd *xhci;
329
- struct hc_driver *driver;
330393 struct usb_hcd *hcd;
394
+ struct xhci_driver_data *driver_data;
395
+ struct reset_control *reset;
331396
332
- driver = (struct hc_driver *)id->driver_data;
397
+ driver_data = (struct xhci_driver_data *)id->driver_data;
398
+ if (driver_data && driver_data->quirks & XHCI_RENESAS_FW_QUIRK) {
399
+ retval = renesas_xhci_check_request_fw(dev, id);
400
+ if (retval)
401
+ return retval;
402
+ }
403
+
404
+ reset = devm_reset_control_get_optional_exclusive(&dev->dev, NULL);
405
+ if (IS_ERR(reset))
406
+ return PTR_ERR(reset);
407
+ reset_control_reset(reset);
333408
334409 /* Prevent runtime suspending between USB-2 and USB-3 initialization */
335410 pm_runtime_get_noresume(&dev->dev);
....@@ -340,7 +415,7 @@
340415 * to say USB 2.0, but I'm not sure what the implications would be in
341416 * the other parts of the HCD code.
342417 */
343
- retval = usb_hcd_pci_probe(dev, id);
418
+ retval = usb_hcd_pci_probe(dev, id, &xhci_pci_hc_driver);
344419
345420 if (retval)
346421 goto put_runtime_pm;
....@@ -348,8 +423,9 @@
348423 /* USB 2.0 roothub is stored in the PCI device now. */
349424 hcd = dev_get_drvdata(&dev->dev);
350425 xhci = hcd_to_xhci(hcd);
351
- xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev,
352
- pci_name(dev), hcd);
426
+ xhci->reset = reset;
427
+ xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev,
428
+ pci_name(dev), hcd);
353429 if (!xhci->shared_hcd) {
354430 retval = -ENOMEM;
355431 goto dealloc_usb2_hcd;
....@@ -372,6 +448,9 @@
372448 /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */
373449 pm_runtime_put_noidle(&dev->dev);
374450
451
+ if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
452
+ pm_runtime_allow(&dev->dev);
453
+
375454 return 0;
376455
377456 put_usb3_hcd:
....@@ -388,7 +467,14 @@
388467 struct xhci_hcd *xhci;
389468
390469 xhci = hcd_to_xhci(pci_get_drvdata(dev));
470
+ if (xhci->quirks & XHCI_RENESAS_FW_QUIRK)
471
+ renesas_xhci_pci_exit(dev);
472
+
391473 xhci->xhc_state |= XHCI_STATE_REMOVING;
474
+
475
+ if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
476
+ pm_runtime_forbid(&dev->dev);
477
+
392478 if (xhci->shared_hcd) {
393479 usb_remove_hcd(xhci->shared_hcd);
394480 usb_put_hcd(xhci->shared_hcd);
....@@ -501,6 +587,8 @@
501587 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
502588 int retval = 0;
503589
590
+ reset_control_reset(xhci->reset);
591
+
504592 /* The BIOS on systems with the Intel Panther Point chipset may or may
505593 * not support xHCI natively. That means that during system resume, it
506594 * may switch the ports back to EHCI so that users can use their
....@@ -547,19 +635,37 @@
547635
548636 /*-------------------------------------------------------------------------*/
549637
638
+static const struct xhci_driver_data reneses_data = {
639
+ .quirks = XHCI_RENESAS_FW_QUIRK,
640
+ .firmware = "renesas_usb_fw.mem",
641
+};
642
+
550643 /* PCI driver selection metadata; PCI hotplugging uses this */
551
-static const struct pci_device_id pci_ids[] = { {
644
+static const struct pci_device_id pci_ids[] = {
645
+ { PCI_DEVICE(0x1912, 0x0014),
646
+ .driver_data = (unsigned long)&reneses_data,
647
+ },
648
+ { PCI_DEVICE(0x1912, 0x0015),
649
+ .driver_data = (unsigned long)&reneses_data,
650
+ },
552651 /* 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,
652
+ { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0),
555653 },
556654 { /* end: all zeroes */ }
557655 };
558656 MODULE_DEVICE_TABLE(pci, pci_ids);
559657
658
+/*
659
+ * Without CONFIG_USB_XHCI_PCI_RENESAS renesas_xhci_check_request_fw() won't
660
+ * load firmware, so don't encumber the xhci-pci driver with it.
661
+ */
662
+#if IS_ENABLED(CONFIG_USB_XHCI_PCI_RENESAS)
663
+MODULE_FIRMWARE("renesas_usb_fw.mem");
664
+#endif
665
+
560666 /* pci driver glue; this is a "new style" PCI driver module */
561667 static struct pci_driver xhci_pci_driver = {
562
- .name = (char *) hcd_name,
668
+ .name = hcd_name,
563669 .id_table = pci_ids,
564670
565671 .probe = xhci_pci_probe,