blob: 501ecea4917f92a36b803506c6a219e6dfdab317 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Alan Stern578333a2011-06-15 16:32:46 -04002 * Open Host Controller Interface (OHCI) driver for USB.
3 *
4 * Maintainer: Alan Stern <stern@rowland.harvard.edu>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
7 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
David Brownelldd9048a2006-12-05 03:18:31 -08008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * [ Initialisation is based on Linus' ]
10 * [ uhci code and gregs ohci fragments ]
11 * [ (C) Copyright 1999 Linus Torvalds ]
12 * [ (C) Copyright 1999 Gregory P. Smith]
David Brownelldd9048a2006-12-05 03:18:31 -080013 *
14 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
16 * interfaces (though some non-x86 Intel chips use it). It supports
17 * smarter hardware than UHCI. A download link for the spec available
18 * through the http://www.usb.org website.
19 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * This file is licenced under the GPL.
21 */
David Brownelldd9048a2006-12-05 03:18:31 -080022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/pci.h>
26#include <linux/kernel.h>
27#include <linux/delay.h>
28#include <linux/ioport.h>
29#include <linux/sched.h>
30#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/errno.h>
32#include <linux/init.h>
33#include <linux/timer.h>
34#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/usb.h>
David Brownell3a16f7b2006-06-29 12:27:23 -070036#include <linux/usb/otg.h>
Eric Lescouet27729aa2010-04-24 23:21:52 +020037#include <linux/usb/hcd.h>
David Brownelldd9048a2006-12-05 03:18:31 -080038#include <linux/dma-mapping.h>
David Brownellf4df0e32005-04-23 12:49:16 -070039#include <linux/dmapool.h>
Michael Hanselmannd576bb92007-05-31 23:34:27 +020040#include <linux/workqueue.h>
Tony Jones684c19e2007-09-11 14:07:31 -070041#include <linux/debugfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <asm/io.h>
44#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/unaligned.h>
46#include <asm/byteorder.h>
47
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
50#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
51
52/*-------------------------------------------------------------------------*/
53
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +110054#undef OHCI_VERBOSE_DEBUG /* not always helpful */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/* For initializing controller (mask in an HCFS mode too) */
David Brownelld4139842006-08-04 11:31:55 -070057#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define OHCI_INTR_INIT \
David Brownelld4139842006-08-04 11:31:55 -070059 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
60 | OHCI_INTR_RD | OHCI_INTR_WDH)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#ifdef __hppa__
63/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
64#define IR_DISABLE
65#endif
66
67#ifdef CONFIG_ARCH_OMAP
68/* OMAP doesn't support IR (no SMM; not needed) */
69#define IR_DISABLE
70#endif
71
72/*-------------------------------------------------------------------------*/
73
74static const char hcd_name [] = "ohci_hcd";
75
David Brownelld4139842006-08-04 11:31:55 -070076#define STATECHANGE_DELAY msecs_to_jiffies(300)
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include "ohci.h"
Andiry Xuad935622011-03-01 14:57:05 +080079#include "pci-quirks.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81static void ohci_dump (struct ohci_hcd *ohci, int verbose);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static void ohci_stop (struct usb_hcd *hcd);
Libin Yangab1666c2008-08-08 15:03:31 +080083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#include "ohci-hub.c"
85#include "ohci-dbg.c"
86#include "ohci-mem.c"
87#include "ohci-q.c"
88
89
90/*
91 * On architectures with edge-triggered interrupts we must never return
92 * IRQ_NONE.
93 */
94#if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
95#define IRQ_NOTMINE IRQ_HANDLED
96#else
97#define IRQ_NOTMINE IRQ_NONE
98#endif
99
100
101/* Some boards misreport power switching/overcurrent */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030102static bool distrust_firmware = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103module_param (distrust_firmware, bool, 0);
104MODULE_PARM_DESC (distrust_firmware,
105 "true to distrust firmware power/overcurrent setup");
106
107/* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030108static bool no_handshake = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109module_param (no_handshake, bool, 0);
110MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
111
112/*-------------------------------------------------------------------------*/
113
114/*
115 * queue up an urb for anything except the root hub
116 */
117static int ohci_urb_enqueue (
118 struct usb_hcd *hcd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400120 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121) {
122 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
123 struct ed *ed;
124 urb_priv_t *urb_priv;
125 unsigned int pipe = urb->pipe;
126 int i, size = 0;
127 unsigned long flags;
128 int retval = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 /* every endpoint has a ed, locate and maybe (re)initialize it */
Alan Sterne9df41c2007-08-08 11:48:02 -0400131 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return -ENOMEM;
133
134 /* for the private part of the URB we need the number of TDs (size) */
135 switch (ed->type) {
136 case PIPE_CONTROL:
137 /* td_submit_urb() doesn't yet handle these */
138 if (urb->transfer_buffer_length > 4096)
139 return -EMSGSIZE;
140
141 /* 1 TD for setup, 1 for ACK, plus ... */
142 size = 2;
143 /* FALLTHROUGH */
144 // case PIPE_INTERRUPT:
145 // case PIPE_BULK:
146 default:
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300147 /* one TD for every 4096 Bytes (can be up to 8K) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 size += urb->transfer_buffer_length / 4096;
149 /* ... and for any remaining bytes ... */
150 if ((urb->transfer_buffer_length % 4096) != 0)
151 size++;
152 /* ... and maybe a zero length packet to wrap it up */
153 if (size == 0)
154 size++;
155 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
156 && (urb->transfer_buffer_length
157 % usb_maxpacket (urb->dev, pipe,
158 usb_pipeout (pipe))) == 0)
159 size++;
160 break;
161 case PIPE_ISOCHRONOUS: /* number of packets from URB */
162 size = urb->number_of_packets;
163 break;
164 }
165
166 /* allocate the private part of the URB */
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700167 urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 mem_flags);
169 if (!urb_priv)
170 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 INIT_LIST_HEAD (&urb_priv->pending);
172 urb_priv->length = size;
David Brownelldd9048a2006-12-05 03:18:31 -0800173 urb_priv->ed = ed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 /* allocate the TDs (deferring hash chain updates) */
176 for (i = 0; i < size; i++) {
177 urb_priv->td [i] = td_alloc (ohci, mem_flags);
178 if (!urb_priv->td [i]) {
179 urb_priv->length = i;
180 urb_free_priv (ohci, urb_priv);
181 return -ENOMEM;
182 }
David Brownelldd9048a2006-12-05 03:18:31 -0800183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 spin_lock_irqsave (&ohci->lock, flags);
186
187 /* don't submit to a dead HC */
Alan Stern541c7d42010-06-22 16:39:10 -0400188 if (!HCD_HW_ACCESSIBLE(hcd)) {
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100189 retval = -ENODEV;
190 goto fail;
191 }
Alan Sternb7463c72011-11-17 16:41:56 -0500192 if (ohci->rh_state != OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 retval = -ENODEV;
194 goto fail;
195 }
Alan Sterne9df41c2007-08-08 11:48:02 -0400196 retval = usb_hcd_link_urb_to_ep(hcd, urb);
197 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 /* schedule the ed if needed */
201 if (ed->state == ED_IDLE) {
202 retval = ed_schedule (ohci, ed);
Alan Sterne9df41c2007-08-08 11:48:02 -0400203 if (retval < 0) {
204 usb_hcd_unlink_urb_from_ep(hcd, urb);
205 goto fail;
206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 if (ed->type == PIPE_ISOCHRONOUS) {
208 u16 frame = ohci_frame_no(ohci);
209
210 /* delay a few frames before the first TD */
211 frame += max_t (u16, 8, ed->interval);
212 frame &= ~(ed->interval - 1);
213 frame |= ed->branch;
214 urb->start_frame = frame;
Alan Sterna8693422013-09-24 15:46:45 -0400215 ed->last_iso = frame + ed->interval * (size - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400217 } else if (ed->type == PIPE_ISOCHRONOUS) {
Alan Sterne19440172013-05-14 13:57:19 -0400218 u16 next = ohci_frame_no(ohci) + 1;
Alan Stern6a41b4d2012-10-01 10:32:15 -0400219 u16 frame = ed->last_iso + ed->interval;
Alan Sterna8693422013-09-24 15:46:45 -0400220 u16 length = ed->interval * (size - 1);
Alan Stern6a41b4d2012-10-01 10:32:15 -0400221
222 /* Behind the scheduling threshold? */
223 if (unlikely(tick_before(frame, next))) {
224
Alan Sterna8693422013-09-24 15:46:45 -0400225 /* URB_ISO_ASAP: Round up to the first available slot */
Alan Stern815fa7b2013-05-14 13:57:51 -0400226 if (urb->transfer_flags & URB_ISO_ASAP) {
Alan Stern6a41b4d2012-10-01 10:32:15 -0400227 frame += (next - frame + ed->interval - 1) &
228 -ed->interval;
229
230 /*
Alan Sterna8693422013-09-24 15:46:45 -0400231 * Not ASAP: Use the next slot in the stream,
232 * no matter what.
Alan Stern6a41b4d2012-10-01 10:32:15 -0400233 */
Alan Stern815fa7b2013-05-14 13:57:51 -0400234 } else {
Alan Stern815fa7b2013-05-14 13:57:51 -0400235 /*
236 * Some OHCI hardware doesn't handle late TDs
237 * correctly. After retiring them it proceeds
238 * to the next ED instead of the next TD.
239 * Therefore we have to omit the late TDs
240 * entirely.
241 */
242 urb_priv->td_cnt = DIV_ROUND_UP(
243 (u16) (next - frame),
244 ed->interval);
Alan Sterna8693422013-09-24 15:46:45 -0400245 if (urb_priv->td_cnt >= urb_priv->length) {
246 ++urb_priv->td_cnt; /* Mark it */
247 ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n",
248 urb, frame, length,
249 next);
250 }
Alan Stern815fa7b2013-05-14 13:57:51 -0400251 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400252 }
253 urb->start_frame = frame;
Alan Sterna8693422013-09-24 15:46:45 -0400254 ed->last_iso = frame + length;
Alan Stern6a41b4d2012-10-01 10:32:15 -0400255 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 /* fill the TDs and link them to the ed; and
258 * enable that part of the schedule, if needed
259 * and update count of queued periodic urbs
260 */
261 urb->hcpriv = urb_priv;
262 td_submit_urb (ohci, urb);
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264fail:
265 if (retval)
266 urb_free_priv (ohci, urb_priv);
267 spin_unlock_irqrestore (&ohci->lock, flags);
268 return retval;
269}
270
271/*
Alan Stern55d84962007-08-24 15:40:34 -0400272 * decouple the URB from the HC queues (TDs, urb_priv).
273 * reporting is always done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 * asynchronously, and we might be dealing with an urb that's
275 * partially transferred, or an ED with other urbs being unlinked.
276 */
Alan Sterne9df41c2007-08-08 11:48:02 -0400277static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
280 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400281 int rc;
David Brownelldd9048a2006-12-05 03:18:31 -0800282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 spin_lock_irqsave (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400284 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
285 if (rc) {
286 ; /* Do nothing */
Alan Sternb7463c72011-11-17 16:41:56 -0500287 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 urb_priv_t *urb_priv;
289
290 /* Unless an IRQ completed the unlink while it was being
291 * handed to us, flag it for unlink and giveback, and force
292 * some upcoming INTR_SF to call finish_unlinks()
293 */
294 urb_priv = urb->hcpriv;
295 if (urb_priv) {
296 if (urb_priv->ed->state == ED_OPER)
297 start_ed_unlink (ohci, urb_priv->ed);
298 }
299 } else {
300 /*
301 * with HC dead, we won't respect hc queue pointers
302 * any more ... just clean up every urb's memory.
303 */
304 if (urb->hcpriv)
Alan Stern55d84962007-08-24 15:40:34 -0400305 finish_urb(ohci, urb, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307 spin_unlock_irqrestore (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400308 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
311/*-------------------------------------------------------------------------*/
312
313/* frees config/altsetting state for endpoints,
314 * including ED memory, dummy TD, and bulk/intr data toggle
315 */
316
317static void
318ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
319{
320 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
321 unsigned long flags;
322 struct ed *ed = ep->hcpriv;
323 unsigned limit = 1000;
324
325 /* ASSERT: any requests/urbs are being unlinked */
326 /* ASSERT: nobody can be submitting urbs for this any more */
327
328 if (!ed)
329 return;
330
331rescan:
332 spin_lock_irqsave (&ohci->lock, flags);
333
Alan Sternb7463c72011-11-17 16:41:56 -0500334 if (ohci->rh_state != OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335sanitize:
336 ed->state = ED_IDLE;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700337 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
338 ohci->eds_scheduled--;
David Howells7d12e782006-10-05 14:55:46 +0100339 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
341
342 switch (ed->state) {
343 case ED_UNLINK: /* wait for hw to finish? */
344 /* major IRQ delivery trouble loses INTR_SF too... */
345 if (limit-- == 0) {
Mike Nuss89a0fd12007-08-01 13:24:30 -0700346 ohci_warn(ohci, "ED unlink timeout\n");
347 if (quirk_zfmicro(ohci)) {
348 ohci_warn(ohci, "Attempting ZF TD recovery\n");
349 ohci->ed_to_check = ed;
350 ohci->zf_delay = 2;
351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 goto sanitize;
353 }
354 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700355 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 goto rescan;
357 case ED_IDLE: /* fully unlinked */
358 if (list_empty (&ed->td_list)) {
359 td_free (ohci, ed->dummy);
360 ed_free (ohci, ed);
361 break;
362 }
363 /* else FALL THROUGH */
364 default:
365 /* caller was supposed to have unlinked any requests;
366 * that's not our job. can't recover; must leak ed.
367 */
368 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
369 ed, ep->desc.bEndpointAddress, ed->state,
370 list_empty (&ed->td_list) ? "" : " (has tds)");
371 td_free (ohci, ed->dummy);
372 break;
373 }
374 ep->hcpriv = NULL;
375 spin_unlock_irqrestore (&ohci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
378static int ohci_get_frame (struct usb_hcd *hcd)
379{
380 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
381
382 return ohci_frame_no(ohci);
383}
384
385static void ohci_usb_reset (struct ohci_hcd *ohci)
386{
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);
Alan Sternb7463c72011-11-17 16:41:56 -0500390 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700393/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700394 * other cases where the next software may expect clean state from the
395 * "firmware". this is bus-neutral, unlike shutdown() methods.
396 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700397static void
398ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700399{
400 struct ohci_hcd *ohci;
401
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700402 ohci = hcd_to_ohci (hcd);
Alan Sternc6187592011-11-17 16:41:45 -0500403 ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
Alan Stern3df71692010-09-10 16:37:05 -0400404
Alan Sternc6187592011-11-17 16:41:45 -0500405 /* Software reset, after which the controller goes into SUSPEND */
406 ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
407 ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */
408 udelay(10);
Alan Stern3df71692010-09-10 16:37:05 -0400409
Alan Sternc6187592011-11-17 16:41:45 -0500410 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
David Brownellf4df0e32005-04-23 12:49:16 -0700411}
412
Mike Nuss89a0fd12007-08-01 13:24:30 -0700413static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
414{
415 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
416 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
417 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
418 && !list_empty(&ed->td_list);
419}
420
421/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
422 * an interrupt TD but neglects to add it to the donelist. On systems with
423 * this chipset, we need to periodically check the state of the queues to look
424 * for such "lost" TDs.
425 */
426static void unlink_watchdog_func(unsigned long _ohci)
427{
David Brownellda6fb572007-10-24 17:23:42 -0700428 unsigned long flags;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700429 unsigned max;
430 unsigned seen_count = 0;
431 unsigned i;
432 struct ed **seen = NULL;
433 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
434
435 spin_lock_irqsave(&ohci->lock, flags);
436 max = ohci->eds_scheduled;
437 if (!max)
438 goto done;
439
440 if (ohci->ed_to_check)
441 goto out;
442
443 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
444 if (!seen)
445 goto out;
446
447 for (i = 0; i < NUM_INTS; i++) {
448 struct ed *ed = ohci->periodic[i];
449
450 while (ed) {
451 unsigned temp;
452
453 /* scan this branch of the periodic schedule tree */
454 for (temp = 0; temp < seen_count; temp++) {
455 if (seen[temp] == ed) {
456 /* we've checked it and what's after */
457 ed = NULL;
458 break;
459 }
460 }
461 if (!ed)
462 break;
463 seen[seen_count++] = ed;
464 if (!check_ed(ohci, ed)) {
465 ed = ed->ed_next;
466 continue;
467 }
468
469 /* HC's TD list is empty, but HCD sees at least one
470 * TD that's not been sent through the donelist.
471 */
472 ohci->ed_to_check = ed;
473 ohci->zf_delay = 2;
474
475 /* The HC may wait until the next frame to report the
476 * TD as done through the donelist and INTR_WDH. (We
477 * just *assume* it's not a multi-TD interrupt URB;
478 * those could defer the IRQ more than one frame, using
479 * DI...) Check again after the next INTR_SF.
480 */
481 ohci_writel(ohci, OHCI_INTR_SF,
482 &ohci->regs->intrstatus);
483 ohci_writel(ohci, OHCI_INTR_SF,
484 &ohci->regs->intrenable);
485
486 /* flush those writes */
487 (void) ohci_readl(ohci, &ohci->regs->control);
488
489 goto out;
490 }
491 }
492out:
493 kfree(seen);
494 if (ohci->eds_scheduled)
Richard Kennedy9cebcdc2008-03-28 14:50:30 -0700495 mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700496done:
497 spin_unlock_irqrestore(&ohci->lock, flags);
498}
499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500/*-------------------------------------------------------------------------*
501 * HC functions
502 *-------------------------------------------------------------------------*/
503
504/* init memory, and kick BIOS/SMM off */
505
506static int ohci_init (struct ohci_hcd *ohci)
507{
508 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800509 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400511 if (distrust_firmware)
512 ohci->flags |= OHCI_QUIRK_HUB_POWER;
513
Alan Sternb7463c72011-11-17 16:41:56 -0500514 ohci->rh_state = OHCI_RH_HALTED;
David Brownell6a9062f2006-01-23 15:28:07 -0800515 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
David Brownell6a9062f2006-01-23 15:28:07 -0800517 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
518 * was never needed for most non-PCI systems ... remove the code?
519 */
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#ifndef IR_DISABLE
522 /* SMM owns the HC? not for long! */
523 if (!no_handshake && ohci_readl (ohci,
524 &ohci->regs->control) & OHCI_CTRL_IR) {
525 u32 temp;
526
527 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
528
529 /* this timeout is arbitrary. we make it long, so systems
530 * depending on usb keyboards may be usable even if the
531 * BIOS/SMM code seems pretty broken.
532 */
533 temp = 500; /* arbitrary: five seconds */
534
535 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
536 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
537 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
538 msleep (10);
539 if (--temp == 0) {
540 ohci_err (ohci, "USB HC takeover failed!"
541 " (BIOS/SMM bug)\n");
542 return -EBUSY;
543 }
544 }
545 ohci_usb_reset (ohci);
546 }
547#endif
548
549 /* Disable HC interrupts */
550 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800551
552 /* flush the writes, and save key bits like RWC */
553 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
554 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
David Brownellfdd13b32005-08-31 11:52:57 -0700556 /* Read the number of ports unless overridden */
557 if (ohci->num_ports == 0)
558 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (ohci->hcca)
561 return 0;
562
David Brownell6a9062f2006-01-23 15:28:07 -0800563 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
565 if (!ohci->hcca)
566 return -ENOMEM;
567
568 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800569 ohci_stop (hcd);
570 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800571 create_debug_files (ohci);
572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}
576
577/*-------------------------------------------------------------------------*/
578
579/* Start an OHCI controller, set the BUS operational
580 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800581 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 */
583static int ohci_run (struct ohci_hcd *ohci)
584{
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400585 u32 mask, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800587 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Alan Sternb7463c72011-11-17 16:41:56 -0500589 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 /* boot firmware should have set this up (5.1.1.3.1) */
592 if (first) {
593
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400594 val = ohci_readl (ohci, &ohci->regs->fminterval);
595 ohci->fminterval = val & 0x3fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 if (ohci->fminterval != FI)
597 ohci_dbg (ohci, "fminterval delta %d\n",
598 ohci->fminterval - FI);
599 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
600 /* also: power/overcurrent flags in roothub.a */
601 }
602
Alan Stern6fd90862008-12-17 17:20:38 -0500603 /* Reset USB nearly "by the book". RemoteWakeupConnected has
604 * to be checked in case boot firmware (BIOS/SMM/...) has set up
605 * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
606 * If the bus glue detected wakeup capability then it should
Alan Sternbcca06e2009-01-13 11:35:54 -0500607 * already be enabled; if so we'll just enable it again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 */
Alan Sternbcca06e2009-01-13 11:35:54 -0500609 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
610 device_set_wakeup_capable(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
613 case OHCI_USB_OPER:
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400614 val = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 break;
616 case OHCI_USB_SUSPEND:
617 case OHCI_USB_RESUME:
618 ohci->hc_control &= OHCI_CTRL_RWC;
619 ohci->hc_control |= OHCI_USB_RESUME;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400620 val = 10 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 break;
622 // case OHCI_USB_RESET:
623 default:
624 ohci->hc_control &= OHCI_CTRL_RWC;
625 ohci->hc_control |= OHCI_USB_RESET;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400626 val = 50 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 break;
628 }
629 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
630 // flush the writes
631 (void) ohci_readl (ohci, &ohci->regs->control);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400632 msleep(val);
Alan Stern383975d2007-05-04 11:52:40 -0400633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
635
636 /* 2msec timelimit here means no irqs/preempt */
637 spin_lock_irq (&ohci->lock);
638
639retry:
640 /* HC Reset requires max 10 us delay */
641 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400642 val = 30; /* ... allow extra time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400644 if (--val == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 spin_unlock_irq (&ohci->lock);
646 ohci_err (ohci, "USB HC reset timed out!\n");
647 return -1;
648 }
649 udelay (1);
650 }
651
652 /* now we're in the SUSPEND state ... must go OPERATIONAL
653 * within 2msec else HC enters RESUME
654 *
655 * ... but some hardware won't init fmInterval "by the book"
656 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
657 * this if we write fmInterval after we're OPERATIONAL.
658 * Unclear about ALi, ServerWorks, and others ... this could
659 * easily be a longstanding bug in chip init on Linux.
660 */
661 if (ohci->flags & OHCI_QUIRK_INITRESET) {
662 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
663 // flush those writes
664 (void) ohci_readl (ohci, &ohci->regs->control);
665 }
666
667 /* Tell the controller where the control and bulk lists are
668 * The lists are empty now. */
669 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
670 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
671
672 /* a reset clears this */
673 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
674
675 periodic_reinit (ohci);
676
677 /* some OHCI implementations are finicky about how they init.
678 * bogus values here mean not even enumeration could work.
679 */
680 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
681 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
682 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
683 ohci->flags |= OHCI_QUIRK_INITRESET;
684 ohci_dbg (ohci, "enabling initreset quirk\n");
685 goto retry;
686 }
687 spin_unlock_irq (&ohci->lock);
688 ohci_err (ohci, "init err (%08x %04x)\n",
689 ohci_readl (ohci, &ohci->regs->fminterval),
690 ohci_readl (ohci, &ohci->regs->periodicstart));
691 return -EOVERFLOW;
692 }
693
David Brownelld4139842006-08-04 11:31:55 -0700694 /* use rhsc irqs after khubd is fully initialized */
Alan Stern541c7d42010-06-22 16:39:10 -0400695 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
David Brownelld4139842006-08-04 11:31:55 -0700696 hcd->uses_new_polling = 1;
697
698 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700700 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
701 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
Alan Sternb7463c72011-11-17 16:41:56 -0500702 ohci->rh_state = OHCI_RH_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704 /* wake on ConnectStatusChange, matching external hubs */
705 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
706
707 /* Choose the interrupts we care about now, others later on demand */
708 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700709 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 ohci_writel (ohci, mask, &ohci->regs->intrenable);
711
712 /* handle root hub init quirks ... */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400713 val = roothub_a (ohci);
714 val &= ~(RH_A_PSM | RH_A_OCPM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
716 /* NSC 87560 and maybe others */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400717 val |= RH_A_NOCP;
718 val &= ~(RH_A_POTPGT | RH_A_NPS);
719 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400720 } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
721 (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 /* hub power always on; required for AMD-756 and some
723 * Mac platforms. ganged overcurrent reporting, if any.
724 */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400725 val |= RH_A_NPS;
726 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 }
728 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400729 ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 &ohci->regs->roothub.b);
731 // flush those writes
732 (void) ohci_readl (ohci, &ohci->regs->control);
733
David Brownelld4139842006-08-04 11:31:55 -0700734 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 spin_unlock_irq (&ohci->lock);
736
737 // POTPGT delay is bits 24-31, in 2 ms units.
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400738 mdelay ((val >> 23) & 0x1fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Mike Nuss89a0fd12007-08-01 13:24:30 -0700740 if (quirk_zfmicro(ohci)) {
741 /* Create timer to watch for bad queue state on ZF Micro */
742 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
743 (unsigned long) ohci);
744
745 ohci->eds_scheduled = 0;
746 ohci->ed_to_check = NULL;
747 }
748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 ohci_dump (ohci, 1);
750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 return 0;
752}
753
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530754/* ohci_setup routine for generic controller initialization */
755
756int ohci_setup(struct usb_hcd *hcd)
757{
758 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
759
760 ohci_hcd_init(ohci);
761
762 return ohci_init(ohci);
763}
764EXPORT_SYMBOL_GPL(ohci_setup);
765
766/* ohci_start routine for generic controller start of all OHCI bus glue */
767static int ohci_start(struct usb_hcd *hcd)
768{
769 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
770 int ret;
771
772 ret = ohci_run(ohci);
773 if (ret < 0) {
774 ohci_err(ohci, "can't start\n");
775 ohci_stop(hcd);
776 }
777 return ret;
778}
779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780/*-------------------------------------------------------------------------*/
781
782/* an interrupt happens */
783
David Howells7d12e782006-10-05 14:55:46 +0100784static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
786 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
787 struct ohci_regs __iomem *regs = ohci->regs;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700788 int ints;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800790 /* Read interrupt status (and flush pending writes). We ignore the
791 * optimization of checking the LSB of hcca->done_head; it doesn't
792 * work on all systems (edge triggering for OHCI can be a factor).
Mike Nuss89a0fd12007-08-01 13:24:30 -0700793 */
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800794 ints = ohci_readl(ohci, &regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800796 /* Check for an all 1's result which is a typical consequence
797 * of dead, unclocked, or unplugged (CardBus...) devices
798 */
799 if (ints == ~(u32)0) {
Alan Sternb7463c72011-11-17 16:41:56 -0500800 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 ohci_dbg (ohci, "device removed!\n");
Alan Stern69fff592011-05-17 17:27:12 -0400802 usb_hc_died(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return IRQ_HANDLED;
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800804 }
805
806 /* We only care about interrupts that are enabled */
807 ints &= ohci_readl(ohci, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 /* interrupt for some other device? */
Alan Sternb7463c72011-11-17 16:41:56 -0500810 if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 if (ints & OHCI_INTR_UE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 // e.g. due to PCI Master/Target Abort
Mike Nuss89a0fd12007-08-01 13:24:30 -0700815 if (quirk_nec(ohci)) {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200816 /* Workaround for a silicon bug in some NEC chips used
817 * in Apple's PowerBooks. Adapted from Darwin code.
818 */
819 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
820
821 ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
822
823 schedule_work (&ohci->nec_work);
824 } else {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200825 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
Alan Sternb7463c72011-11-17 16:41:56 -0500826 ohci->rh_state = OHCI_RH_HALTED;
Alan Stern69fff592011-05-17 17:27:12 -0400827 usb_hc_died(hcd);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 ohci_dump (ohci, 1);
831 ohci_usb_reset (ohci);
832 }
833
Alan Stern583cead2006-10-24 12:04:22 -0400834 if (ints & OHCI_INTR_RHSC) {
Oliver Neukumd2c42542013-11-18 13:22:58 +0100835 ohci_dbg(ohci, "rhsc\n");
Alan Stern583cead2006-10-24 12:04:22 -0400836 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
837 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
838 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400839
840 /* NOTE: Vendors didn't always make the same implementation
841 * choices for RHSC. Many followed the spec; RHSC triggers
842 * on an edge, like setting and maybe clearing a port status
843 * change bit. With others it's level-triggered, active
844 * until khubd clears all the port status change bits. We'll
845 * always disable it here and rely on polling until khubd
846 * re-enables it.
847 */
848 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400849 usb_hcd_poll_rh_status(hcd);
850 }
851
852 /* For connect and disconnect events, we expect the controller
853 * to turn on RHSC along with RD. But for remote wakeup events
854 * this might not happen.
855 */
856 else if (ints & OHCI_INTR_RD) {
Oliver Neukumd2c42542013-11-18 13:22:58 +0100857 ohci_dbg(ohci, "resume detect\n");
Alan Stern583cead2006-10-24 12:04:22 -0400858 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern541c7d42010-06-22 16:39:10 -0400859 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
Alan Stern8d1a2432006-09-26 14:46:16 -0400860 if (ohci->autostop) {
861 spin_lock (&ohci->lock);
862 ohci_rh_resume (ohci);
863 spin_unlock (&ohci->lock);
864 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700865 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867
868 if (ints & OHCI_INTR_WDH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100870 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 spin_unlock (&ohci->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
David Brownelldd9048a2006-12-05 03:18:31 -0800873
Mike Nuss89a0fd12007-08-01 13:24:30 -0700874 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
875 spin_lock(&ohci->lock);
876 if (ohci->ed_to_check) {
877 struct ed *ed = ohci->ed_to_check;
878
879 if (check_ed(ohci, ed)) {
880 /* HC thinks the TD list is empty; HCD knows
881 * at least one TD is outstanding
882 */
883 if (--ohci->zf_delay == 0) {
884 struct td *td = list_entry(
885 ed->td_list.next,
886 struct td, td_list);
887 ohci_warn(ohci,
888 "Reclaiming orphan TD %p\n",
889 td);
890 takeback_td(ohci, td);
891 ohci->ed_to_check = NULL;
892 }
893 } else
894 ohci->ed_to_check = NULL;
895 }
896 spin_unlock(&ohci->lock);
897 }
898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 /* could track INTR_SO to reduce available PCI/... bandwidth */
900
901 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
902 * when there's still unlinking to be done (next frame).
903 */
904 spin_lock (&ohci->lock);
905 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100906 finish_unlinks (ohci, ohci_frame_no(ohci));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700907 if ((ints & OHCI_INTR_SF) != 0
908 && !ohci->ed_rm_list
909 && !ohci->ed_to_check
Alan Sternb7463c72011-11-17 16:41:56 -0500910 && ohci->rh_state == OHCI_RH_RUNNING)
David Brownelldd9048a2006-12-05 03:18:31 -0800911 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 spin_unlock (&ohci->lock);
913
Alan Sternb7463c72011-11-17 16:41:56 -0500914 if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800916 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 // flush those writes
918 (void) ohci_readl (ohci, &ohci->regs->control);
919 }
920
921 return IRQ_HANDLED;
922}
923
924/*-------------------------------------------------------------------------*/
925
926static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800927{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 ohci_dump (ohci, 1);
931
Tejun Heo569ff2d2010-12-24 16:14:20 +0100932 if (quirk_nec(ohci))
Tejun Heo43829732012-08-20 14:51:24 -0700933 flush_work(&ohci->nec_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
caizhiyong435932f2013-07-26 07:12:14 +0000936 ohci_usb_reset(ohci);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700937 free_irq(hcd->irq, hcd);
Felipe Balbicd704692012-02-29 16:46:23 +0200938 hcd->irq = 0;
Pete Zaitcev71795c12006-09-18 22:57:22 -0700939
Mike Nuss89a0fd12007-08-01 13:24:30 -0700940 if (quirk_zfmicro(ohci))
941 del_timer(&ohci->unlink_watchdog);
Libin Yangab1666c2008-08-08 15:03:31 +0800942 if (quirk_amdiso(ohci))
Andiry Xuad935622011-03-01 14:57:05 +0800943 usb_amd_dev_put();
Mike Nuss89a0fd12007-08-01 13:24:30 -0700944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 ohci_mem_cleanup (ohci);
947 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800948 dma_free_coherent (hcd->self.controller,
949 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 ohci->hcca, ohci->hcca_dma);
951 ohci->hcca = NULL;
952 ohci->hcca_dma = 0;
953 }
954}
955
956/*-------------------------------------------------------------------------*/
957
David Brownellda6fb572007-10-24 17:23:42 -0700958#if defined(CONFIG_PM) || defined(CONFIG_PCI)
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960/* must not be called from interrupt context */
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530961int ohci_restart(struct ohci_hcd *ohci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
963 int temp;
964 int i;
965 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530967 ohci_init(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 spin_lock_irq(&ohci->lock);
Alan Sternb7463c72011-11-17 16:41:56 -0500969 ohci->rh_state = OHCI_RH_HALTED;
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200970
971 /* Recycle any "live" eds/tds (and urbs). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (!list_empty (&ohci->pending))
973 ohci_dbg(ohci, "abort schedule...\n");
974 list_for_each_entry (priv, &ohci->pending, pending) {
975 struct urb *urb = priv->td[0]->urb;
976 struct ed *ed = priv->ed;
977
978 switch (ed->state) {
979 case ED_OPER:
980 ed->state = ED_UNLINK;
981 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
982 ed_deschedule (ohci, ed);
983
984 ed->ed_next = ohci->ed_rm_list;
985 ed->ed_prev = NULL;
986 ohci->ed_rm_list = ed;
987 /* FALLTHROUGH */
988 case ED_UNLINK:
989 break;
990 default:
991 ohci_dbg(ohci, "bogus ed %p state %d\n",
992 ed, ed->state);
993 }
994
Alan Stern55d84962007-08-24 15:40:34 -0400995 if (!urb->unlinked)
996 urb->unlinked = -ESHUTDOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 }
David Howells7d12e782006-10-05 14:55:46 +0100998 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 spin_unlock_irq(&ohci->lock);
1000
1001 /* paranoia, in case that didn't work: */
1002
1003 /* empty the interrupt branches */
1004 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
1005 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -08001006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 /* no EDs to remove */
1008 ohci->ed_rm_list = NULL;
1009
David Brownelldd9048a2006-12-05 03:18:31 -08001010 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 ohci->ed_controltail = NULL;
1012 ohci->ed_bulktail = NULL;
1013
1014 if ((temp = ohci_run (ohci)) < 0) {
1015 ohci_err (ohci, "can't restart, %d\n", temp);
1016 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
Alan Stern383975d2007-05-04 11:52:40 -04001018 ohci_dbg(ohci, "restart complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 return 0;
1020}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301021EXPORT_SYMBOL_GPL(ohci_restart);
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001022
David Brownellda6fb572007-10-24 17:23:42 -07001023#endif
1024
Florian Fainellicd1965d2012-10-08 15:11:27 +02001025#ifdef CONFIG_PM
1026
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301027int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001028{
1029 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
1030 unsigned long flags;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001031
Florian Fainellid4ae47d2012-10-08 15:11:28 +02001032 /* Disable irq emission and mark HW unaccessible. Use
Florian Fainellicd1965d2012-10-08 15:11:27 +02001033 * the spinlock to properly synchronize with possible pending
1034 * RH suspend or resume activity.
1035 */
1036 spin_lock_irqsave (&ohci->lock, flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001037 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
1038 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
1039
1040 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001041 spin_unlock_irqrestore (&ohci->lock, flags);
1042
Greg Kroah-Hartmanca1ad0f2013-10-14 10:19:10 -07001043 return 0;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001044}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301045EXPORT_SYMBOL_GPL(ohci_suspend);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001046
1047
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301048int ohci_resume(struct usb_hcd *hcd, bool hibernated)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001049{
Florian Fainellicfa49b42012-10-08 15:11:29 +02001050 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
1051 int port;
1052 bool need_reinit = false;
1053
Florian Fainellicd1965d2012-10-08 15:11:27 +02001054 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1055
1056 /* Make sure resume from hibernation re-enumerates everything */
1057 if (hibernated)
Florian Fainellicfa49b42012-10-08 15:11:29 +02001058 ohci_usb_reset(ohci);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001059
Florian Fainellicfa49b42012-10-08 15:11:29 +02001060 /* See if the controller is already running or has been reset */
1061 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
1062 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
1063 need_reinit = true;
1064 } else {
1065 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
1066 case OHCI_USB_OPER:
1067 case OHCI_USB_RESET:
1068 need_reinit = true;
1069 }
1070 }
1071
1072 /* If needed, reinitialize and suspend the root hub */
1073 if (need_reinit) {
1074 spin_lock_irq(&ohci->lock);
1075 ohci_rh_resume(ohci);
1076 ohci_rh_suspend(ohci, 0);
1077 spin_unlock_irq(&ohci->lock);
1078 }
1079
1080 /* Normally just turn on port power and enable interrupts */
1081 else {
1082 ohci_dbg(ohci, "powerup ports\n");
1083 for (port = 0; port < ohci->num_ports; port++)
1084 ohci_writel(ohci, RH_PS_PPS,
1085 &ohci->regs->roothub.portstatus[port]);
1086
1087 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
1088 ohci_readl(ohci, &ohci->regs->intrenable);
1089 msleep(20);
1090 }
1091
1092 usb_hcd_resume_root_hub(hcd);
1093
Florian Fainellicd1965d2012-10-08 15:11:27 +02001094 return 0;
1095}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301096EXPORT_SYMBOL_GPL(ohci_resume);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001097
1098#endif
1099
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001100/*-------------------------------------------------------------------------*/
1101
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301102/*
1103 * Generic structure: This gets copied for platform drivers so that
1104 * individual entries can be overridden as needed.
1105 */
1106
1107static const struct hc_driver ohci_hc_driver = {
1108 .description = hcd_name,
1109 .product_desc = "OHCI Host Controller",
1110 .hcd_priv_size = sizeof(struct ohci_hcd),
1111
1112 /*
1113 * generic hardware linkage
1114 */
1115 .irq = ohci_irq,
1116 .flags = HCD_MEMORY | HCD_USB11,
1117
1118 /*
1119 * basic lifecycle operations
1120 */
1121 .reset = ohci_setup,
1122 .start = ohci_start,
1123 .stop = ohci_stop,
1124 .shutdown = ohci_shutdown,
1125
1126 /*
1127 * managing i/o requests and associated device resources
1128 */
1129 .urb_enqueue = ohci_urb_enqueue,
1130 .urb_dequeue = ohci_urb_dequeue,
1131 .endpoint_disable = ohci_endpoint_disable,
1132
1133 /*
1134 * scheduling support
1135 */
1136 .get_frame_number = ohci_get_frame,
1137
1138 /*
1139 * root hub support
1140 */
1141 .hub_status_data = ohci_hub_status_data,
1142 .hub_control = ohci_hub_control,
1143#ifdef CONFIG_PM
1144 .bus_suspend = ohci_bus_suspend,
1145 .bus_resume = ohci_bus_resume,
1146#endif
1147 .start_port_reset = ohci_start_port_reset,
1148};
1149
1150void ohci_init_driver(struct hc_driver *drv,
1151 const struct ohci_driver_overrides *over)
1152{
1153 /* Copy the generic table to drv and then apply the overrides */
1154 *drv = ohci_hc_driver;
1155
Kevin Hilmanc80ad6d2013-09-27 08:10:32 -07001156 if (over) {
1157 drv->product_desc = over->product_desc;
1158 drv->hcd_priv_size += over->extra_priv_size;
1159 if (over->reset)
1160 drv->reset = over->reset;
1161 }
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301162}
1163EXPORT_SYMBOL_GPL(ohci_init_driver);
1164
1165/*-------------------------------------------------------------------------*/
1166
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167MODULE_AUTHOR (DRIVER_AUTHOR);
Alan Stern2b70f072008-10-02 11:47:15 -04001168MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169MODULE_LICENSE ("GPL");
1170
Eric Miao6381fad2008-06-02 10:05:30 +08001171#if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001173#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174#endif
1175
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001176#ifdef CONFIG_ARCH_DAVINCI_DA8XX
1177#include "ohci-da8xx.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001178#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001179#endif
1180
Sylvain Munaut495a6782006-12-13 21:09:55 +01001181#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1182#include "ohci-ppc-of.c"
1183#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1184#endif
1185
Geoff Levand6a6c9572007-01-15 20:12:10 -08001186#ifdef CONFIG_PPC_PS3
1187#include "ohci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001188#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
Geoff Levand6a6c9572007-01-15 20:12:10 -08001189#endif
1190
Magnus Dammf54aab62008-01-23 15:58:46 +09001191#ifdef CONFIG_MFD_SM501
1192#include "ohci-sm501.c"
Ben Dooks3ee38d82008-06-08 17:20:11 +01001193#define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
Magnus Dammf54aab62008-01-23 15:58:46 +09001194#endif
1195
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001196#ifdef CONFIG_MFD_TC6393XB
1197#include "ohci-tmio.c"
1198#define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
1199#endif
1200
Lars-Peter Clausen22490712010-06-19 04:08:24 +00001201#ifdef CONFIG_MACH_JZ4740
1202#include "ohci-jz4740.c"
1203#define PLATFORM_DRIVER ohci_hcd_jz4740_driver
1204#endif
1205
David Daney1643acc2010-10-08 14:47:52 -07001206#ifdef CONFIG_USB_OCTEON_OHCI
1207#include "ohci-octeon.c"
1208#define PLATFORM_DRIVER ohci_octeon_driver
1209#endif
1210
Chris Metcalf47fc28b2012-05-09 13:58:14 -04001211#ifdef CONFIG_TILE_USB
1212#include "ohci-tilegx.c"
1213#define PLATFORM_DRIVER ohci_hcd_tilegx_driver
1214#endif
1215
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001216static int __init ohci_hcd_mod_init(void)
1217{
1218 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001219
1220 if (usb_disabled())
1221 return -ENODEV;
1222
Alan Stern2b70f072008-10-02 11:47:15 -04001223 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001224 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1225 sizeof (struct ed), sizeof (struct td));
Alan Stern9beeee62008-10-02 11:48:13 -04001226 set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001227
Tony Jones684c19e2007-09-11 14:07:31 -07001228#ifdef DEBUG
Greg Kroah-Hartman485f4f32009-04-24 15:14:38 -07001229 ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
Tony Jones684c19e2007-09-11 14:07:31 -07001230 if (!ohci_debug_root) {
1231 retval = -ENOENT;
1232 goto error_debug;
1233 }
1234#endif
1235
Geoff Levand6a6c9572007-01-15 20:12:10 -08001236#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001237 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1238 if (retval < 0)
1239 goto error_ps3;
Geoff Levand6a6c9572007-01-15 20:12:10 -08001240#endif
1241
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001242#ifdef PLATFORM_DRIVER
1243 retval = platform_driver_register(&PLATFORM_DRIVER);
1244 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001245 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001246#endif
1247
Sylvain Munaut495a6782006-12-13 21:09:55 +01001248#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001249 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001250 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001251 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +01001252#endif
1253
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001254#ifdef SA1111_DRIVER
1255 retval = sa1111_driver_register(&SA1111_DRIVER);
1256 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001257 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001258#endif
1259
Ben Dooks3ee38d82008-06-08 17:20:11 +01001260#ifdef SM501_OHCI_DRIVER
1261 retval = platform_driver_register(&SM501_OHCI_DRIVER);
1262 if (retval < 0)
1263 goto error_sm501;
1264#endif
1265
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001266#ifdef TMIO_OHCI_DRIVER
1267 retval = platform_driver_register(&TMIO_OHCI_DRIVER);
1268 if (retval < 0)
1269 goto error_tmio;
1270#endif
1271
Arnd Bergmann80978042013-04-25 19:29:04 +02001272#ifdef DAVINCI_PLATFORM_DRIVER
1273 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
1274 if (retval < 0)
1275 goto error_davinci;
1276#endif
1277
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001278 return retval;
1279
1280 /* Error path */
Arnd Bergmann80978042013-04-25 19:29:04 +02001281#ifdef DAVINCI_PLATFORM_DRIVER
1282 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1283 error_davinci:
1284#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001285#ifdef TMIO_OHCI_DRIVER
1286 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1287 error_tmio:
1288#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001289#ifdef SM501_OHCI_DRIVER
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001290 platform_driver_unregister(&SM501_OHCI_DRIVER);
Ben Dooks3ee38d82008-06-08 17:20:11 +01001291 error_sm501:
1292#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001293#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001294 sa1111_driver_unregister(&SA1111_DRIVER);
1295 error_sa1111:
1296#endif
1297#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001298 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001299 error_of_platform:
1300#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001301#ifdef PLATFORM_DRIVER
1302 platform_driver_unregister(&PLATFORM_DRIVER);
1303 error_platform:
Anand Gadiyar968b4482010-05-10 21:56:12 +05301304#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001305#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001306 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001307 error_ps3:
1308#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001309#ifdef DEBUG
1310 debugfs_remove(ohci_debug_root);
1311 ohci_debug_root = NULL;
1312 error_debug:
1313#endif
1314
Alan Stern9beeee62008-10-02 11:48:13 -04001315 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001316 return retval;
1317}
1318module_init(ohci_hcd_mod_init);
1319
1320static void __exit ohci_hcd_mod_exit(void)
1321{
Arnd Bergmann80978042013-04-25 19:29:04 +02001322#ifdef DAVINCI_PLATFORM_DRIVER
1323 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1324#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001325#ifdef TMIO_OHCI_DRIVER
1326 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1327#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001328#ifdef SM501_OHCI_DRIVER
1329 platform_driver_unregister(&SM501_OHCI_DRIVER);
1330#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001331#ifdef SA1111_DRIVER
1332 sa1111_driver_unregister(&SA1111_DRIVER);
1333#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001334#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001335 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001336#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001337#ifdef PLATFORM_DRIVER
1338 platform_driver_unregister(&PLATFORM_DRIVER);
1339#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001340#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001341 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001342#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001343#ifdef DEBUG
1344 debugfs_remove(ohci_debug_root);
1345#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001346 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001347}
1348module_exit(ohci_hcd_mod_exit);
1349