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