blob: ecfe800fd7208e6c9602e87d51affcb4d2f948be [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
David Brownelldd9048a2006-12-05 03:18:31 -08006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * [ Initialisation is based on Linus' ]
8 * [ uhci code and gregs ohci fragments ]
9 * [ (C) Copyright 1999 Linus Torvalds ]
10 * [ (C) Copyright 1999 Gregory P. Smith]
David Brownelldd9048a2006-12-05 03:18:31 -080011 *
12 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
14 * interfaces (though some non-x86 Intel chips use it). It supports
15 * smarter hardware than UHCI. A download link for the spec available
16 * through the http://www.usb.org website.
17 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * This file is licenced under the GPL.
19 */
David Brownelldd9048a2006-12-05 03:18:31 -080020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/pci.h>
24#include <linux/kernel.h>
25#include <linux/delay.h>
26#include <linux/ioport.h>
27#include <linux/sched.h>
28#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/errno.h>
30#include <linux/init.h>
31#include <linux/timer.h>
32#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/usb.h>
David Brownell3a16f7b2006-06-29 12:27:23 -070034#include <linux/usb/otg.h>
David Brownelldd9048a2006-12-05 03:18:31 -080035#include <linux/dma-mapping.h>
David Brownellf4df0e32005-04-23 12:49:16 -070036#include <linux/dmapool.h>
37#include <linux/reboot.h>
Michael Hanselmannd576bb92007-05-31 23:34:27 +020038#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#include <asm/io.h>
41#include <asm/irq.h>
42#include <asm/system.h>
43#include <asm/unaligned.h>
44#include <asm/byteorder.h>
45
David Brownellf4df0e32005-04-23 12:49:16 -070046#include "../core/hcd.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
David Brownelld4139842006-08-04 11:31:55 -070048#define DRIVER_VERSION "2006 August 04"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
50#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
51
52/*-------------------------------------------------------------------------*/
53
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +110054#undef OHCI_VERBOSE_DEBUG /* not always helpful */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/* For initializing controller (mask in an HCFS mode too) */
David Brownelld4139842006-08-04 11:31:55 -070057#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define OHCI_INTR_INIT \
David Brownelld4139842006-08-04 11:31:55 -070059 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
60 | OHCI_INTR_RD | OHCI_INTR_WDH)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#ifdef __hppa__
63/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
64#define IR_DISABLE
65#endif
66
67#ifdef CONFIG_ARCH_OMAP
68/* OMAP doesn't support IR (no SMM; not needed) */
69#define IR_DISABLE
70#endif
71
72/*-------------------------------------------------------------------------*/
73
74static const char hcd_name [] = "ohci_hcd";
75
David Brownelld4139842006-08-04 11:31:55 -070076#define STATECHANGE_DELAY msecs_to_jiffies(300)
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include "ohci.h"
79
80static void ohci_dump (struct ohci_hcd *ohci, int verbose);
81static int ohci_init (struct ohci_hcd *ohci);
82static void ohci_stop (struct usb_hcd *hcd);
David Brownellda6fb572007-10-24 17:23:42 -070083
84#if defined(CONFIG_PM) || defined(CONFIG_PCI)
Michael Hanselmannd576bb92007-05-31 23:34:27 +020085static int ohci_restart (struct ohci_hcd *ohci);
David Brownellda6fb572007-10-24 17:23:42 -070086#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88#include "ohci-hub.c"
89#include "ohci-dbg.c"
90#include "ohci-mem.c"
91#include "ohci-q.c"
92
93
94/*
95 * On architectures with edge-triggered interrupts we must never return
96 * IRQ_NONE.
97 */
98#if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
99#define IRQ_NOTMINE IRQ_HANDLED
100#else
101#define IRQ_NOTMINE IRQ_NONE
102#endif
103
104
105/* Some boards misreport power switching/overcurrent */
106static int distrust_firmware = 1;
107module_param (distrust_firmware, bool, 0);
108MODULE_PARM_DESC (distrust_firmware,
109 "true to distrust firmware power/overcurrent setup");
110
111/* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
112static int no_handshake = 0;
113module_param (no_handshake, bool, 0);
114MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
115
116/*-------------------------------------------------------------------------*/
117
118/*
119 * queue up an urb for anything except the root hub
120 */
121static int ohci_urb_enqueue (
122 struct usb_hcd *hcd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400124 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125) {
126 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
127 struct ed *ed;
128 urb_priv_t *urb_priv;
129 unsigned int pipe = urb->pipe;
130 int i, size = 0;
131 unsigned long flags;
132 int retval = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#ifdef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -0400135 urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#endif
David Brownelldd9048a2006-12-05 03:18:31 -0800137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 /* every endpoint has a ed, locate and maybe (re)initialize it */
Alan Sterne9df41c2007-08-08 11:48:02 -0400139 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return -ENOMEM;
141
142 /* for the private part of the URB we need the number of TDs (size) */
143 switch (ed->type) {
144 case PIPE_CONTROL:
145 /* td_submit_urb() doesn't yet handle these */
146 if (urb->transfer_buffer_length > 4096)
147 return -EMSGSIZE;
148
149 /* 1 TD for setup, 1 for ACK, plus ... */
150 size = 2;
151 /* FALLTHROUGH */
152 // case PIPE_INTERRUPT:
153 // case PIPE_BULK:
154 default:
155 /* one TD for every 4096 Bytes (can be upto 8K) */
156 size += urb->transfer_buffer_length / 4096;
157 /* ... and for any remaining bytes ... */
158 if ((urb->transfer_buffer_length % 4096) != 0)
159 size++;
160 /* ... and maybe a zero length packet to wrap it up */
161 if (size == 0)
162 size++;
163 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
164 && (urb->transfer_buffer_length
165 % usb_maxpacket (urb->dev, pipe,
166 usb_pipeout (pipe))) == 0)
167 size++;
168 break;
169 case PIPE_ISOCHRONOUS: /* number of packets from URB */
170 size = urb->number_of_packets;
171 break;
172 }
173
174 /* allocate the private part of the URB */
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700175 urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 mem_flags);
177 if (!urb_priv)
178 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 INIT_LIST_HEAD (&urb_priv->pending);
180 urb_priv->length = size;
David Brownelldd9048a2006-12-05 03:18:31 -0800181 urb_priv->ed = ed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 /* allocate the TDs (deferring hash chain updates) */
184 for (i = 0; i < size; i++) {
185 urb_priv->td [i] = td_alloc (ohci, mem_flags);
186 if (!urb_priv->td [i]) {
187 urb_priv->length = i;
188 urb_free_priv (ohci, urb_priv);
189 return -ENOMEM;
190 }
David Brownelldd9048a2006-12-05 03:18:31 -0800191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 spin_lock_irqsave (&ohci->lock, flags);
194
195 /* don't submit to a dead HC */
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100196 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
197 retval = -ENODEV;
198 goto fail;
199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 if (!HC_IS_RUNNING(hcd->state)) {
201 retval = -ENODEV;
202 goto fail;
203 }
Alan Sterne9df41c2007-08-08 11:48:02 -0400204 retval = usb_hcd_link_urb_to_ep(hcd, urb);
205 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 /* schedule the ed if needed */
209 if (ed->state == ED_IDLE) {
210 retval = ed_schedule (ohci, ed);
Alan Sterne9df41c2007-08-08 11:48:02 -0400211 if (retval < 0) {
212 usb_hcd_unlink_urb_from_ep(hcd, urb);
213 goto fail;
214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 if (ed->type == PIPE_ISOCHRONOUS) {
216 u16 frame = ohci_frame_no(ohci);
217
218 /* delay a few frames before the first TD */
219 frame += max_t (u16, 8, ed->interval);
220 frame &= ~(ed->interval - 1);
221 frame |= ed->branch;
222 urb->start_frame = frame;
223
224 /* yes, only URB_ISO_ASAP is supported, and
225 * urb->start_frame is never used as input.
226 */
227 }
228 } else if (ed->type == PIPE_ISOCHRONOUS)
229 urb->start_frame = ed->last_iso + ed->interval;
230
231 /* fill the TDs and link them to the ed; and
232 * enable that part of the schedule, if needed
233 * and update count of queued periodic urbs
234 */
235 urb->hcpriv = urb_priv;
236 td_submit_urb (ohci, urb);
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238fail:
239 if (retval)
240 urb_free_priv (ohci, urb_priv);
241 spin_unlock_irqrestore (&ohci->lock, flags);
242 return retval;
243}
244
245/*
Alan Stern55d84962007-08-24 15:40:34 -0400246 * decouple the URB from the HC queues (TDs, urb_priv).
247 * reporting is always done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 * asynchronously, and we might be dealing with an urb that's
249 * partially transferred, or an ED with other urbs being unlinked.
250 */
Alan Sterne9df41c2007-08-08 11:48:02 -0400251static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
254 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400255 int rc;
David Brownelldd9048a2006-12-05 03:18:31 -0800256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#ifdef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -0400258 urb_print(urb, "UNLINK", 1, status);
David Brownelldd9048a2006-12-05 03:18:31 -0800259#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 spin_lock_irqsave (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400262 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
263 if (rc) {
264 ; /* Do nothing */
265 } else if (HC_IS_RUNNING(hcd->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 urb_priv_t *urb_priv;
267
268 /* Unless an IRQ completed the unlink while it was being
269 * handed to us, flag it for unlink and giveback, and force
270 * some upcoming INTR_SF to call finish_unlinks()
271 */
272 urb_priv = urb->hcpriv;
273 if (urb_priv) {
274 if (urb_priv->ed->state == ED_OPER)
275 start_ed_unlink (ohci, urb_priv->ed);
276 }
277 } else {
278 /*
279 * with HC dead, we won't respect hc queue pointers
280 * any more ... just clean up every urb's memory.
281 */
282 if (urb->hcpriv)
Alan Stern55d84962007-08-24 15:40:34 -0400283 finish_urb(ohci, urb, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285 spin_unlock_irqrestore (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400286 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
289/*-------------------------------------------------------------------------*/
290
291/* frees config/altsetting state for endpoints,
292 * including ED memory, dummy TD, and bulk/intr data toggle
293 */
294
295static void
296ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
297{
298 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
299 unsigned long flags;
300 struct ed *ed = ep->hcpriv;
301 unsigned limit = 1000;
302
303 /* ASSERT: any requests/urbs are being unlinked */
304 /* ASSERT: nobody can be submitting urbs for this any more */
305
306 if (!ed)
307 return;
308
309rescan:
310 spin_lock_irqsave (&ohci->lock, flags);
311
312 if (!HC_IS_RUNNING (hcd->state)) {
313sanitize:
314 ed->state = ED_IDLE;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700315 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
316 ohci->eds_scheduled--;
David Howells7d12e782006-10-05 14:55:46 +0100317 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 }
319
320 switch (ed->state) {
321 case ED_UNLINK: /* wait for hw to finish? */
322 /* major IRQ delivery trouble loses INTR_SF too... */
323 if (limit-- == 0) {
Mike Nuss89a0fd12007-08-01 13:24:30 -0700324 ohci_warn(ohci, "ED unlink timeout\n");
325 if (quirk_zfmicro(ohci)) {
326 ohci_warn(ohci, "Attempting ZF TD recovery\n");
327 ohci->ed_to_check = ed;
328 ohci->zf_delay = 2;
329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 goto sanitize;
331 }
332 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700333 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 goto rescan;
335 case ED_IDLE: /* fully unlinked */
336 if (list_empty (&ed->td_list)) {
337 td_free (ohci, ed->dummy);
338 ed_free (ohci, ed);
339 break;
340 }
341 /* else FALL THROUGH */
342 default:
343 /* caller was supposed to have unlinked any requests;
344 * that's not our job. can't recover; must leak ed.
345 */
346 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
347 ed, ep->desc.bEndpointAddress, ed->state,
348 list_empty (&ed->td_list) ? "" : " (has tds)");
349 td_free (ohci, ed->dummy);
350 break;
351 }
352 ep->hcpriv = NULL;
353 spin_unlock_irqrestore (&ohci->lock, flags);
354 return;
355}
356
357static int ohci_get_frame (struct usb_hcd *hcd)
358{
359 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
360
361 return ohci_frame_no(ohci);
362}
363
364static void ohci_usb_reset (struct ohci_hcd *ohci)
365{
366 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
367 ohci->hc_control &= OHCI_CTRL_RWC;
368 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
369}
370
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700371/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700372 * other cases where the next software may expect clean state from the
373 * "firmware". this is bus-neutral, unlike shutdown() methods.
374 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700375static void
376ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700377{
378 struct ohci_hcd *ohci;
379
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700380 ohci = hcd_to_ohci (hcd);
David Brownellf4df0e32005-04-23 12:49:16 -0700381 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
382 ohci_usb_reset (ohci);
383 /* flush the writes */
384 (void) ohci_readl (ohci, &ohci->regs->control);
David Brownellf4df0e32005-04-23 12:49:16 -0700385}
386
Mike Nuss89a0fd12007-08-01 13:24:30 -0700387static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
388{
389 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
390 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
391 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
392 && !list_empty(&ed->td_list);
393}
394
395/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
396 * an interrupt TD but neglects to add it to the donelist. On systems with
397 * this chipset, we need to periodically check the state of the queues to look
398 * for such "lost" TDs.
399 */
400static void unlink_watchdog_func(unsigned long _ohci)
401{
David Brownellda6fb572007-10-24 17:23:42 -0700402 unsigned long flags;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700403 unsigned max;
404 unsigned seen_count = 0;
405 unsigned i;
406 struct ed **seen = NULL;
407 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
408
409 spin_lock_irqsave(&ohci->lock, flags);
410 max = ohci->eds_scheduled;
411 if (!max)
412 goto done;
413
414 if (ohci->ed_to_check)
415 goto out;
416
417 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
418 if (!seen)
419 goto out;
420
421 for (i = 0; i < NUM_INTS; i++) {
422 struct ed *ed = ohci->periodic[i];
423
424 while (ed) {
425 unsigned temp;
426
427 /* scan this branch of the periodic schedule tree */
428 for (temp = 0; temp < seen_count; temp++) {
429 if (seen[temp] == ed) {
430 /* we've checked it and what's after */
431 ed = NULL;
432 break;
433 }
434 }
435 if (!ed)
436 break;
437 seen[seen_count++] = ed;
438 if (!check_ed(ohci, ed)) {
439 ed = ed->ed_next;
440 continue;
441 }
442
443 /* HC's TD list is empty, but HCD sees at least one
444 * TD that's not been sent through the donelist.
445 */
446 ohci->ed_to_check = ed;
447 ohci->zf_delay = 2;
448
449 /* The HC may wait until the next frame to report the
450 * TD as done through the donelist and INTR_WDH. (We
451 * just *assume* it's not a multi-TD interrupt URB;
452 * those could defer the IRQ more than one frame, using
453 * DI...) Check again after the next INTR_SF.
454 */
455 ohci_writel(ohci, OHCI_INTR_SF,
456 &ohci->regs->intrstatus);
457 ohci_writel(ohci, OHCI_INTR_SF,
458 &ohci->regs->intrenable);
459
460 /* flush those writes */
461 (void) ohci_readl(ohci, &ohci->regs->control);
462
463 goto out;
464 }
465 }
466out:
467 kfree(seen);
468 if (ohci->eds_scheduled)
469 mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
470done:
471 spin_unlock_irqrestore(&ohci->lock, flags);
472}
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474/*-------------------------------------------------------------------------*
475 * HC functions
476 *-------------------------------------------------------------------------*/
477
478/* init memory, and kick BIOS/SMM off */
479
480static int ohci_init (struct ohci_hcd *ohci)
481{
482 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800483 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 disable (ohci);
David Brownell6a9062f2006-01-23 15:28:07 -0800486 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
David Brownell6a9062f2006-01-23 15:28:07 -0800488 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
489 * was never needed for most non-PCI systems ... remove the code?
490 */
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#ifndef IR_DISABLE
493 /* SMM owns the HC? not for long! */
494 if (!no_handshake && ohci_readl (ohci,
495 &ohci->regs->control) & OHCI_CTRL_IR) {
496 u32 temp;
497
498 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
499
500 /* this timeout is arbitrary. we make it long, so systems
501 * depending on usb keyboards may be usable even if the
502 * BIOS/SMM code seems pretty broken.
503 */
504 temp = 500; /* arbitrary: five seconds */
505
506 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
507 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
508 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
509 msleep (10);
510 if (--temp == 0) {
511 ohci_err (ohci, "USB HC takeover failed!"
512 " (BIOS/SMM bug)\n");
513 return -EBUSY;
514 }
515 }
516 ohci_usb_reset (ohci);
517 }
518#endif
519
520 /* Disable HC interrupts */
521 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800522
523 /* flush the writes, and save key bits like RWC */
524 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
525 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
David Brownellfdd13b32005-08-31 11:52:57 -0700527 /* Read the number of ports unless overridden */
528 if (ohci->num_ports == 0)
529 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 if (ohci->hcca)
532 return 0;
533
David Brownell6a9062f2006-01-23 15:28:07 -0800534 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
536 if (!ohci->hcca)
537 return -ENOMEM;
538
539 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800540 ohci_stop (hcd);
541 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800542 create_debug_files (ohci);
543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
547
548/*-------------------------------------------------------------------------*/
549
550/* Start an OHCI controller, set the BUS operational
551 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800552 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 */
554static int ohci_run (struct ohci_hcd *ohci)
555{
David Brownelldd9048a2006-12-05 03:18:31 -0800556 u32 mask, temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800558 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 disable (ohci);
561
562 /* boot firmware should have set this up (5.1.1.3.1) */
563 if (first) {
564
565 temp = ohci_readl (ohci, &ohci->regs->fminterval);
566 ohci->fminterval = temp & 0x3fff;
567 if (ohci->fminterval != FI)
568 ohci_dbg (ohci, "fminterval delta %d\n",
569 ohci->fminterval - FI);
570 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
571 /* also: power/overcurrent flags in roothub.a */
572 }
573
David Brownelldd9048a2006-12-05 03:18:31 -0800574 /* Reset USB nearly "by the book". RemoteWakeupConnected was
David Brownell6a9062f2006-01-23 15:28:07 -0800575 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
576 * or if bus glue did the same (e.g. for PCI add-in cards with
577 * PCI PM support).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 */
David Brownell6a9062f2006-01-23 15:28:07 -0800579 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0
580 && !device_may_wakeup(hcd->self.controller))
581 device_init_wakeup(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
584 case OHCI_USB_OPER:
585 temp = 0;
586 break;
587 case OHCI_USB_SUSPEND:
588 case OHCI_USB_RESUME:
589 ohci->hc_control &= OHCI_CTRL_RWC;
590 ohci->hc_control |= OHCI_USB_RESUME;
591 temp = 10 /* msec wait */;
592 break;
593 // case OHCI_USB_RESET:
594 default:
595 ohci->hc_control &= OHCI_CTRL_RWC;
596 ohci->hc_control |= OHCI_USB_RESET;
597 temp = 50 /* msec wait */;
598 break;
599 }
600 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
601 // flush the writes
602 (void) ohci_readl (ohci, &ohci->regs->control);
603 msleep(temp);
Alan Stern383975d2007-05-04 11:52:40 -0400604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
606
607 /* 2msec timelimit here means no irqs/preempt */
608 spin_lock_irq (&ohci->lock);
609
610retry:
611 /* HC Reset requires max 10 us delay */
612 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
613 temp = 30; /* ... allow extra time */
614 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
615 if (--temp == 0) {
616 spin_unlock_irq (&ohci->lock);
617 ohci_err (ohci, "USB HC reset timed out!\n");
618 return -1;
619 }
620 udelay (1);
621 }
622
623 /* now we're in the SUSPEND state ... must go OPERATIONAL
624 * within 2msec else HC enters RESUME
625 *
626 * ... but some hardware won't init fmInterval "by the book"
627 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
628 * this if we write fmInterval after we're OPERATIONAL.
629 * Unclear about ALi, ServerWorks, and others ... this could
630 * easily be a longstanding bug in chip init on Linux.
631 */
632 if (ohci->flags & OHCI_QUIRK_INITRESET) {
633 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
634 // flush those writes
635 (void) ohci_readl (ohci, &ohci->regs->control);
636 }
637
638 /* Tell the controller where the control and bulk lists are
639 * The lists are empty now. */
640 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
641 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
642
643 /* a reset clears this */
644 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
645
646 periodic_reinit (ohci);
647
648 /* some OHCI implementations are finicky about how they init.
649 * bogus values here mean not even enumeration could work.
650 */
651 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
652 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
653 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
654 ohci->flags |= OHCI_QUIRK_INITRESET;
655 ohci_dbg (ohci, "enabling initreset quirk\n");
656 goto retry;
657 }
658 spin_unlock_irq (&ohci->lock);
659 ohci_err (ohci, "init err (%08x %04x)\n",
660 ohci_readl (ohci, &ohci->regs->fminterval),
661 ohci_readl (ohci, &ohci->regs->periodicstart));
662 return -EOVERFLOW;
663 }
664
David Brownelld4139842006-08-04 11:31:55 -0700665 /* use rhsc irqs after khubd is fully initialized */
666 hcd->poll_rh = 1;
667 hcd->uses_new_polling = 1;
668
669 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700671 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
672 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
David Brownell6a9062f2006-01-23 15:28:07 -0800673 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 /* wake on ConnectStatusChange, matching external hubs */
676 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
677
678 /* Choose the interrupts we care about now, others later on demand */
679 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700680 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 ohci_writel (ohci, mask, &ohci->regs->intrenable);
682
683 /* handle root hub init quirks ... */
684 temp = roothub_a (ohci);
685 temp &= ~(RH_A_PSM | RH_A_OCPM);
686 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
687 /* NSC 87560 and maybe others */
688 temp |= RH_A_NOCP;
689 temp &= ~(RH_A_POTPGT | RH_A_NPS);
690 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
691 } else if ((ohci->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
692 /* hub power always on; required for AMD-756 and some
693 * Mac platforms. ganged overcurrent reporting, if any.
694 */
695 temp |= RH_A_NPS;
696 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
697 }
698 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
699 ohci_writel (ohci, (temp & RH_A_NPS) ? 0 : RH_B_PPCM,
700 &ohci->regs->roothub.b);
701 // flush those writes
702 (void) ohci_readl (ohci, &ohci->regs->control);
703
David Brownelld4139842006-08-04 11:31:55 -0700704 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 spin_unlock_irq (&ohci->lock);
706
707 // POTPGT delay is bits 24-31, in 2 ms units.
708 mdelay ((temp >> 23) & 0x1fe);
David Brownell6a9062f2006-01-23 15:28:07 -0800709 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Mike Nuss89a0fd12007-08-01 13:24:30 -0700711 if (quirk_zfmicro(ohci)) {
712 /* Create timer to watch for bad queue state on ZF Micro */
713 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
714 (unsigned long) ohci);
715
716 ohci->eds_scheduled = 0;
717 ohci->ed_to_check = NULL;
718 }
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 ohci_dump (ohci, 1);
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 return 0;
723}
724
725/*-------------------------------------------------------------------------*/
726
727/* an interrupt happens */
728
David Howells7d12e782006-10-05 14:55:46 +0100729static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
731 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
732 struct ohci_regs __iomem *regs = ohci->regs;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700733 int ints;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800735 /* Read interrupt status (and flush pending writes). We ignore the
736 * optimization of checking the LSB of hcca->done_head; it doesn't
737 * work on all systems (edge triggering for OHCI can be a factor).
Mike Nuss89a0fd12007-08-01 13:24:30 -0700738 */
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800739 ints = ohci_readl(ohci, &regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800741 /* Check for an all 1's result which is a typical consequence
742 * of dead, unclocked, or unplugged (CardBus...) devices
743 */
744 if (ints == ~(u32)0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 disable (ohci);
746 ohci_dbg (ohci, "device removed!\n");
747 return IRQ_HANDLED;
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800748 }
749
750 /* We only care about interrupts that are enabled */
751 ints &= ohci_readl(ohci, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 /* interrupt for some other device? */
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800754 if (ints == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 if (ints & OHCI_INTR_UE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 // e.g. due to PCI Master/Target Abort
Mike Nuss89a0fd12007-08-01 13:24:30 -0700759 if (quirk_nec(ohci)) {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200760 /* Workaround for a silicon bug in some NEC chips used
761 * in Apple's PowerBooks. Adapted from Darwin code.
762 */
763 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
764
765 ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
766
767 schedule_work (&ohci->nec_work);
768 } else {
769 disable (ohci);
770 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 ohci_dump (ohci, 1);
774 ohci_usb_reset (ohci);
775 }
776
Alan Stern583cead2006-10-24 12:04:22 -0400777 if (ints & OHCI_INTR_RHSC) {
778 ohci_vdbg(ohci, "rhsc\n");
779 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
780 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
781 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400782
783 /* NOTE: Vendors didn't always make the same implementation
784 * choices for RHSC. Many followed the spec; RHSC triggers
785 * on an edge, like setting and maybe clearing a port status
786 * change bit. With others it's level-triggered, active
787 * until khubd clears all the port status change bits. We'll
788 * always disable it here and rely on polling until khubd
789 * re-enables it.
790 */
791 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400792 usb_hcd_poll_rh_status(hcd);
793 }
794
795 /* For connect and disconnect events, we expect the controller
796 * to turn on RHSC along with RD. But for remote wakeup events
797 * this might not happen.
798 */
799 else if (ints & OHCI_INTR_RD) {
800 ohci_vdbg(ohci, "resume detect\n");
801 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern8d1a2432006-09-26 14:46:16 -0400802 hcd->poll_rh = 1;
803 if (ohci->autostop) {
804 spin_lock (&ohci->lock);
805 ohci_rh_resume (ohci);
806 spin_unlock (&ohci->lock);
807 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700808 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 }
810
811 if (ints & OHCI_INTR_WDH) {
812 if (HC_IS_RUNNING(hcd->state))
Alan Stern8d1a2432006-09-26 14:46:16 -0400813 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100815 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 spin_unlock (&ohci->lock);
817 if (HC_IS_RUNNING(hcd->state))
David Brownelldd9048a2006-12-05 03:18:31 -0800818 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 }
David Brownelldd9048a2006-12-05 03:18:31 -0800820
Mike Nuss89a0fd12007-08-01 13:24:30 -0700821 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
822 spin_lock(&ohci->lock);
823 if (ohci->ed_to_check) {
824 struct ed *ed = ohci->ed_to_check;
825
826 if (check_ed(ohci, ed)) {
827 /* HC thinks the TD list is empty; HCD knows
828 * at least one TD is outstanding
829 */
830 if (--ohci->zf_delay == 0) {
831 struct td *td = list_entry(
832 ed->td_list.next,
833 struct td, td_list);
834 ohci_warn(ohci,
835 "Reclaiming orphan TD %p\n",
836 td);
837 takeback_td(ohci, td);
838 ohci->ed_to_check = NULL;
839 }
840 } else
841 ohci->ed_to_check = NULL;
842 }
843 spin_unlock(&ohci->lock);
844 }
845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 /* could track INTR_SO to reduce available PCI/... bandwidth */
847
848 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
849 * when there's still unlinking to be done (next frame).
850 */
851 spin_lock (&ohci->lock);
852 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100853 finish_unlinks (ohci, ohci_frame_no(ohci));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700854 if ((ints & OHCI_INTR_SF) != 0
855 && !ohci->ed_rm_list
856 && !ohci->ed_to_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 && HC_IS_RUNNING(hcd->state))
David Brownelldd9048a2006-12-05 03:18:31 -0800858 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 spin_unlock (&ohci->lock);
860
861 if (HC_IS_RUNNING(hcd->state)) {
862 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800863 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 // flush those writes
865 (void) ohci_readl (ohci, &ohci->regs->control);
866 }
867
868 return IRQ_HANDLED;
869}
870
871/*-------------------------------------------------------------------------*/
872
873static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800874{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 ohci_dump (ohci, 1);
878
879 flush_scheduled_work();
880
881 ohci_usb_reset (ohci);
882 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700883 free_irq(hcd->irq, hcd);
884 hcd->irq = -1;
885
Mike Nuss89a0fd12007-08-01 13:24:30 -0700886 if (quirk_zfmicro(ohci))
887 del_timer(&ohci->unlink_watchdog);
888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 ohci_mem_cleanup (ohci);
891 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800892 dma_free_coherent (hcd->self.controller,
893 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 ohci->hcca, ohci->hcca_dma);
895 ohci->hcca = NULL;
896 ohci->hcca_dma = 0;
897 }
898}
899
900/*-------------------------------------------------------------------------*/
901
David Brownellda6fb572007-10-24 17:23:42 -0700902#if defined(CONFIG_PM) || defined(CONFIG_PCI)
903
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904/* must not be called from interrupt context */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905static int ohci_restart (struct ohci_hcd *ohci)
906{
907 int temp;
908 int i;
909 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 spin_lock_irq(&ohci->lock);
912 disable (ohci);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200913
914 /* Recycle any "live" eds/tds (and urbs). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 if (!list_empty (&ohci->pending))
916 ohci_dbg(ohci, "abort schedule...\n");
917 list_for_each_entry (priv, &ohci->pending, pending) {
918 struct urb *urb = priv->td[0]->urb;
919 struct ed *ed = priv->ed;
920
921 switch (ed->state) {
922 case ED_OPER:
923 ed->state = ED_UNLINK;
924 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
925 ed_deschedule (ohci, ed);
926
927 ed->ed_next = ohci->ed_rm_list;
928 ed->ed_prev = NULL;
929 ohci->ed_rm_list = ed;
930 /* FALLTHROUGH */
931 case ED_UNLINK:
932 break;
933 default:
934 ohci_dbg(ohci, "bogus ed %p state %d\n",
935 ed, ed->state);
936 }
937
Alan Stern55d84962007-08-24 15:40:34 -0400938 if (!urb->unlinked)
939 urb->unlinked = -ESHUTDOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 }
David Howells7d12e782006-10-05 14:55:46 +0100941 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 spin_unlock_irq(&ohci->lock);
943
944 /* paranoia, in case that didn't work: */
945
946 /* empty the interrupt branches */
947 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
948 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 /* no EDs to remove */
951 ohci->ed_rm_list = NULL;
952
David Brownelldd9048a2006-12-05 03:18:31 -0800953 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 ohci->ed_controltail = NULL;
955 ohci->ed_bulktail = NULL;
956
957 if ((temp = ohci_run (ohci)) < 0) {
958 ohci_err (ohci, "can't restart, %d\n", temp);
959 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 }
Alan Stern383975d2007-05-04 11:52:40 -0400961 ohci_dbg(ohci, "restart complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 return 0;
963}
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200964
David Brownellda6fb572007-10-24 17:23:42 -0700965#endif
966
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200967/*-------------------------------------------------------------------------*/
968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
970
971MODULE_AUTHOR (DRIVER_AUTHOR);
972MODULE_DESCRIPTION (DRIVER_INFO);
973MODULE_LICENSE ("GPL");
974
975#ifdef CONFIG_PCI
976#include "ohci-pci.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100977#define PCI_DRIVER ohci_pci_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978#endif
979
980#ifdef CONFIG_SA1111
981#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100982#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983#endif
984
Ben Dooks3eb0c5f2005-07-29 12:18:03 -0700985#ifdef CONFIG_ARCH_S3C2410
986#include "ohci-s3c2410.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100987#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
Ben Dooks3eb0c5f2005-07-29 12:18:03 -0700988#endif
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990#ifdef CONFIG_ARCH_OMAP
991#include "ohci-omap.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100992#define PLATFORM_DRIVER ohci_hcd_omap_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993#endif
994
995#ifdef CONFIG_ARCH_LH7A404
996#include "ohci-lh7a404.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100997#define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998#endif
999
1000#ifdef CONFIG_PXA27x
1001#include "ohci-pxa27x.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001002#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003#endif
1004
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001005#ifdef CONFIG_ARCH_EP93XX
1006#include "ohci-ep93xx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001007#define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001008#endif
1009
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010#ifdef CONFIG_SOC_AU1X00
1011#include "ohci-au1xxx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001012#define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013#endif
1014
Vitaly Wool5151d042006-10-09 01:32:00 -07001015#ifdef CONFIG_PNX8550
1016#include "ohci-pnx8550.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001017#define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
Vitaly Wool5151d042006-10-09 01:32:00 -07001018#endif
1019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020#ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
1021#include "ohci-ppc-soc.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001022#define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023#endif
1024
Andrew Victor58a0cd72006-12-01 14:51:13 +01001025#ifdef CONFIG_ARCH_AT91
Andrew Victor39a269c2006-01-22 10:32:13 -08001026#include "ohci-at91.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001027#define PLATFORM_DRIVER ohci_hcd_at91_driver
Andrew Victor39a269c2006-01-22 10:32:13 -08001028#endif
1029
Vitaly Wool60bbfc82006-06-29 18:28:18 +04001030#ifdef CONFIG_ARCH_PNX4008
1031#include "ohci-pnx4008.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001032#define PLATFORM_DRIVER usb_hcd_pnx4008_driver
Vitaly Wool60bbfc82006-06-29 18:28:18 +04001033#endif
1034
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001035
Sylvain Munaut495a6782006-12-13 21:09:55 +01001036#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1037#include "ohci-ppc-of.c"
1038#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1039#endif
1040
Geoff Levand6a6c9572007-01-15 20:12:10 -08001041#ifdef CONFIG_PPC_PS3
1042#include "ohci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001043#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
Geoff Levand6a6c9572007-01-15 20:12:10 -08001044#endif
1045
Michael Bueschc604e852007-10-09 23:47:17 -07001046#ifdef CONFIG_USB_OHCI_HCD_SSB
1047#include "ohci-ssb.c"
1048#define SSB_OHCI_DRIVER ssb_ohci_driver
1049#endif
1050
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001051#if !defined(PCI_DRIVER) && \
1052 !defined(PLATFORM_DRIVER) && \
Sylvain Munaut495a6782006-12-13 21:09:55 +01001053 !defined(OF_PLATFORM_DRIVER) && \
Geoff Levand6a6c9572007-01-15 20:12:10 -08001054 !defined(SA1111_DRIVER) && \
Michael Bueschc604e852007-10-09 23:47:17 -07001055 !defined(PS3_SYSTEM_BUS_DRIVER) && \
1056 !defined(SSB_OHCI_DRIVER)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057#error "missing bus glue for ohci-hcd"
1058#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001059
1060static int __init ohci_hcd_mod_init(void)
1061{
1062 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001063
1064 if (usb_disabled())
1065 return -ENODEV;
1066
1067 printk (KERN_DEBUG "%s: " DRIVER_INFO "\n", hcd_name);
1068 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1069 sizeof (struct ed), sizeof (struct td));
1070
Geoff Levand6a6c9572007-01-15 20:12:10 -08001071#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001072 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1073 if (retval < 0)
1074 goto error_ps3;
Geoff Levand6a6c9572007-01-15 20:12:10 -08001075#endif
1076
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001077#ifdef PLATFORM_DRIVER
1078 retval = platform_driver_register(&PLATFORM_DRIVER);
1079 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001080 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001081#endif
1082
Sylvain Munaut495a6782006-12-13 21:09:55 +01001083#ifdef OF_PLATFORM_DRIVER
1084 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
1085 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001086 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +01001087#endif
1088
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001089#ifdef SA1111_DRIVER
1090 retval = sa1111_driver_register(&SA1111_DRIVER);
1091 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001092 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001093#endif
1094
1095#ifdef PCI_DRIVER
1096 retval = pci_register_driver(&PCI_DRIVER);
1097 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001098 goto error_pci;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001099#endif
1100
Michael Bueschc604e852007-10-09 23:47:17 -07001101#ifdef SSB_OHCI_DRIVER
1102 retval = ssb_driver_register(&SSB_OHCI_DRIVER);
1103 if (retval)
1104 goto error_ssb;
1105#endif
1106
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001107 return retval;
1108
1109 /* Error path */
Michael Bueschc604e852007-10-09 23:47:17 -07001110#ifdef SSB_OHCI_DRIVER
1111 error_ssb:
1112#endif
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001113#ifdef PCI_DRIVER
Michael Bueschc604e852007-10-09 23:47:17 -07001114 pci_unregister_driver(&PCI_DRIVER);
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001115 error_pci:
Sylvain Munaut495a6782006-12-13 21:09:55 +01001116#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001117#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001118 sa1111_driver_unregister(&SA1111_DRIVER);
1119 error_sa1111:
1120#endif
1121#ifdef OF_PLATFORM_DRIVER
1122 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1123 error_of_platform:
1124#endif
1125#ifdef PLATFORM_DRIVER
1126 platform_driver_unregister(&PLATFORM_DRIVER);
1127 error_platform:
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001128#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001129#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001130 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001131 error_ps3:
1132#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001133 return retval;
1134}
1135module_init(ohci_hcd_mod_init);
1136
1137static void __exit ohci_hcd_mod_exit(void)
1138{
Michael Bueschc604e852007-10-09 23:47:17 -07001139#ifdef SSB_OHCI_DRIVER
1140 ssb_driver_unregister(&SSB_OHCI_DRIVER);
1141#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001142#ifdef PCI_DRIVER
1143 pci_unregister_driver(&PCI_DRIVER);
1144#endif
1145#ifdef SA1111_DRIVER
1146 sa1111_driver_unregister(&SA1111_DRIVER);
1147#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001148#ifdef OF_PLATFORM_DRIVER
1149 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1150#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001151#ifdef PLATFORM_DRIVER
1152 platform_driver_unregister(&PLATFORM_DRIVER);
1153#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001154#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001155 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001156#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001157}
1158module_exit(ohci_hcd_mod_exit);
1159