xhci-pci.c 24.3 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
2 3 4 5 6 7 8 9 10 11
/*
 * xHCI host controller driver PCI Bus Glue.
 *
 * Copyright (C) 2008 Intel Corp.
 *
 * Author: Sarah Sharp
 * Some code borrowed from the Linux EHCI driver.
 */

#include <linux/pci.h>
12
#include <linux/slab.h>
13
#include <linux/module.h>
14
#include <linux/acpi.h>
15
#include <linux/reset.h>
16 17

#include "xhci.h"
18
#include "xhci-trace.h"
19
#include "xhci-pci.h"
20

21 22 23
#define SSIC_PORT_NUM		2
#define SSIC_PORT_CFG2		0x880c
#define SSIC_PORT_CFG2_OFFSET	0x30
24 25
#define PROG_DONE		(1 << 30)
#define SSIC_PORT_UNUSED	(1 << 31)
26 27
#define SPARSE_DISABLE_BIT	17
#define SPARSE_CNTL_ENABLE	0xC12C
28

29 30 31
/* Device for a quirk */
#define PCI_VENDOR_ID_FRESCO_LOGIC	0x1b73
#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK	0x1000
32
#define PCI_DEVICE_ID_FRESCO_LOGIC_FL1009	0x1009
33
#define PCI_DEVICE_ID_FRESCO_LOGIC_FL1100	0x1100
S
Sarah Sharp 已提交
34
#define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400	0x1400
35

36
#define PCI_VENDOR_ID_ETRON		0x1b6f
37
#define PCI_DEVICE_ID_EJ168		0x7023
38
#define PCI_DEVICE_ID_EJ188		0x7052
39

40 41
#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI	0x8c31
#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI	0x9c31
42
#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI	0x9cb1
43 44 45
#define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI		0x22b5
#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI		0xa12f
#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI	0x9d2f
46
#define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI		0x0aa8
47
#define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI		0x1aa8
48
#define PCI_DEVICE_ID_INTEL_APL_XHCI			0x5aa8
49
#define PCI_DEVICE_ID_INTEL_DNV_XHCI			0x19d0
50 51
#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI	0x15b5
#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI	0x15b6
52
#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI	0x15c1
53 54 55 56 57
#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI	0x15db
#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI	0x15d4
#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI		0x15e9
#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI		0x15ec
#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI		0x15f0
58
#define PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI		0x8a13
59
#define PCI_DEVICE_ID_INTEL_CML_XHCI			0xa3af
60
#define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI		0x9a13
61
#define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI		0x1138
62
#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_XHCI		0x461e
63
#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_XHCI		0x464e
64
#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI	0x51ed
65
#define PCI_DEVICE_ID_INTEL_RAPTOR_LAKE_XHCI		0xa71e
66
#define PCI_DEVICE_ID_INTEL_METEOR_LAKE_XHCI		0x7ec0
67

68 69 70 71
#define PCI_DEVICE_ID_AMD_PROMONTORYA_4			0x43b9
#define PCI_DEVICE_ID_AMD_PROMONTORYA_3			0x43ba
#define PCI_DEVICE_ID_AMD_PROMONTORYA_2			0x43bb
#define PCI_DEVICE_ID_AMD_PROMONTORYA_1			0x43bc
72 73 74 75 76 77
#define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_1		0x161a
#define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_2		0x161b
#define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_3		0x161d
#define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_4		0x161e
#define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_5		0x15d6
#define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_6		0x15d7
78 79
#define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_7		0x161c
#define PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_8		0x161f
80

81
#define PCI_DEVICE_ID_ASMEDIA_1042_XHCI			0x1042
82
#define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI		0x1142
83
#define PCI_DEVICE_ID_ASMEDIA_1142_XHCI			0x1242
84
#define PCI_DEVICE_ID_ASMEDIA_2142_XHCI			0x2142
85
#define PCI_DEVICE_ID_ASMEDIA_3242_XHCI			0x3242
86

87 88
static const char hcd_name[] = "xhci_hcd";

89 90
static struct hc_driver __read_mostly xhci_pci_hc_driver;

91 92 93 94 95 96
static int xhci_pci_setup(struct usb_hcd *hcd);

