xref: /linux/drivers/usb/host/ehci-pci.c (revision 4f6838436915fdc281173bfd5bef6d8ab5cb1a7f)
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 
25*4f683843SDirk Brandewie /* defined here to avoid adding to pci_ids.h for single instance use */
26*4f683843SDirk Brandewie #define PCI_DEVICE_ID_INTEL_CE4100_USB	0x2e70
27*4f683843SDirk 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 +
73083522d7SBenjamin Herrenschmidt 		HC_LENGTH(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 
1098926bfa7SDavid Brownell 	/* data structure init */
1108926bfa7SDavid Brownell 	retval = ehci_init(hcd);
1118926bfa7SDavid Brownell 	if (retval)
1128926bfa7SDavid Brownell 		return retval;
1138926bfa7SDavid Brownell 
1147ff71d6aSMatt Porter 	switch (pdev->vendor) {
1153681d8f3SDavid Miller 	case PCI_VENDOR_ID_NEC:
1163681d8f3SDavid Miller 		ehci->need_io_watchdog = 0;
1173681d8f3SDavid Miller 		break;
118403dbd36SAlek Du 	case PCI_VENDOR_ID_INTEL:
119403dbd36SAlek Du 		ehci->need_io_watchdog = 0;
120ae68a83bSAlan Stern 		ehci->fs_i_thresh = 1;
121ee4ecb8aSOliver Neukum 		if (pdev->device == 0x27cc) {
122ee4ecb8aSOliver Neukum 			ehci->broken_periodic = 1;
123ee4ecb8aSOliver Neukum 			ehci_info(ehci, "using broken periodic workaround\n");
124ee4ecb8aSOliver Neukum 		}
125fc928250SAlek Du 		if (pdev->device == 0x0806 || pdev->device == 0x0811
126fc928250SAlek Du 				|| pdev->device == 0x0829) {
127fc928250SAlek Du 			ehci_info(ehci, "disable lpm for langwell/penwell\n");
128fc928250SAlek Du 			ehci->has_lpm = 0;
129fc928250SAlek Du 		}
130*4f683843SDirk Brandewie 		if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB) {
131*4f683843SDirk Brandewie 			hcd->has_tt = 1;
132*4f683843SDirk Brandewie 			tdi_reset(ehci);
133*4f683843SDirk Brandewie 		}
134403dbd36SAlek Du 		break;
1357ff71d6aSMatt Porter 	case PCI_VENDOR_ID_TDI:
1367ff71d6aSMatt Porter 		if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
1377329e211SAlan Stern 			hcd->has_tt = 1;
1387ff71d6aSMatt Porter 			tdi_reset(ehci);
1397ff71d6aSMatt Porter 		}
1407ff71d6aSMatt Porter 		break;
1417ff71d6aSMatt Porter 	case PCI_VENDOR_ID_AMD:
1427ff71d6aSMatt Porter 		/* AMD8111 EHCI doesn't work, according to AMD errata */
1437ff71d6aSMatt Porter 		if (pdev->device == 0x7463) {
1447ff71d6aSMatt Porter 			ehci_info(ehci, "ignoring AMD8111 (errata)\n");
1458926bfa7SDavid Brownell 			retval = -EIO;
1468926bfa7SDavid Brownell 			goto done;
1477ff71d6aSMatt Porter 		}
1487ff71d6aSMatt Porter 		break;
1497ff71d6aSMatt Porter 	case PCI_VENDOR_ID_NVIDIA:
150f8aeb3bbSDavid Brownell 		switch (pdev->device) {
151f8aeb3bbSDavid Brownell 		/* Some NForce2 chips have problems with selective suspend;
152f8aeb3bbSDavid Brownell 		 * fixed in newer silicon.
153f8aeb3bbSDavid Brownell 		 */
154f8aeb3bbSDavid Brownell 		case 0x0068:
15544c10138SAuke Kok 			if (pdev->revision < 0xa4)
156f8aeb3bbSDavid Brownell 				ehci->no_selective_suspend = 1;
157f8aeb3bbSDavid Brownell 			break;
1587ff71d6aSMatt Porter 		}
1597ff71d6aSMatt Porter 		break;
160055b93c9SRene Herman 	case PCI_VENDOR_ID_VIA:
161055b93c9SRene Herman 		if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) {
162055b93c9SRene Herman 			u8 tmp;
163055b93c9SRene Herman 
164055b93c9SRene Herman 			/* The VT6212 defaults to a 1 usec EHCI sleep time which
165055b93c9SRene Herman 			 * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes
166055b93c9SRene Herman 			 * that sleep time use the conventional 10 usec.
167055b93c9SRene Herman 			 */
168055b93c9SRene Herman 			pci_read_config_byte(pdev, 0x4b, &tmp);
169055b93c9SRene Herman 			if (tmp & 0x20)
170055b93c9SRene Herman 				break;
171055b93c9SRene Herman 			pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
172055b93c9SRene Herman 		}
173055b93c9SRene Herman 		break;
174b09bc6cbSAndiry Xu 	case PCI_VENDOR_ID_ATI:
1750a99e8acSShane Huang 		/* SB600 and old version of SB700 have a bug in EHCI controller,
176b09bc6cbSAndiry Xu 		 * which causes usb devices lose response in some cases.
177b09bc6cbSAndiry Xu 		 */
1780a99e8acSShane Huang 		if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) {
179b09bc6cbSAndiry Xu 			p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
180b09bc6cbSAndiry Xu 						 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
181b09bc6cbSAndiry Xu 						 NULL);
182b09bc6cbSAndiry Xu 			if (!p_smbus)
183b09bc6cbSAndiry Xu 				break;
184b09bc6cbSAndiry Xu 			rev = p_smbus->revision;
1850a99e8acSShane Huang 			if ((pdev->device == 0x4386) || (rev == 0x3a)
1860a99e8acSShane Huang 			    || (rev == 0x3b)) {
187b09bc6cbSAndiry Xu 				u8 tmp;
1880a99e8acSShane Huang 				ehci_info(ehci, "applying AMD SB600/SB700 USB "
1890a99e8acSShane Huang 					"freeze workaround\n");
190b09bc6cbSAndiry Xu 				pci_read_config_byte(pdev, 0x53, &tmp);
191b09bc6cbSAndiry Xu 				pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
192b09bc6cbSAndiry Xu 			}
193b09bc6cbSAndiry Xu 			pci_dev_put(p_smbus);
194b09bc6cbSAndiry Xu 		}
195b09bc6cbSAndiry Xu 		break;
1967ff71d6aSMatt Porter 	}
1977ff71d6aSMatt Porter 
1988d053c79SJason Wessel 	/* optional debug port, normally in the first BAR */
1998d053c79SJason Wessel 	temp = pci_find_capability(pdev, 0x0a);
2008d053c79SJason Wessel 	if (temp) {
2018d053c79SJason Wessel 		pci_read_config_dword(pdev, temp, &temp);
2028d053c79SJason Wessel 		temp >>= 16;
2038d053c79SJason Wessel 		if ((temp & (3 << 13)) == (1 << 13)) {
2048d053c79SJason Wessel 			temp &= 0x1fff;
2058d053c79SJason Wessel 			ehci->debug = ehci_to_hcd(ehci)->regs + temp;
2068d053c79SJason Wessel 			temp = ehci_readl(ehci, &ehci->debug->control);
2078d053c79SJason Wessel 			ehci_info(ehci, "debug port %d%s\n",
2088d053c79SJason Wessel 				HCS_DEBUG_PORT(ehci->hcs_params),
2098d053c79SJason Wessel 				(temp & DBGP_ENABLED)
2108d053c79SJason Wessel 					? " IN USE"
2118d053c79SJason Wessel 					: "");
2128d053c79SJason Wessel 			if (!(temp & DBGP_ENABLED))
2138d053c79SJason Wessel 				ehci->debug = NULL;
2148d053c79SJason Wessel 		}
2158d053c79SJason Wessel 	}
2168d053c79SJason Wessel 
2177ff71d6aSMatt Porter 	ehci_reset(ehci);
2187ff71d6aSMatt Porter 
2197ff71d6aSMatt Porter 	/* at least the Genesys GL880S needs fixup here */
2207ff71d6aSMatt Porter 	temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
2217ff71d6aSMatt Porter 	temp &= 0x0f;
2227ff71d6aSMatt Porter 	if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
2237ff71d6aSMatt Porter 		ehci_dbg(ehci, "bogus port configuration: "
2247ff71d6aSMatt Porter 			"cc=%d x pcc=%d < ports=%d\n",
2257ff71d6aSMatt Porter 			HCS_N_CC(ehci->hcs_params),
2267ff71d6aSMatt Porter 			HCS_N_PCC(ehci->hcs_params),
2277ff71d6aSMatt Porter 			HCS_N_PORTS(ehci->hcs_params));
2287ff71d6aSMatt Porter 
2297ff71d6aSMatt Porter 		switch (pdev->vendor) {
2307ff71d6aSMatt Porter 		case 0x17a0:		/* GENESYS */
2317ff71d6aSMatt Porter 			/* GL880S: should be PORTS=2 */
2327ff71d6aSMatt Porter 			temp |= (ehci->hcs_params & ~0xf);
2337ff71d6aSMatt Porter 			ehci->hcs_params = temp;
2347ff71d6aSMatt Porter 			break;
2357ff71d6aSMatt Porter 		case PCI_VENDOR_ID_NVIDIA:
2367ff71d6aSMatt Porter 			/* NF4: should be PCC=10 */
2377ff71d6aSMatt Porter 			break;
2387ff71d6aSMatt Porter 		}
2397ff71d6aSMatt Porter 	}
2407ff71d6aSMatt Porter 
2417ff71d6aSMatt Porter 	/* Serial Bus Release Number is at PCI 0x60 offset */
2427ff71d6aSMatt Porter 	pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
2437ff71d6aSMatt Porter 
2446fd9086aSAlan Stern 	/* Keep this around for a while just in case some EHCI
2456fd9086aSAlan Stern 	 * implementation uses legacy PCI PM support.  This test
2466fd9086aSAlan Stern 	 * can be removed on 17 Dec 2009 if the dev_warn() hasn't
2476fd9086aSAlan Stern 	 * been triggered by then.
2482c1c3c4cSDavid Brownell 	 */
2492c1c3c4cSDavid Brownell 	if (!device_can_wakeup(&pdev->dev)) {
2502c1c3c4cSDavid Brownell 		u16	port_wake;
2512c1c3c4cSDavid Brownell 
2522c1c3c4cSDavid Brownell 		pci_read_config_word(pdev, 0x62, &port_wake);
2536fd9086aSAlan Stern 		if (port_wake & 0x0001) {
2546fd9086aSAlan Stern 			dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
255bcca06efSAlan Stern 			device_set_wakeup_capable(&pdev->dev, 1);
2562c1c3c4cSDavid Brownell 		}
2576fd9086aSAlan Stern 	}
2587ff71d6aSMatt Porter 
259f8aeb3bbSDavid Brownell #ifdef	CONFIG_USB_SUSPEND
260f8aeb3bbSDavid Brownell 	/* REVISIT: the controller works fine for wakeup iff the root hub
261f8aeb3bbSDavid Brownell 	 * itself is "globally" suspended, but usbcore currently doesn't
262f8aeb3bbSDavid Brownell 	 * understand such things.
263f8aeb3bbSDavid Brownell 	 *
264f8aeb3bbSDavid Brownell 	 * System suspend currently expects to be able to suspend the entire
265f8aeb3bbSDavid Brownell 	 * device tree, device-at-a-time.  If we failed selective suspend
266f8aeb3bbSDavid Brownell 	 * reports, system suspend would fail; so the root hub code must claim
267411c9403SAnand Gadiyar 	 * success.  That's lying to usbcore, and it matters for runtime
268f8aeb3bbSDavid Brownell 	 * PM scenarios with selective suspend and remote wakeup...
269f8aeb3bbSDavid Brownell 	 */
270f8aeb3bbSDavid Brownell 	if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
271f8aeb3bbSDavid Brownell 		ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
272f8aeb3bbSDavid Brownell #endif
273f8aeb3bbSDavid Brownell 
274aff6d18fSAlan Stern 	ehci_port_power(ehci, 1);
27518807521SDavid Brownell 	retval = ehci_pci_reinit(ehci, pdev);
2768926bfa7SDavid Brownell done:
2778926bfa7SDavid Brownell 	return retval;
2787ff71d6aSMatt Porter }
2797ff71d6aSMatt Porter 
2807ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
2817ff71d6aSMatt Porter 
2827ff71d6aSMatt Porter #ifdef	CONFIG_PM
2837ff71d6aSMatt Porter 
2847ff71d6aSMatt Porter /* suspend/resume, section 4.3 */
2857ff71d6aSMatt Porter 
286f03c17fcSDavid Brownell /* These routines rely on the PCI bus glue
2877ff71d6aSMatt Porter  * to handle powerdown and wakeup, and currently also on
2887ff71d6aSMatt Porter  * transceivers that don't need any software attention to set up
2897ff71d6aSMatt Porter  * the right sort of wakeup.
290f03c17fcSDavid Brownell  * Also they depend on separate root hub suspend/resume.
2917ff71d6aSMatt Porter  */
2927ff71d6aSMatt Porter 
2934147200dSAlan Stern static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
2947ff71d6aSMatt Porter {
2957ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
2968de98402SBenjamin Herrenschmidt 	unsigned long		flags;
2978de98402SBenjamin Herrenschmidt 	int			rc = 0;
2987ff71d6aSMatt Porter 
2997ff71d6aSMatt Porter 	if (time_before(jiffies, ehci->next_statechange))
300f03c17fcSDavid Brownell 		msleep(10);
3017ff71d6aSMatt Porter 
3028de98402SBenjamin Herrenschmidt 	/* Root hub was already suspended. Disable irq emission and
30316032c4fSAlan Stern 	 * mark HW unaccessible.  The PM and USB cores make sure that
30416032c4fSAlan Stern 	 * the root hub is either suspended or stopped.
3058de98402SBenjamin Herrenschmidt 	 */
3068de98402SBenjamin Herrenschmidt 	spin_lock_irqsave (&ehci->lock, flags);
3074147200dSAlan Stern 	ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
308083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, 0, &ehci->regs->intr_enable);
309083522d7SBenjamin Herrenschmidt 	(void)ehci_readl(ehci, &ehci->regs->intr_enable);
3108de98402SBenjamin Herrenschmidt 
3118de98402SBenjamin Herrenschmidt 	clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
3128de98402SBenjamin Herrenschmidt 	spin_unlock_irqrestore (&ehci->lock, flags);
3138de98402SBenjamin Herrenschmidt 
314f03c17fcSDavid Brownell 	// could save FLADJ in case of Vaux power loss
3157ff71d6aSMatt Porter 	// ... we'd only use it to handle clock skew
3167ff71d6aSMatt Porter 
3178de98402SBenjamin Herrenschmidt 	return rc;
3187ff71d6aSMatt Porter }
3197ff71d6aSMatt Porter 
3206ec4beb5SAlan Stern static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
3217ff71d6aSMatt Porter {
3227ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
32318807521SDavid Brownell 	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
3247ff71d6aSMatt Porter 
325f03c17fcSDavid Brownell 	// maybe restore FLADJ
3267ff71d6aSMatt Porter 
3277ff71d6aSMatt Porter 	if (time_before(jiffies, ehci->next_statechange))
3287ff71d6aSMatt Porter 		msleep(100);
3297ff71d6aSMatt Porter 
3308de98402SBenjamin Herrenschmidt 	/* Mark hardware accessible again as we are out of D3 state by now */
3318de98402SBenjamin Herrenschmidt 	set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
3328de98402SBenjamin Herrenschmidt 
3336ec4beb5SAlan Stern 	/* If CF is still set and we aren't resuming from hibernation
3346ec4beb5SAlan Stern 	 * then we maintained PCI Vaux power.
3358c03356aSAlan Stern 	 * Just undo the effect of ehci_pci_suspend().
3367ff71d6aSMatt Porter 	 */
3376ec4beb5SAlan Stern 	if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
3386ec4beb5SAlan Stern 				!hibernated) {
3398c03356aSAlan Stern 		int	mask = INTR_MASK;
3408c03356aSAlan Stern 
34116032c4fSAlan Stern 		ehci_prepare_ports_for_controller_resume(ehci);
34258a97ffeSAlan Stern 		if (!hcd->self.root_hub->do_remote_wakeup)
3438c03356aSAlan Stern 			mask &= ~STS_PCD;
344083522d7SBenjamin Herrenschmidt 		ehci_writel(ehci, mask, &ehci->regs->intr_enable);
345083522d7SBenjamin Herrenschmidt 		ehci_readl(ehci, &ehci->regs->intr_enable);
346f03c17fcSDavid Brownell 		return 0;
3477ff71d6aSMatt Porter 	}
348f03c17fcSDavid Brownell 
3491c50c317SAlan Stern 	usb_root_hub_lost_power(hcd->self.root_hub);
3507ff71d6aSMatt Porter 
3517ff71d6aSMatt Porter 	/* Else reset, to cope with power loss or flush-to-storage
352f03c17fcSDavid Brownell 	 * style "resume" having let BIOS kick in during reboot.
3537ff71d6aSMatt Porter 	 */
3547ff71d6aSMatt Porter 	(void) ehci_halt(ehci);
3557ff71d6aSMatt Porter 	(void) ehci_reset(ehci);
35618807521SDavid Brownell 	(void) ehci_pci_reinit(ehci, pdev);
3577ff71d6aSMatt Porter 
3587ff71d6aSMatt Porter 	/* emptying the schedule aborts any urbs */
3597ff71d6aSMatt Porter 	spin_lock_irq(&ehci->lock);
3607ff71d6aSMatt Porter 	if (ehci->reclaim)
36107d29b63SAlan Stern 		end_unlink_async(ehci);
3627d12e780SDavid Howells 	ehci_work(ehci);
3637ff71d6aSMatt Porter 	spin_unlock_irq(&ehci->lock);
3647ff71d6aSMatt Porter 
365083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, ehci->command, &ehci->regs->command);
366083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
367083522d7SBenjamin Herrenschmidt 	ehci_readl(ehci, &ehci->regs->command);	/* unblock posted writes */
3688c03356aSAlan Stern 
369383975d7SAlan Stern 	/* here we "know" root ports should always stay powered */
370383975d7SAlan Stern 	ehci_port_power(ehci, 1);
371383975d7SAlan Stern 
3728c03356aSAlan Stern 	hcd->state = HC_STATE_SUSPENDED;
3738c03356aSAlan Stern 	return 0;
3747ff71d6aSMatt Porter }
3757ff71d6aSMatt Porter #endif
3767ff71d6aSMatt Porter 
37748f24970SAlek Du static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
37848f24970SAlek Du {
37948f24970SAlek Du 	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
38048f24970SAlek Du 	int rc = 0;
38148f24970SAlek Du 
38248f24970SAlek Du 	if (!udev->parent) /* udev is root hub itself, impossible */
38348f24970SAlek Du 		rc = -1;
38448f24970SAlek Du 	/* we only support lpm device connected to root hub yet */
38548f24970SAlek Du 	if (ehci->has_lpm && !udev->parent->parent) {
38648f24970SAlek Du 		rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
38748f24970SAlek Du 		if (!rc)
38848f24970SAlek Du 			rc = ehci_lpm_check(ehci, udev->portnum);
38948f24970SAlek Du 	}
39048f24970SAlek Du 	return rc;
39148f24970SAlek Du }
39248f24970SAlek Du 
3937ff71d6aSMatt Porter static const struct hc_driver ehci_pci_hc_driver = {
3947ff71d6aSMatt Porter 	.description =		hcd_name,
3957ff71d6aSMatt Porter 	.product_desc =		"EHCI Host Controller",
3967ff71d6aSMatt Porter 	.hcd_priv_size =	sizeof(struct ehci_hcd),
3977ff71d6aSMatt Porter 
3987ff71d6aSMatt Porter 	/*
3997ff71d6aSMatt Porter 	 * generic hardware linkage
4007ff71d6aSMatt Porter 	 */
4017ff71d6aSMatt Porter 	.irq =			ehci_irq,
4027ff71d6aSMatt Porter 	.flags =		HCD_MEMORY | HCD_USB2,
4037ff71d6aSMatt Porter 
4047ff71d6aSMatt Porter 	/*
4057ff71d6aSMatt Porter 	 * basic lifecycle operations
4067ff71d6aSMatt Porter 	 */
4078926bfa7SDavid Brownell 	.reset =		ehci_pci_setup,
40818807521SDavid Brownell 	.start =		ehci_run,
4097ff71d6aSMatt Porter #ifdef	CONFIG_PM
4107be7d741SAlan Stern 	.pci_suspend =		ehci_pci_suspend,
4117be7d741SAlan Stern 	.pci_resume =		ehci_pci_resume,
4127ff71d6aSMatt Porter #endif
41318807521SDavid Brownell 	.stop =			ehci_stop,
41464a21d02SAleksey Gorelov 	.shutdown =		ehci_shutdown,
4157ff71d6aSMatt Porter 
4167ff71d6aSMatt Porter 	/*
4177ff71d6aSMatt Porter 	 * managing i/o requests and associated device resources
4187ff71d6aSMatt Porter 	 */
4197ff71d6aSMatt Porter 	.urb_enqueue =		ehci_urb_enqueue,
4207ff71d6aSMatt Porter 	.urb_dequeue =		ehci_urb_dequeue,
4217ff71d6aSMatt Porter 	.endpoint_disable =	ehci_endpoint_disable,
422b18ffd49SAlan Stern 	.endpoint_reset =	ehci_endpoint_reset,
4237ff71d6aSMatt Porter 
4247ff71d6aSMatt Porter 	/*
4257ff71d6aSMatt Porter 	 * scheduling support
4267ff71d6aSMatt Porter 	 */
4277ff71d6aSMatt Porter 	.get_frame_number =	ehci_get_frame,
4287ff71d6aSMatt Porter 
4297ff71d6aSMatt Porter 	/*
4307ff71d6aSMatt Porter 	 * root hub support
4317ff71d6aSMatt Porter 	 */
4327ff71d6aSMatt Porter 	.hub_status_data =	ehci_hub_status_data,
4337ff71d6aSMatt Porter 	.hub_control =		ehci_hub_control,
4340c0382e3SAlan Stern 	.bus_suspend =		ehci_bus_suspend,
4350c0382e3SAlan Stern 	.bus_resume =		ehci_bus_resume,
43690da096eSBalaji Rao 	.relinquish_port =	ehci_relinquish_port,
4373a31155cSAlan Stern 	.port_handed_over =	ehci_port_handed_over,
438914b7012SAlan Stern 
43948f24970SAlek Du 	/*
44048f24970SAlek Du 	 * call back when device connected and addressed
44148f24970SAlek Du 	 */
44248f24970SAlek Du 	.update_device =	ehci_update_device,
44348f24970SAlek Du 
444914b7012SAlan Stern 	.clear_tt_buffer_complete	= ehci_clear_tt_buffer_complete,
4457ff71d6aSMatt Porter };
4467ff71d6aSMatt Porter 
4477ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
4487ff71d6aSMatt Porter 
4497ff71d6aSMatt Porter /* PCI driver selection metadata; PCI hotplugging uses this */
4507ff71d6aSMatt Porter static const struct pci_device_id pci_ids [] = { {
4517ff71d6aSMatt Porter 	/* handle any USB 2.0 EHCI controller */
452c67808eeSJean Delvare 	PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
4537ff71d6aSMatt Porter 	.driver_data =	(unsigned long) &ehci_pci_hc_driver,
4547ff71d6aSMatt Porter 	},
4557ff71d6aSMatt Porter 	{ /* end: all zeroes */ }
4567ff71d6aSMatt Porter };
4577ff71d6aSMatt Porter MODULE_DEVICE_TABLE(pci, pci_ids);
4587ff71d6aSMatt Porter 
4597ff71d6aSMatt Porter /* pci driver glue; this is a "new style" PCI driver module */
4607ff71d6aSMatt Porter static struct pci_driver ehci_pci_driver = {
4617ff71d6aSMatt Porter 	.name =		(char *) hcd_name,
4627ff71d6aSMatt Porter 	.id_table =	pci_ids,
4637ff71d6aSMatt Porter 
4647ff71d6aSMatt Porter 	.probe =	usb_hcd_pci_probe,
4657ff71d6aSMatt Porter 	.remove =	usb_hcd_pci_remove,
46664a21d02SAleksey Gorelov 	.shutdown = 	usb_hcd_pci_shutdown,
467abb30641SAlan Stern 
468abb30641SAlan Stern #ifdef CONFIG_PM_SLEEP
469abb30641SAlan Stern 	.driver =	{
470abb30641SAlan Stern 		.pm =	&usb_hcd_pci_pm_ops
471abb30641SAlan Stern 	},
472abb30641SAlan Stern #endif
4737ff71d6aSMatt Porter };
474