xref: /linux/drivers/usb/host/ehci-pci.c (revision c5cf9212a368d88fe1e25797699b167f6daa64a5)
17ff71d6aSMatt Porter /*
27ff71d6aSMatt Porter  * EHCI HCD (Host Controller Driver) PCI Bus Glue.
37ff71d6aSMatt Porter  *
47ff71d6aSMatt Porter  * Copyright (c) 2000-2004 by David Brownell
57ff71d6aSMatt Porter  *
67ff71d6aSMatt Porter  * This program is free software; you can redistribute it and/or modify it
77ff71d6aSMatt Porter  * under the terms of the GNU General Public License as published by the
87ff71d6aSMatt Porter  * Free Software Foundation; either version 2 of the License, or (at your
97ff71d6aSMatt Porter  * option) any later version.
107ff71d6aSMatt Porter  *
117ff71d6aSMatt Porter  * This program is distributed in the hope that it will be useful, but
127ff71d6aSMatt Porter  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
137ff71d6aSMatt Porter  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
147ff71d6aSMatt Porter  * for more details.
157ff71d6aSMatt Porter  *
167ff71d6aSMatt Porter  * You should have received a copy of the GNU General Public License
177ff71d6aSMatt Porter  * along with this program; if not, write to the Free Software Foundation,
187ff71d6aSMatt Porter  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
197ff71d6aSMatt Porter  */
207ff71d6aSMatt Porter 
217ff71d6aSMatt Porter #ifndef CONFIG_PCI
227ff71d6aSMatt Porter #error "This file is PCI bus glue.  CONFIG_PCI must be defined."
237ff71d6aSMatt Porter #endif
247ff71d6aSMatt Porter 
254f683843SDirk Brandewie /* defined here to avoid adding to pci_ids.h for single instance use */
264f683843SDirk Brandewie #define PCI_DEVICE_ID_INTEL_CE4100_USB	0x2e70
274f683843SDirk Brandewie 
287ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
297ff71d6aSMatt Porter 
3018807521SDavid Brownell /* called after powerup, by probe or system-pm "wakeup" */
3118807521SDavid Brownell static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
3218807521SDavid Brownell {
3318807521SDavid Brownell 	int			retval;
3418807521SDavid Brownell 
35401feafaSDavid Brownell 	/* we expect static quirk code to handle the "extended capabilities"
36401feafaSDavid Brownell 	 * (currently just BIOS handoff) allowed starting with EHCI 0.96
37401feafaSDavid Brownell 	 */
3818807521SDavid Brownell 
3918807521SDavid Brownell 	/* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
4018807521SDavid Brownell 	retval = pci_set_mwi(pdev);
4118807521SDavid Brownell 	if (!retval)
4218807521SDavid Brownell 		ehci_dbg(ehci, "MWI active\n");
4318807521SDavid Brownell 
4418807521SDavid Brownell 	return 0;
4518807521SDavid Brownell }
4618807521SDavid Brownell 
478926bfa7SDavid Brownell /* called during probe() after chip reset completes */
488926bfa7SDavid Brownell static int ehci_pci_setup(struct usb_hcd *hcd)
497ff71d6aSMatt Porter {
507ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
51abcc9448SDavid Brownell 	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
52b09bc6cbSAndiry Xu 	struct pci_dev		*p_smbus;
53b09bc6cbSAndiry Xu 	u8			rev;
547ff71d6aSMatt Porter 	u32			temp;
5518807521SDavid Brownell 	int			retval;
567ff71d6aSMatt Porter 
57083522d7SBenjamin Herrenschmidt 	switch (pdev->vendor) {
58083522d7SBenjamin Herrenschmidt 	case PCI_VENDOR_ID_TOSHIBA_2:
59083522d7SBenjamin Herrenschmidt 		/* celleb's companion chip */
60083522d7SBenjamin Herrenschmidt 		if (pdev->device == 0x01b5) {
61083522d7SBenjamin Herrenschmidt #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
62083522d7SBenjamin Herrenschmidt 			ehci->big_endian_mmio = 1;
63083522d7SBenjamin Herrenschmidt #else
64083522d7SBenjamin Herrenschmidt 			ehci_warn(ehci,
65083522d7SBenjamin Herrenschmidt 				  "unsupported big endian Toshiba quirk\n");
66083522d7SBenjamin Herrenschmidt #endif
67083522d7SBenjamin Herrenschmidt 		}
68083522d7SBenjamin Herrenschmidt 		break;
69083522d7SBenjamin Herrenschmidt 	}
70083522d7SBenjamin Herrenschmidt 
717ff71d6aSMatt Porter 	ehci->caps = hcd->regs;
72083522d7SBenjamin Herrenschmidt 	ehci->regs = hcd->regs +
73c430131aSJan Andersson 		HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
74083522d7SBenjamin Herrenschmidt 
757ff71d6aSMatt Porter 	dbg_hcs_params(ehci, "reset");
767ff71d6aSMatt Porter 	dbg_hcc_params(ehci, "reset");
777ff71d6aSMatt Porter 
78c32ba30fSPaul Serice         /* ehci_init() causes memory for DMA transfers to be
79c32ba30fSPaul Serice          * allocated.  Thus, any vendor-specific workarounds based on
80c32ba30fSPaul Serice          * limiting the type of memory used for DMA transfers must
81c32ba30fSPaul Serice          * happen before ehci_init() is called. */
82c32ba30fSPaul Serice 	switch (pdev->vendor) {
83c32ba30fSPaul Serice 	case PCI_VENDOR_ID_NVIDIA:
84c32ba30fSPaul Serice 		/* NVidia reports that certain chips don't handle
85c32ba30fSPaul Serice 		 * QH, ITD, or SITD addresses above 2GB.  (But TD,
86c32ba30fSPaul Serice 		 * data buffer, and periodic schedule are normal.)
87c32ba30fSPaul Serice 		 */
88c32ba30fSPaul Serice 		switch (pdev->device) {
89c32ba30fSPaul Serice 		case 0x003c:	/* MCP04 */
90c32ba30fSPaul Serice 		case 0x005b:	/* CK804 */
91c32ba30fSPaul Serice 		case 0x00d8:	/* CK8 */
92c32ba30fSPaul Serice 		case 0x00e8:	/* CK8S */
93c32ba30fSPaul Serice 			if (pci_set_consistent_dma_mask(pdev,
94929a22a5SYang Hongyang 						DMA_BIT_MASK(31)) < 0)
95c32ba30fSPaul Serice 				ehci_warn(ehci, "can't enable NVidia "
96c32ba30fSPaul Serice 					"workaround for >2GB RAM\n");
97c32ba30fSPaul Serice 			break;
98c32ba30fSPaul Serice 		}
99c32ba30fSPaul Serice 		break;
100c32ba30fSPaul Serice 	}
101c32ba30fSPaul Serice 
1027ff71d6aSMatt Porter 	/* cache this readonly data; minimize chip reads */
103083522d7SBenjamin Herrenschmidt 	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
1047ff71d6aSMatt Porter 
10518807521SDavid Brownell 	retval = ehci_halt(ehci);
10618807521SDavid Brownell 	if (retval)
10718807521SDavid Brownell 		return retval;
10818807521SDavid Brownell 
1093d091a6fSAndiry Xu 	if ((pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x7808) ||
1103d091a6fSAndiry Xu 	    (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x4396)) {
1113d091a6fSAndiry Xu 		/* EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
1123d091a6fSAndiry Xu 		 * read/write memory space which does not belong to it when
1133d091a6fSAndiry Xu 		 * there is NULL pointer with T-bit set to 1 in the frame list
1143d091a6fSAndiry Xu 		 * table. To avoid the issue, the frame list link pointer
1153d091a6fSAndiry Xu 		 * should always contain a valid pointer to a inactive qh.
1163d091a6fSAndiry Xu 		 */
1173d091a6fSAndiry Xu 		ehci->use_dummy_qh = 1;
1183d091a6fSAndiry Xu 		ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI "
1193d091a6fSAndiry Xu 				"dummy qh workaround\n");
1203d091a6fSAndiry Xu 	}
1213d091a6fSAndiry Xu 
1228926bfa7SDavid Brownell 	/* data structure init */
1238926bfa7SDavid Brownell 	retval = ehci_init(hcd);
1248926bfa7SDavid Brownell 	if (retval)
1258926bfa7SDavid Brownell 		return retval;
1268926bfa7SDavid Brownell 
1277ff71d6aSMatt Porter 	switch (pdev->vendor) {
1283681d8f3SDavid Miller 	case PCI_VENDOR_ID_NEC:
1293681d8f3SDavid Miller 		ehci->need_io_watchdog = 0;
1303681d8f3SDavid Miller 		break;
131403dbd36SAlek Du 	case PCI_VENDOR_ID_INTEL:
132403dbd36SAlek Du 		ehci->need_io_watchdog = 0;
133ae68a83bSAlan Stern 		ehci->fs_i_thresh = 1;
134ee4ecb8aSOliver Neukum 		if (pdev->device == 0x27cc) {
135ee4ecb8aSOliver Neukum 			ehci->broken_periodic = 1;
136ee4ecb8aSOliver Neukum 			ehci_info(ehci, "using broken periodic workaround\n");
137ee4ecb8aSOliver Neukum 		}
138fc928250SAlek Du 		if (pdev->device == 0x0806 || pdev->device == 0x0811
139fc928250SAlek Du 				|| pdev->device == 0x0829) {
140fc928250SAlek Du 			ehci_info(ehci, "disable lpm for langwell/penwell\n");
141fc928250SAlek Du 			ehci->has_lpm = 0;
142fc928250SAlek Du 		}
1434f683843SDirk Brandewie 		if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB) {
1444f683843SDirk Brandewie 			hcd->has_tt = 1;
1454f683843SDirk Brandewie 			tdi_reset(ehci);
1464f683843SDirk Brandewie 		}
147403dbd36SAlek Du 		break;
1487ff71d6aSMatt Porter 	case PCI_VENDOR_ID_TDI:
1497ff71d6aSMatt Porter 		if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
1507329e211SAlan Stern 			hcd->has_tt = 1;
1517ff71d6aSMatt Porter 			tdi_reset(ehci);
1527ff71d6aSMatt Porter 		}
1537ff71d6aSMatt Porter 		break;
1547ff71d6aSMatt Porter 	case PCI_VENDOR_ID_AMD:
155ad93562bSAndiry Xu 		/* AMD PLL quirk */
156ad93562bSAndiry Xu 		if (usb_amd_find_chipset_info())
157ad93562bSAndiry Xu 			ehci->amd_pll_fix = 1;
1587ff71d6aSMatt Porter 		/* AMD8111 EHCI doesn't work, according to AMD errata */
1597ff71d6aSMatt Porter 		if (pdev->device == 0x7463) {
1607ff71d6aSMatt Porter 			ehci_info(ehci, "ignoring AMD8111 (errata)\n");
1618926bfa7SDavid Brownell 			retval = -EIO;
1628926bfa7SDavid Brownell 			goto done;
1637ff71d6aSMatt Porter 		}
1647ff71d6aSMatt Porter 		break;
1657ff71d6aSMatt Porter 	case PCI_VENDOR_ID_NVIDIA:
166f8aeb3bbSDavid Brownell 		switch (pdev->device) {
167f8aeb3bbSDavid Brownell 		/* Some NForce2 chips have problems with selective suspend;
168f8aeb3bbSDavid Brownell 		 * fixed in newer silicon.
169f8aeb3bbSDavid Brownell 		 */
170f8aeb3bbSDavid Brownell 		case 0x0068:
17144c10138SAuke Kok 			if (pdev->revision < 0xa4)
172f8aeb3bbSDavid Brownell 				ehci->no_selective_suspend = 1;
173f8aeb3bbSDavid Brownell 			break;
174a85b4e7fSBrian J. Tarricone 
175a85b4e7fSBrian J. Tarricone 		/* MCP89 chips on the MacBookAir3,1 give EPROTO when
176a85b4e7fSBrian J. Tarricone 		 * fetching device descriptors unless LPM is disabled.
177a85b4e7fSBrian J. Tarricone 		 * There are also intermittent problems enumerating
178a85b4e7fSBrian J. Tarricone 		 * devices with PPCD enabled.
179a85b4e7fSBrian J. Tarricone 		 */
180a85b4e7fSBrian J. Tarricone 		case 0x0d9d:
181a85b4e7fSBrian J. Tarricone 			ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89");
182a85b4e7fSBrian J. Tarricone 			ehci->has_lpm = 0;
183a85b4e7fSBrian J. Tarricone 			ehci->has_ppcd = 0;
184a85b4e7fSBrian J. Tarricone 			ehci->command &= ~CMD_PPCEE;
185a85b4e7fSBrian J. Tarricone 			break;
1867ff71d6aSMatt Porter 		}
1877ff71d6aSMatt Porter 		break;
188055b93c9SRene Herman 	case PCI_VENDOR_ID_VIA:
189055b93c9SRene Herman 		if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) {
190055b93c9SRene Herman 			u8 tmp;
191055b93c9SRene Herman 
192055b93c9SRene Herman 			/* The VT6212 defaults to a 1 usec EHCI sleep time which
193055b93c9SRene Herman 			 * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes
194055b93c9SRene Herman 			 * that sleep time use the conventional 10 usec.
195055b93c9SRene Herman 			 */
196055b93c9SRene Herman 			pci_read_config_byte(pdev, 0x4b, &tmp);
197055b93c9SRene Herman 			if (tmp & 0x20)
198055b93c9SRene Herman 				break;
199055b93c9SRene Herman 			pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
200055b93c9SRene Herman 		}
201055b93c9SRene Herman 		break;
202b09bc6cbSAndiry Xu 	case PCI_VENDOR_ID_ATI:
203ad93562bSAndiry Xu 		/* AMD PLL quirk */
204ad93562bSAndiry Xu 		if (usb_amd_find_chipset_info())
205ad93562bSAndiry Xu 			ehci->amd_pll_fix = 1;
2060a99e8acSShane Huang 		/* SB600 and old version of SB700 have a bug in EHCI controller,
207b09bc6cbSAndiry Xu 		 * which causes usb devices lose response in some cases.
208b09bc6cbSAndiry Xu 		 */
2090a99e8acSShane Huang 		if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) {
210b09bc6cbSAndiry Xu 			p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
211b09bc6cbSAndiry Xu 						 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
212b09bc6cbSAndiry Xu 						 NULL);
213b09bc6cbSAndiry Xu 			if (!p_smbus)
214b09bc6cbSAndiry Xu 				break;
215b09bc6cbSAndiry Xu 			rev = p_smbus->revision;
2160a99e8acSShane Huang 			if ((pdev->device == 0x4386) || (rev == 0x3a)
2170a99e8acSShane Huang 			    || (rev == 0x3b)) {
218b09bc6cbSAndiry Xu 				u8 tmp;
2190a99e8acSShane Huang 				ehci_info(ehci, "applying AMD SB600/SB700 USB "
2200a99e8acSShane Huang 					"freeze workaround\n");
221b09bc6cbSAndiry Xu 				pci_read_config_byte(pdev, 0x53, &tmp);
222b09bc6cbSAndiry Xu 				pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
223b09bc6cbSAndiry Xu 			}
224b09bc6cbSAndiry Xu 			pci_dev_put(p_smbus);
225b09bc6cbSAndiry Xu 		}
226b09bc6cbSAndiry Xu 		break;
22768aa95d5SAlan Stern 	case PCI_VENDOR_ID_NETMOS:
22868aa95d5SAlan Stern 		/* MosChip frame-index-register bug */
22968aa95d5SAlan Stern 		ehci_info(ehci, "applying MosChip frame-index workaround\n");
23068aa95d5SAlan Stern 		ehci->frame_index_bug = 1;
23168aa95d5SAlan Stern 		break;
2327ff71d6aSMatt Porter 	}
2337ff71d6aSMatt Porter 
2348d053c79SJason Wessel 	/* optional debug port, normally in the first BAR */
2358d053c79SJason Wessel 	temp = pci_find_capability(pdev, 0x0a);
2368d053c79SJason Wessel 	if (temp) {
2378d053c79SJason Wessel 		pci_read_config_dword(pdev, temp, &temp);
2388d053c79SJason Wessel 		temp >>= 16;
2398d053c79SJason Wessel 		if ((temp & (3 << 13)) == (1 << 13)) {
2408d053c79SJason Wessel 			temp &= 0x1fff;
2418d053c79SJason Wessel 			ehci->debug = ehci_to_hcd(ehci)->regs + temp;
2428d053c79SJason Wessel 			temp = ehci_readl(ehci, &ehci->debug->control);
2438d053c79SJason Wessel 			ehci_info(ehci, "debug port %d%s\n",
2448d053c79SJason Wessel 				HCS_DEBUG_PORT(ehci->hcs_params),
2458d053c79SJason Wessel 				(temp & DBGP_ENABLED)
2468d053c79SJason Wessel 					? " IN USE"
2478d053c79SJason Wessel 					: "");
2488d053c79SJason Wessel 			if (!(temp & DBGP_ENABLED))
2498d053c79SJason Wessel 				ehci->debug = NULL;
2508d053c79SJason Wessel 		}
2518d053c79SJason Wessel 	}
2528d053c79SJason Wessel 
2537ff71d6aSMatt Porter 	ehci_reset(ehci);
2547ff71d6aSMatt Porter 
2557ff71d6aSMatt Porter 	/* at least the Genesys GL880S needs fixup here */
2567ff71d6aSMatt Porter 	temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
2577ff71d6aSMatt Porter 	temp &= 0x0f;
2587ff71d6aSMatt Porter 	if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
2597ff71d6aSMatt Porter 		ehci_dbg(ehci, "bogus port configuration: "
2607ff71d6aSMatt Porter 			"cc=%d x pcc=%d < ports=%d\n",
2617ff71d6aSMatt Porter 			HCS_N_CC(ehci->hcs_params),
2627ff71d6aSMatt Porter 			HCS_N_PCC(ehci->hcs_params),
2637ff71d6aSMatt Porter 			HCS_N_PORTS(ehci->hcs_params));
2647ff71d6aSMatt Porter 
2657ff71d6aSMatt Porter 		switch (pdev->vendor) {
2667ff71d6aSMatt Porter 		case 0x17a0:		/* GENESYS */
2677ff71d6aSMatt Porter 			/* GL880S: should be PORTS=2 */
2687ff71d6aSMatt Porter 			temp |= (ehci->hcs_params & ~0xf);
2697ff71d6aSMatt Porter 			ehci->hcs_params = temp;
2707ff71d6aSMatt Porter 			break;
2717ff71d6aSMatt Porter 		case PCI_VENDOR_ID_NVIDIA:
2727ff71d6aSMatt Porter 			/* NF4: should be PCC=10 */
2737ff71d6aSMatt Porter 			break;
2747ff71d6aSMatt Porter 		}
2757ff71d6aSMatt Porter 	}
2767ff71d6aSMatt Porter 
2777ff71d6aSMatt Porter 	/* Serial Bus Release Number is at PCI 0x60 offset */
2787ff71d6aSMatt Porter 	pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
2793a0bac06SAlessandro Rubini 	if (pdev->vendor == PCI_VENDOR_ID_STMICRO
2803a0bac06SAlessandro Rubini 	    && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST)
2813a0bac06SAlessandro Rubini 		ehci->sbrn = 0x20; /* ConneXT has no sbrn register */
2827ff71d6aSMatt Porter 
2836fd9086aSAlan Stern 	/* Keep this around for a while just in case some EHCI
2846fd9086aSAlan Stern 	 * implementation uses legacy PCI PM support.  This test
2856fd9086aSAlan Stern 	 * can be removed on 17 Dec 2009 if the dev_warn() hasn't
2866fd9086aSAlan Stern 	 * been triggered by then.
2872c1c3c4cSDavid Brownell 	 */
2882c1c3c4cSDavid Brownell 	if (!device_can_wakeup(&pdev->dev)) {
2892c1c3c4cSDavid Brownell 		u16	port_wake;
2902c1c3c4cSDavid Brownell 
2912c1c3c4cSDavid Brownell 		pci_read_config_word(pdev, 0x62, &port_wake);
2926fd9086aSAlan Stern 		if (port_wake & 0x0001) {
2936fd9086aSAlan Stern 			dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
294bcca06efSAlan Stern 			device_set_wakeup_capable(&pdev->dev, 1);
2952c1c3c4cSDavid Brownell 		}
2966fd9086aSAlan Stern 	}
2977ff71d6aSMatt Porter 
298f8aeb3bbSDavid Brownell #ifdef	CONFIG_USB_SUSPEND
299f8aeb3bbSDavid Brownell 	/* REVISIT: the controller works fine for wakeup iff the root hub
300f8aeb3bbSDavid Brownell 	 * itself is "globally" suspended, but usbcore currently doesn't
301f8aeb3bbSDavid Brownell 	 * understand such things.
302f8aeb3bbSDavid Brownell 	 *
303f8aeb3bbSDavid Brownell 	 * System suspend currently expects to be able to suspend the entire
304f8aeb3bbSDavid Brownell 	 * device tree, device-at-a-time.  If we failed selective suspend
305f8aeb3bbSDavid Brownell 	 * reports, system suspend would fail; so the root hub code must claim
306411c9403SAnand Gadiyar 	 * success.  That's lying to usbcore, and it matters for runtime
307f8aeb3bbSDavid Brownell 	 * PM scenarios with selective suspend and remote wakeup...
308f8aeb3bbSDavid Brownell 	 */
309f8aeb3bbSDavid Brownell 	if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
310f8aeb3bbSDavid Brownell 		ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
311f8aeb3bbSDavid Brownell #endif
312f8aeb3bbSDavid Brownell 
313aff6d18fSAlan Stern 	ehci_port_power(ehci, 1);
31418807521SDavid Brownell 	retval = ehci_pci_reinit(ehci, pdev);
3158926bfa7SDavid Brownell done:
3168926bfa7SDavid Brownell 	return retval;
3177ff71d6aSMatt Porter }
3187ff71d6aSMatt Porter 
3197ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
3207ff71d6aSMatt Porter 
3217ff71d6aSMatt Porter #ifdef	CONFIG_PM
3227ff71d6aSMatt Porter 
3237ff71d6aSMatt Porter /* suspend/resume, section 4.3 */
3247ff71d6aSMatt Porter 
325f03c17fcSDavid Brownell /* These routines rely on the PCI bus glue
3267ff71d6aSMatt Porter  * to handle powerdown and wakeup, and currently also on
3277ff71d6aSMatt Porter  * transceivers that don't need any software attention to set up
3287ff71d6aSMatt Porter  * the right sort of wakeup.
329f03c17fcSDavid Brownell  * Also they depend on separate root hub suspend/resume.
3307ff71d6aSMatt Porter  */
3317ff71d6aSMatt Porter 
3324147200dSAlan Stern static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
3337ff71d6aSMatt Porter {
334*c5cf9212SAlan Stern 	return ehci_suspend(hcd, do_wakeup);
3357ff71d6aSMatt Porter }
3367ff71d6aSMatt Porter 
33769e848c2SSarah Sharp static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
33869e848c2SSarah Sharp {
33969e848c2SSarah Sharp 	return pdev->class == PCI_CLASS_SERIAL_USB_EHCI &&
34069e848c2SSarah Sharp 		pdev->vendor == PCI_VENDOR_ID_INTEL &&
3411c12443aSSarah Sharp 		(pdev->device == 0x1E26 ||
3421c12443aSSarah Sharp 		 pdev->device == 0x8C2D ||
3431c12443aSSarah Sharp 		 pdev->device == 0x8C26);
34469e848c2SSarah Sharp }
34569e848c2SSarah Sharp 
34669e848c2SSarah Sharp static void ehci_enable_xhci_companion(void)
34769e848c2SSarah Sharp {
34869e848c2SSarah Sharp 	struct pci_dev		*companion = NULL;
34969e848c2SSarah Sharp 
35069e848c2SSarah Sharp 	/* The xHCI and EHCI controllers are not on the same PCI slot */
35169e848c2SSarah Sharp 	for_each_pci_dev(companion) {
35269e848c2SSarah Sharp 		if (!usb_is_intel_switchable_xhci(companion))
35369e848c2SSarah Sharp 			continue;
35469e848c2SSarah Sharp 		usb_enable_xhci_ports(companion);
35569e848c2SSarah Sharp 		return;
35669e848c2SSarah Sharp 	}
35769e848c2SSarah Sharp }
35869e848c2SSarah Sharp 
3596ec4beb5SAlan Stern static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
3607ff71d6aSMatt Porter {
3617ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
36218807521SDavid Brownell 	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
3637ff71d6aSMatt Porter 
36469e848c2SSarah Sharp 	/* The BIOS on systems with the Intel Panther Point chipset may or may
36569e848c2SSarah Sharp 	 * not support xHCI natively.  That means that during system resume, it
36669e848c2SSarah Sharp 	 * may switch the ports back to EHCI so that users can use their
36769e848c2SSarah Sharp 	 * keyboard to select a kernel from GRUB after resume from hibernate.
36869e848c2SSarah Sharp 	 *
36969e848c2SSarah Sharp 	 * The BIOS is supposed to remember whether the OS had xHCI ports
37069e848c2SSarah Sharp 	 * enabled before resume, and switch the ports back to xHCI when the
37169e848c2SSarah Sharp 	 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
37269e848c2SSarah Sharp 	 * writers.
37369e848c2SSarah Sharp 	 *
37469e848c2SSarah Sharp 	 * Unconditionally switch the ports back to xHCI after a system resume.
37569e848c2SSarah Sharp 	 * We can't tell whether the EHCI or xHCI controller will be resumed
37669e848c2SSarah Sharp 	 * first, so we have to do the port switchover in both drivers.  Writing
37769e848c2SSarah Sharp 	 * a '1' to the port switchover registers should have no effect if the
37869e848c2SSarah Sharp 	 * port was already switched over.
37969e848c2SSarah Sharp 	 */
38069e848c2SSarah Sharp 	if (usb_is_intel_switchable_ehci(pdev))
38169e848c2SSarah Sharp 		ehci_enable_xhci_companion();
38269e848c2SSarah Sharp 
383*c5cf9212SAlan Stern 	if (ehci_resume(hcd, hibernated) != 0)
38418807521SDavid Brownell 		(void) ehci_pci_reinit(ehci, pdev);
3858c03356aSAlan Stern 	return 0;
3867ff71d6aSMatt Porter }
3877ff71d6aSMatt Porter #endif
3887ff71d6aSMatt Porter 
38948f24970SAlek Du static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
39048f24970SAlek Du {
39148f24970SAlek Du 	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
39248f24970SAlek Du 	int rc = 0;
39348f24970SAlek Du 
39448f24970SAlek Du 	if (!udev->parent) /* udev is root hub itself, impossible */
39548f24970SAlek Du 		rc = -1;
39648f24970SAlek Du 	/* we only support lpm device connected to root hub yet */
39748f24970SAlek Du 	if (ehci->has_lpm && !udev->parent->parent) {
39848f24970SAlek Du 		rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
39948f24970SAlek Du 		if (!rc)
40048f24970SAlek Du 			rc = ehci_lpm_check(ehci, udev->portnum);
40148f24970SAlek Du 	}
40248f24970SAlek Du 	return rc;
40348f24970SAlek Du }
40448f24970SAlek Du 
4057ff71d6aSMatt Porter static const struct hc_driver ehci_pci_hc_driver = {
4067ff71d6aSMatt Porter 	.description =		hcd_name,
4077ff71d6aSMatt Porter 	.product_desc =		"EHCI Host Controller",
4087ff71d6aSMatt Porter 	.hcd_priv_size =	sizeof(struct ehci_hcd),
4097ff71d6aSMatt Porter 
4107ff71d6aSMatt Porter 	/*
4117ff71d6aSMatt Porter 	 * generic hardware linkage
4127ff71d6aSMatt Porter 	 */
4137ff71d6aSMatt Porter 	.irq =			ehci_irq,
4147ff71d6aSMatt Porter 	.flags =		HCD_MEMORY | HCD_USB2,
4157ff71d6aSMatt Porter 
4167ff71d6aSMatt Porter 	/*
4177ff71d6aSMatt Porter 	 * basic lifecycle operations
4187ff71d6aSMatt Porter 	 */
4198926bfa7SDavid Brownell 	.reset =		ehci_pci_setup,
42018807521SDavid Brownell 	.start =		ehci_run,
4217ff71d6aSMatt Porter #ifdef	CONFIG_PM
4227be7d741SAlan Stern 	.pci_suspend =		ehci_pci_suspend,
4237be7d741SAlan Stern 	.pci_resume =		ehci_pci_resume,
4247ff71d6aSMatt Porter #endif
42518807521SDavid Brownell 	.stop =			ehci_stop,
42664a21d02SAleksey Gorelov 	.shutdown =		ehci_shutdown,
4277ff71d6aSMatt Porter 
4287ff71d6aSMatt Porter 	/*
4297ff71d6aSMatt Porter 	 * managing i/o requests and associated device resources
4307ff71d6aSMatt Porter 	 */
4317ff71d6aSMatt Porter 	.urb_enqueue =		ehci_urb_enqueue,
4327ff71d6aSMatt Porter 	.urb_dequeue =		ehci_urb_dequeue,
4337ff71d6aSMatt Porter 	.endpoint_disable =	ehci_endpoint_disable,
434b18ffd49SAlan Stern 	.endpoint_reset =	ehci_endpoint_reset,
4357ff71d6aSMatt Porter 
4367ff71d6aSMatt Porter 	/*
4377ff71d6aSMatt Porter 	 * scheduling support
4387ff71d6aSMatt Porter 	 */
4397ff71d6aSMatt Porter 	.get_frame_number =	ehci_get_frame,
4407ff71d6aSMatt Porter 
4417ff71d6aSMatt Porter 	/*
4427ff71d6aSMatt Porter 	 * root hub support
4437ff71d6aSMatt Porter 	 */
4447ff71d6aSMatt Porter 	.hub_status_data =	ehci_hub_status_data,
4457ff71d6aSMatt Porter 	.hub_control =		ehci_hub_control,
4460c0382e3SAlan Stern 	.bus_suspend =		ehci_bus_suspend,
4470c0382e3SAlan Stern 	.bus_resume =		ehci_bus_resume,
44890da096eSBalaji Rao 	.relinquish_port =	ehci_relinquish_port,
4493a31155cSAlan Stern 	.port_handed_over =	ehci_port_handed_over,
450914b7012SAlan Stern 
45148f24970SAlek Du 	/*
45248f24970SAlek Du 	 * call back when device connected and addressed
45348f24970SAlek Du 	 */
45448f24970SAlek Du 	.update_device =	ehci_update_device,
45548f24970SAlek Du 
456914b7012SAlan Stern 	.clear_tt_buffer_complete	= ehci_clear_tt_buffer_complete,
4577ff71d6aSMatt Porter };
4587ff71d6aSMatt Porter 
4597ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
4607ff71d6aSMatt Porter 
4617ff71d6aSMatt Porter /* PCI driver selection metadata; PCI hotplugging uses this */
4627ff71d6aSMatt Porter static const struct pci_device_id pci_ids [] = { {
4637ff71d6aSMatt Porter 	/* handle any USB 2.0 EHCI controller */
464c67808eeSJean Delvare 	PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
4657ff71d6aSMatt Porter 	.driver_data =	(unsigned long) &ehci_pci_hc_driver,
4663a0bac06SAlessandro Rubini 	}, {
4673a0bac06SAlessandro Rubini 	PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_HOST),
4683a0bac06SAlessandro Rubini 	.driver_data = (unsigned long) &ehci_pci_hc_driver,
4697ff71d6aSMatt Porter 	},
4707ff71d6aSMatt Porter 	{ /* end: all zeroes */ }
4717ff71d6aSMatt Porter };
4727ff71d6aSMatt Porter MODULE_DEVICE_TABLE(pci, pci_ids);
4737ff71d6aSMatt Porter 
4747ff71d6aSMatt Porter /* pci driver glue; this is a "new style" PCI driver module */
4757ff71d6aSMatt Porter static struct pci_driver ehci_pci_driver = {
4767ff71d6aSMatt Porter 	.name =		(char *) hcd_name,
4777ff71d6aSMatt Porter 	.id_table =	pci_ids,
4787ff71d6aSMatt Porter 
4797ff71d6aSMatt Porter 	.probe =	usb_hcd_pci_probe,
4807ff71d6aSMatt Porter 	.remove =	usb_hcd_pci_remove,
48164a21d02SAleksey Gorelov 	.shutdown = 	usb_hcd_pci_shutdown,
482abb30641SAlan Stern 
483abb30641SAlan Stern #ifdef CONFIG_PM_SLEEP
484abb30641SAlan Stern 	.driver =	{
485abb30641SAlan Stern 		.pm =	&usb_hcd_pci_pm_ops
486abb30641SAlan Stern 	},
487abb30641SAlan Stern #endif
4887ff71d6aSMatt Porter };
489