blob: c7458f7e56cc51013895b0f53c1ada648cd6b27f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000-2004 by David Brownell
David Brownell53bd6a62006-08-30 14:50:06 -07003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/module.h>
20#include <linux/pci.h>
21#include <linux/dmapool.h>
22#include <linux/kernel.h>
23#include <linux/delay.h>
24#include <linux/ioport.h>
25#include <linux/sched.h>
26#include <linux/slab.h>
27#include <linux/smp_lock.h>
28#include <linux/errno.h>
29#include <linux/init.h>
30#include <linux/timer.h>
31#include <linux/list.h>
32#include <linux/interrupt.h>
33#include <linux/reboot.h>
34#include <linux/usb.h>
35#include <linux/moduleparam.h>
36#include <linux/dma-mapping.h>
37
38#include "../core/hcd.h"
39
40#include <asm/byteorder.h>
41#include <asm/io.h>
42#include <asm/irq.h>
43#include <asm/system.h>
44#include <asm/unaligned.h>
Ishizaki Kou48fda452007-02-14 16:04:17 +090045#ifdef CONFIG_PPC_PS3
46#include <asm/firmware.h>
47#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49
50/*-------------------------------------------------------------------------*/
51
52/*
53 * EHCI hc_driver implementation ... experimental, incomplete.
54 * Based on the final 1.0 register interface specification.
55 *
56 * USB 2.0 shows up in upcoming www.pcmcia.org technology.
57 * First was PCMCIA, like ISA; then CardBus, which is PCI.
58 * Next comes "CardBay", using USB 2.0 signals.
59 *
60 * Contains additional contributions by Brad Hards, Rory Bolt, and others.
61 * Special thanks to Intel and VIA for providing host controllers to
62 * test this driver on, and Cypress (including In-System Design) for
63 * providing early devices for those host controllers to talk to!
64 *
65 * HISTORY:
66 *
67 * 2004-05-10 Root hub and PCI suspend/resume support; remote wakeup. (db)
68 * 2004-02-24 Replace pci_* with generic dma_* API calls (dsaxena@plexity.net)
69 * 2003-12-29 Rewritten high speed iso transfer support (by Michal Sojka,
70 * <sojkam@centrum.cz>, updates by DB).
71 *
72 * 2002-11-29 Correct handling for hw async_next register.
73 * 2002-08-06 Handling for bulk and interrupt transfers is mostly shared;
74 * only scheduling is different, no arbitrary limitations.
75 * 2002-07-25 Sanity check PCI reads, mostly for better cardbus support,
David Brownell53bd6a62006-08-30 14:50:06 -070076 * clean up HC run state handshaking.
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 * 2002-05-24 Preliminary FS/LS interrupts, using scheduling shortcuts
78 * 2002-05-11 Clear TT errors for FS/LS ctrl/bulk. Fill in some other
79 * missing pieces: enabling 64bit dma, handoff from BIOS/SMM.
80 * 2002-05-07 Some error path cleanups to report better errors; wmb();
81 * use non-CVS version id; better iso bandwidth claim.
82 * 2002-04-19 Control/bulk/interrupt submit no longer uses giveback() on
83 * errors in submit path. Bugfixes to interrupt scheduling/processing.
84 * 2002-03-05 Initial high-speed ISO support; reduce ITD memory; shift
85 * more checking to generic hcd framework (db). Make it work with
86 * Philips EHCI; reduce PCI traffic; shorten IRQ path (Rory Bolt).
87 * 2002-01-14 Minor cleanup; version synch.
88 * 2002-01-08 Fix roothub handoff of FS/LS to companion controllers.
89 * 2002-01-04 Control/Bulk queuing behaves.
90 *
91 * 2001-12-12 Initial patch version for Linux 2.5.1 kernel.
92 * 2001-June Works with usb-storage and NEC EHCI on 2.4
93 */
94
95#define DRIVER_VERSION "10 Dec 2004"
96#define DRIVER_AUTHOR "David Brownell"
97#define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
98
99static const char hcd_name [] = "ehci_hcd";
100
101
102#undef EHCI_VERBOSE_DEBUG
103#undef EHCI_URB_TRACE
104
105#ifdef DEBUG
106#define EHCI_STATS
107#endif
108
109/* magic numbers that can affect system performance */
110#define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
111#define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
112#define EHCI_TUNE_RL_TT 0
113#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
114#define EHCI_TUNE_MULT_TT 1
115#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
116
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700117#define EHCI_IAA_JIFFIES (HZ/100) /* arbitrary; ~10 msec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
119#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
120#define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */
121
122/* Initial IRQ latency: faster than hw default */
123static int log2_irq_thresh = 0; // 0 to 6
124module_param (log2_irq_thresh, int, S_IRUGO);
125MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
126
127/* initial park setting: slower than hw default */
128static unsigned park = 0;
129module_param (park, uint, S_IRUGO);
130MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
131
David Brownell93f1a472006-11-16 23:34:58 -0800132/* for flakey hardware, ignore overcurrent indicators */
133static int ignore_oc = 0;
134module_param (ignore_oc, bool, S_IRUGO);
135MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
138
139/*-------------------------------------------------------------------------*/
140
141#include "ehci.h"
142#include "ehci-dbg.c"
143
144/*-------------------------------------------------------------------------*/
145
146/*
147 * handshake - spin reading hc until handshake completes or fails
148 * @ptr: address of hc register to be read
149 * @mask: bits to look at in result of read
150 * @done: value of those bits when handshake succeeds
151 * @usec: timeout in microseconds
152 *
153 * Returns negative errno, or zero on success
154 *
155 * Success happens when the "mask" bits have the specified value (hardware
156 * handshake done). There are two failure modes: "usec" have passed (major
157 * hardware flakeout), or the register reads as all-ones (hardware removed).
158 *
159 * That last failure should_only happen in cases like physical cardbus eject
160 * before driver shutdown. But it also seems to be caused by bugs in cardbus
161 * bridge shutdown: shutting down the bridge before the devices using it.
162 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100163static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
164 u32 mask, u32 done, int usec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
166 u32 result;
167
168 do {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100169 result = ehci_readl(ehci, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 if (result == ~(u32)0) /* card removed */
171 return -ENODEV;
172 result &= mask;
173 if (result == done)
174 return 0;
175 udelay (1);
176 usec--;
177 } while (usec > 0);
178 return -ETIMEDOUT;
179}
180
181/* force HC to halt state from unknown (EHCI spec section 2.3) */
182static int ehci_halt (struct ehci_hcd *ehci)
183{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100184 u32 temp = ehci_readl(ehci, &ehci->regs->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
David Brownell72f30b62005-09-27 10:19:39 -0700186 /* disable any irqs left enabled by previous code */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100187 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
David Brownell72f30b62005-09-27 10:19:39 -0700188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 if ((temp & STS_HALT) != 0)
190 return 0;
191
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100192 temp = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 temp &= ~CMD_RUN;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100194 ehci_writel(ehci, temp, &ehci->regs->command);
195 return handshake (ehci, &ehci->regs->status,
196 STS_HALT, STS_HALT, 16 * 125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
199/* put TDI/ARC silicon into EHCI mode */
200static void tdi_reset (struct ehci_hcd *ehci)
201{
202 u32 __iomem *reg_ptr;
203 u32 tmp;
204
205 reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + 0x68);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100206 tmp = ehci_readl(ehci, reg_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 tmp |= 0x3;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100208 ehci_writel(ehci, tmp, reg_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209}
210
211/* reset a non-running (STS_HALT == 1) controller */
212static int ehci_reset (struct ehci_hcd *ehci)
213{
214 int retval;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100215 u32 command = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 command |= CMD_RESET;
218 dbg_cmd (ehci, "reset", command);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100219 ehci_writel(ehci, command, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
221 ehci->next_statechange = jiffies;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100222 retval = handshake (ehci, &ehci->regs->command,
223 CMD_RESET, 0, 250 * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 if (retval)
226 return retval;
227
228 if (ehci_is_TDI(ehci))
229 tdi_reset (ehci);
230
231 return retval;
232}
233
234/* idle the controller (from running) */
235static void ehci_quiesce (struct ehci_hcd *ehci)
236{
237 u32 temp;
238
239#ifdef DEBUG
240 if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))
241 BUG ();
242#endif
243
244 /* wait for any schedule enables/disables to take effect */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100245 temp = ehci_readl(ehci, &ehci->regs->command) << 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 temp &= STS_ASS | STS_PSS;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100247 if (handshake (ehci, &ehci->regs->status, STS_ASS | STS_PSS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 temp, 16 * 125) != 0) {
249 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
250 return;
251 }
252
253 /* then disable anything that's still active */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100254 temp = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 temp &= ~(CMD_ASE | CMD_IAAD | CMD_PSE);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100256 ehci_writel(ehci, temp, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 /* hardware can take 16 microframes to turn off ... */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100259 if (handshake (ehci, &ehci->regs->status, STS_ASS | STS_PSS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 0, 16 * 125) != 0) {
261 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
262 return;
263 }
264}
265
266/*-------------------------------------------------------------------------*/
267
David Howells7d12e782006-10-05 14:55:46 +0100268static void ehci_work(struct ehci_hcd *ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270#include "ehci-hub.c"
271#include "ehci-mem.c"
272#include "ehci-q.c"
273#include "ehci-sched.c"
274
275/*-------------------------------------------------------------------------*/
276
277static void ehci_watchdog (unsigned long param)
278{
279 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
280 unsigned long flags;
281
282 spin_lock_irqsave (&ehci->lock, flags);
283
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700284 /* lost IAA irqs wedge things badly; seen with a vt8235 */
285 if (ehci->reclaim) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100286 u32 status = ehci_readl(ehci, &ehci->regs->status);
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700287 if (status & STS_IAA) {
288 ehci_vdbg (ehci, "lost IAA\n");
289 COUNT (ehci->stats.lost_iaa);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100290 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700291 ehci->reclaim_ready = 1;
292 }
293 }
294
295 /* stop async processing after it's idled a bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
David Brownell26f953f2006-09-18 17:03:16 -0700297 start_unlink_async (ehci, ehci->async);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 /* ehci could run by timer, without IRQs ... */
David Howells7d12e782006-10-05 14:55:46 +0100300 ehci_work (ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 spin_unlock_irqrestore (&ehci->lock, flags);
303}
304
Alan Stern89037952007-02-13 14:55:27 -0500305/* On some systems, leaving remote wakeup enabled prevents system shutdown.
306 * The firmware seems to think that powering off is a wakeup event!
307 * This routine turns off remote wakeup and everything else, on all ports.
308 */
309static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
310{
311 int port = HCS_N_PORTS(ehci->hcs_params);
312
313 while (port--)
314 ehci_writel(ehci, PORT_RWC_BITS,
315 &ehci->regs->port_status[port]);
316}
317
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700318/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
David Brownell72f30b62005-09-27 10:19:39 -0700319 * This forcibly disables dma and IRQs, helping kexec and other cases
320 * where the next system software may expect clean state.
321 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700322static void
323ehci_shutdown (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700325 struct ehci_hcd *ehci;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700327 ehci = hcd_to_ehci (hcd);
David Brownell72f30b62005-09-27 10:19:39 -0700328 (void) ehci_halt (ehci);
Alan Stern89037952007-02-13 14:55:27 -0500329 ehci_turn_off_all_ports(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 /* make BIOS/etc use companion controller during reboot */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100332 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
Alan Stern89037952007-02-13 14:55:27 -0500333
334 /* unblock posted writes */
335 ehci_readl(ehci, &ehci->regs->configured_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
David Brownell56c1e262005-04-09 09:00:29 -0700338static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
339{
340 unsigned port;
341
342 if (!HCS_PPC (ehci->hcs_params))
343 return;
344
345 ehci_dbg (ehci, "...power%s ports...\n", is_on ? "up" : "down");
346 for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; )
347 (void) ehci_hub_control(ehci_to_hcd(ehci),
348 is_on ? SetPortFeature : ClearPortFeature,
349 USB_PORT_FEAT_POWER,
350 port--, NULL, 0);
351 msleep(20);
352}
353
Matt Porter7ff71d62005-09-22 22:31:15 -0700354/*-------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Matt Porter7ff71d62005-09-22 22:31:15 -0700356/*
357 * ehci_work is called from some interrupts, timers, and so on.
358 * it calls driver completion functions, after dropping ehci->lock.
359 */
David Howells7d12e782006-10-05 14:55:46 +0100360static void ehci_work (struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Matt Porter7ff71d62005-09-22 22:31:15 -0700362 timer_action_done (ehci, TIMER_IO_WATCHDOG);
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700363 if (ehci->reclaim_ready)
364 end_unlink_async (ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Matt Porter7ff71d62005-09-22 22:31:15 -0700366 /* another CPU may drop ehci->lock during a schedule scan while
367 * it reports urb completions. this flag guards against bogus
368 * attempts at re-entrant schedule scanning.
369 */
370 if (ehci->scanning)
371 return;
372 ehci->scanning = 1;
David Howells7d12e782006-10-05 14:55:46 +0100373 scan_async (ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700374 if (ehci->next_uframe != -1)
David Howells7d12e782006-10-05 14:55:46 +0100375 scan_periodic (ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700376 ehci->scanning = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Matt Porter7ff71d62005-09-22 22:31:15 -0700378 /* the IO watchdog guards against hardware or driver bugs that
379 * misplace IRQs, and should let us run completely without IRQs.
380 * such lossage has been observed on both VT6202 and VT8235.
381 */
382 if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) &&
383 (ehci->async->qh_next.ptr != NULL ||
384 ehci->periodic_sched != 0))
385 timer_action (ehci, TIMER_IO_WATCHDOG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
387
Matt Porter7ff71d62005-09-22 22:31:15 -0700388static void ehci_stop (struct usb_hcd *hcd)
389{
390 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
391
392 ehci_dbg (ehci, "stop\n");
393
394 /* Turn off port power on all root hub ports. */
395 ehci_port_power (ehci, 0);
396
397 /* no more interrupts ... */
398 del_timer_sync (&ehci->watchdog);
399
400 spin_lock_irq(&ehci->lock);
401 if (HC_IS_RUNNING (hcd->state))
402 ehci_quiesce (ehci);
403
404 ehci_reset (ehci);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100405 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
Matt Porter7ff71d62005-09-22 22:31:15 -0700406 spin_unlock_irq(&ehci->lock);
407
408 /* let companion controllers work when we aren't */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100409 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
Matt Porter7ff71d62005-09-22 22:31:15 -0700410
Alan Stern57e06c12007-01-16 11:59:45 -0500411 remove_companion_file(ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700412 remove_debug_files (ehci);
413
414 /* root hub is shut down separately (first, when possible) */
415 spin_lock_irq (&ehci->lock);
416 if (ehci->async)
David Howells7d12e782006-10-05 14:55:46 +0100417 ehci_work (ehci);
Matt Porter7ff71d62005-09-22 22:31:15 -0700418 spin_unlock_irq (&ehci->lock);
419 ehci_mem_cleanup (ehci);
420
421#ifdef EHCI_STATS
422 ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
423 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
424 ehci->stats.lost_iaa);
425 ehci_dbg (ehci, "complete %ld unlink %ld\n",
426 ehci->stats.complete, ehci->stats.unlink);
427#endif
428
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100429 dbg_status (ehci, "ehci_stop completed",
430 ehci_readl(ehci, &ehci->regs->status));
Matt Porter7ff71d62005-09-22 22:31:15 -0700431}
432
David Brownell18807522005-11-23 15:45:37 -0800433/* one-time init, only for memory state */
434static int ehci_init(struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
David Brownell18807522005-11-23 15:45:37 -0800436 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 int retval;
439 u32 hcc_params;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
David Brownell18807522005-11-23 15:45:37 -0800441 spin_lock_init(&ehci->lock);
442
443 init_timer(&ehci->watchdog);
444 ehci->watchdog.function = ehci_watchdog;
445 ehci->watchdog.data = (unsigned long) ehci;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 /*
448 * hw default: 1K periodic list heads, one per frame.
449 * periodic_size can shrink by USBCMD update if hcc_params allows.
450 */
451 ehci->periodic_size = DEFAULT_I_TDPS;
David Brownell18807522005-11-23 15:45:37 -0800452 if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 return retval;
454
455 /* controllers may cache some of the periodic schedule ... */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100456 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
David Brownell53bd6a62006-08-30 14:50:06 -0700457 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 ehci->i_thresh = 8;
459 else // N microframes cached
David Brownell18807522005-11-23 15:45:37 -0800460 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 ehci->reclaim = NULL;
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700463 ehci->reclaim_ready = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 ehci->next_uframe = -1;
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 /*
467 * dedicate a qh for the async ring head, since we couldn't unlink
468 * a 'real' qh without stopping the async schedule [4.8]. use it
469 * as the 'reclamation list head' too.
470 * its dummy is used in hw_alt_next of many tds, to prevent the qh
471 * from automatically advancing to the next td after short reads.
472 */
David Brownell18807522005-11-23 15:45:37 -0800473 ehci->async->qh_next.qh = NULL;
474 ehci->async->hw_next = QH_NEXT(ehci->async->qh_dma);
475 ehci->async->hw_info1 = cpu_to_le32(QH_HEAD);
476 ehci->async->hw_token = cpu_to_le32(QTD_STS_HALT);
477 ehci->async->hw_qtd_next = EHCI_LIST_END;
478 ehci->async->qh_state = QH_STATE_LINKED;
479 ehci->async->hw_alt_next = QTD_NEXT(ehci->async->dummy->qtd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 /* clear interrupt enables, set irq latency */
482 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
483 log2_irq_thresh = 0;
484 temp = 1 << (16 + log2_irq_thresh);
485 if (HCC_CANPARK(hcc_params)) {
486 /* HW default park == 3, on hardware that supports it (like
487 * NVidia and ALI silicon), maximizes throughput on the async
488 * schedule by avoiding QH fetches between transfers.
489 *
490 * With fast usb storage devices and NForce2, "park" seems to
491 * make problems: throughput reduction (!), data errors...
492 */
493 if (park) {
David Brownell18807522005-11-23 15:45:37 -0800494 park = min(park, (unsigned) 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 temp |= CMD_PARK;
496 temp |= park << 8;
497 }
David Brownell18807522005-11-23 15:45:37 -0800498 ehci_dbg(ehci, "park %d\n", park);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
David Brownell18807522005-11-23 15:45:37 -0800500 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 /* periodic schedule size can be smaller than default */
502 temp &= ~(3 << 2);
503 temp |= (EHCI_TUNE_FLS << 2);
504 switch (EHCI_TUNE_FLS) {
505 case 0: ehci->periodic_size = 1024; break;
506 case 1: ehci->periodic_size = 512; break;
507 case 2: ehci->periodic_size = 256; break;
David Brownell18807522005-11-23 15:45:37 -0800508 default: BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
510 }
David Brownell18807522005-11-23 15:45:37 -0800511 ehci->command = temp;
512
David Brownell18807522005-11-23 15:45:37 -0800513 return 0;
514}
515
516/* start HC running; it's halted, ehci_init() has been run (once) */
517static int ehci_run (struct usb_hcd *hcd)
518{
519 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
520 int retval;
521 u32 temp;
522 u32 hcc_params;
523
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200524 hcd->uses_new_polling = 1;
525 hcd->poll_rh = 0;
526
David Brownell18807522005-11-23 15:45:37 -0800527 /* EHCI spec section 4.1 */
528 if ((retval = ehci_reset(ehci)) != 0) {
David Brownell18807522005-11-23 15:45:37 -0800529 ehci_mem_cleanup(ehci);
530 return retval;
531 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100532 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
533 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
David Brownell18807522005-11-23 15:45:37 -0800534
535 /*
536 * hcc_params controls whether ehci->regs->segment must (!!!)
537 * be used; it constrains QH/ITD/SITD and QTD locations.
538 * pci_pool consistent memory always uses segment zero.
539 * streaming mappings for I/O buffers, like pci_map_single(),
540 * can return segments above 4GB, if the device allows.
541 *
542 * NOTE: the dma mask is visible through dma_supported(), so
543 * drivers can pass this info along ... like NETIF_F_HIGHDMA,
544 * Scsi_Host.highmem_io, and so forth. It's readonly to all
545 * host side drivers though.
546 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100547 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
David Brownell18807522005-11-23 15:45:37 -0800548 if (HCC_64BIT_ADDR(hcc_params)) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100549 ehci_writel(ehci, 0, &ehci->regs->segment);
David Brownell18807522005-11-23 15:45:37 -0800550#if 0
551// this is deeply broken on almost all architectures
552 if (!dma_set_mask(hcd->self.controller, DMA_64BIT_MASK))
553 ehci_info(ehci, "enabled 64bit DMA\n");
554#endif
555 }
556
557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 // Philips, Intel, and maybe others need CMD_RUN before the
559 // root hub will detect new devices (why?); NEC doesn't
David Brownell18807522005-11-23 15:45:37 -0800560 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
561 ehci->command |= CMD_RUN;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100562 ehci_writel(ehci, ehci->command, &ehci->regs->command);
David Brownell18807522005-11-23 15:45:37 -0800563 dbg_cmd (ehci, "init", ehci->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 /*
566 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
567 * are explicitly handed to companion controller(s), so no TT is
568 * involved with the root hub. (Except where one is integrated,
569 * and there's no companion controller unless maybe for USB OTG.)
570 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 hcd->state = HC_STATE_RUNNING;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100572 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
573 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100575 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 ehci_info (ehci,
David Brownell93f1a472006-11-16 23:34:58 -0800577 "USB %x.%x started, EHCI %x.%02x, driver %s%s\n",
Matt Porter7ff71d62005-09-22 22:31:15 -0700578 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
David Brownell93f1a472006-11-16 23:34:58 -0800579 temp >> 8, temp & 0xff, DRIVER_VERSION,
580 ignore_oc ? ", overcurrent ignored" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100582 ehci_writel(ehci, INTR_MASK,
583 &ehci->regs->intr_enable); /* Turn On Interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
David Brownell18807522005-11-23 15:45:37 -0800585 /* GRR this is run-once init(), being done every time the HC starts.
586 * So long as they're part of class devices, we can't do it init()
587 * since the class device isn't created that early.
588 */
589 create_debug_files(ehci);
Alan Stern57e06c12007-01-16 11:59:45 -0500590 create_companion_file(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 return 0;
593}
594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595/*-------------------------------------------------------------------------*/
596
David Howells7d12e782006-10-05 14:55:46 +0100597static irqreturn_t ehci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
599 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200600 u32 status, pcd_status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 int bh;
602
603 spin_lock (&ehci->lock);
604
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100605 status = ehci_readl(ehci, &ehci->regs->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 /* e.g. cardbus physical eject */
608 if (status == ~(u32) 0) {
609 ehci_dbg (ehci, "device removed\n");
610 goto dead;
611 }
612
613 status &= INTR_MASK;
614 if (!status) { /* irq sharing? */
615 spin_unlock(&ehci->lock);
616 return IRQ_NONE;
617 }
618
619 /* clear (just) interrupts */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100620 ehci_writel(ehci, status, &ehci->regs->status);
621 ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 bh = 0;
623
624#ifdef EHCI_VERBOSE_DEBUG
625 /* unrequested/ignored: Frame List Rollover */
626 dbg_status (ehci, "irq", status);
627#endif
628
629 /* INT, ERR, and IAA interrupt rates can be throttled */
630
631 /* normal [4.15.1.2] or error [4.15.1.1] completion */
632 if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
633 if (likely ((status & STS_ERR) == 0))
634 COUNT (ehci->stats.normal);
635 else
636 COUNT (ehci->stats.error);
637 bh = 1;
638 }
639
640 /* complete the unlinking of some qh [4.15.2.3] */
641 if (status & STS_IAA) {
642 COUNT (ehci->stats.reclaim);
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700643 ehci->reclaim_ready = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 bh = 1;
645 }
646
647 /* remote wakeup [4.3.1] */
David Brownelld97cc2f2005-12-22 17:05:18 -0800648 if (status & STS_PCD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 unsigned i = HCS_N_PORTS (ehci->hcs_params);
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200650 pcd_status = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652 /* resume root hub? */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100653 if (!(ehci_readl(ehci, &ehci->regs->command) & CMD_RUN))
Alan Stern8c033562006-11-09 14:42:16 -0500654 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100657 int pstatus = ehci_readl(ehci,
658 &ehci->regs->port_status [i]);
David Brownellb972b682006-06-30 02:34:42 -0700659
660 if (pstatus & PORT_OWNER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 continue;
David Brownellb972b682006-06-30 02:34:42 -0700662 if (!(pstatus & PORT_RESUME)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 || ehci->reset_done [i] != 0)
664 continue;
665
666 /* start 20 msec resume signaling from this port,
667 * and make khubd collect PORT_STAT_C_SUSPEND to
668 * stop that signaling.
669 */
670 ehci->reset_done [i] = jiffies + msecs_to_jiffies (20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
Alan Stern61e8b852007-04-09 11:52:31 -0400672 mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674 }
675
676 /* PCI errors [4.15.2.4] */
677 if (unlikely ((status & STS_FATAL) != 0)) {
678 /* bogus "fatal" IRQs appear on some chips... why? */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100679 status = ehci_readl(ehci, &ehci->regs->status);
680 dbg_cmd (ehci, "fatal", ehci_readl(ehci,
681 &ehci->regs->command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 dbg_status (ehci, "fatal", status);
683 if (status & STS_HALT) {
684 ehci_err (ehci, "fatal error\n");
685dead:
686 ehci_reset (ehci);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100687 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 /* generic layer kills/unlinks all urbs, then
689 * uses ehci_stop to clean up the rest
690 */
691 bh = 1;
692 }
693 }
694
695 if (bh)
David Howells7d12e782006-10-05 14:55:46 +0100696 ehci_work (ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 spin_unlock (&ehci->lock);
Marcelo Tosatti1d619f12007-01-21 19:45:59 -0200698 if (pcd_status & STS_PCD)
699 usb_hcd_poll_rh_status(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 return IRQ_HANDLED;
701}
702
703/*-------------------------------------------------------------------------*/
704
705/*
706 * non-error returns are a promise to giveback() the urb later
707 * we drop ownership so next owner (or urb unlink) can get it
708 *
709 * urb + dev is in hcd.self.controller.urb_list
710 * we're queueing TDs onto software and hardware lists
711 *
712 * hcd-specific init for hcpriv hasn't been done yet
713 *
714 * NOTE: control, bulk, and interrupt share the same code to append TDs
715 * to a (possibly active) QH, and the same QH scanning code.
716 */
717static int ehci_urb_enqueue (
718 struct usb_hcd *hcd,
719 struct usb_host_endpoint *ep,
720 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400721 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722) {
723 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
724 struct list_head qtd_list;
725
726 INIT_LIST_HEAD (&qtd_list);
727
728 switch (usb_pipetype (urb->pipe)) {
729 // case PIPE_CONTROL:
730 // case PIPE_BULK:
731 default:
732 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
733 return -ENOMEM;
734 return submit_async (ehci, ep, urb, &qtd_list, mem_flags);
735
736 case PIPE_INTERRUPT:
737 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
738 return -ENOMEM;
739 return intr_submit (ehci, ep, urb, &qtd_list, mem_flags);
740
741 case PIPE_ISOCHRONOUS:
742 if (urb->dev->speed == USB_SPEED_HIGH)
743 return itd_submit (ehci, urb, mem_flags);
744 else
745 return sitd_submit (ehci, urb, mem_flags);
746 }
747}
748
749static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
750{
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700751 /* if we need to use IAA and it's busy, defer */
752 if (qh->qh_state == QH_STATE_LINKED
753 && ehci->reclaim
754 && HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 struct ehci_qh *last;
756
757 for (last = ehci->reclaim;
758 last->reclaim;
759 last = last->reclaim)
760 continue;
761 qh->qh_state = QH_STATE_UNLINK_WAIT;
762 last->reclaim = qh;
763
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700764 /* bypass IAA if the hc can't care */
765 } else if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state) && ehci->reclaim)
766 end_unlink_async (ehci);
767
768 /* something else might have unlinked the qh by now */
769 if (qh->qh_state == QH_STATE_LINKED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 start_unlink_async (ehci, qh);
771}
772
773/* remove from hardware lists
774 * completions normally happen asynchronously
775 */
776
777static int ehci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
778{
779 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
780 struct ehci_qh *qh;
781 unsigned long flags;
782
783 spin_lock_irqsave (&ehci->lock, flags);
784 switch (usb_pipetype (urb->pipe)) {
785 // case PIPE_CONTROL:
786 // case PIPE_BULK:
787 default:
788 qh = (struct ehci_qh *) urb->hcpriv;
789 if (!qh)
790 break;
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -0700791 unlink_async (ehci, qh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 break;
793
794 case PIPE_INTERRUPT:
795 qh = (struct ehci_qh *) urb->hcpriv;
796 if (!qh)
797 break;
798 switch (qh->qh_state) {
799 case QH_STATE_LINKED:
800 intr_deschedule (ehci, qh);
801 /* FALL THROUGH */
802 case QH_STATE_IDLE:
David Howells7d12e782006-10-05 14:55:46 +0100803 qh_completions (ehci, qh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 break;
805 default:
806 ehci_dbg (ehci, "bogus qh %p state %d\n",
807 qh, qh->qh_state);
808 goto done;
809 }
810
811 /* reschedule QH iff another request is queued */
812 if (!list_empty (&qh->qtd_list)
813 && HC_IS_RUNNING (hcd->state)) {
814 int status;
815
816 status = qh_schedule (ehci, qh);
817 spin_unlock_irqrestore (&ehci->lock, flags);
818
819 if (status != 0) {
820 // shouldn't happen often, but ...
821 // FIXME kill those tds' urbs
822 err ("can't reschedule qh %p, err %d",
823 qh, status);
824 }
825 return status;
826 }
827 break;
828
829 case PIPE_ISOCHRONOUS:
830 // itd or sitd ...
831
832 // wait till next completion, do it then.
833 // completion irqs can wait up to 1024 msec,
834 break;
835 }
836done:
837 spin_unlock_irqrestore (&ehci->lock, flags);
838 return 0;
839}
840
841/*-------------------------------------------------------------------------*/
842
843// bulk qh holds the data toggle
844
845static void
846ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
847{
848 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
849 unsigned long flags;
850 struct ehci_qh *qh, *tmp;
851
852 /* ASSERT: any requests/urbs are being unlinked */
853 /* ASSERT: nobody can be submitting urbs for this any more */
854
855rescan:
856 spin_lock_irqsave (&ehci->lock, flags);
857 qh = ep->hcpriv;
858 if (!qh)
859 goto done;
860
861 /* endpoints can be iso streams. for now, we don't
862 * accelerate iso completions ... so spin a while.
863 */
864 if (qh->hw_info1 == 0) {
865 ehci_vdbg (ehci, "iso delay\n");
866 goto idle_timeout;
867 }
868
869 if (!HC_IS_RUNNING (hcd->state))
870 qh->qh_state = QH_STATE_IDLE;
871 switch (qh->qh_state) {
872 case QH_STATE_LINKED:
873 for (tmp = ehci->async->qh_next.qh;
874 tmp && tmp != qh;
875 tmp = tmp->qh_next.qh)
876 continue;
877 /* periodic qh self-unlinks on empty */
878 if (!tmp)
879 goto nogood;
880 unlink_async (ehci, qh);
881 /* FALL THROUGH */
882 case QH_STATE_UNLINK: /* wait for hw to finish? */
883idle_timeout:
884 spin_unlock_irqrestore (&ehci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700885 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 goto rescan;
887 case QH_STATE_IDLE: /* fully unlinked */
888 if (list_empty (&qh->qtd_list)) {
889 qh_put (qh);
890 break;
891 }
892 /* else FALL THROUGH */
893 default:
894nogood:
895 /* caller was supposed to have unlinked any requests;
896 * that's not our job. just leak this memory.
897 */
898 ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
899 qh, ep->desc.bEndpointAddress, qh->qh_state,
900 list_empty (&qh->qtd_list) ? "" : "(has tds)");
901 break;
902 }
903 ep->hcpriv = NULL;
904done:
905 spin_unlock_irqrestore (&ehci->lock, flags);
906 return;
907}
908
Matt Porter7ff71d62005-09-22 22:31:15 -0700909static int ehci_get_frame (struct usb_hcd *hcd)
910{
911 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100912 return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) %
913 ehci->periodic_size;
Matt Porter7ff71d62005-09-22 22:31:15 -0700914}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916/*-------------------------------------------------------------------------*/
917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
919
920MODULE_DESCRIPTION (DRIVER_INFO);
921MODULE_AUTHOR (DRIVER_AUTHOR);
922MODULE_LICENSE ("GPL");
923
Matt Porter7ff71d62005-09-22 22:31:15 -0700924#ifdef CONFIG_PCI
925#include "ehci-pci.c"
Kumar Gala01cced22006-04-11 10:07:16 -0500926#define PCI_DRIVER ehci_pci_driver
Matt Porter7ff71d62005-09-22 22:31:15 -0700927#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Li Yanga11570f2006-07-14 19:58:14 +0800929#ifdef CONFIG_MPC834x
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800930#include "ehci-fsl.c"
Kumar Gala01cced22006-04-11 10:07:16 -0500931#define PLATFORM_DRIVER ehci_fsl_driver
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800932#endif
933
Ralf Baechledfbaa7d2006-06-03 23:58:55 +0100934#ifdef CONFIG_SOC_AU1200
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800935#include "ehci-au1xxx.c"
Kumar Gala01cced22006-04-11 10:07:16 -0500936#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800937#endif
938
Geoff Levandad75a412007-01-15 20:11:47 -0800939#ifdef CONFIG_PPC_PS3
940#include "ehci-ps3.c"
941#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_sb_driver
942#endif
943
944#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
945 !defined(PS3_SYSTEM_BUS_DRIVER)
Matt Porter7ff71d62005-09-22 22:31:15 -0700946#error "missing bus glue for ehci-hcd"
947#endif
Kumar Gala01cced22006-04-11 10:07:16 -0500948
949static int __init ehci_hcd_init(void)
950{
951 int retval = 0;
952
953 pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
954 hcd_name,
955 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
956 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
957
958#ifdef PLATFORM_DRIVER
959 retval = platform_driver_register(&PLATFORM_DRIVER);
960 if (retval < 0)
961 return retval;
962#endif
963
964#ifdef PCI_DRIVER
965 retval = pci_register_driver(&PCI_DRIVER);
966 if (retval < 0) {
967#ifdef PLATFORM_DRIVER
968 platform_driver_unregister(&PLATFORM_DRIVER);
969#endif
Geoff Levandad75a412007-01-15 20:11:47 -0800970 return retval;
971 }
972#endif
973
974#ifdef PS3_SYSTEM_BUS_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +0900975 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
976 retval = ps3_system_bus_driver_register(
977 &PS3_SYSTEM_BUS_DRIVER);
978 if (retval < 0) {
Geoff Levandad75a412007-01-15 20:11:47 -0800979#ifdef PLATFORM_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +0900980 platform_driver_unregister(&PLATFORM_DRIVER);
Geoff Levandad75a412007-01-15 20:11:47 -0800981#endif
982#ifdef PCI_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +0900983 pci_unregister_driver(&PCI_DRIVER);
Geoff Levandad75a412007-01-15 20:11:47 -0800984#endif
Ishizaki Kou48fda452007-02-14 16:04:17 +0900985 return retval;
986 }
Kumar Gala01cced22006-04-11 10:07:16 -0500987 }
988#endif
989
990 return retval;
991}
992module_init(ehci_hcd_init);
993
994static void __exit ehci_hcd_cleanup(void)
995{
996#ifdef PLATFORM_DRIVER
997 platform_driver_unregister(&PLATFORM_DRIVER);
998#endif
999#ifdef PCI_DRIVER
1000 pci_unregister_driver(&PCI_DRIVER);
1001#endif
Geoff Levandad75a412007-01-15 20:11:47 -08001002#ifdef PS3_SYSTEM_BUS_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +09001003 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1004 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levandad75a412007-01-15 20:11:47 -08001005#endif
Kumar Gala01cced22006-04-11 10:07:16 -05001006}
1007module_exit(ehci_hcd_cleanup);
1008