static const struct xhci_driver_overrides xhci_pci_overrides __initconst = {
	.reset = xhci_pci_setup,
};

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
/* called after powerup, by probe or system-pm "wakeup" */
static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
{
	/*
	 * TODO: Implement finding debug ports later.
	 * TODO: see if there are any quirks that need to be added to handle
	 * new extended capabilities.
	 */

	/* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
	if (!pci_set_mwi(pdev))
		xhci_dbg(xhci, "MWI active\n");

	xhci_dbg(xhci, "Finished xhci_pci_reinit\n");
	return 0;
}

114 115
static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
{
116 117 118 119 120 121 122 123 124 125
	struct pci_dev                  *pdev = to_pci_dev(dev);
	struct xhci_driver_data         *driver_data;
	const struct pci_device_id      *id;

	id = pci_match_id(pdev->driver->id_table, pdev);

	if (id && id->driver_data) {
		driver_data = (struct xhci_driver_data *)id->driver_data;
		xhci->quirks |= driver_data->quirks;
	}
126

127 128
	/* Look for vendor-specific quirks */
	if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
S
Sarah Sharp 已提交
129 130 131 132
			(pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK ||
			 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1400)) {
		if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
				pdev->revision == 0x0) {
133
			xhci->quirks |= XHCI_RESET_EP_QUIRK;
134 135 136
			xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
				"QUIRK: Fresco Logic xHC needs configure"
				" endpoint cmd after reset endpoint");
137
		}
138 139 140 141 142 143 144 145
		if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
				pdev->revision == 0x4) {
			xhci->quirks |= XHCI_SLOW_SUSPEND;
			xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
				"QUIRK: Fresco Logic xHC revision %u"
				"must be suspended extra slowly",
				pdev->revision);
		}
146 147
		if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK)
			xhci->quirks |= XHCI_BROKEN_STREAMS;
148 149 150 151 152
		/* Fresco Logic confirms: all revisions of this chip do not
		 * support MSI, even though some of them claim to in their PCI
		 * capabilities.
		 */
		xhci->quirks |= XHCI_BROKEN_MSI;
153 154 155
		xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
				"QUIRK: Fresco Logic revision %u "
				"has broken MSI implementation",
156
				pdev->revision);
157
		xhci->quirks |= XHCI_TRUST_TX_LENGTH;
158
	}
159

160 161 162 163
	if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
			pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1009)
		xhci->quirks |= XHCI_BROKEN_STREAMS;

164 165 166 167
	if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
			pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1100)
		xhci->quirks |= XHCI_TRUST_TX_LENGTH;

168 169
	if (pdev->vendor == PCI_VENDOR_ID_NEC)
		xhci->quirks |= XHCI_NEC_HOST;
170

171 172 173
	if (pdev->vendor == PCI_VENDOR_ID_AMD && xhci->hci_version == 0x96)
		xhci->quirks |= XHCI_AMD_0x96_HOST;

A
Andiry Xu 已提交
174
	/* AMD PLL quirk */
175
	if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_quirk_pll_check())
A
Andiry Xu 已提交
176
		xhci->quirks |= XHCI_AMD_PLL_FIX;
177

178
	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
179 180
		(pdev->device == 0x145c ||
		 pdev->device == 0x15e0 ||
181 182
		 pdev->device == 0x15e1 ||
		 pdev->device == 0x43bb))
183 184
		xhci->quirks |= XHCI_SUSPEND_DELAY;

185 186 187 188
	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
	    (pdev->device == 0x15e0 || pdev->device == 0x15e1))
		xhci->quirks |= XHCI_SNPS_BROKEN_SUSPEND;

189
	if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x15e5) {
190
		xhci->quirks |= XHCI_DISABLE_SPARSE;
191 192
		xhci->quirks |= XHCI_RESET_ON_RESUME;
	}
193

194 195 196
	if (pdev->vendor == PCI_VENDOR_ID_AMD)
		xhci->quirks |= XHCI_TRUST_TX_LENGTH;

197 198 199 200 201 202 203
	if ((pdev->vendor == PCI_VENDOR_ID_AMD) &&
		((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) ||
		(pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) ||
		(pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2) ||
		(pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_1)))
		xhci->quirks |= XHCI_U2_DISABLE_WAKE;

204 205 206
	if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
		xhci->quirks |= XHCI_LPM_SUPPORT;
		xhci->quirks |= XHCI_INTEL_HOST;
