blob: 78bb7710f36d9ef641f7857b3f688b5c2c9640af [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
David Brownelldd9048a2006-12-05 03:18:31 -08006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * [ Initialisation is based on Linus' ]
8 * [ uhci code and gregs ohci fragments ]
9 * [ (C) Copyright 1999 Linus Torvalds ]
10 * [ (C) Copyright 1999 Gregory P. Smith]
David Brownelldd9048a2006-12-05 03:18:31 -080011 *
12 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
14 * interfaces (though some non-x86 Intel chips use it). It supports
15 * smarter hardware than UHCI. A download link for the spec available
16 * through the http://www.usb.org website.
17 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * This file is licenced under the GPL.
19 */
David Brownelldd9048a2006-12-05 03:18:31 -080020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/pci.h>
24#include <linux/kernel.h>
25#include <linux/delay.h>
26#include <linux/ioport.h>
27#include <linux/sched.h>
28#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/errno.h>
30#include <linux/init.h>
31#include <linux/timer.h>
32#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/usb.h>
David Brownell3a16f7b2006-06-29 12:27:23 -070034#include <linux/usb/otg.h>
David Brownelldd9048a2006-12-05 03:18:31 -080035#include <linux/dma-mapping.h>
David Brownellf4df0e32005-04-23 12:49:16 -070036#include <linux/dmapool.h>
Michael Hanselmannd576bb92007-05-31 23:34:27 +020037#include <linux/workqueue.h>
Tony Jones684c19e2007-09-11 14:07:31 -070038#include <linux/debugfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#include <asm/io.h>
41#include <asm/irq.h>
42#include <asm/system.h>
43#include <asm/unaligned.h>
44#include <asm/byteorder.h>
45
David Brownellf4df0e32005-04-23 12:49:16 -070046#include "../core/hcd.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
49#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
50
51/*-------------------------------------------------------------------------*/
52
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +110053#undef OHCI_VERBOSE_DEBUG /* not always helpful */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/* For initializing controller (mask in an HCFS mode too) */
David Brownelld4139842006-08-04 11:31:55 -070056#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define OHCI_INTR_INIT \
David Brownelld4139842006-08-04 11:31:55 -070058 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
59 | OHCI_INTR_RD | OHCI_INTR_WDH)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61#ifdef __hppa__
62/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
63#define IR_DISABLE
64#endif
65
66#ifdef CONFIG_ARCH_OMAP
67/* OMAP doesn't support IR (no SMM; not needed) */
68#define IR_DISABLE
69#endif
70
71/*-------------------------------------------------------------------------*/
72
73static const char hcd_name [] = "ohci_hcd";
74
David Brownelld4139842006-08-04 11:31:55 -070075#define STATECHANGE_DELAY msecs_to_jiffies(300)
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include "ohci.h"
78
79static void ohci_dump (struct ohci_hcd *ohci, int verbose);
80static int ohci_init (struct ohci_hcd *ohci);
81static void ohci_stop (struct usb_hcd *hcd);
David Brownellda6fb572007-10-24 17:23:42 -070082
83#if defined(CONFIG_PM) || defined(CONFIG_PCI)
Michael Hanselmannd576bb92007-05-31 23:34:27 +020084static int ohci_restart (struct ohci_hcd *ohci);
David Brownellda6fb572007-10-24 17:23:42 -070085#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Libin Yangab1666c2008-08-08 15:03:31 +080087#ifdef CONFIG_PCI
88static void quirk_amd_pll(int state);
89static void amd_iso_dev_put(void);
90#else
91static inline void quirk_amd_pll(int state)
92{
93 return;
94}
95static inline void amd_iso_dev_put(void)
96{
97 return;
98}
99#endif
100
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#include "ohci-hub.c"
103#include "ohci-dbg.c"
104#include "ohci-mem.c"
105#include "ohci-q.c"
106
107
108/*
109 * On architectures with edge-triggered interrupts we must never return
110 * IRQ_NONE.
111 */
112#if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
113#define IRQ_NOTMINE IRQ_HANDLED
114#else
115#define IRQ_NOTMINE IRQ_NONE
116#endif
117
118
119/* Some boards misreport power switching/overcurrent */
120static int distrust_firmware = 1;
121module_param (distrust_firmware, bool, 0);
122MODULE_PARM_DESC (distrust_firmware,
123 "true to distrust firmware power/overcurrent setup");
124
125/* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
126static int no_handshake = 0;
127module_param (no_handshake, bool, 0);
128MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
129
130/*-------------------------------------------------------------------------*/
131
132/*
133 * queue up an urb for anything except the root hub
134 */
135static int ohci_urb_enqueue (
136 struct usb_hcd *hcd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400138 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139) {
140 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
141 struct ed *ed;
142 urb_priv_t *urb_priv;
143 unsigned int pipe = urb->pipe;
144 int i, size = 0;
145 unsigned long flags;
146 int retval = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#ifdef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -0400149 urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#endif
David Brownelldd9048a2006-12-05 03:18:31 -0800151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 /* every endpoint has a ed, locate and maybe (re)initialize it */
Alan Sterne9df41c2007-08-08 11:48:02 -0400153 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return -ENOMEM;
155
156 /* for the private part of the URB we need the number of TDs (size) */
157 switch (ed->type) {
158 case PIPE_CONTROL:
159 /* td_submit_urb() doesn't yet handle these */
160 if (urb->transfer_buffer_length > 4096)
161 return -EMSGSIZE;
162
163 /* 1 TD for setup, 1 for ACK, plus ... */
164 size = 2;
165 /* FALLTHROUGH */
166 // case PIPE_INTERRUPT:
167 // case PIPE_BULK:
168 default:
169 /* one TD for every 4096 Bytes (can be upto 8K) */
170 size += urb->transfer_buffer_length / 4096;
171 /* ... and for any remaining bytes ... */
172 if ((urb->transfer_buffer_length % 4096) != 0)
173 size++;
174 /* ... and maybe a zero length packet to wrap it up */
175 if (size == 0)
176 size++;
177 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
178 && (urb->transfer_buffer_length
179 % usb_maxpacket (urb->dev, pipe,
180 usb_pipeout (pipe))) == 0)
181 size++;
182 break;
183 case PIPE_ISOCHRONOUS: /* number of packets from URB */
184 size = urb->number_of_packets;
185 break;
186 }
187
188 /* allocate the private part of the URB */
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700189 urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 mem_flags);
191 if (!urb_priv)
192 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 INIT_LIST_HEAD (&urb_priv->pending);
194 urb_priv->length = size;
David Brownelldd9048a2006-12-05 03:18:31 -0800195 urb_priv->ed = ed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 /* allocate the TDs (deferring hash chain updates) */
198 for (i = 0; i < size; i++) {
199 urb_priv->td [i] = td_alloc (ohci, mem_flags);
200 if (!urb_priv->td [i]) {
201 urb_priv->length = i;
202 urb_free_priv (ohci, urb_priv);
203 return -ENOMEM;
204 }
David Brownelldd9048a2006-12-05 03:18:31 -0800205 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 spin_lock_irqsave (&ohci->lock, flags);
208
209 /* don't submit to a dead HC */
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100210 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
211 retval = -ENODEV;
212 goto fail;
213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 if (!HC_IS_RUNNING(hcd->state)) {
215 retval = -ENODEV;
216 goto fail;
217 }
Alan Sterne9df41c2007-08-08 11:48:02 -0400218 retval = usb_hcd_link_urb_to_ep(hcd, urb);
219 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 /* schedule the ed if needed */
223 if (ed->state == ED_IDLE) {
224 retval = ed_schedule (ohci, ed);
Alan Sterne9df41c2007-08-08 11:48:02 -0400225 if (retval < 0) {
226 usb_hcd_unlink_urb_from_ep(hcd, urb);
227 goto fail;
228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if (ed->type == PIPE_ISOCHRONOUS) {
230 u16 frame = ohci_frame_no(ohci);
231
232 /* delay a few frames before the first TD */
233 frame += max_t (u16, 8, ed->interval);
234 frame &= ~(ed->interval - 1);
235 frame |= ed->branch;
236 urb->start_frame = frame;
237
238 /* yes, only URB_ISO_ASAP is supported, and
239 * urb->start_frame is never used as input.
240 */
241 }
242 } else if (ed->type == PIPE_ISOCHRONOUS)
243 urb->start_frame = ed->last_iso + ed->interval;
244
245 /* fill the TDs and link them to the ed; and
246 * enable that part of the schedule, if needed
247 * and update count of queued periodic urbs
248 */
249 urb->hcpriv = urb_priv;
250 td_submit_urb (ohci, urb);
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252fail:
253 if (retval)
254 urb_free_priv (ohci, urb_priv);
255 spin_unlock_irqrestore (&ohci->lock, flags);
256 return retval;
257}
258
259/*
Alan Stern55d84962007-08-24 15:40:34 -0400260 * decouple the URB from the HC queues (TDs, urb_priv).
261 * reporting is always done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 * asynchronously, and we might be dealing with an urb that's
263 * partially transferred, or an ED with other urbs being unlinked.
264 */
Alan Sterne9df41c2007-08-08 11:48:02 -0400265static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
267 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
268 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400269 int rc;
David Brownelldd9048a2006-12-05 03:18:31 -0800270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#ifdef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -0400272 urb_print(urb, "UNLINK", 1, status);
David Brownelldd9048a2006-12-05 03:18:31 -0800273#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275 spin_lock_irqsave (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400276 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
277 if (rc) {
278 ; /* Do nothing */
279 } else if (HC_IS_RUNNING(hcd->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 urb_priv_t *urb_priv;
281
282 /* Unless an IRQ completed the unlink while it was being
283 * handed to us, flag it for unlink and giveback, and force
284 * some upcoming INTR_SF to call finish_unlinks()
285 */
286 urb_priv = urb->hcpriv;
287 if (urb_priv) {
288 if (urb_priv->ed->state == ED_OPER)
289 start_ed_unlink (ohci, urb_priv->ed);
290 }
291 } else {
292 /*
293 * with HC dead, we won't respect hc queue pointers
294 * any more ... just clean up every urb's memory.
295 */
296 if (urb->hcpriv)
Alan Stern55d84962007-08-24 15:40:34 -0400297 finish_urb(ohci, urb, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299 spin_unlock_irqrestore (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400300 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
303/*-------------------------------------------------------------------------*/
304
305/* frees config/altsetting state for endpoints,
306 * including ED memory, dummy TD, and bulk/intr data toggle
307 */
308
309static void
310ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
311{
312 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
313 unsigned long flags;
314 struct ed *ed = ep->hcpriv;
315 unsigned limit = 1000;
316
317 /* ASSERT: any requests/urbs are being unlinked */
318 /* ASSERT: nobody can be submitting urbs for this any more */
319
320 if (!ed)
321 return;
322
323rescan:
324 spin_lock_irqsave (&ohci->lock, flags);
325
326 if (!HC_IS_RUNNING (hcd->state)) {
327sanitize:
328 ed->state = ED_IDLE;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700329 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
330 ohci->eds_scheduled--;
David Howells7d12e782006-10-05 14:55:46 +0100331 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333
334 switch (ed->state) {
335 case ED_UNLINK: /* wait for hw to finish? */
336 /* major IRQ delivery trouble loses INTR_SF too... */
337 if (limit-- == 0) {
Mike Nuss89a0fd12007-08-01 13:24:30 -0700338 ohci_warn(ohci, "ED unlink timeout\n");
339 if (quirk_zfmicro(ohci)) {
340 ohci_warn(ohci, "Attempting ZF TD recovery\n");
341 ohci->ed_to_check = ed;
342 ohci->zf_delay = 2;
343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 goto sanitize;
345 }
346 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700347 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 goto rescan;
349 case ED_IDLE: /* fully unlinked */
350 if (list_empty (&ed->td_list)) {
351 td_free (ohci, ed->dummy);
352 ed_free (ohci, ed);
353 break;
354 }
355 /* else FALL THROUGH */
356 default:
357 /* caller was supposed to have unlinked any requests;
358 * that's not our job. can't recover; must leak ed.
359 */
360 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
361 ed, ep->desc.bEndpointAddress, ed->state,
362 list_empty (&ed->td_list) ? "" : " (has tds)");
363 td_free (ohci, ed->dummy);
364 break;
365 }
366 ep->hcpriv = NULL;
367 spin_unlock_irqrestore (&ohci->lock, flags);
368 return;
369}
370
371static int ohci_get_frame (struct usb_hcd *hcd)
372{
373 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
374
375 return ohci_frame_no(ohci);
376}
377
378static void ohci_usb_reset (struct ohci_hcd *ohci)
379{
380 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
381 ohci->hc_control &= OHCI_CTRL_RWC;
382 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
383}
384
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700385/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700386 * other cases where the next software may expect clean state from the
387 * "firmware". this is bus-neutral, unlike shutdown() methods.
388 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700389static void
390ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700391{
392 struct ohci_hcd *ohci;
393
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700394 ohci = hcd_to_ohci (hcd);
David Brownellf4df0e32005-04-23 12:49:16 -0700395 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
396 ohci_usb_reset (ohci);
397 /* flush the writes */
398 (void) ohci_readl (ohci, &ohci->regs->control);
David Brownellf4df0e32005-04-23 12:49:16 -0700399}
400
Mike Nuss89a0fd12007-08-01 13:24:30 -0700401static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
402{
403 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
404 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
405 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
406 && !list_empty(&ed->td_list);
407}
408
409/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
410 * an interrupt TD but neglects to add it to the donelist. On systems with
411 * this chipset, we need to periodically check the state of the queues to look
412 * for such "lost" TDs.
413 */
414static void unlink_watchdog_func(unsigned long _ohci)
415{
David Brownellda6fb572007-10-24 17:23:42 -0700416 unsigned long flags;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700417 unsigned max;
418 unsigned seen_count = 0;
419 unsigned i;
420 struct ed **seen = NULL;
421 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
422
423 spin_lock_irqsave(&ohci->lock, flags);
424 max = ohci->eds_scheduled;
425 if (!max)
426 goto done;
427
428 if (ohci->ed_to_check)
429 goto out;
430
431 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
432 if (!seen)
433 goto out;
434
435 for (i = 0; i < NUM_INTS; i++) {
436 struct ed *ed = ohci->periodic[i];
437
438 while (ed) {
439 unsigned temp;
440
441 /* scan this branch of the periodic schedule tree */
442 for (temp = 0; temp < seen_count; temp++) {
443 if (seen[temp] == ed) {
444 /* we've checked it and what's after */
445 ed = NULL;
446 break;
447 }
448 }
449 if (!ed)
450 break;
451 seen[seen_count++] = ed;
452 if (!check_ed(ohci, ed)) {
453 ed = ed->ed_next;
454 continue;
455 }
456
457 /* HC's TD list is empty, but HCD sees at least one
458 * TD that's not been sent through the donelist.
459 */
460 ohci->ed_to_check = ed;
461 ohci->zf_delay = 2;
462
463 /* The HC may wait until the next frame to report the
464 * TD as done through the donelist and INTR_WDH. (We
465 * just *assume* it's not a multi-TD interrupt URB;
466 * those could defer the IRQ more than one frame, using
467 * DI...) Check again after the next INTR_SF.
468 */
469 ohci_writel(ohci, OHCI_INTR_SF,
470 &ohci->regs->intrstatus);
471 ohci_writel(ohci, OHCI_INTR_SF,
472 &ohci->regs->intrenable);
473
474 /* flush those writes */
475 (void) ohci_readl(ohci, &ohci->regs->control);
476
477 goto out;
478 }
479 }
480out:
481 kfree(seen);
482 if (ohci->eds_scheduled)
Richard Kennedy9cebcdc2008-03-28 14:50:30 -0700483 mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700484done:
485 spin_unlock_irqrestore(&ohci->lock, flags);
486}
487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488/*-------------------------------------------------------------------------*
489 * HC functions
490 *-------------------------------------------------------------------------*/
491
492/* init memory, and kick BIOS/SMM off */
493
494static int ohci_init (struct ohci_hcd *ohci)
495{
496 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800497 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400499 if (distrust_firmware)
500 ohci->flags |= OHCI_QUIRK_HUB_POWER;
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 disable (ohci);
David Brownell6a9062f2006-01-23 15:28:07 -0800503 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
David Brownell6a9062f2006-01-23 15:28:07 -0800505 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
506 * was never needed for most non-PCI systems ... remove the code?
507 */
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509#ifndef IR_DISABLE
510 /* SMM owns the HC? not for long! */
511 if (!no_handshake && ohci_readl (ohci,
512 &ohci->regs->control) & OHCI_CTRL_IR) {
513 u32 temp;
514
515 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
516
517 /* this timeout is arbitrary. we make it long, so systems
518 * depending on usb keyboards may be usable even if the
519 * BIOS/SMM code seems pretty broken.
520 */
521 temp = 500; /* arbitrary: five seconds */
522
523 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
524 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
525 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
526 msleep (10);
527 if (--temp == 0) {
528 ohci_err (ohci, "USB HC takeover failed!"
529 " (BIOS/SMM bug)\n");
530 return -EBUSY;
531 }
532 }
533 ohci_usb_reset (ohci);
534 }
535#endif
536
537 /* Disable HC interrupts */
538 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800539
540 /* flush the writes, and save key bits like RWC */
541 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
542 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
David Brownellfdd13b32005-08-31 11:52:57 -0700544 /* Read the number of ports unless overridden */
545 if (ohci->num_ports == 0)
546 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 if (ohci->hcca)
549 return 0;
550
David Brownell6a9062f2006-01-23 15:28:07 -0800551 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
553 if (!ohci->hcca)
554 return -ENOMEM;
555
556 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800557 ohci_stop (hcd);
558 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800559 create_debug_files (ohci);
560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
565/*-------------------------------------------------------------------------*/
566
567/* Start an OHCI controller, set the BUS operational
568 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800569 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 */
571static int ohci_run (struct ohci_hcd *ohci)
572{
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400573 u32 mask, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800575 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 disable (ohci);
578
579 /* boot firmware should have set this up (5.1.1.3.1) */
580 if (first) {
581
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400582 val = ohci_readl (ohci, &ohci->regs->fminterval);
583 ohci->fminterval = val & 0x3fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if (ohci->fminterval != FI)
585 ohci_dbg (ohci, "fminterval delta %d\n",
586 ohci->fminterval - FI);
587 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
588 /* also: power/overcurrent flags in roothub.a */
589 }
590
Alan Stern6fd90862008-12-17 17:20:38 -0500591 /* Reset USB nearly "by the book". RemoteWakeupConnected has
592 * to be checked in case boot firmware (BIOS/SMM/...) has set up
593 * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
594 * If the bus glue detected wakeup capability then it should
Alan Sternbcca06e2009-01-13 11:35:54 -0500595 * already be enabled; if so we'll just enable it again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 */
Alan Sternbcca06e2009-01-13 11:35:54 -0500597 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
598 device_set_wakeup_capable(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
601 case OHCI_USB_OPER:
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400602 val = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 break;
604 case OHCI_USB_SUSPEND:
605 case OHCI_USB_RESUME:
606 ohci->hc_control &= OHCI_CTRL_RWC;
607 ohci->hc_control |= OHCI_USB_RESUME;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400608 val = 10 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 break;
610 // case OHCI_USB_RESET:
611 default:
612 ohci->hc_control &= OHCI_CTRL_RWC;
613 ohci->hc_control |= OHCI_USB_RESET;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400614 val = 50 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 break;
616 }
617 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
618 // flush the writes
619 (void) ohci_readl (ohci, &ohci->regs->control);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400620 msleep(val);
Alan Stern383975d2007-05-04 11:52:40 -0400621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
623
624 /* 2msec timelimit here means no irqs/preempt */
625 spin_lock_irq (&ohci->lock);
626
627retry:
628 /* HC Reset requires max 10 us delay */
629 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400630 val = 30; /* ... allow extra time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400632 if (--val == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 spin_unlock_irq (&ohci->lock);
634 ohci_err (ohci, "USB HC reset timed out!\n");
635 return -1;
636 }
637 udelay (1);
638 }
639
640 /* now we're in the SUSPEND state ... must go OPERATIONAL
641 * within 2msec else HC enters RESUME
642 *
643 * ... but some hardware won't init fmInterval "by the book"
644 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
645 * this if we write fmInterval after we're OPERATIONAL.
646 * Unclear about ALi, ServerWorks, and others ... this could
647 * easily be a longstanding bug in chip init on Linux.
648 */
649 if (ohci->flags & OHCI_QUIRK_INITRESET) {
650 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
651 // flush those writes
652 (void) ohci_readl (ohci, &ohci->regs->control);
653 }
654
655 /* Tell the controller where the control and bulk lists are
656 * The lists are empty now. */
657 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
658 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
659
660 /* a reset clears this */
661 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
662
663 periodic_reinit (ohci);
664
665 /* some OHCI implementations are finicky about how they init.
666 * bogus values here mean not even enumeration could work.
667 */
668 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
669 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
670 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
671 ohci->flags |= OHCI_QUIRK_INITRESET;
672 ohci_dbg (ohci, "enabling initreset quirk\n");
673 goto retry;
674 }
675 spin_unlock_irq (&ohci->lock);
676 ohci_err (ohci, "init err (%08x %04x)\n",
677 ohci_readl (ohci, &ohci->regs->fminterval),
678 ohci_readl (ohci, &ohci->regs->periodicstart));
679 return -EOVERFLOW;
680 }
681
David Brownelld4139842006-08-04 11:31:55 -0700682 /* use rhsc irqs after khubd is fully initialized */
683 hcd->poll_rh = 1;
684 hcd->uses_new_polling = 1;
685
686 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700688 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
689 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
David Brownell6a9062f2006-01-23 15:28:07 -0800690 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 /* wake on ConnectStatusChange, matching external hubs */
693 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
694
695 /* Choose the interrupts we care about now, others later on demand */
696 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700697 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 ohci_writel (ohci, mask, &ohci->regs->intrenable);
699
700 /* handle root hub init quirks ... */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400701 val = roothub_a (ohci);
702 val &= ~(RH_A_PSM | RH_A_OCPM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
704 /* NSC 87560 and maybe others */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400705 val |= RH_A_NOCP;
706 val &= ~(RH_A_POTPGT | RH_A_NPS);
707 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400708 } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
709 (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 /* hub power always on; required for AMD-756 and some
711 * Mac platforms. ganged overcurrent reporting, if any.
712 */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400713 val |= RH_A_NPS;
714 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 }
716 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400717 ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 &ohci->regs->roothub.b);
719 // flush those writes
720 (void) ohci_readl (ohci, &ohci->regs->control);
721
David Brownelld4139842006-08-04 11:31:55 -0700722 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 spin_unlock_irq (&ohci->lock);
724
725 // POTPGT delay is bits 24-31, in 2 ms units.
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400726 mdelay ((val >> 23) & 0x1fe);
David Brownell6a9062f2006-01-23 15:28:07 -0800727 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Mike Nuss89a0fd12007-08-01 13:24:30 -0700729 if (quirk_zfmicro(ohci)) {
730 /* Create timer to watch for bad queue state on ZF Micro */
731 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
732 (unsigned long) ohci);
733
734 ohci->eds_scheduled = 0;
735 ohci->ed_to_check = NULL;
736 }
737
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 ohci_dump (ohci, 1);
739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 return 0;
741}
742
743/*-------------------------------------------------------------------------*/
744
745/* an interrupt happens */
746
David Howells7d12e782006-10-05 14:55:46 +0100747static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
749 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
750 struct ohci_regs __iomem *regs = ohci->regs;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700751 int ints;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800753 /* Read interrupt status (and flush pending writes). We ignore the
754 * optimization of checking the LSB of hcca->done_head; it doesn't
755 * work on all systems (edge triggering for OHCI can be a factor).
Mike Nuss89a0fd12007-08-01 13:24:30 -0700756 */
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800757 ints = ohci_readl(ohci, &regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800759 /* Check for an all 1's result which is a typical consequence
760 * of dead, unclocked, or unplugged (CardBus...) devices
761 */
762 if (ints == ~(u32)0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 disable (ohci);
764 ohci_dbg (ohci, "device removed!\n");
765 return IRQ_HANDLED;
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800766 }
767
768 /* We only care about interrupts that are enabled */
769 ints &= ohci_readl(ohci, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 /* interrupt for some other device? */
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800772 if (ints == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 if (ints & OHCI_INTR_UE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 // e.g. due to PCI Master/Target Abort
Mike Nuss89a0fd12007-08-01 13:24:30 -0700777 if (quirk_nec(ohci)) {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200778 /* Workaround for a silicon bug in some NEC chips used
779 * in Apple's PowerBooks. Adapted from Darwin code.
780 */
781 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
782
783 ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
784
785 schedule_work (&ohci->nec_work);
786 } else {
787 disable (ohci);
788 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 ohci_dump (ohci, 1);
792 ohci_usb_reset (ohci);
793 }
794
Alan Stern583cead2006-10-24 12:04:22 -0400795 if (ints & OHCI_INTR_RHSC) {
796 ohci_vdbg(ohci, "rhsc\n");
797 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
798 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
799 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400800
801 /* NOTE: Vendors didn't always make the same implementation
802 * choices for RHSC. Many followed the spec; RHSC triggers
803 * on an edge, like setting and maybe clearing a port status
804 * change bit. With others it's level-triggered, active
805 * until khubd clears all the port status change bits. We'll
806 * always disable it here and rely on polling until khubd
807 * re-enables it.
808 */
809 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400810 usb_hcd_poll_rh_status(hcd);
811 }
812
813 /* For connect and disconnect events, we expect the controller
814 * to turn on RHSC along with RD. But for remote wakeup events
815 * this might not happen.
816 */
817 else if (ints & OHCI_INTR_RD) {
818 ohci_vdbg(ohci, "resume detect\n");
819 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern8d1a2432006-09-26 14:46:16 -0400820 hcd->poll_rh = 1;
821 if (ohci->autostop) {
822 spin_lock (&ohci->lock);
823 ohci_rh_resume (ohci);
824 spin_unlock (&ohci->lock);
825 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700826 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
828
829 if (ints & OHCI_INTR_WDH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100831 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 spin_unlock (&ohci->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 }
David Brownelldd9048a2006-12-05 03:18:31 -0800834
Mike Nuss89a0fd12007-08-01 13:24:30 -0700835 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
836 spin_lock(&ohci->lock);
837 if (ohci->ed_to_check) {
838 struct ed *ed = ohci->ed_to_check;
839
840 if (check_ed(ohci, ed)) {
841 /* HC thinks the TD list is empty; HCD knows
842 * at least one TD is outstanding
843 */
844 if (--ohci->zf_delay == 0) {
845 struct td *td = list_entry(
846 ed->td_list.next,
847 struct td, td_list);
848 ohci_warn(ohci,
849 "Reclaiming orphan TD %p\n",
850 td);
851 takeback_td(ohci, td);
852 ohci->ed_to_check = NULL;
853 }
854 } else
855 ohci->ed_to_check = NULL;
856 }
857 spin_unlock(&ohci->lock);
858 }
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 /* could track INTR_SO to reduce available PCI/... bandwidth */
861
862 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
863 * when there's still unlinking to be done (next frame).
864 */
865 spin_lock (&ohci->lock);
866 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100867 finish_unlinks (ohci, ohci_frame_no(ohci));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700868 if ((ints & OHCI_INTR_SF) != 0
869 && !ohci->ed_rm_list
870 && !ohci->ed_to_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 && HC_IS_RUNNING(hcd->state))
David Brownelldd9048a2006-12-05 03:18:31 -0800872 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 spin_unlock (&ohci->lock);
874
875 if (HC_IS_RUNNING(hcd->state)) {
876 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800877 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 // flush those writes
879 (void) ohci_readl (ohci, &ohci->regs->control);
880 }
881
882 return IRQ_HANDLED;
883}
884
885/*-------------------------------------------------------------------------*/
886
887static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800888{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 ohci_dump (ohci, 1);
892
893 flush_scheduled_work();
894
895 ohci_usb_reset (ohci);
896 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700897 free_irq(hcd->irq, hcd);
898 hcd->irq = -1;
899
Mike Nuss89a0fd12007-08-01 13:24:30 -0700900 if (quirk_zfmicro(ohci))
901 del_timer(&ohci->unlink_watchdog);
Libin Yangab1666c2008-08-08 15:03:31 +0800902 if (quirk_amdiso(ohci))
903 amd_iso_dev_put();
Mike Nuss89a0fd12007-08-01 13:24:30 -0700904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 ohci_mem_cleanup (ohci);
907 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800908 dma_free_coherent (hcd->self.controller,
909 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 ohci->hcca, ohci->hcca_dma);
911 ohci->hcca = NULL;
912 ohci->hcca_dma = 0;
913 }
914}
915
916/*-------------------------------------------------------------------------*/
917
David Brownellda6fb572007-10-24 17:23:42 -0700918#if defined(CONFIG_PM) || defined(CONFIG_PCI)
919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920/* must not be called from interrupt context */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921static int ohci_restart (struct ohci_hcd *ohci)
922{
923 int temp;
924 int i;
925 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 spin_lock_irq(&ohci->lock);
928 disable (ohci);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200929
930 /* Recycle any "live" eds/tds (and urbs). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 if (!list_empty (&ohci->pending))
932 ohci_dbg(ohci, "abort schedule...\n");
933 list_for_each_entry (priv, &ohci->pending, pending) {
934 struct urb *urb = priv->td[0]->urb;
935 struct ed *ed = priv->ed;
936
937 switch (ed->state) {
938 case ED_OPER:
939 ed->state = ED_UNLINK;
940 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
941 ed_deschedule (ohci, ed);
942
943 ed->ed_next = ohci->ed_rm_list;
944 ed->ed_prev = NULL;
945 ohci->ed_rm_list = ed;
946 /* FALLTHROUGH */
947 case ED_UNLINK:
948 break;
949 default:
950 ohci_dbg(ohci, "bogus ed %p state %d\n",
951 ed, ed->state);
952 }
953
Alan Stern55d84962007-08-24 15:40:34 -0400954 if (!urb->unlinked)
955 urb->unlinked = -ESHUTDOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
David Howells7d12e782006-10-05 14:55:46 +0100957 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 spin_unlock_irq(&ohci->lock);
959
960 /* paranoia, in case that didn't work: */
961
962 /* empty the interrupt branches */
963 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
964 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 /* no EDs to remove */
967 ohci->ed_rm_list = NULL;
968
David Brownelldd9048a2006-12-05 03:18:31 -0800969 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 ohci->ed_controltail = NULL;
971 ohci->ed_bulktail = NULL;
972
973 if ((temp = ohci_run (ohci)) < 0) {
974 ohci_err (ohci, "can't restart, %d\n", temp);
975 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 }
Alan Stern383975d2007-05-04 11:52:40 -0400977 ohci_dbg(ohci, "restart complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 return 0;
979}
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200980
David Brownellda6fb572007-10-24 17:23:42 -0700981#endif
982
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200983/*-------------------------------------------------------------------------*/
984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985MODULE_AUTHOR (DRIVER_AUTHOR);
Alan Stern2b70f072008-10-02 11:47:15 -0400986MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987MODULE_LICENSE ("GPL");
988
989#ifdef CONFIG_PCI
990#include "ohci-pci.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100991#define PCI_DRIVER ohci_pci_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992#endif
993
Eric Miao6381fad2008-06-02 10:05:30 +0800994#if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100996#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997#endif
998
Ben Dooks3ba5f382009-03-07 11:44:10 +0000999#if defined(CONFIG_ARCH_S3C2410) || defined(CONFIG_ARCH_S3C64XX)
Ben Dooks3eb0c5f2005-07-29 12:18:03 -07001000#include "ohci-s3c2410.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001001#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
Ben Dooks3eb0c5f2005-07-29 12:18:03 -07001002#endif
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004#ifdef CONFIG_ARCH_OMAP
1005#include "ohci-omap.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001006#define PLATFORM_DRIVER ohci_hcd_omap_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007#endif
1008
1009#ifdef CONFIG_ARCH_LH7A404
1010#include "ohci-lh7a404.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001011#define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012#endif
1013
eric miaoe77ec182007-12-12 09:07:47 +08001014#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015#include "ohci-pxa27x.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001016#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017#endif
1018
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001019#ifdef CONFIG_ARCH_EP93XX
1020#include "ohci-ep93xx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001021#define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001022#endif
1023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024#ifdef CONFIG_SOC_AU1X00
1025#include "ohci-au1xxx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001026#define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027#endif
1028
Vitaly Wool5151d042006-10-09 01:32:00 -07001029#ifdef CONFIG_PNX8550
1030#include "ohci-pnx8550.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001031#define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
Vitaly Wool5151d042006-10-09 01:32:00 -07001032#endif
1033
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034#ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
1035#include "ohci-ppc-soc.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001036#define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037#endif
1038
Andrew Victor58a0cd72006-12-01 14:51:13 +01001039#ifdef CONFIG_ARCH_AT91
Andrew Victor39a269c2006-01-22 10:32:13 -08001040#include "ohci-at91.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001041#define PLATFORM_DRIVER ohci_hcd_at91_driver
Andrew Victor39a269c2006-01-22 10:32:13 -08001042#endif
1043
Vitaly Wool60bbfc82006-06-29 18:28:18 +04001044#ifdef CONFIG_ARCH_PNX4008
1045#include "ohci-pnx4008.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001046#define PLATFORM_DRIVER usb_hcd_pnx4008_driver
Vitaly Wool60bbfc82006-06-29 18:28:18 +04001047#endif
1048
Yoshihiro Shimoda828d55c2008-01-11 22:56:15 +09001049#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
1050 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
Kuninori Morimoto4c3f4502009-03-12 08:40:15 +00001051 defined(CONFIG_CPU_SUBTYPE_SH7763) || \
1052 defined(CONFIG_CPU_SUBTYPE_SH7786)
Yoshihiro Shimoda828d55c2008-01-11 22:56:15 +09001053#include "ohci-sh.c"
1054#define PLATFORM_DRIVER ohci_hcd_sh_driver
1055#endif
1056
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001057
Sylvain Munaut495a6782006-12-13 21:09:55 +01001058#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1059#include "ohci-ppc-of.c"
1060#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1061#endif
1062
Geoff Levand6a6c9572007-01-15 20:12:10 -08001063#ifdef CONFIG_PPC_PS3
1064#include "ohci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001065#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
Geoff Levand6a6c9572007-01-15 20:12:10 -08001066#endif
1067
Michael Bueschc604e852007-10-09 23:47:17 -07001068#ifdef CONFIG_USB_OHCI_HCD_SSB
1069#include "ohci-ssb.c"
1070#define SSB_OHCI_DRIVER ssb_ohci_driver
1071#endif
1072
Magnus Dammf54aab62008-01-23 15:58:46 +09001073#ifdef CONFIG_MFD_SM501
1074#include "ohci-sm501.c"
Ben Dooks3ee38d82008-06-08 17:20:11 +01001075#define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
Magnus Dammf54aab62008-01-23 15:58:46 +09001076#endif
1077
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001078#ifdef CONFIG_MFD_TC6393XB
1079#include "ohci-tmio.c"
1080#define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
1081#endif
1082
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001083#if !defined(PCI_DRIVER) && \
1084 !defined(PLATFORM_DRIVER) && \
Sylvain Munaut495a6782006-12-13 21:09:55 +01001085 !defined(OF_PLATFORM_DRIVER) && \
Geoff Levand6a6c9572007-01-15 20:12:10 -08001086 !defined(SA1111_DRIVER) && \
Michael Bueschc604e852007-10-09 23:47:17 -07001087 !defined(PS3_SYSTEM_BUS_DRIVER) && \
Ben Dooks3ee38d82008-06-08 17:20:11 +01001088 !defined(SM501_OHCI_DRIVER) && \
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001089 !defined(TMIO_OHCI_DRIVER) && \
Michael Bueschc604e852007-10-09 23:47:17 -07001090 !defined(SSB_OHCI_DRIVER)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091#error "missing bus glue for ohci-hcd"
1092#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001093
1094static int __init ohci_hcd_mod_init(void)
1095{
1096 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001097
1098 if (usb_disabled())
1099 return -ENODEV;
1100
Alan Stern2b70f072008-10-02 11:47:15 -04001101 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001102 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1103 sizeof (struct ed), sizeof (struct td));
Alan Stern9beeee62008-10-02 11:48:13 -04001104 set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001105
Tony Jones684c19e2007-09-11 14:07:31 -07001106#ifdef DEBUG
Greg Kroah-Hartman485f4f32009-04-24 15:14:38 -07001107 ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
Tony Jones684c19e2007-09-11 14:07:31 -07001108 if (!ohci_debug_root) {
1109 retval = -ENOENT;
1110 goto error_debug;
1111 }
1112#endif
1113
Geoff Levand6a6c9572007-01-15 20:12:10 -08001114#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001115 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1116 if (retval < 0)
1117 goto error_ps3;
Geoff Levand6a6c9572007-01-15 20:12:10 -08001118#endif
1119
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001120#ifdef PLATFORM_DRIVER
1121 retval = platform_driver_register(&PLATFORM_DRIVER);
1122 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001123 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001124#endif
1125
Sylvain Munaut495a6782006-12-13 21:09:55 +01001126#ifdef OF_PLATFORM_DRIVER
1127 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
1128 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001129 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +01001130#endif
1131
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001132#ifdef SA1111_DRIVER
1133 retval = sa1111_driver_register(&SA1111_DRIVER);
1134 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001135 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001136#endif
1137
1138#ifdef PCI_DRIVER
1139 retval = pci_register_driver(&PCI_DRIVER);
1140 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001141 goto error_pci;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001142#endif
1143
Michael Bueschc604e852007-10-09 23:47:17 -07001144#ifdef SSB_OHCI_DRIVER
1145 retval = ssb_driver_register(&SSB_OHCI_DRIVER);
1146 if (retval)
1147 goto error_ssb;
1148#endif
1149
Ben Dooks3ee38d82008-06-08 17:20:11 +01001150#ifdef SM501_OHCI_DRIVER
1151 retval = platform_driver_register(&SM501_OHCI_DRIVER);
1152 if (retval < 0)
1153 goto error_sm501;
1154#endif
1155
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001156#ifdef TMIO_OHCI_DRIVER
1157 retval = platform_driver_register(&TMIO_OHCI_DRIVER);
1158 if (retval < 0)
1159 goto error_tmio;
1160#endif
1161
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001162 return retval;
1163
1164 /* Error path */
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001165#ifdef TMIO_OHCI_DRIVER
1166 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1167 error_tmio:
1168#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001169#ifdef SM501_OHCI_DRIVER
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001170 platform_driver_unregister(&SM501_OHCI_DRIVER);
Ben Dooks3ee38d82008-06-08 17:20:11 +01001171 error_sm501:
1172#endif
Michael Bueschc604e852007-10-09 23:47:17 -07001173#ifdef SSB_OHCI_DRIVER
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001174 ssb_driver_unregister(&SSB_OHCI_DRIVER);
Michael Bueschc604e852007-10-09 23:47:17 -07001175 error_ssb:
1176#endif
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001177#ifdef PCI_DRIVER
Michael Bueschc604e852007-10-09 23:47:17 -07001178 pci_unregister_driver(&PCI_DRIVER);
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001179 error_pci:
Sylvain Munaut495a6782006-12-13 21:09:55 +01001180#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001181#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001182 sa1111_driver_unregister(&SA1111_DRIVER);
1183 error_sa1111:
1184#endif
1185#ifdef OF_PLATFORM_DRIVER
1186 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1187 error_of_platform:
1188#endif
1189#ifdef PLATFORM_DRIVER
1190 platform_driver_unregister(&PLATFORM_DRIVER);
1191 error_platform:
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001192#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001193#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001194 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001195 error_ps3:
1196#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001197#ifdef DEBUG
1198 debugfs_remove(ohci_debug_root);
1199 ohci_debug_root = NULL;
1200 error_debug:
1201#endif
1202
Alan Stern9beeee62008-10-02 11:48:13 -04001203 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001204 return retval;
1205}
1206module_init(ohci_hcd_mod_init);
1207
1208static void __exit ohci_hcd_mod_exit(void)
1209{
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001210#ifdef TMIO_OHCI_DRIVER
1211 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1212#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001213#ifdef SM501_OHCI_DRIVER
1214 platform_driver_unregister(&SM501_OHCI_DRIVER);
1215#endif
Michael Bueschc604e852007-10-09 23:47:17 -07001216#ifdef SSB_OHCI_DRIVER
1217 ssb_driver_unregister(&SSB_OHCI_DRIVER);
1218#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001219#ifdef PCI_DRIVER
1220 pci_unregister_driver(&PCI_DRIVER);
1221#endif
1222#ifdef SA1111_DRIVER
1223 sa1111_driver_unregister(&SA1111_DRIVER);
1224#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001225#ifdef OF_PLATFORM_DRIVER
1226 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1227#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001228#ifdef PLATFORM_DRIVER
1229 platform_driver_unregister(&PLATFORM_DRIVER);
1230#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001231#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001232 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001233#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001234#ifdef DEBUG
1235 debugfs_remove(ohci_debug_root);
1236#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001237 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001238}
1239module_exit(ohci_hcd_mod_exit);
1240