blob: 340c9c4894bf59e296cf32ff24a8eec39918c5eb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Alan Stern578333a2011-06-15 16:32:46 -04002 * Enhanced Host Controller Interface (EHCI) driver for USB.
3 *
4 * Maintainer: Alan Stern <stern@rowland.harvard.edu>
5 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright (c) 2000-2004 by David Brownell
David Brownell53bd6a62006-08-30 14:50:06 -07007 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/module.h>
24#include <linux/pci.h>
25#include <linux/dmapool.h>
26#include <linux/kernel.h>
27#include <linux/delay.h>
28#include <linux/ioport.h>
29#include <linux/sched.h>
Ming Lei3c04e202008-09-18 23:06:21 +080030#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/errno.h>
32#include <linux/init.h>
Alan Sternd58b4bc2012-07-11 11:21:54 -040033#include <linux/hrtimer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/list.h>
35#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/usb.h>
Eric Lescouet27729aa2010-04-24 23:21:52 +020037#include <linux/usb/hcd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/moduleparam.h>
39#include <linux/dma-mapping.h>
Tony Jones694cc202007-09-11 14:07:31 -070040#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Alek Duaa4d8342010-06-04 15:47:54 +080042#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/byteorder.h>
45#include <asm/io.h>
46#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Geoff Levanddf7c1ca2011-11-30 16:40:57 -080049#if defined(CONFIG_PPC_PS3)
50#include <asm/firmware.h>
51#endif
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/*-------------------------------------------------------------------------*/
54
55/*
56 * EHCI hc_driver implementation ... experimental, incomplete.
57 * Based on the final 1.0 register interface specification.
58 *
59 * USB 2.0 shows up in upcoming www.pcmcia.org technology.
60 * First was PCMCIA, like ISA; then CardBus, which is PCI.
61 * Next comes "CardBay", using USB 2.0 signals.
62 *
63 * Contains additional contributions by Brad Hards, Rory Bolt, and others.
64 * Special thanks to Intel and VIA for providing host controllers to
65 * test this driver on, and Cypress (including In-System Design) for
66 * providing early devices for those host controllers to talk to!
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 */
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define DRIVER_AUTHOR "David Brownell"
70#define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
71
72static const char hcd_name [] = "ehci_hcd";
73
74
David Brownell9776afc2008-02-01 11:42:05 -080075#undef VERBOSE_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#undef EHCI_URB_TRACE
77
78#ifdef DEBUG
79#define EHCI_STATS
80#endif
81
82/* magic numbers that can affect system performance */
83#define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
84#define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
85#define EHCI_TUNE_RL_TT 0
86#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
87#define EHCI_TUNE_MULT_TT 1
Alan Sternffda0802010-07-14 11:03:46 -040088/*
89 * Some drivers think it's safe to schedule isochronous transfers more than
90 * 256 ms into the future (partly as a result of an old bug in the scheduling
91 * code). In an attempt to avoid trouble, we will use a minimum scheduling
92 * length of 512 frames instead of 256.
93 */
94#define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/* Initial IRQ latency: faster than hw default */
97static int log2_irq_thresh = 0; // 0 to 6
98module_param (log2_irq_thresh, int, S_IRUGO);
99MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
100
101/* initial park setting: slower than hw default */
102static unsigned park = 0;
103module_param (park, uint, S_IRUGO);
104MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
105
David Brownell93f1a472006-11-16 23:34:58 -0800106/* for flakey hardware, ignore overcurrent indicators */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030107static bool ignore_oc = 0;
David Brownell93f1a472006-11-16 23:34:58 -0800108module_param (ignore_oc, bool, S_IRUGO);
109MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
110
Alek Du48f24972010-06-04 15:47:55 +0800111/* for link power management(LPM) feature */
112static unsigned int hird;
113module_param(hird, int, S_IRUGO);
Niels de Voscc556872011-05-31 23:00:10 +0100114MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us");
Alek Du48f24972010-06-04 15:47:55 +0800115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
117
118/*-------------------------------------------------------------------------*/
119
120#include "ehci.h"
121#include "ehci-dbg.c"
Andiry Xuad935622011-03-01 14:57:05 +0800122#include "pci-quirks.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/*-------------------------------------------------------------------------*/
125
126/*
127 * handshake - spin reading hc until handshake completes or fails
128 * @ptr: address of hc register to be read
129 * @mask: bits to look at in result of read
130 * @done: value of those bits when handshake succeeds
131 * @usec: timeout in microseconds
132 *
133 * Returns negative errno, or zero on success
134 *
135 * Success happens when the "mask" bits have the specified value (hardware
136 * handshake done). There are two failure modes: "usec" have passed (major
137 * hardware flakeout), or the register reads as all-ones (hardware removed).
138 *
139 * That last failure should_only happen in cases like physical cardbus eject
140 * before driver shutdown. But it also seems to be caused by bugs in cardbus
141 * bridge shutdown: shutting down the bridge before the devices using it.
142 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100143static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
144 u32 mask, u32 done, int usec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 u32 result;
147
148 do {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100149 result = ehci_readl(ehci, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 if (result == ~(u32)0) /* card removed */
151 return -ENODEV;
152 result &= mask;
153 if (result == done)
154 return 0;
155 udelay (1);
156 usec--;
157 } while (usec > 0);
158 return -ETIMEDOUT;
159}
160
Matthieu CASTET65fd4272010-09-06 18:26:56 +0200161/* check TDI/ARC silicon is in host mode */
162static int tdi_in_host_mode (struct ehci_hcd *ehci)
163{
Matthieu CASTET65fd4272010-09-06 18:26:56 +0200164 u32 tmp;
165
Alan Sterna46af4e2012-06-25 12:19:03 -0400166 tmp = ehci_readl(ehci, &ehci->regs->usbmode);
Matthieu CASTET65fd4272010-09-06 18:26:56 +0200167 return (tmp & 3) == USBMODE_CM_HC;
168}
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/* force HC to halt state from unknown (EHCI spec section 2.3) */
171static int ehci_halt (struct ehci_hcd *ehci)
172{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100173 u32 temp = ehci_readl(ehci, &ehci->regs->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
David Brownell72f30b62005-09-27 10:19:39 -0700175 /* disable any irqs left enabled by previous code */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100176 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
David Brownell72f30b62005-09-27 10:19:39 -0700177
Matthieu CASTET65fd4272010-09-06 18:26:56 +0200178 if (ehci_is_TDI(ehci) && tdi_in_host_mode(ehci) == 0) {
179 return 0;
180 }
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 if ((temp & STS_HALT) != 0)
183 return 0;
184
Alan Stern3d9545c2012-04-23 13:54:36 -0400185 /*
186 * This routine gets called during probe before ehci->command
187 * has been initialized, so we can't rely on its value.
188 */
189 ehci->command &= ~CMD_RUN;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100190 temp = ehci_readl(ehci, &ehci->regs->command);
Alan Stern3d9545c2012-04-23 13:54:36 -0400191 temp &= ~(CMD_RUN | CMD_IAAD);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100192 ehci_writel(ehci, temp, &ehci->regs->command);
193 return handshake (ehci, &ehci->regs->status,
194 STS_HALT, STS_HALT, 16 * 125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
197/* put TDI/ARC silicon into EHCI mode */
198static void tdi_reset (struct ehci_hcd *ehci)
199{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 u32 tmp;
201
Alan Sterna46af4e2012-06-25 12:19:03 -0400202 tmp = ehci_readl(ehci, &ehci->regs->usbmode);
Vladimir Barinovd23a1372007-05-23 20:07:48 +0400203 tmp |= USBMODE_CM_HC;
204 /* The default byte access to MMR space is LE after
205 * controller reset. Set the required endian mode
206 * for transfer buffers to match the host microprocessor
207 */
208 if (ehci_big_endian_mmio(ehci))
209 tmp |= USBMODE_BE;
Alan Sterna46af4e2012-06-25 12:19:03 -0400210 ehci_writel(ehci, tmp, &ehci->regs->usbmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}
212
213/* reset a non-running (STS_HALT == 1) controller */
214static int ehci_reset (struct ehci_hcd *ehci)
215{
216 int retval;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100217 u32 command = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Jason Wessel8d053c72009-08-20 15:39:54 -0500219 /* If the EHCI debug controller is active, special care must be
220 * taken before and after a host controller reset */
221 if (ehci->debug && !dbgp_reset_prep())
222 ehci->debug = NULL;
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 command |= CMD_RESET;
225 dbg_cmd (ehci, "reset", command);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100226 ehci_writel(ehci, command, &ehci->regs->command);
Alan Sterne8799902011-08-18 16:31:30 -0400227 ehci->rh_state = EHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 ehci->next_statechange = jiffies;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100229 retval = handshake (ehci, &ehci->regs->command,
230 CMD_RESET, 0, 250 * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Alek Du331ac6b2009-07-13 12:41:20 +0800232 if (ehci->has_hostpc) {
233 ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
Alan Sterna46af4e2012-06-25 12:19:03 -0400234 &ehci->regs->usbmode_ex);
235 ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning);
Alek Du331ac6b2009-07-13 12:41:20 +0800236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 if (retval)
238 return retval;
239
240 if (ehci_is_TDI(ehci))
241 tdi_reset (ehci);
242
Jason Wessel8d053c72009-08-20 15:39:54 -0500243 if (ehci->debug)
244 dbgp_external_startup();
245
Alan Sterna448e4d2012-04-03 15:24:30 -0400246 ehci->port_c_suspend = ehci->suspended_ports =
247 ehci->resuming_ports = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return retval;
249}
250
251/* idle the controller (from running) */
252static void ehci_quiesce (struct ehci_hcd *ehci)
253{
254 u32 temp;
255
Alan Sterne8799902011-08-18 16:31:30 -0400256 if (ehci->rh_state != EHCI_RH_RUNNING)
Alan Sternc0c53db2012-07-11 11:21:48 -0400257 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 /* wait for any schedule enables/disables to take effect */
Alan Stern3d9545c2012-04-23 13:54:36 -0400260 temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
Alan Stern9671cd72012-07-11 11:22:16 -0400261 handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, temp, 16 * 125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 /* then disable anything that's still active */
Alan Stern3d9545c2012-04-23 13:54:36 -0400264 ehci->command &= ~(CMD_ASE | CMD_PSE);
265 ehci_writel(ehci, ehci->command, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 /* hardware can take 16 microframes to turn off ... */
Alan Stern9671cd72012-07-11 11:22:16 -0400268 handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, 0, 16 * 125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
270
271/*-------------------------------------------------------------------------*/
272
Alan Stern07d29b62007-12-11 16:05:30 -0500273static void end_unlink_async(struct ehci_hcd *ehci);
Alan Stern32830f22012-07-11 11:22:53 -0400274static void unlink_empty_async(struct ehci_hcd *ehci);
David Howells7d12e782006-10-05 14:55:46 +0100275static void ehci_work(struct ehci_hcd *ehci);
Alan Sterndf202252012-07-11 11:22:26 -0400276static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
277static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Alan Sternd58b4bc2012-07-11 11:21:54 -0400279#include "ehci-timer.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280#include "ehci-hub.c"
Alek Du48f24972010-06-04 15:47:55 +0800281#include "ehci-lpm.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#include "ehci-mem.c"
283#include "ehci-q.c"
284#include "ehci-sched.c"
Kirill Smelkov4c670452011-07-03 20:36:56 +0400285#include "ehci-sysfs.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287/*-------------------------------------------------------------------------*/
288
Alan Stern89037952007-02-13 14:55:27 -0500289/* On some systems, leaving remote wakeup enabled prevents system shutdown.
290 * The firmware seems to think that powering off is a wakeup event!
291 * This routine turns off remote wakeup and everything else, on all ports.
292 */
293static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
294{
295 int port = HCS_N_PORTS(ehci->hcs_params);
296
297 while (port--)
298 ehci_writel(ehci, PORT_RWC_BITS,
299 &ehci->regs->port_status[port]);
300}
301
Sarah Sharp21da84a2008-04-08 14:30:18 -0700302/*
303 * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
304 * Should be called with ehci->lock held.
David Brownell72f30b62005-09-27 10:19:39 -0700305 */
Sarah Sharp21da84a2008-04-08 14:30:18 -0700306static void ehci_silence_controller(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
Sarah Sharp21da84a2008-04-08 14:30:18 -0700308 ehci_halt(ehci);
Alan Stern89037952007-02-13 14:55:27 -0500309 ehci_turn_off_all_ports(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 /* make BIOS/etc use companion controller during reboot */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100312 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
Alan Stern89037952007-02-13 14:55:27 -0500313
314 /* unblock posted writes */
315 ehci_readl(ehci, &ehci->regs->configured_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Sarah Sharp21da84a2008-04-08 14:30:18 -0700318/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
319 * This forcibly disables dma and IRQs, helping kexec and other cases
320 * where the next system software may expect clean state.
321 */
322static void ehci_shutdown(struct usb_hcd *hcd)
323{
324 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
325
Sarah Sharp21da84a2008-04-08 14:30:18 -0700326 spin_lock_irq(&ehci->lock);
Alan Sternc0c53db2012-07-11 11:21:48 -0400327 ehci->rh_state = EHCI_RH_STOPPING;
Sarah Sharp21da84a2008-04-08 14:30:18 -0700328 ehci_silence_controller(ehci);
Alan Sternd58b4bc2012-07-11 11:21:54 -0400329 ehci->enabled_hrtimer_events = 0;
Sarah Sharp21da84a2008-04-08 14:30:18 -0700330 spin_unlock_irq(&ehci->lock);
Alan Sternd58b4bc2012-07-11 11:21:54 -0400331
332 hrtimer_cancel(&ehci->hrtimer);
Sarah Sharp21da84a2008-04-08 14:30:18 -0700333}
334
David Brownell56c1e262005-04-09 09:00:29 -0700335static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
336{
337 unsigned port;
338
339 if (!HCS_PPC (ehci->hcs_params))
340 return;
341
342 ehci_dbg (ehci, "...power%s ports...\n", is_on ? "up" : "down");
343 for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; )
344 (void) ehci_hub_control(ehci_to_hcd(ehci),
345 is_on ? SetPortFeature : ClearPortFeature,
346 USB_PORT_FEAT_POWER,
347 port--, NULL, 0);
Alan Stern383975d2007-05-04 11:52:40 -0400348 /* Flush those writes */
349 ehci_readl(ehci, &ehci->regs->command);
David Brownell56c1e262005-04-09 09:00:29 -0700350 msleep(20);
351}
352
Matt Porter7ff71d62005-09-22 22:31:15 -0700353/*-------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Matt Porter7ff71d62005-09-22 22:31:15 -0700355/*
356 * ehci_work is called from some interrupts, timers, and so on.
357 * it calls driver completion functions, after dropping ehci->lock.
358 */
David Howells7d12e782006-10-05 14:55:46 +0100359static void ehci_work (struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Matt Porter7ff71d62005-09-22 22:31:15 -0700361 /* another CPU may drop ehci->lock during a schedule scan while
362 * it reports urb completions. this flag guards against bogus
363 * attempts at re-entrant schedule scanning.
364 */
Alan Stern361aabf2012-07-11 11:22:57 -0400365 if (ehci->scanning) {
366 ehci->need_rescan = true;
Matt Porter7ff71d62005-09-22 22:31:15 -0700367 return;
Alan Stern361aabf2012-07-11 11:22:57 -0400368 }
369 ehci->scanning = true;
370
371 rescan:
372 ehci->need_rescan = false;
Alan Stern31446612012-07-11 11:22:21 -0400373 if (ehci->async_count)
374 scan_async(ehci);
Alan Stern569b3942012-07-11 11:23:00 -0400375 if (ehci->intr_count > 0)
376 scan_intr(ehci);
377 if (ehci->isoc_count > 0)
378 scan_isoc(ehci);
Alan Stern361aabf2012-07-11 11:22:57 -0400379 if (ehci->need_rescan)
380 goto rescan;
381 ehci->scanning = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Matt Porter7ff71d62005-09-22 22:31:15 -0700383 /* the IO watchdog guards against hardware or driver bugs that
384 * misplace IRQs, and should let us run completely without IRQs.
385 * such lossage has been observed on both VT6202 and VT8235.
386 */
Alan Stern18aafe62012-07-11 11:23:04 -0400387 turn_on_io_watchdog(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388}
389
Sarah Sharp21da84a2008-04-08 14:30:18 -0700390/*
391 * Called when the ehci_hcd module is removed.
392 */
Matt Porter7ff71d62005-09-22 22:31:15 -0700393static void ehci_stop (struct usb_hcd *hcd)
394{
395 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
396
397 ehci_dbg (ehci, "stop\n");
398
Matt Porter7ff71d62005-09-22 22:31:15 -0700399 /* no more interrupts ... */
Matt Porter7ff71d62005-09-22 22:31:15 -0700400
401 spin_lock_irq(&ehci->lock);
Alan Sternd58b4bc2012-07-11 11:21:54 -0400402 ehci->enabled_hrtimer_events = 0;
Alan Sternc0c53db2012-07-11 11:21:48 -0400403 ehci_quiesce(ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700404
Sarah Sharp21da84a2008-04-08 14:30:18 -0700405 ehci_silence_controller(ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700406 ehci_reset (ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700407 spin_unlock_irq(&ehci->lock);
408
Alan Sternd58b4bc2012-07-11 11:21:54 -0400409 hrtimer_cancel(&ehci->hrtimer);
Kirill Smelkov4c670452011-07-03 20:36:56 +0400410 remove_sysfs_files(ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700411 remove_debug_files (ehci);
412
413 /* root hub is shut down separately (first, when possible) */
414 spin_lock_irq (&ehci->lock);
415 if (ehci->async)
David Howells7d12e782006-10-05 14:55:46 +0100416 ehci_work (ehci);
Alan Stern55934eb2012-07-11 11:22:35 -0400417 end_free_itds(ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700418 spin_unlock_irq (&ehci->lock);
419 ehci_mem_cleanup (ehci);
420
Andiry Xuad935622011-03-01 14:57:05 +0800421 if (ehci->amd_pll_fix == 1)
422 usb_amd_dev_put();
Alex He05570292010-12-07 10:10:08 +0800423
Matt Porter7ff71d62005-09-22 22:31:15 -0700424#ifdef EHCI_STATS
Alan Stern99ac5b12012-07-11 11:21:38 -0400425 ehci_dbg(ehci, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
426 ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
Matt Porter7ff71d62005-09-22 22:31:15 -0700427 ehci->stats.lost_iaa);
428 ehci_dbg (ehci, "complete %ld unlink %ld\n",
429 ehci->stats.complete, ehci->stats.unlink);
430#endif
431
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100432 dbg_status (ehci, "ehci_stop completed",
433 ehci_readl(ehci, &ehci->regs->status));
Matt Porter7ff71d62005-09-22 22:31:15 -0700434}
435
David Brownell18807522005-11-23 15:45:37 -0800436/* one-time init, only for memory state */
437static int ehci_init(struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
David Brownell18807522005-11-23 15:45:37 -0800439 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 int retval;
442 u32 hcc_params;
Alek Du3807e262009-07-14 07:23:29 +0800443 struct ehci_qh_hw *hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
David Brownell18807522005-11-23 15:45:37 -0800445 spin_lock_init(&ehci->lock);
446
Alek Du403dbd32009-07-13 17:30:41 +0800447 /*
448 * keep io watchdog by default, those good HCDs could turn off it later
449 */
450 ehci->need_io_watchdog = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Alan Sternd58b4bc2012-07-11 11:21:54 -0400452 hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
453 ehci->hrtimer.function = ehci_hrtimer_func;
454 ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
455
Alan Sternf75593c2011-01-06 10:17:09 -0500456 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 /*
Kirill Smelkovcc62a7e2011-07-03 20:36:57 +0400459 * by default set standard 80% (== 100 usec/uframe) max periodic
460 * bandwidth as required by USB 2.0
461 */
462 ehci->uframe_periodic_max = 100;
463
464 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 * hw default: 1K periodic list heads, one per frame.
466 * periodic_size can shrink by USBCMD update if hcc_params allows.
467 */
468 ehci->periodic_size = DEFAULT_I_TDPS;
Alan Stern569b3942012-07-11 11:23:00 -0400469 INIT_LIST_HEAD(&ehci->intr_qh_list);
Karsten Wiese9aa09d22009-02-08 16:07:58 -0800470 INIT_LIST_HEAD(&ehci->cached_itd_list);
Alan Stern0e5f2312010-04-08 16:56:37 -0400471 INIT_LIST_HEAD(&ehci->cached_sitd_list);
Alan Sternf75593c2011-01-06 10:17:09 -0500472
Greg Kroah-Hartman8e192912012-05-21 08:54:43 -0700473 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
Alan Sternf75593c2011-01-06 10:17:09 -0500474 /* periodic schedule size can be smaller than default */
475 switch (EHCI_TUNE_FLS) {
476 case 0: ehci->periodic_size = 1024; break;
477 case 1: ehci->periodic_size = 512; break;
478 case 2: ehci->periodic_size = 256; break;
479 default: BUG();
480 }
481 }
David Brownell18807522005-11-23 15:45:37 -0800482 if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return retval;
484
485 /* controllers may cache some of the periodic schedule ... */
David Brownell53bd6a62006-08-30 14:50:06 -0700486 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
Sarah Sharpdccd5742009-10-27 10:55:05 -0700487 ehci->i_thresh = 2 + 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 else // N microframes cached
David Brownell18807522005-11-23 15:45:37 -0800489 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 /*
492 * dedicate a qh for the async ring head, since we couldn't unlink
493 * a 'real' qh without stopping the async schedule [4.8]. use it
494 * as the 'reclamation list head' too.
495 * its dummy is used in hw_alt_next of many tds, to prevent the qh
496 * from automatically advancing to the next td after short reads.
497 */
David Brownell18807522005-11-23 15:45:37 -0800498 ehci->async->qh_next.qh = NULL;
Alek Du3807e262009-07-14 07:23:29 +0800499 hw = ehci->async->hw;
500 hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
501 hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
Ricardo Martins4f7a67e2012-05-22 18:02:03 +0100502#if defined(CONFIG_PPC_PS3)
Alan Stern4c53de72012-07-11 11:21:32 -0400503 hw->hw_info1 |= cpu_to_hc32(ehci, QH_INACTIVATE);
Ricardo Martins4f7a67e2012-05-22 18:02:03 +0100504#endif
Alek Du3807e262009-07-14 07:23:29 +0800505 hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
506 hw->hw_qtd_next = EHCI_LIST_END(ehci);
David Brownell18807522005-11-23 15:45:37 -0800507 ehci->async->qh_state = QH_STATE_LINKED;
Alek Du3807e262009-07-14 07:23:29 +0800508 hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 /* clear interrupt enables, set irq latency */
511 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
512 log2_irq_thresh = 0;
513 temp = 1 << (16 + log2_irq_thresh);
Alek Du5a9cdf32010-06-04 15:47:56 +0800514 if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
515 ehci->has_ppcd = 1;
516 ehci_dbg(ehci, "enable per-port change event\n");
517 temp |= CMD_PPCEE;
518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (HCC_CANPARK(hcc_params)) {
520 /* HW default park == 3, on hardware that supports it (like
521 * NVidia and ALI silicon), maximizes throughput on the async
522 * schedule by avoiding QH fetches between transfers.
523 *
524 * With fast usb storage devices and NForce2, "park" seems to
525 * make problems: throughput reduction (!), data errors...
526 */
527 if (park) {
David Brownell18807522005-11-23 15:45:37 -0800528 park = min(park, (unsigned) 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 temp |= CMD_PARK;
530 temp |= park << 8;
531 }
David Brownell18807522005-11-23 15:45:37 -0800532 ehci_dbg(ehci, "park %d\n", park);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
David Brownell18807522005-11-23 15:45:37 -0800534 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 /* periodic schedule size can be smaller than default */
536 temp &= ~(3 << 2);
537 temp |= (EHCI_TUNE_FLS << 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
Alek Du48f24972010-06-04 15:47:55 +0800539 if (HCC_LPM(hcc_params)) {
540 /* support link power management EHCI 1.1 addendum */
541 ehci_dbg(ehci, "support lpm\n");
542 ehci->has_lpm = 1;
543 if (hird > 0xf) {
544 ehci_dbg(ehci, "hird %d invalid, use default 0",
545 hird);
546 hird = 0;
547 }
548 temp |= hird << 24;
549 }
David Brownell18807522005-11-23 15:45:37 -0800550 ehci->command = temp;
551
Alan Stern40f8db82009-11-06 12:29:40 -0500552 /* Accept arbitrarily long scatter-gather lists */
Andrea Righi4307a282010-06-28 16:56:45 +0200553 if (!(hcd->driver->flags & HCD_LOCAL_MEM))
554 hcd->self.sg_tablesize = ~0;
David Brownell18807522005-11-23 15:45:37 -0800555 return 0;
556}
557
558/* start HC running; it's halted, ehci_init() has been run (once) */
559static int ehci_run (struct usb_hcd *hcd)
560{
561 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
David Brownell18807522005-11-23 15:45:37 -0800562 u32 temp;
563 u32 hcc_params;
564
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200565 hcd->uses_new_polling = 1;
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200566
David Brownell18807522005-11-23 15:45:37 -0800567 /* EHCI spec section 4.1 */
Geoff Levand876e0df2011-11-22 18:04:45 -0800568
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100569 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
570 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
David Brownell18807522005-11-23 15:45:37 -0800571
572 /*
573 * hcc_params controls whether ehci->regs->segment must (!!!)
574 * be used; it constrains QH/ITD/SITD and QTD locations.
575 * pci_pool consistent memory always uses segment zero.
576 * streaming mappings for I/O buffers, like pci_map_single(),
577 * can return segments above 4GB, if the device allows.
578 *
579 * NOTE: the dma mask is visible through dma_supported(), so
580 * drivers can pass this info along ... like NETIF_F_HIGHDMA,
581 * Scsi_Host.highmem_io, and so forth. It's readonly to all
582 * host side drivers though.
583 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100584 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
David Brownell18807522005-11-23 15:45:37 -0800585 if (HCC_64BIT_ADDR(hcc_params)) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100586 ehci_writel(ehci, 0, &ehci->regs->segment);
David Brownell18807522005-11-23 15:45:37 -0800587#if 0
588// this is deeply broken on almost all architectures
Yang Hongyang6a355282009-04-06 19:01:13 -0700589 if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
David Brownell18807522005-11-23 15:45:37 -0800590 ehci_info(ehci, "enabled 64bit DMA\n");
591#endif
592 }
593
594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 // Philips, Intel, and maybe others need CMD_RUN before the
596 // root hub will detect new devices (why?); NEC doesn't
David Brownell18807522005-11-23 15:45:37 -0800597 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
598 ehci->command |= CMD_RUN;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100599 ehci_writel(ehci, ehci->command, &ehci->regs->command);
David Brownell18807522005-11-23 15:45:37 -0800600 dbg_cmd (ehci, "init", ehci->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /*
603 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
604 * are explicitly handed to companion controller(s), so no TT is
605 * involved with the root hub. (Except where one is integrated,
606 * and there's no companion controller unless maybe for USB OTG.)
Alan Stern32fe0192007-10-10 16:27:07 -0400607 *
608 * Turning on the CF flag will transfer ownership of all ports
609 * from the companions to the EHCI controller. If any of the
610 * companions are in the middle of a port reset at the time, it
611 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
David Brownell1cb52652007-11-13 16:22:30 -0800612 * guarantees that no resets are in progress. After we set CF,
613 * a short delay lets the hardware catch up; new resets shouldn't
614 * be started before the port switching actions could complete.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 */
Alan Stern32fe0192007-10-10 16:27:07 -0400616 down_write(&ehci_cf_port_reset_rwsem);
Alan Sterne8799902011-08-18 16:31:30 -0400617 ehci->rh_state = EHCI_RH_RUNNING;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100618 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
619 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
David Brownell1cb52652007-11-13 16:22:30 -0800620 msleep(5);
Alan Stern32fe0192007-10-10 16:27:07 -0400621 up_write(&ehci_cf_port_reset_rwsem);
Oliver Neukumee4ecb82009-11-27 15:17:59 +0100622 ehci->last_periodic_enable = ktime_get_real();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Jan Anderssonc4301312011-05-03 20:11:57 +0200624 temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 ehci_info (ehci,
Alan Stern2b70f072008-10-02 11:47:15 -0400626 "USB %x.%x started, EHCI %x.%02x%s\n",
Matt Porter7ff71d62005-09-22 22:31:15 -0700627 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
Alan Stern2b70f072008-10-02 11:47:15 -0400628 temp >> 8, temp & 0xff,
David Brownell93f1a472006-11-16 23:34:58 -0800629 ignore_oc ? ", overcurrent ignored" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100631 ehci_writel(ehci, INTR_MASK,
632 &ehci->regs->intr_enable); /* Turn On Interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
David Brownell18807522005-11-23 15:45:37 -0800634 /* GRR this is run-once init(), being done every time the HC starts.
635 * So long as they're part of class devices, we can't do it init()
636 * since the class device isn't created that early.
637 */
638 create_debug_files(ehci);
Kirill Smelkov4c670452011-07-03 20:36:56 +0400639 create_sysfs_files(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 return 0;
642}
643
Alan Stern1a49e2a2012-07-09 15:55:14 -0400644static int ehci_setup(struct usb_hcd *hcd)
Matthieu CASTET2093c6b2011-07-02 19:47:33 +0200645{
646 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
647 int retval;
648
649 ehci->regs = (void __iomem *)ehci->caps +
650 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
651 dbg_hcs_params(ehci, "reset");
652 dbg_hcc_params(ehci, "reset");
653
654 /* cache this readonly data; minimize chip reads */
655 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
656
657 ehci->sbrn = HCD_USB2;
658
Alan Stern631fe9d2012-07-11 11:21:09 -0400659 /* data structure init */
660 retval = ehci_init(hcd);
Matthieu CASTET2093c6b2011-07-02 19:47:33 +0200661 if (retval)
662 return retval;
663
Alan Stern631fe9d2012-07-11 11:21:09 -0400664 retval = ehci_halt(ehci);
Matthieu CASTET2093c6b2011-07-02 19:47:33 +0200665 if (retval)
666 return retval;
667
Alan Stern1a49e2a2012-07-09 15:55:14 -0400668 if (ehci_is_TDI(ehci))
669 tdi_reset(ehci);
670
Matthieu CASTET2093c6b2011-07-02 19:47:33 +0200671 ehci_reset(ehci);
672
673 return 0;
674}
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676/*-------------------------------------------------------------------------*/
677
David Howells7d12e782006-10-05 14:55:46 +0100678static irqreturn_t ehci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
680 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
Alan Stern67b2e022008-11-12 17:04:53 -0500681 u32 status, masked_status, pcd_status = 0, cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 int bh;
683
684 spin_lock (&ehci->lock);
685
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100686 status = ehci_readl(ehci, &ehci->regs->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688 /* e.g. cardbus physical eject */
689 if (status == ~(u32) 0) {
690 ehci_dbg (ehci, "device removed\n");
691 goto dead;
692 }
693
Alan Stern2fbe2bf2012-04-18 11:33:00 -0400694 /*
695 * We don't use STS_FLR, but some controllers don't like it to
696 * remain on, so mask it out along with the other status bits.
697 */
698 masked_status = status & (INTR_MASK | STS_FLR);
699
Alan Stern69fff592011-05-17 17:27:12 -0400700 /* Shared IRQ? */
Alan Sterne8799902011-08-18 16:31:30 -0400701 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 spin_unlock(&ehci->lock);
703 return IRQ_NONE;
704 }
705
706 /* clear (just) interrupts */
Alan Stern67b2e022008-11-12 17:04:53 -0500707 ehci_writel(ehci, masked_status, &ehci->regs->status);
David Brownelle82cc122008-03-07 13:49:42 -0800708 cmd = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 bh = 0;
710
David Brownell9776afc2008-02-01 11:42:05 -0800711#ifdef VERBOSE_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 /* unrequested/ignored: Frame List Rollover */
713 dbg_status (ehci, "irq", status);
714#endif
715
716 /* INT, ERR, and IAA interrupt rates can be throttled */
717
718 /* normal [4.15.1.2] or error [4.15.1.1] completion */
719 if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
720 if (likely ((status & STS_ERR) == 0))
721 COUNT (ehci->stats.normal);
722 else
723 COUNT (ehci->stats.error);
724 bh = 1;
725 }
726
727 /* complete the unlinking of some qh [4.15.2.3] */
728 if (status & STS_IAA) {
Alan Stern9d938742012-07-11 11:22:44 -0400729
730 /* Turn off the IAA watchdog */
731 ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG);
732
733 /*
734 * Mild optimization: Allow another IAAD to reset the
735 * hrtimer, if one occurs before the next expiration.
736 * In theory we could always cancel the hrtimer, but
737 * tests show that about half the time it will be reset
738 * for some other event anyway.
739 */
740 if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG)
741 ++ehci->next_hrtimer_event;
742
David Brownelle82cc122008-03-07 13:49:42 -0800743 /* guard against (alleged) silicon errata */
Alan Stern6feff1b2012-04-17 15:23:25 -0400744 if (cmd & CMD_IAAD)
David Brownelle82cc122008-03-07 13:49:42 -0800745 ehci_dbg(ehci, "IAA with IAAD still set?\n");
Alan Stern3c273a02012-07-11 11:22:49 -0400746 if (ehci->async_iaa) {
Alan Stern99ac5b12012-07-11 11:21:38 -0400747 COUNT(ehci->stats.iaa);
David Brownelle82cc122008-03-07 13:49:42 -0800748 end_unlink_async(ehci);
749 } else
Alan Stern99ac5b12012-07-11 11:21:38 -0400750 ehci_dbg(ehci, "IAA with nothing unlinked?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 }
752
753 /* remote wakeup [4.3.1] */
David Brownelld97cc2f2005-12-22 17:05:18 -0800754 if (status & STS_PCD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 unsigned i = HCS_N_PORTS (ehci->hcs_params);
Alek Du5a9cdf32010-06-04 15:47:56 +0800756 u32 ppcd = 0;
David Brownelld1b18422008-03-05 23:37:52 -0800757
758 /* kick root hub later */
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200759 pcd_status = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 /* resume root hub? */
Alan Sterndc75ce92012-04-17 15:24:15 -0400762 if (ehci->rh_state == EHCI_RH_SUSPENDED)
Alan Stern8c033562006-11-09 14:42:16 -0500763 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Alek Du5a9cdf32010-06-04 15:47:56 +0800765 /* get per-port change detect bits */
766 if (ehci->has_ppcd)
767 ppcd = status >> 16;
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 while (i--) {
Alek Du5a9cdf32010-06-04 15:47:56 +0800770 int pstatus;
771
772 /* leverage per-port change bits feature */
773 if (ehci->has_ppcd && !(ppcd & (1 << i)))
774 continue;
775 pstatus = ehci_readl(ehci,
776 &ehci->regs->port_status[i]);
David Brownellb972b682006-06-30 02:34:42 -0700777
778 if (pstatus & PORT_OWNER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 continue;
Alan Sterneafe5b92008-10-06 11:25:53 -0400780 if (!(test_bit(i, &ehci->suspended_ports) &&
781 ((pstatus & PORT_RESUME) ||
782 !(pstatus & PORT_SUSPEND)) &&
783 (pstatus & PORT_PE) &&
784 ehci->reset_done[i] == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 continue;
786
787 /* start 20 msec resume signaling from this port,
788 * and make khubd collect PORT_STAT_C_SUSPEND to
Alan Stern49d0f072010-01-08 11:18:38 -0500789 * stop that signaling. Use 5 ms extra for safety,
790 * like usb_port_resume() does.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 */
Alan Stern49d0f072010-01-08 11:18:38 -0500792 ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
Alan Sterna448e4d2012-04-03 15:24:30 -0400793 set_bit(i, &ehci->resuming_ports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
Alan Stern61e8b852007-04-09 11:52:31 -0400795 mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 }
797 }
798
799 /* PCI errors [4.15.2.4] */
800 if (unlikely ((status & STS_FATAL) != 0)) {
Alan Stern67b2e022008-11-12 17:04:53 -0500801 ehci_err(ehci, "fatal error\n");
Alan Sterneafe5b92008-10-06 11:25:53 -0400802 dbg_cmd(ehci, "fatal", cmd);
803 dbg_status(ehci, "fatal", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804dead:
Alan Stern69fff592011-05-17 17:27:12 -0400805 usb_hc_died(hcd);
Alan Sternbf6387b2012-07-11 11:22:31 -0400806
807 /* Don't let the controller do anything more */
808 ehci->rh_state = EHCI_RH_STOPPING;
809 ehci->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
810 ehci_writel(ehci, ehci->command, &ehci->regs->command);
811 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
812 ehci_handle_controller_death(ehci);
813
814 /* Handle completions when the controller stops */
815 bh = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
817
818 if (bh)
David Howells7d12e782006-10-05 14:55:46 +0100819 ehci_work (ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 spin_unlock (&ehci->lock);
David Brownelld1b18422008-03-05 23:37:52 -0800821 if (pcd_status)
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200822 usb_hcd_poll_rh_status(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 return IRQ_HANDLED;
824}
825
826/*-------------------------------------------------------------------------*/
827
828/*
829 * non-error returns are a promise to giveback() the urb later
830 * we drop ownership so next owner (or urb unlink) can get it
831 *
832 * urb + dev is in hcd.self.controller.urb_list
833 * we're queueing TDs onto software and hardware lists
834 *
835 * hcd-specific init for hcpriv hasn't been done yet
836 *
837 * NOTE: control, bulk, and interrupt share the same code to append TDs
838 * to a (possibly active) QH, and the same QH scanning code.
839 */
840static int ehci_urb_enqueue (
841 struct usb_hcd *hcd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400843 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844) {
845 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
846 struct list_head qtd_list;
847
848 INIT_LIST_HEAD (&qtd_list);
849
850 switch (usb_pipetype (urb->pipe)) {
David Brownell25b70a82008-03-04 15:11:07 -0800851 case PIPE_CONTROL:
852 /* qh_completions() code doesn't handle all the fault cases
853 * in multi-TD control transfers. Even 1KB is rare anyway.
854 */
855 if (urb->transfer_buffer_length > (16 * 1024))
856 return -EMSGSIZE;
857 /* FALLTHROUGH */
858 /* case PIPE_BULK: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 default:
860 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
861 return -ENOMEM;
Alan Sterne9df41c2007-08-08 11:48:02 -0400862 return submit_async(ehci, urb, &qtd_list, mem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
864 case PIPE_INTERRUPT:
865 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
866 return -ENOMEM;
Alan Sterne9df41c2007-08-08 11:48:02 -0400867 return intr_submit(ehci, urb, &qtd_list, mem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869 case PIPE_ISOCHRONOUS:
870 if (urb->dev->speed == USB_SPEED_HIGH)
871 return itd_submit (ehci, urb, mem_flags);
872 else
873 return sitd_submit (ehci, urb, mem_flags);
874 }
875}
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877/* remove from hardware lists
878 * completions normally happen asynchronously
879 */
880
Alan Sterne9df41c2007-08-08 11:48:02 -0400881static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
883 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
884 struct ehci_qh *qh;
885 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400886 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 spin_lock_irqsave (&ehci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400889 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
890 if (rc)
891 goto done;
892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 switch (usb_pipetype (urb->pipe)) {
894 // case PIPE_CONTROL:
895 // case PIPE_BULK:
896 default:
897 qh = (struct ehci_qh *) urb->hcpriv;
898 if (!qh)
899 break;
Alan Stern07d29b62007-12-11 16:05:30 -0500900 switch (qh->qh_state) {
901 case QH_STATE_LINKED:
902 case QH_STATE_COMPLETING:
Alan Stern3c273a02012-07-11 11:22:49 -0400903 start_unlink_async(ehci, qh);
Alan Stern07d29b62007-12-11 16:05:30 -0500904 break;
905 case QH_STATE_UNLINK:
906 case QH_STATE_UNLINK_WAIT:
907 /* already started */
908 break;
909 case QH_STATE_IDLE:
Alan Stern7a0f0d92009-07-31 10:40:22 -0400910 /* QH might be waiting for a Clear-TT-Buffer */
911 qh_completions(ehci, qh);
Alan Stern07d29b62007-12-11 16:05:30 -0500912 break;
913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 break;
915
916 case PIPE_INTERRUPT:
917 qh = (struct ehci_qh *) urb->hcpriv;
918 if (!qh)
919 break;
920 switch (qh->qh_state) {
921 case QH_STATE_LINKED:
Alan Sterna448c9d2009-08-19 12:22:44 -0400922 case QH_STATE_COMPLETING:
Alan Sterndf202252012-07-11 11:22:26 -0400923 start_unlink_intr(ehci, qh);
Alan Sterna448c9d2009-08-19 12:22:44 -0400924 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 case QH_STATE_IDLE:
David Howells7d12e782006-10-05 14:55:46 +0100926 qh_completions (ehci, qh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 break;
928 default:
929 ehci_dbg (ehci, "bogus qh %p state %d\n",
930 qh, qh->qh_state);
931 goto done;
932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 break;
934
935 case PIPE_ISOCHRONOUS:
936 // itd or sitd ...
937
938 // wait till next completion, do it then.
939 // completion irqs can wait up to 1024 msec,
940 break;
941 }
942done:
943 spin_unlock_irqrestore (&ehci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400944 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945}
946
947/*-------------------------------------------------------------------------*/
948
949// bulk qh holds the data toggle
950
951static void
952ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
953{
954 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
955 unsigned long flags;
956 struct ehci_qh *qh, *tmp;
957
958 /* ASSERT: any requests/urbs are being unlinked */
959 /* ASSERT: nobody can be submitting urbs for this any more */
960
961rescan:
962 spin_lock_irqsave (&ehci->lock, flags);
963 qh = ep->hcpriv;
964 if (!qh)
965 goto done;
966
967 /* endpoints can be iso streams. for now, we don't
968 * accelerate iso completions ... so spin a while.
969 */
Clemens Ladisch1082f572010-03-01 17:18:56 +0100970 if (qh->hw == NULL) {
Alan Stern8c5bf7b2012-07-11 11:22:39 -0400971 struct ehci_iso_stream *stream = ep->hcpriv;
972
973 if (!list_empty(&stream->td_list))
974 goto idle_timeout;
975
976 /* BUG_ON(!list_empty(&stream->free_list)); */
977 kfree(stream);
978 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 }
980
Alan Sternc0c53db2012-07-11 11:21:48 -0400981 if (ehci->rh_state < EHCI_RH_RUNNING)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 qh->qh_state = QH_STATE_IDLE;
983 switch (qh->qh_state) {
984 case QH_STATE_LINKED:
Alan Stern3a444942009-08-19 12:22:06 -0400985 case QH_STATE_COMPLETING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 for (tmp = ehci->async->qh_next.qh;
987 tmp && tmp != qh;
988 tmp = tmp->qh_next.qh)
989 continue;
Alan Stern02e2c512010-11-16 10:57:37 -0500990 /* periodic qh self-unlinks on empty, and a COMPLETING qh
991 * may already be unlinked.
992 */
993 if (tmp)
Alan Stern3c273a02012-07-11 11:22:49 -0400994 start_unlink_async(ehci, qh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 /* FALL THROUGH */
996 case QH_STATE_UNLINK: /* wait for hw to finish? */
Alan Stern07d29b62007-12-11 16:05:30 -0500997 case QH_STATE_UNLINK_WAIT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998idle_timeout:
999 spin_unlock_irqrestore (&ehci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -07001000 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 goto rescan;
1002 case QH_STATE_IDLE: /* fully unlinked */
Alan Stern914b7012009-06-29 10:47:30 -04001003 if (qh->clearing_tt)
1004 goto idle_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (list_empty (&qh->qtd_list)) {
Alan Sternc83e1a92012-07-11 11:21:25 -04001006 qh_destroy(ehci, qh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 break;
1008 }
1009 /* else FALL THROUGH */
1010 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 /* caller was supposed to have unlinked any requests;
1012 * that's not our job. just leak this memory.
1013 */
1014 ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
1015 qh, ep->desc.bEndpointAddress, qh->qh_state,
1016 list_empty (&qh->qtd_list) ? "" : "(has tds)");
1017 break;
1018 }
Alan Stern8c5bf7b2012-07-11 11:22:39 -04001019 done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 ep->hcpriv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 spin_unlock_irqrestore (&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022}
1023
Alan Sternb18ffd42009-05-27 18:21:56 -04001024static void
1025ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1026{
1027 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1028 struct ehci_qh *qh;
1029 int eptype = usb_endpoint_type(&ep->desc);
Alan Sterna455212d2009-06-11 14:56:22 -04001030 int epnum = usb_endpoint_num(&ep->desc);
1031 int is_out = usb_endpoint_dir_out(&ep->desc);
1032 unsigned long flags;
Alan Sternb18ffd42009-05-27 18:21:56 -04001033
1034 if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
1035 return;
1036
Alan Sterna455212d2009-06-11 14:56:22 -04001037 spin_lock_irqsave(&ehci->lock, flags);
Alan Sternb18ffd42009-05-27 18:21:56 -04001038 qh = ep->hcpriv;
1039
1040 /* For Bulk and Interrupt endpoints we maintain the toggle state
1041 * in the hardware; the toggle bits in udev aren't used at all.
1042 * When an endpoint is reset by usb_clear_halt() we must reset
1043 * the toggle bit in the QH.
1044 */
1045 if (qh) {
Alan Sterna455212d2009-06-11 14:56:22 -04001046 usb_settoggle(qh->dev, epnum, is_out, 0);
Alan Sternb18ffd42009-05-27 18:21:56 -04001047 if (!list_empty(&qh->qtd_list)) {
1048 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
Alan Stern3a444942009-08-19 12:22:06 -04001049 } else if (qh->qh_state == QH_STATE_LINKED ||
1050 qh->qh_state == QH_STATE_COMPLETING) {
Alan Sterna455212d2009-06-11 14:56:22 -04001051
1052 /* The toggle value in the QH can't be updated
1053 * while the QH is active. Unlink it now;
1054 * re-linking will call qh_refresh().
Alan Sternb18ffd42009-05-27 18:21:56 -04001055 */
Alan Sterna448c9d2009-08-19 12:22:44 -04001056 if (eptype == USB_ENDPOINT_XFER_BULK)
Alan Stern3c273a02012-07-11 11:22:49 -04001057 start_unlink_async(ehci, qh);
Alan Sterna448c9d2009-08-19 12:22:44 -04001058 else
Alan Sterndf202252012-07-11 11:22:26 -04001059 start_unlink_intr(ehci, qh);
Alan Sternb18ffd42009-05-27 18:21:56 -04001060 }
1061 }
Alan Sterna455212d2009-06-11 14:56:22 -04001062 spin_unlock_irqrestore(&ehci->lock, flags);
Alan Sternb18ffd42009-05-27 18:21:56 -04001063}
1064
Matt Porter7ff71d62005-09-22 22:31:15 -07001065static int ehci_get_frame (struct usb_hcd *hcd)
1066{
1067 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
Alan Stern68aa95d2011-10-12 10:39:14 -04001068 return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size;
Matt Porter7ff71d62005-09-22 22:31:15 -07001069}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071/*-------------------------------------------------------------------------*/
Alan Sternc5cf9212012-06-28 11:19:02 -04001072
1073#ifdef CONFIG_PM
1074
1075/* suspend/resume, section 4.3 */
1076
1077/* These routines handle the generic parts of controller suspend/resume */
1078
1079static int __maybe_unused ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
1080{
1081 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1082
1083 if (time_before(jiffies, ehci->next_statechange))
1084 msleep(10);
1085
1086 /*
1087 * Root hub was already suspended. Disable IRQ emission and
1088 * mark HW unaccessible. The PM and USB cores make sure that
1089 * the root hub is either suspended or stopped.
1090 */
1091 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
1092
1093 spin_lock_irq(&ehci->lock);
1094 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
1095 (void) ehci_readl(ehci, &ehci->regs->intr_enable);
1096
1097 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1098 spin_unlock_irq(&ehci->lock);
1099
1100 return 0;
1101}
1102
1103/* Returns 0 if power was preserved, 1 if power was lost */
1104static int __maybe_unused ehci_resume(struct usb_hcd *hcd, bool hibernated)
1105{
1106 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1107
1108 if (time_before(jiffies, ehci->next_statechange))
1109 msleep(100);
1110
1111 /* Mark hardware accessible again as we are back to full power by now */
1112 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1113
1114 /*
1115 * If CF is still set and we aren't resuming from hibernation
1116 * then we maintained suspend power.
1117 * Just undo the effect of ehci_suspend().
1118 */
1119 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
1120 !hibernated) {
1121 int mask = INTR_MASK;
1122
1123 ehci_prepare_ports_for_controller_resume(ehci);
1124 if (!hcd->self.root_hub->do_remote_wakeup)
1125 mask &= ~STS_PCD;
1126 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
1127 ehci_readl(ehci, &ehci->regs->intr_enable);
1128 return 0;
1129 }
1130
1131 /*
1132 * Else reset, to cope with power loss or resume from hibernation
1133 * having let the firmware kick in during reboot.
1134 */
1135 usb_root_hub_lost_power(hcd->self.root_hub);
1136 (void) ehci_halt(ehci);
1137 (void) ehci_reset(ehci);
1138
Alan Sternc5cf9212012-06-28 11:19:02 -04001139 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1140 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
1141 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
1142
1143 /* here we "know" root ports should always stay powered */
1144 ehci_port_power(ehci, 1);
1145
1146 ehci->rh_state = EHCI_RH_SUSPENDED;
1147 return 1;
1148}
1149
1150#endif
1151
1152/*-------------------------------------------------------------------------*/
1153
Alexander Shishkineb70e5a2012-05-11 17:25:54 +03001154/*
1155 * The EHCI in ChipIdea HDRC cannot be a separate module or device,
1156 * because its registers (and irq) are shared between host/gadget/otg
1157 * functions and in order to facilitate role switching we cannot
1158 * give the ehci driver exclusive access to those.
1159 */
1160#ifndef CHIPIDEA_EHCI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Alan Stern2b70f072008-10-02 11:47:15 -04001162MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163MODULE_AUTHOR (DRIVER_AUTHOR);
1164MODULE_LICENSE ("GPL");
1165
Matt Porter7ff71d62005-09-22 22:31:15 -07001166#ifdef CONFIG_PCI
1167#include "ehci-pci.c"
Kumar Gala01cced22006-04-11 10:07:16 -05001168#define PCI_DRIVER ehci_pci_driver
Matt Porter7ff71d62005-09-22 22:31:15 -07001169#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Li Yangba029782007-05-11 17:09:55 +08001171#ifdef CONFIG_USB_EHCI_FSL
Randy Vinson80cb9ae2006-01-20 13:53:38 -08001172#include "ehci-fsl.c"
Kumar Gala01cced22006-04-11 10:07:16 -05001173#define PLATFORM_DRIVER ehci_fsl_driver
Randy Vinson80cb9ae2006-01-20 13:53:38 -08001174#endif
1175
Daniel Mack7e8d5cd2009-10-28 01:14:59 +01001176#ifdef CONFIG_USB_EHCI_MXC
1177#include "ehci-mxc.c"
1178#define PLATFORM_DRIVER ehci_mxc_driver
1179#endif
1180
Yoshihiro Shimoda60b0bf02011-03-01 16:58:37 +09001181#ifdef CONFIG_USB_EHCI_SH
Paul Mundt63c84552010-11-01 17:03:27 -04001182#include "ehci-sh.c"
1183#define PLATFORM_DRIVER ehci_hcd_sh_driver
1184#endif
1185
Manuel Lauss3766386032011-08-12 11:39:45 +02001186#ifdef CONFIG_MIPS_ALCHEMY
Jordan Crouse76fa9a22006-01-20 14:06:09 -08001187#include "ehci-au1xxx.c"
Kumar Gala01cced22006-04-11 10:07:16 -05001188#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
Jordan Crouse76fa9a22006-01-20 14:06:09 -08001189#endif
1190
Keshava Munegowda7f124f42010-11-21 23:23:41 +05301191#ifdef CONFIG_USB_EHCI_HCD_OMAP
Felipe Balbi54ab2b02009-10-14 11:44:14 +03001192#include "ehci-omap.c"
1193#define PLATFORM_DRIVER ehci_hcd_omap_driver
1194#endif
1195
Geoff Levandad75a412007-01-15 20:11:47 -08001196#ifdef CONFIG_PPC_PS3
1197#include "ehci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001198#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
Geoff Levandad75a412007-01-15 20:11:47 -08001199#endif
1200
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001201#ifdef CONFIG_USB_EHCI_HCD_PPC_OF
1202#include "ehci-ppc-of.c"
1203#define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
1204#endif
1205
Julie Zhu08d3c182009-09-21 16:08:19 -06001206#ifdef CONFIG_XPS_USB_HCD_XILINX
1207#include "ehci-xilinx-of.c"
Grant Likely1f23b2d2010-06-02 13:53:17 -06001208#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
Julie Zhu08d3c182009-09-21 16:08:19 -06001209#endif
1210
Lennert Buytenhek705a7522008-03-27 14:51:40 -04001211#ifdef CONFIG_PLAT_ORION
Tzachi Perelsteine96ffe22007-12-01 11:07:04 -05001212#include "ehci-orion.c"
1213#define PLATFORM_DRIVER ehci_orion_driver
1214#endif
1215
Vladimir Barinov91bc4d32007-12-30 15:21:11 -08001216#ifdef CONFIG_ARCH_IXP4XX
1217#include "ehci-ixp4xx.c"
1218#define PLATFORM_DRIVER ixp4xx_ehci_driver
1219#endif
1220
Wan ZongShun586dfc82009-06-13 09:14:28 +08001221#ifdef CONFIG_USB_W90X900_EHCI
1222#include "ehci-w90x900.c"
1223#define PLATFORM_DRIVER ehci_hcd_w90x900_driver
1224#endif
1225
Nicolas Ferre501c9c02009-07-27 14:47:40 -07001226#ifdef CONFIG_ARCH_AT91
1227#include "ehci-atmel.c"
1228#define PLATFORM_DRIVER ehci_atmel_driver
1229#endif
1230
David Daney1643acc2010-10-08 14:47:52 -07001231#ifdef CONFIG_USB_OCTEON_EHCI
1232#include "ehci-octeon.c"
1233#define PLATFORM_DRIVER ehci_octeon_driver
1234#endif
1235
Mac Lin760efe62010-11-25 23:58:00 +08001236#ifdef CONFIG_USB_CNS3XXX_EHCI
1237#include "ehci-cns3xxx.c"
1238#define PLATFORM_DRIVER cns3xxx_ehci_driver
1239#endif
1240
Alexey Charkovad78aca2010-11-07 19:28:55 +03001241#ifdef CONFIG_ARCH_VT8500
1242#include "ehci-vt8500.c"
1243#define PLATFORM_DRIVER vt8500_ehci_driver
1244#endif
1245
Deepak Sikric8c38de2010-11-10 14:33:18 +05301246#ifdef CONFIG_PLAT_SPEAR
1247#include "ehci-spear.c"
1248#define PLATFORM_DRIVER spear_ehci_hcd_driver
1249#endif
1250
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +05301251#ifdef CONFIG_USB_EHCI_MSM
1252#include "ehci-msm.c"
1253#define PLATFORM_DRIVER ehci_msm_driver
1254#endif
1255
Anoop22ced6872011-02-24 19:26:28 +05301256#ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
1257#include "ehci-pmcmsp.c"
1258#define PLATFORM_DRIVER ehci_hcd_msp_driver
1259#endif
1260
Benoit Goby79ad3b52011-03-09 16:28:56 -08001261#ifdef CONFIG_USB_EHCI_TEGRA
1262#include "ehci-tegra.c"
1263#define PLATFORM_DRIVER tegra_ehci_driver
1264#endif
1265
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +09001266#ifdef CONFIG_USB_EHCI_S5P
1267#include "ehci-s5p.c"
1268#define PLATFORM_DRIVER s5p_ehci_driver
1269#endif
1270
Jan Andersson9be03922011-05-03 20:11:58 +02001271#ifdef CONFIG_SPARC_LEON
1272#include "ehci-grlib.c"
1273#define PLATFORM_DRIVER ehci_grlib_driver
1274#endif
1275
Jayachandran C3af51542011-11-18 12:12:42 +05301276#ifdef CONFIG_CPU_XLR
Jayachandran C23106342011-08-05 01:28:22 +05301277#include "ehci-xls.c"
1278#define PLATFORM_DRIVER ehci_xls_driver
1279#endif
1280
Neil Zhang3a082ec2011-12-20 13:20:23 +08001281#ifdef CONFIG_USB_EHCI_MV
1282#include "ehci-mv.c"
1283#define PLATFORM_DRIVER ehci_mv_driver
1284#endif
1285
Kelvin Cheungf30cdbc2012-01-18 14:41:16 +08001286#ifdef CONFIG_MACH_LOONGSON1
1287#include "ehci-ls1x.c"
1288#define PLATFORM_DRIVER ehci_ls1x_driver
1289#endif
1290
Steven J. Hillc2566672012-04-19 12:57:31 -05001291#ifdef CONFIG_MIPS_SEAD3
1292#include "ehci-sead3.c"
1293#define PLATFORM_DRIVER ehci_hcd_sead3_driver
1294#endif
1295
Hauke Mehrtens7a7a4a592012-03-13 01:04:48 +01001296#ifdef CONFIG_USB_EHCI_HCD_PLATFORM
1297#include "ehci-platform.c"
1298#define PLATFORM_DRIVER ehci_platform_driver
1299#endif
1300
Geoff Levandad75a412007-01-15 20:11:47 -08001301#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
Grant Likely1f23b2d2010-06-02 13:53:17 -06001302 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
1303 !defined(XILINX_OF_PLATFORM_DRIVER)
Matt Porter7ff71d62005-09-22 22:31:15 -07001304#error "missing bus glue for ehci-hcd"
1305#endif
Kumar Gala01cced22006-04-11 10:07:16 -05001306
1307static int __init ehci_hcd_init(void)
1308{
1309 int retval = 0;
1310
Alan Stern2b70f072008-10-02 11:47:15 -04001311 if (usb_disabled())
1312 return -ENODEV;
1313
1314 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
Alan Stern9beeee62008-10-02 11:48:13 -04001315 set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
1316 if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
1317 test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
1318 printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
1319 " before uhci_hcd and ohci_hcd, not after\n");
1320
Kumar Gala01cced22006-04-11 10:07:16 -05001321 pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
1322 hcd_name,
1323 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
1324 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
1325
Tony Jones694cc202007-09-11 14:07:31 -07001326#ifdef DEBUG
Greg Kroah-Hartman08f4e582009-04-24 15:13:18 -07001327 ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
Alan Stern9beeee62008-10-02 11:48:13 -04001328 if (!ehci_debug_root) {
1329 retval = -ENOENT;
1330 goto err_debug;
1331 }
Tony Jones694cc202007-09-11 14:07:31 -07001332#endif
1333
Kumar Gala01cced22006-04-11 10:07:16 -05001334#ifdef PLATFORM_DRIVER
1335 retval = platform_driver_register(&PLATFORM_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001336 if (retval < 0)
1337 goto clean0;
Kumar Gala01cced22006-04-11 10:07:16 -05001338#endif
1339
1340#ifdef PCI_DRIVER
1341 retval = pci_register_driver(&PCI_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001342 if (retval < 0)
1343 goto clean1;
Geoff Levandad75a412007-01-15 20:11:47 -08001344#endif
1345
1346#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001347 retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001348 if (retval < 0)
1349 goto clean2;
Kumar Gala01cced22006-04-11 10:07:16 -05001350#endif
1351
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001352#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001353 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001354 if (retval < 0)
1355 goto clean3;
1356#endif
Grant Likely1f23b2d2010-06-02 13:53:17 -06001357
1358#ifdef XILINX_OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001359 retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
Grant Likely1f23b2d2010-06-02 13:53:17 -06001360 if (retval < 0)
1361 goto clean4;
1362#endif
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001363 return retval;
1364
Grant Likely1f23b2d2010-06-02 13:53:17 -06001365#ifdef XILINX_OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001366 /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
Grant Likely1f23b2d2010-06-02 13:53:17 -06001367clean4:
1368#endif
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001369#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001370 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001371clean3:
1372#endif
1373#ifdef PS3_SYSTEM_BUS_DRIVER
1374 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1375clean2:
1376#endif
1377#ifdef PCI_DRIVER
1378 pci_unregister_driver(&PCI_DRIVER);
1379clean1:
1380#endif
1381#ifdef PLATFORM_DRIVER
1382 platform_driver_unregister(&PLATFORM_DRIVER);
1383clean0:
1384#endif
1385#ifdef DEBUG
1386 debugfs_remove(ehci_debug_root);
1387 ehci_debug_root = NULL;
Alan Stern9beeee62008-10-02 11:48:13 -04001388err_debug:
Linus Torvaldsa9b61482008-10-20 14:23:29 -07001389#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001390 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
Kumar Gala01cced22006-04-11 10:07:16 -05001391 return retval;
1392}
1393module_init(ehci_hcd_init);
1394
1395static void __exit ehci_hcd_cleanup(void)
1396{
Grant Likely1f23b2d2010-06-02 13:53:17 -06001397#ifdef XILINX_OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001398 platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
Grant Likely1f23b2d2010-06-02 13:53:17 -06001399#endif
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001400#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001401 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Valentine Barshakda0e8fb2007-12-30 15:28:50 -08001402#endif
Kumar Gala01cced22006-04-11 10:07:16 -05001403#ifdef PLATFORM_DRIVER
1404 platform_driver_unregister(&PLATFORM_DRIVER);
1405#endif
1406#ifdef PCI_DRIVER
1407 pci_unregister_driver(&PCI_DRIVER);
1408#endif
Geoff Levandad75a412007-01-15 20:11:47 -08001409#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001410 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levandad75a412007-01-15 20:11:47 -08001411#endif
Tony Jones694cc202007-09-11 14:07:31 -07001412#ifdef DEBUG
1413 debugfs_remove(ehci_debug_root);
1414#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001415 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
Kumar Gala01cced22006-04-11 10:07:16 -05001416}
1417module_exit(ehci_hcd_cleanup);
1418
Alexander Shishkineb70e5a2012-05-11 17:25:54 +03001419#endif /* CHIPIDEA_EHCI */