blob: d673cb9c36b155a025b9b0aa88c0baa7f70e4d9c [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);
Michael Hanselmannd576bb92007-05-31 23:34:27 +020083static int ohci_restart (struct ohci_hcd *ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85#include "ohci-hub.c"
86#include "ohci-dbg.c"
87#include "ohci-mem.c"
88#include "ohci-q.c"
89
90
91/*
92 * On architectures with edge-triggered interrupts we must never return
93 * IRQ_NONE.
94 */
95#if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
96#define IRQ_NOTMINE IRQ_HANDLED
97#else
98#define IRQ_NOTMINE IRQ_NONE
99#endif
100
101
102/* Some boards misreport power switching/overcurrent */
103static int distrust_firmware = 1;
104module_param (distrust_firmware, bool, 0);
105MODULE_PARM_DESC (distrust_firmware,
106 "true to distrust firmware power/overcurrent setup");
107
108/* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
109static int no_handshake = 0;
110module_param (no_handshake, bool, 0);
111MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
112
113/*-------------------------------------------------------------------------*/
114
115/*
116 * queue up an urb for anything except the root hub
117 */
118static int ohci_urb_enqueue (
119 struct usb_hcd *hcd,
120 struct usb_host_endpoint *ep,
121 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400122 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123) {
124 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
125 struct ed *ed;
126 urb_priv_t *urb_priv;
127 unsigned int pipe = urb->pipe;
128 int i, size = 0;
129 unsigned long flags;
130 int retval = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#ifdef OHCI_VERBOSE_DEBUG
133 urb_print (urb, "SUB", usb_pipein (pipe));
134#endif
David Brownelldd9048a2006-12-05 03:18:31 -0800135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 /* every endpoint has a ed, locate and maybe (re)initialize it */
137 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval)))
138 return -ENOMEM;
139
140 /* for the private part of the URB we need the number of TDs (size) */
141 switch (ed->type) {
142 case PIPE_CONTROL:
143 /* td_submit_urb() doesn't yet handle these */
144 if (urb->transfer_buffer_length > 4096)
145 return -EMSGSIZE;
146
147 /* 1 TD for setup, 1 for ACK, plus ... */
148 size = 2;
149 /* FALLTHROUGH */
150 // case PIPE_INTERRUPT:
151 // case PIPE_BULK:
152 default:
153 /* one TD for every 4096 Bytes (can be upto 8K) */
154 size += urb->transfer_buffer_length / 4096;
155 /* ... and for any remaining bytes ... */
156 if ((urb->transfer_buffer_length % 4096) != 0)
157 size++;
158 /* ... and maybe a zero length packet to wrap it up */
159 if (size == 0)
160 size++;
161 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
162 && (urb->transfer_buffer_length
163 % usb_maxpacket (urb->dev, pipe,
164 usb_pipeout (pipe))) == 0)
165 size++;
166 break;
167 case PIPE_ISOCHRONOUS: /* number of packets from URB */
168 size = urb->number_of_packets;
169 break;
170 }
171
172 /* allocate the private part of the URB */
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700173 urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 mem_flags);
175 if (!urb_priv)
176 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 INIT_LIST_HEAD (&urb_priv->pending);
178 urb_priv->length = size;
David Brownelldd9048a2006-12-05 03:18:31 -0800179 urb_priv->ed = ed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 /* allocate the TDs (deferring hash chain updates) */
182 for (i = 0; i < size; i++) {
183 urb_priv->td [i] = td_alloc (ohci, mem_flags);
184 if (!urb_priv->td [i]) {
185 urb_priv->length = i;
186 urb_free_priv (ohci, urb_priv);
187 return -ENOMEM;
188 }
David Brownelldd9048a2006-12-05 03:18:31 -0800189 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 spin_lock_irqsave (&ohci->lock, flags);
192
193 /* don't submit to a dead HC */
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100194 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
195 retval = -ENODEV;
196 goto fail;
197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 if (!HC_IS_RUNNING(hcd->state)) {
199 retval = -ENODEV;
200 goto fail;
201 }
202
203 /* in case of unlink-during-submit */
204 spin_lock (&urb->lock);
205 if (urb->status != -EINPROGRESS) {
206 spin_unlock (&urb->lock);
207 urb->hcpriv = urb_priv;
David Howells7d12e782006-10-05 14:55:46 +0100208 finish_urb (ohci, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 retval = 0;
210 goto fail;
211 }
212
213 /* schedule the ed if needed */
214 if (ed->state == ED_IDLE) {
215 retval = ed_schedule (ohci, ed);
216 if (retval < 0)
217 goto fail0;
218 if (ed->type == PIPE_ISOCHRONOUS) {
219 u16 frame = ohci_frame_no(ohci);
220
221 /* delay a few frames before the first TD */
222 frame += max_t (u16, 8, ed->interval);
223 frame &= ~(ed->interval - 1);
224 frame |= ed->branch;
225 urb->start_frame = frame;
226
227 /* yes, only URB_ISO_ASAP is supported, and
228 * urb->start_frame is never used as input.
229 */
230 }
231 } else if (ed->type == PIPE_ISOCHRONOUS)
232 urb->start_frame = ed->last_iso + ed->interval;
233
234 /* fill the TDs and link them to the ed; and
235 * enable that part of the schedule, if needed
236 * and update count of queued periodic urbs
237 */
238 urb->hcpriv = urb_priv;
239 td_submit_urb (ohci, urb);
240
241fail0:
242 spin_unlock (&urb->lock);
243fail:
244 if (retval)
245 urb_free_priv (ohci, urb_priv);
246 spin_unlock_irqrestore (&ohci->lock, flags);
247 return retval;
248}
249
250/*
251 * decouple the URB from the HC queues (TDs, urb_priv); it's
252 * already marked using urb->status. reporting is always done
253 * asynchronously, and we might be dealing with an urb that's
254 * partially transferred, or an ED with other urbs being unlinked.
255 */
256static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
257{
258 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
259 unsigned long flags;
David Brownelldd9048a2006-12-05 03:18:31 -0800260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#ifdef OHCI_VERBOSE_DEBUG
262 urb_print (urb, "UNLINK", 1);
David Brownelldd9048a2006-12-05 03:18:31 -0800263#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 spin_lock_irqsave (&ohci->lock, flags);
David Brownelldd9048a2006-12-05 03:18:31 -0800266 if (HC_IS_RUNNING(hcd->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 urb_priv_t *urb_priv;
268
269 /* Unless an IRQ completed the unlink while it was being
270 * handed to us, flag it for unlink and giveback, and force
271 * some upcoming INTR_SF to call finish_unlinks()
272 */
273 urb_priv = urb->hcpriv;
274 if (urb_priv) {
275 if (urb_priv->ed->state == ED_OPER)
276 start_ed_unlink (ohci, urb_priv->ed);
277 }
278 } else {
279 /*
280 * with HC dead, we won't respect hc queue pointers
281 * any more ... just clean up every urb's memory.
282 */
283 if (urb->hcpriv)
David Howells7d12e782006-10-05 14:55:46 +0100284 finish_urb (ohci, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 }
286 spin_unlock_irqrestore (&ohci->lock, flags);
287 return 0;
288}
289
290/*-------------------------------------------------------------------------*/
291
292/* frees config/altsetting state for endpoints,
293 * including ED memory, dummy TD, and bulk/intr data toggle
294 */
295
296static void
297ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
298{
299 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
300 unsigned long flags;
301 struct ed *ed = ep->hcpriv;
302 unsigned limit = 1000;
303
304 /* ASSERT: any requests/urbs are being unlinked */
305 /* ASSERT: nobody can be submitting urbs for this any more */
306
307 if (!ed)
308 return;
309
310rescan:
311 spin_lock_irqsave (&ohci->lock, flags);
312
313 if (!HC_IS_RUNNING (hcd->state)) {
314sanitize:
315 ed->state = ED_IDLE;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700316 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
317 ohci->eds_scheduled--;
David Howells7d12e782006-10-05 14:55:46 +0100318 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
320
321 switch (ed->state) {
322 case ED_UNLINK: /* wait for hw to finish? */
323 /* major IRQ delivery trouble loses INTR_SF too... */
324 if (limit-- == 0) {
Mike Nuss89a0fd12007-08-01 13:24:30 -0700325 ohci_warn(ohci, "ED unlink timeout\n");
326 if (quirk_zfmicro(ohci)) {
327 ohci_warn(ohci, "Attempting ZF TD recovery\n");
328 ohci->ed_to_check = ed;
329 ohci->zf_delay = 2;
330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 goto sanitize;
332 }
333 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700334 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 goto rescan;
336 case ED_IDLE: /* fully unlinked */
337 if (list_empty (&ed->td_list)) {
338 td_free (ohci, ed->dummy);
339 ed_free (ohci, ed);
340 break;
341 }
342 /* else FALL THROUGH */
343 default:
344 /* caller was supposed to have unlinked any requests;
345 * that's not our job. can't recover; must leak ed.
346 */
347 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
348 ed, ep->desc.bEndpointAddress, ed->state,
349 list_empty (&ed->td_list) ? "" : " (has tds)");
350 td_free (ohci, ed->dummy);
351 break;
352 }
353 ep->hcpriv = NULL;
354 spin_unlock_irqrestore (&ohci->lock, flags);
355 return;
356}
357
358static int ohci_get_frame (struct usb_hcd *hcd)
359{
360 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
361
362 return ohci_frame_no(ohci);
363}
364
365static void ohci_usb_reset (struct ohci_hcd *ohci)
366{
367 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
368 ohci->hc_control &= OHCI_CTRL_RWC;
369 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
370}
371
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700372/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700373 * other cases where the next software may expect clean state from the
374 * "firmware". this is bus-neutral, unlike shutdown() methods.
375 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700376static void
377ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700378{
379 struct ohci_hcd *ohci;
380
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700381 ohci = hcd_to_ohci (hcd);
David Brownellf4df0e32005-04-23 12:49:16 -0700382 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
383 ohci_usb_reset (ohci);
384 /* flush the writes */
385 (void) ohci_readl (ohci, &ohci->regs->control);
David Brownellf4df0e32005-04-23 12:49:16 -0700386}
387
Mike Nuss89a0fd12007-08-01 13:24:30 -0700388static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
389{
390 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
391 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
392 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
393 && !list_empty(&ed->td_list);
394}
395
396/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
397 * an interrupt TD but neglects to add it to the donelist. On systems with
398 * this chipset, we need to periodically check the state of the queues to look
399 * for such "lost" TDs.
400 */
401static void unlink_watchdog_func(unsigned long _ohci)
402{
403 long flags;
404 unsigned max;
405 unsigned seen_count = 0;
406 unsigned i;
407 struct ed **seen = NULL;
408 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
409
410 spin_lock_irqsave(&ohci->lock, flags);
411 max = ohci->eds_scheduled;
412 if (!max)
413 goto done;
414
415 if (ohci->ed_to_check)
416 goto out;
417
418 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
419 if (!seen)
420 goto out;
421
422 for (i = 0; i < NUM_INTS; i++) {
423 struct ed *ed = ohci->periodic[i];
424
425 while (ed) {
426 unsigned temp;
427
428 /* scan this branch of the periodic schedule tree */
429 for (temp = 0; temp < seen_count; temp++) {
430 if (seen[temp] == ed) {
431 /* we've checked it and what's after */
432 ed = NULL;
433 break;
434 }
435 }
436 if (!ed)
437 break;
438 seen[seen_count++] = ed;
439 if (!check_ed(ohci, ed)) {
440 ed = ed->ed_next;
441 continue;
442 }
443
444 /* HC's TD list is empty, but HCD sees at least one
445 * TD that's not been sent through the donelist.
446 */
447 ohci->ed_to_check = ed;
448 ohci->zf_delay = 2;
449
450 /* The HC may wait until the next frame to report the
451 * TD as done through the donelist and INTR_WDH. (We
452 * just *assume* it's not a multi-TD interrupt URB;
453 * those could defer the IRQ more than one frame, using
454 * DI...) Check again after the next INTR_SF.
455 */
456 ohci_writel(ohci, OHCI_INTR_SF,
457 &ohci->regs->intrstatus);
458 ohci_writel(ohci, OHCI_INTR_SF,
459 &ohci->regs->intrenable);
460
461 /* flush those writes */
462 (void) ohci_readl(ohci, &ohci->regs->control);
463
464 goto out;
465 }
466 }
467out:
468 kfree(seen);
469 if (ohci->eds_scheduled)
470 mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
471done:
472 spin_unlock_irqrestore(&ohci->lock, flags);
473}
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475/*-------------------------------------------------------------------------*
476 * HC functions
477 *-------------------------------------------------------------------------*/
478
479/* init memory, and kick BIOS/SMM off */
480
481static int ohci_init (struct ohci_hcd *ohci)
482{
483 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800484 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 disable (ohci);
David Brownell6a9062f2006-01-23 15:28:07 -0800487 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
David Brownell6a9062f2006-01-23 15:28:07 -0800489 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
490 * was never needed for most non-PCI systems ... remove the code?
491 */
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#ifndef IR_DISABLE
494 /* SMM owns the HC? not for long! */
495 if (!no_handshake && ohci_readl (ohci,
496 &ohci->regs->control) & OHCI_CTRL_IR) {
497 u32 temp;
498
499 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
500
501 /* this timeout is arbitrary. we make it long, so systems
502 * depending on usb keyboards may be usable even if the
503 * BIOS/SMM code seems pretty broken.
504 */
505 temp = 500; /* arbitrary: five seconds */
506
507 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
508 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
509 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
510 msleep (10);
511 if (--temp == 0) {
512 ohci_err (ohci, "USB HC takeover failed!"
513 " (BIOS/SMM bug)\n");
514 return -EBUSY;
515 }
516 }
517 ohci_usb_reset (ohci);
518 }
519#endif
520
521 /* Disable HC interrupts */
522 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800523
524 /* flush the writes, and save key bits like RWC */
525 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
526 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
David Brownellfdd13b32005-08-31 11:52:57 -0700528 /* Read the number of ports unless overridden */
529 if (ohci->num_ports == 0)
530 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 if (ohci->hcca)
533 return 0;
534
David Brownell6a9062f2006-01-23 15:28:07 -0800535 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
537 if (!ohci->hcca)
538 return -ENOMEM;
539
540 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800541 ohci_stop (hcd);
542 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800543 create_debug_files (ohci);
544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547}
548
549/*-------------------------------------------------------------------------*/
550
551/* Start an OHCI controller, set the BUS operational
552 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800553 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 */
555static int ohci_run (struct ohci_hcd *ohci)
556{
David Brownelldd9048a2006-12-05 03:18:31 -0800557 u32 mask, temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800559 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 disable (ohci);
562
563 /* boot firmware should have set this up (5.1.1.3.1) */
564 if (first) {
565
566 temp = ohci_readl (ohci, &ohci->regs->fminterval);
567 ohci->fminterval = temp & 0x3fff;
568 if (ohci->fminterval != FI)
569 ohci_dbg (ohci, "fminterval delta %d\n",
570 ohci->fminterval - FI);
571 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
572 /* also: power/overcurrent flags in roothub.a */
573 }
574
David Brownelldd9048a2006-12-05 03:18:31 -0800575 /* Reset USB nearly "by the book". RemoteWakeupConnected was
David Brownell6a9062f2006-01-23 15:28:07 -0800576 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
577 * or if bus glue did the same (e.g. for PCI add-in cards with
578 * PCI PM support).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 */
David Brownell6a9062f2006-01-23 15:28:07 -0800580 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0
581 && !device_may_wakeup(hcd->self.controller))
582 device_init_wakeup(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
585 case OHCI_USB_OPER:
586 temp = 0;
587 break;
588 case OHCI_USB_SUSPEND:
589 case OHCI_USB_RESUME:
590 ohci->hc_control &= OHCI_CTRL_RWC;
591 ohci->hc_control |= OHCI_USB_RESUME;
592 temp = 10 /* msec wait */;
593 break;
594 // case OHCI_USB_RESET:
595 default:
596 ohci->hc_control &= OHCI_CTRL_RWC;
597 ohci->hc_control |= OHCI_USB_RESET;
598 temp = 50 /* msec wait */;
599 break;
600 }
601 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
602 // flush the writes
603 (void) ohci_readl (ohci, &ohci->regs->control);
604 msleep(temp);
Alan Stern383975d2007-05-04 11:52:40 -0400605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
607
608 /* 2msec timelimit here means no irqs/preempt */
609 spin_lock_irq (&ohci->lock);
610
611retry:
612 /* HC Reset requires max 10 us delay */
613 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
614 temp = 30; /* ... allow extra time */
615 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
616 if (--temp == 0) {
617 spin_unlock_irq (&ohci->lock);
618 ohci_err (ohci, "USB HC reset timed out!\n");
619 return -1;
620 }
621 udelay (1);
622 }
623
624 /* now we're in the SUSPEND state ... must go OPERATIONAL
625 * within 2msec else HC enters RESUME
626 *
627 * ... but some hardware won't init fmInterval "by the book"
628 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
629 * this if we write fmInterval after we're OPERATIONAL.
630 * Unclear about ALi, ServerWorks, and others ... this could
631 * easily be a longstanding bug in chip init on Linux.
632 */
633 if (ohci->flags & OHCI_QUIRK_INITRESET) {
634 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
635 // flush those writes
636 (void) ohci_readl (ohci, &ohci->regs->control);
637 }
638
639 /* Tell the controller where the control and bulk lists are
640 * The lists are empty now. */
641 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
642 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
643
644 /* a reset clears this */
645 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
646
647 periodic_reinit (ohci);
648
649 /* some OHCI implementations are finicky about how they init.
650 * bogus values here mean not even enumeration could work.
651 */
652 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
653 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
654 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
655 ohci->flags |= OHCI_QUIRK_INITRESET;
656 ohci_dbg (ohci, "enabling initreset quirk\n");
657 goto retry;
658 }
659 spin_unlock_irq (&ohci->lock);
660 ohci_err (ohci, "init err (%08x %04x)\n",
661 ohci_readl (ohci, &ohci->regs->fminterval),
662 ohci_readl (ohci, &ohci->regs->periodicstart));
663 return -EOVERFLOW;
664 }
665
David Brownelld4139842006-08-04 11:31:55 -0700666 /* use rhsc irqs after khubd is fully initialized */
667 hcd->poll_rh = 1;
668 hcd->uses_new_polling = 1;
669
670 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700672 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
673 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
David Brownell6a9062f2006-01-23 15:28:07 -0800674 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 /* wake on ConnectStatusChange, matching external hubs */
677 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
678
679 /* Choose the interrupts we care about now, others later on demand */
680 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700681 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 ohci_writel (ohci, mask, &ohci->regs->intrenable);
683
684 /* handle root hub init quirks ... */
685 temp = roothub_a (ohci);
686 temp &= ~(RH_A_PSM | RH_A_OCPM);
687 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
688 /* NSC 87560 and maybe others */
689 temp |= RH_A_NOCP;
690 temp &= ~(RH_A_POTPGT | RH_A_NPS);
691 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
692 } else if ((ohci->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
693 /* hub power always on; required for AMD-756 and some
694 * Mac platforms. ganged overcurrent reporting, if any.
695 */
696 temp |= RH_A_NPS;
697 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
698 }
699 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
700 ohci_writel (ohci, (temp & RH_A_NPS) ? 0 : RH_B_PPCM,
701 &ohci->regs->roothub.b);
702 // flush those writes
703 (void) ohci_readl (ohci, &ohci->regs->control);
704
David Brownelld4139842006-08-04 11:31:55 -0700705 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 spin_unlock_irq (&ohci->lock);
707
708 // POTPGT delay is bits 24-31, in 2 ms units.
709 mdelay ((temp >> 23) & 0x1fe);
David Brownell6a9062f2006-01-23 15:28:07 -0800710 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Mike Nuss89a0fd12007-08-01 13:24:30 -0700712 if (quirk_zfmicro(ohci)) {
713 /* Create timer to watch for bad queue state on ZF Micro */
714 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
715 (unsigned long) ohci);
716
717 ohci->eds_scheduled = 0;
718 ohci->ed_to_check = NULL;
719 }
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 ohci_dump (ohci, 1);
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 return 0;
724}
725
726/*-------------------------------------------------------------------------*/
727
728/* an interrupt happens */
729
David Howells7d12e782006-10-05 14:55:46 +0100730static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
732 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
733 struct ohci_regs __iomem *regs = ohci->regs;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700734 int ints;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 /* we can eliminate a (slow) ohci_readl()
Mike Nuss89a0fd12007-08-01 13:24:30 -0700737 * if _only_ WDH caused this irq
738 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 if ((ohci->hcca->done_head != 0)
740 && ! (hc32_to_cpup (ohci, &ohci->hcca->done_head)
741 & 0x01)) {
742 ints = OHCI_INTR_WDH;
743
744 /* cardbus/... hardware gone before remove() */
745 } else if ((ints = ohci_readl (ohci, &regs->intrstatus)) == ~(u32)0) {
746 disable (ohci);
747 ohci_dbg (ohci, "device removed!\n");
748 return IRQ_HANDLED;
749
750 /* interrupt for some other device? */
751 } else if ((ints &= ohci_readl (ohci, &regs->intrenable)) == 0) {
752 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700753 }
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 if (ints & OHCI_INTR_UE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 // e.g. due to PCI Master/Target Abort
Mike Nuss89a0fd12007-08-01 13:24:30 -0700757 if (quirk_nec(ohci)) {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200758 /* Workaround for a silicon bug in some NEC chips used
759 * in Apple's PowerBooks. Adapted from Darwin code.
760 */
761 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
762
763 ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
764
765 schedule_work (&ohci->nec_work);
766 } else {
767 disable (ohci);
768 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
769 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 ohci_dump (ohci, 1);
772 ohci_usb_reset (ohci);
773 }
774
Alan Stern583cead2006-10-24 12:04:22 -0400775 if (ints & OHCI_INTR_RHSC) {
776 ohci_vdbg(ohci, "rhsc\n");
777 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
778 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
779 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400780
781 /* NOTE: Vendors didn't always make the same implementation
782 * choices for RHSC. Many followed the spec; RHSC triggers
783 * on an edge, like setting and maybe clearing a port status
784 * change bit. With others it's level-triggered, active
785 * until khubd clears all the port status change bits. We'll
786 * always disable it here and rely on polling until khubd
787 * re-enables it.
788 */
789 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400790 usb_hcd_poll_rh_status(hcd);
791 }
792
793 /* For connect and disconnect events, we expect the controller
794 * to turn on RHSC along with RD. But for remote wakeup events
795 * this might not happen.
796 */
797 else if (ints & OHCI_INTR_RD) {
798 ohci_vdbg(ohci, "resume detect\n");
799 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern8d1a2432006-09-26 14:46:16 -0400800 hcd->poll_rh = 1;
801 if (ohci->autostop) {
802 spin_lock (&ohci->lock);
803 ohci_rh_resume (ohci);
804 spin_unlock (&ohci->lock);
805 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700806 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
808
809 if (ints & OHCI_INTR_WDH) {
810 if (HC_IS_RUNNING(hcd->state))
Alan Stern8d1a2432006-09-26 14:46:16 -0400811 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100813 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 spin_unlock (&ohci->lock);
815 if (HC_IS_RUNNING(hcd->state))
David Brownelldd9048a2006-12-05 03:18:31 -0800816 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 }
David Brownelldd9048a2006-12-05 03:18:31 -0800818
Mike Nuss89a0fd12007-08-01 13:24:30 -0700819 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
820 spin_lock(&ohci->lock);
821 if (ohci->ed_to_check) {
822 struct ed *ed = ohci->ed_to_check;
823
824 if (check_ed(ohci, ed)) {
825 /* HC thinks the TD list is empty; HCD knows
826 * at least one TD is outstanding
827 */
828 if (--ohci->zf_delay == 0) {
829 struct td *td = list_entry(
830 ed->td_list.next,
831 struct td, td_list);
832 ohci_warn(ohci,
833 "Reclaiming orphan TD %p\n",
834 td);
835 takeback_td(ohci, td);
836 ohci->ed_to_check = NULL;
837 }
838 } else
839 ohci->ed_to_check = NULL;
840 }
841 spin_unlock(&ohci->lock);
842 }
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 /* could track INTR_SO to reduce available PCI/... bandwidth */
845
846 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
847 * when there's still unlinking to be done (next frame).
848 */
849 spin_lock (&ohci->lock);
850 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100851 finish_unlinks (ohci, ohci_frame_no(ohci));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700852 if ((ints & OHCI_INTR_SF) != 0
853 && !ohci->ed_rm_list
854 && !ohci->ed_to_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 && HC_IS_RUNNING(hcd->state))
David Brownelldd9048a2006-12-05 03:18:31 -0800856 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 spin_unlock (&ohci->lock);
858
859 if (HC_IS_RUNNING(hcd->state)) {
860 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800861 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 // flush those writes
863 (void) ohci_readl (ohci, &ohci->regs->control);
864 }
865
866 return IRQ_HANDLED;
867}
868
869/*-------------------------------------------------------------------------*/
870
871static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800872{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 ohci_dump (ohci, 1);
876
877 flush_scheduled_work();
878
879 ohci_usb_reset (ohci);
880 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700881 free_irq(hcd->irq, hcd);
882 hcd->irq = -1;
883
Mike Nuss89a0fd12007-08-01 13:24:30 -0700884 if (quirk_zfmicro(ohci))
885 del_timer(&ohci->unlink_watchdog);
886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 ohci_mem_cleanup (ohci);
889 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800890 dma_free_coherent (hcd->self.controller,
891 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 ohci->hcca, ohci->hcca_dma);
893 ohci->hcca = NULL;
894 ohci->hcca_dma = 0;
895 }
896}
897
898/*-------------------------------------------------------------------------*/
899
900/* must not be called from interrupt context */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901static int ohci_restart (struct ohci_hcd *ohci)
902{
903 int temp;
904 int i;
905 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 spin_lock_irq(&ohci->lock);
908 disable (ohci);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200909
910 /* Recycle any "live" eds/tds (and urbs). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 if (!list_empty (&ohci->pending))
912 ohci_dbg(ohci, "abort schedule...\n");
913 list_for_each_entry (priv, &ohci->pending, pending) {
914 struct urb *urb = priv->td[0]->urb;
915 struct ed *ed = priv->ed;
916
917 switch (ed->state) {
918 case ED_OPER:
919 ed->state = ED_UNLINK;
920 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
921 ed_deschedule (ohci, ed);
922
923 ed->ed_next = ohci->ed_rm_list;
924 ed->ed_prev = NULL;
925 ohci->ed_rm_list = ed;
926 /* FALLTHROUGH */
927 case ED_UNLINK:
928 break;
929 default:
930 ohci_dbg(ohci, "bogus ed %p state %d\n",
931 ed, ed->state);
932 }
933
934 spin_lock (&urb->lock);
935 urb->status = -ESHUTDOWN;
936 spin_unlock (&urb->lock);
937 }
David Howells7d12e782006-10-05 14:55:46 +0100938 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 spin_unlock_irq(&ohci->lock);
940
941 /* paranoia, in case that didn't work: */
942
943 /* empty the interrupt branches */
944 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
945 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 /* no EDs to remove */
948 ohci->ed_rm_list = NULL;
949
David Brownelldd9048a2006-12-05 03:18:31 -0800950 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 ohci->ed_controltail = NULL;
952 ohci->ed_bulktail = NULL;
953
954 if ((temp = ohci_run (ohci)) < 0) {
955 ohci_err (ohci, "can't restart, %d\n", temp);
956 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 }
Alan Stern383975d2007-05-04 11:52:40 -0400958 ohci_dbg(ohci, "restart complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 return 0;
960}
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200961
962/*-------------------------------------------------------------------------*/
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
965
966MODULE_AUTHOR (DRIVER_AUTHOR);
967MODULE_DESCRIPTION (DRIVER_INFO);
968MODULE_LICENSE ("GPL");
969
970#ifdef CONFIG_PCI
971#include "ohci-pci.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100972#define PCI_DRIVER ohci_pci_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973#endif
974
975#ifdef CONFIG_SA1111
976#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100977#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978#endif
979
Ben Dooks3eb0c5f2005-07-29 12:18:03 -0700980#ifdef CONFIG_ARCH_S3C2410
981#include "ohci-s3c2410.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100982#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
Ben Dooks3eb0c5f2005-07-29 12:18:03 -0700983#endif
984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985#ifdef CONFIG_ARCH_OMAP
986#include "ohci-omap.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100987#define PLATFORM_DRIVER ohci_hcd_omap_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988#endif
989
990#ifdef CONFIG_ARCH_LH7A404
991#include "ohci-lh7a404.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100992#define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993#endif
994
995#ifdef CONFIG_PXA27x
996#include "ohci-pxa27x.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100997#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998#endif
999
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001000#ifdef CONFIG_ARCH_EP93XX
1001#include "ohci-ep93xx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001002#define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001003#endif
1004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005#ifdef CONFIG_SOC_AU1X00
1006#include "ohci-au1xxx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001007#define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008#endif
1009
Vitaly Wool5151d042006-10-09 01:32:00 -07001010#ifdef CONFIG_PNX8550
1011#include "ohci-pnx8550.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001012#define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
Vitaly Wool5151d042006-10-09 01:32:00 -07001013#endif
1014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015#ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
1016#include "ohci-ppc-soc.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001017#define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018#endif
1019
Andrew Victor58a0cd72006-12-01 14:51:13 +01001020#ifdef CONFIG_ARCH_AT91
Andrew Victor39a269c2006-01-22 10:32:13 -08001021#include "ohci-at91.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001022#define PLATFORM_DRIVER ohci_hcd_at91_driver
Andrew Victor39a269c2006-01-22 10:32:13 -08001023#endif
1024
Vitaly Wool60bbfc82006-06-29 18:28:18 +04001025#ifdef CONFIG_ARCH_PNX4008
1026#include "ohci-pnx4008.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001027#define PLATFORM_DRIVER usb_hcd_pnx4008_driver
Vitaly Wool60bbfc82006-06-29 18:28:18 +04001028#endif
1029
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001030
Sylvain Munaut495a6782006-12-13 21:09:55 +01001031#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1032#include "ohci-ppc-of.c"
1033#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1034#endif
1035
Geoff Levand6a6c9572007-01-15 20:12:10 -08001036#ifdef CONFIG_PPC_PS3
1037#include "ohci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001038#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
Geoff Levand6a6c9572007-01-15 20:12:10 -08001039#endif
1040
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001041#if !defined(PCI_DRIVER) && \
1042 !defined(PLATFORM_DRIVER) && \
Sylvain Munaut495a6782006-12-13 21:09:55 +01001043 !defined(OF_PLATFORM_DRIVER) && \
Geoff Levand6a6c9572007-01-15 20:12:10 -08001044 !defined(SA1111_DRIVER) && \
1045 !defined(PS3_SYSTEM_BUS_DRIVER)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046#error "missing bus glue for ohci-hcd"
1047#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001048
1049static int __init ohci_hcd_mod_init(void)
1050{
1051 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001052
1053 if (usb_disabled())
1054 return -ENODEV;
1055
1056 printk (KERN_DEBUG "%s: " DRIVER_INFO "\n", hcd_name);
1057 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1058 sizeof (struct ed), sizeof (struct td));
1059
Geoff Levand6a6c9572007-01-15 20:12:10 -08001060#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001061 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1062 if (retval < 0)
1063 goto error_ps3;
Geoff Levand6a6c9572007-01-15 20:12:10 -08001064#endif
1065
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001066#ifdef PLATFORM_DRIVER
1067 retval = platform_driver_register(&PLATFORM_DRIVER);
1068 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001069 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001070#endif
1071
Sylvain Munaut495a6782006-12-13 21:09:55 +01001072#ifdef OF_PLATFORM_DRIVER
1073 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
1074 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001075 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +01001076#endif
1077
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001078#ifdef SA1111_DRIVER
1079 retval = sa1111_driver_register(&SA1111_DRIVER);
1080 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001081 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001082#endif
1083
1084#ifdef PCI_DRIVER
1085 retval = pci_register_driver(&PCI_DRIVER);
1086 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001087 goto error_pci;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001088#endif
1089
1090 return retval;
1091
1092 /* Error path */
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001093#ifdef PCI_DRIVER
1094 error_pci:
Sylvain Munaut495a6782006-12-13 21:09:55 +01001095#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001096#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001097 sa1111_driver_unregister(&SA1111_DRIVER);
1098 error_sa1111:
1099#endif
1100#ifdef OF_PLATFORM_DRIVER
1101 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1102 error_of_platform:
1103#endif
1104#ifdef PLATFORM_DRIVER
1105 platform_driver_unregister(&PLATFORM_DRIVER);
1106 error_platform:
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001107#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001108#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001109 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001110 error_ps3:
1111#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001112 return retval;
1113}
1114module_init(ohci_hcd_mod_init);
1115
1116static void __exit ohci_hcd_mod_exit(void)
1117{
1118#ifdef PCI_DRIVER
1119 pci_unregister_driver(&PCI_DRIVER);
1120#endif
1121#ifdef SA1111_DRIVER
1122 sa1111_driver_unregister(&SA1111_DRIVER);
1123#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001124#ifdef OF_PLATFORM_DRIVER
1125 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1126#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001127#ifdef PLATFORM_DRIVER
1128 platform_driver_unregister(&PLATFORM_DRIVER);
1129#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001130#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001131 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001132#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001133}
1134module_exit(ohci_hcd_mod_exit);
1135