207
		xhci->quirks |= XHCI_AVOID_BEI;
208
	}
209 210
	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
			pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
211 212
		xhci->quirks |= XHCI_EP_LIMIT_QUIRK;
		xhci->limit_active_eps = 64;
213
		xhci->quirks |= XHCI_SW_BW_CHECKING;
214 215 216 217 218 219 220 221 222
		/*
		 * PPT desktop boards DH77EB and DH77DF will power back on after
		 * a few seconds of being shutdown.  The fix for this is to
		 * switch the ports from xHCI to EHCI on shutdown.  We can't use
		 * DMI information to find those particular boards (since each
		 * vendor will change the board name), so we have to key off all
		 * PPT chipsets.
		 */
		xhci->quirks |= XHCI_SPURIOUS_REBOOT;
223
	}
224
	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
225 226
		(pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI ||
		 pdev->device == PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI)) {
227
		xhci->quirks |= XHCI_SPURIOUS_REBOOT;
228
		xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
229
	}
230 231 232
	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
		(pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
		 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
233
		 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
234
		 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI ||
235
		 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI ||
236
		 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI ||
237 238
		 pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI ||
		 pdev->device == PCI_DEVICE_ID_INTEL_CML_XHCI)) {
239 240
		xhci->quirks |= XHCI_PME_STUCK_QUIRK;
	}
241
	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
242
	    pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI)
243
		xhci->quirks |= XHCI_SSIC_PORT_UNUSED;
244 245
	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
	    (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
246
	     pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
247
	     pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI))
248
		xhci->quirks |= XHCI_INTEL_USB_ROLE_SW;
249 250
	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
	    (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
251 252
	     pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
	     pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
253 254
	     pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI ||
	     pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI))
255 256
		xhci->quirks |= XHCI_MISSING_CAS;

257 258 259 260
	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
	    pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI)
		xhci->quirks |= XHCI_RESET_TO_DEFAULT;

261 262 263
	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
	    (pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI ||
	     pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI ||
264
	     pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI ||
265 266 267 268
	     pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI ||
	     pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI ||
	     pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI ||
	     pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI ||
269
	     pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI ||
270
	     pdev->device == PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI ||
271
	     pdev->device == PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI ||
272
	     pdev->device == PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI ||
273
	     pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_XHCI ||
274
	     pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_XHCI ||
275
	     pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI ||
276 277
	     pdev->device == PCI_DEVICE_ID_INTEL_RAPTOR_LAKE_XHCI ||
	     pdev->device == PCI_DEVICE_ID_INTEL_METEOR_LAKE_XHCI))
278 279
		xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;

280
	if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
281
			pdev->device == PCI_DEVICE_ID_EJ168) {
282
		xhci->quirks |= XHCI_RESET_ON_RESUME;
283
		xhci->quirks |= XHCI_TRUST_TX_LENGTH;
284
		xhci->quirks |= XHCI_BROKEN_STREAMS;
285
	}
286 287 288 289 290

	if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
			pdev->device == PCI_DEVICE_ID_EJ188)
		xhci->quirks |= XHCI_NO_SOFT_RETRY;

291
	if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
292
	    pdev->device == 0x0014) {
293
		xhci->quirks |= XHCI_TRUST_TX_LENGTH;
294 295
		xhci->quirks |= XHCI_ZERO_64B_REGS;
	}
296
	if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
297
	    pdev->device == 0x0015) {
298
		xhci->quirks |= XHCI_RESET_ON_RESUME;
299 300
		xhci->quirks |= XHCI_ZERO_64B_REGS;
	}
301 302
	if (pdev->vendor == PCI_VENDOR_ID_VIA)
		xhci->quirks |= XHCI_RESET_ON_RESUME;
303 304 305 306
	if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN) {
		xhci->quirks |= XHCI_LPM_SUPPORT;
		xhci->quirks |= XHCI_ZHAOXIN_HOST;
	}
307 308
	if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN)
		xhci->quirks |= XHCI_SUSPEND_DELAY;
309

310 311 312 313 314
	/* See https://bugzilla.kernel.org/show_bug.cgi?id=79511 */
	if (pdev->vendor == PCI_VENDOR_ID_VIA &&
			pdev->device == 0x3432)
		xhci->quirks |= XHCI_BROKEN_STREAMS;

