hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/usb/host/pci-quirks.c
....@@ -16,6 +16,9 @@
1616 #include <linux/export.h>
1717 #include <linux/acpi.h>
1818 #include <linux/dmi.h>
19
+#include <linux/of.h>
20
+#include <linux/iopoll.h>
21
+
1922 #include "pci-quirks.h"
2023 #include "xhci-ext-caps.h"
2124
....@@ -132,7 +135,7 @@
132135 struct amd_chipset_type sb_type;
133136 int isoc_reqs;
134137 int probe_count;
135
- int probe_result;
138
+ bool need_pll_quirk;
136139 } amd_chipset;
137140
138141 static DEFINE_SPINLOCK(amd_lock);
....@@ -201,11 +204,11 @@
201204 }
202205 EXPORT_SYMBOL_GPL(sb800_prefetch);
203206
204
-int usb_amd_find_chipset_info(void)
207
+static void usb_amd_find_chipset_info(void)
205208 {
206209 unsigned long flags;
207210 struct amd_chipset_info info;
208
- int need_pll_quirk = 0;
211
+ info.need_pll_quirk = false;
209212
210213 spin_lock_irqsave(&amd_lock, flags);
211214
....@@ -213,7 +216,7 @@
213216 if (amd_chipset.probe_count > 0) {
214217 amd_chipset.probe_count++;
215218 spin_unlock_irqrestore(&amd_lock, flags);
216
- return amd_chipset.probe_result;
219
+ return;
217220 }
218221 memset(&info, 0, sizeof(info));
219222 spin_unlock_irqrestore(&amd_lock, flags);
....@@ -224,19 +227,19 @@
224227
225228 switch (info.sb_type.gen) {
226229 case AMD_CHIPSET_SB700:
227
- need_pll_quirk = info.sb_type.rev <= 0x3B;
230
+ info.need_pll_quirk = info.sb_type.rev <= 0x3B;
228231 break;
229232 case AMD_CHIPSET_SB800:
230233 case AMD_CHIPSET_HUDSON2:
231234 case AMD_CHIPSET_BOLTON:
232
- need_pll_quirk = 1;
235
+ info.need_pll_quirk = true;
233236 break;
234237 default:
235
- need_pll_quirk = 0;
238
+ info.need_pll_quirk = false;
236239 break;
237240 }
238241
239
- if (!need_pll_quirk) {
242
+ if (!info.need_pll_quirk) {
240243 if (info.smbus_dev) {
241244 pci_dev_put(info.smbus_dev);
242245 info.smbus_dev = NULL;
....@@ -259,7 +262,6 @@
259262 }
260263 }
261264
262
- need_pll_quirk = info.probe_result = 1;
263265 printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n");
264266
265267 commit:
....@@ -270,7 +272,6 @@
270272
271273 /* Mark that we where here */
272274 amd_chipset.probe_count++;
273
- need_pll_quirk = amd_chipset.probe_result;
274275
275276 spin_unlock_irqrestore(&amd_lock, flags);
276277
....@@ -283,10 +284,7 @@
283284 amd_chipset = info;
284285 spin_unlock_irqrestore(&amd_lock, flags);
285286 }
286
-
287
- return need_pll_quirk;
288287 }
289
-EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info);
290288
291289 int usb_hcd_amd_remote_wakeup_quirk(struct pci_dev *pdev)
292290 {
....@@ -321,6 +319,13 @@
321319 return amd_chipset.sb_type.gen == AMD_CHIPSET_SB800;
322320 }
323321 EXPORT_SYMBOL_GPL(usb_amd_prefetch_quirk);
322
+
323
+bool usb_amd_quirk_pll_check(void)
324
+{
325
+ usb_amd_find_chipset_info();
326
+ return amd_chipset.need_pll_quirk;
327
+}
328
+EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_check);
324329
325330 /*
326331 * The hardware normally enables the A-link power management feature, which
....@@ -527,7 +532,7 @@
527532 amd_chipset.nb_type = 0;
528533 memset(&amd_chipset.sb_type, 0, sizeof(amd_chipset.sb_type));
529534 amd_chipset.isoc_reqs = 0;
530
- amd_chipset.probe_result = 0;
535
+ amd_chipset.need_pll_quirk = false;
531536
532537 spin_unlock_irqrestore(&amd_lock, flags);
533538
....@@ -726,7 +731,7 @@
726731 if (!pio_enabled(pdev))
727732 return;
728733
729
- for (i = 0; i < PCI_ROM_RESOURCE; i++)
734
+ for (i = 0; i < PCI_STD_NUM_BARS; i++)
730735 if ((pci_resource_flags(pdev, i) & IORESOURCE_IO)) {
731736 base = pci_resource_start(pdev, i);
732737 break;
....@@ -790,15 +795,9 @@
790795 /* disable interrupts */
791796 writel((u32) ~0, base + OHCI_INTRDISABLE);
792797
793
- /* Reset the USB bus, if the controller isn't already in RESET */
794
- if (control & OHCI_HCFS) {
795
- /* Go into RESET, preserving RWC (and possibly IR) */
796
- writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL);
797
- readl(base + OHCI_CONTROL);
798
-
799
- /* drive bus reset for at least 50 ms (7.1.7.5) */
800
- msleep(50);
801
- }
798
+ /* Go into the USB_RESET state, preserving RWC (and possibly IR) */
799
+ writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL);
800
+ readl(base + OHCI_CONTROL);
802801
803802 /* software reset of the controller, preserving HcFmInterval */
804803 if (!no_fminterval)
....@@ -958,7 +957,8 @@
958957 ehci_bios_handoff(pdev, op_reg_base, cap, offset);
959958 break;
960959 case 0: /* Illegal reserved cap, set cap=0 so we exit */
961
- cap = 0; /* fall through */
960
+ cap = 0;
961
+ fallthrough;
962962 default:
963963 dev_warn(&pdev->dev,
964964 "EHCI: unrecognized capability %02x\n",
....@@ -1013,15 +1013,9 @@
10131013 {
10141014 u32 result;
10151015
1016
- do {
1017
- result = readl(ptr);
1018
- result &= mask;
1019
- if (result == done)
1020
- return 0;
1021
- udelay(delay_usec);
1022
- wait_usec -= delay_usec;
1023
- } while (wait_usec > 0);
1024
- return -ETIMEDOUT;
1016
+ return readl_poll_timeout_atomic(ptr, result,
1017
+ ((result & mask) == done),
1018
+ delay_usec, wait_usec);
10251019 }
10261020
10271021 /*
....@@ -1134,7 +1128,7 @@
11341128 }
11351129 EXPORT_SYMBOL_GPL(usb_disable_xhci_ports);
11361130
1137
-/**
1131
+/*
11381132 * PCI Quirks for xHCI.
11391133 *
11401134 * Takes care of the handoff between the Pre-OS (i.e. BIOS) and the OS.
....@@ -1154,7 +1148,7 @@
11541148 if (!mmio_resource_enabled(pdev, 0))
11551149 return;
11561150
1157
- base = ioremap_nocache(pci_resource_start(pdev, 0), len);
1151
+ base = ioremap(pci_resource_start(pdev, 0), len);
11581152 if (base == NULL)
11591153 return;
11601154
....@@ -1247,11 +1241,27 @@
12471241
12481242 static void quirk_usb_early_handoff(struct pci_dev *pdev)
12491243 {
1244
+ struct device_node *parent;
1245
+ bool is_rpi;
1246
+
12501247 /* Skip Netlogic mips SoC's internal PCI USB controller.
12511248 * This device does not need/support EHCI/OHCI handoff
12521249 */
12531250 if (pdev->vendor == 0x184e) /* vendor Netlogic */
12541251 return;
1252
+
1253
+ /*
1254
+ * Bypass the Raspberry Pi 4 controller xHCI controller, things are
1255
+ * taken care of by the board's co-processor.
1256
+ */
1257
+ if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483) {
1258
+ parent = of_get_parent(pdev->bus->dev.of_node);
1259
+ is_rpi = of_device_is_compatible(parent, "brcm,bcm2711-pcie");
1260
+ of_node_put(parent);
1261
+ if (is_rpi)
1262
+ return;
1263
+ }
1264
+
12551265 if (pdev->class != PCI_CLASS_SERIAL_USB_UHCI &&
12561266 pdev->class != PCI_CLASS_SERIAL_USB_OHCI &&
12571267 pdev->class != PCI_CLASS_SERIAL_USB_EHCI &&