2 * Open Host Controller Interface (OHCI) driver for USB.
4 * Maintainer: Alan Stern <stern@rowland.harvard.edu>
6 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
7 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
9 * [ Initialisation is based on Linus' ]
10 * [ uhci code and gregs ohci fragments ]
11 * [ (C) Copyright 1999 Linus Torvalds ]
12 * [ (C) Copyright 1999 Gregory P. Smith]
15 * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
16 * interfaces (though some non-x86 Intel chips use it). It supports
17 * smarter hardware than UHCI. A download link for the spec available
18 * through the http://www.usb.org website.
20 * This file is licenced under the GPL.
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/pci.h>
26 #include <linux/kernel.h>
27 #include <linux/delay.h>
28 #include <linux/ioport.h>
29 #include <linux/sched.h>
30 #include <linux/slab.h>
31 #include <linux/errno.h>
32 #include <linux/init.h>
33 #include <linux/timer.h>
34 #include <linux/list.h>
35 #include <linux/usb.h>
36 #include <linux/usb/otg.h>
37 #include <linux/usb/hcd.h>
38 #include <linux/dma-mapping.h>
39 #include <linux/dmapool.h>
40 #include <linux/workqueue.h>
41 #include <linux/debugfs.h>
45 #include <asm/unaligned.h>
46 #include <asm/byteorder.h>
49 #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
50 #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
52 /*-------------------------------------------------------------------------*/
54 /* For initializing controller (mask in an HCFS mode too) */
55 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
56 #define OHCI_INTR_INIT \
57 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
58 | OHCI_INTR_RD | OHCI_INTR_WDH)
61 /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
65 #ifdef CONFIG_ARCH_OMAP
66 /* OMAP doesn't support IR (no SMM; not needed) */
70 /*-------------------------------------------------------------------------*/
72 static const char hcd_name [] = "ohci_hcd";
74 #define STATECHANGE_DELAY msecs_to_jiffies(300)
77 #include "pci-quirks.h"
79 static void ohci_dump(struct ohci_hcd *ohci);
80 static void ohci_stop(struct usb_hcd *hcd);
89 * On architectures with edge-triggered interrupts we must never return
92 #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
93 #define IRQ_NOTMINE IRQ_HANDLED
95 #define IRQ_NOTMINE IRQ_NONE
99 /* Some boards misreport power switching/overcurrent */
100 static bool distrust_firmware = 1;
101 module_param (distrust_firmware, bool, 0);
102 MODULE_PARM_DESC (distrust_firmware,
103 "true to distrust firmware power/overcurrent setup");
105 /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
106 static bool no_handshake = 0;
107 module_param (no_handshake, bool, 0);
108 MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
110 /*-------------------------------------------------------------------------*/
112 static int number_of_tds(struct urb *urb)
114 int len, i, num, this_sg_len;
115 struct scatterlist *sg;
117 len = urb->transfer_buffer_length;
118 i = urb->num_mapped_sgs;
120 if (len > 0 && i > 0) { /* Scatter-gather transfer */
124 this_sg_len = min_t(int, sg_dma_len(sg), len);
125 num += DIV_ROUND_UP(this_sg_len, 4096);
127 if (--i <= 0 || len <= 0)
132 } else { /* Non-SG transfer */
133 /* one TD for every 4096 Bytes (could be up to 8K) */
134 num = DIV_ROUND_UP(len, 4096);
140 * queue up an urb for anything except the root hub
142 static int ohci_urb_enqueue (
147 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
149 urb_priv_t *urb_priv;
150 unsigned int pipe = urb->pipe;
155 /* every endpoint has a ed, locate and maybe (re)initialize it */
156 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
159 /* for the private part of the URB we need the number of TDs (size) */
162 /* td_submit_urb() doesn't yet handle these */
163 if (urb->transfer_buffer_length > 4096)
166 /* 1 TD for setup, 1 for ACK, plus ... */
169 // case PIPE_INTERRUPT:
172 size += number_of_tds(urb);
173 /* maybe a zero-length packet to wrap it up */
176 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
177 && (urb->transfer_buffer_length
178 % usb_maxpacket (urb->dev, pipe,
179 usb_pipeout (pipe))) == 0)
182 case PIPE_ISOCHRONOUS: /* number of packets from URB */
183 size = urb->number_of_packets;
187 /* allocate the private part of the URB */
188 urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
192 INIT_LIST_HEAD (&urb_priv->pending);
193 urb_priv->length = size;
196 /* allocate the TDs (deferring hash chain updates) */
197 for (i = 0; i < size; i++) {
198 urb_priv->td [i] = td_alloc (ohci, mem_flags);
199 if (!urb_priv->td [i]) {
200 urb_priv->length = i;
201 urb_free_priv (ohci, urb_priv);
206 spin_lock_irqsave (&ohci->lock, flags);
208 /* don't submit to a dead HC */
209 if (!HCD_HW_ACCESSIBLE(hcd)) {
213 if (ohci->rh_state != OHCI_RH_RUNNING) {
217 retval = usb_hcd_link_urb_to_ep(hcd, urb);
221 /* schedule the ed if needed */
222 if (ed->state == ED_IDLE) {
223 retval = ed_schedule (ohci, ed);
225 usb_hcd_unlink_urb_from_ep(hcd, urb);
228 if (ed->type == PIPE_ISOCHRONOUS) {
229 u16 frame = ohci_frame_no(ohci);
231 /* delay a few frames before the first TD */
232 frame += max_t (u16, 8, ed->interval);
233 frame &= ~(ed->interval - 1);
235 urb->start_frame = frame;
236 ed->last_iso = frame + ed->interval * (size - 1);
238 } else if (ed->type == PIPE_ISOCHRONOUS) {
239 u16 next = ohci_frame_no(ohci) + 1;
240 u16 frame = ed->last_iso + ed->interval;
241 u16 length = ed->interval * (size - 1);
243 /* Behind the scheduling threshold? */
244 if (unlikely(tick_before(frame, next))) {
246 /* URB_ISO_ASAP: Round up to the first available slot */
247 if (urb->transfer_flags & URB_ISO_ASAP) {
248 frame += (next - frame + ed->interval - 1) &
252 * Not ASAP: Use the next slot in the stream,
257 * Some OHCI hardware doesn't handle late TDs
258 * correctly. After retiring them it proceeds
259 * to the next ED instead of the next TD.
260 * Therefore we have to omit the late TDs
263 urb_priv->td_cnt = DIV_ROUND_UP(
264 (u16) (next - frame),
266 if (urb_priv->td_cnt >= urb_priv->length) {
267 ++urb_priv->td_cnt; /* Mark it */
268 ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n",
274 urb->start_frame = frame;
275 ed->last_iso = frame + length;
278 /* fill the TDs and link them to the ed; and
279 * enable that part of the schedule, if needed
280 * and update count of queued periodic urbs
282 urb->hcpriv = urb_priv;
283 td_submit_urb (ohci, urb);
287 urb_free_priv (ohci, urb_priv);
288 spin_unlock_irqrestore (&ohci->lock, flags);
293 * decouple the URB from the HC queues (TDs, urb_priv).
294 * reporting is always done
295 * asynchronously, and we might be dealing with an urb that's
296 * partially transferred, or an ED with other urbs being unlinked.
298 static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
300 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
304 spin_lock_irqsave (&ohci->lock, flags);
305 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
308 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
309 urb_priv_t *urb_priv;
311 /* Unless an IRQ completed the unlink while it was being
312 * handed to us, flag it for unlink and giveback, and force
313 * some upcoming INTR_SF to call finish_unlinks()
315 urb_priv = urb->hcpriv;
317 if (urb_priv->ed->state == ED_OPER)
318 start_ed_unlink (ohci, urb_priv->ed);
322 * with HC dead, we won't respect hc queue pointers
323 * any more ... just clean up every urb's memory.
326 finish_urb(ohci, urb, status);
328 spin_unlock_irqrestore (&ohci->lock, flags);
332 /*-------------------------------------------------------------------------*/
334 /* frees config/altsetting state for endpoints,
335 * including ED memory, dummy TD, and bulk/intr data toggle
339 ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
341 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
343 struct ed *ed = ep->hcpriv;
344 unsigned limit = 1000;
346 /* ASSERT: any requests/urbs are being unlinked */
347 /* ASSERT: nobody can be submitting urbs for this any more */
353 spin_lock_irqsave (&ohci->lock, flags);
355 if (ohci->rh_state != OHCI_RH_RUNNING) {
358 finish_unlinks (ohci, 0);
362 case ED_UNLINK: /* wait for hw to finish? */
363 /* major IRQ delivery trouble loses INTR_SF too... */
365 ohci_warn(ohci, "ED unlink timeout\n");
368 spin_unlock_irqrestore (&ohci->lock, flags);
369 schedule_timeout_uninterruptible(1);
371 case ED_IDLE: /* fully unlinked */
372 if (list_empty (&ed->td_list)) {
373 td_free (ohci, ed->dummy);
377 /* else FALL THROUGH */
379 /* caller was supposed to have unlinked any requests;
380 * that's not our job. can't recover; must leak ed.
382 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
383 ed, ep->desc.bEndpointAddress, ed->state,
384 list_empty (&ed->td_list) ? "" : " (has tds)");
385 td_free (ohci, ed->dummy);
389 spin_unlock_irqrestore (&ohci->lock, flags);
392 static int ohci_get_frame (struct usb_hcd *hcd)
394 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
396 return ohci_frame_no(ohci);
399 static void ohci_usb_reset (struct ohci_hcd *ohci)
401 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
402 ohci->hc_control &= OHCI_CTRL_RWC;
403 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
404 ohci->rh_state = OHCI_RH_HALTED;
407 /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
408 * other cases where the next software may expect clean state from the
409 * "firmware". this is bus-neutral, unlike shutdown() methods.
412 ohci_shutdown (struct usb_hcd *hcd)
414 struct ohci_hcd *ohci;
416 ohci = hcd_to_ohci (hcd);
417 ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
419 /* Software reset, after which the controller goes into SUSPEND */
420 ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
421 ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */
424 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
427 /*-------------------------------------------------------------------------*
429 *-------------------------------------------------------------------------*/
431 /* init memory, and kick BIOS/SMM off */
433 static int ohci_init (struct ohci_hcd *ohci)
436 struct usb_hcd *hcd = ohci_to_hcd(ohci);
438 /* Accept arbitrarily long scatter-gather lists */
439 hcd->self.sg_tablesize = ~0;
441 if (distrust_firmware)
442 ohci->flags |= OHCI_QUIRK_HUB_POWER;
444 ohci->rh_state = OHCI_RH_HALTED;
445 ohci->regs = hcd->regs;
447 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
448 * was never needed for most non-PCI systems ... remove the code?
452 /* SMM owns the HC? not for long! */
453 if (!no_handshake && ohci_readl (ohci,
454 &ohci->regs->control) & OHCI_CTRL_IR) {
457 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
459 /* this timeout is arbitrary. we make it long, so systems
460 * depending on usb keyboards may be usable even if the
461 * BIOS/SMM code seems pretty broken.
463 temp = 500; /* arbitrary: five seconds */
465 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
466 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
467 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
470 ohci_err (ohci, "USB HC takeover failed!"
471 " (BIOS/SMM bug)\n");
475 ohci_usb_reset (ohci);
479 /* Disable HC interrupts */
480 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
482 /* flush the writes, and save key bits like RWC */
483 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
484 ohci->hc_control |= OHCI_CTRL_RWC;
486 /* Read the number of ports unless overridden */
487 if (ohci->num_ports == 0)
488 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
493 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
494 sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL);
498 if ((ret = ohci_mem_init (ohci)) < 0)
501 create_debug_files (ohci);
507 /*-------------------------------------------------------------------------*/
509 /* Start an OHCI controller, set the BUS operational
510 * resets USB and controller
513 static int ohci_run (struct ohci_hcd *ohci)
516 int first = ohci->fminterval == 0;
517 struct usb_hcd *hcd = ohci_to_hcd(ohci);
519 ohci->rh_state = OHCI_RH_HALTED;
521 /* boot firmware should have set this up (5.1.1.3.1) */
524 val = ohci_readl (ohci, &ohci->regs->fminterval);
525 ohci->fminterval = val & 0x3fff;
526 if (ohci->fminterval != FI)
527 ohci_dbg (ohci, "fminterval delta %d\n",
528 ohci->fminterval - FI);
529 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
530 /* also: power/overcurrent flags in roothub.a */
533 /* Reset USB nearly "by the book". RemoteWakeupConnected has
534 * to be checked in case boot firmware (BIOS/SMM/...) has set up
535 * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
536 * If the bus glue detected wakeup capability then it should
537 * already be enabled; if so we'll just enable it again.
539 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
540 device_set_wakeup_capable(hcd->self.controller, 1);
542 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
546 case OHCI_USB_SUSPEND:
547 case OHCI_USB_RESUME:
548 ohci->hc_control &= OHCI_CTRL_RWC;
549 ohci->hc_control |= OHCI_USB_RESUME;
550 val = 10 /* msec wait */;
552 // case OHCI_USB_RESET:
554 ohci->hc_control &= OHCI_CTRL_RWC;
555 ohci->hc_control |= OHCI_USB_RESET;
556 val = 50 /* msec wait */;
559 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
561 (void) ohci_readl (ohci, &ohci->regs->control);
564 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
566 /* 2msec timelimit here means no irqs/preempt */
567 spin_lock_irq (&ohci->lock);
570 /* HC Reset requires max 10 us delay */
571 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
572 val = 30; /* ... allow extra time */
573 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
575 spin_unlock_irq (&ohci->lock);
576 ohci_err (ohci, "USB HC reset timed out!\n");
582 /* now we're in the SUSPEND state ... must go OPERATIONAL
583 * within 2msec else HC enters RESUME
585 * ... but some hardware won't init fmInterval "by the book"
586 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
587 * this if we write fmInterval after we're OPERATIONAL.
588 * Unclear about ALi, ServerWorks, and others ... this could
589 * easily be a longstanding bug in chip init on Linux.
591 if (ohci->flags & OHCI_QUIRK_INITRESET) {
592 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
593 // flush those writes
594 (void) ohci_readl (ohci, &ohci->regs->control);
597 /* Tell the controller where the control and bulk lists are
598 * The lists are empty now. */
599 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
600 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
602 /* a reset clears this */
603 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
605 periodic_reinit (ohci);
607 /* some OHCI implementations are finicky about how they init.
608 * bogus values here mean not even enumeration could work.
610 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
611 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
612 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
613 ohci->flags |= OHCI_QUIRK_INITRESET;
614 ohci_dbg (ohci, "enabling initreset quirk\n");
617 spin_unlock_irq (&ohci->lock);
618 ohci_err (ohci, "init err (%08x %04x)\n",
619 ohci_readl (ohci, &ohci->regs->fminterval),
620 ohci_readl (ohci, &ohci->regs->periodicstart));
624 /* use rhsc irqs after khubd is fully initialized */
625 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
626 hcd->uses_new_polling = 1;
628 /* start controller operations */
629 ohci->hc_control &= OHCI_CTRL_RWC;
630 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
631 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
632 ohci->rh_state = OHCI_RH_RUNNING;
634 /* wake on ConnectStatusChange, matching external hubs */
635 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
637 /* Choose the interrupts we care about now, others later on demand */
638 mask = OHCI_INTR_INIT;
639 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
640 ohci_writel (ohci, mask, &ohci->regs->intrenable);
642 /* handle root hub init quirks ... */
643 val = roothub_a (ohci);
644 val &= ~(RH_A_PSM | RH_A_OCPM);
645 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
646 /* NSC 87560 and maybe others */
648 val &= ~(RH_A_POTPGT | RH_A_NPS);
649 ohci_writel (ohci, val, &ohci->regs->roothub.a);
650 } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
651 (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
652 /* hub power always on; required for AMD-756 and some
653 * Mac platforms. ganged overcurrent reporting, if any.
656 ohci_writel (ohci, val, &ohci->regs->roothub.a);
658 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
659 ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
660 &ohci->regs->roothub.b);
661 // flush those writes
662 (void) ohci_readl (ohci, &ohci->regs->control);
664 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
665 spin_unlock_irq (&ohci->lock);
667 // POTPGT delay is bits 24-31, in 2 ms units.
668 mdelay ((val >> 23) & 0x1fe);
675 /* ohci_setup routine for generic controller initialization */
677 int ohci_setup(struct usb_hcd *hcd)
679 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
683 return ohci_init(ohci);
685 EXPORT_SYMBOL_GPL(ohci_setup);
687 /* ohci_start routine for generic controller start of all OHCI bus glue */
688 static int ohci_start(struct usb_hcd *hcd)
690 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
693 ret = ohci_run(ohci);
695 ohci_err(ohci, "can't start\n");
701 /*-------------------------------------------------------------------------*/
703 /* an interrupt happens */
705 static irqreturn_t ohci_irq (struct usb_hcd *hcd)
707 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
708 struct ohci_regs __iomem *regs = ohci->regs;
711 /* Read interrupt status (and flush pending writes). We ignore the
712 * optimization of checking the LSB of hcca->done_head; it doesn't
713 * work on all systems (edge triggering for OHCI can be a factor).
715 ints = ohci_readl(ohci, ®s->intrstatus);
717 /* Check for an all 1's result which is a typical consequence
718 * of dead, unclocked, or unplugged (CardBus...) devices
720 if (ints == ~(u32)0) {
721 ohci->rh_state = OHCI_RH_HALTED;
722 ohci_dbg (ohci, "device removed!\n");
727 /* We only care about interrupts that are enabled */
728 ints &= ohci_readl(ohci, ®s->intrenable);
730 /* interrupt for some other device? */
731 if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
734 if (ints & OHCI_INTR_UE) {
735 // e.g. due to PCI Master/Target Abort
736 if (quirk_nec(ohci)) {
737 /* Workaround for a silicon bug in some NEC chips used
738 * in Apple's PowerBooks. Adapted from Darwin code.
740 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
742 ohci_writel (ohci, OHCI_INTR_UE, ®s->intrdisable);
744 schedule_work (&ohci->nec_work);
746 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
747 ohci->rh_state = OHCI_RH_HALTED;
752 ohci_usb_reset (ohci);
755 if (ints & OHCI_INTR_RHSC) {
756 ohci_dbg(ohci, "rhsc\n");
757 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
758 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
761 /* NOTE: Vendors didn't always make the same implementation
762 * choices for RHSC. Many followed the spec; RHSC triggers
763 * on an edge, like setting and maybe clearing a port status
764 * change bit. With others it's level-triggered, active
765 * until khubd clears all the port status change bits. We'll
766 * always disable it here and rely on polling until khubd
769 ohci_writel(ohci, OHCI_INTR_RHSC, ®s->intrdisable);
770 usb_hcd_poll_rh_status(hcd);
773 /* For connect and disconnect events, we expect the controller
774 * to turn on RHSC along with RD. But for remote wakeup events
775 * this might not happen.
777 else if (ints & OHCI_INTR_RD) {
778 ohci_dbg(ohci, "resume detect\n");
779 ohci_writel(ohci, OHCI_INTR_RD, ®s->intrstatus);
780 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
781 if (ohci->autostop) {
782 spin_lock (&ohci->lock);
783 ohci_rh_resume (ohci);
784 spin_unlock (&ohci->lock);
786 usb_hcd_resume_root_hub(hcd);
789 if (ints & OHCI_INTR_WDH) {
790 spin_lock (&ohci->lock);
792 spin_unlock (&ohci->lock);
795 /* could track INTR_SO to reduce available PCI/... bandwidth */
797 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
798 * when there's still unlinking to be done (next frame).
800 spin_lock (&ohci->lock);
801 if (ohci->ed_rm_list)
802 finish_unlinks (ohci, ohci_frame_no(ohci));
803 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
804 && ohci->rh_state == OHCI_RH_RUNNING)
805 ohci_writel (ohci, OHCI_INTR_SF, ®s->intrdisable);
806 spin_unlock (&ohci->lock);
808 if (ohci->rh_state == OHCI_RH_RUNNING) {
809 ohci_writel (ohci, ints, ®s->intrstatus);
810 ohci_writel (ohci, OHCI_INTR_MIE, ®s->intrenable);
811 // flush those writes
812 (void) ohci_readl (ohci, &ohci->regs->control);
818 /*-------------------------------------------------------------------------*/
820 static void ohci_stop (struct usb_hcd *hcd)
822 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
827 flush_work(&ohci->nec_work);
829 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
830 ohci_usb_reset(ohci);
831 free_irq(hcd->irq, hcd);
834 if (quirk_amdiso(ohci))
837 remove_debug_files (ohci);
838 ohci_mem_cleanup (ohci);
840 dma_free_coherent (hcd->self.controller,
842 ohci->hcca, ohci->hcca_dma);
848 /*-------------------------------------------------------------------------*/
850 #if defined(CONFIG_PM) || defined(CONFIG_PCI)
852 /* must not be called from interrupt context */
853 int ohci_restart(struct ohci_hcd *ohci)
857 struct urb_priv *priv;
860 spin_lock_irq(&ohci->lock);
861 ohci->rh_state = OHCI_RH_HALTED;
863 /* Recycle any "live" eds/tds (and urbs). */
864 if (!list_empty (&ohci->pending))
865 ohci_dbg(ohci, "abort schedule...\n");
866 list_for_each_entry (priv, &ohci->pending, pending) {
867 struct urb *urb = priv->td[0]->urb;
868 struct ed *ed = priv->ed;
872 ed->state = ED_UNLINK;
873 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
874 ed_deschedule (ohci, ed);
876 ed->ed_next = ohci->ed_rm_list;
878 ohci->ed_rm_list = ed;
883 ohci_dbg(ohci, "bogus ed %p state %d\n",
888 urb->unlinked = -ESHUTDOWN;
890 finish_unlinks (ohci, 0);
891 spin_unlock_irq(&ohci->lock);
893 /* paranoia, in case that didn't work: */
895 /* empty the interrupt branches */
896 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
897 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
899 /* no EDs to remove */
900 ohci->ed_rm_list = NULL;
902 /* empty control and bulk lists */
903 ohci->ed_controltail = NULL;
904 ohci->ed_bulktail = NULL;
906 if ((temp = ohci_run (ohci)) < 0) {
907 ohci_err (ohci, "can't restart, %d\n", temp);
910 ohci_dbg(ohci, "restart complete\n");
913 EXPORT_SYMBOL_GPL(ohci_restart);
919 int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
921 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
925 /* Disable irq emission and mark HW unaccessible. Use
926 * the spinlock to properly synchronize with possible pending
927 * RH suspend or resume activity.
929 spin_lock_irqsave (&ohci->lock, flags);
930 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
931 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
933 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
934 spin_unlock_irqrestore (&ohci->lock, flags);
936 synchronize_irq(hcd->irq);
938 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
939 ohci_resume(hcd, false);
944 EXPORT_SYMBOL_GPL(ohci_suspend);
947 int ohci_resume(struct usb_hcd *hcd, bool hibernated)
949 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
951 bool need_reinit = false;
953 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
955 /* Make sure resume from hibernation re-enumerates everything */
957 ohci_usb_reset(ohci);
959 /* See if the controller is already running or has been reset */
960 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
961 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
964 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
971 /* If needed, reinitialize and suspend the root hub */
973 spin_lock_irq(&ohci->lock);
974 ohci_rh_resume(ohci);
975 ohci_rh_suspend(ohci, 0);
976 spin_unlock_irq(&ohci->lock);
979 /* Normally just turn on port power and enable interrupts */
981 ohci_dbg(ohci, "powerup ports\n");
982 for (port = 0; port < ohci->num_ports; port++)
983 ohci_writel(ohci, RH_PS_PPS,
984 &ohci->regs->roothub.portstatus[port]);
986 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
987 ohci_readl(ohci, &ohci->regs->intrenable);
991 usb_hcd_resume_root_hub(hcd);
995 EXPORT_SYMBOL_GPL(ohci_resume);
999 /*-------------------------------------------------------------------------*/
1002 * Generic structure: This gets copied for platform drivers so that
1003 * individual entries can be overridden as needed.
1006 static const struct hc_driver ohci_hc_driver = {
1007 .description = hcd_name,
1008 .product_desc = "OHCI Host Controller",
1009 .hcd_priv_size = sizeof(struct ohci_hcd),
1012 * generic hardware linkage
1015 .flags = HCD_MEMORY | HCD_USB11,
1018 * basic lifecycle operations
1020 .reset = ohci_setup,
1021 .start = ohci_start,
1023 .shutdown = ohci_shutdown,
1026 * managing i/o requests and associated device resources
1028 .urb_enqueue = ohci_urb_enqueue,
1029 .urb_dequeue = ohci_urb_dequeue,
1030 .endpoint_disable = ohci_endpoint_disable,
1033 * scheduling support
1035 .get_frame_number = ohci_get_frame,
1040 .hub_status_data = ohci_hub_status_data,
1041 .hub_control = ohci_hub_control,
1043 .bus_suspend = ohci_bus_suspend,
1044 .bus_resume = ohci_bus_resume,
1046 .start_port_reset = ohci_start_port_reset,
1049 void ohci_init_driver(struct hc_driver *drv,
1050 const struct ohci_driver_overrides *over)
1052 /* Copy the generic table to drv and then apply the overrides */
1053 *drv = ohci_hc_driver;
1056 drv->product_desc = over->product_desc;
1057 drv->hcd_priv_size += over->extra_priv_size;
1059 drv->reset = over->reset;
1062 EXPORT_SYMBOL_GPL(ohci_init_driver);
1064 /*-------------------------------------------------------------------------*/
1066 MODULE_AUTHOR (DRIVER_AUTHOR);
1067 MODULE_DESCRIPTION(DRIVER_DESC);
1068 MODULE_LICENSE ("GPL");
1070 #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
1071 #include "ohci-sa1111.c"
1072 #define SA1111_DRIVER ohci_hcd_sa1111_driver
1075 #ifdef CONFIG_USB_OHCI_HCD_DAVINCI
1076 #include "ohci-da8xx.c"
1077 #define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
1080 #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1081 #include "ohci-ppc-of.c"
1082 #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1085 #ifdef CONFIG_PPC_PS3
1086 #include "ohci-ps3.c"
1087 #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
1090 #ifdef CONFIG_MFD_SM501
1091 #include "ohci-sm501.c"
1092 #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
1095 #ifdef CONFIG_MFD_TC6393XB
1096 #include "ohci-tmio.c"
1097 #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
1100 #ifdef CONFIG_MACH_JZ4740
1101 #include "ohci-jz4740.c"
1102 #define PLATFORM_DRIVER ohci_hcd_jz4740_driver
1105 #ifdef CONFIG_USB_OCTEON_OHCI
1106 #include "ohci-octeon.c"
1107 #define PLATFORM_DRIVER ohci_octeon_driver
1110 #ifdef CONFIG_TILE_USB
1111 #include "ohci-tilegx.c"
1112 #define PLATFORM_DRIVER ohci_hcd_tilegx_driver
1115 static int __init ohci_hcd_mod_init(void)
1122 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
1123 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1124 sizeof (struct ed), sizeof (struct td));
1125 set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
1127 ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
1128 if (!ohci_debug_root) {
1133 #ifdef PS3_SYSTEM_BUS_DRIVER
1134 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1139 #ifdef PLATFORM_DRIVER
1140 retval = platform_driver_register(&PLATFORM_DRIVER);
1142 goto error_platform;
1145 #ifdef OF_PLATFORM_DRIVER
1146 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1148 goto error_of_platform;
1151 #ifdef SA1111_DRIVER
1152 retval = sa1111_driver_register(&SA1111_DRIVER);
1157 #ifdef SM501_OHCI_DRIVER
1158 retval = platform_driver_register(&SM501_OHCI_DRIVER);
1163 #ifdef TMIO_OHCI_DRIVER
1164 retval = platform_driver_register(&TMIO_OHCI_DRIVER);
1169 #ifdef DAVINCI_PLATFORM_DRIVER
1170 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
1178 #ifdef DAVINCI_PLATFORM_DRIVER
1179 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1182 #ifdef TMIO_OHCI_DRIVER
1183 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1186 #ifdef SM501_OHCI_DRIVER
1187 platform_driver_unregister(&SM501_OHCI_DRIVER);
1190 #ifdef SA1111_DRIVER
1191 sa1111_driver_unregister(&SA1111_DRIVER);
1194 #ifdef OF_PLATFORM_DRIVER
1195 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1198 #ifdef PLATFORM_DRIVER
1199 platform_driver_unregister(&PLATFORM_DRIVER);
1202 #ifdef PS3_SYSTEM_BUS_DRIVER
1203 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1206 debugfs_remove(ohci_debug_root);
1207 ohci_debug_root = NULL;
1210 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
1213 module_init(ohci_hcd_mod_init);
1215 static void __exit ohci_hcd_mod_exit(void)
1217 #ifdef DAVINCI_PLATFORM_DRIVER
1218 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1220 #ifdef TMIO_OHCI_DRIVER
1221 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1223 #ifdef SM501_OHCI_DRIVER
1224 platform_driver_unregister(&SM501_OHCI_DRIVER);
1226 #ifdef SA1111_DRIVER
1227 sa1111_driver_unregister(&SA1111_DRIVER);
1229 #ifdef OF_PLATFORM_DRIVER
1230 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1232 #ifdef PLATFORM_DRIVER
1233 platform_driver_unregister(&PLATFORM_DRIVER);
1235 #ifdef PS3_SYSTEM_BUS_DRIVER
1236 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1238 debugfs_remove(ohci_debug_root);
1239 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
1241 module_exit(ohci_hcd_mod_exit);