315
	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483) {
316
		xhci->quirks |= XHCI_LPM_SUPPORT;
317 318
		xhci->quirks |= XHCI_EP_CTX_BROKEN_DCS;
	}
319

320 321 322 323 324
	if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN &&
		(pdev->device == 0x9202 ||
		 pdev->device == 0x9203))
		xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH;

325
	if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
326 327 328 329 330 331
		pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI) {
		/*
		 * try to tame the ASMedia 1042 controller which reports 0.96
		 * but appears to behave more like 1.0
		 */
		xhci->quirks |= XHCI_SPURIOUS_SUCCESS;
332
		xhci->quirks |= XHCI_BROKEN_STREAMS;
333
	}
334
	if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
335
		pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI) {
336
		xhci->quirks |= XHCI_TRUST_TX_LENGTH;
337 338
		xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
	}
339
	if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
340
	    (pdev->device == PCI_DEVICE_ID_ASMEDIA_1142_XHCI ||
341 342
	     pdev->device == PCI_DEVICE_ID_ASMEDIA_2142_XHCI ||
	     pdev->device == PCI_DEVICE_ID_ASMEDIA_3242_XHCI))
343
		xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
344

345 346 347 348
	if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
		pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI)
		xhci->quirks |= XHCI_ASMEDIA_MODIFY_FLOWCONTROL;

349 350 351
	if (pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241)
		xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_7;

352 353 354
	if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN && pdev->device == 0x9202)
		xhci->quirks |= XHCI_RESET_ON_RESUME;

355 356 357 358 359
	if ((pdev->vendor == PCI_VENDOR_ID_BROADCOM ||
	     pdev->vendor == PCI_VENDOR_ID_CAVIUM) &&
	     pdev->device == 0x9026)
		xhci->quirks |= XHCI_RESET_PLL_ON_DISCONNECT;

360 361 362 363 364
	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
	    (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2 ||
	     pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4))
		xhci->quirks |= XHCI_NO_SOFT_RETRY;

365 366 367 368 369 370
	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
	    (pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_1 ||
	    pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_2 ||
	    pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_3 ||
	    pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_4 ||
	    pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_5 ||
371 372 373
	    pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_6 ||
	    pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_7 ||
	    pdev->device == PCI_DEVICE_ID_AMD_YELLOW_CARP_XHCI_8))
374 375
		xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;

376 377 378
	if (xhci->quirks & XHCI_RESET_ON_RESUME)
		xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
				"QUIRK: Resetting on resume");
379 380 381 382

	if (pdev->vendor == PCI_VENDOR_ID_HUAWEI &&
	   (pdev->device == 0xa23c || pdev->device == 0xa23d))
		xhci->quirks |= XHCI_USB3_NOOP;
383
}
A
Andiry Xu 已提交
384

385 386 387
#ifdef CONFIG_ACPI
static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev)
{
388 389 390
	static const guid_t intel_dsm_guid =
		GUID_INIT(0xac340cb7, 0xe901, 0x45bf,
			  0xb7, 0xe6, 0x2b, 0x34, 0xec, 0x93, 0x1e, 0x23);
391 392
	union acpi_object *obj;

393
	obj = acpi_evaluate_dsm(ACPI_HANDLE(&dev->dev), &intel_dsm_guid, 3, 1,
394 395
				NULL);
	ACPI_FREE(obj);
396 397
}
#else
398
static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev) { }
399 400
#endif /* CONFIG_ACPI */

401 402 403 404 405 406
/* called during probe() after chip reset completes */
static int xhci_pci_setup(struct usb_hcd *hcd)
{
	struct xhci_hcd		*xhci;
	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
	int			retval;
407

408 409 410 411
	xhci = hcd_to_xhci(hcd);
	if (!xhci->sbrn)
		pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn);

412 413 414
	/* imod_interval is the interrupt moderation value in nanoseconds. */
	xhci->imod_interval = 40000;

415
	retval = xhci_gen_setup(hcd, xhci_pci_quirks);
416
	if (retval)
417
		return retval;
S
Sarah Sharp 已提交
418

419 420
	if (!usb_hcd_is_primary_hcd(hcd))
		return 0;
