2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
7 * [ 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]
13 * 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.
18 * This file is licenced under the GPL.
21 #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>
29 #include <linux/errno.h>
30 #include <linux/init.h>
31 #include <linux/timer.h>
32 #include <linux/list.h>
33 #include <linux/usb.h>
34 #include <linux/usb/otg.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/dmapool.h>
37 #include <linux/reboot.h>
38 #include <linux/workqueue.h>
42 #include <asm/system.h>
43 #include <asm/unaligned.h>
44 #include <asm/byteorder.h>
46 #include <asm/firmware.h>
49 #include "../core/hcd.h"
51 #define DRIVER_VERSION "2006 August 04"
52 #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
53 #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
55 /*-------------------------------------------------------------------------*/
57 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
59 /* For initializing controller (mask in an HCFS mode too) */
60 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
61 #define OHCI_INTR_INIT \
62 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
63 | OHCI_INTR_RD | OHCI_INTR_WDH)
66 /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
70 #ifdef CONFIG_ARCH_OMAP
71 /* OMAP doesn't support IR (no SMM; not needed) */
75 /*-------------------------------------------------------------------------*/
77 static const char hcd_name [] = "ohci_hcd";
79 #define STATECHANGE_DELAY msecs_to_jiffies(300)
83 static void ohci_dump (struct ohci_hcd *ohci, int verbose);
84 static int ohci_init (struct ohci_hcd *ohci);
85 static void ohci_stop (struct usb_hcd *hcd);
86 static int ohci_restart (struct ohci_hcd *ohci);
87 static void ohci_quirk_nec_worker (struct work_struct *work);
96 * On architectures with edge-triggered interrupts we must never return
99 #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
100 #define IRQ_NOTMINE IRQ_HANDLED
102 #define IRQ_NOTMINE IRQ_NONE
106 /* Some boards misreport power switching/overcurrent */
107 static int distrust_firmware = 1;
108 module_param (distrust_firmware, bool, 0);
109 MODULE_PARM_DESC (distrust_firmware,
110 "true to distrust firmware power/overcurrent setup");
112 /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
113 static int no_handshake = 0;
114 module_param (no_handshake, bool, 0);
115 MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
117 /*-------------------------------------------------------------------------*/
120 * queue up an urb for anything except the root hub
122 static int ohci_urb_enqueue (
124 struct usb_host_endpoint *ep,
128 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
130 urb_priv_t *urb_priv;
131 unsigned int pipe = urb->pipe;
136 #ifdef OHCI_VERBOSE_DEBUG
137 urb_print (urb, "SUB", usb_pipein (pipe));
140 /* every endpoint has a ed, locate and maybe (re)initialize it */
141 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval)))
144 /* for the private part of the URB we need the number of TDs (size) */
147 /* td_submit_urb() doesn't yet handle these */
148 if (urb->transfer_buffer_length > 4096)
151 /* 1 TD for setup, 1 for ACK, plus ... */
154 // case PIPE_INTERRUPT:
157 /* one TD for every 4096 Bytes (can be upto 8K) */
158 size += urb->transfer_buffer_length / 4096;
159 /* ... and for any remaining bytes ... */
160 if ((urb->transfer_buffer_length % 4096) != 0)
162 /* ... and maybe a zero length packet to wrap it up */
165 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
166 && (urb->transfer_buffer_length
167 % usb_maxpacket (urb->dev, pipe,
168 usb_pipeout (pipe))) == 0)
171 case PIPE_ISOCHRONOUS: /* number of packets from URB */
172 size = urb->number_of_packets;
176 /* allocate the private part of the URB */
177 urb_priv = kmalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
181 memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (struct td *));
182 INIT_LIST_HEAD (&urb_priv->pending);
183 urb_priv->length = size;
186 /* allocate the TDs (deferring hash chain updates) */
187 for (i = 0; i < size; i++) {
188 urb_priv->td [i] = td_alloc (ohci, mem_flags);
189 if (!urb_priv->td [i]) {
190 urb_priv->length = i;
191 urb_free_priv (ohci, urb_priv);
196 spin_lock_irqsave (&ohci->lock, flags);
198 /* don't submit to a dead HC */
199 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
203 if (!HC_IS_RUNNING(hcd->state)) {
208 /* in case of unlink-during-submit */
209 spin_lock (&urb->lock);
210 if (urb->status != -EINPROGRESS) {
211 spin_unlock (&urb->lock);
212 urb->hcpriv = urb_priv;
213 finish_urb (ohci, urb);
218 /* schedule the ed if needed */
219 if (ed->state == ED_IDLE) {
220 retval = ed_schedule (ohci, ed);
223 if (ed->type == PIPE_ISOCHRONOUS) {
224 u16 frame = ohci_frame_no(ohci);
226 /* delay a few frames before the first TD */
227 frame += max_t (u16, 8, ed->interval);
228 frame &= ~(ed->interval - 1);
230 urb->start_frame = frame;
232 /* yes, only URB_ISO_ASAP is supported, and
233 * urb->start_frame is never used as input.
236 } else if (ed->type == PIPE_ISOCHRONOUS)
237 urb->start_frame = ed->last_iso + ed->interval;
239 /* fill the TDs and link them to the ed; and
240 * enable that part of the schedule, if needed
241 * and update count of queued periodic urbs
243 urb->hcpriv = urb_priv;
244 td_submit_urb (ohci, urb);
247 spin_unlock (&urb->lock);
250 urb_free_priv (ohci, urb_priv);
251 spin_unlock_irqrestore (&ohci->lock, flags);
256 * decouple the URB from the HC queues (TDs, urb_priv); it's
257 * already marked using urb->status. reporting is always done
258 * asynchronously, and we might be dealing with an urb that's
259 * partially transferred, or an ED with other urbs being unlinked.
261 static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
263 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
266 #ifdef OHCI_VERBOSE_DEBUG
267 urb_print (urb, "UNLINK", 1);
270 spin_lock_irqsave (&ohci->lock, flags);
271 if (HC_IS_RUNNING(hcd->state)) {
272 urb_priv_t *urb_priv;
274 /* Unless an IRQ completed the unlink while it was being
275 * handed to us, flag it for unlink and giveback, and force
276 * some upcoming INTR_SF to call finish_unlinks()
278 urb_priv = urb->hcpriv;
280 if (urb_priv->ed->state == ED_OPER)
281 start_ed_unlink (ohci, urb_priv->ed);
285 * with HC dead, we won't respect hc queue pointers
286 * any more ... just clean up every urb's memory.
289 finish_urb (ohci, urb);
291 spin_unlock_irqrestore (&ohci->lock, flags);
295 /*-------------------------------------------------------------------------*/
297 /* frees config/altsetting state for endpoints,
298 * including ED memory, dummy TD, and bulk/intr data toggle
302 ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
304 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
306 struct ed *ed = ep->hcpriv;
307 unsigned limit = 1000;
309 /* ASSERT: any requests/urbs are being unlinked */
310 /* ASSERT: nobody can be submitting urbs for this any more */
316 spin_lock_irqsave (&ohci->lock, flags);
318 if (!HC_IS_RUNNING (hcd->state)) {
321 finish_unlinks (ohci, 0);
325 case ED_UNLINK: /* wait for hw to finish? */
326 /* major IRQ delivery trouble loses INTR_SF too... */
328 ohci_warn (ohci, "IRQ INTR_SF lossage\n");
331 spin_unlock_irqrestore (&ohci->lock, flags);
332 schedule_timeout_uninterruptible(1);
334 case ED_IDLE: /* fully unlinked */
335 if (list_empty (&ed->td_list)) {
336 td_free (ohci, ed->dummy);
340 /* else FALL THROUGH */
342 /* caller was supposed to have unlinked any requests;
343 * that's not our job. can't recover; must leak ed.
345 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
346 ed, ep->desc.bEndpointAddress, ed->state,
347 list_empty (&ed->td_list) ? "" : " (has tds)");
348 td_free (ohci, ed->dummy);
352 spin_unlock_irqrestore (&ohci->lock, flags);
356 static int ohci_get_frame (struct usb_hcd *hcd)
358 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
360 return ohci_frame_no(ohci);
363 static void ohci_usb_reset (struct ohci_hcd *ohci)
365 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
366 ohci->hc_control &= OHCI_CTRL_RWC;
367 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
370 /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
371 * other cases where the next software may expect clean state from the
372 * "firmware". this is bus-neutral, unlike shutdown() methods.
375 ohci_shutdown (struct usb_hcd *hcd)
377 struct ohci_hcd *ohci;
379 ohci = hcd_to_ohci (hcd);
380 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
381 ohci_usb_reset (ohci);
382 /* flush the writes */
383 (void) ohci_readl (ohci, &ohci->regs->control);
386 /*-------------------------------------------------------------------------*
388 *-------------------------------------------------------------------------*/
390 /* init memory, and kick BIOS/SMM off */
392 static int ohci_init (struct ohci_hcd *ohci)
395 struct usb_hcd *hcd = ohci_to_hcd(ohci);
398 ohci->regs = hcd->regs;
400 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
401 * was never needed for most non-PCI systems ... remove the code?
405 /* SMM owns the HC? not for long! */
406 if (!no_handshake && ohci_readl (ohci,
407 &ohci->regs->control) & OHCI_CTRL_IR) {
410 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
412 /* this timeout is arbitrary. we make it long, so systems
413 * depending on usb keyboards may be usable even if the
414 * BIOS/SMM code seems pretty broken.
416 temp = 500; /* arbitrary: five seconds */
418 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
419 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
420 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
423 ohci_err (ohci, "USB HC takeover failed!"
424 " (BIOS/SMM bug)\n");
428 ohci_usb_reset (ohci);
432 /* Disable HC interrupts */
433 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
435 /* flush the writes, and save key bits like RWC */
436 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
437 ohci->hc_control |= OHCI_CTRL_RWC;
439 /* Read the number of ports unless overridden */
440 if (ohci->num_ports == 0)
441 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
446 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
447 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
451 if ((ret = ohci_mem_init (ohci)) < 0)
454 create_debug_files (ohci);
460 /*-------------------------------------------------------------------------*/
462 /* Start an OHCI controller, set the BUS operational
463 * resets USB and controller
466 static int ohci_run (struct ohci_hcd *ohci)
469 int first = ohci->fminterval == 0;
470 struct usb_hcd *hcd = ohci_to_hcd(ohci);
474 /* boot firmware should have set this up (5.1.1.3.1) */
477 temp = ohci_readl (ohci, &ohci->regs->fminterval);
478 ohci->fminterval = temp & 0x3fff;
479 if (ohci->fminterval != FI)
480 ohci_dbg (ohci, "fminterval delta %d\n",
481 ohci->fminterval - FI);
482 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
483 /* also: power/overcurrent flags in roothub.a */
486 /* Reset USB nearly "by the book". RemoteWakeupConnected was
487 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
488 * or if bus glue did the same (e.g. for PCI add-in cards with
491 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0
492 && !device_may_wakeup(hcd->self.controller))
493 device_init_wakeup(hcd->self.controller, 1);
495 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
499 case OHCI_USB_SUSPEND:
500 case OHCI_USB_RESUME:
501 ohci->hc_control &= OHCI_CTRL_RWC;
502 ohci->hc_control |= OHCI_USB_RESUME;
503 temp = 10 /* msec wait */;
505 // case OHCI_USB_RESET:
507 ohci->hc_control &= OHCI_CTRL_RWC;
508 ohci->hc_control |= OHCI_USB_RESET;
509 temp = 50 /* msec wait */;
512 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
514 (void) ohci_readl (ohci, &ohci->regs->control);
517 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
519 /* 2msec timelimit here means no irqs/preempt */
520 spin_lock_irq (&ohci->lock);
523 /* HC Reset requires max 10 us delay */
524 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
525 temp = 30; /* ... allow extra time */
526 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
528 spin_unlock_irq (&ohci->lock);
529 ohci_err (ohci, "USB HC reset timed out!\n");
535 /* now we're in the SUSPEND state ... must go OPERATIONAL
536 * within 2msec else HC enters RESUME
538 * ... but some hardware won't init fmInterval "by the book"
539 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
540 * this if we write fmInterval after we're OPERATIONAL.
541 * Unclear about ALi, ServerWorks, and others ... this could
542 * easily be a longstanding bug in chip init on Linux.
544 if (ohci->flags & OHCI_QUIRK_INITRESET) {
545 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
546 // flush those writes
547 (void) ohci_readl (ohci, &ohci->regs->control);
550 /* Tell the controller where the control and bulk lists are
551 * The lists are empty now. */
552 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
553 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
555 /* a reset clears this */
556 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
558 periodic_reinit (ohci);
560 /* some OHCI implementations are finicky about how they init.
561 * bogus values here mean not even enumeration could work.
563 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
564 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
565 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
566 ohci->flags |= OHCI_QUIRK_INITRESET;
567 ohci_dbg (ohci, "enabling initreset quirk\n");
570 spin_unlock_irq (&ohci->lock);
571 ohci_err (ohci, "init err (%08x %04x)\n",
572 ohci_readl (ohci, &ohci->regs->fminterval),
573 ohci_readl (ohci, &ohci->regs->periodicstart));
577 /* use rhsc irqs after khubd is fully initialized */
579 hcd->uses_new_polling = 1;
581 /* start controller operations */
582 ohci->hc_control &= OHCI_CTRL_RWC;
583 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
584 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
585 hcd->state = HC_STATE_RUNNING;
587 /* wake on ConnectStatusChange, matching external hubs */
588 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
590 /* Choose the interrupts we care about now, others later on demand */
591 mask = OHCI_INTR_INIT;
592 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
593 ohci_writel (ohci, mask, &ohci->regs->intrenable);
595 /* handle root hub init quirks ... */
596 temp = roothub_a (ohci);
597 temp &= ~(RH_A_PSM | RH_A_OCPM);
598 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
599 /* NSC 87560 and maybe others */
601 temp &= ~(RH_A_POTPGT | RH_A_NPS);
602 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
603 } else if ((ohci->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
604 /* hub power always on; required for AMD-756 and some
605 * Mac platforms. ganged overcurrent reporting, if any.
608 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
610 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
611 ohci_writel (ohci, (temp & RH_A_NPS) ? 0 : RH_B_PPCM,
612 &ohci->regs->roothub.b);
613 // flush those writes
614 (void) ohci_readl (ohci, &ohci->regs->control);
616 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
617 spin_unlock_irq (&ohci->lock);
619 // POTPGT delay is bits 24-31, in 2 ms units.
620 mdelay ((temp >> 23) & 0x1fe);
621 hcd->state = HC_STATE_RUNNING;
628 /*-------------------------------------------------------------------------*/
630 /* an interrupt happens */
632 static irqreturn_t ohci_irq (struct usb_hcd *hcd)
634 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
635 struct ohci_regs __iomem *regs = ohci->regs;
638 /* we can eliminate a (slow) ohci_readl()
639 if _only_ WDH caused this irq */
640 if ((ohci->hcca->done_head != 0)
641 && ! (hc32_to_cpup (ohci, &ohci->hcca->done_head)
643 ints = OHCI_INTR_WDH;
645 /* cardbus/... hardware gone before remove() */
646 } else if ((ints = ohci_readl (ohci, ®s->intrstatus)) == ~(u32)0) {
648 ohci_dbg (ohci, "device removed!\n");
651 /* interrupt for some other device? */
652 } else if ((ints &= ohci_readl (ohci, ®s->intrenable)) == 0) {
656 if (ints & OHCI_INTR_UE) {
657 // e.g. due to PCI Master/Target Abort
658 if (ohci->flags & OHCI_QUIRK_NEC) {
659 /* Workaround for a silicon bug in some NEC chips used
660 * in Apple's PowerBooks. Adapted from Darwin code.
662 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
664 ohci_writel (ohci, OHCI_INTR_UE, ®s->intrdisable);
666 schedule_work (&ohci->nec_work);
669 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
673 ohci_usb_reset (ohci);
676 if (ints & OHCI_INTR_RHSC) {
677 ohci_vdbg(ohci, "rhsc\n");
678 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
679 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
682 /* NOTE: Vendors didn't always make the same implementation
683 * choices for RHSC. Many followed the spec; RHSC triggers
684 * on an edge, like setting and maybe clearing a port status
685 * change bit. With others it's level-triggered, active
686 * until khubd clears all the port status change bits. We'll
687 * always disable it here and rely on polling until khubd
690 ohci_writel(ohci, OHCI_INTR_RHSC, ®s->intrdisable);
691 usb_hcd_poll_rh_status(hcd);
694 /* For connect and disconnect events, we expect the controller
695 * to turn on RHSC along with RD. But for remote wakeup events
696 * this might not happen.
698 else if (ints & OHCI_INTR_RD) {
699 ohci_vdbg(ohci, "resume detect\n");
700 ohci_writel(ohci, OHCI_INTR_RD, ®s->intrstatus);
702 if (ohci->autostop) {
703 spin_lock (&ohci->lock);
704 ohci_rh_resume (ohci);
705 spin_unlock (&ohci->lock);
707 usb_hcd_resume_root_hub(hcd);
710 if (ints & OHCI_INTR_WDH) {
711 if (HC_IS_RUNNING(hcd->state))
712 ohci_writel (ohci, OHCI_INTR_WDH, ®s->intrdisable);
713 spin_lock (&ohci->lock);
715 spin_unlock (&ohci->lock);
716 if (HC_IS_RUNNING(hcd->state))
717 ohci_writel (ohci, OHCI_INTR_WDH, ®s->intrenable);
720 /* could track INTR_SO to reduce available PCI/... bandwidth */
722 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
723 * when there's still unlinking to be done (next frame).
725 spin_lock (&ohci->lock);
726 if (ohci->ed_rm_list)
727 finish_unlinks (ohci, ohci_frame_no(ohci));
728 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
729 && HC_IS_RUNNING(hcd->state))
730 ohci_writel (ohci, OHCI_INTR_SF, ®s->intrdisable);
731 spin_unlock (&ohci->lock);
733 if (HC_IS_RUNNING(hcd->state)) {
734 ohci_writel (ohci, ints, ®s->intrstatus);
735 ohci_writel (ohci, OHCI_INTR_MIE, ®s->intrenable);
736 // flush those writes
737 (void) ohci_readl (ohci, &ohci->regs->control);
743 /*-------------------------------------------------------------------------*/
745 static void ohci_stop (struct usb_hcd *hcd)
747 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
751 flush_scheduled_work();
753 ohci_usb_reset (ohci);
754 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
755 free_irq(hcd->irq, hcd);
758 remove_debug_files (ohci);
759 ohci_mem_cleanup (ohci);
761 dma_free_coherent (hcd->self.controller,
763 ohci->hcca, ohci->hcca_dma);
769 /*-------------------------------------------------------------------------*/
771 /* must not be called from interrupt context */
772 static int ohci_restart (struct ohci_hcd *ohci)
776 struct urb_priv *priv;
778 spin_lock_irq(&ohci->lock);
781 /* Recycle any "live" eds/tds (and urbs). */
782 if (!list_empty (&ohci->pending))
783 ohci_dbg(ohci, "abort schedule...\n");
784 list_for_each_entry (priv, &ohci->pending, pending) {
785 struct urb *urb = priv->td[0]->urb;
786 struct ed *ed = priv->ed;
790 ed->state = ED_UNLINK;
791 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
792 ed_deschedule (ohci, ed);
794 ed->ed_next = ohci->ed_rm_list;
796 ohci->ed_rm_list = ed;
801 ohci_dbg(ohci, "bogus ed %p state %d\n",
805 spin_lock (&urb->lock);
806 urb->status = -ESHUTDOWN;
807 spin_unlock (&urb->lock);
809 finish_unlinks (ohci, 0);
810 spin_unlock_irq(&ohci->lock);
812 /* paranoia, in case that didn't work: */
814 /* empty the interrupt branches */
815 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
816 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
818 /* no EDs to remove */
819 ohci->ed_rm_list = NULL;
821 /* empty control and bulk lists */
822 ohci->ed_controltail = NULL;
823 ohci->ed_bulktail = NULL;
825 if ((temp = ohci_run (ohci)) < 0) {
826 ohci_err (ohci, "can't restart, %d\n", temp);
829 ohci_dbg(ohci, "restart complete\n");
833 /*-------------------------------------------------------------------------*/
836 static void ohci_quirk_nec_worker(struct work_struct *work)
838 struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work);
841 status = ohci_init(ohci);
843 ohci_err(ohci, "Restarting NEC controller failed "
844 "in ohci_init, %d\n", status);
848 status = ohci_restart(ohci);
850 ohci_err(ohci, "Restarting NEC controller failed "
851 "in ohci_restart, %d\n", status);
854 /*-------------------------------------------------------------------------*/
856 #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
858 MODULE_AUTHOR (DRIVER_AUTHOR);
859 MODULE_DESCRIPTION (DRIVER_INFO);
860 MODULE_LICENSE ("GPL");
863 #include "ohci-pci.c"
864 #define PCI_DRIVER ohci_pci_driver
868 #include "ohci-sa1111.c"
869 #define SA1111_DRIVER ohci_hcd_sa1111_driver
872 #ifdef CONFIG_ARCH_S3C2410
873 #include "ohci-s3c2410.c"
874 #define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
877 #ifdef CONFIG_ARCH_OMAP
878 #include "ohci-omap.c"
879 #define PLATFORM_DRIVER ohci_hcd_omap_driver
882 #ifdef CONFIG_ARCH_LH7A404
883 #include "ohci-lh7a404.c"
884 #define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
888 #include "ohci-pxa27x.c"
889 #define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
892 #ifdef CONFIG_ARCH_EP93XX
893 #include "ohci-ep93xx.c"
894 #define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
897 #ifdef CONFIG_SOC_AU1X00
898 #include "ohci-au1xxx.c"
899 #define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
902 #ifdef CONFIG_PNX8550
903 #include "ohci-pnx8550.c"
904 #define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
907 #ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
908 #include "ohci-ppc-soc.c"
909 #define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
912 #ifdef CONFIG_ARCH_AT91
913 #include "ohci-at91.c"
914 #define PLATFORM_DRIVER ohci_hcd_at91_driver
917 #ifdef CONFIG_ARCH_PNX4008
918 #include "ohci-pnx4008.c"
919 #define PLATFORM_DRIVER usb_hcd_pnx4008_driver
923 #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
924 #include "ohci-ppc-of.c"
925 #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
928 #ifdef CONFIG_PPC_PS3
929 #include "ohci-ps3.c"
930 #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_sb_driver
933 #if !defined(PCI_DRIVER) && \
934 !defined(PLATFORM_DRIVER) && \
935 !defined(OF_PLATFORM_DRIVER) && \
936 !defined(SA1111_DRIVER) && \
937 !defined(PS3_SYSTEM_BUS_DRIVER)
938 #error "missing bus glue for ohci-hcd"
941 static int __init ohci_hcd_mod_init(void)
948 printk (KERN_DEBUG "%s: " DRIVER_INFO "\n", hcd_name);
949 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
950 sizeof (struct ed), sizeof (struct td));
952 #ifdef PS3_SYSTEM_BUS_DRIVER
953 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
954 retval = ps3_system_bus_driver_register(
955 &PS3_SYSTEM_BUS_DRIVER);
961 #ifdef PLATFORM_DRIVER
962 retval = platform_driver_register(&PLATFORM_DRIVER);
967 #ifdef OF_PLATFORM_DRIVER
968 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
970 goto error_of_platform;
974 retval = sa1111_driver_register(&SA1111_DRIVER);
980 retval = pci_register_driver(&PCI_DRIVER);
992 sa1111_driver_unregister(&SA1111_DRIVER);
995 #ifdef OF_PLATFORM_DRIVER
996 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
999 #ifdef PLATFORM_DRIVER
1000 platform_driver_unregister(&PLATFORM_DRIVER);
1003 #ifdef PS3_SYSTEM_BUS_DRIVER
1004 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1005 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1010 module_init(ohci_hcd_mod_init);
1012 static void __exit ohci_hcd_mod_exit(void)
1015 pci_unregister_driver(&PCI_DRIVER);
1017 #ifdef SA1111_DRIVER
1018 sa1111_driver_unregister(&SA1111_DRIVER);
1020 #ifdef OF_PLATFORM_DRIVER
1021 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1023 #ifdef PLATFORM_DRIVER
1024 platform_driver_unregister(&PLATFORM_DRIVER);
1026 #ifdef PS3_SYSTEM_BUS_DRIVER
1027 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1028 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1031 module_exit(ohci_hcd_mod_exit);