blob: 8ada13f8dde2c7350977cf343987fbb14c2f303b [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#ifdef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -0400131 urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#endif
David Brownelldd9048a2006-12-05 03:18:31 -0800133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 /* every endpoint has a ed, locate and maybe (re)initialize it */
Alan Sterne9df41c2007-08-08 11:48:02 -0400135 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return -ENOMEM;
137
138 /* for the private part of the URB we need the number of TDs (size) */
139 switch (ed->type) {
140 case PIPE_CONTROL:
141 /* td_submit_urb() doesn't yet handle these */
142 if (urb->transfer_buffer_length > 4096)
143 return -EMSGSIZE;
144
145 /* 1 TD for setup, 1 for ACK, plus ... */
146 size = 2;
147 /* FALLTHROUGH */
148 // case PIPE_INTERRUPT:
149 // case PIPE_BULK:
150 default:
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300151 /* one TD for every 4096 Bytes (can be up to 8K) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 size += urb->transfer_buffer_length / 4096;
153 /* ... and for any remaining bytes ... */
154 if ((urb->transfer_buffer_length % 4096) != 0)
155 size++;
156 /* ... and maybe a zero length packet to wrap it up */
157 if (size == 0)
158 size++;
159 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
160 && (urb->transfer_buffer_length
161 % usb_maxpacket (urb->dev, pipe,
162 usb_pipeout (pipe))) == 0)
163 size++;
164 break;
165 case PIPE_ISOCHRONOUS: /* number of packets from URB */
166 size = urb->number_of_packets;
167 break;
168 }
169
170 /* allocate the private part of the URB */
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700171 urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 mem_flags);
173 if (!urb_priv)
174 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 INIT_LIST_HEAD (&urb_priv->pending);
176 urb_priv->length = size;
David Brownelldd9048a2006-12-05 03:18:31 -0800177 urb_priv->ed = ed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 /* allocate the TDs (deferring hash chain updates) */
180 for (i = 0; i < size; i++) {
181 urb_priv->td [i] = td_alloc (ohci, mem_flags);
182 if (!urb_priv->td [i]) {
183 urb_priv->length = i;
184 urb_free_priv (ohci, urb_priv);
185 return -ENOMEM;
186 }
David Brownelldd9048a2006-12-05 03:18:31 -0800187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 spin_lock_irqsave (&ohci->lock, flags);
190
191 /* don't submit to a dead HC */
Alan Stern541c7d42010-06-22 16:39:10 -0400192 if (!HCD_HW_ACCESSIBLE(hcd)) {
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100193 retval = -ENODEV;
194 goto fail;
195 }
Alan Sternb7463c72011-11-17 16:41:56 -0500196 if (ohci->rh_state != OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 retval = -ENODEV;
198 goto fail;
199 }
Alan Sterne9df41c2007-08-08 11:48:02 -0400200 retval = usb_hcd_link_urb_to_ep(hcd, urb);
201 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 /* schedule the ed if needed */
205 if (ed->state == ED_IDLE) {
206 retval = ed_schedule (ohci, ed);
Alan Sterne9df41c2007-08-08 11:48:02 -0400207 if (retval < 0) {
208 usb_hcd_unlink_urb_from_ep(hcd, urb);
209 goto fail;
210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 if (ed->type == PIPE_ISOCHRONOUS) {
212 u16 frame = ohci_frame_no(ohci);
213
214 /* delay a few frames before the first TD */
215 frame += max_t (u16, 8, ed->interval);
216 frame &= ~(ed->interval - 1);
217 frame |= ed->branch;
218 urb->start_frame = frame;
Alan Sterna8693422013-09-24 15:46:45 -0400219 ed->last_iso = frame + ed->interval * (size - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400221 } else if (ed->type == PIPE_ISOCHRONOUS) {
Alan Sterne19440172013-05-14 13:57:19 -0400222 u16 next = ohci_frame_no(ohci) + 1;
Alan Stern6a41b4d2012-10-01 10:32:15 -0400223 u16 frame = ed->last_iso + ed->interval;
Alan Sterna8693422013-09-24 15:46:45 -0400224 u16 length = ed->interval * (size - 1);
Alan Stern6a41b4d2012-10-01 10:32:15 -0400225
226 /* Behind the scheduling threshold? */
227 if (unlikely(tick_before(frame, next))) {
228
Alan Sterna8693422013-09-24 15:46:45 -0400229 /* URB_ISO_ASAP: Round up to the first available slot */
Alan Stern815fa7b2013-05-14 13:57:51 -0400230 if (urb->transfer_flags & URB_ISO_ASAP) {
Alan Stern6a41b4d2012-10-01 10:32:15 -0400231 frame += (next - frame + ed->interval - 1) &
232 -ed->interval;
233
234 /*
Alan Sterna8693422013-09-24 15:46:45 -0400235 * Not ASAP: Use the next slot in the stream,
236 * no matter what.
Alan Stern6a41b4d2012-10-01 10:32:15 -0400237 */
Alan Stern815fa7b2013-05-14 13:57:51 -0400238 } else {
Alan Stern815fa7b2013-05-14 13:57:51 -0400239 /*
240 * Some OHCI hardware doesn't handle late TDs
241 * correctly. After retiring them it proceeds
242 * to the next ED instead of the next TD.
243 * Therefore we have to omit the late TDs
244 * entirely.
245 */
246 urb_priv->td_cnt = DIV_ROUND_UP(
247 (u16) (next - frame),
248 ed->interval);
Alan Sterna8693422013-09-24 15:46:45 -0400249 if (urb_priv->td_cnt >= urb_priv->length) {
250 ++urb_priv->td_cnt; /* Mark it */
251 ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n",
252 urb, frame, length,
253 next);
254 }
Alan Stern815fa7b2013-05-14 13:57:51 -0400255 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400256 }
257 urb->start_frame = frame;
Alan Sterna8693422013-09-24 15:46:45 -0400258 ed->last_iso = frame + length;
Alan Stern6a41b4d2012-10-01 10:32:15 -0400259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 /* fill the TDs and link them to the ed; and
262 * enable that part of the schedule, if needed
263 * and update count of queued periodic urbs
264 */
265 urb->hcpriv = urb_priv;
266 td_submit_urb (ohci, urb);
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268fail:
269 if (retval)
270 urb_free_priv (ohci, urb_priv);
271 spin_unlock_irqrestore (&ohci->lock, flags);
272 return retval;
273}
274
275/*
Alan Stern55d84962007-08-24 15:40:34 -0400276 * decouple the URB from the HC queues (TDs, urb_priv).
277 * reporting is always done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 * asynchronously, and we might be dealing with an urb that's
279 * partially transferred, or an ED with other urbs being unlinked.
280 */
Alan Sterne9df41c2007-08-08 11:48:02 -0400281static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
283 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
284 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400285 int rc;
David Brownelldd9048a2006-12-05 03:18:31 -0800286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287#ifdef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -0400288 urb_print(urb, "UNLINK", 1, status);
David Brownelldd9048a2006-12-05 03:18:31 -0800289#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 spin_lock_irqsave (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400292 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
293 if (rc) {
294 ; /* Do nothing */
Alan Sternb7463c72011-11-17 16:41:56 -0500295 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 urb_priv_t *urb_priv;
297
298 /* Unless an IRQ completed the unlink while it was being
299 * handed to us, flag it for unlink and giveback, and force
300 * some upcoming INTR_SF to call finish_unlinks()
301 */
302 urb_priv = urb->hcpriv;
303 if (urb_priv) {
304 if (urb_priv->ed->state == ED_OPER)
305 start_ed_unlink (ohci, urb_priv->ed);
306 }
307 } else {
308 /*
309 * with HC dead, we won't respect hc queue pointers
310 * any more ... just clean up every urb's memory.
311 */
312 if (urb->hcpriv)
Alan Stern55d84962007-08-24 15:40:34 -0400313 finish_urb(ohci, urb, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315 spin_unlock_irqrestore (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400316 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
319/*-------------------------------------------------------------------------*/
320
321/* frees config/altsetting state for endpoints,
322 * including ED memory, dummy TD, and bulk/intr data toggle
323 */
324
325static void
326ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
327{
328 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
329 unsigned long flags;
330 struct ed *ed = ep->hcpriv;
331 unsigned limit = 1000;
332
333 /* ASSERT: any requests/urbs are being unlinked */
334 /* ASSERT: nobody can be submitting urbs for this any more */
335
336 if (!ed)
337 return;
338
339rescan:
340 spin_lock_irqsave (&ohci->lock, flags);
341
Alan Sternb7463c72011-11-17 16:41:56 -0500342 if (ohci->rh_state != OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343sanitize:
344 ed->state = ED_IDLE;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700345 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
346 ohci->eds_scheduled--;
David Howells7d12e782006-10-05 14:55:46 +0100347 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
349
350 switch (ed->state) {
351 case ED_UNLINK: /* wait for hw to finish? */
352 /* major IRQ delivery trouble loses INTR_SF too... */
353 if (limit-- == 0) {
Mike Nuss89a0fd12007-08-01 13:24:30 -0700354 ohci_warn(ohci, "ED unlink timeout\n");
355 if (quirk_zfmicro(ohci)) {
356 ohci_warn(ohci, "Attempting ZF TD recovery\n");
357 ohci->ed_to_check = ed;
358 ohci->zf_delay = 2;
359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 goto sanitize;
361 }
362 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700363 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 goto rescan;
365 case ED_IDLE: /* fully unlinked */
366 if (list_empty (&ed->td_list)) {
367 td_free (ohci, ed->dummy);
368 ed_free (ohci, ed);
369 break;
370 }
371 /* else FALL THROUGH */
372 default:
373 /* caller was supposed to have unlinked any requests;
374 * that's not our job. can't recover; must leak ed.
375 */
376 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
377 ed, ep->desc.bEndpointAddress, ed->state,
378 list_empty (&ed->td_list) ? "" : " (has tds)");
379 td_free (ohci, ed->dummy);
380 break;
381 }
382 ep->hcpriv = NULL;
383 spin_unlock_irqrestore (&ohci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
386static int ohci_get_frame (struct usb_hcd *hcd)
387{
388 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
389
390 return ohci_frame_no(ohci);
391}
392
393static void ohci_usb_reset (struct ohci_hcd *ohci)
394{
395 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
396 ohci->hc_control &= OHCI_CTRL_RWC;
397 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
Alan Sternb7463c72011-11-17 16:41:56 -0500398 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
400
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700401/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700402 * other cases where the next software may expect clean state from the
403 * "firmware". this is bus-neutral, unlike shutdown() methods.
404 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700405static void
406ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700407{
408 struct ohci_hcd *ohci;
409
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700410 ohci = hcd_to_ohci (hcd);
Alan Sternc6187592011-11-17 16:41:45 -0500411 ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
Alan Stern3df71692010-09-10 16:37:05 -0400412
Alan Sternc6187592011-11-17 16:41:45 -0500413 /* Software reset, after which the controller goes into SUSPEND */
414 ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
415 ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */
416 udelay(10);
Alan Stern3df71692010-09-10 16:37:05 -0400417
Alan Sternc6187592011-11-17 16:41:45 -0500418 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
David Brownellf4df0e32005-04-23 12:49:16 -0700419}
420
Mike Nuss89a0fd12007-08-01 13:24:30 -0700421static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
422{
423 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
424 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
425 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
426 && !list_empty(&ed->td_list);
427}
428
429/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
430 * an interrupt TD but neglects to add it to the donelist. On systems with
431 * this chipset, we need to periodically check the state of the queues to look
432 * for such "lost" TDs.
433 */
434static void unlink_watchdog_func(unsigned long _ohci)
435{
David Brownellda6fb572007-10-24 17:23:42 -0700436 unsigned long flags;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700437 unsigned max;
438 unsigned seen_count = 0;
439 unsigned i;
440 struct ed **seen = NULL;
441 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
442
443 spin_lock_irqsave(&ohci->lock, flags);
444 max = ohci->eds_scheduled;
445 if (!max)
446 goto done;
447
448 if (ohci->ed_to_check)
449 goto out;
450
451 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
452 if (!seen)
453 goto out;
454
455 for (i = 0; i < NUM_INTS; i++) {
456 struct ed *ed = ohci->periodic[i];
457
458 while (ed) {
459 unsigned temp;
460
461 /* scan this branch of the periodic schedule tree */
462 for (temp = 0; temp < seen_count; temp++) {
463 if (seen[temp] == ed) {
464 /* we've checked it and what's after */
465 ed = NULL;
466 break;
467 }
468 }
469 if (!ed)
470 break;
471 seen[seen_count++] = ed;
472 if (!check_ed(ohci, ed)) {
473 ed = ed->ed_next;
474 continue;
475 }
476
477 /* HC's TD list is empty, but HCD sees at least one
478 * TD that's not been sent through the donelist.
479 */
480 ohci->ed_to_check = ed;
481 ohci->zf_delay = 2;
482
483 /* The HC may wait until the next frame to report the
484 * TD as done through the donelist and INTR_WDH. (We
485 * just *assume* it's not a multi-TD interrupt URB;
486 * those could defer the IRQ more than one frame, using
487 * DI...) Check again after the next INTR_SF.
488 */
489 ohci_writel(ohci, OHCI_INTR_SF,
490 &ohci->regs->intrstatus);
491 ohci_writel(ohci, OHCI_INTR_SF,
492 &ohci->regs->intrenable);
493
494 /* flush those writes */
495 (void) ohci_readl(ohci, &ohci->regs->control);
496
497 goto out;
498 }
499 }
500out:
501 kfree(seen);
502 if (ohci->eds_scheduled)
Richard Kennedy9cebcdc2008-03-28 14:50:30 -0700503 mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700504done:
505 spin_unlock_irqrestore(&ohci->lock, flags);
506}
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508/*-------------------------------------------------------------------------*
509 * HC functions
510 *-------------------------------------------------------------------------*/
511
512/* init memory, and kick BIOS/SMM off */
513
514static int ohci_init (struct ohci_hcd *ohci)
515{
516 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800517 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400519 if (distrust_firmware)
520 ohci->flags |= OHCI_QUIRK_HUB_POWER;
521
Alan Sternb7463c72011-11-17 16:41:56 -0500522 ohci->rh_state = OHCI_RH_HALTED;
David Brownell6a9062f2006-01-23 15:28:07 -0800523 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
David Brownell6a9062f2006-01-23 15:28:07 -0800525 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
526 * was never needed for most non-PCI systems ... remove the code?
527 */
528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#ifndef IR_DISABLE
530 /* SMM owns the HC? not for long! */
531 if (!no_handshake && ohci_readl (ohci,
532 &ohci->regs->control) & OHCI_CTRL_IR) {
533 u32 temp;
534
535 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
536
537 /* this timeout is arbitrary. we make it long, so systems
538 * depending on usb keyboards may be usable even if the
539 * BIOS/SMM code seems pretty broken.
540 */
541 temp = 500; /* arbitrary: five seconds */
542
543 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
544 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
545 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
546 msleep (10);
547 if (--temp == 0) {
548 ohci_err (ohci, "USB HC takeover failed!"
549 " (BIOS/SMM bug)\n");
550 return -EBUSY;
551 }
552 }
553 ohci_usb_reset (ohci);
554 }
555#endif
556
557 /* Disable HC interrupts */
558 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800559
560 /* flush the writes, and save key bits like RWC */
561 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
562 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
David Brownellfdd13b32005-08-31 11:52:57 -0700564 /* Read the number of ports unless overridden */
565 if (ohci->num_ports == 0)
566 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 if (ohci->hcca)
569 return 0;
570
David Brownell6a9062f2006-01-23 15:28:07 -0800571 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
573 if (!ohci->hcca)
574 return -ENOMEM;
575
576 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800577 ohci_stop (hcd);
578 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800579 create_debug_files (ohci);
580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583}
584
585/*-------------------------------------------------------------------------*/
586
587/* Start an OHCI controller, set the BUS operational
588 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800589 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 */
591static int ohci_run (struct ohci_hcd *ohci)
592{
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400593 u32 mask, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800595 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Alan Sternb7463c72011-11-17 16:41:56 -0500597 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 /* boot firmware should have set this up (5.1.1.3.1) */
600 if (first) {
601
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400602 val = ohci_readl (ohci, &ohci->regs->fminterval);
603 ohci->fminterval = val & 0x3fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 if (ohci->fminterval != FI)
605 ohci_dbg (ohci, "fminterval delta %d\n",
606 ohci->fminterval - FI);
607 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
608 /* also: power/overcurrent flags in roothub.a */
609 }
610
Alan Stern6fd90862008-12-17 17:20:38 -0500611 /* Reset USB nearly "by the book". RemoteWakeupConnected has
612 * to be checked in case boot firmware (BIOS/SMM/...) has set up
613 * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
614 * If the bus glue detected wakeup capability then it should
Alan Sternbcca06e2009-01-13 11:35:54 -0500615 * already be enabled; if so we'll just enable it again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 */
Alan Sternbcca06e2009-01-13 11:35:54 -0500617 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
618 device_set_wakeup_capable(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
621 case OHCI_USB_OPER:
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400622 val = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 break;
624 case OHCI_USB_SUSPEND:
625 case OHCI_USB_RESUME:
626 ohci->hc_control &= OHCI_CTRL_RWC;
627 ohci->hc_control |= OHCI_USB_RESUME;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400628 val = 10 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 break;
630 // case OHCI_USB_RESET:
631 default:
632 ohci->hc_control &= OHCI_CTRL_RWC;
633 ohci->hc_control |= OHCI_USB_RESET;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400634 val = 50 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 break;
636 }
637 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
638 // flush the writes
639 (void) ohci_readl (ohci, &ohci->regs->control);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400640 msleep(val);
Alan Stern383975d2007-05-04 11:52:40 -0400641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
643
644 /* 2msec timelimit here means no irqs/preempt */
645 spin_lock_irq (&ohci->lock);
646
647retry:
648 /* HC Reset requires max 10 us delay */
649 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400650 val = 30; /* ... allow extra time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400652 if (--val == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 spin_unlock_irq (&ohci->lock);
654 ohci_err (ohci, "USB HC reset timed out!\n");
655 return -1;
656 }
657 udelay (1);
658 }
659
660 /* now we're in the SUSPEND state ... must go OPERATIONAL
661 * within 2msec else HC enters RESUME
662 *
663 * ... but some hardware won't init fmInterval "by the book"
664 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
665 * this if we write fmInterval after we're OPERATIONAL.
666 * Unclear about ALi, ServerWorks, and others ... this could
667 * easily be a longstanding bug in chip init on Linux.
668 */
669 if (ohci->flags & OHCI_QUIRK_INITRESET) {
670 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
671 // flush those writes
672 (void) ohci_readl (ohci, &ohci->regs->control);
673 }
674
675 /* Tell the controller where the control and bulk lists are
676 * The lists are empty now. */
677 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
678 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
679
680 /* a reset clears this */
681 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
682
683 periodic_reinit (ohci);
684
685 /* some OHCI implementations are finicky about how they init.
686 * bogus values here mean not even enumeration could work.
687 */
688 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
689 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
690 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
691 ohci->flags |= OHCI_QUIRK_INITRESET;
692 ohci_dbg (ohci, "enabling initreset quirk\n");
693 goto retry;
694 }
695 spin_unlock_irq (&ohci->lock);
696 ohci_err (ohci, "init err (%08x %04x)\n",
697 ohci_readl (ohci, &ohci->regs->fminterval),
698 ohci_readl (ohci, &ohci->regs->periodicstart));
699 return -EOVERFLOW;
700 }
701
David Brownelld4139842006-08-04 11:31:55 -0700702 /* use rhsc irqs after khubd is fully initialized */
Alan Stern541c7d42010-06-22 16:39:10 -0400703 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
David Brownelld4139842006-08-04 11:31:55 -0700704 hcd->uses_new_polling = 1;
705
706 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700708 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
709 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
Alan Sternb7463c72011-11-17 16:41:56 -0500710 ohci->rh_state = OHCI_RH_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712 /* wake on ConnectStatusChange, matching external hubs */
713 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
714
715 /* Choose the interrupts we care about now, others later on demand */
716 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700717 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 ohci_writel (ohci, mask, &ohci->regs->intrenable);
719
720 /* handle root hub init quirks ... */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400721 val = roothub_a (ohci);
722 val &= ~(RH_A_PSM | RH_A_OCPM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
724 /* NSC 87560 and maybe others */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400725 val |= RH_A_NOCP;
726 val &= ~(RH_A_POTPGT | RH_A_NPS);
727 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400728 } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
729 (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 /* hub power always on; required for AMD-756 and some
731 * Mac platforms. ganged overcurrent reporting, if any.
732 */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400733 val |= RH_A_NPS;
734 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 }
736 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400737 ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 &ohci->regs->roothub.b);
739 // flush those writes
740 (void) ohci_readl (ohci, &ohci->regs->control);
741
David Brownelld4139842006-08-04 11:31:55 -0700742 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 spin_unlock_irq (&ohci->lock);
744
745 // POTPGT delay is bits 24-31, in 2 ms units.
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400746 mdelay ((val >> 23) & 0x1fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Mike Nuss89a0fd12007-08-01 13:24:30 -0700748 if (quirk_zfmicro(ohci)) {
749 /* Create timer to watch for bad queue state on ZF Micro */
750 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
751 (unsigned long) ohci);
752
753 ohci->eds_scheduled = 0;
754 ohci->ed_to_check = NULL;
755 }
756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 ohci_dump (ohci, 1);
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 return 0;
760}
761
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530762/* ohci_setup routine for generic controller initialization */
763
764int ohci_setup(struct usb_hcd *hcd)
765{
766 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
767
768 ohci_hcd_init(ohci);
769
770 return ohci_init(ohci);
771}
772EXPORT_SYMBOL_GPL(ohci_setup);
773
774/* ohci_start routine for generic controller start of all OHCI bus glue */
775static int ohci_start(struct usb_hcd *hcd)
776{
777 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
778 int ret;
779
780 ret = ohci_run(ohci);
781 if (ret < 0) {
782 ohci_err(ohci, "can't start\n");
783 ohci_stop(hcd);
784 }
785 return ret;
786}
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788/*-------------------------------------------------------------------------*/
789
790/* an interrupt happens */
791
David Howells7d12e782006-10-05 14:55:46 +0100792static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
794 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
795 struct ohci_regs __iomem *regs = ohci->regs;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700796 int ints;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800798 /* Read interrupt status (and flush pending writes). We ignore the
799 * optimization of checking the LSB of hcca->done_head; it doesn't
800 * work on all systems (edge triggering for OHCI can be a factor).
Mike Nuss89a0fd12007-08-01 13:24:30 -0700801 */
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800802 ints = ohci_readl(ohci, &regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800804 /* Check for an all 1's result which is a typical consequence
805 * of dead, unclocked, or unplugged (CardBus...) devices
806 */
807 if (ints == ~(u32)0) {
Alan Sternb7463c72011-11-17 16:41:56 -0500808 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 ohci_dbg (ohci, "device removed!\n");
Alan Stern69fff592011-05-17 17:27:12 -0400810 usb_hc_died(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 return IRQ_HANDLED;
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800812 }
813
814 /* We only care about interrupts that are enabled */
815 ints &= ohci_readl(ohci, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 /* interrupt for some other device? */
Alan Sternb7463c72011-11-17 16:41:56 -0500818 if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (ints & OHCI_INTR_UE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 // e.g. due to PCI Master/Target Abort
Mike Nuss89a0fd12007-08-01 13:24:30 -0700823 if (quirk_nec(ohci)) {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200824 /* Workaround for a silicon bug in some NEC chips used
825 * in Apple's PowerBooks. Adapted from Darwin code.
826 */
827 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
828
829 ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
830
831 schedule_work (&ohci->nec_work);
832 } else {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200833 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
Alan Sternb7463c72011-11-17 16:41:56 -0500834 ohci->rh_state = OHCI_RH_HALTED;
Alan Stern69fff592011-05-17 17:27:12 -0400835 usb_hc_died(hcd);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 ohci_dump (ohci, 1);
839 ohci_usb_reset (ohci);
840 }
841
Alan Stern583cead2006-10-24 12:04:22 -0400842 if (ints & OHCI_INTR_RHSC) {
843 ohci_vdbg(ohci, "rhsc\n");
844 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
845 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
846 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400847
848 /* NOTE: Vendors didn't always make the same implementation
849 * choices for RHSC. Many followed the spec; RHSC triggers
850 * on an edge, like setting and maybe clearing a port status
851 * change bit. With others it's level-triggered, active
852 * until khubd clears all the port status change bits. We'll
853 * always disable it here and rely on polling until khubd
854 * re-enables it.
855 */
856 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400857 usb_hcd_poll_rh_status(hcd);
858 }
859
860 /* For connect and disconnect events, we expect the controller
861 * to turn on RHSC along with RD. But for remote wakeup events
862 * this might not happen.
863 */
864 else if (ints & OHCI_INTR_RD) {
865 ohci_vdbg(ohci, "resume detect\n");
866 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern541c7d42010-06-22 16:39:10 -0400867 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
Alan Stern8d1a2432006-09-26 14:46:16 -0400868 if (ohci->autostop) {
869 spin_lock (&ohci->lock);
870 ohci_rh_resume (ohci);
871 spin_unlock (&ohci->lock);
872 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700873 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 }
875
876 if (ints & OHCI_INTR_WDH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100878 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 spin_unlock (&ohci->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
David Brownelldd9048a2006-12-05 03:18:31 -0800881
Mike Nuss89a0fd12007-08-01 13:24:30 -0700882 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
883 spin_lock(&ohci->lock);
884 if (ohci->ed_to_check) {
885 struct ed *ed = ohci->ed_to_check;
886
887 if (check_ed(ohci, ed)) {
888 /* HC thinks the TD list is empty; HCD knows
889 * at least one TD is outstanding
890 */
891 if (--ohci->zf_delay == 0) {
892 struct td *td = list_entry(
893 ed->td_list.next,
894 struct td, td_list);
895 ohci_warn(ohci,
896 "Reclaiming orphan TD %p\n",
897 td);
898 takeback_td(ohci, td);
899 ohci->ed_to_check = NULL;
900 }
901 } else
902 ohci->ed_to_check = NULL;
903 }
904 spin_unlock(&ohci->lock);
905 }
906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 /* could track INTR_SO to reduce available PCI/... bandwidth */
908
909 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
910 * when there's still unlinking to be done (next frame).
911 */
912 spin_lock (&ohci->lock);
913 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100914 finish_unlinks (ohci, ohci_frame_no(ohci));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700915 if ((ints & OHCI_INTR_SF) != 0
916 && !ohci->ed_rm_list
917 && !ohci->ed_to_check
Alan Sternb7463c72011-11-17 16:41:56 -0500918 && ohci->rh_state == OHCI_RH_RUNNING)
David Brownelldd9048a2006-12-05 03:18:31 -0800919 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 spin_unlock (&ohci->lock);
921
Alan Sternb7463c72011-11-17 16:41:56 -0500922 if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800924 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 // flush those writes
926 (void) ohci_readl (ohci, &ohci->regs->control);
927 }
928
929 return IRQ_HANDLED;
930}
931
932/*-------------------------------------------------------------------------*/
933
934static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800935{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 ohci_dump (ohci, 1);
939
Tejun Heo569ff2d2010-12-24 16:14:20 +0100940 if (quirk_nec(ohci))
Tejun Heo43829732012-08-20 14:51:24 -0700941 flush_work(&ohci->nec_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
caizhiyong435932f2013-07-26 07:12:14 +0000944 ohci_usb_reset(ohci);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700945 free_irq(hcd->irq, hcd);
Felipe Balbicd704692012-02-29 16:46:23 +0200946 hcd->irq = 0;
Pete Zaitcev71795c12006-09-18 22:57:22 -0700947
Mike Nuss89a0fd12007-08-01 13:24:30 -0700948 if (quirk_zfmicro(ohci))
949 del_timer(&ohci->unlink_watchdog);
Libin Yangab1666c2008-08-08 15:03:31 +0800950 if (quirk_amdiso(ohci))
Andiry Xuad935622011-03-01 14:57:05 +0800951 usb_amd_dev_put();
Mike Nuss89a0fd12007-08-01 13:24:30 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 ohci_mem_cleanup (ohci);
955 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800956 dma_free_coherent (hcd->self.controller,
957 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 ohci->hcca, ohci->hcca_dma);
959 ohci->hcca = NULL;
960 ohci->hcca_dma = 0;
961 }
962}
963
964/*-------------------------------------------------------------------------*/
965
David Brownellda6fb572007-10-24 17:23:42 -0700966#if defined(CONFIG_PM) || defined(CONFIG_PCI)
967
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968/* must not be called from interrupt context */
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530969int ohci_restart(struct ohci_hcd *ohci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
971 int temp;
972 int i;
973 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530975 ohci_init(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 spin_lock_irq(&ohci->lock);
Alan Sternb7463c72011-11-17 16:41:56 -0500977 ohci->rh_state = OHCI_RH_HALTED;
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200978
979 /* Recycle any "live" eds/tds (and urbs). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 if (!list_empty (&ohci->pending))
981 ohci_dbg(ohci, "abort schedule...\n");
982 list_for_each_entry (priv, &ohci->pending, pending) {
983 struct urb *urb = priv->td[0]->urb;
984 struct ed *ed = priv->ed;
985
986 switch (ed->state) {
987 case ED_OPER:
988 ed->state = ED_UNLINK;
989 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
990 ed_deschedule (ohci, ed);
991
992 ed->ed_next = ohci->ed_rm_list;
993 ed->ed_prev = NULL;
994 ohci->ed_rm_list = ed;
995 /* FALLTHROUGH */
996 case ED_UNLINK:
997 break;
998 default:
999 ohci_dbg(ohci, "bogus ed %p state %d\n",
1000 ed, ed->state);
1001 }
1002
Alan Stern55d84962007-08-24 15:40:34 -04001003 if (!urb->unlinked)
1004 urb->unlinked = -ESHUTDOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 }
David Howells7d12e782006-10-05 14:55:46 +01001006 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 spin_unlock_irq(&ohci->lock);
1008
1009 /* paranoia, in case that didn't work: */
1010
1011 /* empty the interrupt branches */
1012 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
1013 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -08001014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 /* no EDs to remove */
1016 ohci->ed_rm_list = NULL;
1017
David Brownelldd9048a2006-12-05 03:18:31 -08001018 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 ohci->ed_controltail = NULL;
1020 ohci->ed_bulktail = NULL;
1021
1022 if ((temp = ohci_run (ohci)) < 0) {
1023 ohci_err (ohci, "can't restart, %d\n", temp);
1024 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
Alan Stern383975d2007-05-04 11:52:40 -04001026 ohci_dbg(ohci, "restart complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 return 0;
1028}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301029EXPORT_SYMBOL_GPL(ohci_restart);
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001030
David Brownellda6fb572007-10-24 17:23:42 -07001031#endif
1032
Florian Fainellicd1965d2012-10-08 15:11:27 +02001033#ifdef CONFIG_PM
1034
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301035int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001036{
1037 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
1038 unsigned long flags;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001039
Florian Fainellid4ae47d2012-10-08 15:11:28 +02001040 /* Disable irq emission and mark HW unaccessible. Use
Florian Fainellicd1965d2012-10-08 15:11:27 +02001041 * the spinlock to properly synchronize with possible pending
1042 * RH suspend or resume activity.
1043 */
1044 spin_lock_irqsave (&ohci->lock, flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001045 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
1046 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
1047
1048 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001049 spin_unlock_irqrestore (&ohci->lock, flags);
1050
Greg Kroah-Hartmanca1ad0f2013-10-14 10:19:10 -07001051 return 0;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001052}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301053EXPORT_SYMBOL_GPL(ohci_suspend);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001054
1055
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301056int ohci_resume(struct usb_hcd *hcd, bool hibernated)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001057{
Florian Fainellicfa49b42012-10-08 15:11:29 +02001058 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
1059 int port;
1060 bool need_reinit = false;
1061
Florian Fainellicd1965d2012-10-08 15:11:27 +02001062 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1063
1064 /* Make sure resume from hibernation re-enumerates everything */
1065 if (hibernated)
Florian Fainellicfa49b42012-10-08 15:11:29 +02001066 ohci_usb_reset(ohci);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001067
Florian Fainellicfa49b42012-10-08 15:11:29 +02001068 /* See if the controller is already running or has been reset */
1069 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
1070 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
1071 need_reinit = true;
1072 } else {
1073 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
1074 case OHCI_USB_OPER:
1075 case OHCI_USB_RESET:
1076 need_reinit = true;
1077 }
1078 }
1079
1080 /* If needed, reinitialize and suspend the root hub */
1081 if (need_reinit) {
1082 spin_lock_irq(&ohci->lock);
1083 ohci_rh_resume(ohci);
1084 ohci_rh_suspend(ohci, 0);
1085 spin_unlock_irq(&ohci->lock);
1086 }
1087
1088 /* Normally just turn on port power and enable interrupts */
1089 else {
1090 ohci_dbg(ohci, "powerup ports\n");
1091 for (port = 0; port < ohci->num_ports; port++)
1092 ohci_writel(ohci, RH_PS_PPS,
1093 &ohci->regs->roothub.portstatus[port]);
1094
1095 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
1096 ohci_readl(ohci, &ohci->regs->intrenable);
1097 msleep(20);
1098 }
1099
1100 usb_hcd_resume_root_hub(hcd);
1101
Florian Fainellicd1965d2012-10-08 15:11:27 +02001102 return 0;
1103}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301104EXPORT_SYMBOL_GPL(ohci_resume);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001105
1106#endif
1107
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001108/*-------------------------------------------------------------------------*/
1109
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301110/*
1111 * Generic structure: This gets copied for platform drivers so that
1112 * individual entries can be overridden as needed.
1113 */
1114
1115static const struct hc_driver ohci_hc_driver = {
1116 .description = hcd_name,
1117 .product_desc = "OHCI Host Controller",
1118 .hcd_priv_size = sizeof(struct ohci_hcd),
1119
1120 /*
1121 * generic hardware linkage
1122 */
1123 .irq = ohci_irq,
1124 .flags = HCD_MEMORY | HCD_USB11,
1125
1126 /*
1127 * basic lifecycle operations
1128 */
1129 .reset = ohci_setup,
1130 .start = ohci_start,
1131 .stop = ohci_stop,
1132 .shutdown = ohci_shutdown,
1133
1134 /*
1135 * managing i/o requests and associated device resources
1136 */
1137 .urb_enqueue = ohci_urb_enqueue,
1138 .urb_dequeue = ohci_urb_dequeue,
1139 .endpoint_disable = ohci_endpoint_disable,
1140
1141 /*
1142 * scheduling support
1143 */
1144 .get_frame_number = ohci_get_frame,
1145
1146 /*
1147 * root hub support
1148 */
1149 .hub_status_data = ohci_hub_status_data,
1150 .hub_control = ohci_hub_control,
1151#ifdef CONFIG_PM
1152 .bus_suspend = ohci_bus_suspend,
1153 .bus_resume = ohci_bus_resume,
1154#endif
1155 .start_port_reset = ohci_start_port_reset,
1156};
1157
1158void ohci_init_driver(struct hc_driver *drv,
1159 const struct ohci_driver_overrides *over)
1160{
1161 /* Copy the generic table to drv and then apply the overrides */
1162 *drv = ohci_hc_driver;
1163
Kevin Hilmanc80ad6d2013-09-27 08:10:32 -07001164 if (over) {
1165 drv->product_desc = over->product_desc;
1166 drv->hcd_priv_size += over->extra_priv_size;
1167 if (over->reset)
1168 drv->reset = over->reset;
1169 }
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301170}
1171EXPORT_SYMBOL_GPL(ohci_init_driver);
1172
1173/*-------------------------------------------------------------------------*/
1174
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175MODULE_AUTHOR (DRIVER_AUTHOR);
Alan Stern2b70f072008-10-02 11:47:15 -04001176MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177MODULE_LICENSE ("GPL");
1178
Eric Miao6381fad2008-06-02 10:05:30 +08001179#if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001181#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182#endif
1183
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001184#ifdef CONFIG_ARCH_DAVINCI_DA8XX
1185#include "ohci-da8xx.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001186#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001187#endif
1188
Sylvain Munaut495a6782006-12-13 21:09:55 +01001189#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1190#include "ohci-ppc-of.c"
1191#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1192#endif
1193
Geoff Levand6a6c9572007-01-15 20:12:10 -08001194#ifdef CONFIG_PPC_PS3
1195#include "ohci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001196#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
Geoff Levand6a6c9572007-01-15 20:12:10 -08001197#endif
1198
Magnus Dammf54aab62008-01-23 15:58:46 +09001199#ifdef CONFIG_MFD_SM501
1200#include "ohci-sm501.c"
Ben Dooks3ee38d82008-06-08 17:20:11 +01001201#define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
Magnus Dammf54aab62008-01-23 15:58:46 +09001202#endif
1203
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001204#ifdef CONFIG_MFD_TC6393XB
1205#include "ohci-tmio.c"
1206#define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
1207#endif
1208
Lars-Peter Clausen22490712010-06-19 04:08:24 +00001209#ifdef CONFIG_MACH_JZ4740
1210#include "ohci-jz4740.c"
1211#define PLATFORM_DRIVER ohci_hcd_jz4740_driver
1212#endif
1213
David Daney1643acc2010-10-08 14:47:52 -07001214#ifdef CONFIG_USB_OCTEON_OHCI
1215#include "ohci-octeon.c"
1216#define PLATFORM_DRIVER ohci_octeon_driver
1217#endif
1218
Chris Metcalf47fc28b2012-05-09 13:58:14 -04001219#ifdef CONFIG_TILE_USB
1220#include "ohci-tilegx.c"
1221#define PLATFORM_DRIVER ohci_hcd_tilegx_driver
1222#endif
1223
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001224static int __init ohci_hcd_mod_init(void)
1225{
1226 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001227
1228 if (usb_disabled())
1229 return -ENODEV;
1230
Alan Stern2b70f072008-10-02 11:47:15 -04001231 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001232 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1233 sizeof (struct ed), sizeof (struct td));
Alan Stern9beeee62008-10-02 11:48:13 -04001234 set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001235
Tony Jones684c19e2007-09-11 14:07:31 -07001236#ifdef DEBUG
Greg Kroah-Hartman485f4f32009-04-24 15:14:38 -07001237 ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
Tony Jones684c19e2007-09-11 14:07:31 -07001238 if (!ohci_debug_root) {
1239 retval = -ENOENT;
1240 goto error_debug;
1241 }
1242#endif
1243
Geoff Levand6a6c9572007-01-15 20:12:10 -08001244#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001245 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1246 if (retval < 0)
1247 goto error_ps3;
Geoff Levand6a6c9572007-01-15 20:12:10 -08001248#endif
1249
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001250#ifdef PLATFORM_DRIVER
1251 retval = platform_driver_register(&PLATFORM_DRIVER);
1252 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001253 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001254#endif
1255
Sylvain Munaut495a6782006-12-13 21:09:55 +01001256#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001257 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001258 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001259 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +01001260#endif
1261
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001262#ifdef SA1111_DRIVER
1263 retval = sa1111_driver_register(&SA1111_DRIVER);
1264 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001265 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001266#endif
1267
Ben Dooks3ee38d82008-06-08 17:20:11 +01001268#ifdef SM501_OHCI_DRIVER
1269 retval = platform_driver_register(&SM501_OHCI_DRIVER);
1270 if (retval < 0)
1271 goto error_sm501;
1272#endif
1273
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001274#ifdef TMIO_OHCI_DRIVER
1275 retval = platform_driver_register(&TMIO_OHCI_DRIVER);
1276 if (retval < 0)
1277 goto error_tmio;
1278#endif
1279
Arnd Bergmann80978042013-04-25 19:29:04 +02001280#ifdef DAVINCI_PLATFORM_DRIVER
1281 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
1282 if (retval < 0)
1283 goto error_davinci;
1284#endif
1285
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001286 return retval;
1287
1288 /* Error path */
Arnd Bergmann80978042013-04-25 19:29:04 +02001289#ifdef DAVINCI_PLATFORM_DRIVER
1290 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1291 error_davinci:
1292#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001293#ifdef TMIO_OHCI_DRIVER
1294 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1295 error_tmio:
1296#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001297#ifdef SM501_OHCI_DRIVER
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001298 platform_driver_unregister(&SM501_OHCI_DRIVER);
Ben Dooks3ee38d82008-06-08 17:20:11 +01001299 error_sm501:
1300#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001301#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001302 sa1111_driver_unregister(&SA1111_DRIVER);
1303 error_sa1111:
1304#endif
1305#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001306 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001307 error_of_platform:
1308#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001309#ifdef PLATFORM_DRIVER
1310 platform_driver_unregister(&PLATFORM_DRIVER);
1311 error_platform:
Anand Gadiyar968b4482010-05-10 21:56:12 +05301312#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001313#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001314 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001315 error_ps3:
1316#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001317#ifdef DEBUG
1318 debugfs_remove(ohci_debug_root);
1319 ohci_debug_root = NULL;
1320 error_debug:
1321#endif
1322
Alan Stern9beeee62008-10-02 11:48:13 -04001323 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001324 return retval;
1325}
1326module_init(ohci_hcd_mod_init);
1327
1328static void __exit ohci_hcd_mod_exit(void)
1329{
Arnd Bergmann80978042013-04-25 19:29:04 +02001330#ifdef DAVINCI_PLATFORM_DRIVER
1331 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1332#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001333#ifdef TMIO_OHCI_DRIVER
1334 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1335#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001336#ifdef SM501_OHCI_DRIVER
1337 platform_driver_unregister(&SM501_OHCI_DRIVER);
1338#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001339#ifdef SA1111_DRIVER
1340 sa1111_driver_unregister(&SA1111_DRIVER);
1341#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001342#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001343 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001344#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001345#ifdef PLATFORM_DRIVER
1346 platform_driver_unregister(&PLATFORM_DRIVER);
1347#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001348#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001349 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001350#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001351#ifdef DEBUG
1352 debugfs_remove(ohci_debug_root);
1353#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001354 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001355}
1356module_exit(ohci_hcd_mod_exit);
1357