421

422 423 424
	if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
		xhci_pme_acpi_rtd3_enable(pdev);

425 426 427
	xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn);

	/* Find any debug ports */
428
	return xhci_pci_reinit(xhci, pdev);
429 430
}

431 432 433 434
#ifdef CONFIG_ARM64
#include <asm/cputype.h>
static void phytium_xhci_pci_workaround(struct pci_dev *dev)
{
435 436
	u32 midr = read_cpuid_id();

437
	/* Firmware bug, DMA mask is not reported by the firmware */
438
	if ((midr & MIDR_CPU_MODEL_MASK) == MIDR_FT_2000PLUS)
439 440 441 442 443 444
		dma_set_mask(&dev->dev, DMA_BIT_MASK(64));
}
#else
static inline void phytium_xhci_pci_workaround(struct pci_dev *dev) { }
#endif

445 446 447 448 449 450 451 452 453
/*
 * We need to register our own PCI probe function (instead of the USB core's
 * function) in order to create a second roothub under xHCI.
 */
static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
{
	int retval;
	struct xhci_hcd *xhci;
	struct usb_hcd *hcd;
454
	struct xhci_driver_data *driver_data;
455
	struct reset_control *reset;
456 457 458 459 460 461 462

	driver_data = (struct xhci_driver_data *)id->driver_data;
	if (driver_data && driver_data->quirks & XHCI_RENESAS_FW_QUIRK) {
		retval = renesas_xhci_check_request_fw(dev, id);
		if (retval)
			return retval;
	}
463

464 465 466 467 468
	reset = devm_reset_control_get_optional_exclusive(&dev->dev, NULL);
	if (IS_ERR(reset))
		return PTR_ERR(reset);
	reset_control_reset(reset);

469 470
	phytium_xhci_pci_workaround(dev);

471 472 473
	/* Prevent runtime suspending between USB-2 and USB-3 initialization */
	pm_runtime_get_noresume(&dev->dev);

474 475 476 477 478 479
	/* Register the USB 2.0 roothub.
	 * FIXME: USB core must know to register the USB 2.0 roothub first.
	 * This is sort of silly, because we could just set the HCD driver flags
	 * to say USB 2.0, but I'm not sure what the implications would be in
	 * the other parts of the HCD code.
	 */
480
	retval = usb_hcd_pci_probe(dev, id, &xhci_pci_hc_driver);
481 482

	if (retval)
483
		goto put_runtime_pm;
484 485 486 487

	/* USB 2.0 roothub is stored in the PCI device now. */
	hcd = dev_get_drvdata(&dev->dev);
	xhci = hcd_to_xhci(hcd);
488
	xhci->reset = reset;
489 490
	xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev,
						 pci_name(dev), hcd);
491 492 493 494 495
	if (!xhci->shared_hcd) {
		retval = -ENOMEM;
		goto dealloc_usb2_hcd;
	}

496 497 498 499
	retval = xhci_ext_cap_init(xhci);
	if (retval)
		goto put_usb3_hcd;

500
	retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
Y
Yong Zhang 已提交
501
			IRQF_SHARED);
502 503 504
	if (retval)
		goto put_usb3_hcd;
	/* Roothub already marked as USB 3.0 speed */
505

506 507
	if (!(xhci->quirks & XHCI_BROKEN_STREAMS) &&
			HCC_MAX_PSA(xhci->hcc_params) >= 4)
508 509
		xhci->shared_hcd->can_do_streams = 1;

510 511 512
	/* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */
	pm_runtime_put_noidle(&dev->dev);

513 514 515
	if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
		pm_runtime_allow(&dev->dev);

516 517 518 519 520 521
	return 0;

put_usb3_hcd:
	usb_put_hcd(xhci->shared_hcd);
dealloc_usb2_hcd:
	usb_hcd_pci_remove(dev);
522 523
put_runtime_pm:
	pm_runtime_put_noidle(&dev->dev);
524 525 526
	return retval;
}

