xref: /linux/drivers/usb/host/ehci-hcd.c (revision 4f7a67e2dd49fbfba002c453bc24bf00e701cc71)
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>
331da177e4SLinus Torvalds #include <linux/timer.h>
34ee4ecb8aSOliver Neukum #include <linux/ktime.h>
351da177e4SLinus Torvalds #include <linux/list.h>
361da177e4SLinus Torvalds #include <linux/interrupt.h>
371da177e4SLinus Torvalds #include <linux/usb.h>
3827729aadSEric Lescouet #include <linux/usb/hcd.h>
391da177e4SLinus Torvalds #include <linux/moduleparam.h>
401da177e4SLinus Torvalds #include <linux/dma-mapping.h>
41694cc208STony Jones #include <linux/debugfs.h>
425a0e3ad6STejun Heo #include <linux/slab.h>
43aa4d8342SAlek Du #include <linux/uaccess.h>
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds #include <asm/byteorder.h>
461da177e4SLinus Torvalds #include <asm/io.h>
471da177e4SLinus Torvalds #include <asm/irq.h>
481da177e4SLinus Torvalds #include <asm/unaligned.h>
491da177e4SLinus Torvalds 
50df7c1ca2SGeoff Levand #if defined(CONFIG_PPC_PS3)
51df7c1ca2SGeoff Levand #include <asm/firmware.h>
52df7c1ca2SGeoff Levand #endif
53df7c1ca2SGeoff Levand 
541da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds /*
571da177e4SLinus Torvalds  * EHCI hc_driver implementation ... experimental, incomplete.
581da177e4SLinus Torvalds  * Based on the final 1.0 register interface specification.
591da177e4SLinus Torvalds  *
601da177e4SLinus Torvalds  * USB 2.0 shows up in upcoming www.pcmcia.org technology.
611da177e4SLinus Torvalds  * First was PCMCIA, like ISA; then CardBus, which is PCI.
621da177e4SLinus Torvalds  * Next comes "CardBay", using USB 2.0 signals.
631da177e4SLinus Torvalds  *
641da177e4SLinus Torvalds  * Contains additional contributions by Brad Hards, Rory Bolt, and others.
651da177e4SLinus Torvalds  * Special thanks to Intel and VIA for providing host controllers to
661da177e4SLinus Torvalds  * test this driver on, and Cypress (including In-System Design) for
671da177e4SLinus Torvalds  * providing early devices for those host controllers to talk to!
681da177e4SLinus Torvalds  */
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds #define DRIVER_AUTHOR "David Brownell"
711da177e4SLinus Torvalds #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds static const char	hcd_name [] = "ehci_hcd";
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds 
769776afc8SDavid Brownell #undef VERBOSE_DEBUG
771da177e4SLinus Torvalds #undef EHCI_URB_TRACE
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds #ifdef DEBUG
801da177e4SLinus Torvalds #define EHCI_STATS
811da177e4SLinus Torvalds #endif
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds /* magic numbers that can affect system performance */
841da177e4SLinus Torvalds #define	EHCI_TUNE_CERR		3	/* 0-3 qtd retries; 0 == don't stop */
851da177e4SLinus Torvalds #define	EHCI_TUNE_RL_HS		4	/* nak throttle; see 4.9 */
861da177e4SLinus Torvalds #define	EHCI_TUNE_RL_TT		0
871da177e4SLinus Torvalds #define	EHCI_TUNE_MULT_HS	1	/* 1-3 transactions/uframe; 4.10.3 */
881da177e4SLinus Torvalds #define	EHCI_TUNE_MULT_TT	1
89ffda0803SAlan Stern /*
90ffda0803SAlan Stern  * Some drivers think it's safe to schedule isochronous transfers more than
91ffda0803SAlan Stern  * 256 ms into the future (partly as a result of an old bug in the scheduling
92ffda0803SAlan Stern  * code).  In an attempt to avoid trouble, we will use a minimum scheduling
93ffda0803SAlan Stern  * length of 512 frames instead of 256.
94ffda0803SAlan Stern  */
95ffda0803SAlan Stern #define	EHCI_TUNE_FLS		1	/* (medium) 512-frame schedule */
961da177e4SLinus Torvalds 
9707d29b63SAlan Stern #define EHCI_IAA_MSECS		10		/* arbitrary */
981da177e4SLinus Torvalds #define EHCI_IO_JIFFIES		(HZ/10)		/* io watchdog > irq_thresh */
991da177e4SLinus Torvalds #define EHCI_ASYNC_JIFFIES	(HZ/20)		/* async idle timeout */
100004c1968SAlan Stern #define EHCI_SHRINK_JIFFIES	(DIV_ROUND_UP(HZ, 200) + 1)
101fcda37cbSMing Lei 						/* 5-ms async qh unlink delay */
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds /* Initial IRQ latency:  faster than hw default */
1041da177e4SLinus Torvalds static int log2_irq_thresh = 0;		// 0 to 6
1051da177e4SLinus Torvalds module_param (log2_irq_thresh, int, S_IRUGO);
1061da177e4SLinus Torvalds MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
1071da177e4SLinus Torvalds 
1081da177e4SLinus Torvalds /* initial park setting:  slower than hw default */
1091da177e4SLinus Torvalds static unsigned park = 0;
1101da177e4SLinus Torvalds module_param (park, uint, S_IRUGO);
1111da177e4SLinus Torvalds MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
1121da177e4SLinus Torvalds 
11393f1a47cSDavid Brownell /* for flakey hardware, ignore overcurrent indicators */
11490ab5ee9SRusty Russell static bool ignore_oc = 0;
11593f1a47cSDavid Brownell module_param (ignore_oc, bool, S_IRUGO);
11693f1a47cSDavid Brownell MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
11793f1a47cSDavid Brownell 
11848f24970SAlek Du /* for link power management(LPM) feature */
11948f24970SAlek Du static unsigned int hird;
12048f24970SAlek Du module_param(hird, int, S_IRUGO);
121cc556871SNiels de Vos MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us");
12248f24970SAlek Du 
1231da177e4SLinus Torvalds #define	INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds #include "ehci.h"
1281da177e4SLinus Torvalds #include "ehci-dbg.c"
129ad93562bSAndiry Xu #include "pci-quirks.h"
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
1321da177e4SLinus Torvalds 
133bc29847eSAlan Stern static void
134bc29847eSAlan Stern timer_action(struct ehci_hcd *ehci, enum ehci_timer_action action)
135bc29847eSAlan Stern {
136bc29847eSAlan Stern 	/* Don't override timeouts which shrink or (later) disable
137bc29847eSAlan Stern 	 * the async ring; just the I/O watchdog.  Note that if a
138bc29847eSAlan Stern 	 * SHRINK were pending, OFF would never be requested.
139bc29847eSAlan Stern 	 */
140bc29847eSAlan Stern 	if (timer_pending(&ehci->watchdog)
141bc29847eSAlan Stern 			&& ((BIT(TIMER_ASYNC_SHRINK) | BIT(TIMER_ASYNC_OFF))
142bc29847eSAlan Stern 				& ehci->actions))
143bc29847eSAlan Stern 		return;
144bc29847eSAlan Stern 
145bc29847eSAlan Stern 	if (!test_and_set_bit(action, &ehci->actions)) {
146bc29847eSAlan Stern 		unsigned long t;
147bc29847eSAlan Stern 
148bc29847eSAlan Stern 		switch (action) {
149bc29847eSAlan Stern 		case TIMER_IO_WATCHDOG:
150403dbd36SAlek Du 			if (!ehci->need_io_watchdog)
151403dbd36SAlek Du 				return;
152bc29847eSAlan Stern 			t = EHCI_IO_JIFFIES;
153bc29847eSAlan Stern 			break;
154bc29847eSAlan Stern 		case TIMER_ASYNC_OFF:
155bc29847eSAlan Stern 			t = EHCI_ASYNC_JIFFIES;
156bc29847eSAlan Stern 			break;
157bc29847eSAlan Stern 		/* case TIMER_ASYNC_SHRINK: */
158bc29847eSAlan Stern 		default:
159004c1968SAlan Stern 			t = EHCI_SHRINK_JIFFIES;
160bc29847eSAlan Stern 			break;
161bc29847eSAlan Stern 		}
162bc29847eSAlan Stern 		mod_timer(&ehci->watchdog, t + jiffies);
163bc29847eSAlan Stern 	}
164bc29847eSAlan Stern }
165bc29847eSAlan Stern 
166bc29847eSAlan Stern /*-------------------------------------------------------------------------*/
167bc29847eSAlan Stern 
1681da177e4SLinus Torvalds /*
1691da177e4SLinus Torvalds  * handshake - spin reading hc until handshake completes or fails
1701da177e4SLinus Torvalds  * @ptr: address of hc register to be read
1711da177e4SLinus Torvalds  * @mask: bits to look at in result of read
1721da177e4SLinus Torvalds  * @done: value of those bits when handshake succeeds
1731da177e4SLinus Torvalds  * @usec: timeout in microseconds
1741da177e4SLinus Torvalds  *
1751da177e4SLinus Torvalds  * Returns negative errno, or zero on success
1761da177e4SLinus Torvalds  *
1771da177e4SLinus Torvalds  * Success happens when the "mask" bits have the specified value (hardware
1781da177e4SLinus Torvalds  * handshake done).  There are two failure modes:  "usec" have passed (major
1791da177e4SLinus Torvalds  * hardware flakeout), or the register reads as all-ones (hardware removed).
1801da177e4SLinus Torvalds  *
1811da177e4SLinus Torvalds  * That last failure should_only happen in cases like physical cardbus eject
1821da177e4SLinus Torvalds  * before driver shutdown. But it also seems to be caused by bugs in cardbus
1831da177e4SLinus Torvalds  * bridge shutdown:  shutting down the bridge before the devices using it.
1841da177e4SLinus Torvalds  */
185083522d7SBenjamin Herrenschmidt static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
186083522d7SBenjamin Herrenschmidt 		      u32 mask, u32 done, int usec)
1871da177e4SLinus Torvalds {
1881da177e4SLinus Torvalds 	u32	result;
1891da177e4SLinus Torvalds 
1901da177e4SLinus Torvalds 	do {
191083522d7SBenjamin Herrenschmidt 		result = ehci_readl(ehci, ptr);
1921da177e4SLinus Torvalds 		if (result == ~(u32)0)		/* card removed */
1931da177e4SLinus Torvalds 			return -ENODEV;
1941da177e4SLinus Torvalds 		result &= mask;
1951da177e4SLinus Torvalds 		if (result == done)
1961da177e4SLinus Torvalds 			return 0;
1971da177e4SLinus Torvalds 		udelay (1);
1981da177e4SLinus Torvalds 		usec--;
1991da177e4SLinus Torvalds 	} while (usec > 0);
2001da177e4SLinus Torvalds 	return -ETIMEDOUT;
2011da177e4SLinus Torvalds }
2021da177e4SLinus Torvalds 
20365fd4272SMatthieu CASTET /* check TDI/ARC silicon is in host mode */
20465fd4272SMatthieu CASTET static int tdi_in_host_mode (struct ehci_hcd *ehci)
20565fd4272SMatthieu CASTET {
20665fd4272SMatthieu CASTET 	u32 __iomem	*reg_ptr;
20765fd4272SMatthieu CASTET 	u32		tmp;
20865fd4272SMatthieu CASTET 
20965fd4272SMatthieu CASTET 	reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE);
21065fd4272SMatthieu CASTET 	tmp = ehci_readl(ehci, reg_ptr);
21165fd4272SMatthieu CASTET 	return (tmp & 3) == USBMODE_CM_HC;
21265fd4272SMatthieu CASTET }
21365fd4272SMatthieu CASTET 
2141da177e4SLinus Torvalds /* force HC to halt state from unknown (EHCI spec section 2.3) */
2151da177e4SLinus Torvalds static int ehci_halt (struct ehci_hcd *ehci)
2161da177e4SLinus Torvalds {
217083522d7SBenjamin Herrenschmidt 	u32	temp = ehci_readl(ehci, &ehci->regs->status);
2181da177e4SLinus Torvalds 
21972f30b6fSDavid Brownell 	/* disable any irqs left enabled by previous code */
220083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, 0, &ehci->regs->intr_enable);
22172f30b6fSDavid Brownell 
22265fd4272SMatthieu CASTET 	if (ehci_is_TDI(ehci) && tdi_in_host_mode(ehci) == 0) {
22365fd4272SMatthieu CASTET 		return 0;
22465fd4272SMatthieu CASTET 	}
22565fd4272SMatthieu CASTET 
2261da177e4SLinus Torvalds 	if ((temp & STS_HALT) != 0)
2271da177e4SLinus Torvalds 		return 0;
2281da177e4SLinus Torvalds 
2293d9545ccSAlan Stern 	/*
2303d9545ccSAlan Stern 	 * This routine gets called during probe before ehci->command
2313d9545ccSAlan Stern 	 * has been initialized, so we can't rely on its value.
2323d9545ccSAlan Stern 	 */
2333d9545ccSAlan Stern 	ehci->command &= ~CMD_RUN;
234083522d7SBenjamin Herrenschmidt 	temp = ehci_readl(ehci, &ehci->regs->command);
2353d9545ccSAlan Stern 	temp &= ~(CMD_RUN | CMD_IAAD);
236083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, temp, &ehci->regs->command);
237083522d7SBenjamin Herrenschmidt 	return handshake (ehci, &ehci->regs->status,
238083522d7SBenjamin Herrenschmidt 			  STS_HALT, STS_HALT, 16 * 125);
2391da177e4SLinus Torvalds }
2401da177e4SLinus Torvalds 
241df7c1ca2SGeoff Levand #if defined(CONFIG_USB_SUSPEND) && defined(CONFIG_PPC_PS3)
242df7c1ca2SGeoff Levand 
243df7c1ca2SGeoff Levand /*
244df7c1ca2SGeoff Levand  * The EHCI controller of the Cell Super Companion Chip used in the
245df7c1ca2SGeoff Levand  * PS3 will stop the root hub after all root hub ports are suspended.
246df7c1ca2SGeoff Levand  * When in this condition handshake will return -ETIMEDOUT.  The
247df7c1ca2SGeoff Levand  * STS_HLT bit will not be set, so inspection of the frame index is
248df7c1ca2SGeoff Levand  * used here to test for the condition.  If the condition is found
249df7c1ca2SGeoff Levand  * return success to allow the USB suspend to complete.
250df7c1ca2SGeoff Levand  */
251df7c1ca2SGeoff Levand 
252df7c1ca2SGeoff Levand static int handshake_for_broken_root_hub(struct ehci_hcd *ehci,
253df7c1ca2SGeoff Levand 					 void __iomem *ptr, u32 mask, u32 done,
254df7c1ca2SGeoff Levand 					 int usec)
255df7c1ca2SGeoff Levand {
256df7c1ca2SGeoff Levand 	unsigned int old_index;
257df7c1ca2SGeoff Levand 	int error;
258df7c1ca2SGeoff Levand 
259df7c1ca2SGeoff Levand 	if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
260df7c1ca2SGeoff Levand 		return -ETIMEDOUT;
261df7c1ca2SGeoff Levand 
262df7c1ca2SGeoff Levand 	old_index = ehci_read_frame_index(ehci);
263df7c1ca2SGeoff Levand 
264df7c1ca2SGeoff Levand 	error = handshake(ehci, ptr, mask, done, usec);
265df7c1ca2SGeoff Levand 
266df7c1ca2SGeoff Levand 	if (error == -ETIMEDOUT && ehci_read_frame_index(ehci) == old_index)
267df7c1ca2SGeoff Levand 		return 0;
268df7c1ca2SGeoff Levand 
269df7c1ca2SGeoff Levand 	return error;
270df7c1ca2SGeoff Levand }
271df7c1ca2SGeoff Levand 
272df7c1ca2SGeoff Levand #else
273df7c1ca2SGeoff Levand 
274df7c1ca2SGeoff Levand static int handshake_for_broken_root_hub(struct ehci_hcd *ehci,
275df7c1ca2SGeoff Levand 					 void __iomem *ptr, u32 mask, u32 done,
276df7c1ca2SGeoff Levand 					 int usec)
277df7c1ca2SGeoff Levand {
278df7c1ca2SGeoff Levand 	return -ETIMEDOUT;
279df7c1ca2SGeoff Levand }
280df7c1ca2SGeoff Levand 
281df7c1ca2SGeoff Levand #endif
282df7c1ca2SGeoff Levand 
2830bcfeb3eSDavid Brownell static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr,
2840bcfeb3eSDavid Brownell 				       u32 mask, u32 done, int usec)
2850bcfeb3eSDavid Brownell {
2860bcfeb3eSDavid Brownell 	int error;
2870bcfeb3eSDavid Brownell 
2880bcfeb3eSDavid Brownell 	error = handshake(ehci, ptr, mask, done, usec);
289df7c1ca2SGeoff Levand 	if (error == -ETIMEDOUT)
290df7c1ca2SGeoff Levand 		error = handshake_for_broken_root_hub(ehci, ptr, mask, done,
291df7c1ca2SGeoff Levand 						      usec);
292df7c1ca2SGeoff Levand 
2930bcfeb3eSDavid Brownell 	if (error) {
2940bcfeb3eSDavid Brownell 		ehci_halt(ehci);
295e8799906SAlan Stern 		ehci->rh_state = EHCI_RH_HALTED;
29665cb76baSOzan Çağlayan 		ehci_err(ehci, "force halt; handshake %p %08x %08x -> %d\n",
2970bcfeb3eSDavid Brownell 			ptr, mask, done, error);
2980bcfeb3eSDavid Brownell 	}
2990bcfeb3eSDavid Brownell 
3000bcfeb3eSDavid Brownell 	return error;
3010bcfeb3eSDavid Brownell }
3020bcfeb3eSDavid Brownell 
3031da177e4SLinus Torvalds /* put TDI/ARC silicon into EHCI mode */
3041da177e4SLinus Torvalds static void tdi_reset (struct ehci_hcd *ehci)
3051da177e4SLinus Torvalds {
3061da177e4SLinus Torvalds 	u32 __iomem	*reg_ptr;
3071da177e4SLinus Torvalds 	u32		tmp;
3081da177e4SLinus Torvalds 
309d23a1377SVladimir Barinov 	reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE);
310083522d7SBenjamin Herrenschmidt 	tmp = ehci_readl(ehci, reg_ptr);
311d23a1377SVladimir Barinov 	tmp |= USBMODE_CM_HC;
312d23a1377SVladimir Barinov 	/* The default byte access to MMR space is LE after
313d23a1377SVladimir Barinov 	 * controller reset. Set the required endian mode
314d23a1377SVladimir Barinov 	 * for transfer buffers to match the host microprocessor
315d23a1377SVladimir Barinov 	 */
316d23a1377SVladimir Barinov 	if (ehci_big_endian_mmio(ehci))
317d23a1377SVladimir Barinov 		tmp |= USBMODE_BE;
318083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, tmp, reg_ptr);
3191da177e4SLinus Torvalds }
3201da177e4SLinus Torvalds 
3211da177e4SLinus Torvalds /* reset a non-running (STS_HALT == 1) controller */
3221da177e4SLinus Torvalds static int ehci_reset (struct ehci_hcd *ehci)
3231da177e4SLinus Torvalds {
3241da177e4SLinus Torvalds 	int	retval;
325083522d7SBenjamin Herrenschmidt 	u32	command = ehci_readl(ehci, &ehci->regs->command);
3261da177e4SLinus Torvalds 
3278d053c79SJason Wessel 	/* If the EHCI debug controller is active, special care must be
3288d053c79SJason Wessel 	 * taken before and after a host controller reset */
3298d053c79SJason Wessel 	if (ehci->debug && !dbgp_reset_prep())
3308d053c79SJason Wessel 		ehci->debug = NULL;
3318d053c79SJason Wessel 
3321da177e4SLinus Torvalds 	command |= CMD_RESET;
3331da177e4SLinus Torvalds 	dbg_cmd (ehci, "reset", command);
334083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, command, &ehci->regs->command);
335e8799906SAlan Stern 	ehci->rh_state = EHCI_RH_HALTED;
3361da177e4SLinus Torvalds 	ehci->next_statechange = jiffies;
337083522d7SBenjamin Herrenschmidt 	retval = handshake (ehci, &ehci->regs->command,
338083522d7SBenjamin Herrenschmidt 			    CMD_RESET, 0, 250 * 1000);
3391da177e4SLinus Torvalds 
340331ac6b2SAlek Du 	if (ehci->has_hostpc) {
341331ac6b2SAlek Du 		ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
342331ac6b2SAlek Du 			(u32 __iomem *)(((u8 *)ehci->regs) + USBMODE_EX));
343331ac6b2SAlek Du 		ehci_writel(ehci, TXFIFO_DEFAULT,
344331ac6b2SAlek Du 			(u32 __iomem *)(((u8 *)ehci->regs) + TXFILLTUNING));
345331ac6b2SAlek Du 	}
3461da177e4SLinus Torvalds 	if (retval)
3471da177e4SLinus Torvalds 		return retval;
3481da177e4SLinus Torvalds 
3491da177e4SLinus Torvalds 	if (ehci_is_TDI(ehci))
3501da177e4SLinus Torvalds 		tdi_reset (ehci);
3511da177e4SLinus Torvalds 
3528d053c79SJason Wessel 	if (ehci->debug)
3538d053c79SJason Wessel 		dbgp_external_startup();
3548d053c79SJason Wessel 
355a448e4dcSAlan Stern 	ehci->port_c_suspend = ehci->suspended_ports =
356a448e4dcSAlan Stern 			ehci->resuming_ports = 0;
3571da177e4SLinus Torvalds 	return retval;
3581da177e4SLinus Torvalds }
3591da177e4SLinus Torvalds 
3601da177e4SLinus Torvalds /* idle the controller (from running) */
3611da177e4SLinus Torvalds static void ehci_quiesce (struct ehci_hcd *ehci)
3621da177e4SLinus Torvalds {
3631da177e4SLinus Torvalds 	u32	temp;
3641da177e4SLinus Torvalds 
3651da177e4SLinus Torvalds #ifdef DEBUG
366e8799906SAlan Stern 	if (ehci->rh_state != EHCI_RH_RUNNING)
3671da177e4SLinus Torvalds 		BUG ();
3681da177e4SLinus Torvalds #endif
3691da177e4SLinus Torvalds 
3701da177e4SLinus Torvalds 	/* wait for any schedule enables/disables to take effect */
3713d9545ccSAlan Stern 	temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
372c765d4caSKarsten Wiese 	if (handshake_on_error_set_halt(ehci, &ehci->regs->status,
373c765d4caSKarsten Wiese 					STS_ASS | STS_PSS, temp, 16 * 125))
3741da177e4SLinus Torvalds 		return;
3751da177e4SLinus Torvalds 
3761da177e4SLinus Torvalds 	/* then disable anything that's still active */
3773d9545ccSAlan Stern 	ehci->command &= ~(CMD_ASE | CMD_PSE);
3783d9545ccSAlan Stern 	ehci_writel(ehci, ehci->command, &ehci->regs->command);
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds 	/* hardware can take 16 microframes to turn off ... */
381c765d4caSKarsten Wiese 	handshake_on_error_set_halt(ehci, &ehci->regs->status,
382c765d4caSKarsten Wiese 				    STS_ASS | STS_PSS, 0, 16 * 125);
3831da177e4SLinus Torvalds }
3841da177e4SLinus Torvalds 
3851da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3861da177e4SLinus Torvalds 
38707d29b63SAlan Stern static void end_unlink_async(struct ehci_hcd *ehci);
3887d12e780SDavid Howells static void ehci_work(struct ehci_hcd *ehci);
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds #include "ehci-hub.c"
39148f24970SAlek Du #include "ehci-lpm.c"
3921da177e4SLinus Torvalds #include "ehci-mem.c"
3931da177e4SLinus Torvalds #include "ehci-q.c"
3941da177e4SLinus Torvalds #include "ehci-sched.c"
3954c67045bSKirill Smelkov #include "ehci-sysfs.c"
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3981da177e4SLinus Torvalds 
39907d29b63SAlan Stern static void ehci_iaa_watchdog(unsigned long param)
40007d29b63SAlan Stern {
40107d29b63SAlan Stern 	struct ehci_hcd		*ehci = (struct ehci_hcd *) param;
40207d29b63SAlan Stern 	unsigned long		flags;
40307d29b63SAlan Stern 
40407d29b63SAlan Stern 	spin_lock_irqsave (&ehci->lock, flags);
40507d29b63SAlan Stern 
406e82cc128SDavid Brownell 	/* Lost IAA irqs wedge things badly; seen first with a vt8235.
407e82cc128SDavid Brownell 	 * So we need this watchdog, but must protect it against both
408e82cc128SDavid Brownell 	 * (a) SMP races against real IAA firing and retriggering, and
409e82cc128SDavid Brownell 	 * (b) clean HC shutdown, when IAA watchdog was pending.
410e82cc128SDavid Brownell 	 */
411e82cc128SDavid Brownell 	if (ehci->reclaim
412e82cc128SDavid Brownell 			&& !timer_pending(&ehci->iaa_watchdog)
413e8799906SAlan Stern 			&& ehci->rh_state == EHCI_RH_RUNNING) {
414e82cc128SDavid Brownell 		u32 cmd, status;
415e82cc128SDavid Brownell 
416e82cc128SDavid Brownell 		/* If we get here, IAA is *REALLY* late.  It's barely
417e82cc128SDavid Brownell 		 * conceivable that the system is so busy that CMD_IAAD
418e82cc128SDavid Brownell 		 * is still legitimately set, so let's be sure it's
419e82cc128SDavid Brownell 		 * clear before we read STS_IAA.  (The HC should clear
420e82cc128SDavid Brownell 		 * CMD_IAAD when it sets STS_IAA.)
421e82cc128SDavid Brownell 		 */
42207d29b63SAlan Stern 		cmd = ehci_readl(ehci, &ehci->regs->command);
42307d29b63SAlan Stern 
424e82cc128SDavid Brownell 		/* If IAA is set here it either legitimately triggered
425e82cc128SDavid Brownell 		 * before we cleared IAAD above (but _way_ late, so we'll
426e82cc128SDavid Brownell 		 * still count it as lost) ... or a silicon erratum:
427e82cc128SDavid Brownell 		 * - VIA seems to set IAA without triggering the IRQ;
428e82cc128SDavid Brownell 		 * - IAAD potentially cleared without setting IAA.
429e82cc128SDavid Brownell 		 */
430e82cc128SDavid Brownell 		status = ehci_readl(ehci, &ehci->regs->status);
431e82cc128SDavid Brownell 		if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
43207d29b63SAlan Stern 			COUNT (ehci->stats.lost_iaa);
43307d29b63SAlan Stern 			ehci_writel(ehci, STS_IAA, &ehci->regs->status);
43407d29b63SAlan Stern 		}
435e82cc128SDavid Brownell 
436e82cc128SDavid Brownell 		ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n",
437e82cc128SDavid Brownell 				status, cmd);
43807d29b63SAlan Stern 		end_unlink_async(ehci);
43907d29b63SAlan Stern 	}
44007d29b63SAlan Stern 
44107d29b63SAlan Stern 	spin_unlock_irqrestore(&ehci->lock, flags);
44207d29b63SAlan Stern }
44307d29b63SAlan Stern 
4441da177e4SLinus Torvalds static void ehci_watchdog(unsigned long param)
4451da177e4SLinus Torvalds {
4461da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = (struct ehci_hcd *) param;
4471da177e4SLinus Torvalds 	unsigned long		flags;
4481da177e4SLinus Torvalds 
4491da177e4SLinus Torvalds 	spin_lock_irqsave(&ehci->lock, flags);
4501da177e4SLinus Torvalds 
4511da177e4SLinus Torvalds 	/* stop async processing after it's idled a bit */
4521da177e4SLinus Torvalds 	if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
4531da177e4SLinus Torvalds 		start_unlink_async (ehci, ehci->async);
4541da177e4SLinus Torvalds 
4551da177e4SLinus Torvalds 	/* ehci could run by timer, without IRQs ... */
4567d12e780SDavid Howells 	ehci_work (ehci);
4571da177e4SLinus Torvalds 
4581da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ehci->lock, flags);
4591da177e4SLinus Torvalds }
4601da177e4SLinus Torvalds 
4618903795aSAlan Stern /* On some systems, leaving remote wakeup enabled prevents system shutdown.
4628903795aSAlan Stern  * The firmware seems to think that powering off is a wakeup event!
4638903795aSAlan Stern  * This routine turns off remote wakeup and everything else, on all ports.
4648903795aSAlan Stern  */
4658903795aSAlan Stern static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
4668903795aSAlan Stern {
4678903795aSAlan Stern 	int	port = HCS_N_PORTS(ehci->hcs_params);
4688903795aSAlan Stern 
4698903795aSAlan Stern 	while (port--)
4708903795aSAlan Stern 		ehci_writel(ehci, PORT_RWC_BITS,
4718903795aSAlan Stern 				&ehci->regs->port_status[port]);
4728903795aSAlan Stern }
4738903795aSAlan Stern 
47421da84a8SSarah Sharp /*
47521da84a8SSarah Sharp  * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
47621da84a8SSarah Sharp  * Should be called with ehci->lock held.
47772f30b6fSDavid Brownell  */
47821da84a8SSarah Sharp static void ehci_silence_controller(struct ehci_hcd *ehci)
4791da177e4SLinus Torvalds {
48021da84a8SSarah Sharp 	ehci_halt(ehci);
4818903795aSAlan Stern 	ehci_turn_off_all_ports(ehci);
4821da177e4SLinus Torvalds 
4831da177e4SLinus Torvalds 	/* make BIOS/etc use companion controller during reboot */
484083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, 0, &ehci->regs->configured_flag);
4858903795aSAlan Stern 
4868903795aSAlan Stern 	/* unblock posted writes */
4878903795aSAlan Stern 	ehci_readl(ehci, &ehci->regs->configured_flag);
4881da177e4SLinus Torvalds }
4891da177e4SLinus Torvalds 
49021da84a8SSarah Sharp /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
49121da84a8SSarah Sharp  * This forcibly disables dma and IRQs, helping kexec and other cases
49221da84a8SSarah Sharp  * where the next system software may expect clean state.
49321da84a8SSarah Sharp  */
49421da84a8SSarah Sharp static void ehci_shutdown(struct usb_hcd *hcd)
49521da84a8SSarah Sharp {
49621da84a8SSarah Sharp 	struct ehci_hcd	*ehci = hcd_to_ehci(hcd);
49721da84a8SSarah Sharp 
49821da84a8SSarah Sharp 	del_timer_sync(&ehci->watchdog);
49921da84a8SSarah Sharp 	del_timer_sync(&ehci->iaa_watchdog);
50021da84a8SSarah Sharp 
50121da84a8SSarah Sharp 	spin_lock_irq(&ehci->lock);
50221da84a8SSarah Sharp 	ehci_silence_controller(ehci);
50321da84a8SSarah Sharp 	spin_unlock_irq(&ehci->lock);
50421da84a8SSarah Sharp }
50521da84a8SSarah Sharp 
50656c1e26dSDavid Brownell static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
50756c1e26dSDavid Brownell {
50856c1e26dSDavid Brownell 	unsigned port;
50956c1e26dSDavid Brownell 
51056c1e26dSDavid Brownell 	if (!HCS_PPC (ehci->hcs_params))
51156c1e26dSDavid Brownell 		return;
51256c1e26dSDavid Brownell 
51356c1e26dSDavid Brownell 	ehci_dbg (ehci, "...power%s ports...\n", is_on ? "up" : "down");
51456c1e26dSDavid Brownell 	for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; )
51556c1e26dSDavid Brownell 		(void) ehci_hub_control(ehci_to_hcd(ehci),
51656c1e26dSDavid Brownell 				is_on ? SetPortFeature : ClearPortFeature,
51756c1e26dSDavid Brownell 				USB_PORT_FEAT_POWER,
51856c1e26dSDavid Brownell 				port--, NULL, 0);
519383975d7SAlan Stern 	/* Flush those writes */
520383975d7SAlan Stern 	ehci_readl(ehci, &ehci->regs->command);
52156c1e26dSDavid Brownell 	msleep(20);
52256c1e26dSDavid Brownell }
52356c1e26dSDavid Brownell 
5247ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
5251da177e4SLinus Torvalds 
5267ff71d6aSMatt Porter /*
5277ff71d6aSMatt Porter  * ehci_work is called from some interrupts, timers, and so on.
5287ff71d6aSMatt Porter  * it calls driver completion functions, after dropping ehci->lock.
5297ff71d6aSMatt Porter  */
5307d12e780SDavid Howells static void ehci_work (struct ehci_hcd *ehci)
5317ff71d6aSMatt Porter {
5327ff71d6aSMatt Porter 	timer_action_done (ehci, TIMER_IO_WATCHDOG);
5331da177e4SLinus Torvalds 
5347ff71d6aSMatt Porter 	/* another CPU may drop ehci->lock during a schedule scan while
5357ff71d6aSMatt Porter 	 * it reports urb completions.  this flag guards against bogus
5367ff71d6aSMatt Porter 	 * attempts at re-entrant schedule scanning.
5377ff71d6aSMatt Porter 	 */
5387ff71d6aSMatt Porter 	if (ehci->scanning)
5397ff71d6aSMatt Porter 		return;
5407ff71d6aSMatt Porter 	ehci->scanning = 1;
5417d12e780SDavid Howells 	scan_async (ehci);
5427ff71d6aSMatt Porter 	if (ehci->next_uframe != -1)
5437d12e780SDavid Howells 		scan_periodic (ehci);
5447ff71d6aSMatt Porter 	ehci->scanning = 0;
5457ff71d6aSMatt Porter 
5467ff71d6aSMatt Porter 	/* the IO watchdog guards against hardware or driver bugs that
5477ff71d6aSMatt Porter 	 * misplace IRQs, and should let us run completely without IRQs.
5487ff71d6aSMatt Porter 	 * such lossage has been observed on both VT6202 and VT8235.
5497ff71d6aSMatt Porter 	 */
550e8799906SAlan Stern 	if (ehci->rh_state == EHCI_RH_RUNNING &&
5517ff71d6aSMatt Porter 			(ehci->async->qh_next.ptr != NULL ||
5527ff71d6aSMatt Porter 			 ehci->periodic_sched != 0))
5537ff71d6aSMatt Porter 		timer_action (ehci, TIMER_IO_WATCHDOG);
5547ff71d6aSMatt Porter }
5557ff71d6aSMatt Porter 
55621da84a8SSarah Sharp /*
55721da84a8SSarah Sharp  * Called when the ehci_hcd module is removed.
55821da84a8SSarah Sharp  */
5597ff71d6aSMatt Porter static void ehci_stop (struct usb_hcd *hcd)
5601da177e4SLinus Torvalds {
5611da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
5621da177e4SLinus Torvalds 
5637ff71d6aSMatt Porter 	ehci_dbg (ehci, "stop\n");
5641da177e4SLinus Torvalds 
5657ff71d6aSMatt Porter 	/* no more interrupts ... */
5667ff71d6aSMatt Porter 	del_timer_sync (&ehci->watchdog);
56707d29b63SAlan Stern 	del_timer_sync(&ehci->iaa_watchdog);
5681da177e4SLinus Torvalds 
5697ff71d6aSMatt Porter 	spin_lock_irq(&ehci->lock);
570e8799906SAlan Stern 	if (ehci->rh_state == EHCI_RH_RUNNING)
5717ff71d6aSMatt Porter 		ehci_quiesce (ehci);
5721da177e4SLinus Torvalds 
57321da84a8SSarah Sharp 	ehci_silence_controller(ehci);
5747ff71d6aSMatt Porter 	ehci_reset (ehci);
5757ff71d6aSMatt Porter 	spin_unlock_irq(&ehci->lock);
5767ff71d6aSMatt Porter 
5774c67045bSKirill Smelkov 	remove_sysfs_files(ehci);
5787ff71d6aSMatt Porter 	remove_debug_files (ehci);
5797ff71d6aSMatt Porter 
5807ff71d6aSMatt Porter 	/* root hub is shut down separately (first, when possible) */
5817ff71d6aSMatt Porter 	spin_lock_irq (&ehci->lock);
5827ff71d6aSMatt Porter 	if (ehci->async)
5837d12e780SDavid Howells 		ehci_work (ehci);
5847ff71d6aSMatt Porter 	spin_unlock_irq (&ehci->lock);
5857ff71d6aSMatt Porter 	ehci_mem_cleanup (ehci);
5867ff71d6aSMatt Porter 
587ad93562bSAndiry Xu 	if (ehci->amd_pll_fix == 1)
588ad93562bSAndiry Xu 		usb_amd_dev_put();
58905570297SAlex He 
5907ff71d6aSMatt Porter #ifdef	EHCI_STATS
5917ff71d6aSMatt Porter 	ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
5927ff71d6aSMatt Porter 		ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
5937ff71d6aSMatt Porter 		ehci->stats.lost_iaa);
5947ff71d6aSMatt Porter 	ehci_dbg (ehci, "complete %ld unlink %ld\n",
5957ff71d6aSMatt Porter 		ehci->stats.complete, ehci->stats.unlink);
5961da177e4SLinus Torvalds #endif
5977ff71d6aSMatt Porter 
598083522d7SBenjamin Herrenschmidt 	dbg_status (ehci, "ehci_stop completed",
599083522d7SBenjamin Herrenschmidt 		    ehci_readl(ehci, &ehci->regs->status));
6001da177e4SLinus Torvalds }
6011da177e4SLinus Torvalds 
60218807521SDavid Brownell /* one-time init, only for memory state */
60318807521SDavid Brownell static int ehci_init(struct usb_hcd *hcd)
6041da177e4SLinus Torvalds {
6051da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
6061da177e4SLinus Torvalds 	u32			temp;
6071da177e4SLinus Torvalds 	int			retval;
6081da177e4SLinus Torvalds 	u32			hcc_params;
6093807e26dSAlek Du 	struct ehci_qh_hw	*hw;
6101da177e4SLinus Torvalds 
61118807521SDavid Brownell 	spin_lock_init(&ehci->lock);
61218807521SDavid Brownell 
613403dbd36SAlek Du 	/*
614403dbd36SAlek Du 	 * keep io watchdog by default, those good HCDs could turn off it later
615403dbd36SAlek Du 	 */
616403dbd36SAlek Du 	ehci->need_io_watchdog = 1;
6171da177e4SLinus Torvalds 	init_timer(&ehci->watchdog);
6181da177e4SLinus Torvalds 	ehci->watchdog.function = ehci_watchdog;
6191da177e4SLinus Torvalds 	ehci->watchdog.data = (unsigned long) ehci;
6201da177e4SLinus Torvalds 
62107d29b63SAlan Stern 	init_timer(&ehci->iaa_watchdog);
62207d29b63SAlan Stern 	ehci->iaa_watchdog.function = ehci_iaa_watchdog;
62307d29b63SAlan Stern 	ehci->iaa_watchdog.data = (unsigned long) ehci;
62407d29b63SAlan Stern 
625f75593ceSAlan Stern 	hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
626f75593ceSAlan Stern 
6271da177e4SLinus Torvalds 	/*
628cc62a7ebSKirill Smelkov 	 * by default set standard 80% (== 100 usec/uframe) max periodic
629cc62a7ebSKirill Smelkov 	 * bandwidth as required by USB 2.0
630cc62a7ebSKirill Smelkov 	 */
631cc62a7ebSKirill Smelkov 	ehci->uframe_periodic_max = 100;
632cc62a7ebSKirill Smelkov 
633cc62a7ebSKirill Smelkov 	/*
6341da177e4SLinus Torvalds 	 * hw default: 1K periodic list heads, one per frame.
6351da177e4SLinus Torvalds 	 * periodic_size can shrink by USBCMD update if hcc_params allows.
6361da177e4SLinus Torvalds 	 */
6371da177e4SLinus Torvalds 	ehci->periodic_size = DEFAULT_I_TDPS;
6389aa09d2fSKarsten Wiese 	INIT_LIST_HEAD(&ehci->cached_itd_list);
6390e5f231bSAlan Stern 	INIT_LIST_HEAD(&ehci->cached_sitd_list);
640f75593ceSAlan Stern 
6418e192910SGreg Kroah-Hartman 	if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
642f75593ceSAlan Stern 		/* periodic schedule size can be smaller than default */
643f75593ceSAlan Stern 		switch (EHCI_TUNE_FLS) {
644f75593ceSAlan Stern 		case 0: ehci->periodic_size = 1024; break;
645f75593ceSAlan Stern 		case 1: ehci->periodic_size = 512; break;
646f75593ceSAlan Stern 		case 2: ehci->periodic_size = 256; break;
647f75593ceSAlan Stern 		default:	BUG();
648f75593ceSAlan Stern 		}
649f75593ceSAlan Stern 	}
65018807521SDavid Brownell 	if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
6511da177e4SLinus Torvalds 		return retval;
6521da177e4SLinus Torvalds 
6531da177e4SLinus Torvalds 	/* controllers may cache some of the periodic schedule ... */
6541da177e4SLinus Torvalds 	if (HCC_ISOC_CACHE(hcc_params))		// full frame cache
655dccd574cSSarah Sharp 		ehci->i_thresh = 2 + 8;
6561da177e4SLinus Torvalds 	else					// N microframes cached
6571da177e4SLinus Torvalds 		ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
6581da177e4SLinus Torvalds 
6591da177e4SLinus Torvalds 	ehci->reclaim = NULL;
6601da177e4SLinus Torvalds 	ehci->next_uframe = -1;
6619aa09d2fSKarsten Wiese 	ehci->clock_frame = -1;
6621da177e4SLinus Torvalds 
6631da177e4SLinus Torvalds 	/*
6641da177e4SLinus Torvalds 	 * dedicate a qh for the async ring head, since we couldn't unlink
6651da177e4SLinus Torvalds 	 * a 'real' qh without stopping the async schedule [4.8].  use it
6661da177e4SLinus Torvalds 	 * as the 'reclamation list head' too.
6671da177e4SLinus Torvalds 	 * its dummy is used in hw_alt_next of many tds, to prevent the qh
6681da177e4SLinus Torvalds 	 * from automatically advancing to the next td after short reads.
6691da177e4SLinus Torvalds 	 */
6701da177e4SLinus Torvalds 	ehci->async->qh_next.qh = NULL;
6713807e26dSAlek Du 	hw = ehci->async->hw;
6723807e26dSAlek Du 	hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
6733807e26dSAlek Du 	hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
674*4f7a67e2SRicardo Martins #if defined(CONFIG_PPC_PS3)
675aaa0ef28SGeoff Levand 	hw->hw_info1 |= cpu_to_hc32(ehci, (1 << 7));	/* I = 1 */
676*4f7a67e2SRicardo Martins #endif
6773807e26dSAlek Du 	hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
6783807e26dSAlek Du 	hw->hw_qtd_next = EHCI_LIST_END(ehci);
6791da177e4SLinus Torvalds 	ehci->async->qh_state = QH_STATE_LINKED;
6803807e26dSAlek Du 	hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
6811da177e4SLinus Torvalds 
6821da177e4SLinus Torvalds 	/* clear interrupt enables, set irq latency */
6831da177e4SLinus Torvalds 	if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
6841da177e4SLinus Torvalds 		log2_irq_thresh = 0;
6851da177e4SLinus Torvalds 	temp = 1 << (16 + log2_irq_thresh);
6865a9cdf33SAlek Du 	if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
6875a9cdf33SAlek Du 		ehci->has_ppcd = 1;
6885a9cdf33SAlek Du 		ehci_dbg(ehci, "enable per-port change event\n");
6895a9cdf33SAlek Du 		temp |= CMD_PPCEE;
6905a9cdf33SAlek Du 	}
6911da177e4SLinus Torvalds 	if (HCC_CANPARK(hcc_params)) {
6921da177e4SLinus Torvalds 		/* HW default park == 3, on hardware that supports it (like
6931da177e4SLinus Torvalds 		 * NVidia and ALI silicon), maximizes throughput on the async
6941da177e4SLinus Torvalds 		 * schedule by avoiding QH fetches between transfers.
6951da177e4SLinus Torvalds 		 *
6961da177e4SLinus Torvalds 		 * With fast usb storage devices and NForce2, "park" seems to
6971da177e4SLinus Torvalds 		 * make problems:  throughput reduction (!), data errors...
6981da177e4SLinus Torvalds 		 */
6991da177e4SLinus Torvalds 		if (park) {
7001da177e4SLinus Torvalds 			park = min(park, (unsigned) 3);
7011da177e4SLinus Torvalds 			temp |= CMD_PARK;
7021da177e4SLinus Torvalds 			temp |= park << 8;
7031da177e4SLinus Torvalds 		}
70418807521SDavid Brownell 		ehci_dbg(ehci, "park %d\n", park);
7051da177e4SLinus Torvalds 	}
7061da177e4SLinus Torvalds 	if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
7071da177e4SLinus Torvalds 		/* periodic schedule size can be smaller than default */
7081da177e4SLinus Torvalds 		temp &= ~(3 << 2);
7091da177e4SLinus Torvalds 		temp |= (EHCI_TUNE_FLS << 2);
7101da177e4SLinus Torvalds 	}
71148f24970SAlek Du 	if (HCC_LPM(hcc_params)) {
71248f24970SAlek Du 		/* support link power management EHCI 1.1 addendum */
71348f24970SAlek Du 		ehci_dbg(ehci, "support lpm\n");
71448f24970SAlek Du 		ehci->has_lpm = 1;
71548f24970SAlek Du 		if (hird > 0xf) {
71648f24970SAlek Du 			ehci_dbg(ehci, "hird %d invalid, use default 0",
71748f24970SAlek Du 			hird);
71848f24970SAlek Du 			hird = 0;
71948f24970SAlek Du 		}
72048f24970SAlek Du 		temp |= hird << 24;
72148f24970SAlek Du 	}
72218807521SDavid Brownell 	ehci->command = temp;
72318807521SDavid Brownell 
72440f8db8fSAlan Stern 	/* Accept arbitrarily long scatter-gather lists */
7254307a28eSAndrea Righi 	if (!(hcd->driver->flags & HCD_LOCAL_MEM))
72640f8db8fSAlan Stern 		hcd->self.sg_tablesize = ~0;
72718807521SDavid Brownell 	return 0;
72818807521SDavid Brownell }
72918807521SDavid Brownell 
73018807521SDavid Brownell /* start HC running; it's halted, ehci_init() has been run (once) */
73118807521SDavid Brownell static int ehci_run (struct usb_hcd *hcd)
73218807521SDavid Brownell {
73318807521SDavid Brownell 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
73418807521SDavid Brownell 	u32			temp;
73518807521SDavid Brownell 	u32			hcc_params;
73618807521SDavid Brownell 
7371d619f12SMarcelo Tosatti 	hcd->uses_new_polling = 1;
7381d619f12SMarcelo Tosatti 
73918807521SDavid Brownell 	/* EHCI spec section 4.1 */
740876e0df9SGeoff Levand 
741083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
742083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
74318807521SDavid Brownell 
74418807521SDavid Brownell 	/*
74518807521SDavid Brownell 	 * hcc_params controls whether ehci->regs->segment must (!!!)
74618807521SDavid Brownell 	 * be used; it constrains QH/ITD/SITD and QTD locations.
74718807521SDavid Brownell 	 * pci_pool consistent memory always uses segment zero.
74818807521SDavid Brownell 	 * streaming mappings for I/O buffers, like pci_map_single(),
74918807521SDavid Brownell 	 * can return segments above 4GB, if the device allows.
75018807521SDavid Brownell 	 *
75118807521SDavid Brownell 	 * NOTE:  the dma mask is visible through dma_supported(), so
75218807521SDavid Brownell 	 * drivers can pass this info along ... like NETIF_F_HIGHDMA,
75318807521SDavid Brownell 	 * Scsi_Host.highmem_io, and so forth.  It's readonly to all
75418807521SDavid Brownell 	 * host side drivers though.
75518807521SDavid Brownell 	 */
756083522d7SBenjamin Herrenschmidt 	hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
75718807521SDavid Brownell 	if (HCC_64BIT_ADDR(hcc_params)) {
758083522d7SBenjamin Herrenschmidt 		ehci_writel(ehci, 0, &ehci->regs->segment);
75918807521SDavid Brownell #if 0
76018807521SDavid Brownell // this is deeply broken on almost all architectures
7616a35528aSYang Hongyang 		if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
76218807521SDavid Brownell 			ehci_info(ehci, "enabled 64bit DMA\n");
76318807521SDavid Brownell #endif
76418807521SDavid Brownell 	}
76518807521SDavid Brownell 
76618807521SDavid Brownell 
7671da177e4SLinus Torvalds 	// Philips, Intel, and maybe others need CMD_RUN before the
7681da177e4SLinus Torvalds 	// root hub will detect new devices (why?); NEC doesn't
76918807521SDavid Brownell 	ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
77018807521SDavid Brownell 	ehci->command |= CMD_RUN;
771083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, ehci->command, &ehci->regs->command);
77218807521SDavid Brownell 	dbg_cmd (ehci, "init", ehci->command);
7731da177e4SLinus Torvalds 
7741da177e4SLinus Torvalds 	/*
7751da177e4SLinus Torvalds 	 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
7761da177e4SLinus Torvalds 	 * are explicitly handed to companion controller(s), so no TT is
7771da177e4SLinus Torvalds 	 * involved with the root hub.  (Except where one is integrated,
7781da177e4SLinus Torvalds 	 * and there's no companion controller unless maybe for USB OTG.)
77932fe0198SAlan Stern 	 *
78032fe0198SAlan Stern 	 * Turning on the CF flag will transfer ownership of all ports
78132fe0198SAlan Stern 	 * from the companions to the EHCI controller.  If any of the
78232fe0198SAlan Stern 	 * companions are in the middle of a port reset at the time, it
78332fe0198SAlan Stern 	 * could cause trouble.  Write-locking ehci_cf_port_reset_rwsem
7841cb52658SDavid Brownell 	 * guarantees that no resets are in progress.  After we set CF,
7851cb52658SDavid Brownell 	 * a short delay lets the hardware catch up; new resets shouldn't
7861cb52658SDavid Brownell 	 * be started before the port switching actions could complete.
7871da177e4SLinus Torvalds 	 */
78832fe0198SAlan Stern 	down_write(&ehci_cf_port_reset_rwsem);
789e8799906SAlan Stern 	ehci->rh_state = EHCI_RH_RUNNING;
790083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
791083522d7SBenjamin Herrenschmidt 	ehci_readl(ehci, &ehci->regs->command);	/* unblock posted writes */
7921cb52658SDavid Brownell 	msleep(5);
79332fe0198SAlan Stern 	up_write(&ehci_cf_port_reset_rwsem);
794ee4ecb8aSOliver Neukum 	ehci->last_periodic_enable = ktime_get_real();
7951da177e4SLinus Torvalds 
796c430131aSJan Andersson 	temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
7971da177e4SLinus Torvalds 	ehci_info (ehci,
7982b70f073SAlan Stern 		"USB %x.%x started, EHCI %x.%02x%s\n",
7997ff71d6aSMatt Porter 		((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
8002b70f073SAlan Stern 		temp >> 8, temp & 0xff,
80193f1a47cSDavid Brownell 		ignore_oc ? ", overcurrent ignored" : "");
8021da177e4SLinus Torvalds 
803083522d7SBenjamin Herrenschmidt 	ehci_writel(ehci, INTR_MASK,
804083522d7SBenjamin Herrenschmidt 		    &ehci->regs->intr_enable); /* Turn On Interrupts */
8051da177e4SLinus Torvalds 
80618807521SDavid Brownell 	/* GRR this is run-once init(), being done every time the HC starts.
80718807521SDavid Brownell 	 * So long as they're part of class devices, we can't do it init()
80818807521SDavid Brownell 	 * since the class device isn't created that early.
80918807521SDavid Brownell 	 */
8101da177e4SLinus Torvalds 	create_debug_files(ehci);
8114c67045bSKirill Smelkov 	create_sysfs_files(ehci);
8121da177e4SLinus Torvalds 
8131da177e4SLinus Torvalds 	return 0;
8141da177e4SLinus Torvalds }
8151da177e4SLinus Torvalds 
8162093c6b4SMatthieu CASTET static int __maybe_unused ehci_setup (struct usb_hcd *hcd)
8172093c6b4SMatthieu CASTET {
8182093c6b4SMatthieu CASTET 	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
8192093c6b4SMatthieu CASTET 	int retval;
8202093c6b4SMatthieu CASTET 
8212093c6b4SMatthieu CASTET 	ehci->regs = (void __iomem *)ehci->caps +
8222093c6b4SMatthieu CASTET 	    HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
8232093c6b4SMatthieu CASTET 	dbg_hcs_params(ehci, "reset");
8242093c6b4SMatthieu CASTET 	dbg_hcc_params(ehci, "reset");
8252093c6b4SMatthieu CASTET 
8262093c6b4SMatthieu CASTET 	/* cache this readonly data; minimize chip reads */
8272093c6b4SMatthieu CASTET 	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
8282093c6b4SMatthieu CASTET 
8292093c6b4SMatthieu CASTET 	ehci->sbrn = HCD_USB2;
8302093c6b4SMatthieu CASTET 
8312093c6b4SMatthieu CASTET 	retval = ehci_halt(ehci);
8322093c6b4SMatthieu CASTET 	if (retval)
8332093c6b4SMatthieu CASTET 		return retval;
8342093c6b4SMatthieu CASTET 
8352093c6b4SMatthieu CASTET 	/* data structure init */
8362093c6b4SMatthieu CASTET 	retval = ehci_init(hcd);
8372093c6b4SMatthieu CASTET 	if (retval)
8382093c6b4SMatthieu CASTET 		return retval;
8392093c6b4SMatthieu CASTET 
8402093c6b4SMatthieu CASTET 	ehci_reset(ehci);
8412093c6b4SMatthieu CASTET 
8422093c6b4SMatthieu CASTET 	return 0;
8432093c6b4SMatthieu CASTET }
8442093c6b4SMatthieu CASTET 
8451da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
8461da177e4SLinus Torvalds 
8477d12e780SDavid Howells static irqreturn_t ehci_irq (struct usb_hcd *hcd)
8481da177e4SLinus Torvalds {
8491da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
85067b2e029SAlan Stern 	u32			status, masked_status, pcd_status = 0, cmd;
8511da177e4SLinus Torvalds 	int			bh;
8521da177e4SLinus Torvalds 
8531da177e4SLinus Torvalds 	spin_lock (&ehci->lock);
8541da177e4SLinus Torvalds 
855083522d7SBenjamin Herrenschmidt 	status = ehci_readl(ehci, &ehci->regs->status);
8561da177e4SLinus Torvalds 
8571da177e4SLinus Torvalds 	/* e.g. cardbus physical eject */
8581da177e4SLinus Torvalds 	if (status == ~(u32) 0) {
8591da177e4SLinus Torvalds 		ehci_dbg (ehci, "device removed\n");
8601da177e4SLinus Torvalds 		goto dead;
8611da177e4SLinus Torvalds 	}
8621da177e4SLinus Torvalds 
8632fbe2bf1SAlan Stern 	/*
8642fbe2bf1SAlan Stern 	 * We don't use STS_FLR, but some controllers don't like it to
8652fbe2bf1SAlan Stern 	 * remain on, so mask it out along with the other status bits.
8662fbe2bf1SAlan Stern 	 */
8672fbe2bf1SAlan Stern 	masked_status = status & (INTR_MASK | STS_FLR);
8682fbe2bf1SAlan Stern 
86969fff59dSAlan Stern 	/* Shared IRQ? */
870e8799906SAlan Stern 	if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
8711da177e4SLinus Torvalds 		spin_unlock(&ehci->lock);
8721da177e4SLinus Torvalds 		return IRQ_NONE;
8731da177e4SLinus Torvalds 	}
8741da177e4SLinus Torvalds 
8751da177e4SLinus Torvalds 	/* clear (just) interrupts */
87667b2e029SAlan Stern 	ehci_writel(ehci, masked_status, &ehci->regs->status);
877e82cc128SDavid Brownell 	cmd = ehci_readl(ehci, &ehci->regs->command);
8781da177e4SLinus Torvalds 	bh = 0;
8791da177e4SLinus Torvalds 
8809776afc8SDavid Brownell #ifdef	VERBOSE_DEBUG
8811da177e4SLinus Torvalds 	/* unrequested/ignored: Frame List Rollover */
8821da177e4SLinus Torvalds 	dbg_status (ehci, "irq", status);
8831da177e4SLinus Torvalds #endif
8841da177e4SLinus Torvalds 
8851da177e4SLinus Torvalds 	/* INT, ERR, and IAA interrupt rates can be throttled */
8861da177e4SLinus Torvalds 
8871da177e4SLinus Torvalds 	/* normal [4.15.1.2] or error [4.15.1.1] completion */
8881da177e4SLinus Torvalds 	if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
8891da177e4SLinus Torvalds 		if (likely ((status & STS_ERR) == 0))
8901da177e4SLinus Torvalds 			COUNT (ehci->stats.normal);
8911da177e4SLinus Torvalds 		else
8921da177e4SLinus Torvalds 			COUNT (ehci->stats.error);
8931da177e4SLinus Torvalds 		bh = 1;
8941da177e4SLinus Torvalds 	}
8951da177e4SLinus Torvalds 
8961da177e4SLinus Torvalds 	/* complete the unlinking of some qh [4.15.2.3] */
8971da177e4SLinus Torvalds 	if (status & STS_IAA) {
898e82cc128SDavid Brownell 		/* guard against (alleged) silicon errata */
8996feff1b9SAlan Stern 		if (cmd & CMD_IAAD)
900e82cc128SDavid Brownell 			ehci_dbg(ehci, "IAA with IAAD still set?\n");
901e82cc128SDavid Brownell 		if (ehci->reclaim) {
9021da177e4SLinus Torvalds 			COUNT(ehci->stats.reclaim);
90307d29b63SAlan Stern 			end_unlink_async(ehci);
904e82cc128SDavid Brownell 		} else
905e82cc128SDavid Brownell 			ehci_dbg(ehci, "IAA with nothing to reclaim?\n");
9061da177e4SLinus Torvalds 	}
9071da177e4SLinus Torvalds 
9081da177e4SLinus Torvalds 	/* remote wakeup [4.3.1] */
909d97cc2f2SDavid Brownell 	if (status & STS_PCD) {
9101da177e4SLinus Torvalds 		unsigned	i = HCS_N_PORTS (ehci->hcs_params);
9115a9cdf33SAlek Du 		u32		ppcd = 0;
912d1b1842cSDavid Brownell 
913d1b1842cSDavid Brownell 		/* kick root hub later */
9141d619f12SMarcelo Tosatti 		pcd_status = status;
9151da177e4SLinus Torvalds 
9161da177e4SLinus Torvalds 		/* resume root hub? */
917dc75ce9dSAlan Stern 		if (ehci->rh_state == EHCI_RH_SUSPENDED)
9188c03356aSAlan Stern 			usb_hcd_resume_root_hub(hcd);
9191da177e4SLinus Torvalds 
9205a9cdf33SAlek Du 		/* get per-port change detect bits */
9215a9cdf33SAlek Du 		if (ehci->has_ppcd)
9225a9cdf33SAlek Du 			ppcd = status >> 16;
9235a9cdf33SAlek Du 
9241da177e4SLinus Torvalds 		while (i--) {
9255a9cdf33SAlek Du 			int pstatus;
9265a9cdf33SAlek Du 
9275a9cdf33SAlek Du 			/* leverage per-port change bits feature */
9285a9cdf33SAlek Du 			if (ehci->has_ppcd && !(ppcd & (1 << i)))
9295a9cdf33SAlek Du 				continue;
9305a9cdf33SAlek Du 			pstatus = ehci_readl(ehci,
931083522d7SBenjamin Herrenschmidt 					 &ehci->regs->port_status[i]);
932b972b68cSDavid Brownell 
933b972b68cSDavid Brownell 			if (pstatus & PORT_OWNER)
9341da177e4SLinus Torvalds 				continue;
935eafe5b99SAlan Stern 			if (!(test_bit(i, &ehci->suspended_ports) &&
936eafe5b99SAlan Stern 					((pstatus & PORT_RESUME) ||
937eafe5b99SAlan Stern 						!(pstatus & PORT_SUSPEND)) &&
938eafe5b99SAlan Stern 					(pstatus & PORT_PE) &&
939eafe5b99SAlan Stern 					ehci->reset_done[i] == 0))
9401da177e4SLinus Torvalds 				continue;
9411da177e4SLinus Torvalds 
9421da177e4SLinus Torvalds 			/* start 20 msec resume signaling from this port,
9431da177e4SLinus Torvalds 			 * and make khubd collect PORT_STAT_C_SUSPEND to
94449d0f078SAlan Stern 			 * stop that signaling.  Use 5 ms extra for safety,
94549d0f078SAlan Stern 			 * like usb_port_resume() does.
9461da177e4SLinus Torvalds 			 */
94749d0f078SAlan Stern 			ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
948a448e4dcSAlan Stern 			set_bit(i, &ehci->resuming_ports);
9491da177e4SLinus Torvalds 			ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
95061e8b858SAlan Stern 			mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
9511da177e4SLinus Torvalds 		}
9521da177e4SLinus Torvalds 	}
9531da177e4SLinus Torvalds 
9541da177e4SLinus Torvalds 	/* PCI errors [4.15.2.4] */
9551da177e4SLinus Torvalds 	if (unlikely ((status & STS_FATAL) != 0)) {
95667b2e029SAlan Stern 		ehci_err(ehci, "fatal error\n");
957eafe5b99SAlan Stern 		dbg_cmd(ehci, "fatal", cmd);
9581da177e4SLinus Torvalds 		dbg_status(ehci, "fatal", status);
95967b2e029SAlan Stern 		ehci_halt(ehci);
9601da177e4SLinus Torvalds dead:
9611da177e4SLinus Torvalds 		ehci_reset(ehci);
962083522d7SBenjamin Herrenschmidt 		ehci_writel(ehci, 0, &ehci->regs->configured_flag);
96369fff59dSAlan Stern 		usb_hc_died(hcd);
9641da177e4SLinus Torvalds 		/* generic layer kills/unlinks all urbs, then
9651da177e4SLinus Torvalds 		 * uses ehci_stop to clean up the rest
9661da177e4SLinus Torvalds 		 */
9671da177e4SLinus Torvalds 		bh = 1;
9681da177e4SLinus Torvalds 	}
9691da177e4SLinus Torvalds 
9701da177e4SLinus Torvalds 	if (bh)
9717d12e780SDavid Howells 		ehci_work (ehci);
9721da177e4SLinus Torvalds 	spin_unlock (&ehci->lock);
973d1b1842cSDavid Brownell 	if (pcd_status)
9741d619f12SMarcelo Tosatti 		usb_hcd_poll_rh_status(hcd);
9751da177e4SLinus Torvalds 	return IRQ_HANDLED;
9761da177e4SLinus Torvalds }
9771da177e4SLinus Torvalds 
9781da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
9791da177e4SLinus Torvalds 
9801da177e4SLinus Torvalds /*
9811da177e4SLinus Torvalds  * non-error returns are a promise to giveback() the urb later
9821da177e4SLinus Torvalds  * we drop ownership so next owner (or urb unlink) can get it
9831da177e4SLinus Torvalds  *
9841da177e4SLinus Torvalds  * urb + dev is in hcd.self.controller.urb_list
9851da177e4SLinus Torvalds  * we're queueing TDs onto software and hardware lists
9861da177e4SLinus Torvalds  *
9871da177e4SLinus Torvalds  * hcd-specific init for hcpriv hasn't been done yet
9881da177e4SLinus Torvalds  *
9891da177e4SLinus Torvalds  * NOTE:  control, bulk, and interrupt share the same code to append TDs
9901da177e4SLinus Torvalds  * to a (possibly active) QH, and the same QH scanning code.
9911da177e4SLinus Torvalds  */
9921da177e4SLinus Torvalds static int ehci_urb_enqueue (
9931da177e4SLinus Torvalds 	struct usb_hcd	*hcd,
9941da177e4SLinus Torvalds 	struct urb	*urb,
99555016f10SAl Viro 	gfp_t		mem_flags
9961da177e4SLinus Torvalds ) {
9971da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
9981da177e4SLinus Torvalds 	struct list_head	qtd_list;
9991da177e4SLinus Torvalds 
10001da177e4SLinus Torvalds 	INIT_LIST_HEAD (&qtd_list);
10011da177e4SLinus Torvalds 
10021da177e4SLinus Torvalds 	switch (usb_pipetype (urb->pipe)) {
100325b70a86SDavid Brownell 	case PIPE_CONTROL:
100425b70a86SDavid Brownell 		/* qh_completions() code doesn't handle all the fault cases
100525b70a86SDavid Brownell 		 * in multi-TD control transfers.  Even 1KB is rare anyway.
100625b70a86SDavid Brownell 		 */
100725b70a86SDavid Brownell 		if (urb->transfer_buffer_length > (16 * 1024))
100825b70a86SDavid Brownell 			return -EMSGSIZE;
100925b70a86SDavid Brownell 		/* FALLTHROUGH */
101025b70a86SDavid Brownell 	/* case PIPE_BULK: */
10111da177e4SLinus Torvalds 	default:
10121da177e4SLinus Torvalds 		if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
10131da177e4SLinus Torvalds 			return -ENOMEM;
1014e9df41c5SAlan Stern 		return submit_async(ehci, urb, &qtd_list, mem_flags);
10151da177e4SLinus Torvalds 
10161da177e4SLinus Torvalds 	case PIPE_INTERRUPT:
10171da177e4SLinus Torvalds 		if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
10181da177e4SLinus Torvalds 			return -ENOMEM;
1019e9df41c5SAlan Stern 		return intr_submit(ehci, urb, &qtd_list, mem_flags);
10201da177e4SLinus Torvalds 
10211da177e4SLinus Torvalds 	case PIPE_ISOCHRONOUS:
10221da177e4SLinus Torvalds 		if (urb->dev->speed == USB_SPEED_HIGH)
10231da177e4SLinus Torvalds 			return itd_submit (ehci, urb, mem_flags);
10241da177e4SLinus Torvalds 		else
10251da177e4SLinus Torvalds 			return sitd_submit (ehci, urb, mem_flags);
10261da177e4SLinus Torvalds 	}
10271da177e4SLinus Torvalds }
10281da177e4SLinus Torvalds 
10291da177e4SLinus Torvalds static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
10301da177e4SLinus Torvalds {
103107d29b63SAlan Stern 	/* failfast */
1032e8799906SAlan Stern 	if (ehci->rh_state != EHCI_RH_RUNNING && ehci->reclaim)
103307d29b63SAlan Stern 		end_unlink_async(ehci);
103407d29b63SAlan Stern 
10353a44494eSAlan Stern 	/* If the QH isn't linked then there's nothing we can do
10363a44494eSAlan Stern 	 * unless we were called during a giveback, in which case
10373a44494eSAlan Stern 	 * qh_completions() has to deal with it.
10383a44494eSAlan Stern 	 */
10393a44494eSAlan Stern 	if (qh->qh_state != QH_STATE_LINKED) {
10403a44494eSAlan Stern 		if (qh->qh_state == QH_STATE_COMPLETING)
10413a44494eSAlan Stern 			qh->needs_rescan = 1;
10423a44494eSAlan Stern 		return;
10433a44494eSAlan Stern 	}
104407d29b63SAlan Stern 
104507d29b63SAlan Stern 	/* defer till later if busy */
10463a44494eSAlan Stern 	if (ehci->reclaim) {
10471da177e4SLinus Torvalds 		struct ehci_qh		*last;
10481da177e4SLinus Torvalds 
10491da177e4SLinus Torvalds 		for (last = ehci->reclaim;
10501da177e4SLinus Torvalds 				last->reclaim;
10511da177e4SLinus Torvalds 				last = last->reclaim)
10521da177e4SLinus Torvalds 			continue;
10531da177e4SLinus Torvalds 		qh->qh_state = QH_STATE_UNLINK_WAIT;
10541da177e4SLinus Torvalds 		last->reclaim = qh;
10551da177e4SLinus Torvalds 
105607d29b63SAlan Stern 	/* start IAA cycle */
105707d29b63SAlan Stern 	} else
10581da177e4SLinus Torvalds 		start_unlink_async (ehci, qh);
10591da177e4SLinus Torvalds }
10601da177e4SLinus Torvalds 
10611da177e4SLinus Torvalds /* remove from hardware lists
10621da177e4SLinus Torvalds  * completions normally happen asynchronously
10631da177e4SLinus Torvalds  */
10641da177e4SLinus Torvalds 
1065e9df41c5SAlan Stern static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
10661da177e4SLinus Torvalds {
10671da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
10681da177e4SLinus Torvalds 	struct ehci_qh		*qh;
10691da177e4SLinus Torvalds 	unsigned long		flags;
1070e9df41c5SAlan Stern 	int			rc;
10711da177e4SLinus Torvalds 
10721da177e4SLinus Torvalds 	spin_lock_irqsave (&ehci->lock, flags);
1073e9df41c5SAlan Stern 	rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1074e9df41c5SAlan Stern 	if (rc)
1075e9df41c5SAlan Stern 		goto done;
1076e9df41c5SAlan Stern 
10771da177e4SLinus Torvalds 	switch (usb_pipetype (urb->pipe)) {
10781da177e4SLinus Torvalds 	// case PIPE_CONTROL:
10791da177e4SLinus Torvalds 	// case PIPE_BULK:
10801da177e4SLinus Torvalds 	default:
10811da177e4SLinus Torvalds 		qh = (struct ehci_qh *) urb->hcpriv;
10821da177e4SLinus Torvalds 		if (!qh)
10831da177e4SLinus Torvalds 			break;
108407d29b63SAlan Stern 		switch (qh->qh_state) {
108507d29b63SAlan Stern 		case QH_STATE_LINKED:
108607d29b63SAlan Stern 		case QH_STATE_COMPLETING:
10871da177e4SLinus Torvalds 			unlink_async(ehci, qh);
10881da177e4SLinus Torvalds 			break;
108907d29b63SAlan Stern 		case QH_STATE_UNLINK:
109007d29b63SAlan Stern 		case QH_STATE_UNLINK_WAIT:
109107d29b63SAlan Stern 			/* already started */
109207d29b63SAlan Stern 			break;
109307d29b63SAlan Stern 		case QH_STATE_IDLE:
10947a0f0d95SAlan Stern 			/* QH might be waiting for a Clear-TT-Buffer */
10957a0f0d95SAlan Stern 			qh_completions(ehci, qh);
109607d29b63SAlan Stern 			break;
109707d29b63SAlan Stern 		}
109807d29b63SAlan Stern 		break;
10991da177e4SLinus Torvalds 
11001da177e4SLinus Torvalds 	case PIPE_INTERRUPT:
11011da177e4SLinus Torvalds 		qh = (struct ehci_qh *) urb->hcpriv;
11021da177e4SLinus Torvalds 		if (!qh)
11031da177e4SLinus Torvalds 			break;
11041da177e4SLinus Torvalds 		switch (qh->qh_state) {
11051da177e4SLinus Torvalds 		case QH_STATE_LINKED:
1106a448c9d8SAlan Stern 		case QH_STATE_COMPLETING:
11071da177e4SLinus Torvalds 			intr_deschedule (ehci, qh);
1108a448c9d8SAlan Stern 			break;
11091da177e4SLinus Torvalds 		case QH_STATE_IDLE:
11107d12e780SDavid Howells 			qh_completions (ehci, qh);
11111da177e4SLinus Torvalds 			break;
11121da177e4SLinus Torvalds 		default:
11131da177e4SLinus Torvalds 			ehci_dbg (ehci, "bogus qh %p state %d\n",
11141da177e4SLinus Torvalds 					qh, qh->qh_state);
11151da177e4SLinus Torvalds 			goto done;
11161da177e4SLinus Torvalds 		}
11171da177e4SLinus Torvalds 		break;
11181da177e4SLinus Torvalds 
11191da177e4SLinus Torvalds 	case PIPE_ISOCHRONOUS:
11201da177e4SLinus Torvalds 		// itd or sitd ...
11211da177e4SLinus Torvalds 
11221da177e4SLinus Torvalds 		// wait till next completion, do it then.
11231da177e4SLinus Torvalds 		// completion irqs can wait up to 1024 msec,
11241da177e4SLinus Torvalds 		break;
11251da177e4SLinus Torvalds 	}
11261da177e4SLinus Torvalds done:
11271da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ehci->lock, flags);
1128e9df41c5SAlan Stern 	return rc;
11291da177e4SLinus Torvalds }
11301da177e4SLinus Torvalds 
11311da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
11321da177e4SLinus Torvalds 
11331da177e4SLinus Torvalds // bulk qh holds the data toggle
11341da177e4SLinus Torvalds 
11351da177e4SLinus Torvalds static void
11361da177e4SLinus Torvalds ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
11371da177e4SLinus Torvalds {
11381da177e4SLinus Torvalds 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
11391da177e4SLinus Torvalds 	unsigned long		flags;
11401da177e4SLinus Torvalds 	struct ehci_qh		*qh, *tmp;
11411da177e4SLinus Torvalds 
11421da177e4SLinus Torvalds 	/* ASSERT:  any requests/urbs are being unlinked */
11431da177e4SLinus Torvalds 	/* ASSERT:  nobody can be submitting urbs for this any more */
11441da177e4SLinus Torvalds 
11451da177e4SLinus Torvalds rescan:
11461da177e4SLinus Torvalds 	spin_lock_irqsave (&ehci->lock, flags);
11471da177e4SLinus Torvalds 	qh = ep->hcpriv;
11481da177e4SLinus Torvalds 	if (!qh)
11491da177e4SLinus Torvalds 		goto done;
11501da177e4SLinus Torvalds 
11511da177e4SLinus Torvalds 	/* endpoints can be iso streams.  for now, we don't
11521da177e4SLinus Torvalds 	 * accelerate iso completions ... so spin a while.
11531da177e4SLinus Torvalds 	 */
11541082f57aSClemens Ladisch 	if (qh->hw == NULL) {
11551da177e4SLinus Torvalds 		ehci_vdbg (ehci, "iso delay\n");
11561da177e4SLinus Torvalds 		goto idle_timeout;
11571da177e4SLinus Torvalds 	}
11581da177e4SLinus Torvalds 
1159e8799906SAlan Stern 	if (ehci->rh_state != EHCI_RH_RUNNING)
11601da177e4SLinus Torvalds 		qh->qh_state = QH_STATE_IDLE;
11611da177e4SLinus Torvalds 	switch (qh->qh_state) {
11621da177e4SLinus Torvalds 	case QH_STATE_LINKED:
11633a44494eSAlan Stern 	case QH_STATE_COMPLETING:
11641da177e4SLinus Torvalds 		for (tmp = ehci->async->qh_next.qh;
11651da177e4SLinus Torvalds 				tmp && tmp != qh;
11661da177e4SLinus Torvalds 				tmp = tmp->qh_next.qh)
11671da177e4SLinus Torvalds 			continue;
116802e2c51bSAlan Stern 		/* periodic qh self-unlinks on empty, and a COMPLETING qh
116902e2c51bSAlan Stern 		 * may already be unlinked.
117002e2c51bSAlan Stern 		 */
117102e2c51bSAlan Stern 		if (tmp)
11721da177e4SLinus Torvalds 			unlink_async(ehci, qh);
11731da177e4SLinus Torvalds 		/* FALL THROUGH */
11741da177e4SLinus Torvalds 	case QH_STATE_UNLINK:		/* wait for hw to finish? */
117507d29b63SAlan Stern 	case QH_STATE_UNLINK_WAIT:
11761da177e4SLinus Torvalds idle_timeout:
11771da177e4SLinus Torvalds 		spin_unlock_irqrestore (&ehci->lock, flags);
117822c43863SNishanth Aravamudan 		schedule_timeout_uninterruptible(1);
11791da177e4SLinus Torvalds 		goto rescan;
11801da177e4SLinus Torvalds 	case QH_STATE_IDLE:		/* fully unlinked */
1181914b7012SAlan Stern 		if (qh->clearing_tt)
1182914b7012SAlan Stern 			goto idle_timeout;
11831da177e4SLinus Torvalds 		if (list_empty (&qh->qtd_list)) {
11841da177e4SLinus Torvalds 			qh_put (qh);
11851da177e4SLinus Torvalds 			break;
11861da177e4SLinus Torvalds 		}
11871da177e4SLinus Torvalds 		/* else FALL THROUGH */
11881da177e4SLinus Torvalds 	default:
11891da177e4SLinus Torvalds 		/* caller was supposed to have unlinked any requests;
11901da177e4SLinus Torvalds 		 * that's not our job.  just leak this memory.
11911da177e4SLinus Torvalds 		 */
11921da177e4SLinus Torvalds 		ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
11931da177e4SLinus Torvalds 			qh, ep->desc.bEndpointAddress, qh->qh_state,
11941da177e4SLinus Torvalds 			list_empty (&qh->qtd_list) ? "" : "(has tds)");
11951da177e4SLinus Torvalds 		break;
11961da177e4SLinus Torvalds 	}
11971da177e4SLinus Torvalds 	ep->hcpriv = NULL;
11981da177e4SLinus Torvalds done:
11991da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ehci->lock, flags);
12001da177e4SLinus Torvalds }
12011da177e4SLinus Torvalds 
1202b18ffd49SAlan Stern static void
1203b18ffd49SAlan Stern ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1204b18ffd49SAlan Stern {
1205b18ffd49SAlan Stern 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
1206b18ffd49SAlan Stern 	struct ehci_qh		*qh;
1207b18ffd49SAlan Stern 	int			eptype = usb_endpoint_type(&ep->desc);
1208a455212dSAlan Stern 	int			epnum = usb_endpoint_num(&ep->desc);
1209a455212dSAlan Stern 	int			is_out = usb_endpoint_dir_out(&ep->desc);
1210a455212dSAlan Stern 	unsigned long		flags;
1211b18ffd49SAlan Stern 
1212b18ffd49SAlan Stern 	if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
1213b18ffd49SAlan Stern 		return;
1214b18ffd49SAlan Stern 
1215a455212dSAlan Stern 	spin_lock_irqsave(&ehci->lock, flags);
1216b18ffd49SAlan Stern 	qh = ep->hcpriv;
1217b18ffd49SAlan Stern 
1218b18ffd49SAlan Stern 	/* For Bulk and Interrupt endpoints we maintain the toggle state
1219b18ffd49SAlan Stern 	 * in the hardware; the toggle bits in udev aren't used at all.
1220b18ffd49SAlan Stern 	 * When an endpoint is reset by usb_clear_halt() we must reset
1221b18ffd49SAlan Stern 	 * the toggle bit in the QH.
1222b18ffd49SAlan Stern 	 */
1223b18ffd49SAlan Stern 	if (qh) {
1224a455212dSAlan Stern 		usb_settoggle(qh->dev, epnum, is_out, 0);
1225b18ffd49SAlan Stern 		if (!list_empty(&qh->qtd_list)) {
1226b18ffd49SAlan Stern 			WARN_ONCE(1, "clear_halt for a busy endpoint\n");
12273a44494eSAlan Stern 		} else if (qh->qh_state == QH_STATE_LINKED ||
12283a44494eSAlan Stern 				qh->qh_state == QH_STATE_COMPLETING) {
1229a455212dSAlan Stern 
1230a455212dSAlan Stern 			/* The toggle value in the QH can't be updated
1231a455212dSAlan Stern 			 * while the QH is active.  Unlink it now;
1232a455212dSAlan Stern 			 * re-linking will call qh_refresh().
1233b18ffd49SAlan Stern 			 */
1234a448c9d8SAlan Stern 			if (eptype == USB_ENDPOINT_XFER_BULK)
1235b18ffd49SAlan Stern 				unlink_async(ehci, qh);
1236a448c9d8SAlan Stern 			else
1237b18ffd49SAlan Stern 				intr_deschedule(ehci, qh);
1238b18ffd49SAlan Stern 		}
1239b18ffd49SAlan Stern 	}
1240a455212dSAlan Stern 	spin_unlock_irqrestore(&ehci->lock, flags);
1241b18ffd49SAlan Stern }
1242b18ffd49SAlan Stern 
12437ff71d6aSMatt Porter static int ehci_get_frame (struct usb_hcd *hcd)
12447ff71d6aSMatt Porter {
12457ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
124668aa95d5SAlan Stern 	return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size;
12477ff71d6aSMatt Porter }
12481da177e4SLinus Torvalds 
12491da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
1250eb70e5abSAlexander Shishkin /*
1251eb70e5abSAlexander Shishkin  * The EHCI in ChipIdea HDRC cannot be a separate module or device,
1252eb70e5abSAlexander Shishkin  * because its registers (and irq) are shared between host/gadget/otg
1253eb70e5abSAlexander Shishkin  * functions  and in order to facilitate role switching we cannot
1254eb70e5abSAlexander Shishkin  * give the ehci driver exclusive access to those.
1255eb70e5abSAlexander Shishkin  */
1256eb70e5abSAlexander Shishkin #ifndef CHIPIDEA_EHCI
12571da177e4SLinus Torvalds 
12582b70f073SAlan Stern MODULE_DESCRIPTION(DRIVER_DESC);
12591da177e4SLinus Torvalds MODULE_AUTHOR (DRIVER_AUTHOR);
12601da177e4SLinus Torvalds MODULE_LICENSE ("GPL");
12611da177e4SLinus Torvalds 
12627ff71d6aSMatt Porter #ifdef CONFIG_PCI
12637ff71d6aSMatt Porter #include "ehci-pci.c"
126401cced25SKumar Gala #define	PCI_DRIVER		ehci_pci_driver
12657ff71d6aSMatt Porter #endif
12661da177e4SLinus Torvalds 
1267ba02978aSLi Yang #ifdef CONFIG_USB_EHCI_FSL
126880cb9aeeSRandy Vinson #include "ehci-fsl.c"
126901cced25SKumar Gala #define	PLATFORM_DRIVER		ehci_fsl_driver
127080cb9aeeSRandy Vinson #endif
127180cb9aeeSRandy Vinson 
12727e8d5cd9SDaniel Mack #ifdef CONFIG_USB_EHCI_MXC
12737e8d5cd9SDaniel Mack #include "ehci-mxc.c"
12747e8d5cd9SDaniel Mack #define PLATFORM_DRIVER		ehci_mxc_driver
12757e8d5cd9SDaniel Mack #endif
12767e8d5cd9SDaniel Mack 
127760b0bf0fSYoshihiro Shimoda #ifdef CONFIG_USB_EHCI_SH
127863c84552SPaul Mundt #include "ehci-sh.c"
127963c84552SPaul Mundt #define PLATFORM_DRIVER		ehci_hcd_sh_driver
128063c84552SPaul Mundt #endif
128163c84552SPaul Mundt 
128237663860SManuel Lauss #ifdef CONFIG_MIPS_ALCHEMY
128376fa9a24SJordan Crouse #include "ehci-au1xxx.c"
128401cced25SKumar Gala #define	PLATFORM_DRIVER		ehci_hcd_au1xxx_driver
128576fa9a24SJordan Crouse #endif
128676fa9a24SJordan Crouse 
12877f124f4bSKeshava Munegowda #ifdef CONFIG_USB_EHCI_HCD_OMAP
128854ab2b02SFelipe Balbi #include "ehci-omap.c"
128954ab2b02SFelipe Balbi #define        PLATFORM_DRIVER         ehci_hcd_omap_driver
129054ab2b02SFelipe Balbi #endif
129154ab2b02SFelipe Balbi 
1292ad75a410SGeoff Levand #ifdef CONFIG_PPC_PS3
1293ad75a410SGeoff Levand #include "ehci-ps3.c"
12947a4eb7fdSGeoff Levand #define	PS3_SYSTEM_BUS_DRIVER	ps3_ehci_driver
1295ad75a410SGeoff Levand #endif
1296ad75a410SGeoff Levand 
1297da0e8fb0SValentine Barshak #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
1298da0e8fb0SValentine Barshak #include "ehci-ppc-of.c"
1299da0e8fb0SValentine Barshak #define OF_PLATFORM_DRIVER	ehci_hcd_ppc_of_driver
1300da0e8fb0SValentine Barshak #endif
1301da0e8fb0SValentine Barshak 
130208d3c18eSJulie Zhu #ifdef CONFIG_XPS_USB_HCD_XILINX
130308d3c18eSJulie Zhu #include "ehci-xilinx-of.c"
13041f23b2d9SGrant Likely #define XILINX_OF_PLATFORM_DRIVER	ehci_hcd_xilinx_of_driver
130508d3c18eSJulie Zhu #endif
130608d3c18eSJulie Zhu 
1307705a7521SLennert Buytenhek #ifdef CONFIG_PLAT_ORION
1308e96ffe2fSTzachi Perelstein #include "ehci-orion.c"
1309e96ffe2fSTzachi Perelstein #define	PLATFORM_DRIVER		ehci_orion_driver
1310e96ffe2fSTzachi Perelstein #endif
1311e96ffe2fSTzachi Perelstein 
131291bc4d31SVladimir Barinov #ifdef CONFIG_ARCH_IXP4XX
131391bc4d31SVladimir Barinov #include "ehci-ixp4xx.c"
131491bc4d31SVladimir Barinov #define	PLATFORM_DRIVER		ixp4xx_ehci_driver
131591bc4d31SVladimir Barinov #endif
131691bc4d31SVladimir Barinov 
1317586dfc8cSWan ZongShun #ifdef CONFIG_USB_W90X900_EHCI
1318586dfc8cSWan ZongShun #include "ehci-w90x900.c"
1319586dfc8cSWan ZongShun #define	PLATFORM_DRIVER		ehci_hcd_w90x900_driver
1320586dfc8cSWan ZongShun #endif
1321586dfc8cSWan ZongShun 
1322501c9c08SNicolas Ferre #ifdef CONFIG_ARCH_AT91
1323501c9c08SNicolas Ferre #include "ehci-atmel.c"
1324501c9c08SNicolas Ferre #define	PLATFORM_DRIVER		ehci_atmel_driver
1325501c9c08SNicolas Ferre #endif
1326501c9c08SNicolas Ferre 
13271643accdSDavid Daney #ifdef CONFIG_USB_OCTEON_EHCI
13281643accdSDavid Daney #include "ehci-octeon.c"
13291643accdSDavid Daney #define PLATFORM_DRIVER		ehci_octeon_driver
13301643accdSDavid Daney #endif
13311643accdSDavid Daney 
1332760efe69SMac Lin #ifdef CONFIG_USB_CNS3XXX_EHCI
1333760efe69SMac Lin #include "ehci-cns3xxx.c"
1334760efe69SMac Lin #define PLATFORM_DRIVER		cns3xxx_ehci_driver
1335760efe69SMac Lin #endif
1336760efe69SMac Lin 
1337ad78acafSAlexey Charkov #ifdef CONFIG_ARCH_VT8500
1338ad78acafSAlexey Charkov #include "ehci-vt8500.c"
1339ad78acafSAlexey Charkov #define	PLATFORM_DRIVER		vt8500_ehci_driver
1340ad78acafSAlexey Charkov #endif
1341ad78acafSAlexey Charkov 
1342c8c38de9SDeepak Sikri #ifdef CONFIG_PLAT_SPEAR
1343c8c38de9SDeepak Sikri #include "ehci-spear.c"
1344c8c38de9SDeepak Sikri #define PLATFORM_DRIVER		spear_ehci_hcd_driver
1345c8c38de9SDeepak Sikri #endif
1346c8c38de9SDeepak Sikri 
1347b0848aeaSPavankumar Kondeti #ifdef CONFIG_USB_EHCI_MSM
1348b0848aeaSPavankumar Kondeti #include "ehci-msm.c"
1349b0848aeaSPavankumar Kondeti #define PLATFORM_DRIVER		ehci_msm_driver
1350b0848aeaSPavankumar Kondeti #endif
1351b0848aeaSPavankumar Kondeti 
135222ced687SAnoop #ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
135322ced687SAnoop #include "ehci-pmcmsp.c"
135422ced687SAnoop #define	PLATFORM_DRIVER		ehci_hcd_msp_driver
135522ced687SAnoop #endif
135622ced687SAnoop 
135779ad3b5aSBenoit Goby #ifdef CONFIG_USB_EHCI_TEGRA
135879ad3b5aSBenoit Goby #include "ehci-tegra.c"
135979ad3b5aSBenoit Goby #define PLATFORM_DRIVER		tegra_ehci_driver
136079ad3b5aSBenoit Goby #endif
136179ad3b5aSBenoit Goby 
13621bcc5aa8SJoonyoung Shim #ifdef CONFIG_USB_EHCI_S5P
13631bcc5aa8SJoonyoung Shim #include "ehci-s5p.c"
13641bcc5aa8SJoonyoung Shim #define PLATFORM_DRIVER		s5p_ehci_driver
13651bcc5aa8SJoonyoung Shim #endif
13661bcc5aa8SJoonyoung Shim 
13679be03929SJan Andersson #ifdef CONFIG_SPARC_LEON
13689be03929SJan Andersson #include "ehci-grlib.c"
13699be03929SJan Andersson #define PLATFORM_DRIVER		ehci_grlib_driver
13709be03929SJan Andersson #endif
13719be03929SJan Andersson 
13723af5154aSJayachandran C #ifdef CONFIG_CPU_XLR
137323106343SJayachandran C #include "ehci-xls.c"
137423106343SJayachandran C #define PLATFORM_DRIVER		ehci_xls_driver
137523106343SJayachandran C #endif
137623106343SJayachandran C 
13773a082ec9SNeil Zhang #ifdef CONFIG_USB_EHCI_MV
13783a082ec9SNeil Zhang #include "ehci-mv.c"
13793a082ec9SNeil Zhang #define        PLATFORM_DRIVER         ehci_mv_driver
13803a082ec9SNeil Zhang #endif
13813a082ec9SNeil Zhang 
1382f30cdbcbSKelvin Cheung #ifdef CONFIG_MACH_LOONGSON1
1383f30cdbcbSKelvin Cheung #include "ehci-ls1x.c"
1384f30cdbcbSKelvin Cheung #define PLATFORM_DRIVER		ehci_ls1x_driver
1385f30cdbcbSKelvin Cheung #endif
1386f30cdbcbSKelvin Cheung 
1387c256667fSSteven J. Hill #ifdef CONFIG_MIPS_SEAD3
1388c256667fSSteven J. Hill #include "ehci-sead3.c"
1389c256667fSSteven J. Hill #define	PLATFORM_DRIVER		ehci_hcd_sead3_driver
1390c256667fSSteven J. Hill #endif
1391c256667fSSteven J. Hill 
13927a7a4a59SHauke Mehrtens #ifdef CONFIG_USB_EHCI_HCD_PLATFORM
13937a7a4a59SHauke Mehrtens #include "ehci-platform.c"
13947a7a4a59SHauke Mehrtens #define PLATFORM_DRIVER		ehci_platform_driver
13957a7a4a59SHauke Mehrtens #endif
13967a7a4a59SHauke Mehrtens 
1397ad75a410SGeoff Levand #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
13981f23b2d9SGrant Likely     !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
13991f23b2d9SGrant Likely     !defined(XILINX_OF_PLATFORM_DRIVER)
14007ff71d6aSMatt Porter #error "missing bus glue for ehci-hcd"
14017ff71d6aSMatt Porter #endif
140201cced25SKumar Gala 
140301cced25SKumar Gala static int __init ehci_hcd_init(void)
140401cced25SKumar Gala {
140501cced25SKumar Gala 	int retval = 0;
140601cced25SKumar Gala 
14072b70f073SAlan Stern 	if (usb_disabled())
14082b70f073SAlan Stern 		return -ENODEV;
14092b70f073SAlan Stern 
14102b70f073SAlan Stern 	printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
14119beeee65SAlan Stern 	set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
14129beeee65SAlan Stern 	if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
14139beeee65SAlan Stern 			test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
14149beeee65SAlan Stern 		printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
14159beeee65SAlan Stern 				" before uhci_hcd and ohci_hcd, not after\n");
14169beeee65SAlan Stern 
141701cced25SKumar Gala 	pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
141801cced25SKumar Gala 		 hcd_name,
141901cced25SKumar Gala 		 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
142001cced25SKumar Gala 		 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
142101cced25SKumar Gala 
1422694cc208STony Jones #ifdef DEBUG
142308f4e586SGreg Kroah-Hartman 	ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
14249beeee65SAlan Stern 	if (!ehci_debug_root) {
14259beeee65SAlan Stern 		retval = -ENOENT;
14269beeee65SAlan Stern 		goto err_debug;
14279beeee65SAlan Stern 	}
1428694cc208STony Jones #endif
1429694cc208STony Jones 
143001cced25SKumar Gala #ifdef PLATFORM_DRIVER
143101cced25SKumar Gala 	retval = platform_driver_register(&PLATFORM_DRIVER);
1432da0e8fb0SValentine Barshak 	if (retval < 0)
1433da0e8fb0SValentine Barshak 		goto clean0;
143401cced25SKumar Gala #endif
143501cced25SKumar Gala 
143601cced25SKumar Gala #ifdef PCI_DRIVER
143701cced25SKumar Gala 	retval = pci_register_driver(&PCI_DRIVER);
1438da0e8fb0SValentine Barshak 	if (retval < 0)
1439da0e8fb0SValentine Barshak 		goto clean1;
1440ad75a410SGeoff Levand #endif
1441ad75a410SGeoff Levand 
1442ad75a410SGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
14437a4eb7fdSGeoff Levand 	retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1444da0e8fb0SValentine Barshak 	if (retval < 0)
1445da0e8fb0SValentine Barshak 		goto clean2;
1446da0e8fb0SValentine Barshak #endif
1447da0e8fb0SValentine Barshak 
1448da0e8fb0SValentine Barshak #ifdef OF_PLATFORM_DRIVER
1449d35fb641SGrant Likely 	retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1450da0e8fb0SValentine Barshak 	if (retval < 0)
1451da0e8fb0SValentine Barshak 		goto clean3;
1452da0e8fb0SValentine Barshak #endif
14531f23b2d9SGrant Likely 
14541f23b2d9SGrant Likely #ifdef XILINX_OF_PLATFORM_DRIVER
1455d35fb641SGrant Likely 	retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
14561f23b2d9SGrant Likely 	if (retval < 0)
14571f23b2d9SGrant Likely 		goto clean4;
14581f23b2d9SGrant Likely #endif
1459da0e8fb0SValentine Barshak 	return retval;
1460da0e8fb0SValentine Barshak 
14611f23b2d9SGrant Likely #ifdef XILINX_OF_PLATFORM_DRIVER
1462d35fb641SGrant Likely 	/* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
14631f23b2d9SGrant Likely clean4:
14641f23b2d9SGrant Likely #endif
1465da0e8fb0SValentine Barshak #ifdef OF_PLATFORM_DRIVER
1466d35fb641SGrant Likely 	platform_driver_unregister(&OF_PLATFORM_DRIVER);
1467da0e8fb0SValentine Barshak clean3:
1468da0e8fb0SValentine Barshak #endif
1469da0e8fb0SValentine Barshak #ifdef PS3_SYSTEM_BUS_DRIVER
1470da0e8fb0SValentine Barshak 	ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1471da0e8fb0SValentine Barshak clean2:
1472da0e8fb0SValentine Barshak #endif
1473da0e8fb0SValentine Barshak #ifdef PCI_DRIVER
1474da0e8fb0SValentine Barshak 	pci_unregister_driver(&PCI_DRIVER);
1475da0e8fb0SValentine Barshak clean1:
1476da0e8fb0SValentine Barshak #endif
1477da0e8fb0SValentine Barshak #ifdef PLATFORM_DRIVER
1478da0e8fb0SValentine Barshak 	platform_driver_unregister(&PLATFORM_DRIVER);
1479da0e8fb0SValentine Barshak clean0:
1480da0e8fb0SValentine Barshak #endif
1481694cc208STony Jones #ifdef DEBUG
1482694cc208STony Jones 	debugfs_remove(ehci_debug_root);
1483694cc208STony Jones 	ehci_debug_root = NULL;
14849beeee65SAlan Stern err_debug:
1485a9b6148dSLinus Torvalds #endif
14869beeee65SAlan Stern 	clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
148701cced25SKumar Gala 	return retval;
148801cced25SKumar Gala }
148901cced25SKumar Gala module_init(ehci_hcd_init);
149001cced25SKumar Gala 
149101cced25SKumar Gala static void __exit ehci_hcd_cleanup(void)
149201cced25SKumar Gala {
14931f23b2d9SGrant Likely #ifdef XILINX_OF_PLATFORM_DRIVER
1494d35fb641SGrant Likely 	platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
14951f23b2d9SGrant Likely #endif
1496da0e8fb0SValentine Barshak #ifdef OF_PLATFORM_DRIVER
1497d35fb641SGrant Likely 	platform_driver_unregister(&OF_PLATFORM_DRIVER);
1498da0e8fb0SValentine Barshak #endif
149901cced25SKumar Gala #ifdef PLATFORM_DRIVER
150001cced25SKumar Gala 	platform_driver_unregister(&PLATFORM_DRIVER);
150101cced25SKumar Gala #endif
150201cced25SKumar Gala #ifdef PCI_DRIVER
150301cced25SKumar Gala 	pci_unregister_driver(&PCI_DRIVER);
150401cced25SKumar Gala #endif
1505ad75a410SGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
15067a4eb7fdSGeoff Levand 	ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1507ad75a410SGeoff Levand #endif
1508694cc208STony Jones #ifdef DEBUG
1509694cc208STony Jones 	debugfs_remove(ehci_debug_root);
1510694cc208STony Jones #endif
15119beeee65SAlan Stern 	clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
151201cced25SKumar Gala }
151301cced25SKumar Gala module_exit(ehci_hcd_cleanup);
151401cced25SKumar Gala 
1515eb70e5abSAlexander Shishkin #endif /* CHIPIDEA_EHCI */
1516