xref: /linux/drivers/usb/host/ehci-hcd.c (revision 11c011a5e777c83819078a18672543f04482b3ec)
11da177e4SLinus Torvalds /*
2578333abSAlan Stern  * Enhanced Host Controller Interface (EHCI) driver for USB.
3578333abSAlan Stern  *
4578333abSAlan Stern  * Maintainer: Alan Stern <stern@rowland.harvard.edu>
5578333abSAlan Stern  *
61da177e4SLinus Torvalds  * Copyright (c) 2000-2004 by David Brownell
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify it
91da177e4SLinus Torvalds  * under the terms of the GNU General Public License as published by the
101da177e4SLinus Torvalds  * Free Software Foundation; either version 2 of the License, or (at your
111da177e4SLinus Torvalds  * option) any later version.
121da177e4SLinus Torvalds  *
131da177e4SLinus Torvalds  * This program is distributed in the hope that it will be useful, but
141da177e4SLinus Torvalds  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
151da177e4SLinus Torvalds  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
161da177e4SLinus Torvalds  * for more details.
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  * You should have received a copy of the GNU General Public License
191da177e4SLinus Torvalds  * along with this program; if not, write to the Free Software Foundation,
201da177e4SLinus Torvalds  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
211da177e4SLinus Torvalds  */
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds #include <linux/module.h>
241da177e4SLinus Torvalds #include <linux/pci.h>
251da177e4SLinus Torvalds #include <linux/dmapool.h>
261da177e4SLinus Torvalds #include <linux/kernel.h>
271da177e4SLinus Torvalds #include <linux/delay.h>
281da177e4SLinus Torvalds #include <linux/ioport.h>
291da177e4SLinus Torvalds #include <linux/sched.h>
303c04e20eSMing Lei #include <linux/vmalloc.h>
311da177e4SLinus Torvalds #include <linux/errno.h>
321da177e4SLinus Torvalds #include <linux/init.h>
33d58b4bccSAlan Stern #include <linux/hrtimer.h>
341da177e4SLinus Torvalds #include <linux/list.h>
351da177e4SLinus Torvalds #include <linux/interrupt.h>
361da177e4SLinus Torvalds #include <linux/usb.h>
3727729aadSEric Lescouet #include <linux/usb/hcd.h>
381da177e4SLinus Torvalds #include <linux/moduleparam.h>
391da177e4SLinus Torvalds #include <linux/dma-mapping.h>
40694cc208STony Jones #include <linux/debugfs.h>
415a0e3ad6STejun Heo #include <linux/slab.h>
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds #include <asm/byteorder.h>
441da177e4SLinus Torvalds #include <asm/io.h>
451da177e4SLinus Torvalds #include <asm/irq.h>
461da177e4SLinus Torvalds #include <asm/unaligned.h>
471da177e4SLinus Torvalds 
48df7c1ca2SGeoff Levand #if defined(CONFIG_PPC_PS3)
49df7c1ca2SGeoff Levand #include <asm/firmware.h>
50df7c1ca2SGeoff Levand #endif
51df7c1ca2SGeoff Levand 
521da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds /*
551da177e4SLinus Torvalds  * EHCI hc_driver implementation ... experimental, incomplete.
561da177e4SLinus Torvalds  * Based on the final 1.0 register interface specification.
571da177e4SLinus Torvalds  *
581da177e4SLinus Torvalds  * USB 2.0 shows up in upcoming www.pcmcia.org technology.
591da177e4SLinus Torvalds  * First was PCMCIA, like ISA; then CardBus, which is PCI.
601da177e4SLinus Torvalds  * Next comes "CardBay", using USB 2.0 signals.
611da177e4SLinus Torvalds  *
621da177e4SLinus Torvalds  * Contains additional contributions by Brad Hards, Rory Bolt, and others.
631da177e4SLinus Torvalds  * Special thanks to Intel and VIA for providing host controllers to
641da177e4SLinus Torvalds  * test this driver on, and Cypress (including In-System Design) for
651da177e4SLinus Torvalds  * providing early devices for those host controllers to talk to!
661da177e4SLinus Torvalds  */
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds #define DRIVER_AUTHOR "David Brownell"
691da177e4SLinus Torvalds #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds static const char	hcd_name [] = "ehci_hcd";
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds #undef EHCI_URB_TRACE
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds /* magic numbers that can affect system performance */
771da177e4SLinus Torvalds #define	EHCI_TUNE_CERR		3	/* 0-3 qtd retries; 0 == don't stop */
781da177e4SLinus Torvalds #define	EHCI_TUNE_RL_HS		4	/* nak throttle; see 4.9 */
791da177e4SLinus Torvalds #define	EHCI_TUNE_RL_TT		0
801da177e4SLinus Torvalds #define	EHCI_TUNE_MULT_HS	1	/* 1-3 transactions/uframe; 4.10.3 */
811da177e4SLinus Torvalds #define	EHCI_TUNE_MULT_TT	1
82ffda0803SAlan Stern /*
83ffda0803SAlan Stern  * Some drivers think it's safe to schedule isochronous transfers more than
84ffda0803SAlan Stern  * 256 ms into the future (partly as a result of an old bug in the scheduling
85ffda0803SAlan Stern  * code).  In an attempt to avoid trouble, we will use a minimum scheduling
86ffda0803SAlan Stern  * length of 512 frames instead of 256.
87ffda0803SAlan Stern  */
88ffda0803SAlan Stern #define	EHCI_TUNE_FLS		1	/* (medium) 512-frame schedule */
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds /* Initial IRQ latency:  faster than hw default */
911da177e4SLinus Torvalds static int log2_irq_thresh = 0;		// 0 to 6
921da177e4SLinus Torvalds module_param (log2_irq_thresh, int, S_IRUGO);
931da177e4SLinus Torvalds MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds /* initial park setting:  slower than hw default */
961da177e4SLinus Torvalds static unsigned park = 0;
971da177e4SLinus Torvalds module_param (park, uint, S_IRUGO);
981da177e4SLinus Torvalds MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
991da177e4SLinus Torvalds 
10093f1a47cSDavid Brownell /* for flakey hardware, ignore overcurrent indicators */
101900937c0SGeyslan G. Bem static bool ignore_oc;
10293f1a47cSDavid Brownell module_param (ignore_oc, bool, S_IRUGO);
10393f1a47cSDavid Brownell MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
10493f1a47cSDavid Brownell 
1051da177e4SLinus Torvalds #define	INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds #include "ehci.h"
110ad93562bSAndiry Xu #include "pci-quirks.h"
1111da177e4SLinus Torvalds 
112b35c5009SAlan Stern static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE],
113b35c5009SAlan Stern 		struct ehci_tt *tt);
114b35c5009SAlan Stern 
115acc08503SAlan Stern /*
116acc08503SAlan Stern  * The MosChip MCS9990 controller updates its microframe counter
117acc08503SAlan Stern  * a little before the frame counter, and occasionally we will read
118acc08503SAlan Stern  * the invalid intermediate value.  Avoid problems by checking the
119acc08503SAlan Stern  * microframe number (the low-order 3 bits); if they are 0 then
120acc08503SAlan Stern  * re-read the register to get the correct value.
121acc08503SAlan Stern  */
122acc08503SAlan Stern static unsigned ehci_moschip_read_frame_index(struct ehci_hcd *ehci)
123acc08503SAlan Stern {
124acc08503SAlan Stern 	unsigned uf;
125acc08503SAlan Stern 
126acc08503SAlan Stern 	uf = ehci_readl(ehci, &ehci->regs->frame_index);
127acc08503SAlan Stern 	if (unlikely((uf & 7) == 0))
128acc08503SAlan Stern 		uf = ehci_readl(ehci, &ehci->regs->frame_index);
129acc08503SAlan Stern 	return uf;
130acc08503SAlan Stern }
131acc08503SAlan Stern 
132acc08503SAlan Stern static inline unsigned ehci_read_frame_index(struct ehci_hcd *ehci)
133acc08503SAlan Stern {
134acc08503SAlan Stern 	if (ehci->frame_index_bug)
135acc08503SAlan Stern 		return ehci_moschip_read_frame_index(ehci);
136acc08503SAlan Stern 	return ehci_readl(ehci, &ehci->regs->frame_index);
137acc08503SAlan Stern }
138acc08503SAlan Stern 
139acc08503SAlan Stern #include "ehci-dbg.c"
140acc08503SAlan Stern 
1411da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds /*
1442f3a6b86SManjunath Goudar  * ehci_handshake - spin reading hc until handshake completes or fails
1451da177e4SLinus Torvalds  * @ptr: address of hc register to be read
1461da177e4SLinus Torvalds  * @mask: bits to look at in result of read
1471da177e4SLinus Torvalds  * @done: value of those bits when handshake succeeds
1481da177e4SLinus Torvalds  * @usec: timeout in microseconds
1491da177e4SLinus Torvalds  *
1501da177e4SLinus Torvalds  * Returns negative errno, or zero on success
1511da177e4SLinus Torvalds  *
1521da177e4SLinus Torvalds  * Success happens when the "mask" bits have the specified value (hardware
1531da177e4SLinus Torvalds  * handshake done).  There are two failure modes:  "usec" have passed (major
1541da177e4SLinus Torvalds  * hardware flakeout), or the register reads as all-ones (hardware removed).
1551da177e4SLinus Torvalds  *
1561da177e4SLinus Torvalds  * That last failure should_only happen in cases like physical cardbus eject
1571da177e4SLinus Torvalds  * before driver shutdown. But it also seems to be caused by bugs in cardbus
1581da177e4SLinus Torvalds  * bridge shutdown:  shutting down the bridge before the devices using it.
1591da177e4SLinus Torvalds  */
1602f3a6b86SManjunath Goudar int ehci_handshake(struct ehci_hcd *ehci, void __iomem *ptr,
161083522d7SBenjamin Herrenschmidt 		   u32 mask, u32 done, int usec)
1621da177e4SLinus Torvalds {
1631da177e4SLinus Torvalds 	u32	result;
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 	do {
166083522d7SBenjamin Herrenschmidt 		result = ehci_readl(ehci, ptr);
1671da177e4SLinus Torvalds 		if (result == ~(u32)0)		/* card removed */
1681da177e4SLinus Torvalds 			return -ENODEV;
1691da177e4SLinus Torvalds 		result &= mask;
1701da177e4SLinus Torvalds 		if (result == done)
1711da177e4SLinus Torvalds 			return 0;
1721da177e4SLinus Torvalds 		udelay (1);
1731da177e4SLinus Torvalds 		usec--;
1741da177e4SLinus Torvalds 	} while (usec > 0);
1751da177e4SLinus Torvalds 	return -ETIMEDOUT;
1761da177e4SLinus Torvalds }
1772f3a6b86SManjunath Goudar EXPORT_SYMBOL_GPL(ehci_handshake);
1781da177e4SLinus Torvalds 
17965fd4272SMatthieu CASTET /* check TDI/ARC silicon is in host mode */
18065fd4272SMatthieu CASTET static int tdi_in_host_mode (struct ehci_hcd *ehci)
18165fd4272SMatthieu CASTET {
18265fd4272SMatthieu CASTET 	u32		tmp;
18365fd4272SMatthieu CASTET 
184a46af4ebSAlan Stern 	tmp = ehci_readl(ehci, &ehci->regs->usbmode);
18565fd4272SMatthieu CASTET 	return (tmp & 3) == USBMODE_CM_HC;
18665fd4272SMatthieu CASTET }
18765fd4272SMatthieu CASTET 
188c4f34764SAlan Stern /*
189c4f34764SAlan Stern  * Force HC to halt state from unknown (EHCI spec section 2.3).
190c4f34764SAlan Stern  * Must be called with interrupts enabled and the lock not held.
191c4f34764SAlan Stern  */
1921da177e4SLinus Torvalds static int ehci_halt (struct ehci_hcd *ehci)
1931da177e4SLinus Torvalds {
194c4f34764SAlan Stern 	u32	temp;
195c4f34764SAlan Stern 
196c4f34764SAlan Stern 	spin_lock_irq(&ehci->lock);
1971da177e4SLinus Torvalds 
19872f30b6fSDavid Brownell 	/* disable any irqs left enabled by previous code */
199083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, 0, &ehci->regs->intr_enable);
20072f30b6fSDavid Brownell 
201c4f34764SAlan Stern 	if (ehci_is_TDI(ehci) && !tdi_in_host_mode(ehci)) {
202c4f34764SAlan Stern 		spin_unlock_irq(&ehci->lock);
20365fd4272SMatthieu CASTET 		return 0;
20465fd4272SMatthieu CASTET 	}
20565fd4272SMatthieu CASTET 
2063d9545ccSAlan Stern 	/*
2073d9545ccSAlan Stern 	 * This routine gets called during probe before ehci->command
2083d9545ccSAlan Stern 	 * has been initialized, so we can't rely on its value.
2093d9545ccSAlan Stern 	 */
2103d9545ccSAlan Stern 	ehci->command &= ~CMD_RUN;
211083522d7SBenjamin Herrenschmidt 	temp = ehci_readl(ehci, &ehci->regs->command);
2123d9545ccSAlan Stern 	temp &= ~(CMD_RUN | CMD_IAAD);
213083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, temp, &ehci->regs->command);
214c4f34764SAlan Stern 
215c4f34764SAlan Stern 	spin_unlock_irq(&ehci->lock);
216c4f34764SAlan Stern 	synchronize_irq(ehci_to_hcd(ehci)->irq);
217c4f34764SAlan Stern 
2182f3a6b86SManjunath Goudar 	return ehci_handshake(ehci, &ehci->regs->status,
219083522d7SBenjamin Herrenschmidt 			  STS_HALT, STS_HALT, 16 * 125);
2201da177e4SLinus Torvalds }
2211da177e4SLinus Torvalds 
2221da177e4SLinus Torvalds /* put TDI/ARC silicon into EHCI mode */
2231da177e4SLinus Torvalds static void tdi_reset (struct ehci_hcd *ehci)
2241da177e4SLinus Torvalds {
2251da177e4SLinus Torvalds 	u32		tmp;
2261da177e4SLinus Torvalds 
227a46af4ebSAlan Stern 	tmp = ehci_readl(ehci, &ehci->regs->usbmode);
228d23a1377SVladimir Barinov 	tmp |= USBMODE_CM_HC;
229d23a1377SVladimir Barinov 	/* The default byte access to MMR space is LE after
230d23a1377SVladimir Barinov 	 * controller reset. Set the required endian mode
231d23a1377SVladimir Barinov 	 * for transfer buffers to match the host microprocessor
232d23a1377SVladimir Barinov 	 */
233d23a1377SVladimir Barinov 	if (ehci_big_endian_mmio(ehci))
234d23a1377SVladimir Barinov 		tmp |= USBMODE_BE;
235a46af4ebSAlan Stern 	ehci_writel(ehci, tmp, &ehci->regs->usbmode);
2361da177e4SLinus Torvalds }
2371da177e4SLinus Torvalds 
238c4f34764SAlan Stern /*
239c4f34764SAlan Stern  * Reset a non-running (STS_HALT == 1) controller.
240c4f34764SAlan Stern  * Must be called with interrupts enabled and the lock not held.
241c4f34764SAlan Stern  */
24274db22cbSRamneek Mehresh int ehci_reset(struct ehci_hcd *ehci)
2431da177e4SLinus Torvalds {
2441da177e4SLinus Torvalds 	int	retval;
245083522d7SBenjamin Herrenschmidt 	u32	command = ehci_readl(ehci, &ehci->regs->command);
2461da177e4SLinus Torvalds 
2478d053c79SJason Wessel 	/* If the EHCI debug controller is active, special care must be
2488d053c79SJason Wessel 	 * taken before and after a host controller reset */
2499fa5780bSJan Beulich 	if (ehci->debug && !dbgp_reset_prep(ehci_to_hcd(ehci)))
2508d053c79SJason Wessel 		ehci->debug = NULL;
2518d053c79SJason Wessel 
2521da177e4SLinus Torvalds 	command |= CMD_RESET;
2531da177e4SLinus Torvalds 	dbg_cmd (ehci, "reset", command);
254083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, command, &ehci->regs->command);
255e8799906SAlan Stern 	ehci->rh_state = EHCI_RH_HALTED;
2561da177e4SLinus Torvalds 	ehci->next_statechange = jiffies;
2572f3a6b86SManjunath Goudar 	retval = ehci_handshake(ehci, &ehci->regs->command,
258083522d7SBenjamin Herrenschmidt 			    CMD_RESET, 0, 250 * 1000);
2591da177e4SLinus Torvalds 
260331ac6b2SAlek Du 	if (ehci->has_hostpc) {
261331ac6b2SAlek Du 		ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
262a46af4ebSAlan Stern 				&ehci->regs->usbmode_ex);
263a46af4ebSAlan Stern 		ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning);
264331ac6b2SAlek Du 	}
2651da177e4SLinus Torvalds 	if (retval)
2661da177e4SLinus Torvalds 		return retval;
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds 	if (ehci_is_TDI(ehci))
2691da177e4SLinus Torvalds 		tdi_reset (ehci);
2701da177e4SLinus Torvalds 
2718d053c79SJason Wessel 	if (ehci->debug)
2729fa5780bSJan Beulich 		dbgp_external_startup(ehci_to_hcd(ehci));
2738d053c79SJason Wessel 
274a448e4dcSAlan Stern 	ehci->port_c_suspend = ehci->suspended_ports =
275a448e4dcSAlan Stern 			ehci->resuming_ports = 0;
2761da177e4SLinus Torvalds 	return retval;
2771da177e4SLinus Torvalds }
27874db22cbSRamneek Mehresh EXPORT_SYMBOL_GPL(ehci_reset);
2791da177e4SLinus Torvalds 
280c4f34764SAlan Stern /*
281c4f34764SAlan Stern  * Idle the controller (turn off the schedules).
282c4f34764SAlan Stern  * Must be called with interrupts enabled and the lock not held.
283c4f34764SAlan Stern  */
2841da177e4SLinus Torvalds static void ehci_quiesce (struct ehci_hcd *ehci)
2851da177e4SLinus Torvalds {
2861da177e4SLinus Torvalds 	u32	temp;
2871da177e4SLinus Torvalds 
288e8799906SAlan Stern 	if (ehci->rh_state != EHCI_RH_RUNNING)
289c0c53dbcSAlan Stern 		return;
2901da177e4SLinus Torvalds 
2911da177e4SLinus Torvalds 	/* wait for any schedule enables/disables to take effect */
2923d9545ccSAlan Stern 	temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
2932f3a6b86SManjunath Goudar 	ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, temp,
2942f3a6b86SManjunath Goudar 			16 * 125);
2951da177e4SLinus Torvalds 
2961da177e4SLinus Torvalds 	/* then disable anything that's still active */
297c4f34764SAlan Stern 	spin_lock_irq(&ehci->lock);
2983d9545ccSAlan Stern 	ehci->command &= ~(CMD_ASE | CMD_PSE);
2993d9545ccSAlan Stern 	ehci_writel(ehci, ehci->command, &ehci->regs->command);
300c4f34764SAlan Stern 	spin_unlock_irq(&ehci->lock);
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds 	/* hardware can take 16 microframes to turn off ... */
3032f3a6b86SManjunath Goudar 	ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, 0,
3042f3a6b86SManjunath Goudar 			16 * 125);
3051da177e4SLinus Torvalds }
3061da177e4SLinus Torvalds 
3071da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3081da177e4SLinus Torvalds 
309f96fba0dSAlan Stern static void end_iaa_cycle(struct ehci_hcd *ehci);
31007d29b63SAlan Stern static void end_unlink_async(struct ehci_hcd *ehci);
31132830f20SAlan Stern static void unlink_empty_async(struct ehci_hcd *ehci);
3127d12e780SDavid Howells static void ehci_work(struct ehci_hcd *ehci);
313df202255SAlan Stern static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
314df202255SAlan Stern static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
31511a7e594SMichael Grzeschik static int ehci_port_power(struct ehci_hcd *ehci, int portnum, bool enable);
3161da177e4SLinus Torvalds 
317d58b4bccSAlan Stern #include "ehci-timer.c"
3181da177e4SLinus Torvalds #include "ehci-hub.c"
3191da177e4SLinus Torvalds #include "ehci-mem.c"
3201da177e4SLinus Torvalds #include "ehci-q.c"
3211da177e4SLinus Torvalds #include "ehci-sched.c"
3224c67045bSKirill Smelkov #include "ehci-sysfs.c"
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3251da177e4SLinus Torvalds 
3268903795aSAlan Stern /* On some systems, leaving remote wakeup enabled prevents system shutdown.
3278903795aSAlan Stern  * The firmware seems to think that powering off is a wakeup event!
3288903795aSAlan Stern  * This routine turns off remote wakeup and everything else, on all ports.
3298903795aSAlan Stern  */
3308903795aSAlan Stern static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
3318903795aSAlan Stern {
3328903795aSAlan Stern 	int	port = HCS_N_PORTS(ehci->hcs_params);
3338903795aSAlan Stern 
33411a7e594SMichael Grzeschik 	while (port--) {
3358903795aSAlan Stern 		ehci_writel(ehci, PORT_RWC_BITS,
3368903795aSAlan Stern 				&ehci->regs->port_status[port]);
33711a7e594SMichael Grzeschik 		spin_unlock_irq(&ehci->lock);
33811a7e594SMichael Grzeschik 		ehci_port_power(ehci, port, false);
33911a7e594SMichael Grzeschik 		spin_lock_irq(&ehci->lock);
34011a7e594SMichael Grzeschik 	}
3418903795aSAlan Stern }
3428903795aSAlan Stern 
34321da84a8SSarah Sharp /*
34421da84a8SSarah Sharp  * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
345c4f34764SAlan Stern  * Must be called with interrupts enabled and the lock not held.
34672f30b6fSDavid Brownell  */
34721da84a8SSarah Sharp static void ehci_silence_controller(struct ehci_hcd *ehci)
3481da177e4SLinus Torvalds {
34921da84a8SSarah Sharp 	ehci_halt(ehci);
350c4f34764SAlan Stern 
351c4f34764SAlan Stern 	spin_lock_irq(&ehci->lock);
352c4f34764SAlan Stern 	ehci->rh_state = EHCI_RH_HALTED;
3538903795aSAlan Stern 	ehci_turn_off_all_ports(ehci);
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds 	/* make BIOS/etc use companion controller during reboot */
356083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, 0, &ehci->regs->configured_flag);
3578903795aSAlan Stern 
3588903795aSAlan Stern 	/* unblock posted writes */
3598903795aSAlan Stern 	ehci_readl(ehci, &ehci->regs->configured_flag);
360c4f34764SAlan Stern 	spin_unlock_irq(&ehci->lock);
3611da177e4SLinus Torvalds }
3621da177e4SLinus Torvalds 
36321da84a8SSarah Sharp /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
36421da84a8SSarah Sharp  * This forcibly disables dma and IRQs, helping kexec and other cases
36521da84a8SSarah Sharp  * where the next system software may expect clean state.
36621da84a8SSarah Sharp  */
36721da84a8SSarah Sharp static void ehci_shutdown(struct usb_hcd *hcd)
36821da84a8SSarah Sharp {
36921da84a8SSarah Sharp 	struct ehci_hcd	*ehci = hcd_to_ehci(hcd);
37021da84a8SSarah Sharp 
371*11c011a5SSrinivas Kandagatla 	/**
372*11c011a5SSrinivas Kandagatla 	 * Protect the system from crashing at system shutdown in cases where
373*11c011a5SSrinivas Kandagatla 	 * usb host is not added yet from OTG controller driver.
374*11c011a5SSrinivas Kandagatla 	 * As ehci_setup() not done yet, so stop accessing registers or
375*11c011a5SSrinivas Kandagatla 	 * variables initialized in ehci_setup()
376*11c011a5SSrinivas Kandagatla 	 */
377*11c011a5SSrinivas Kandagatla 	if (!ehci->sbrn)
378*11c011a5SSrinivas Kandagatla 		return;
379*11c011a5SSrinivas Kandagatla 
38021da84a8SSarah Sharp 	spin_lock_irq(&ehci->lock);
38143fe3a99SAlan Stern 	ehci->shutdown = true;
382c0c53dbcSAlan Stern 	ehci->rh_state = EHCI_RH_STOPPING;
383d58b4bccSAlan Stern 	ehci->enabled_hrtimer_events = 0;
38421da84a8SSarah Sharp 	spin_unlock_irq(&ehci->lock);
385d58b4bccSAlan Stern 
386c4f34764SAlan Stern 	ehci_silence_controller(ehci);
387c4f34764SAlan Stern 
388d58b4bccSAlan Stern 	hrtimer_cancel(&ehci->hrtimer);
38921da84a8SSarah Sharp }
39021da84a8SSarah Sharp 
3917ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
3921da177e4SLinus Torvalds 
3937ff71d6aSMatt Porter /*
3947ff71d6aSMatt Porter  * ehci_work is called from some interrupts, timers, and so on.
3957ff71d6aSMatt Porter  * it calls driver completion functions, after dropping ehci->lock.
3967ff71d6aSMatt Porter  */
3977d12e780SDavid Howells static void ehci_work (struct ehci_hcd *ehci)
3987ff71d6aSMatt Porter {
3997ff71d6aSMatt Porter 	/* another CPU may drop ehci->lock during a schedule scan while
4007ff71d6aSMatt Porter 	 * it reports urb completions.  this flag guards against bogus
4017ff71d6aSMatt Porter 	 * attempts at re-entrant schedule scanning.
4027ff71d6aSMatt Porter 	 */
403361aabf3SAlan Stern 	if (ehci->scanning) {
404361aabf3SAlan Stern 		ehci->need_rescan = true;
4057ff71d6aSMatt Porter 		return;
406361aabf3SAlan Stern 	}
407361aabf3SAlan Stern 	ehci->scanning = true;
408361aabf3SAlan Stern 
409361aabf3SAlan Stern  rescan:
410361aabf3SAlan Stern 	ehci->need_rescan = false;
41131446610SAlan Stern 	if (ehci->async_count)
4127d12e780SDavid Howells 		scan_async(ehci);
413569b394fSAlan Stern 	if (ehci->intr_count > 0)
414569b394fSAlan Stern 		scan_intr(ehci);
415569b394fSAlan Stern 	if (ehci->isoc_count > 0)
416569b394fSAlan Stern 		scan_isoc(ehci);
417361aabf3SAlan Stern 	if (ehci->need_rescan)
418361aabf3SAlan Stern 		goto rescan;
419361aabf3SAlan Stern 	ehci->scanning = false;
4207ff71d6aSMatt Porter 
4217ff71d6aSMatt Porter 	/* the IO watchdog guards against hardware or driver bugs that
4227ff71d6aSMatt Porter 	 * misplace IRQs, and should let us run completely without IRQs.
4237ff71d6aSMatt Porter 	 * such lossage has been observed on both VT6202 and VT8235.
4247ff71d6aSMatt Porter 	 */
42518aafe64SAlan Stern 	turn_on_io_watchdog(ehci);
4267ff71d6aSMatt Porter }
4277ff71d6aSMatt Porter 
42821da84a8SSarah Sharp /*
42921da84a8SSarah Sharp  * Called when the ehci_hcd module is removed.
43021da84a8SSarah Sharp  */
4317ff71d6aSMatt Porter static void ehci_stop (struct usb_hcd *hcd)
4321da177e4SLinus Torvalds {
4331da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
4341da177e4SLinus Torvalds 
4357ff71d6aSMatt Porter 	ehci_dbg (ehci, "stop\n");
4361da177e4SLinus Torvalds 
4377ff71d6aSMatt Porter 	/* no more interrupts ... */
4381da177e4SLinus Torvalds 
4397ff71d6aSMatt Porter 	spin_lock_irq(&ehci->lock);
440d58b4bccSAlan Stern 	ehci->enabled_hrtimer_events = 0;
4417ff71d6aSMatt Porter 	spin_unlock_irq(&ehci->lock);
4427ff71d6aSMatt Porter 
443c4f34764SAlan Stern 	ehci_quiesce(ehci);
4447ff71d6aSMatt Porter 	ehci_silence_controller(ehci);
4457ff71d6aSMatt Porter 	ehci_reset (ehci);
4467ff71d6aSMatt Porter 
447d58b4bccSAlan Stern 	hrtimer_cancel(&ehci->hrtimer);
4484c67045bSKirill Smelkov 	remove_sysfs_files(ehci);
4497ff71d6aSMatt Porter 	remove_debug_files (ehci);
4507ff71d6aSMatt Porter 
4517ff71d6aSMatt Porter 	/* root hub is shut down separately (first, when possible) */
4527ff71d6aSMatt Porter 	spin_lock_irq (&ehci->lock);
45355934eb3SAlan Stern 	end_free_itds(ehci);
4547ff71d6aSMatt Porter 	spin_unlock_irq (&ehci->lock);
4557ff71d6aSMatt Porter 	ehci_mem_cleanup (ehci);
4567ff71d6aSMatt Porter 
457ad93562bSAndiry Xu 	if (ehci->amd_pll_fix == 1)
458ad93562bSAndiry Xu 		usb_amd_dev_put();
45905570297SAlex He 
460083522d7SBenjamin Herrenschmidt 	dbg_status (ehci, "ehci_stop completed",
461083522d7SBenjamin Herrenschmidt 		    ehci_readl(ehci, &ehci->regs->status));
4621da177e4SLinus Torvalds }
4631da177e4SLinus Torvalds 
46418807521SDavid Brownell /* one-time init, only for memory state */
46518807521SDavid Brownell static int ehci_init(struct usb_hcd *hcd)
4661da177e4SLinus Torvalds {
4671da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
4681da177e4SLinus Torvalds 	u32			temp;
4691da177e4SLinus Torvalds 	int			retval;
4701da177e4SLinus Torvalds 	u32			hcc_params;
4713807e26dSAlek Du 	struct ehci_qh_hw	*hw;
4721da177e4SLinus Torvalds 
47318807521SDavid Brownell 	spin_lock_init(&ehci->lock);
47418807521SDavid Brownell 
475403dbd36SAlek Du 	/*
476403dbd36SAlek Du 	 * keep io watchdog by default, those good HCDs could turn off it later
477403dbd36SAlek Du 	 */
478403dbd36SAlek Du 	ehci->need_io_watchdog = 1;
4791da177e4SLinus Torvalds 
480d58b4bccSAlan Stern 	hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
481d58b4bccSAlan Stern 	ehci->hrtimer.function = ehci_hrtimer_func;
482d58b4bccSAlan Stern 	ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
48307d29b63SAlan Stern 
484f75593ceSAlan Stern 	hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
485f75593ceSAlan Stern 
4861da177e4SLinus Torvalds 	/*
487cc62a7ebSKirill Smelkov 	 * by default set standard 80% (== 100 usec/uframe) max periodic
488cc62a7ebSKirill Smelkov 	 * bandwidth as required by USB 2.0
489cc62a7ebSKirill Smelkov 	 */
490cc62a7ebSKirill Smelkov 	ehci->uframe_periodic_max = 100;
491cc62a7ebSKirill Smelkov 
492cc62a7ebSKirill Smelkov 	/*
4931da177e4SLinus Torvalds 	 * hw default: 1K periodic list heads, one per frame.
4941da177e4SLinus Torvalds 	 * periodic_size can shrink by USBCMD update if hcc_params allows.
4951da177e4SLinus Torvalds 	 */
4961da177e4SLinus Torvalds 	ehci->periodic_size = DEFAULT_I_TDPS;
4976e018751SAlan Stern 	INIT_LIST_HEAD(&ehci->async_unlink);
498214ac7a0SAlan Stern 	INIT_LIST_HEAD(&ehci->async_idle);
4999118f9ebSMing Lei 	INIT_LIST_HEAD(&ehci->intr_unlink_wait);
5006e018751SAlan Stern 	INIT_LIST_HEAD(&ehci->intr_unlink);
501569b394fSAlan Stern 	INIT_LIST_HEAD(&ehci->intr_qh_list);
5029aa09d2fSKarsten Wiese 	INIT_LIST_HEAD(&ehci->cached_itd_list);
5030e5f231bSAlan Stern 	INIT_LIST_HEAD(&ehci->cached_sitd_list);
504b35c5009SAlan Stern 	INIT_LIST_HEAD(&ehci->tt_list);
505f75593ceSAlan Stern 
5068e192910SGreg Kroah-Hartman 	if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
507f75593ceSAlan Stern 		/* periodic schedule size can be smaller than default */
508f75593ceSAlan Stern 		switch (EHCI_TUNE_FLS) {
509f75593ceSAlan Stern 		case 0: ehci->periodic_size = 1024; break;
510f75593ceSAlan Stern 		case 1: ehci->periodic_size = 512; break;
511f75593ceSAlan Stern 		case 2: ehci->periodic_size = 256; break;
512f75593ceSAlan Stern 		default:	BUG();
513f75593ceSAlan Stern 		}
514f75593ceSAlan Stern 	}
51518807521SDavid Brownell 	if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
5161da177e4SLinus Torvalds 		return retval;
5171da177e4SLinus Torvalds 
5181da177e4SLinus Torvalds 	/* controllers may cache some of the periodic schedule ... */
5191da177e4SLinus Torvalds 	if (HCC_ISOC_CACHE(hcc_params))		// full frame cache
52098cae42dSAlan Stern 		ehci->i_thresh = 0;
5211da177e4SLinus Torvalds 	else					// N microframes cached
5221da177e4SLinus Torvalds 		ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
5231da177e4SLinus Torvalds 
5241da177e4SLinus Torvalds 	/*
5251da177e4SLinus Torvalds 	 * dedicate a qh for the async ring head, since we couldn't unlink
5261da177e4SLinus Torvalds 	 * a 'real' qh without stopping the async schedule [4.8].  use it
5271da177e4SLinus Torvalds 	 * as the 'reclamation list head' too.
5281da177e4SLinus Torvalds 	 * its dummy is used in hw_alt_next of many tds, to prevent the qh
5291da177e4SLinus Torvalds 	 * from automatically advancing to the next td after short reads.
5301da177e4SLinus Torvalds 	 */
5311da177e4SLinus Torvalds 	ehci->async->qh_next.qh = NULL;
5323807e26dSAlek Du 	hw = ehci->async->hw;
5333807e26dSAlek Du 	hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
5343807e26dSAlek Du 	hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
5354f7a67e2SRicardo Martins #if defined(CONFIG_PPC_PS3)
5364c53de72SAlan Stern 	hw->hw_info1 |= cpu_to_hc32(ehci, QH_INACTIVATE);
5374f7a67e2SRicardo Martins #endif
5383807e26dSAlek Du 	hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
5393807e26dSAlek Du 	hw->hw_qtd_next = EHCI_LIST_END(ehci);
5401da177e4SLinus Torvalds 	ehci->async->qh_state = QH_STATE_LINKED;
5413807e26dSAlek Du 	hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
5421da177e4SLinus Torvalds 
5431da177e4SLinus Torvalds 	/* clear interrupt enables, set irq latency */
5441da177e4SLinus Torvalds 	if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
5451da177e4SLinus Torvalds 		log2_irq_thresh = 0;
5461da177e4SLinus Torvalds 	temp = 1 << (16 + log2_irq_thresh);
5475a9cdf33SAlek Du 	if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
5485a9cdf33SAlek Du 		ehci->has_ppcd = 1;
5495a9cdf33SAlek Du 		ehci_dbg(ehci, "enable per-port change event\n");
5505a9cdf33SAlek Du 		temp |= CMD_PPCEE;
5515a9cdf33SAlek Du 	}
5521da177e4SLinus Torvalds 	if (HCC_CANPARK(hcc_params)) {
5531da177e4SLinus Torvalds 		/* HW default park == 3, on hardware that supports it (like
5541da177e4SLinus Torvalds 		 * NVidia and ALI silicon), maximizes throughput on the async
5551da177e4SLinus Torvalds 		 * schedule by avoiding QH fetches between transfers.
5561da177e4SLinus Torvalds 		 *
5571da177e4SLinus Torvalds 		 * With fast usb storage devices and NForce2, "park" seems to
5581da177e4SLinus Torvalds 		 * make problems:  throughput reduction (!), data errors...
5591da177e4SLinus Torvalds 		 */
5601da177e4SLinus Torvalds 		if (park) {
5611da177e4SLinus Torvalds 			park = min(park, (unsigned) 3);
5621da177e4SLinus Torvalds 			temp |= CMD_PARK;
5631da177e4SLinus Torvalds 			temp |= park << 8;
5641da177e4SLinus Torvalds 		}
56518807521SDavid Brownell 		ehci_dbg(ehci, "park %d\n", park);
5661da177e4SLinus Torvalds 	}
5671da177e4SLinus Torvalds 	if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
5681da177e4SLinus Torvalds 		/* periodic schedule size can be smaller than default */
5691da177e4SLinus Torvalds 		temp &= ~(3 << 2);
5701da177e4SLinus Torvalds 		temp |= (EHCI_TUNE_FLS << 2);
5711da177e4SLinus Torvalds 	}
57218807521SDavid Brownell 	ehci->command = temp;
57318807521SDavid Brownell 
57440f8db8fSAlan Stern 	/* Accept arbitrarily long scatter-gather lists */
5754307a28eSAndrea Righi 	if (!(hcd->driver->flags & HCD_LOCAL_MEM))
57640f8db8fSAlan Stern 		hcd->self.sg_tablesize = ~0;
57787d61912SAlan Stern 
57887d61912SAlan Stern 	/* Prepare for unlinking active QHs */
57987d61912SAlan Stern 	ehci->old_current = ~0;
58018807521SDavid Brownell 	return 0;
58118807521SDavid Brownell }
58218807521SDavid Brownell 
58318807521SDavid Brownell /* start HC running; it's halted, ehci_init() has been run (once) */
58418807521SDavid Brownell static int ehci_run (struct usb_hcd *hcd)
58518807521SDavid Brownell {
58618807521SDavid Brownell 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
58718807521SDavid Brownell 	u32			temp;
58818807521SDavid Brownell 	u32			hcc_params;
58918807521SDavid Brownell 
5901d619f12SMarcelo Tosatti 	hcd->uses_new_polling = 1;
5911d619f12SMarcelo Tosatti 
59218807521SDavid Brownell 	/* EHCI spec section 4.1 */
593876e0df9SGeoff Levand 
594083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
595083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
59618807521SDavid Brownell 
59718807521SDavid Brownell 	/*
59818807521SDavid Brownell 	 * hcc_params controls whether ehci->regs->segment must (!!!)
59918807521SDavid Brownell 	 * be used; it constrains QH/ITD/SITD and QTD locations.
60018807521SDavid Brownell 	 * pci_pool consistent memory always uses segment zero.
60118807521SDavid Brownell 	 * streaming mappings for I/O buffers, like pci_map_single(),
60218807521SDavid Brownell 	 * can return segments above 4GB, if the device allows.
60318807521SDavid Brownell 	 *
6040e77acefSChristoph Hellwig 	 * NOTE:  the dma mask is visible through dev->dma_mask, so
60518807521SDavid Brownell 	 * drivers can pass this info along ... like NETIF_F_HIGHDMA,
60618807521SDavid Brownell 	 * Scsi_Host.highmem_io, and so forth.  It's readonly to all
60718807521SDavid Brownell 	 * host side drivers though.
60818807521SDavid Brownell 	 */
609083522d7SBenjamin Herrenschmidt 	hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
61018807521SDavid Brownell 	if (HCC_64BIT_ADDR(hcc_params)) {
611083522d7SBenjamin Herrenschmidt 		ehci_writel(ehci, 0, &ehci->regs->segment);
61218807521SDavid Brownell #if 0
61318807521SDavid Brownell // this is deeply broken on almost all architectures
6146a35528aSYang Hongyang 		if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
61518807521SDavid Brownell 			ehci_info(ehci, "enabled 64bit DMA\n");
61618807521SDavid Brownell #endif
61718807521SDavid Brownell 	}
61818807521SDavid Brownell 
61918807521SDavid Brownell 
6201da177e4SLinus Torvalds 	// Philips, Intel, and maybe others need CMD_RUN before the
6211da177e4SLinus Torvalds 	// root hub will detect new devices (why?); NEC doesn't
62218807521SDavid Brownell 	ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
62318807521SDavid Brownell 	ehci->command |= CMD_RUN;
624083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, ehci->command, &ehci->regs->command);
62518807521SDavid Brownell 	dbg_cmd (ehci, "init", ehci->command);
6261da177e4SLinus Torvalds 
6271da177e4SLinus Torvalds 	/*
6281da177e4SLinus Torvalds 	 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
6291da177e4SLinus Torvalds 	 * are explicitly handed to companion controller(s), so no TT is
6301da177e4SLinus Torvalds 	 * involved with the root hub.  (Except where one is integrated,
6311da177e4SLinus Torvalds 	 * and there's no companion controller unless maybe for USB OTG.)
63232fe0198SAlan Stern 	 *
63332fe0198SAlan Stern 	 * Turning on the CF flag will transfer ownership of all ports
63432fe0198SAlan Stern 	 * from the companions to the EHCI controller.  If any of the
63532fe0198SAlan Stern 	 * companions are in the middle of a port reset at the time, it
63632fe0198SAlan Stern 	 * could cause trouble.  Write-locking ehci_cf_port_reset_rwsem
6371cb52658SDavid Brownell 	 * guarantees that no resets are in progress.  After we set CF,
6381cb52658SDavid Brownell 	 * a short delay lets the hardware catch up; new resets shouldn't
6391cb52658SDavid Brownell 	 * be started before the port switching actions could complete.
6401da177e4SLinus Torvalds 	 */
64132fe0198SAlan Stern 	down_write(&ehci_cf_port_reset_rwsem);
642e8799906SAlan Stern 	ehci->rh_state = EHCI_RH_RUNNING;
643083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
644083522d7SBenjamin Herrenschmidt 	ehci_readl(ehci, &ehci->regs->command);	/* unblock posted writes */
6451cb52658SDavid Brownell 	msleep(5);
64632fe0198SAlan Stern 	up_write(&ehci_cf_port_reset_rwsem);
647ee4ecb8aSOliver Neukum 	ehci->last_periodic_enable = ktime_get_real();
6481da177e4SLinus Torvalds 
649c430131aSJan Andersson 	temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
6501da177e4SLinus Torvalds 	ehci_info (ehci,
6512b70f073SAlan Stern 		"USB %x.%x started, EHCI %x.%02x%s\n",
6527ff71d6aSMatt Porter 		((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
6532b70f073SAlan Stern 		temp >> 8, temp & 0xff,
65493f1a47cSDavid Brownell 		ignore_oc ? ", overcurrent ignored" : "");
6551da177e4SLinus Torvalds 
656083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, INTR_MASK,
657083522d7SBenjamin Herrenschmidt 		    &ehci->regs->intr_enable); /* Turn On Interrupts */
6581da177e4SLinus Torvalds 
65918807521SDavid Brownell 	/* GRR this is run-once init(), being done every time the HC starts.
66018807521SDavid Brownell 	 * So long as they're part of class devices, we can't do it init()
66118807521SDavid Brownell 	 * since the class device isn't created that early.
66218807521SDavid Brownell 	 */
6631da177e4SLinus Torvalds 	create_debug_files(ehci);
6644c67045bSKirill Smelkov 	create_sysfs_files(ehci);
6651da177e4SLinus Torvalds 
6661da177e4SLinus Torvalds 	return 0;
6671da177e4SLinus Torvalds }
6681da177e4SLinus Torvalds 
6693e023203SAlan Stern int ehci_setup(struct usb_hcd *hcd)
6702093c6b4SMatthieu CASTET {
6712093c6b4SMatthieu CASTET 	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
6722093c6b4SMatthieu CASTET 	int retval;
6732093c6b4SMatthieu CASTET 
6742093c6b4SMatthieu CASTET 	ehci->regs = (void __iomem *)ehci->caps +
6752093c6b4SMatthieu CASTET 	    HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
6762093c6b4SMatthieu CASTET 	dbg_hcs_params(ehci, "reset");
6772093c6b4SMatthieu CASTET 	dbg_hcc_params(ehci, "reset");
6782093c6b4SMatthieu CASTET 
6792093c6b4SMatthieu CASTET 	/* cache this readonly data; minimize chip reads */
6802093c6b4SMatthieu CASTET 	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
6812093c6b4SMatthieu CASTET 
6822093c6b4SMatthieu CASTET 	ehci->sbrn = HCD_USB2;
6832093c6b4SMatthieu CASTET 
6842093c6b4SMatthieu CASTET 	/* data structure init */
6852093c6b4SMatthieu CASTET 	retval = ehci_init(hcd);
6862093c6b4SMatthieu CASTET 	if (retval)
6872093c6b4SMatthieu CASTET 		return retval;
6882093c6b4SMatthieu CASTET 
689631fe9d9SAlan Stern 	retval = ehci_halt(ehci);
690d8ff463aSJia-Ju Bai 	if (retval) {
691d8ff463aSJia-Ju Bai 		ehci_mem_cleanup(ehci);
6922093c6b4SMatthieu CASTET 		return retval;
693d8ff463aSJia-Ju Bai 	}
6942093c6b4SMatthieu CASTET 
6952093c6b4SMatthieu CASTET 	ehci_reset(ehci);
6962093c6b4SMatthieu CASTET 
6972093c6b4SMatthieu CASTET 	return 0;
6982093c6b4SMatthieu CASTET }
6993e023203SAlan Stern EXPORT_SYMBOL_GPL(ehci_setup);
7002093c6b4SMatthieu CASTET 
7011da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
7021da177e4SLinus Torvalds 
7037d12e780SDavid Howells static irqreturn_t ehci_irq (struct usb_hcd *hcd)
7041da177e4SLinus Torvalds {
7051da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
70667b2e029SAlan Stern 	u32			status, masked_status, pcd_status = 0, cmd;
7071da177e4SLinus Torvalds 	int			bh;
708a1227f3cSStanislaw Gruszka 	unsigned long		flags;
7091da177e4SLinus Torvalds 
710a1227f3cSStanislaw Gruszka 	/*
711a1227f3cSStanislaw Gruszka 	 * For threadirqs option we use spin_lock_irqsave() variant to prevent
712a1227f3cSStanislaw Gruszka 	 * deadlock with ehci hrtimer callback, because hrtimer callbacks run
713a1227f3cSStanislaw Gruszka 	 * in interrupt context even when threadirqs is specified. We can go
714a1227f3cSStanislaw Gruszka 	 * back to spin_lock() variant when hrtimer callbacks become threaded.
715a1227f3cSStanislaw Gruszka 	 */
716a1227f3cSStanislaw Gruszka 	spin_lock_irqsave(&ehci->lock, flags);
7171da177e4SLinus Torvalds 
718083522d7SBenjamin Herrenschmidt 	status = ehci_readl(ehci, &ehci->regs->status);
7191da177e4SLinus Torvalds 
7201da177e4SLinus Torvalds 	/* e.g. cardbus physical eject */
7211da177e4SLinus Torvalds 	if (status == ~(u32) 0) {
7221da177e4SLinus Torvalds 		ehci_dbg (ehci, "device removed\n");
7231da177e4SLinus Torvalds 		goto dead;
7241da177e4SLinus Torvalds 	}
7251da177e4SLinus Torvalds 
7262fbe2bf1SAlan Stern 	/*
7272fbe2bf1SAlan Stern 	 * We don't use STS_FLR, but some controllers don't like it to
7282fbe2bf1SAlan Stern 	 * remain on, so mask it out along with the other status bits.
7292fbe2bf1SAlan Stern 	 */
7302fbe2bf1SAlan Stern 	masked_status = status & (INTR_MASK | STS_FLR);
7312fbe2bf1SAlan Stern 
73269fff59dSAlan Stern 	/* Shared IRQ? */
733e8799906SAlan Stern 	if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
734a1227f3cSStanislaw Gruszka 		spin_unlock_irqrestore(&ehci->lock, flags);
7351da177e4SLinus Torvalds 		return IRQ_NONE;
7361da177e4SLinus Torvalds 	}
7371da177e4SLinus Torvalds 
7381da177e4SLinus Torvalds 	/* clear (just) interrupts */
73967b2e029SAlan Stern 	ehci_writel(ehci, masked_status, &ehci->regs->status);
740e82cc128SDavid Brownell 	cmd = ehci_readl(ehci, &ehci->regs->command);
7411da177e4SLinus Torvalds 	bh = 0;
7421da177e4SLinus Torvalds 
7431da177e4SLinus Torvalds 	/* normal [4.15.1.2] or error [4.15.1.1] completion */
7441da177e4SLinus Torvalds 	if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
7451da177e4SLinus Torvalds 		if (likely ((status & STS_ERR) == 0))
7461da177e4SLinus Torvalds 			COUNT (ehci->stats.normal);
7471da177e4SLinus Torvalds 		else
7481da177e4SLinus Torvalds 			COUNT (ehci->stats.error);
7491da177e4SLinus Torvalds 		bh = 1;
7501da177e4SLinus Torvalds 	}
7511da177e4SLinus Torvalds 
7521da177e4SLinus Torvalds 	/* complete the unlinking of some qh [4.15.2.3] */
7531da177e4SLinus Torvalds 	if (status & STS_IAA) {
7549d938747SAlan Stern 
7559d938747SAlan Stern 		/* Turn off the IAA watchdog */
7569d938747SAlan Stern 		ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG);
7579d938747SAlan Stern 
7589d938747SAlan Stern 		/*
7599d938747SAlan Stern 		 * Mild optimization: Allow another IAAD to reset the
7609d938747SAlan Stern 		 * hrtimer, if one occurs before the next expiration.
7619d938747SAlan Stern 		 * In theory we could always cancel the hrtimer, but
7629d938747SAlan Stern 		 * tests show that about half the time it will be reset
7639d938747SAlan Stern 		 * for some other event anyway.
7649d938747SAlan Stern 		 */
7659d938747SAlan Stern 		if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG)
7669d938747SAlan Stern 			++ehci->next_hrtimer_event;
7679d938747SAlan Stern 
768e82cc128SDavid Brownell 		/* guard against (alleged) silicon errata */
7696feff1b9SAlan Stern 		if (cmd & CMD_IAAD)
770e82cc128SDavid Brownell 			ehci_dbg(ehci, "IAA with IAAD still set?\n");
771214ac7a0SAlan Stern 		if (ehci->iaa_in_progress)
77299ac5b1eSAlan Stern 			COUNT(ehci->stats.iaa);
773f96fba0dSAlan Stern 		end_iaa_cycle(ehci);
7741da177e4SLinus Torvalds 	}
7751da177e4SLinus Torvalds 
7761da177e4SLinus Torvalds 	/* remote wakeup [4.3.1] */
777d97cc2f2SDavid Brownell 	if (status & STS_PCD) {
7781da177e4SLinus Torvalds 		unsigned	i = HCS_N_PORTS (ehci->hcs_params);
7794dd405a4SAlan Stern 		u32		ppcd = ~0;
780d1b1842cSDavid Brownell 
781d1b1842cSDavid Brownell 		/* kick root hub later */
7821d619f12SMarcelo Tosatti 		pcd_status = status;
7831da177e4SLinus Torvalds 
7841da177e4SLinus Torvalds 		/* resume root hub? */
785dc75ce9dSAlan Stern 		if (ehci->rh_state == EHCI_RH_SUSPENDED)
7868c03356aSAlan Stern 			usb_hcd_resume_root_hub(hcd);
7871da177e4SLinus Torvalds 
7885a9cdf33SAlek Du 		/* get per-port change detect bits */
7895a9cdf33SAlek Du 		if (ehci->has_ppcd)
7905a9cdf33SAlek Du 			ppcd = status >> 16;
7915a9cdf33SAlek Du 
7921da177e4SLinus Torvalds 		while (i--) {
7935a9cdf33SAlek Du 			int pstatus;
7945a9cdf33SAlek Du 
7955a9cdf33SAlek Du 			/* leverage per-port change bits feature */
7964dd405a4SAlan Stern 			if (!(ppcd & (1 << i)))
7975a9cdf33SAlek Du 				continue;
7985a9cdf33SAlek Du 			pstatus = ehci_readl(ehci,
799083522d7SBenjamin Herrenschmidt 					 &ehci->regs->port_status[i]);
800b972b68cSDavid Brownell 
801b972b68cSDavid Brownell 			if (pstatus & PORT_OWNER)
8021da177e4SLinus Torvalds 				continue;
803eafe5b99SAlan Stern 			if (!(test_bit(i, &ehci->suspended_ports) &&
804eafe5b99SAlan Stern 					((pstatus & PORT_RESUME) ||
805eafe5b99SAlan Stern 						!(pstatus & PORT_SUSPEND)) &&
806eafe5b99SAlan Stern 					(pstatus & PORT_PE) &&
807eafe5b99SAlan Stern 					ehci->reset_done[i] == 0))
8081da177e4SLinus Torvalds 				continue;
8091da177e4SLinus Torvalds 
810ea16328fSFelipe Balbi 			/* start USB_RESUME_TIMEOUT msec resume signaling from
811ea16328fSFelipe Balbi 			 * this port, and make hub_wq collect
812ea16328fSFelipe Balbi 			 * PORT_STAT_C_SUSPEND to stop that signaling.
8131da177e4SLinus Torvalds 			 */
814ea16328fSFelipe Balbi 			ehci->reset_done[i] = jiffies +
815ea16328fSFelipe Balbi 				msecs_to_jiffies(USB_RESUME_TIMEOUT);
816a448e4dcSAlan Stern 			set_bit(i, &ehci->resuming_ports);
8171da177e4SLinus Torvalds 			ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
818f292e7f9SAlan Stern 			usb_hcd_start_port_resume(&hcd->self, i);
81961e8b858SAlan Stern 			mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
8201da177e4SLinus Torvalds 		}
8211da177e4SLinus Torvalds 	}
8221da177e4SLinus Torvalds 
8231da177e4SLinus Torvalds 	/* PCI errors [4.15.2.4] */
8241da177e4SLinus Torvalds 	if (unlikely ((status & STS_FATAL) != 0)) {
82567b2e029SAlan Stern 		ehci_err(ehci, "fatal error\n");
826eafe5b99SAlan Stern 		dbg_cmd(ehci, "fatal", cmd);
8271da177e4SLinus Torvalds 		dbg_status(ehci, "fatal", status);
8281da177e4SLinus Torvalds dead:
82969fff59dSAlan Stern 		usb_hc_died(hcd);
830bf6387bcSAlan Stern 
831bf6387bcSAlan Stern 		/* Don't let the controller do anything more */
83243fe3a99SAlan Stern 		ehci->shutdown = true;
833bf6387bcSAlan Stern 		ehci->rh_state = EHCI_RH_STOPPING;
834bf6387bcSAlan Stern 		ehci->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
835bf6387bcSAlan Stern 		ehci_writel(ehci, ehci->command, &ehci->regs->command);
836bf6387bcSAlan Stern 		ehci_writel(ehci, 0, &ehci->regs->intr_enable);
837bf6387bcSAlan Stern 		ehci_handle_controller_death(ehci);
838bf6387bcSAlan Stern 
839bf6387bcSAlan Stern 		/* Handle completions when the controller stops */
840bf6387bcSAlan Stern 		bh = 0;
8411da177e4SLinus Torvalds 	}
8421da177e4SLinus Torvalds 
8431da177e4SLinus Torvalds 	if (bh)
8447d12e780SDavid Howells 		ehci_work (ehci);
845a1227f3cSStanislaw Gruszka 	spin_unlock_irqrestore(&ehci->lock, flags);
846d1b1842cSDavid Brownell 	if (pcd_status)
8471d619f12SMarcelo Tosatti 		usb_hcd_poll_rh_status(hcd);
8481da177e4SLinus Torvalds 	return IRQ_HANDLED;
8491da177e4SLinus Torvalds }
8501da177e4SLinus Torvalds 
8511da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
8521da177e4SLinus Torvalds 
8531da177e4SLinus Torvalds /*
8541da177e4SLinus Torvalds  * non-error returns are a promise to giveback() the urb later
8551da177e4SLinus Torvalds  * we drop ownership so next owner (or urb unlink) can get it
8561da177e4SLinus Torvalds  *
8571da177e4SLinus Torvalds  * urb + dev is in hcd.self.controller.urb_list
8581da177e4SLinus Torvalds  * we're queueing TDs onto software and hardware lists
8591da177e4SLinus Torvalds  *
8601da177e4SLinus Torvalds  * hcd-specific init for hcpriv hasn't been done yet
8611da177e4SLinus Torvalds  *
8621da177e4SLinus Torvalds  * NOTE:  control, bulk, and interrupt share the same code to append TDs
8631da177e4SLinus Torvalds  * to a (possibly active) QH, and the same QH scanning code.
8641da177e4SLinus Torvalds  */
8651da177e4SLinus Torvalds static int ehci_urb_enqueue (
8661da177e4SLinus Torvalds 	struct usb_hcd	*hcd,
8671da177e4SLinus Torvalds 	struct urb	*urb,
86855016f10SAl Viro 	gfp_t		mem_flags
8691da177e4SLinus Torvalds ) {
8701da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
8711da177e4SLinus Torvalds 	struct list_head	qtd_list;
8721da177e4SLinus Torvalds 
8731da177e4SLinus Torvalds 	INIT_LIST_HEAD (&qtd_list);
8741da177e4SLinus Torvalds 
8751da177e4SLinus Torvalds 	switch (usb_pipetype (urb->pipe)) {
87625b70a86SDavid Brownell 	case PIPE_CONTROL:
87725b70a86SDavid Brownell 		/* qh_completions() code doesn't handle all the fault cases
87825b70a86SDavid Brownell 		 * in multi-TD control transfers.  Even 1KB is rare anyway.
87925b70a86SDavid Brownell 		 */
88025b70a86SDavid Brownell 		if (urb->transfer_buffer_length > (16 * 1024))
88125b70a86SDavid Brownell 			return -EMSGSIZE;
88225b70a86SDavid Brownell 		/* FALLTHROUGH */
88325b70a86SDavid Brownell 	/* case PIPE_BULK: */
8841da177e4SLinus Torvalds 	default:
8851da177e4SLinus Torvalds 		if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
8861da177e4SLinus Torvalds 			return -ENOMEM;
887e9df41c5SAlan Stern 		return submit_async(ehci, urb, &qtd_list, mem_flags);
8881da177e4SLinus Torvalds 
8891da177e4SLinus Torvalds 	case PIPE_INTERRUPT:
8901da177e4SLinus Torvalds 		if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
8911da177e4SLinus Torvalds 			return -ENOMEM;
892e9df41c5SAlan Stern 		return intr_submit(ehci, urb, &qtd_list, mem_flags);
8931da177e4SLinus Torvalds 
8941da177e4SLinus Torvalds 	case PIPE_ISOCHRONOUS:
8951da177e4SLinus Torvalds 		if (urb->dev->speed == USB_SPEED_HIGH)
8961da177e4SLinus Torvalds 			return itd_submit (ehci, urb, mem_flags);
8971da177e4SLinus Torvalds 		else
8981da177e4SLinus Torvalds 			return sitd_submit (ehci, urb, mem_flags);
8991da177e4SLinus Torvalds 	}
9001da177e4SLinus Torvalds }
9011da177e4SLinus Torvalds 
9021da177e4SLinus Torvalds /* remove from hardware lists
9031da177e4SLinus Torvalds  * completions normally happen asynchronously
9041da177e4SLinus Torvalds  */
9051da177e4SLinus Torvalds 
906e9df41c5SAlan Stern static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
9071da177e4SLinus Torvalds {
9081da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
9091da177e4SLinus Torvalds 	struct ehci_qh		*qh;
9101da177e4SLinus Torvalds 	unsigned long		flags;
911e9df41c5SAlan Stern 	int			rc;
9121da177e4SLinus Torvalds 
9131da177e4SLinus Torvalds 	spin_lock_irqsave (&ehci->lock, flags);
914e9df41c5SAlan Stern 	rc = usb_hcd_check_unlink_urb(hcd, urb, status);
915e9df41c5SAlan Stern 	if (rc)
916e9df41c5SAlan Stern 		goto done;
917e9df41c5SAlan Stern 
9187655e316SAlan Stern 	if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
9197655e316SAlan Stern 		/*
9207655e316SAlan Stern 		 * We don't expedite dequeue for isochronous URBs.
9217655e316SAlan Stern 		 * Just wait until they complete normally or their
9227655e316SAlan Stern 		 * time slot expires.
9237655e316SAlan Stern 		 */
9247655e316SAlan Stern 	} else {
9251da177e4SLinus Torvalds 		qh = (struct ehci_qh *) urb->hcpriv;
926fcc5184eSAlan Stern 		qh->unlink_reason |= QH_UNLINK_REQUESTED;
92707d29b63SAlan Stern 		switch (qh->qh_state) {
92807d29b63SAlan Stern 		case QH_STATE_LINKED:
9297655e316SAlan Stern 			if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)
9307655e316SAlan Stern 				start_unlink_intr(ehci, qh);
9317655e316SAlan Stern 			else
9323c273a05SAlan Stern 				start_unlink_async(ehci, qh);
9331da177e4SLinus Torvalds 			break;
9347bc782d7SAlan Stern 		case QH_STATE_COMPLETING:
9357bc782d7SAlan Stern 			qh->dequeue_during_giveback = 1;
9367bc782d7SAlan Stern 			break;
93707d29b63SAlan Stern 		case QH_STATE_UNLINK:
93807d29b63SAlan Stern 		case QH_STATE_UNLINK_WAIT:
93907d29b63SAlan Stern 			/* already started */
94007d29b63SAlan Stern 			break;
94107d29b63SAlan Stern 		case QH_STATE_IDLE:
9427a0f0d95SAlan Stern 			/* QH might be waiting for a Clear-TT-Buffer */
9437a0f0d95SAlan Stern 			qh_completions(ehci, qh);
94407d29b63SAlan Stern 			break;
94507d29b63SAlan Stern 		}
9461da177e4SLinus Torvalds 	}
9471da177e4SLinus Torvalds done:
9481da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ehci->lock, flags);
949e9df41c5SAlan Stern 	return rc;
9501da177e4SLinus Torvalds }
9511da177e4SLinus Torvalds 
9521da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
9531da177e4SLinus Torvalds 
9541da177e4SLinus Torvalds // bulk qh holds the data toggle
9551da177e4SLinus Torvalds 
9561da177e4SLinus Torvalds static void
9571da177e4SLinus Torvalds ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
9581da177e4SLinus Torvalds {
9591da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
9601da177e4SLinus Torvalds 	unsigned long		flags;
96135371e4fSMing Lei 	struct ehci_qh		*qh;
9621da177e4SLinus Torvalds 
9631da177e4SLinus Torvalds 	/* ASSERT:  any requests/urbs are being unlinked */
9641da177e4SLinus Torvalds 	/* ASSERT:  nobody can be submitting urbs for this any more */
9651da177e4SLinus Torvalds 
9661da177e4SLinus Torvalds rescan:
9671da177e4SLinus Torvalds 	spin_lock_irqsave (&ehci->lock, flags);
9681da177e4SLinus Torvalds 	qh = ep->hcpriv;
9691da177e4SLinus Torvalds 	if (!qh)
9701da177e4SLinus Torvalds 		goto done;
9711da177e4SLinus Torvalds 
9721da177e4SLinus Torvalds 	/* endpoints can be iso streams.  for now, we don't
9731da177e4SLinus Torvalds 	 * accelerate iso completions ... so spin a while.
9741da177e4SLinus Torvalds 	 */
9751082f57aSClemens Ladisch 	if (qh->hw == NULL) {
9768c5bf7beSAlan Stern 		struct ehci_iso_stream	*stream = ep->hcpriv;
9778c5bf7beSAlan Stern 
9788c5bf7beSAlan Stern 		if (!list_empty(&stream->td_list))
9791da177e4SLinus Torvalds 			goto idle_timeout;
9808c5bf7beSAlan Stern 
9818c5bf7beSAlan Stern 		/* BUG_ON(!list_empty(&stream->free_list)); */
982d0ce5c6bSAlan Stern 		reserve_release_iso_bandwidth(ehci, stream, -1);
9838c5bf7beSAlan Stern 		kfree(stream);
9848c5bf7beSAlan Stern 		goto done;
9851da177e4SLinus Torvalds 	}
9861da177e4SLinus Torvalds 
987fcc5184eSAlan Stern 	qh->unlink_reason |= QH_UNLINK_REQUESTED;
9881da177e4SLinus Torvalds 	switch (qh->qh_state) {
9891da177e4SLinus Torvalds 	case QH_STATE_LINKED:
990fcc5184eSAlan Stern 		if (list_empty(&qh->qtd_list))
991fcc5184eSAlan Stern 			qh->unlink_reason |= QH_UNLINK_QUEUE_EMPTY;
992fcc5184eSAlan Stern 		else
993fcc5184eSAlan Stern 			WARN_ON(1);
99435371e4fSMing Lei 		if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_INT)
9953c273a05SAlan Stern 			start_unlink_async(ehci, qh);
99635371e4fSMing Lei 		else
99735371e4fSMing Lei 			start_unlink_intr(ehci, qh);
9981da177e4SLinus Torvalds 		/* FALL THROUGH */
99935371e4fSMing Lei 	case QH_STATE_COMPLETING:	/* already in unlinking */
10001da177e4SLinus Torvalds 	case QH_STATE_UNLINK:		/* wait for hw to finish? */
100107d29b63SAlan Stern 	case QH_STATE_UNLINK_WAIT:
10021da177e4SLinus Torvalds idle_timeout:
10031da177e4SLinus Torvalds 		spin_unlock_irqrestore (&ehci->lock, flags);
100422c43863SNishanth Aravamudan 		schedule_timeout_uninterruptible(1);
10051da177e4SLinus Torvalds 		goto rescan;
10061da177e4SLinus Torvalds 	case QH_STATE_IDLE:		/* fully unlinked */
1007914b7012SAlan Stern 		if (qh->clearing_tt)
1008914b7012SAlan Stern 			goto idle_timeout;
10091da177e4SLinus Torvalds 		if (list_empty (&qh->qtd_list)) {
1010d0ce5c6bSAlan Stern 			if (qh->ps.bw_uperiod)
1011d0ce5c6bSAlan Stern 				reserve_release_intr_bandwidth(ehci, qh, -1);
1012c83e1a9fSAlan Stern 			qh_destroy(ehci, qh);
10131da177e4SLinus Torvalds 			break;
10141da177e4SLinus Torvalds 		}
10151da177e4SLinus Torvalds 		/* else FALL THROUGH */
10161da177e4SLinus Torvalds 	default:
10171da177e4SLinus Torvalds 		/* caller was supposed to have unlinked any requests;
10181da177e4SLinus Torvalds 		 * that's not our job.  just leak this memory.
10191da177e4SLinus Torvalds 		 */
10201da177e4SLinus Torvalds 		ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
10211da177e4SLinus Torvalds 			qh, ep->desc.bEndpointAddress, qh->qh_state,
10221da177e4SLinus Torvalds 			list_empty (&qh->qtd_list) ? "" : "(has tds)");
10231da177e4SLinus Torvalds 		break;
10241da177e4SLinus Torvalds 	}
10251da177e4SLinus Torvalds  done:
10268c5bf7beSAlan Stern 	ep->hcpriv = NULL;
10271da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ehci->lock, flags);
10281da177e4SLinus Torvalds }
10291da177e4SLinus Torvalds 
1030b18ffd49SAlan Stern static void
1031b18ffd49SAlan Stern ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1032b18ffd49SAlan Stern {
1033b18ffd49SAlan Stern 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
1034b18ffd49SAlan Stern 	struct ehci_qh		*qh;
1035b18ffd49SAlan Stern 	int			eptype = usb_endpoint_type(&ep->desc);
1036a455212dSAlan Stern 	int			epnum = usb_endpoint_num(&ep->desc);
1037a455212dSAlan Stern 	int			is_out = usb_endpoint_dir_out(&ep->desc);
1038a455212dSAlan Stern 	unsigned long		flags;
1039b18ffd49SAlan Stern 
1040b18ffd49SAlan Stern 	if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
1041b18ffd49SAlan Stern 		return;
1042b18ffd49SAlan Stern 
1043a455212dSAlan Stern 	spin_lock_irqsave(&ehci->lock, flags);
1044b18ffd49SAlan Stern 	qh = ep->hcpriv;
1045b18ffd49SAlan Stern 
1046b18ffd49SAlan Stern 	/* For Bulk and Interrupt endpoints we maintain the toggle state
1047b18ffd49SAlan Stern 	 * in the hardware; the toggle bits in udev aren't used at all.
1048b18ffd49SAlan Stern 	 * When an endpoint is reset by usb_clear_halt() we must reset
1049b18ffd49SAlan Stern 	 * the toggle bit in the QH.
1050b18ffd49SAlan Stern 	 */
1051b18ffd49SAlan Stern 	if (qh) {
1052b18ffd49SAlan Stern 		if (!list_empty(&qh->qtd_list)) {
1053b18ffd49SAlan Stern 			WARN_ONCE(1, "clear_halt for a busy endpoint\n");
10547bc782d7SAlan Stern 		} else {
1055a455212dSAlan Stern 			/* The toggle value in the QH can't be updated
1056a455212dSAlan Stern 			 * while the QH is active.  Unlink it now;
1057a455212dSAlan Stern 			 * re-linking will call qh_refresh().
1058b18ffd49SAlan Stern 			 */
1059ffa0248eSAlan Stern 			usb_settoggle(qh->ps.udev, epnum, is_out, 0);
1060fcc5184eSAlan Stern 			qh->unlink_reason |= QH_UNLINK_REQUESTED;
1061a448c9d8SAlan Stern 			if (eptype == USB_ENDPOINT_XFER_BULK)
10623c273a05SAlan Stern 				start_unlink_async(ehci, qh);
1063a448c9d8SAlan Stern 			else
1064df202255SAlan Stern 				start_unlink_intr(ehci, qh);
1065b18ffd49SAlan Stern 		}
1066b18ffd49SAlan Stern 	}
1067a455212dSAlan Stern 	spin_unlock_irqrestore(&ehci->lock, flags);
1068b18ffd49SAlan Stern }
1069b18ffd49SAlan Stern 
10707ff71d6aSMatt Porter static int ehci_get_frame (struct usb_hcd *hcd)
10717ff71d6aSMatt Porter {
10727ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
107368aa95d5SAlan Stern 	return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size;
10747ff71d6aSMatt Porter }
10751da177e4SLinus Torvalds 
10761da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
1077c5cf9212SAlan Stern 
1078b35c5009SAlan Stern /* Device addition and removal */
1079b35c5009SAlan Stern 
1080b35c5009SAlan Stern static void ehci_remove_device(struct usb_hcd *hcd, struct usb_device *udev)
1081b35c5009SAlan Stern {
1082b35c5009SAlan Stern 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
1083b35c5009SAlan Stern 
1084b35c5009SAlan Stern 	spin_lock_irq(&ehci->lock);
1085b35c5009SAlan Stern 	drop_tt(udev);
1086b35c5009SAlan Stern 	spin_unlock_irq(&ehci->lock);
1087b35c5009SAlan Stern }
1088b35c5009SAlan Stern 
1089b35c5009SAlan Stern /*-------------------------------------------------------------------------*/
1090b35c5009SAlan Stern 
1091c5cf9212SAlan Stern #ifdef	CONFIG_PM
1092c5cf9212SAlan Stern 
1093c5cf9212SAlan Stern /* suspend/resume, section 4.3 */
1094c5cf9212SAlan Stern 
1095c5cf9212SAlan Stern /* These routines handle the generic parts of controller suspend/resume */
1096c5cf9212SAlan Stern 
10973e023203SAlan Stern int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
1098c5cf9212SAlan Stern {
1099c5cf9212SAlan Stern 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
1100c5cf9212SAlan Stern 
1101c5cf9212SAlan Stern 	if (time_before(jiffies, ehci->next_statechange))
1102c5cf9212SAlan Stern 		msleep(10);
1103c5cf9212SAlan Stern 
1104c5cf9212SAlan Stern 	/*
1105c5cf9212SAlan Stern 	 * Root hub was already suspended.  Disable IRQ emission and
1106c5cf9212SAlan Stern 	 * mark HW unaccessible.  The PM and USB cores make sure that
1107c5cf9212SAlan Stern 	 * the root hub is either suspended or stopped.
1108c5cf9212SAlan Stern 	 */
1109c5cf9212SAlan Stern 	ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
1110c5cf9212SAlan Stern 
1111c5cf9212SAlan Stern 	spin_lock_irq(&ehci->lock);
1112c5cf9212SAlan Stern 	ehci_writel(ehci, 0, &ehci->regs->intr_enable);
1113c5cf9212SAlan Stern 	(void) ehci_readl(ehci, &ehci->regs->intr_enable);
1114c5cf9212SAlan Stern 
1115c5cf9212SAlan Stern 	clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1116c5cf9212SAlan Stern 	spin_unlock_irq(&ehci->lock);
1117c5cf9212SAlan Stern 
1118b8efdafbSAlan Stern 	synchronize_irq(hcd->irq);
1119b8efdafbSAlan Stern 
1120b8efdafbSAlan Stern 	/* Check for race with a wakeup request */
1121b8efdafbSAlan Stern 	if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
1122b8efdafbSAlan Stern 		ehci_resume(hcd, false);
1123b8efdafbSAlan Stern 		return -EBUSY;
1124b8efdafbSAlan Stern 	}
1125b8efdafbSAlan Stern 
1126c5cf9212SAlan Stern 	return 0;
1127c5cf9212SAlan Stern }
11283e023203SAlan Stern EXPORT_SYMBOL_GPL(ehci_suspend);
1129c5cf9212SAlan Stern 
1130c5cf9212SAlan Stern /* Returns 0 if power was preserved, 1 if power was lost */
1131314b41b1SWu Liang feng int ehci_resume(struct usb_hcd *hcd, bool force_reset)
1132c5cf9212SAlan Stern {
1133c5cf9212SAlan Stern 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
1134c5cf9212SAlan Stern 
1135c5cf9212SAlan Stern 	if (time_before(jiffies, ehci->next_statechange))
1136c5cf9212SAlan Stern 		msleep(100);
1137c5cf9212SAlan Stern 
1138c5cf9212SAlan Stern 	/* Mark hardware accessible again as we are back to full power by now */
1139c5cf9212SAlan Stern 	set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1140c5cf9212SAlan Stern 
114143fe3a99SAlan Stern 	if (ehci->shutdown)
114243fe3a99SAlan Stern 		return 0;		/* Controller is dead */
114343fe3a99SAlan Stern 
1144c5cf9212SAlan Stern 	/*
1145314b41b1SWu Liang feng 	 * If CF is still set and reset isn't forced
1146c5cf9212SAlan Stern 	 * then we maintained suspend power.
1147c5cf9212SAlan Stern 	 * Just undo the effect of ehci_suspend().
1148c5cf9212SAlan Stern 	 */
1149c5cf9212SAlan Stern 	if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
1150314b41b1SWu Liang feng 			!force_reset) {
1151c5cf9212SAlan Stern 		int	mask = INTR_MASK;
1152c5cf9212SAlan Stern 
1153c5cf9212SAlan Stern 		ehci_prepare_ports_for_controller_resume(ehci);
115443fe3a99SAlan Stern 
115543fe3a99SAlan Stern 		spin_lock_irq(&ehci->lock);
115643fe3a99SAlan Stern 		if (ehci->shutdown)
115743fe3a99SAlan Stern 			goto skip;
115843fe3a99SAlan Stern 
1159c5cf9212SAlan Stern 		if (!hcd->self.root_hub->do_remote_wakeup)
1160c5cf9212SAlan Stern 			mask &= ~STS_PCD;
1161c5cf9212SAlan Stern 		ehci_writel(ehci, mask, &ehci->regs->intr_enable);
1162c5cf9212SAlan Stern 		ehci_readl(ehci, &ehci->regs->intr_enable);
116343fe3a99SAlan Stern  skip:
116443fe3a99SAlan Stern 		spin_unlock_irq(&ehci->lock);
1165c5cf9212SAlan Stern 		return 0;
1166c5cf9212SAlan Stern 	}
1167c5cf9212SAlan Stern 
1168c5cf9212SAlan Stern 	/*
1169c5cf9212SAlan Stern 	 * Else reset, to cope with power loss or resume from hibernation
1170c5cf9212SAlan Stern 	 * having let the firmware kick in during reboot.
1171c5cf9212SAlan Stern 	 */
1172c5cf9212SAlan Stern 	usb_root_hub_lost_power(hcd->self.root_hub);
1173c5cf9212SAlan Stern 	(void) ehci_halt(ehci);
1174c5cf9212SAlan Stern 	(void) ehci_reset(ehci);
1175c5cf9212SAlan Stern 
117643fe3a99SAlan Stern 	spin_lock_irq(&ehci->lock);
117743fe3a99SAlan Stern 	if (ehci->shutdown)
117843fe3a99SAlan Stern 		goto skip;
117943fe3a99SAlan Stern 
1180c5cf9212SAlan Stern 	ehci_writel(ehci, ehci->command, &ehci->regs->command);
1181c5cf9212SAlan Stern 	ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
1182c5cf9212SAlan Stern 	ehci_readl(ehci, &ehci->regs->command);	/* unblock posted writes */
1183c5cf9212SAlan Stern 
118443fe3a99SAlan Stern 	ehci->rh_state = EHCI_RH_SUSPENDED;
118543fe3a99SAlan Stern 	spin_unlock_irq(&ehci->lock);
118643fe3a99SAlan Stern 
1187c5cf9212SAlan Stern 	return 1;
1188c5cf9212SAlan Stern }
11893e023203SAlan Stern EXPORT_SYMBOL_GPL(ehci_resume);
1190c5cf9212SAlan Stern 
1191c5cf9212SAlan Stern #endif
1192c5cf9212SAlan Stern 
1193c5cf9212SAlan Stern /*-------------------------------------------------------------------------*/
1194c5cf9212SAlan Stern 
1195eb70e5abSAlexander Shishkin /*
11963e023203SAlan Stern  * Generic structure: This gets copied for platform drivers so that
11973e023203SAlan Stern  * individual entries can be overridden as needed.
11983e023203SAlan Stern  */
11993e023203SAlan Stern 
12003e023203SAlan Stern static const struct hc_driver ehci_hc_driver = {
12013e023203SAlan Stern 	.description =		hcd_name,
12023e023203SAlan Stern 	.product_desc =		"EHCI Host Controller",
12033e023203SAlan Stern 	.hcd_priv_size =	sizeof(struct ehci_hcd),
12043e023203SAlan Stern 
12053e023203SAlan Stern 	/*
12063e023203SAlan Stern 	 * generic hardware linkage
12073e023203SAlan Stern 	 */
12083e023203SAlan Stern 	.irq =			ehci_irq,
1209c04ee4b1SGreg Kroah-Hartman 	.flags =		HCD_MEMORY | HCD_USB2 | HCD_BH,
12103e023203SAlan Stern 
12113e023203SAlan Stern 	/*
12123e023203SAlan Stern 	 * basic lifecycle operations
12133e023203SAlan Stern 	 */
12143e023203SAlan Stern 	.reset =		ehci_setup,
12153e023203SAlan Stern 	.start =		ehci_run,
12163e023203SAlan Stern 	.stop =			ehci_stop,
12173e023203SAlan Stern 	.shutdown =		ehci_shutdown,
12183e023203SAlan Stern 
12193e023203SAlan Stern 	/*
12203e023203SAlan Stern 	 * managing i/o requests and associated device resources
12213e023203SAlan Stern 	 */
12223e023203SAlan Stern 	.urb_enqueue =		ehci_urb_enqueue,
12233e023203SAlan Stern 	.urb_dequeue =		ehci_urb_dequeue,
12243e023203SAlan Stern 	.endpoint_disable =	ehci_endpoint_disable,
12253e023203SAlan Stern 	.endpoint_reset =	ehci_endpoint_reset,
12263e023203SAlan Stern 	.clear_tt_buffer_complete =	ehci_clear_tt_buffer_complete,
12273e023203SAlan Stern 
12283e023203SAlan Stern 	/*
12293e023203SAlan Stern 	 * scheduling support
12303e023203SAlan Stern 	 */
12313e023203SAlan Stern 	.get_frame_number =	ehci_get_frame,
12323e023203SAlan Stern 
12333e023203SAlan Stern 	/*
12343e023203SAlan Stern 	 * root hub support
12353e023203SAlan Stern 	 */
12363e023203SAlan Stern 	.hub_status_data =	ehci_hub_status_data,
12373e023203SAlan Stern 	.hub_control =		ehci_hub_control,
12383e023203SAlan Stern 	.bus_suspend =		ehci_bus_suspend,
12393e023203SAlan Stern 	.bus_resume =		ehci_bus_resume,
12403e023203SAlan Stern 	.relinquish_port =	ehci_relinquish_port,
12413e023203SAlan Stern 	.port_handed_over =	ehci_port_handed_over,
1242b35c5009SAlan Stern 
1243b35c5009SAlan Stern 	/*
1244b35c5009SAlan Stern 	 * device support
1245b35c5009SAlan Stern 	 */
1246b35c5009SAlan Stern 	.free_dev =		ehci_remove_device,
12473e023203SAlan Stern };
12483e023203SAlan Stern 
12493e023203SAlan Stern void ehci_init_driver(struct hc_driver *drv,
12503e023203SAlan Stern 		const struct ehci_driver_overrides *over)
12513e023203SAlan Stern {
12523e023203SAlan Stern 	/* Copy the generic table to drv and then apply the overrides */
12533e023203SAlan Stern 	*drv = ehci_hc_driver;
12543e023203SAlan Stern 
12551b36810eSAlan Stern 	if (over) {
12563e023203SAlan Stern 		drv->hcd_priv_size += over->extra_priv_size;
12573e023203SAlan Stern 		if (over->reset)
12583e023203SAlan Stern 			drv->reset = over->reset;
125911a7e594SMichael Grzeschik 		if (over->port_power)
126011a7e594SMichael Grzeschik 			drv->port_power = over->port_power;
12613e023203SAlan Stern 	}
12621b36810eSAlan Stern }
12633e023203SAlan Stern EXPORT_SYMBOL_GPL(ehci_init_driver);
12643e023203SAlan Stern 
12653e023203SAlan Stern /*-------------------------------------------------------------------------*/
12663e023203SAlan Stern 
12672b70f073SAlan Stern MODULE_DESCRIPTION(DRIVER_DESC);
12681da177e4SLinus Torvalds MODULE_AUTHOR (DRIVER_AUTHOR);
12691da177e4SLinus Torvalds MODULE_LICENSE ("GPL");
12701da177e4SLinus Torvalds 
127160b0bf0fSYoshihiro Shimoda #ifdef CONFIG_USB_EHCI_SH
127263c84552SPaul Mundt #include "ehci-sh.c"
127363c84552SPaul Mundt #define PLATFORM_DRIVER		ehci_hcd_sh_driver
127463c84552SPaul Mundt #endif
127563c84552SPaul Mundt 
1276ad75a410SGeoff Levand #ifdef CONFIG_PPC_PS3
1277ad75a410SGeoff Levand #include "ehci-ps3.c"
12787a4eb7fdSGeoff Levand #define	PS3_SYSTEM_BUS_DRIVER	ps3_ehci_driver
1279ad75a410SGeoff Levand #endif
1280ad75a410SGeoff Levand 
1281da0e8fb0SValentine Barshak #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
1282da0e8fb0SValentine Barshak #include "ehci-ppc-of.c"
1283da0e8fb0SValentine Barshak #define OF_PLATFORM_DRIVER	ehci_hcd_ppc_of_driver
1284da0e8fb0SValentine Barshak #endif
1285da0e8fb0SValentine Barshak 
128608d3c18eSJulie Zhu #ifdef CONFIG_XPS_USB_HCD_XILINX
128708d3c18eSJulie Zhu #include "ehci-xilinx-of.c"
12881f23b2d9SGrant Likely #define XILINX_OF_PLATFORM_DRIVER	ehci_hcd_xilinx_of_driver
128908d3c18eSJulie Zhu #endif
129008d3c18eSJulie Zhu 
129147fc28bfSChris Metcalf #ifdef CONFIG_TILE_USB
129247fc28bfSChris Metcalf #include "ehci-tilegx.c"
129347fc28bfSChris Metcalf #define	PLATFORM_DRIVER		ehci_hcd_tilegx_driver
129447fc28bfSChris Metcalf #endif
129547fc28bfSChris Metcalf 
129622ced687SAnoop #ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
129722ced687SAnoop #include "ehci-pmcmsp.c"
129822ced687SAnoop #define	PLATFORM_DRIVER		ehci_hcd_msp_driver
129922ced687SAnoop #endif
130022ced687SAnoop 
13019be03929SJan Andersson #ifdef CONFIG_SPARC_LEON
13029be03929SJan Andersson #include "ehci-grlib.c"
13039be03929SJan Andersson #define PLATFORM_DRIVER		ehci_grlib_driver
13049be03929SJan Andersson #endif
13059be03929SJan Andersson 
13063a082ec9SNeil Zhang #ifdef CONFIG_USB_EHCI_MV
13073a082ec9SNeil Zhang #include "ehci-mv.c"
13083a082ec9SNeil Zhang #define        PLATFORM_DRIVER         ehci_mv_driver
13093a082ec9SNeil Zhang #endif
13103a082ec9SNeil Zhang 
1311c256667fSSteven J. Hill #ifdef CONFIG_MIPS_SEAD3
1312c256667fSSteven J. Hill #include "ehci-sead3.c"
1313c256667fSSteven J. Hill #define	PLATFORM_DRIVER		ehci_hcd_sead3_driver
1314c256667fSSteven J. Hill #endif
1315c256667fSSteven J. Hill 
131601cced25SKumar Gala static int __init ehci_hcd_init(void)
131701cced25SKumar Gala {
131801cced25SKumar Gala 	int retval = 0;
131901cced25SKumar Gala 
13202b70f073SAlan Stern 	if (usb_disabled())
13212b70f073SAlan Stern 		return -ENODEV;
13222b70f073SAlan Stern 
13232b70f073SAlan Stern 	printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
13249beeee65SAlan Stern 	set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
13259beeee65SAlan Stern 	if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
13269beeee65SAlan Stern 			test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
13279beeee65SAlan Stern 		printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
13289beeee65SAlan Stern 				" before uhci_hcd and ohci_hcd, not after\n");
13299beeee65SAlan Stern 
133001cced25SKumar Gala 	pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
133101cced25SKumar Gala 		 hcd_name,
133201cced25SKumar Gala 		 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
133301cced25SKumar Gala 		 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
133401cced25SKumar Gala 
13351c20163dSOliver Neukum #ifdef CONFIG_DYNAMIC_DEBUG
133608f4e586SGreg Kroah-Hartman 	ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
13379beeee65SAlan Stern 	if (!ehci_debug_root) {
13389beeee65SAlan Stern 		retval = -ENOENT;
13399beeee65SAlan Stern 		goto err_debug;
13409beeee65SAlan Stern 	}
1341694cc208STony Jones #endif
1342694cc208STony Jones 
134301cced25SKumar Gala #ifdef PLATFORM_DRIVER
134401cced25SKumar Gala 	retval = platform_driver_register(&PLATFORM_DRIVER);
1345da0e8fb0SValentine Barshak 	if (retval < 0)
1346da0e8fb0SValentine Barshak 		goto clean0;
134701cced25SKumar Gala #endif
134801cced25SKumar Gala 
1349ad75a410SGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
13507a4eb7fdSGeoff Levand 	retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1351da0e8fb0SValentine Barshak 	if (retval < 0)
1352da0e8fb0SValentine Barshak 		goto clean2;
1353da0e8fb0SValentine Barshak #endif
1354da0e8fb0SValentine Barshak 
1355da0e8fb0SValentine Barshak #ifdef OF_PLATFORM_DRIVER
1356d35fb641SGrant Likely 	retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1357da0e8fb0SValentine Barshak 	if (retval < 0)
1358da0e8fb0SValentine Barshak 		goto clean3;
1359da0e8fb0SValentine Barshak #endif
13601f23b2d9SGrant Likely 
13611f23b2d9SGrant Likely #ifdef XILINX_OF_PLATFORM_DRIVER
1362d35fb641SGrant Likely 	retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
13631f23b2d9SGrant Likely 	if (retval < 0)
13641f23b2d9SGrant Likely 		goto clean4;
13651f23b2d9SGrant Likely #endif
1366da0e8fb0SValentine Barshak 	return retval;
1367da0e8fb0SValentine Barshak 
13681f23b2d9SGrant Likely #ifdef XILINX_OF_PLATFORM_DRIVER
1369d35fb641SGrant Likely 	/* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
13701f23b2d9SGrant Likely clean4:
13711f23b2d9SGrant Likely #endif
1372da0e8fb0SValentine Barshak #ifdef OF_PLATFORM_DRIVER
1373d35fb641SGrant Likely 	platform_driver_unregister(&OF_PLATFORM_DRIVER);
1374da0e8fb0SValentine Barshak clean3:
1375da0e8fb0SValentine Barshak #endif
1376da0e8fb0SValentine Barshak #ifdef PS3_SYSTEM_BUS_DRIVER
1377da0e8fb0SValentine Barshak 	ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1378da0e8fb0SValentine Barshak clean2:
1379da0e8fb0SValentine Barshak #endif
1380da0e8fb0SValentine Barshak #ifdef PLATFORM_DRIVER
1381da0e8fb0SValentine Barshak 	platform_driver_unregister(&PLATFORM_DRIVER);
1382da0e8fb0SValentine Barshak clean0:
1383da0e8fb0SValentine Barshak #endif
13841c20163dSOliver Neukum #ifdef CONFIG_DYNAMIC_DEBUG
1385694cc208STony Jones 	debugfs_remove(ehci_debug_root);
1386694cc208STony Jones 	ehci_debug_root = NULL;
13879beeee65SAlan Stern err_debug:
1388a9b6148dSLinus Torvalds #endif
13899beeee65SAlan Stern 	clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
139001cced25SKumar Gala 	return retval;
139101cced25SKumar Gala }
139201cced25SKumar Gala module_init(ehci_hcd_init);
139301cced25SKumar Gala 
139401cced25SKumar Gala static void __exit ehci_hcd_cleanup(void)
139501cced25SKumar Gala {
13961f23b2d9SGrant Likely #ifdef XILINX_OF_PLATFORM_DRIVER
1397d35fb641SGrant Likely 	platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
13981f23b2d9SGrant Likely #endif
1399da0e8fb0SValentine Barshak #ifdef OF_PLATFORM_DRIVER
1400d35fb641SGrant Likely 	platform_driver_unregister(&OF_PLATFORM_DRIVER);
1401da0e8fb0SValentine Barshak #endif
140201cced25SKumar Gala #ifdef PLATFORM_DRIVER
140301cced25SKumar Gala 	platform_driver_unregister(&PLATFORM_DRIVER);
140401cced25SKumar Gala #endif
1405ad75a410SGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
14067a4eb7fdSGeoff Levand 	ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1407ad75a410SGeoff Levand #endif
14081c20163dSOliver Neukum #ifdef CONFIG_DYNAMIC_DEBUG
1409694cc208STony Jones 	debugfs_remove(ehci_debug_root);
1410694cc208STony Jones #endif
14119beeee65SAlan Stern 	clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
141201cced25SKumar Gala }
141301cced25SKumar Gala module_exit(ehci_hcd_cleanup);
1414