527 528 529 530 531
static void xhci_pci_remove(struct pci_dev *dev)
{
	struct xhci_hcd *xhci;

	xhci = hcd_to_xhci(pci_get_drvdata(dev));
532 533 534
	if (xhci->quirks & XHCI_RENESAS_FW_QUIRK)
		renesas_xhci_pci_exit(dev);

535
	xhci->xhc_state |= XHCI_STATE_REMOVING;
536 537 538 539

	if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
		pm_runtime_forbid(&dev->dev);

540 541 542
	if (xhci->shared_hcd) {
		usb_remove_hcd(xhci->shared_hcd);
		usb_put_hcd(xhci->shared_hcd);
543
		xhci->shared_hcd = NULL;
544
	}
545 546 547 548

	/* Workaround for spurious wakeups at shutdown with HSW */
	if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
		pci_set_power_state(dev, PCI_D3hot);
549 550

	usb_hcd_pci_remove(dev);
551 552
}

553
#ifdef CONFIG_PM
554 555 556 557 558 559 560
/*
 * In some Intel xHCI controllers, in order to get D3 working,
 * through a vendor specific SSIC CONFIG register at offset 0x883c,
 * SSIC PORT need to be marked as "unused" before putting xHCI
 * into D3. After D3 exit, the SSIC port need to be marked as "used".
 * Without this change, xHCI might not enter D3 state.
 */
561
static void xhci_ssic_port_unused_quirk(struct usb_hcd *hcd, bool suspend)
562 563 564 565
{
	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
	u32 val;
	void __iomem *reg;
566
	int i;
567

568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
	for (i = 0; i < SSIC_PORT_NUM; i++) {
		reg = (void __iomem *) xhci->cap_regs +
				SSIC_PORT_CFG2 +
				i * SSIC_PORT_CFG2_OFFSET;

		/* Notify SSIC that SSIC profile programming is not done. */
		val = readl(reg) & ~PROG_DONE;
		writel(val, reg);

		/* Mark SSIC port as unused(suspend) or used(resume) */
		val = readl(reg);
		if (suspend)
			val |= SSIC_PORT_UNUSED;
		else
			val &= ~SSIC_PORT_UNUSED;
		writel(val, reg);

		/* Notify SSIC that SSIC profile programming is done */
		val = readl(reg) | PROG_DONE;
		writel(val, reg);
		readl(reg);
589
	}
590 591 592 593 594 595 596 597 598 599 600
}

/*
 * Make sure PME works on some Intel xHCI controllers by writing 1 to clear
 * the Internal PME flag bit in vendor specific PMCTRL register at offset 0x80a4
 */
static void xhci_pme_quirk(struct usb_hcd *hcd)
{
	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
	void __iomem *reg;
	u32 val;
601 602 603 604 605 606 607

	reg = (void __iomem *) xhci->cap_regs + 0x80a4;
	val = readl(reg);
	writel(val | BIT(28), reg);
	readl(reg);
}

608 609 610 611 612 613 614 615 616
static void xhci_sparse_control_quirk(struct usb_hcd *hcd)
{
	u32 reg;

	reg = readl(hcd->regs + SPARSE_CNTL_ENABLE);
	reg &= ~BIT(SPARSE_DISABLE_BIT);
	writel(reg, hcd->regs + SPARSE_CNTL_ENABLE);
}

617 618 619
static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
{
	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
620
	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
621
	int			ret;
622 623 624 625 626

	/*
	 * Systems with the TI redriver that loses port status change events
	 * need to have the registers polled during D3, so avoid D3cold.
	 */
627
	if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
628
		pci_d3cold_disable(pdev);
629

630
	if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
631 632 633 634
		xhci_pme_quirk(hcd);

	if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
		xhci_ssic_port_unused_quirk(hcd, true);
635

636 637 638
	if (xhci->quirks & XHCI_DISABLE_SPARSE)
		xhci_sparse_control_quirk(hcd);

639 640 641 642 643
	ret = xhci_suspend(xhci, do_wakeup);
	if (ret && (xhci->quirks & XHCI_SSIC_PORT_UNUSED))
		xhci_ssic_port_unused_quirk(hcd, false);

	return ret;
644 645 646 647 648
}

