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>
39 #include <linux/debugfs.h>
43 #include <asm/system.h>
44 #include <asm/unaligned.h>
45 #include <asm/byteorder.h>
47 #include "../core/hcd.h"
49 #define DRIVER_VERSION "2006 August 04"
50 #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
51 #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
53 /*-------------------------------------------------------------------------*/
55 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
57 /* For initializing controller (mask in an HCFS mode too) */
58 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
59 #define OHCI_INTR_INIT \
60 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
61 | OHCI_INTR_RD | OHCI_INTR_WDH)
64 /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
68 #ifdef CONFIG_ARCH_OMAP
69 /* OMAP doesn't support IR (no SMM; not needed) */
73 /*-------------------------------------------------------------------------*/
75 static const char hcd_name
[] = "ohci_hcd";
77 #define STATECHANGE_DELAY msecs_to_jiffies(300)
81 static void ohci_dump (struct ohci_hcd
*ohci
, int verbose
);
82 static int ohci_init (struct ohci_hcd
*ohci
);
83 static void ohci_stop (struct usb_hcd
*hcd
);
85 #if defined(CONFIG_PM) || defined(CONFIG_PCI)
86 static int ohci_restart (struct ohci_hcd
*ohci
);
90 static void quirk_amd_pll(int state
);
91 static void amd_iso_dev_put(void);
92 static void sb800_prefetch(struct ohci_hcd
*ohci
, int on
);
94 static inline void quirk_amd_pll(int state
)
98 static inline void amd_iso_dev_put(void)
102 static inline void sb800_prefetch(struct ohci_hcd
*ohci
, int on
)
109 #include "ohci-hub.c"
110 #include "ohci-dbg.c"
111 #include "ohci-mem.c"
116 * On architectures with edge-triggered interrupts we must never return
119 #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
120 #define IRQ_NOTMINE IRQ_HANDLED
122 #define IRQ_NOTMINE IRQ_NONE
126 /* Some boards misreport power switching/overcurrent */
127 static int distrust_firmware
= 1;
128 module_param (distrust_firmware
, bool, 0);
129 MODULE_PARM_DESC (distrust_firmware
,
130 "true to distrust firmware power/overcurrent setup");
132 /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
133 static int no_handshake
= 0;
134 module_param (no_handshake
, bool, 0);
135 MODULE_PARM_DESC (no_handshake
, "true (not default) disables BIOS handshake");
137 /*-------------------------------------------------------------------------*/
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 #ifdef OHCI_VERBOSE_DEBUG
156 urb_print(urb
, "SUB", usb_pipein(pipe
), -EINPROGRESS
);
159 /* every endpoint has a ed, locate and maybe (re)initialize it */
160 if (! (ed
= ed_get (ohci
, urb
->ep
, urb
->dev
, pipe
, urb
->interval
)))
163 /* for the private part of the URB we need the number of TDs (size) */
166 /* td_submit_urb() doesn't yet handle these */
167 if (urb
->transfer_buffer_length
> 4096)
170 /* 1 TD for setup, 1 for ACK, plus ... */
173 // case PIPE_INTERRUPT:
176 /* one TD for every 4096 Bytes (can be upto 8K) */
177 size
+= urb
->transfer_buffer_length
/ 4096;
178 /* ... and for any remaining bytes ... */
179 if ((urb
->transfer_buffer_length
% 4096) != 0)
181 /* ... and maybe a zero length packet to wrap it up */
184 else if ((urb
->transfer_flags
& URB_ZERO_PACKET
) != 0
185 && (urb
->transfer_buffer_length
186 % usb_maxpacket (urb
->dev
, pipe
,
187 usb_pipeout (pipe
))) == 0)
190 case PIPE_ISOCHRONOUS
: /* number of packets from URB */
191 size
= urb
->number_of_packets
;
195 /* allocate the private part of the URB */
196 urb_priv
= kzalloc (sizeof (urb_priv_t
) + size
* sizeof (struct td
*),
200 INIT_LIST_HEAD (&urb_priv
->pending
);
201 urb_priv
->length
= size
;
204 /* allocate the TDs (deferring hash chain updates) */
205 for (i
= 0; i
< size
; i
++) {
206 urb_priv
->td
[i
] = td_alloc (ohci
, mem_flags
);
207 if (!urb_priv
->td
[i
]) {
208 urb_priv
->length
= i
;
209 urb_free_priv (ohci
, urb_priv
);
214 spin_lock_irqsave (&ohci
->lock
, flags
);
216 /* don't submit to a dead HC */
217 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)) {
221 if (!HC_IS_RUNNING(hcd
->state
)) {
225 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
229 /* schedule the ed if needed */
230 if (ed
->state
== ED_IDLE
) {
231 retval
= ed_schedule (ohci
, ed
);
233 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
236 if (ed
->type
== PIPE_ISOCHRONOUS
) {
237 u16 frame
= ohci_frame_no(ohci
);
239 /* delay a few frames before the first TD */
240 frame
+= max_t (u16
, 8, ed
->interval
);
241 frame
&= ~(ed
->interval
- 1);
243 urb
->start_frame
= frame
;
245 /* yes, only URB_ISO_ASAP is supported, and
246 * urb->start_frame is never used as input.
249 } else if (ed
->type
== PIPE_ISOCHRONOUS
)
250 urb
->start_frame
= ed
->last_iso
+ ed
->interval
;
252 /* fill the TDs and link them to the ed; and
253 * enable that part of the schedule, if needed
254 * and update count of queued periodic urbs
256 urb
->hcpriv
= urb_priv
;
257 td_submit_urb (ohci
, urb
);
261 urb_free_priv (ohci
, urb_priv
);
262 spin_unlock_irqrestore (&ohci
->lock
, flags
);
267 * decouple the URB from the HC queues (TDs, urb_priv).
268 * reporting is always done
269 * asynchronously, and we might be dealing with an urb that's
270 * partially transferred, or an ED with other urbs being unlinked.
272 static int ohci_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
, int status
)
274 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
278 #ifdef OHCI_VERBOSE_DEBUG
279 urb_print(urb
, "UNLINK", 1, status
);
282 spin_lock_irqsave (&ohci
->lock
, flags
);
283 rc
= usb_hcd_check_unlink_urb(hcd
, urb
, status
);
286 } else if (HC_IS_RUNNING(hcd
->state
)) {
287 urb_priv_t
*urb_priv
;
289 /* Unless an IRQ completed the unlink while it was being
290 * handed to us, flag it for unlink and giveback, and force
291 * some upcoming INTR_SF to call finish_unlinks()
293 urb_priv
= urb
->hcpriv
;
295 if (urb_priv
->ed
->state
== ED_OPER
)
296 start_ed_unlink (ohci
, urb_priv
->ed
);
300 * with HC dead, we won't respect hc queue pointers
301 * any more ... just clean up every urb's memory.
304 finish_urb(ohci
, urb
, status
);
306 spin_unlock_irqrestore (&ohci
->lock
, flags
);
310 /*-------------------------------------------------------------------------*/
312 /* frees config/altsetting state for endpoints,
313 * including ED memory, dummy TD, and bulk/intr data toggle
317 ohci_endpoint_disable (struct usb_hcd
*hcd
, struct usb_host_endpoint
*ep
)
319 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
321 struct ed
*ed
= ep
->hcpriv
;
322 unsigned limit
= 1000;
324 /* ASSERT: any requests/urbs are being unlinked */
325 /* ASSERT: nobody can be submitting urbs for this any more */
331 spin_lock_irqsave (&ohci
->lock
, flags
);
333 if (!HC_IS_RUNNING (hcd
->state
)) {
336 if (quirk_zfmicro(ohci
) && ed
->type
== PIPE_INTERRUPT
)
337 ohci
->eds_scheduled
--;
338 finish_unlinks (ohci
, 0);
342 case ED_UNLINK
: /* wait for hw to finish? */
343 /* major IRQ delivery trouble loses INTR_SF too... */
345 ohci_warn(ohci
, "ED unlink timeout\n");
346 if (quirk_zfmicro(ohci
)) {
347 ohci_warn(ohci
, "Attempting ZF TD recovery\n");
348 ohci
->ed_to_check
= ed
;
353 spin_unlock_irqrestore (&ohci
->lock
, flags
);
354 schedule_timeout_uninterruptible(1);
356 case ED_IDLE
: /* fully unlinked */
357 if (list_empty (&ed
->td_list
)) {
358 td_free (ohci
, ed
->dummy
);
362 /* else FALL THROUGH */
364 /* caller was supposed to have unlinked any requests;
365 * that's not our job. can't recover; must leak ed.
367 ohci_err (ohci
, "leak ed %p (#%02x) state %d%s\n",
368 ed
, ep
->desc
.bEndpointAddress
, ed
->state
,
369 list_empty (&ed
->td_list
) ? "" : " (has tds)");
370 td_free (ohci
, ed
->dummy
);
374 spin_unlock_irqrestore (&ohci
->lock
, flags
);
378 static int ohci_get_frame (struct usb_hcd
*hcd
)
380 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
382 return ohci_frame_no(ohci
);
385 static void ohci_usb_reset (struct ohci_hcd
*ohci
)
387 ohci
->hc_control
= ohci_readl (ohci
, &ohci
->regs
->control
);
388 ohci
->hc_control
&= OHCI_CTRL_RWC
;
389 ohci_writel (ohci
, ohci
->hc_control
, &ohci
->regs
->control
);
392 /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
393 * other cases where the next software may expect clean state from the
394 * "firmware". this is bus-neutral, unlike shutdown() methods.
397 ohci_shutdown (struct usb_hcd
*hcd
)
399 struct ohci_hcd
*ohci
;
401 ohci
= hcd_to_ohci (hcd
);
402 ohci_writel (ohci
, OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
403 ohci_usb_reset (ohci
);
404 /* flush the writes */
405 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
408 static int check_ed(struct ohci_hcd
*ohci
, struct ed
*ed
)
410 return (hc32_to_cpu(ohci
, ed
->hwINFO
) & ED_IN
) != 0
411 && (hc32_to_cpu(ohci
, ed
->hwHeadP
) & TD_MASK
)
412 == (hc32_to_cpu(ohci
, ed
->hwTailP
) & TD_MASK
)
413 && !list_empty(&ed
->td_list
);
416 /* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
417 * an interrupt TD but neglects to add it to the donelist. On systems with
418 * this chipset, we need to periodically check the state of the queues to look
419 * for such "lost" TDs.
421 static void unlink_watchdog_func(unsigned long _ohci
)
425 unsigned seen_count
= 0;
427 struct ed
**seen
= NULL
;
428 struct ohci_hcd
*ohci
= (struct ohci_hcd
*) _ohci
;
430 spin_lock_irqsave(&ohci
->lock
, flags
);
431 max
= ohci
->eds_scheduled
;
435 if (ohci
->ed_to_check
)
438 seen
= kcalloc(max
, sizeof *seen
, GFP_ATOMIC
);
442 for (i
= 0; i
< NUM_INTS
; i
++) {
443 struct ed
*ed
= ohci
->periodic
[i
];
448 /* scan this branch of the periodic schedule tree */
449 for (temp
= 0; temp
< seen_count
; temp
++) {
450 if (seen
[temp
] == ed
) {
451 /* we've checked it and what's after */
458 seen
[seen_count
++] = ed
;
459 if (!check_ed(ohci
, ed
)) {
464 /* HC's TD list is empty, but HCD sees at least one
465 * TD that's not been sent through the donelist.
467 ohci
->ed_to_check
= ed
;
470 /* The HC may wait until the next frame to report the
471 * TD as done through the donelist and INTR_WDH. (We
472 * just *assume* it's not a multi-TD interrupt URB;
473 * those could defer the IRQ more than one frame, using
474 * DI...) Check again after the next INTR_SF.
476 ohci_writel(ohci
, OHCI_INTR_SF
,
477 &ohci
->regs
->intrstatus
);
478 ohci_writel(ohci
, OHCI_INTR_SF
,
479 &ohci
->regs
->intrenable
);
481 /* flush those writes */
482 (void) ohci_readl(ohci
, &ohci
->regs
->control
);
489 if (ohci
->eds_scheduled
)
490 mod_timer(&ohci
->unlink_watchdog
, round_jiffies(jiffies
+ HZ
));
492 spin_unlock_irqrestore(&ohci
->lock
, flags
);
495 /*-------------------------------------------------------------------------*
497 *-------------------------------------------------------------------------*/
499 /* init memory, and kick BIOS/SMM off */
501 static int ohci_init (struct ohci_hcd
*ohci
)
504 struct usb_hcd
*hcd
= ohci_to_hcd(ohci
);
506 if (distrust_firmware
)
507 ohci
->flags
|= OHCI_QUIRK_HUB_POWER
;
510 ohci
->regs
= hcd
->regs
;
512 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
513 * was never needed for most non-PCI systems ... remove the code?
517 /* SMM owns the HC? not for long! */
518 if (!no_handshake
&& ohci_readl (ohci
,
519 &ohci
->regs
->control
) & OHCI_CTRL_IR
) {
522 ohci_dbg (ohci
, "USB HC TakeOver from BIOS/SMM\n");
524 /* this timeout is arbitrary. we make it long, so systems
525 * depending on usb keyboards may be usable even if the
526 * BIOS/SMM code seems pretty broken.
528 temp
= 500; /* arbitrary: five seconds */
530 ohci_writel (ohci
, OHCI_INTR_OC
, &ohci
->regs
->intrenable
);
531 ohci_writel (ohci
, OHCI_OCR
, &ohci
->regs
->cmdstatus
);
532 while (ohci_readl (ohci
, &ohci
->regs
->control
) & OHCI_CTRL_IR
) {
535 ohci_err (ohci
, "USB HC takeover failed!"
536 " (BIOS/SMM bug)\n");
540 ohci_usb_reset (ohci
);
544 /* Disable HC interrupts */
545 ohci_writel (ohci
, OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
547 /* flush the writes, and save key bits like RWC */
548 if (ohci_readl (ohci
, &ohci
->regs
->control
) & OHCI_CTRL_RWC
)
549 ohci
->hc_control
|= OHCI_CTRL_RWC
;
551 /* Read the number of ports unless overridden */
552 if (ohci
->num_ports
== 0)
553 ohci
->num_ports
= roothub_a(ohci
) & RH_A_NDP
;
558 ohci
->hcca
= dma_alloc_coherent (hcd
->self
.controller
,
559 sizeof *ohci
->hcca
, &ohci
->hcca_dma
, 0);
563 if ((ret
= ohci_mem_init (ohci
)) < 0)
566 create_debug_files (ohci
);
572 /*-------------------------------------------------------------------------*/
574 /* Start an OHCI controller, set the BUS operational
575 * resets USB and controller
578 static int ohci_run (struct ohci_hcd
*ohci
)
581 int first
= ohci
->fminterval
== 0;
582 struct usb_hcd
*hcd
= ohci_to_hcd(ohci
);
586 /* boot firmware should have set this up (5.1.1.3.1) */
589 temp
= ohci_readl (ohci
, &ohci
->regs
->fminterval
);
590 ohci
->fminterval
= temp
& 0x3fff;
591 if (ohci
->fminterval
!= FI
)
592 ohci_dbg (ohci
, "fminterval delta %d\n",
593 ohci
->fminterval
- FI
);
594 ohci
->fminterval
|= FSMP (ohci
->fminterval
) << 16;
595 /* also: power/overcurrent flags in roothub.a */
598 /* Reset USB nearly "by the book". RemoteWakeupConnected was
599 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
600 * or if bus glue did the same (e.g. for PCI add-in cards with
603 if ((ohci
->hc_control
& OHCI_CTRL_RWC
) != 0
604 && !device_may_wakeup(hcd
->self
.controller
))
605 device_init_wakeup(hcd
->self
.controller
, 1);
607 switch (ohci
->hc_control
& OHCI_CTRL_HCFS
) {
611 case OHCI_USB_SUSPEND
:
612 case OHCI_USB_RESUME
:
613 ohci
->hc_control
&= OHCI_CTRL_RWC
;
614 ohci
->hc_control
|= OHCI_USB_RESUME
;
615 temp
= 10 /* msec wait */;
617 // case OHCI_USB_RESET:
619 ohci
->hc_control
&= OHCI_CTRL_RWC
;
620 ohci
->hc_control
|= OHCI_USB_RESET
;
621 temp
= 50 /* msec wait */;
624 ohci_writel (ohci
, ohci
->hc_control
, &ohci
->regs
->control
);
626 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
629 memset (ohci
->hcca
, 0, sizeof (struct ohci_hcca
));
631 /* 2msec timelimit here means no irqs/preempt */
632 spin_lock_irq (&ohci
->lock
);
635 /* HC Reset requires max 10 us delay */
636 ohci_writel (ohci
, OHCI_HCR
, &ohci
->regs
->cmdstatus
);
637 temp
= 30; /* ... allow extra time */
638 while ((ohci_readl (ohci
, &ohci
->regs
->cmdstatus
) & OHCI_HCR
) != 0) {
640 spin_unlock_irq (&ohci
->lock
);
641 ohci_err (ohci
, "USB HC reset timed out!\n");
647 /* now we're in the SUSPEND state ... must go OPERATIONAL
648 * within 2msec else HC enters RESUME
650 * ... but some hardware won't init fmInterval "by the book"
651 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
652 * this if we write fmInterval after we're OPERATIONAL.
653 * Unclear about ALi, ServerWorks, and others ... this could
654 * easily be a longstanding bug in chip init on Linux.
656 if (ohci
->flags
& OHCI_QUIRK_INITRESET
) {
657 ohci_writel (ohci
, ohci
->hc_control
, &ohci
->regs
->control
);
658 // flush those writes
659 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
662 /* Tell the controller where the control and bulk lists are
663 * The lists are empty now. */
664 ohci_writel (ohci
, 0, &ohci
->regs
->ed_controlhead
);
665 ohci_writel (ohci
, 0, &ohci
->regs
->ed_bulkhead
);
667 /* a reset clears this */
668 ohci_writel (ohci
, (u32
) ohci
->hcca_dma
, &ohci
->regs
->hcca
);
670 periodic_reinit (ohci
);
672 /* some OHCI implementations are finicky about how they init.
673 * bogus values here mean not even enumeration could work.
675 if ((ohci_readl (ohci
, &ohci
->regs
->fminterval
) & 0x3fff0000) == 0
676 || !ohci_readl (ohci
, &ohci
->regs
->periodicstart
)) {
677 if (!(ohci
->flags
& OHCI_QUIRK_INITRESET
)) {
678 ohci
->flags
|= OHCI_QUIRK_INITRESET
;
679 ohci_dbg (ohci
, "enabling initreset quirk\n");
682 spin_unlock_irq (&ohci
->lock
);
683 ohci_err (ohci
, "init err (%08x %04x)\n",
684 ohci_readl (ohci
, &ohci
->regs
->fminterval
),
685 ohci_readl (ohci
, &ohci
->regs
->periodicstart
));
689 /* use rhsc irqs after khubd is fully initialized */
691 hcd
->uses_new_polling
= 1;
693 /* start controller operations */
694 ohci
->hc_control
&= OHCI_CTRL_RWC
;
695 ohci
->hc_control
|= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
696 ohci_writel (ohci
, ohci
->hc_control
, &ohci
->regs
->control
);
697 hcd
->state
= HC_STATE_RUNNING
;
699 /* wake on ConnectStatusChange, matching external hubs */
700 ohci_writel (ohci
, RH_HS_DRWE
, &ohci
->regs
->roothub
.status
);
702 /* Choose the interrupts we care about now, others later on demand */
703 mask
= OHCI_INTR_INIT
;
704 ohci_writel (ohci
, ~0, &ohci
->regs
->intrstatus
);
705 ohci_writel (ohci
, mask
, &ohci
->regs
->intrenable
);
707 /* handle root hub init quirks ... */
708 temp
= roothub_a (ohci
);
709 temp
&= ~(RH_A_PSM
| RH_A_OCPM
);
710 if (ohci
->flags
& OHCI_QUIRK_SUPERIO
) {
711 /* NSC 87560 and maybe others */
713 temp
&= ~(RH_A_POTPGT
| RH_A_NPS
);
714 ohci_writel (ohci
, temp
, &ohci
->regs
->roothub
.a
);
715 } else if ((ohci
->flags
& OHCI_QUIRK_AMD756
) ||
716 (ohci
->flags
& OHCI_QUIRK_HUB_POWER
)) {
717 /* hub power always on; required for AMD-756 and some
718 * Mac platforms. ganged overcurrent reporting, if any.
721 ohci_writel (ohci
, temp
, &ohci
->regs
->roothub
.a
);
723 ohci_writel (ohci
, RH_HS_LPSC
, &ohci
->regs
->roothub
.status
);
724 ohci_writel (ohci
, (temp
& RH_A_NPS
) ? 0 : RH_B_PPCM
,
725 &ohci
->regs
->roothub
.b
);
726 // flush those writes
727 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
729 ohci
->next_statechange
= jiffies
+ STATECHANGE_DELAY
;
730 spin_unlock_irq (&ohci
->lock
);
732 // POTPGT delay is bits 24-31, in 2 ms units.
733 mdelay ((temp
>> 23) & 0x1fe);
734 hcd
->state
= HC_STATE_RUNNING
;
736 if (quirk_zfmicro(ohci
)) {
737 /* Create timer to watch for bad queue state on ZF Micro */
738 setup_timer(&ohci
->unlink_watchdog
, unlink_watchdog_func
,
739 (unsigned long) ohci
);
741 ohci
->eds_scheduled
= 0;
742 ohci
->ed_to_check
= NULL
;
750 /*-------------------------------------------------------------------------*/
752 /* an interrupt happens */
754 static irqreturn_t
ohci_irq (struct usb_hcd
*hcd
)
756 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
757 struct ohci_regs __iomem
*regs
= ohci
->regs
;
760 /* Read interrupt status (and flush pending writes). We ignore the
761 * optimization of checking the LSB of hcca->done_head; it doesn't
762 * work on all systems (edge triggering for OHCI can be a factor).
764 ints
= ohci_readl(ohci
, ®s
->intrstatus
);
766 /* Check for an all 1's result which is a typical consequence
767 * of dead, unclocked, or unplugged (CardBus...) devices
769 if (ints
== ~(u32
)0) {
771 ohci_dbg (ohci
, "device removed!\n");
775 /* We only care about interrupts that are enabled */
776 ints
&= ohci_readl(ohci
, ®s
->intrenable
);
778 /* interrupt for some other device? */
782 if (ints
& OHCI_INTR_UE
) {
783 // e.g. due to PCI Master/Target Abort
784 if (quirk_nec(ohci
)) {
785 /* Workaround for a silicon bug in some NEC chips used
786 * in Apple's PowerBooks. Adapted from Darwin code.
788 ohci_err (ohci
, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
790 ohci_writel (ohci
, OHCI_INTR_UE
, ®s
->intrdisable
);
792 schedule_work (&ohci
->nec_work
);
795 ohci_err (ohci
, "OHCI Unrecoverable Error, disabled\n");
799 ohci_usb_reset (ohci
);
802 if (ints
& OHCI_INTR_RHSC
) {
803 ohci_vdbg(ohci
, "rhsc\n");
804 ohci
->next_statechange
= jiffies
+ STATECHANGE_DELAY
;
805 ohci_writel(ohci
, OHCI_INTR_RD
| OHCI_INTR_RHSC
,
808 /* NOTE: Vendors didn't always make the same implementation
809 * choices for RHSC. Many followed the spec; RHSC triggers
810 * on an edge, like setting and maybe clearing a port status
811 * change bit. With others it's level-triggered, active
812 * until khubd clears all the port status change bits. We'll
813 * always disable it here and rely on polling until khubd
816 ohci_writel(ohci
, OHCI_INTR_RHSC
, ®s
->intrdisable
);
817 usb_hcd_poll_rh_status(hcd
);
820 /* For connect and disconnect events, we expect the controller
821 * to turn on RHSC along with RD. But for remote wakeup events
822 * this might not happen.
824 else if (ints
& OHCI_INTR_RD
) {
825 ohci_vdbg(ohci
, "resume detect\n");
826 ohci_writel(ohci
, OHCI_INTR_RD
, ®s
->intrstatus
);
828 if (ohci
->autostop
) {
829 spin_lock (&ohci
->lock
);
830 ohci_rh_resume (ohci
);
831 spin_unlock (&ohci
->lock
);
833 usb_hcd_resume_root_hub(hcd
);
836 if (ints
& OHCI_INTR_WDH
) {
837 spin_lock (&ohci
->lock
);
839 spin_unlock (&ohci
->lock
);
842 if (quirk_zfmicro(ohci
) && (ints
& OHCI_INTR_SF
)) {
843 spin_lock(&ohci
->lock
);
844 if (ohci
->ed_to_check
) {
845 struct ed
*ed
= ohci
->ed_to_check
;
847 if (check_ed(ohci
, ed
)) {
848 /* HC thinks the TD list is empty; HCD knows
849 * at least one TD is outstanding
851 if (--ohci
->zf_delay
== 0) {
852 struct td
*td
= list_entry(
856 "Reclaiming orphan TD %p\n",
858 takeback_td(ohci
, td
);
859 ohci
->ed_to_check
= NULL
;
862 ohci
->ed_to_check
= NULL
;
864 spin_unlock(&ohci
->lock
);
867 /* could track INTR_SO to reduce available PCI/... bandwidth */
869 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
870 * when there's still unlinking to be done (next frame).
872 spin_lock (&ohci
->lock
);
873 if (ohci
->ed_rm_list
)
874 finish_unlinks (ohci
, ohci_frame_no(ohci
));
875 if ((ints
& OHCI_INTR_SF
) != 0
877 && !ohci
->ed_to_check
878 && HC_IS_RUNNING(hcd
->state
))
879 ohci_writel (ohci
, OHCI_INTR_SF
, ®s
->intrdisable
);
880 spin_unlock (&ohci
->lock
);
882 if (HC_IS_RUNNING(hcd
->state
)) {
883 ohci_writel (ohci
, ints
, ®s
->intrstatus
);
884 ohci_writel (ohci
, OHCI_INTR_MIE
, ®s
->intrenable
);
885 // flush those writes
886 (void) ohci_readl (ohci
, &ohci
->regs
->control
);
892 /*-------------------------------------------------------------------------*/
894 static void ohci_stop (struct usb_hcd
*hcd
)
896 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
900 flush_scheduled_work();
902 ohci_usb_reset (ohci
);
903 ohci_writel (ohci
, OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
904 free_irq(hcd
->irq
, hcd
);
907 if (quirk_zfmicro(ohci
))
908 del_timer(&ohci
->unlink_watchdog
);
909 if (quirk_amdiso(ohci
))
912 remove_debug_files (ohci
);
913 ohci_mem_cleanup (ohci
);
915 dma_free_coherent (hcd
->self
.controller
,
917 ohci
->hcca
, ohci
->hcca_dma
);
923 /*-------------------------------------------------------------------------*/
925 #if defined(CONFIG_PM) || defined(CONFIG_PCI)
927 /* must not be called from interrupt context */
928 static int ohci_restart (struct ohci_hcd
*ohci
)
932 struct urb_priv
*priv
;
934 spin_lock_irq(&ohci
->lock
);
937 /* Recycle any "live" eds/tds (and urbs). */
938 if (!list_empty (&ohci
->pending
))
939 ohci_dbg(ohci
, "abort schedule...\n");
940 list_for_each_entry (priv
, &ohci
->pending
, pending
) {
941 struct urb
*urb
= priv
->td
[0]->urb
;
942 struct ed
*ed
= priv
->ed
;
946 ed
->state
= ED_UNLINK
;
947 ed
->hwINFO
|= cpu_to_hc32(ohci
, ED_DEQUEUE
);
948 ed_deschedule (ohci
, ed
);
950 ed
->ed_next
= ohci
->ed_rm_list
;
952 ohci
->ed_rm_list
= ed
;
957 ohci_dbg(ohci
, "bogus ed %p state %d\n",
962 urb
->unlinked
= -ESHUTDOWN
;
964 finish_unlinks (ohci
, 0);
965 spin_unlock_irq(&ohci
->lock
);
967 /* paranoia, in case that didn't work: */
969 /* empty the interrupt branches */
970 for (i
= 0; i
< NUM_INTS
; i
++) ohci
->load
[i
] = 0;
971 for (i
= 0; i
< NUM_INTS
; i
++) ohci
->hcca
->int_table
[i
] = 0;
973 /* no EDs to remove */
974 ohci
->ed_rm_list
= NULL
;
976 /* empty control and bulk lists */
977 ohci
->ed_controltail
= NULL
;
978 ohci
->ed_bulktail
= NULL
;
980 if ((temp
= ohci_run (ohci
)) < 0) {
981 ohci_err (ohci
, "can't restart, %d\n", temp
);
984 ohci_dbg(ohci
, "restart complete\n");
990 /*-------------------------------------------------------------------------*/
992 #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
994 MODULE_AUTHOR (DRIVER_AUTHOR
);
995 MODULE_DESCRIPTION (DRIVER_INFO
);
996 MODULE_LICENSE ("GPL");
999 #include "ohci-pci.c"
1000 #define PCI_DRIVER ohci_pci_driver
1003 #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
1004 #include "ohci-sa1111.c"
1005 #define SA1111_DRIVER ohci_hcd_sa1111_driver
1008 #ifdef CONFIG_ARCH_S3C2410
1009 #include "ohci-s3c2410.c"
1010 #define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
1013 #ifdef CONFIG_ARCH_OMAP
1014 #include "ohci-omap.c"
1015 #define PLATFORM_DRIVER ohci_hcd_omap_driver
1018 #ifdef CONFIG_ARCH_LH7A404
1019 #include "ohci-lh7a404.c"
1020 #define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
1023 #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
1024 #include "ohci-pxa27x.c"
1025 #define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
1028 #ifdef CONFIG_ARCH_EP93XX
1029 #include "ohci-ep93xx.c"
1030 #define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
1033 #ifdef CONFIG_SOC_AU1X00
1034 #include "ohci-au1xxx.c"
1035 #define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
1038 #ifdef CONFIG_PNX8550
1039 #include "ohci-pnx8550.c"
1040 #define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
1043 #ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
1044 #include "ohci-ppc-soc.c"
1045 #define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
1048 #ifdef CONFIG_ARCH_AT91
1049 #include "ohci-at91.c"
1050 #define PLATFORM_DRIVER ohci_hcd_at91_driver
1053 #ifdef CONFIG_ARCH_PNX4008
1054 #include "ohci-pnx4008.c"
1055 #define PLATFORM_DRIVER usb_hcd_pnx4008_driver
1058 #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
1059 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
1060 defined(CONFIG_CPU_SUBTYPE_SH7763)
1061 #include "ohci-sh.c"
1062 #define PLATFORM_DRIVER ohci_hcd_sh_driver
1066 #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1067 #include "ohci-ppc-of.c"
1068 #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1071 #ifdef CONFIG_PPC_PS3
1072 #include "ohci-ps3.c"
1073 #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
1076 #ifdef CONFIG_USB_OHCI_HCD_SSB
1077 #include "ohci-ssb.c"
1078 #define SSB_OHCI_DRIVER ssb_ohci_driver
1081 #ifdef CONFIG_MFD_SM501
1082 #include "ohci-sm501.c"
1083 #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
1086 #if !defined(PCI_DRIVER) && \
1087 !defined(PLATFORM_DRIVER) && \
1088 !defined(OF_PLATFORM_DRIVER) && \
1089 !defined(SA1111_DRIVER) && \
1090 !defined(PS3_SYSTEM_BUS_DRIVER) && \
1091 !defined(SM501_OHCI_DRIVER) && \
1092 !defined(SSB_OHCI_DRIVER)
1093 #error "missing bus glue for ohci-hcd"
1096 static int __init
ohci_hcd_mod_init(void)
1103 printk (KERN_DEBUG
"%s: " DRIVER_INFO
"\n", hcd_name
);
1104 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name
,
1105 sizeof (struct ed
), sizeof (struct td
));
1106 set_bit(USB_OHCI_LOADED
, &usb_hcds_loaded
);
1109 ohci_debug_root
= debugfs_create_dir("ohci", NULL
);
1110 if (!ohci_debug_root
) {
1116 #ifdef PS3_SYSTEM_BUS_DRIVER
1117 retval
= ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER
);
1122 #ifdef PLATFORM_DRIVER
1123 retval
= platform_driver_register(&PLATFORM_DRIVER
);
1125 goto error_platform
;
1128 #ifdef OF_PLATFORM_DRIVER
1129 retval
= of_register_platform_driver(&OF_PLATFORM_DRIVER
);
1131 goto error_of_platform
;
1134 #ifdef SA1111_DRIVER
1135 retval
= sa1111_driver_register(&SA1111_DRIVER
);
1141 retval
= pci_register_driver(&PCI_DRIVER
);
1146 #ifdef SSB_OHCI_DRIVER
1147 retval
= ssb_driver_register(&SSB_OHCI_DRIVER
);
1152 #ifdef SM501_OHCI_DRIVER
1153 retval
= platform_driver_register(&SM501_OHCI_DRIVER
);
1161 #ifdef SM501_OHCI_DRIVER
1164 #ifdef SSB_OHCI_DRIVER
1168 pci_unregister_driver(&PCI_DRIVER
);
1171 #ifdef SA1111_DRIVER
1172 sa1111_driver_unregister(&SA1111_DRIVER
);
1175 #ifdef OF_PLATFORM_DRIVER
1176 of_unregister_platform_driver(&OF_PLATFORM_DRIVER
);
1179 #ifdef PLATFORM_DRIVER
1180 platform_driver_unregister(&PLATFORM_DRIVER
);
1183 #ifdef PS3_SYSTEM_BUS_DRIVER
1184 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER
);
1188 debugfs_remove(ohci_debug_root
);
1189 ohci_debug_root
= NULL
;
1193 clear_bit(USB_OHCI_LOADED
, &usb_hcds_loaded
);
1196 module_init(ohci_hcd_mod_init
);
1198 static void __exit
ohci_hcd_mod_exit(void)
1200 #ifdef SM501_OHCI_DRIVER
1201 platform_driver_unregister(&SM501_OHCI_DRIVER
);
1203 #ifdef SSB_OHCI_DRIVER
1204 ssb_driver_unregister(&SSB_OHCI_DRIVER
);
1207 pci_unregister_driver(&PCI_DRIVER
);
1209 #ifdef SA1111_DRIVER
1210 sa1111_driver_unregister(&SA1111_DRIVER
);
1212 #ifdef OF_PLATFORM_DRIVER
1213 of_unregister_platform_driver(&OF_PLATFORM_DRIVER
);
1215 #ifdef PLATFORM_DRIVER
1216 platform_driver_unregister(&PLATFORM_DRIVER
);
1218 #ifdef PS3_SYSTEM_BUS_DRIVER
1219 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER
);
1222 debugfs_remove(ohci_debug_root
);
1224 clear_bit(USB_OHCI_LOADED
, &usb_hcds_loaded
);
1226 module_exit(ohci_hcd_mod_exit
);