xref: /linux/drivers/usb/host/ehci-pci.c (revision abb306416a7ec2386678de0da6b632a6cb068af0)
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 
257ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
267ff71d6aSMatt Porter 
2718807521SDavid Brownell /* called after powerup, by probe or system-pm "wakeup" */
2818807521SDavid Brownell static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
2918807521SDavid Brownell {
3018807521SDavid Brownell 	u32			temp;
3118807521SDavid Brownell 	int			retval;
3218807521SDavid Brownell 
3318807521SDavid Brownell 	/* optional debug port, normally in the first BAR */
3418807521SDavid Brownell 	temp = pci_find_capability(pdev, 0x0a);
3518807521SDavid Brownell 	if (temp) {
3618807521SDavid Brownell 		pci_read_config_dword(pdev, temp, &temp);
3718807521SDavid Brownell 		temp >>= 16;
3818807521SDavid Brownell 		if ((temp & (3 << 13)) == (1 << 13)) {
3918807521SDavid Brownell 			temp &= 0x1fff;
4018807521SDavid Brownell 			ehci->debug = ehci_to_hcd(ehci)->regs + temp;
41083522d7SBenjamin Herrenschmidt 			temp = ehci_readl(ehci, &ehci->debug->control);
4218807521SDavid Brownell 			ehci_info(ehci, "debug port %d%s\n",
4318807521SDavid Brownell 				HCS_DEBUG_PORT(ehci->hcs_params),
4418807521SDavid Brownell 				(temp & DBGP_ENABLED)
4518807521SDavid Brownell 					? " IN USE"
4618807521SDavid Brownell 					: "");
4718807521SDavid Brownell 			if (!(temp & DBGP_ENABLED))
4818807521SDavid Brownell 				ehci->debug = NULL;
4918807521SDavid Brownell 		}
5018807521SDavid Brownell 	}
5118807521SDavid Brownell 
52401feafaSDavid Brownell 	/* we expect static quirk code to handle the "extended capabilities"
53401feafaSDavid Brownell 	 * (currently just BIOS handoff) allowed starting with EHCI 0.96
54401feafaSDavid Brownell 	 */
5518807521SDavid Brownell 
5618807521SDavid Brownell 	/* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
5718807521SDavid Brownell 	retval = pci_set_mwi(pdev);
5818807521SDavid Brownell 	if (!retval)
5918807521SDavid Brownell 		ehci_dbg(ehci, "MWI active\n");
6018807521SDavid Brownell 
6118807521SDavid Brownell 	return 0;
6218807521SDavid Brownell }
6318807521SDavid Brownell 
648926bfa7SDavid Brownell /* called during probe() after chip reset completes */
658926bfa7SDavid Brownell static int ehci_pci_setup(struct usb_hcd *hcd)
667ff71d6aSMatt Porter {
677ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
68abcc9448SDavid Brownell 	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
69b09bc6cbSAndiry Xu 	struct pci_dev		*p_smbus;
70b09bc6cbSAndiry Xu 	u8			rev;
717ff71d6aSMatt Porter 	u32			temp;
7218807521SDavid Brownell 	int			retval;
737ff71d6aSMatt Porter 
74083522d7SBenjamin Herrenschmidt 	switch (pdev->vendor) {
75083522d7SBenjamin Herrenschmidt 	case PCI_VENDOR_ID_TOSHIBA_2:
76083522d7SBenjamin Herrenschmidt 		/* celleb's companion chip */
77083522d7SBenjamin Herrenschmidt 		if (pdev->device == 0x01b5) {
78083522d7SBenjamin Herrenschmidt #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
79083522d7SBenjamin Herrenschmidt 			ehci->big_endian_mmio = 1;
80083522d7SBenjamin Herrenschmidt #else
81083522d7SBenjamin Herrenschmidt 			ehci_warn(ehci,
82083522d7SBenjamin Herrenschmidt 				  "unsupported big endian Toshiba quirk\n");
83083522d7SBenjamin Herrenschmidt #endif
84083522d7SBenjamin Herrenschmidt 		}
85083522d7SBenjamin Herrenschmidt 		break;
86083522d7SBenjamin Herrenschmidt 	}
87083522d7SBenjamin Herrenschmidt 
887ff71d6aSMatt Porter 	ehci->caps = hcd->regs;
89083522d7SBenjamin Herrenschmidt 	ehci->regs = hcd->regs +
90083522d7SBenjamin Herrenschmidt 		HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
91083522d7SBenjamin Herrenschmidt 
927ff71d6aSMatt Porter 	dbg_hcs_params(ehci, "reset");
937ff71d6aSMatt Porter 	dbg_hcc_params(ehci, "reset");
947ff71d6aSMatt Porter 
95c32ba30fSPaul Serice         /* ehci_init() causes memory for DMA transfers to be
96c32ba30fSPaul Serice          * allocated.  Thus, any vendor-specific workarounds based on
97c32ba30fSPaul Serice          * limiting the type of memory used for DMA transfers must
98c32ba30fSPaul Serice          * happen before ehci_init() is called. */
99c32ba30fSPaul Serice 	switch (pdev->vendor) {
100c32ba30fSPaul Serice 	case PCI_VENDOR_ID_NVIDIA:
101c32ba30fSPaul Serice 		/* NVidia reports that certain chips don't handle
102c32ba30fSPaul Serice 		 * QH, ITD, or SITD addresses above 2GB.  (But TD,
103c32ba30fSPaul Serice 		 * data buffer, and periodic schedule are normal.)
104c32ba30fSPaul Serice 		 */
105c32ba30fSPaul Serice 		switch (pdev->device) {
106c32ba30fSPaul Serice 		case 0x003c:	/* MCP04 */
107c32ba30fSPaul Serice 		case 0x005b:	/* CK804 */
108c32ba30fSPaul Serice 		case 0x00d8:	/* CK8 */
109c32ba30fSPaul Serice 		case 0x00e8:	/* CK8S */
110c32ba30fSPaul Serice 			if (pci_set_consistent_dma_mask(pdev,
111929a22a5SYang Hongyang 						DMA_BIT_MASK(31)) < 0)
112c32ba30fSPaul Serice 				ehci_warn(ehci, "can't enable NVidia "
113c32ba30fSPaul Serice 					"workaround for >2GB RAM\n");
114c32ba30fSPaul Serice 			break;
115c32ba30fSPaul Serice 		}
116c32ba30fSPaul Serice 		break;
117c32ba30fSPaul Serice 	}
118c32ba30fSPaul Serice 
1197ff71d6aSMatt Porter 	/* cache this readonly data; minimize chip reads */
120083522d7SBenjamin Herrenschmidt 	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
1217ff71d6aSMatt Porter 
12218807521SDavid Brownell 	retval = ehci_halt(ehci);
12318807521SDavid Brownell 	if (retval)
12418807521SDavid Brownell 		return retval;
12518807521SDavid Brownell 
1268926bfa7SDavid Brownell 	/* data structure init */
1278926bfa7SDavid Brownell 	retval = ehci_init(hcd);
1288926bfa7SDavid Brownell 	if (retval)
1298926bfa7SDavid Brownell 		return retval;
1308926bfa7SDavid Brownell 
1317ff71d6aSMatt Porter 	switch (pdev->vendor) {
1327ff71d6aSMatt Porter 	case PCI_VENDOR_ID_TDI:
1337ff71d6aSMatt Porter 		if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
1347329e211SAlan Stern 			hcd->has_tt = 1;
1357ff71d6aSMatt Porter 			tdi_reset(ehci);
1367ff71d6aSMatt Porter 		}
1377ff71d6aSMatt Porter 		break;
1387ff71d6aSMatt Porter 	case PCI_VENDOR_ID_AMD:
1397ff71d6aSMatt Porter 		/* AMD8111 EHCI doesn't work, according to AMD errata */
1407ff71d6aSMatt Porter 		if (pdev->device == 0x7463) {
1417ff71d6aSMatt Porter 			ehci_info(ehci, "ignoring AMD8111 (errata)\n");
1428926bfa7SDavid Brownell 			retval = -EIO;
1438926bfa7SDavid Brownell 			goto done;
1447ff71d6aSMatt Porter 		}
1457ff71d6aSMatt Porter 		break;
1467ff71d6aSMatt Porter 	case PCI_VENDOR_ID_NVIDIA:
147f8aeb3bbSDavid Brownell 		switch (pdev->device) {
148f8aeb3bbSDavid Brownell 		/* Some NForce2 chips have problems with selective suspend;
149f8aeb3bbSDavid Brownell 		 * fixed in newer silicon.
150f8aeb3bbSDavid Brownell 		 */
151f8aeb3bbSDavid Brownell 		case 0x0068:
15244c10138SAuke Kok 			if (pdev->revision < 0xa4)
153f8aeb3bbSDavid Brownell 				ehci->no_selective_suspend = 1;
154f8aeb3bbSDavid Brownell 			break;
1557ff71d6aSMatt Porter 		}
1567ff71d6aSMatt Porter 		break;
157055b93c9SRene Herman 	case PCI_VENDOR_ID_VIA:
158055b93c9SRene Herman 		if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) {
159055b93c9SRene Herman 			u8 tmp;
160055b93c9SRene Herman 
161055b93c9SRene Herman 			/* The VT6212 defaults to a 1 usec EHCI sleep time which
162055b93c9SRene Herman 			 * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes
163055b93c9SRene Herman 			 * that sleep time use the conventional 10 usec.
164055b93c9SRene Herman 			 */
165055b93c9SRene Herman 			pci_read_config_byte(pdev, 0x4b, &tmp);
166055b93c9SRene Herman 			if (tmp & 0x20)
167055b93c9SRene Herman 				break;
168055b93c9SRene Herman 			pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
169055b93c9SRene Herman 		}
170055b93c9SRene Herman 		break;
171b09bc6cbSAndiry Xu 	case PCI_VENDOR_ID_ATI:
1720a99e8acSShane Huang 		/* SB600 and old version of SB700 have a bug in EHCI controller,
173b09bc6cbSAndiry Xu 		 * which causes usb devices lose response in some cases.
174b09bc6cbSAndiry Xu 		 */
1750a99e8acSShane Huang 		if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) {
176b09bc6cbSAndiry Xu 			p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
177b09bc6cbSAndiry Xu 						 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
178b09bc6cbSAndiry Xu 						 NULL);
179b09bc6cbSAndiry Xu 			if (!p_smbus)
180b09bc6cbSAndiry Xu 				break;
181b09bc6cbSAndiry Xu 			rev = p_smbus->revision;
1820a99e8acSShane Huang 			if ((pdev->device == 0x4386) || (rev == 0x3a)
1830a99e8acSShane Huang 			    || (rev == 0x3b)) {
184b09bc6cbSAndiry Xu 				u8 tmp;
1850a99e8acSShane Huang 				ehci_info(ehci, "applying AMD SB600/SB700 USB "
1860a99e8acSShane Huang 					"freeze workaround\n");
187b09bc6cbSAndiry Xu 				pci_read_config_byte(pdev, 0x53, &tmp);
188b09bc6cbSAndiry Xu 				pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
189b09bc6cbSAndiry Xu 			}
190b09bc6cbSAndiry Xu 			pci_dev_put(p_smbus);
191b09bc6cbSAndiry Xu 		}
192b09bc6cbSAndiry Xu 		break;
1937ff71d6aSMatt Porter 	}
1947ff71d6aSMatt Porter 
1957ff71d6aSMatt Porter 	ehci_reset(ehci);
1967ff71d6aSMatt Porter 
1977ff71d6aSMatt Porter 	/* at least the Genesys GL880S needs fixup here */
1987ff71d6aSMatt Porter 	temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
1997ff71d6aSMatt Porter 	temp &= 0x0f;
2007ff71d6aSMatt Porter 	if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
2017ff71d6aSMatt Porter 		ehci_dbg(ehci, "bogus port configuration: "
2027ff71d6aSMatt Porter 			"cc=%d x pcc=%d < ports=%d\n",
2037ff71d6aSMatt Porter 			HCS_N_CC(ehci->hcs_params),
2047ff71d6aSMatt Porter 			HCS_N_PCC(ehci->hcs_params),
2057ff71d6aSMatt Porter 			HCS_N_PORTS(ehci->hcs_params));
2067ff71d6aSMatt Porter 
2077ff71d6aSMatt Porter 		switch (pdev->vendor) {
2087ff71d6aSMatt Porter 		case 0x17a0:		/* GENESYS */
2097ff71d6aSMatt Porter 			/* GL880S: should be PORTS=2 */
2107ff71d6aSMatt Porter 			temp |= (ehci->hcs_params & ~0xf);
2117ff71d6aSMatt Porter 			ehci->hcs_params = temp;
2127ff71d6aSMatt Porter 			break;
2137ff71d6aSMatt Porter 		case PCI_VENDOR_ID_NVIDIA:
2147ff71d6aSMatt Porter 			/* NF4: should be PCC=10 */
2157ff71d6aSMatt Porter 			break;
2167ff71d6aSMatt Porter 		}
2177ff71d6aSMatt Porter 	}
2187ff71d6aSMatt Porter 
2197ff71d6aSMatt Porter 	/* Serial Bus Release Number is at PCI 0x60 offset */
2207ff71d6aSMatt Porter 	pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
2217ff71d6aSMatt Porter 
2226fd9086aSAlan Stern 	/* Keep this around for a while just in case some EHCI
2236fd9086aSAlan Stern 	 * implementation uses legacy PCI PM support.  This test
2246fd9086aSAlan Stern 	 * can be removed on 17 Dec 2009 if the dev_warn() hasn't
2256fd9086aSAlan Stern 	 * been triggered by then.
2262c1c3c4cSDavid Brownell 	 */
2272c1c3c4cSDavid Brownell 	if (!device_can_wakeup(&pdev->dev)) {
2282c1c3c4cSDavid Brownell 		u16	port_wake;
2292c1c3c4cSDavid Brownell 
2302c1c3c4cSDavid Brownell 		pci_read_config_word(pdev, 0x62, &port_wake);
2316fd9086aSAlan Stern 		if (port_wake & 0x0001) {
2326fd9086aSAlan Stern 			dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
233bcca06efSAlan Stern 			device_set_wakeup_capable(&pdev->dev, 1);
2342c1c3c4cSDavid Brownell 		}
2356fd9086aSAlan Stern 	}
2367ff71d6aSMatt Porter 
237f8aeb3bbSDavid Brownell #ifdef	CONFIG_USB_SUSPEND
238f8aeb3bbSDavid Brownell 	/* REVISIT: the controller works fine for wakeup iff the root hub
239f8aeb3bbSDavid Brownell 	 * itself is "globally" suspended, but usbcore currently doesn't
240f8aeb3bbSDavid Brownell 	 * understand such things.
241f8aeb3bbSDavid Brownell 	 *
242f8aeb3bbSDavid Brownell 	 * System suspend currently expects to be able to suspend the entire
243f8aeb3bbSDavid Brownell 	 * device tree, device-at-a-time.  If we failed selective suspend
244f8aeb3bbSDavid Brownell 	 * reports, system suspend would fail; so the root hub code must claim
245f8aeb3bbSDavid Brownell 	 * success.  That's lying to usbcore, and it matters for for runtime
246f8aeb3bbSDavid Brownell 	 * PM scenarios with selective suspend and remote wakeup...
247f8aeb3bbSDavid Brownell 	 */
248f8aeb3bbSDavid Brownell 	if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
249f8aeb3bbSDavid Brownell 		ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
250f8aeb3bbSDavid Brownell #endif
251f8aeb3bbSDavid Brownell 
252aff6d18fSAlan Stern 	ehci_port_power(ehci, 1);
25318807521SDavid Brownell 	retval = ehci_pci_reinit(ehci, pdev);
2548926bfa7SDavid Brownell done:
2558926bfa7SDavid Brownell 	return retval;
2567ff71d6aSMatt Porter }
2577ff71d6aSMatt Porter 
2587ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
2597ff71d6aSMatt Porter 
2607ff71d6aSMatt Porter #ifdef	CONFIG_PM
2617ff71d6aSMatt Porter 
2627ff71d6aSMatt Porter /* suspend/resume, section 4.3 */
2637ff71d6aSMatt Porter 
264f03c17fcSDavid Brownell /* These routines rely on the PCI bus glue
2657ff71d6aSMatt Porter  * to handle powerdown and wakeup, and currently also on
2667ff71d6aSMatt Porter  * transceivers that don't need any software attention to set up
2677ff71d6aSMatt Porter  * the right sort of wakeup.
268f03c17fcSDavid Brownell  * Also they depend on separate root hub suspend/resume.
2697ff71d6aSMatt Porter  */
2707ff71d6aSMatt Porter 
2717ff71d6aSMatt Porter static int ehci_pci_suspend(struct usb_hcd *hcd, pm_message_t message)
2727ff71d6aSMatt Porter {
2737ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
2748de98402SBenjamin Herrenschmidt 	unsigned long		flags;
2758de98402SBenjamin Herrenschmidt 	int			rc = 0;
2767ff71d6aSMatt Porter 
2777ff71d6aSMatt Porter 	if (time_before(jiffies, ehci->next_statechange))
278f03c17fcSDavid Brownell 		msleep(10);
2797ff71d6aSMatt Porter 
2808de98402SBenjamin Herrenschmidt 	/* Root hub was already suspended. Disable irq emission and
2818de98402SBenjamin Herrenschmidt 	 * mark HW unaccessible, bail out if RH has been resumed. Use
2828de98402SBenjamin Herrenschmidt 	 * the spinlock to properly synchronize with possible pending
2838de98402SBenjamin Herrenschmidt 	 * RH suspend or resume activity.
2848de98402SBenjamin Herrenschmidt 	 *
2858de98402SBenjamin Herrenschmidt 	 * This is still racy as hcd->state is manipulated outside of
2868de98402SBenjamin Herrenschmidt 	 * any locks =P But that will be a different fix.
2878de98402SBenjamin Herrenschmidt 	 */
2888de98402SBenjamin Herrenschmidt 	spin_lock_irqsave (&ehci->lock, flags);
2898de98402SBenjamin Herrenschmidt 	if (hcd->state != HC_STATE_SUSPENDED) {
2908de98402SBenjamin Herrenschmidt 		rc = -EINVAL;
2918de98402SBenjamin Herrenschmidt 		goto bail;
2928de98402SBenjamin Herrenschmidt 	}
293083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, 0, &ehci->regs->intr_enable);
294083522d7SBenjamin Herrenschmidt 	(void)ehci_readl(ehci, &ehci->regs->intr_enable);
2958de98402SBenjamin Herrenschmidt 
29618584999SDavid Brownell 	/* make sure snapshot being resumed re-enumerates everything */
29718584999SDavid Brownell 	if (message.event == PM_EVENT_PRETHAW) {
29818584999SDavid Brownell 		ehci_halt(ehci);
29918584999SDavid Brownell 		ehci_reset(ehci);
30018584999SDavid Brownell 	}
30118584999SDavid Brownell 
3028de98402SBenjamin Herrenschmidt 	clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
3038de98402SBenjamin Herrenschmidt  bail:
3048de98402SBenjamin Herrenschmidt 	spin_unlock_irqrestore (&ehci->lock, flags);
3058de98402SBenjamin Herrenschmidt 
306f03c17fcSDavid Brownell 	// could save FLADJ in case of Vaux power loss
3077ff71d6aSMatt Porter 	// ... we'd only use it to handle clock skew
3087ff71d6aSMatt Porter 
3098de98402SBenjamin Herrenschmidt 	return rc;
3107ff71d6aSMatt Porter }
3117ff71d6aSMatt Porter 
3127ff71d6aSMatt Porter static int ehci_pci_resume(struct usb_hcd *hcd)
3137ff71d6aSMatt Porter {
3147ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
31518807521SDavid Brownell 	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
3167ff71d6aSMatt Porter 
317f03c17fcSDavid Brownell 	// maybe restore FLADJ
3187ff71d6aSMatt Porter 
3197ff71d6aSMatt Porter 	if (time_before(jiffies, ehci->next_statechange))
3207ff71d6aSMatt Porter 		msleep(100);
3217ff71d6aSMatt Porter 
3228de98402SBenjamin Herrenschmidt 	/* Mark hardware accessible again as we are out of D3 state by now */
3238de98402SBenjamin Herrenschmidt 	set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
3248de98402SBenjamin Herrenschmidt 
3258c03356aSAlan Stern 	/* If CF is still set, we maintained PCI Vaux power.
3268c03356aSAlan Stern 	 * Just undo the effect of ehci_pci_suspend().
3277ff71d6aSMatt Porter 	 */
328083522d7SBenjamin Herrenschmidt 	if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
3298c03356aSAlan Stern 		int	mask = INTR_MASK;
3308c03356aSAlan Stern 
33158a97ffeSAlan Stern 		if (!hcd->self.root_hub->do_remote_wakeup)
3328c03356aSAlan Stern 			mask &= ~STS_PCD;
333083522d7SBenjamin Herrenschmidt 		ehci_writel(ehci, mask, &ehci->regs->intr_enable);
334083522d7SBenjamin Herrenschmidt 		ehci_readl(ehci, &ehci->regs->intr_enable);
335f03c17fcSDavid Brownell 		return 0;
3367ff71d6aSMatt Porter 	}
337f03c17fcSDavid Brownell 
338f03c17fcSDavid Brownell 	ehci_dbg(ehci, "lost power, restarting\n");
3391c50c317SAlan Stern 	usb_root_hub_lost_power(hcd->self.root_hub);
3407ff71d6aSMatt Porter 
3417ff71d6aSMatt Porter 	/* Else reset, to cope with power loss or flush-to-storage
342f03c17fcSDavid Brownell 	 * style "resume" having let BIOS kick in during reboot.
3437ff71d6aSMatt Porter 	 */
3447ff71d6aSMatt Porter 	(void) ehci_halt(ehci);
3457ff71d6aSMatt Porter 	(void) ehci_reset(ehci);
34618807521SDavid Brownell 	(void) ehci_pci_reinit(ehci, pdev);
3477ff71d6aSMatt Porter 
3487ff71d6aSMatt Porter 	/* emptying the schedule aborts any urbs */
3497ff71d6aSMatt Porter 	spin_lock_irq(&ehci->lock);
3507ff71d6aSMatt Porter 	if (ehci->reclaim)
35107d29b63SAlan Stern 		end_unlink_async(ehci);
3527d12e780SDavid Howells 	ehci_work(ehci);
3537ff71d6aSMatt Porter 	spin_unlock_irq(&ehci->lock);
3547ff71d6aSMatt Porter 
355083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, ehci->command, &ehci->regs->command);
356083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
357083522d7SBenjamin Herrenschmidt 	ehci_readl(ehci, &ehci->regs->command);	/* unblock posted writes */
3588c03356aSAlan Stern 
359383975d7SAlan Stern 	/* here we "know" root ports should always stay powered */
360383975d7SAlan Stern 	ehci_port_power(ehci, 1);
361383975d7SAlan Stern 
3628c03356aSAlan Stern 	hcd->state = HC_STATE_SUSPENDED;
3638c03356aSAlan Stern 	return 0;
3647ff71d6aSMatt Porter }
3657ff71d6aSMatt Porter #endif
3667ff71d6aSMatt Porter 
3677ff71d6aSMatt Porter static const struct hc_driver ehci_pci_hc_driver = {
3687ff71d6aSMatt Porter 	.description =		hcd_name,
3697ff71d6aSMatt Porter 	.product_desc =		"EHCI Host Controller",
3707ff71d6aSMatt Porter 	.hcd_priv_size =	sizeof(struct ehci_hcd),
3717ff71d6aSMatt Porter 
3727ff71d6aSMatt Porter 	/*
3737ff71d6aSMatt Porter 	 * generic hardware linkage
3747ff71d6aSMatt Porter 	 */
3757ff71d6aSMatt Porter 	.irq =			ehci_irq,
3767ff71d6aSMatt Porter 	.flags =		HCD_MEMORY | HCD_USB2,
3777ff71d6aSMatt Porter 
3787ff71d6aSMatt Porter 	/*
3797ff71d6aSMatt Porter 	 * basic lifecycle operations
3807ff71d6aSMatt Porter 	 */
3818926bfa7SDavid Brownell 	.reset =		ehci_pci_setup,
38218807521SDavid Brownell 	.start =		ehci_run,
3837ff71d6aSMatt Porter #ifdef	CONFIG_PM
3847be7d741SAlan Stern 	.pci_suspend =		ehci_pci_suspend,
3857be7d741SAlan Stern 	.pci_resume =		ehci_pci_resume,
3867ff71d6aSMatt Porter #endif
38718807521SDavid Brownell 	.stop =			ehci_stop,
38864a21d02SAleksey Gorelov 	.shutdown =		ehci_shutdown,
3897ff71d6aSMatt Porter 
3907ff71d6aSMatt Porter 	/*
3917ff71d6aSMatt Porter 	 * managing i/o requests and associated device resources
3927ff71d6aSMatt Porter 	 */
3937ff71d6aSMatt Porter 	.urb_enqueue =		ehci_urb_enqueue,
3947ff71d6aSMatt Porter 	.urb_dequeue =		ehci_urb_dequeue,
3957ff71d6aSMatt Porter 	.endpoint_disable =	ehci_endpoint_disable,
3967ff71d6aSMatt Porter 
3977ff71d6aSMatt Porter 	/*
3987ff71d6aSMatt Porter 	 * scheduling support
3997ff71d6aSMatt Porter 	 */
4007ff71d6aSMatt Porter 	.get_frame_number =	ehci_get_frame,
4017ff71d6aSMatt Porter 
4027ff71d6aSMatt Porter 	/*
4037ff71d6aSMatt Porter 	 * root hub support
4047ff71d6aSMatt Porter 	 */
4057ff71d6aSMatt Porter 	.hub_status_data =	ehci_hub_status_data,
4067ff71d6aSMatt Porter 	.hub_control =		ehci_hub_control,
4070c0382e3SAlan Stern 	.bus_suspend =		ehci_bus_suspend,
4080c0382e3SAlan Stern 	.bus_resume =		ehci_bus_resume,
40990da096eSBalaji Rao 	.relinquish_port =	ehci_relinquish_port,
4103a31155cSAlan Stern 	.port_handed_over =	ehci_port_handed_over,
4117ff71d6aSMatt Porter };
4127ff71d6aSMatt Porter 
4137ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
4147ff71d6aSMatt Porter 
4157ff71d6aSMatt Porter /* PCI driver selection metadata; PCI hotplugging uses this */
4167ff71d6aSMatt Porter static const struct pci_device_id pci_ids [] = { {
4177ff71d6aSMatt Porter 	/* handle any USB 2.0 EHCI controller */
418c67808eeSJean Delvare 	PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
4197ff71d6aSMatt Porter 	.driver_data =	(unsigned long) &ehci_pci_hc_driver,
4207ff71d6aSMatt Porter 	},
4217ff71d6aSMatt Porter 	{ /* end: all zeroes */ }
4227ff71d6aSMatt Porter };
4237ff71d6aSMatt Porter MODULE_DEVICE_TABLE(pci, pci_ids);
4247ff71d6aSMatt Porter 
4257ff71d6aSMatt Porter /* pci driver glue; this is a "new style" PCI driver module */
4267ff71d6aSMatt Porter static struct pci_driver ehci_pci_driver = {
4277ff71d6aSMatt Porter 	.name =		(char *) hcd_name,
4287ff71d6aSMatt Porter 	.id_table =	pci_ids,
4297ff71d6aSMatt Porter 
4307ff71d6aSMatt Porter 	.probe =	usb_hcd_pci_probe,
4317ff71d6aSMatt Porter 	.remove =	usb_hcd_pci_remove,
43264a21d02SAleksey Gorelov 	.shutdown = 	usb_hcd_pci_shutdown,
433*abb30641SAlan Stern 
434*abb30641SAlan Stern #ifdef CONFIG_PM_SLEEP
435*abb30641SAlan Stern 	.driver =	{
436*abb30641SAlan Stern 		.pm =	&usb_hcd_pci_pm_ops
437*abb30641SAlan Stern 	},
438*abb30641SAlan Stern #endif
4397ff71d6aSMatt Porter };
440