static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
{
	struct xhci_hcd		*xhci = hcd_to_xhci(hcd);
649
	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
650 651
	int			retval = 0;

652 653
	reset_control_reset(xhci->reset);

654 655 656 657 658 659 660 661 662 663 664
	/* The BIOS on systems with the Intel Panther Point chipset may or may
	 * not support xHCI natively.  That means that during system resume, it
	 * may switch the ports back to EHCI so that users can use their
	 * keyboard to select a kernel from GRUB after resume from hibernate.
	 *
	 * The BIOS is supposed to remember whether the OS had xHCI ports
	 * enabled before resume, and switch the ports back to xHCI when the
	 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
	 * writers.
	 *
	 * Unconditionally switch the ports back to xHCI after a system resume.
665 666 667 668 669
	 * It should not matter whether the EHCI or xHCI controller is
	 * resumed first. It's enough to do the switchover in xHCI because
	 * USB core won't notice anything as the hub driver doesn't start
	 * running again until after all the devices (including both EHCI and
	 * xHCI host controllers) have been resumed.
670
	 */
671 672 673

	if (pdev->vendor == PCI_VENDOR_ID_INTEL)
		usb_enable_intel_xhci_ports(pdev);
674

675 676 677
	if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
		xhci_ssic_port_unused_quirk(hcd, false);

678
	if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
679
		xhci_pme_quirk(hcd);
680

681 682 683 684
	retval = xhci_resume(xhci, hibernated);
	return retval;
}

685 686 687 688 689 690 691 692 693 694 695
static void xhci_pci_shutdown(struct usb_hcd *hcd)
{
	struct xhci_hcd		*xhci = hcd_to_xhci(hcd);
	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);

	xhci_shutdown(hcd);

	/* Yet another workaround for spurious wakeups at shutdown with HSW */
	if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
		pci_set_power_state(pdev, PCI_D3hot);
}
696
#endif /* CONFIG_PM */
697

698 699
/*-------------------------------------------------------------------------*/

700 701 702 703 704
static const struct xhci_driver_data reneses_data = {
	.quirks  = XHCI_RENESAS_FW_QUIRK,
	.firmware = "renesas_usb_fw.mem",
};

705
/* PCI driver selection metadata; PCI hotplugging uses this */
706
static const struct pci_device_id pci_ids[] = {
707 708 709 710 711 712
	{ PCI_DEVICE(0x1912, 0x0014),
		.driver_data =  (unsigned long)&reneses_data,
	},
	{ PCI_DEVICE(0x1912, 0x0015),
		.driver_data =  (unsigned long)&reneses_data,
	},
713
	/* handle any USB 3.0 xHCI controller */
714
	{ PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0),
715 716 717 718
	},
	{ /* end: all zeroes */ }
};
MODULE_DEVICE_TABLE(pci, pci_ids);
719 720 721 722 723 724

/*
 * Without CONFIG_USB_XHCI_PCI_RENESAS renesas_xhci_check_request_fw() won't
 * load firmware, so don't encumber the xhci-pci driver with it.
 */
#if IS_ENABLED(CONFIG_USB_XHCI_PCI_RENESAS)
725
MODULE_FIRMWARE("renesas_usb_fw.mem");
726
#endif
727 728 729

/* pci driver glue; this is a "new style" PCI driver module */
static struct pci_driver xhci_pci_driver = {
730
	.name =		hcd_name,
731 732
	.id_table =	pci_ids,

733
	.probe =	xhci_pci_probe,
734
	.remove =	xhci_pci_remove,
735 736 737
	/* suspend and resume implemented later */

	.shutdown = 	usb_hcd_pci_shutdown,
738
#ifdef CONFIG_PM
739 740 741 742
	.driver = {
		.pm = &usb_hcd_pci_pm_ops
	},
#endif
743 744
};

745
static int __init xhci_pci_init(void)
746
{
747
	xhci_init_driver(&xhci_pci_hc_driver, &xhci_pci_overrides);
748 749 750
#ifdef CONFIG_PM
	xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend;
	xhci_pci_hc_driver.pci_resume = xhci_pci_resume;
751
	xhci_pci_hc_driver.shutdown = xhci_pci_shutdown;
752
#endif
753 754
	return pci_register_driver(&xhci_pci_driver);
}
755
module_init(xhci_pci_init);
756

757
static void __exit xhci_pci_exit(void)
758 759 760
{
	pci_unregister_driver(&xhci_pci_driver);
}
761 762 763 764
module_exit(xhci_pci_exit);

MODULE_DESCRIPTION("xHCI PCI Host Controller Driver");
MODULE_LICENSE("GPL");