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 "../core/hcd.h"
48 #define DRIVER_VERSION "2006 August 04"
49 #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
50 #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
52 /*-------------------------------------------------------------------------*/
54 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
56 /* For initializing controller (mask in an HCFS mode too) */
57 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
58 #define OHCI_INTR_INIT \
59 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
60 | OHCI_INTR_RD | OHCI_INTR_WDH)
63 /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
67 #ifdef CONFIG_ARCH_OMAP
68 /* OMAP doesn't support IR (no SMM; not needed) */
72 /*-------------------------------------------------------------------------*/
74 static const char hcd_name
[] = "ohci_hcd";
76 #define STATECHANGE_DELAY msecs_to_jiffies(300)
80 static void ohci_dump (struct ohci_hcd
*ohci
, int verbose
);
81 static int ohci_init (struct ohci_hcd
*ohci
);
82 static void ohci_stop (struct usb_hcd
*hcd
);
83 static int ohci_restart (struct ohci_hcd
*ohci
);
92 * On architectures with edge-triggered interrupts we must never return
95 #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
96 #define IRQ_NOTMINE IRQ_HANDLED
98 #define IRQ_NOTMINE IRQ_NONE
102 /* Some boards misreport power switching/overcurrent */
103 static int distrust_firmware
= 1;
104 module_param (distrust_firmware
, bool, 0);
105 MODULE_PARM_DESC (distrust_firmware
,
106 "true to distrust firmware power/overcurrent setup");
108 /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
109 static int no_handshake
= 0;
110 module_param (no_handshake
, bool, 0);
111 MODULE_PARM_DESC (no_handshake
, "true (not default) disables BIOS handshake");
113 /*-------------------------------------------------------------------------*/
116 * queue up an urb for anything except the root hub
118 static int ohci_urb_enqueue (
123 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
125 urb_priv_t
*urb_priv
;
126 unsigned int pipe
= urb
->pipe
;
131 #ifdef OHCI_VERBOSE_DEBUG
132 urb_print(urb
, "SUB", usb_pipein(pipe
), -EINPROGRESS
);
135 /* every endpoint has a ed, locate and maybe (re)initialize it */
136 if (! (ed
= ed_get (ohci
, urb
->ep
, urb
->dev
, pipe
, urb
->interval
)))
139 /* for the private part of the URB we need the number of TDs (size) */
142 /* td_submit_urb() doesn't yet handle these */
143 if (urb
->transfer_buffer_length
> 4096)
146 /* 1 TD for setup, 1 for ACK, plus ... */
149 // case PIPE_INTERRUPT:
152 /* one TD for every 4096 Bytes (can be upto 8K) */
153 size
+= urb
->transfer_buffer_length
/ 4096;
154 /* ... and for any remaining bytes ... */
155 if ((urb
->transfer_buffer_length
% 4096) != 0)
157 /* ... and maybe a zero length packet to wrap it up */
160 else if ((urb
->transfer_flags
& URB_ZERO_PACKET
) != 0
161 && (urb
->transfer_buffer_length
162 % usb_maxpacket (urb
->dev
, pipe
,
163 usb_pipeout (pipe
))) == 0)
166 case PIPE_ISOCHRONOUS
: /* number of packets from URB */
167 size
= urb
->number_of_packets
;
171 /* allocate the private part of the URB */
172 urb_priv
= kzalloc (sizeof (urb_priv_t
) + size
* sizeof (struct td
*),
176 INIT_LIST_HEAD (&urb_priv
->pending
);
177 urb_priv
->length
= size
;
180 /* allocate the TDs (deferring hash chain updates) */
181 for (i
= 0; i
< size
; i
++) {
182 urb_priv
->td
[i
] = td_alloc (ohci
, mem_flags
);
183 if (!urb_priv
->td
[i
]) {
184 urb_priv
->length
= i
;
185 urb_free_priv (ohci
, urb_priv
);
190 spin_lock_irqsave (&ohci
->lock
, flags
);
192 /* don't submit to a dead HC */
193 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)) {
197 if (!HC_IS_RUNNING(hcd
->state
)) {
201 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
205 /* schedule the ed if needed */
206 if (ed
->state
== ED_IDLE
) {
207 retval
= ed_schedule (ohci
, ed
);
209 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
212 if (ed
->type
== PIPE_ISOCHRONOUS
) {
213 u16 frame
= ohci_frame_no(ohci
);
215 /* delay a few frames before the first TD */
216 frame
+= max_t (u16
, 8, ed
->interval
);
217 frame
&= ~(ed
->interval
- 1);
219 urb
->start_frame
= frame
;
221 /* yes, only URB_ISO_ASAP is supported, and
222 * urb->start_frame is never used as input.
225 } else if (ed
->type
== PIPE_ISOCHRONOUS
)
226 urb
->start_frame
= ed
->last_iso
+ ed
->interval
;
228 /* fill the TDs and link them to the ed; and
229 * enable that part of the schedule, if needed
230 * and update count of queued periodic urbs
232 urb
->hcpriv
= urb_priv
;
233 td_submit_urb (ohci
, urb
);
237 urb_free_priv (ohci
, urb_priv
);
238 spin_unlock_irqrestore (&ohci
->lock
, flags
);
243 * decouple the URB from the HC queues (TDs, urb_priv).
244 * reporting is always done
245 * asynchronously, and we might be dealing with an urb that's
246 * partially transferred, or an ED with other urbs being unlinked.
248 static int ohci_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
, int status
)
250 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
254 #ifdef OHCI_VERBOSE_DEBUG
255 urb_print(urb
, "UNLINK", 1, status
);
258 spin_lock_irqsave (&ohci
->lock
, flags
);
259 rc
= usb_hcd_check_unlink_urb(hcd
, urb
, status
);
262 } else if (HC_IS_RUNNING(hcd
->state
)) {
263 urb_priv_t
*urb_priv
;
265 /* Unless an IRQ completed the unlink while it was being
266 * handed to us, flag it for unlink and giveback, and force
267 * some upcoming INTR_SF to call finish_unlinks()
269 urb_priv
= urb
->hcpriv
;
271 if (urb_priv
->ed
->state
== ED_OPER
)
272 start_ed_unlink (ohci
, urb_priv
->ed
);
276 * with HC dead, we won't respect hc queue pointers
277 * any more ... just clean up every urb's memory.
280 finish_urb(ohci
, urb
, status
);
282 spin_unlock_irqrestore (&ohci
->lock
, flags
);
286 /*-------------------------------------------------------------------------*/
288 /* frees config/altsetting state for endpoints,
289 * including ED memory, dummy TD, and bulk/intr data toggle
293 ohci_endpoint_disable (struct usb_hcd
*hcd
, struct usb_host_endpoint
*ep
)
295 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
297 struct ed
*ed
= ep
->hcpriv
;
298 unsigned limit
= 1000;
300 /* ASSERT: any requests/urbs are being unlinked */
301 /* ASSERT: nobody can be submitting urbs for this any more */
307 spin_lock_irqsave (&ohci
->lock
, flags
);
309 if (!HC_IS_RUNNING (hcd
->state
)) {
312 if (quirk_zfmicro(ohci
) && ed
->type
== PIPE_INTERRUPT
)
313 ohci
->eds_scheduled
--;
314 finish_unlinks (ohci
, 0);
318 case ED_UNLINK
: /* wait for hw to finish? */
319 /* major IRQ delivery trouble loses INTR_SF too... */
321 ohci_warn(ohci
, "ED unlink timeout\n");
322 if (quirk_zfmicro(ohci
)) {
323 ohci_warn(ohci
, "Attempting ZF TD recovery\n");
324 ohci
->ed_to_check
= ed
;
329 spin_unlock_irqrestore (&ohci
->lock
, flags
);
330 schedule_timeout_uninterruptible(1);
332 case ED_IDLE
: /* fully unlinked */
333 if (list_empty (&ed
->td_list
)) {
334 td_free (ohci
, ed
->dummy
);
338 /* else FALL THROUGH */
340 /* caller was supposed to have unlinked any requests;
341 * that's not our job. can't recover; must leak ed.
343 ohci_err (ohci
, "leak ed %p (#%02x) state %d%s\n",
344 ed
, ep
->desc
.bEndpointAddress
, ed
->state
,
345 list_empty (&ed
->td_list
) ? "" : " (has tds)");
346 td_free (ohci
, ed
->dummy
);
350 spin_unlock_irqrestore (&ohci
->lock
, flags
);
354 static int ohci_get_frame (struct usb_hcd
*hcd
)
356 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
358 return ohci_frame_no(ohci
);
361 static void ohci_usb_reset (struct ohci_hcd
*ohci
)
363 ohci
->hc_control
= ohci_readl (ohci
, &ohci
->regs
->control
);
364 ohci
->hc_control
&= OHCI_CTRL_RWC
;
365 ohci_writel (ohci
, ohci
->hc_control
, &ohci
->regs
->control
);
368 /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
369 * other cases where the next software may expect clean state from the
370 * "firmware". this is bus-neutral, unlike shutdown() methods.
373 ohci_shutdown (struct usb_hcd
*hcd
)
375 struct ohci_hcd
*ohci
;
377 ohci
= hcd_to_ohci (hcd
);
378 ohci_writel (ohci
, OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
379 ohci_usb_reset (ohci
);
380 /* flush the writes */
381 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
384 static int check_ed(struct ohci_hcd
*ohci
, struct ed
*ed
)
386 return (hc32_to_cpu(ohci
, ed
->hwINFO
) & ED_IN
) != 0
387 && (hc32_to_cpu(ohci
, ed
->hwHeadP
) & TD_MASK
)
388 == (hc32_to_cpu(ohci
, ed
->hwTailP
) & TD_MASK
)
389 && !list_empty(&ed
->td_list
);
392 /* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
393 * an interrupt TD but neglects to add it to the donelist. On systems with
394 * this chipset, we need to periodically check the state of the queues to look
395 * for such "lost" TDs.
397 static void unlink_watchdog_func(unsigned long _ohci
)
401 unsigned seen_count
= 0;
403 struct ed
**seen
= NULL
;
404 struct ohci_hcd
*ohci
= (struct ohci_hcd
*) _ohci
;
406 spin_lock_irqsave(&ohci
->lock
, flags
);
407 max
= ohci
->eds_scheduled
;
411 if (ohci
->ed_to_check
)
414 seen
= kcalloc(max
, sizeof *seen
, GFP_ATOMIC
);
418 for (i
= 0; i
< NUM_INTS
; i
++) {
419 struct ed
*ed
= ohci
->periodic
[i
];
424 /* scan this branch of the periodic schedule tree */
425 for (temp
= 0; temp
< seen_count
; temp
++) {
426 if (seen
[temp
] == ed
) {
427 /* we've checked it and what's after */
434 seen
[seen_count
++] = ed
;
435 if (!check_ed(ohci
, ed
)) {
440 /* HC's TD list is empty, but HCD sees at least one
441 * TD that's not been sent through the donelist.
443 ohci
->ed_to_check
= ed
;
446 /* The HC may wait until the next frame to report the
447 * TD as done through the donelist and INTR_WDH. (We
448 * just *assume* it's not a multi-TD interrupt URB;
449 * those could defer the IRQ more than one frame, using
450 * DI...) Check again after the next INTR_SF.
452 ohci_writel(ohci
, OHCI_INTR_SF
,
453 &ohci
->regs
->intrstatus
);
454 ohci_writel(ohci
, OHCI_INTR_SF
,
455 &ohci
->regs
->intrenable
);
457 /* flush those writes */
458 (void) ohci_readl(ohci
, &ohci
->regs
->control
);
465 if (ohci
->eds_scheduled
)
466 mod_timer(&ohci
->unlink_watchdog
, round_jiffies_relative(HZ
));
468 spin_unlock_irqrestore(&ohci
->lock
, flags
);
471 /*-------------------------------------------------------------------------*
473 *-------------------------------------------------------------------------*/
475 /* init memory, and kick BIOS/SMM off */
477 static int ohci_init (struct ohci_hcd
*ohci
)
480 struct usb_hcd
*hcd
= ohci_to_hcd(ohci
);
483 ohci
->regs
= hcd
->regs
;
485 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
486 * was never needed for most non-PCI systems ... remove the code?
490 /* SMM owns the HC? not for long! */
491 if (!no_handshake
&& ohci_readl (ohci
,
492 &ohci
->regs
->control
) & OHCI_CTRL_IR
) {
495 ohci_dbg (ohci
, "USB HC TakeOver from BIOS/SMM\n");
497 /* this timeout is arbitrary. we make it long, so systems
498 * depending on usb keyboards may be usable even if the
499 * BIOS/SMM code seems pretty broken.
501 temp
= 500; /* arbitrary: five seconds */
503 ohci_writel (ohci
, OHCI_INTR_OC
, &ohci
->regs
->intrenable
);
504 ohci_writel (ohci
, OHCI_OCR
, &ohci
->regs
->cmdstatus
);
505 while (ohci_readl (ohci
, &ohci
->regs
->control
) & OHCI_CTRL_IR
) {
508 ohci_err (ohci
, "USB HC takeover failed!"
509 " (BIOS/SMM bug)\n");
513 ohci_usb_reset (ohci
);
517 /* Disable HC interrupts */
518 ohci_writel (ohci
, OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
520 /* flush the writes, and save key bits like RWC */
521 if (ohci_readl (ohci
, &ohci
->regs
->control
) & OHCI_CTRL_RWC
)
522 ohci
->hc_control
|= OHCI_CTRL_RWC
;
524 /* Read the number of ports unless overridden */
525 if (ohci
->num_ports
== 0)
526 ohci
->num_ports
= roothub_a(ohci
) & RH_A_NDP
;
531 ohci
->hcca
= dma_alloc_coherent (hcd
->self
.controller
,
532 sizeof *ohci
->hcca
, &ohci
->hcca_dma
, 0);
536 if ((ret
= ohci_mem_init (ohci
)) < 0)
539 create_debug_files (ohci
);
545 /*-------------------------------------------------------------------------*/
547 /* Start an OHCI controller, set the BUS operational
548 * resets USB and controller
551 static int ohci_run (struct ohci_hcd
*ohci
)
554 int first
= ohci
->fminterval
== 0;
555 struct usb_hcd
*hcd
= ohci_to_hcd(ohci
);
559 /* boot firmware should have set this up (5.1.1.3.1) */
562 temp
= ohci_readl (ohci
, &ohci
->regs
->fminterval
);
563 ohci
->fminterval
= temp
& 0x3fff;
564 if (ohci
->fminterval
!= FI
)
565 ohci_dbg (ohci
, "fminterval delta %d\n",
566 ohci
->fminterval
- FI
);
567 ohci
->fminterval
|= FSMP (ohci
->fminterval
) << 16;
568 /* also: power/overcurrent flags in roothub.a */
571 /* Reset USB nearly "by the book". RemoteWakeupConnected was
572 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
573 * or if bus glue did the same (e.g. for PCI add-in cards with
576 if ((ohci
->hc_control
& OHCI_CTRL_RWC
) != 0
577 && !device_may_wakeup(hcd
->self
.controller
))
578 device_init_wakeup(hcd
->self
.controller
, 1);
580 switch (ohci
->hc_control
& OHCI_CTRL_HCFS
) {
584 case OHCI_USB_SUSPEND
:
585 case OHCI_USB_RESUME
:
586 ohci
->hc_control
&= OHCI_CTRL_RWC
;
587 ohci
->hc_control
|= OHCI_USB_RESUME
;
588 temp
= 10 /* msec wait */;
590 // case OHCI_USB_RESET:
592 ohci
->hc_control
&= OHCI_CTRL_RWC
;
593 ohci
->hc_control
|= OHCI_USB_RESET
;
594 temp
= 50 /* msec wait */;
597 ohci_writel (ohci
, ohci
->hc_control
, &ohci
->regs
->control
);
599 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
602 memset (ohci
->hcca
, 0, sizeof (struct ohci_hcca
));
604 /* 2msec timelimit here means no irqs/preempt */
605 spin_lock_irq (&ohci
->lock
);
608 /* HC Reset requires max 10 us delay */
609 ohci_writel (ohci
, OHCI_HCR
, &ohci
->regs
->cmdstatus
);
610 temp
= 30; /* ... allow extra time */
611 while ((ohci_readl (ohci
, &ohci
->regs
->cmdstatus
) & OHCI_HCR
) != 0) {
613 spin_unlock_irq (&ohci
->lock
);
614 ohci_err (ohci
, "USB HC reset timed out!\n");
620 /* now we're in the SUSPEND state ... must go OPERATIONAL
621 * within 2msec else HC enters RESUME
623 * ... but some hardware won't init fmInterval "by the book"
624 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
625 * this if we write fmInterval after we're OPERATIONAL.
626 * Unclear about ALi, ServerWorks, and others ... this could
627 * easily be a longstanding bug in chip init on Linux.
629 if (ohci
->flags
& OHCI_QUIRK_INITRESET
) {
630 ohci_writel (ohci
, ohci
->hc_control
, &ohci
->regs
->control
);
631 // flush those writes
632 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
635 /* Tell the controller where the control and bulk lists are
636 * The lists are empty now. */
637 ohci_writel (ohci
, 0, &ohci
->regs
->ed_controlhead
);
638 ohci_writel (ohci
, 0, &ohci
->regs
->ed_bulkhead
);
640 /* a reset clears this */
641 ohci_writel (ohci
, (u32
) ohci
->hcca_dma
, &ohci
->regs
->hcca
);
643 periodic_reinit (ohci
);
645 /* some OHCI implementations are finicky about how they init.
646 * bogus values here mean not even enumeration could work.
648 if ((ohci_readl (ohci
, &ohci
->regs
->fminterval
) & 0x3fff0000) == 0
649 || !ohci_readl (ohci
, &ohci
->regs
->periodicstart
)) {
650 if (!(ohci
->flags
& OHCI_QUIRK_INITRESET
)) {
651 ohci
->flags
|= OHCI_QUIRK_INITRESET
;
652 ohci_dbg (ohci
, "enabling initreset quirk\n");
655 spin_unlock_irq (&ohci
->lock
);
656 ohci_err (ohci
, "init err (%08x %04x)\n",
657 ohci_readl (ohci
, &ohci
->regs
->fminterval
),
658 ohci_readl (ohci
, &ohci
->regs
->periodicstart
));
662 /* use rhsc irqs after khubd is fully initialized */
664 hcd
->uses_new_polling
= 1;
666 /* start controller operations */
667 ohci
->hc_control
&= OHCI_CTRL_RWC
;
668 ohci
->hc_control
|= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
669 ohci_writel (ohci
, ohci
->hc_control
, &ohci
->regs
->control
);
670 hcd
->state
= HC_STATE_RUNNING
;
672 /* wake on ConnectStatusChange, matching external hubs */
673 ohci_writel (ohci
, RH_HS_DRWE
, &ohci
->regs
->roothub
.status
);
675 /* Choose the interrupts we care about now, others later on demand */
676 mask
= OHCI_INTR_INIT
;
677 ohci_writel (ohci
, ~0, &ohci
->regs
->intrstatus
);
678 ohci_writel (ohci
, mask
, &ohci
->regs
->intrenable
);
680 /* handle root hub init quirks ... */
681 temp
= roothub_a (ohci
);
682 temp
&= ~(RH_A_PSM
| RH_A_OCPM
);
683 if (ohci
->flags
& OHCI_QUIRK_SUPERIO
) {
684 /* NSC 87560 and maybe others */
686 temp
&= ~(RH_A_POTPGT
| RH_A_NPS
);
687 ohci_writel (ohci
, temp
, &ohci
->regs
->roothub
.a
);
688 } else if ((ohci
->flags
& OHCI_QUIRK_AMD756
) || distrust_firmware
) {
689 /* hub power always on; required for AMD-756 and some
690 * Mac platforms. ganged overcurrent reporting, if any.
693 ohci_writel (ohci
, temp
, &ohci
->regs
->roothub
.a
);
695 ohci_writel (ohci
, RH_HS_LPSC
, &ohci
->regs
->roothub
.status
);
696 ohci_writel (ohci
, (temp
& RH_A_NPS
) ? 0 : RH_B_PPCM
,
697 &ohci
->regs
->roothub
.b
);
698 // flush those writes
699 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
701 ohci
->next_statechange
= jiffies
+ STATECHANGE_DELAY
;
702 spin_unlock_irq (&ohci
->lock
);
704 // POTPGT delay is bits 24-31, in 2 ms units.
705 mdelay ((temp
>> 23) & 0x1fe);
706 hcd
->state
= HC_STATE_RUNNING
;
708 if (quirk_zfmicro(ohci
)) {
709 /* Create timer to watch for bad queue state on ZF Micro */
710 setup_timer(&ohci
->unlink_watchdog
, unlink_watchdog_func
,
711 (unsigned long) ohci
);
713 ohci
->eds_scheduled
= 0;
714 ohci
->ed_to_check
= NULL
;
722 /*-------------------------------------------------------------------------*/
724 /* an interrupt happens */
726 static irqreturn_t
ohci_irq (struct usb_hcd
*hcd
)
728 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
729 struct ohci_regs __iomem
*regs
= ohci
->regs
;
732 /* we can eliminate a (slow) ohci_readl()
733 * if _only_ WDH caused this irq
735 if ((ohci
->hcca
->done_head
!= 0)
736 && ! (hc32_to_cpup (ohci
, &ohci
->hcca
->done_head
)
738 ints
= OHCI_INTR_WDH
;
740 /* cardbus/... hardware gone before remove() */
741 } else if ((ints
= ohci_readl (ohci
, ®s
->intrstatus
)) == ~(u32
)0) {
743 ohci_dbg (ohci
, "device removed!\n");
746 /* interrupt for some other device? */
747 } else if ((ints
&= ohci_readl (ohci
, ®s
->intrenable
)) == 0) {
751 if (ints
& OHCI_INTR_UE
) {
752 // e.g. due to PCI Master/Target Abort
753 if (quirk_nec(ohci
)) {
754 /* Workaround for a silicon bug in some NEC chips used
755 * in Apple's PowerBooks. Adapted from Darwin code.
757 ohci_err (ohci
, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
759 ohci_writel (ohci
, OHCI_INTR_UE
, ®s
->intrdisable
);
761 schedule_work (&ohci
->nec_work
);
764 ohci_err (ohci
, "OHCI Unrecoverable Error, disabled\n");
768 ohci_usb_reset (ohci
);
771 if (ints
& OHCI_INTR_RHSC
) {
772 ohci_vdbg(ohci
, "rhsc\n");
773 ohci
->next_statechange
= jiffies
+ STATECHANGE_DELAY
;
774 ohci_writel(ohci
, OHCI_INTR_RD
| OHCI_INTR_RHSC
,
777 /* NOTE: Vendors didn't always make the same implementation
778 * choices for RHSC. Many followed the spec; RHSC triggers
779 * on an edge, like setting and maybe clearing a port status
780 * change bit. With others it's level-triggered, active
781 * until khubd clears all the port status change bits. We'll
782 * always disable it here and rely on polling until khubd
785 ohci_writel(ohci
, OHCI_INTR_RHSC
, ®s
->intrdisable
);
786 usb_hcd_poll_rh_status(hcd
);
789 /* For connect and disconnect events, we expect the controller
790 * to turn on RHSC along with RD. But for remote wakeup events
791 * this might not happen.
793 else if (ints
& OHCI_INTR_RD
) {
794 ohci_vdbg(ohci
, "resume detect\n");
795 ohci_writel(ohci
, OHCI_INTR_RD
, ®s
->intrstatus
);
797 if (ohci
->autostop
) {
798 spin_lock (&ohci
->lock
);
799 ohci_rh_resume (ohci
);
800 spin_unlock (&ohci
->lock
);
802 usb_hcd_resume_root_hub(hcd
);
805 if (ints
& OHCI_INTR_WDH
) {
806 if (HC_IS_RUNNING(hcd
->state
))
807 ohci_writel (ohci
, OHCI_INTR_WDH
, ®s
->intrdisable
);
808 spin_lock (&ohci
->lock
);
810 spin_unlock (&ohci
->lock
);
811 if (HC_IS_RUNNING(hcd
->state
))
812 ohci_writel (ohci
, OHCI_INTR_WDH
, ®s
->intrenable
);
815 if (quirk_zfmicro(ohci
) && (ints
& OHCI_INTR_SF
)) {
816 spin_lock(&ohci
->lock
);
817 if (ohci
->ed_to_check
) {
818 struct ed
*ed
= ohci
->ed_to_check
;
820 if (check_ed(ohci
, ed
)) {
821 /* HC thinks the TD list is empty; HCD knows
822 * at least one TD is outstanding
824 if (--ohci
->zf_delay
== 0) {
825 struct td
*td
= list_entry(
829 "Reclaiming orphan TD %p\n",
831 takeback_td(ohci
, td
);
832 ohci
->ed_to_check
= NULL
;
835 ohci
->ed_to_check
= NULL
;
837 spin_unlock(&ohci
->lock
);
840 /* could track INTR_SO to reduce available PCI/... bandwidth */
842 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
843 * when there's still unlinking to be done (next frame).
845 spin_lock (&ohci
->lock
);
846 if (ohci
->ed_rm_list
)
847 finish_unlinks (ohci
, ohci_frame_no(ohci
));
848 if ((ints
& OHCI_INTR_SF
) != 0
850 && !ohci
->ed_to_check
851 && HC_IS_RUNNING(hcd
->state
))
852 ohci_writel (ohci
, OHCI_INTR_SF
, ®s
->intrdisable
);
853 spin_unlock (&ohci
->lock
);
855 if (HC_IS_RUNNING(hcd
->state
)) {
856 ohci_writel (ohci
, ints
, ®s
->intrstatus
);
857 ohci_writel (ohci
, OHCI_INTR_MIE
, ®s
->intrenable
);
858 // flush those writes
859 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
865 /*-------------------------------------------------------------------------*/
867 static void ohci_stop (struct usb_hcd
*hcd
)
869 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
873 flush_scheduled_work();
875 ohci_usb_reset (ohci
);
876 ohci_writel (ohci
, OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
877 free_irq(hcd
->irq
, hcd
);
880 if (quirk_zfmicro(ohci
))
881 del_timer(&ohci
->unlink_watchdog
);
883 remove_debug_files (ohci
);
884 ohci_mem_cleanup (ohci
);
886 dma_free_coherent (hcd
->self
.controller
,
888 ohci
->hcca
, ohci
->hcca_dma
);
894 /*-------------------------------------------------------------------------*/
896 /* must not be called from interrupt context */
897 static int ohci_restart (struct ohci_hcd
*ohci
)
901 struct urb_priv
*priv
;
903 spin_lock_irq(&ohci
->lock
);
906 /* Recycle any "live" eds/tds (and urbs). */
907 if (!list_empty (&ohci
->pending
))
908 ohci_dbg(ohci
, "abort schedule...\n");
909 list_for_each_entry (priv
, &ohci
->pending
, pending
) {
910 struct urb
*urb
= priv
->td
[0]->urb
;
911 struct ed
*ed
= priv
->ed
;
915 ed
->state
= ED_UNLINK
;
916 ed
->hwINFO
|= cpu_to_hc32(ohci
, ED_DEQUEUE
);
917 ed_deschedule (ohci
, ed
);
919 ed
->ed_next
= ohci
->ed_rm_list
;
921 ohci
->ed_rm_list
= ed
;
926 ohci_dbg(ohci
, "bogus ed %p state %d\n",
931 urb
->unlinked
= -ESHUTDOWN
;
933 finish_unlinks (ohci
, 0);
934 spin_unlock_irq(&ohci
->lock
);
936 /* paranoia, in case that didn't work: */
938 /* empty the interrupt branches */
939 for (i
= 0; i
< NUM_INTS
; i
++) ohci
->load
[i
] = 0;
940 for (i
= 0; i
< NUM_INTS
; i
++) ohci
->hcca
->int_table
[i
] = 0;
942 /* no EDs to remove */
943 ohci
->ed_rm_list
= NULL
;
945 /* empty control and bulk lists */
946 ohci
->ed_controltail
= NULL
;
947 ohci
->ed_bulktail
= NULL
;
949 if ((temp
= ohci_run (ohci
)) < 0) {
950 ohci_err (ohci
, "can't restart, %d\n", temp
);
953 ohci_dbg(ohci
, "restart complete\n");
957 /*-------------------------------------------------------------------------*/
959 #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
961 MODULE_AUTHOR (DRIVER_AUTHOR
);
962 MODULE_DESCRIPTION (DRIVER_INFO
);
963 MODULE_LICENSE ("GPL");
966 #include "ohci-pci.c"
967 #define PCI_DRIVER ohci_pci_driver
971 #include "ohci-sa1111.c"
972 #define SA1111_DRIVER ohci_hcd_sa1111_driver
975 #ifdef CONFIG_ARCH_S3C2410
976 #include "ohci-s3c2410.c"
977 #define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
980 #ifdef CONFIG_ARCH_OMAP
981 #include "ohci-omap.c"
982 #define PLATFORM_DRIVER ohci_hcd_omap_driver
985 #ifdef CONFIG_ARCH_LH7A404
986 #include "ohci-lh7a404.c"
987 #define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
991 #include "ohci-pxa27x.c"
992 #define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
995 #ifdef CONFIG_ARCH_EP93XX
996 #include "ohci-ep93xx.c"
997 #define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
1000 #ifdef CONFIG_SOC_AU1X00
1001 #include "ohci-au1xxx.c"
1002 #define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
1005 #ifdef CONFIG_PNX8550
1006 #include "ohci-pnx8550.c"
1007 #define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
1010 #ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
1011 #include "ohci-ppc-soc.c"
1012 #define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
1015 #ifdef CONFIG_ARCH_AT91
1016 #include "ohci-at91.c"
1017 #define PLATFORM_DRIVER ohci_hcd_at91_driver
1020 #ifdef CONFIG_ARCH_PNX4008
1021 #include "ohci-pnx4008.c"
1022 #define PLATFORM_DRIVER usb_hcd_pnx4008_driver
1026 #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1027 #include "ohci-ppc-of.c"
1028 #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1031 #ifdef CONFIG_PPC_PS3
1032 #include "ohci-ps3.c"
1033 #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
1036 #ifdef CONFIG_USB_OHCI_HCD_SSB
1037 #include "ohci-ssb.c"
1038 #define SSB_OHCI_DRIVER ssb_ohci_driver
1041 #if !defined(PCI_DRIVER) && \
1042 !defined(PLATFORM_DRIVER) && \
1043 !defined(OF_PLATFORM_DRIVER) && \
1044 !defined(SA1111_DRIVER) && \
1045 !defined(PS3_SYSTEM_BUS_DRIVER) && \
1046 !defined(SSB_OHCI_DRIVER)
1047 #error "missing bus glue for ohci-hcd"
1050 static int __init
ohci_hcd_mod_init(void)
1057 printk (KERN_DEBUG
"%s: " DRIVER_INFO
"\n", hcd_name
);
1058 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name
,
1059 sizeof (struct ed
), sizeof (struct td
));
1061 #ifdef PS3_SYSTEM_BUS_DRIVER
1062 retval
= ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER
);
1067 #ifdef PLATFORM_DRIVER
1068 retval
= platform_driver_register(&PLATFORM_DRIVER
);
1070 goto error_platform
;
1073 #ifdef OF_PLATFORM_DRIVER
1074 retval
= of_register_platform_driver(&OF_PLATFORM_DRIVER
);
1076 goto error_of_platform
;
1079 #ifdef SA1111_DRIVER
1080 retval
= sa1111_driver_register(&SA1111_DRIVER
);
1086 retval
= pci_register_driver(&PCI_DRIVER
);
1091 #ifdef SSB_OHCI_DRIVER
1092 retval
= ssb_driver_register(&SSB_OHCI_DRIVER
);
1100 #ifdef SSB_OHCI_DRIVER
1104 pci_unregister_driver(&PCI_DRIVER
);
1107 #ifdef SA1111_DRIVER
1108 sa1111_driver_unregister(&SA1111_DRIVER
);
1111 #ifdef OF_PLATFORM_DRIVER
1112 of_unregister_platform_driver(&OF_PLATFORM_DRIVER
);
1115 #ifdef PLATFORM_DRIVER
1116 platform_driver_unregister(&PLATFORM_DRIVER
);
1119 #ifdef PS3_SYSTEM_BUS_DRIVER
1120 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER
);
1125 module_init(ohci_hcd_mod_init
);
1127 static void __exit
ohci_hcd_mod_exit(void)
1129 #ifdef SSB_OHCI_DRIVER
1130 ssb_driver_unregister(&SSB_OHCI_DRIVER
);
1133 pci_unregister_driver(&PCI_DRIVER
);
1135 #ifdef SA1111_DRIVER
1136 sa1111_driver_unregister(&SA1111_DRIVER
);
1138 #ifdef OF_PLATFORM_DRIVER
1139 of_unregister_platform_driver(&OF_PLATFORM_DRIVER
);
1141 #ifdef PLATFORM_DRIVER
1142 platform_driver_unregister(&PLATFORM_DRIVER
);
1144 #ifdef PS3_SYSTEM_BUS_DRIVER
1145 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER
);
1148 module_exit(ohci_hcd_mod_exit
);