blob: 7f94c586c5dcb64f2c3a8c50fda6f3dbbc4b9b9f [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/* For initializing controller (mask in an HCFS mode too) */
David Brownelld4139842006-08-04 11:31:55 -070055#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#define OHCI_INTR_INIT \
David Brownelld4139842006-08-04 11:31:55 -070057 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
58 | OHCI_INTR_RD | OHCI_INTR_WDH)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#ifdef __hppa__
61/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
62#define IR_DISABLE
63#endif
64
65#ifdef CONFIG_ARCH_OMAP
66/* OMAP doesn't support IR (no SMM; not needed) */
67#define IR_DISABLE
68#endif
69
70/*-------------------------------------------------------------------------*/
71
72static const char hcd_name [] = "ohci_hcd";
73
David Brownelld4139842006-08-04 11:31:55 -070074#define STATECHANGE_DELAY msecs_to_jiffies(300)
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include "ohci.h"
Andiry Xuad935622011-03-01 14:57:05 +080077#include "pci-quirks.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79static void ohci_dump (struct ohci_hcd *ohci, int verbose);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080static void ohci_stop (struct usb_hcd *hcd);
Libin Yangab1666c2008-08-08 15:03:31 +080081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#include "ohci-hub.c"
83#include "ohci-dbg.c"
84#include "ohci-mem.c"
85#include "ohci-q.c"
86
87
88/*
89 * On architectures with edge-triggered interrupts we must never return
90 * IRQ_NONE.
91 */
92#if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
93#define IRQ_NOTMINE IRQ_HANDLED
94#else
95#define IRQ_NOTMINE IRQ_NONE
96#endif
97
98
99/* Some boards misreport power switching/overcurrent */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030100static bool distrust_firmware = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101module_param (distrust_firmware, bool, 0);
102MODULE_PARM_DESC (distrust_firmware,
103 "true to distrust firmware power/overcurrent setup");
104
105/* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030106static bool no_handshake = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107module_param (no_handshake, bool, 0);
108MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
109
110/*-------------------------------------------------------------------------*/
111
Alan Stern6f651262014-07-17 16:30:01 -0400112static int number_of_tds(struct urb *urb)
113{
114 int len, i, num, this_sg_len;
115 struct scatterlist *sg;
116
117 len = urb->transfer_buffer_length;
118 i = urb->num_mapped_sgs;
119
120 if (len > 0 && i > 0) { /* Scatter-gather transfer */
121 num = 0;
122 sg = urb->sg;
123 for (;;) {
124 this_sg_len = min_t(int, sg_dma_len(sg), len);
125 num += DIV_ROUND_UP(this_sg_len, 4096);
126 len -= this_sg_len;
127 if (--i <= 0 || len <= 0)
128 break;
129 sg = sg_next(sg);
130 }
131
132 } else { /* Non-SG transfer */
133 /* one TD for every 4096 Bytes (could be up to 8K) */
134 num = DIV_ROUND_UP(len, 4096);
135 }
136 return num;
137}
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/*
140 * queue up an urb for anything except the root hub
141 */
142static int ohci_urb_enqueue (
143 struct usb_hcd *hcd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400145 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146) {
147 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
148 struct ed *ed;
149 urb_priv_t *urb_priv;
150 unsigned int pipe = urb->pipe;
151 int i, size = 0;
152 unsigned long flags;
153 int retval = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 /* every endpoint has a ed, locate and maybe (re)initialize it */
Alan Sterne9df41c2007-08-08 11:48:02 -0400156 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 return -ENOMEM;
158
159 /* for the private part of the URB we need the number of TDs (size) */
160 switch (ed->type) {
161 case PIPE_CONTROL:
162 /* td_submit_urb() doesn't yet handle these */
163 if (urb->transfer_buffer_length > 4096)
164 return -EMSGSIZE;
165
166 /* 1 TD for setup, 1 for ACK, plus ... */
167 size = 2;
168 /* FALLTHROUGH */
169 // case PIPE_INTERRUPT:
170 // case PIPE_BULK:
171 default:
Alan Stern6f651262014-07-17 16:30:01 -0400172 size += number_of_tds(urb);
173 /* maybe a zero-length packet to wrap it up */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 if (size == 0)
175 size++;
176 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
177 && (urb->transfer_buffer_length
178 % usb_maxpacket (urb->dev, pipe,
179 usb_pipeout (pipe))) == 0)
180 size++;
181 break;
182 case PIPE_ISOCHRONOUS: /* number of packets from URB */
183 size = urb->number_of_packets;
184 break;
185 }
186
187 /* allocate the private part of the URB */
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700188 urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 mem_flags);
190 if (!urb_priv)
191 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 INIT_LIST_HEAD (&urb_priv->pending);
193 urb_priv->length = size;
David Brownelldd9048a2006-12-05 03:18:31 -0800194 urb_priv->ed = ed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 /* allocate the TDs (deferring hash chain updates) */
197 for (i = 0; i < size; i++) {
198 urb_priv->td [i] = td_alloc (ohci, mem_flags);
199 if (!urb_priv->td [i]) {
200 urb_priv->length = i;
201 urb_free_priv (ohci, urb_priv);
202 return -ENOMEM;
203 }
David Brownelldd9048a2006-12-05 03:18:31 -0800204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 spin_lock_irqsave (&ohci->lock, flags);
207
208 /* don't submit to a dead HC */
Alan Stern541c7d42010-06-22 16:39:10 -0400209 if (!HCD_HW_ACCESSIBLE(hcd)) {
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100210 retval = -ENODEV;
211 goto fail;
212 }
Alan Sternb7463c72011-11-17 16:41:56 -0500213 if (ohci->rh_state != OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 retval = -ENODEV;
215 goto fail;
216 }
Alan Sterne9df41c2007-08-08 11:48:02 -0400217 retval = usb_hcd_link_urb_to_ep(hcd, urb);
218 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 /* schedule the ed if needed */
222 if (ed->state == ED_IDLE) {
223 retval = ed_schedule (ohci, ed);
Alan Sterne9df41c2007-08-08 11:48:02 -0400224 if (retval < 0) {
225 usb_hcd_unlink_urb_from_ep(hcd, urb);
226 goto fail;
227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (ed->type == PIPE_ISOCHRONOUS) {
229 u16 frame = ohci_frame_no(ohci);
230
231 /* delay a few frames before the first TD */
232 frame += max_t (u16, 8, ed->interval);
233 frame &= ~(ed->interval - 1);
234 frame |= ed->branch;
235 urb->start_frame = frame;
Alan Sterna8693422013-09-24 15:46:45 -0400236 ed->last_iso = frame + ed->interval * (size - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400238 } else if (ed->type == PIPE_ISOCHRONOUS) {
Alan Sterne19440172013-05-14 13:57:19 -0400239 u16 next = ohci_frame_no(ohci) + 1;
Alan Stern6a41b4d2012-10-01 10:32:15 -0400240 u16 frame = ed->last_iso + ed->interval;
Alan Sterna8693422013-09-24 15:46:45 -0400241 u16 length = ed->interval * (size - 1);
Alan Stern6a41b4d2012-10-01 10:32:15 -0400242
243 /* Behind the scheduling threshold? */
244 if (unlikely(tick_before(frame, next))) {
245
Alan Sterna8693422013-09-24 15:46:45 -0400246 /* URB_ISO_ASAP: Round up to the first available slot */
Alan Stern815fa7b2013-05-14 13:57:51 -0400247 if (urb->transfer_flags & URB_ISO_ASAP) {
Alan Stern6a41b4d2012-10-01 10:32:15 -0400248 frame += (next - frame + ed->interval - 1) &
249 -ed->interval;
250
251 /*
Alan Sterna8693422013-09-24 15:46:45 -0400252 * Not ASAP: Use the next slot in the stream,
253 * no matter what.
Alan Stern6a41b4d2012-10-01 10:32:15 -0400254 */
Alan Stern815fa7b2013-05-14 13:57:51 -0400255 } else {
Alan Stern815fa7b2013-05-14 13:57:51 -0400256 /*
257 * Some OHCI hardware doesn't handle late TDs
258 * correctly. After retiring them it proceeds
259 * to the next ED instead of the next TD.
260 * Therefore we have to omit the late TDs
261 * entirely.
262 */
263 urb_priv->td_cnt = DIV_ROUND_UP(
264 (u16) (next - frame),
265 ed->interval);
Alan Sterna8693422013-09-24 15:46:45 -0400266 if (urb_priv->td_cnt >= urb_priv->length) {
267 ++urb_priv->td_cnt; /* Mark it */
268 ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n",
269 urb, frame, length,
270 next);
271 }
Alan Stern815fa7b2013-05-14 13:57:51 -0400272 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400273 }
274 urb->start_frame = frame;
Alan Sterna8693422013-09-24 15:46:45 -0400275 ed->last_iso = frame + length;
Alan Stern6a41b4d2012-10-01 10:32:15 -0400276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 /* fill the TDs and link them to the ed; and
279 * enable that part of the schedule, if needed
280 * and update count of queued periodic urbs
281 */
282 urb->hcpriv = urb_priv;
283 td_submit_urb (ohci, urb);
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285fail:
286 if (retval)
287 urb_free_priv (ohci, urb_priv);
288 spin_unlock_irqrestore (&ohci->lock, flags);
289 return retval;
290}
291
292/*
Alan Stern55d84962007-08-24 15:40:34 -0400293 * decouple the URB from the HC queues (TDs, urb_priv).
294 * reporting is always done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 * asynchronously, and we might be dealing with an urb that's
296 * partially transferred, or an ED with other urbs being unlinked.
297 */
Alan Sterne9df41c2007-08-08 11:48:02 -0400298static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
301 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400302 int rc;
David Brownelldd9048a2006-12-05 03:18:31 -0800303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 spin_lock_irqsave (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400305 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
306 if (rc) {
307 ; /* Do nothing */
Alan Sternb7463c72011-11-17 16:41:56 -0500308 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 urb_priv_t *urb_priv;
310
311 /* Unless an IRQ completed the unlink while it was being
312 * handed to us, flag it for unlink and giveback, and force
313 * some upcoming INTR_SF to call finish_unlinks()
314 */
315 urb_priv = urb->hcpriv;
316 if (urb_priv) {
317 if (urb_priv->ed->state == ED_OPER)
318 start_ed_unlink (ohci, urb_priv->ed);
319 }
320 } else {
321 /*
322 * with HC dead, we won't respect hc queue pointers
323 * any more ... just clean up every urb's memory.
324 */
325 if (urb->hcpriv)
Alan Stern55d84962007-08-24 15:40:34 -0400326 finish_urb(ohci, urb, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328 spin_unlock_irqrestore (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400329 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
332/*-------------------------------------------------------------------------*/
333
334/* frees config/altsetting state for endpoints,
335 * including ED memory, dummy TD, and bulk/intr data toggle
336 */
337
338static void
339ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
340{
341 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
342 unsigned long flags;
343 struct ed *ed = ep->hcpriv;
344 unsigned limit = 1000;
345
346 /* ASSERT: any requests/urbs are being unlinked */
347 /* ASSERT: nobody can be submitting urbs for this any more */
348
349 if (!ed)
350 return;
351
352rescan:
353 spin_lock_irqsave (&ohci->lock, flags);
354
Alan Sternb7463c72011-11-17 16:41:56 -0500355 if (ohci->rh_state != OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356sanitize:
357 ed->state = ED_IDLE;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700358 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
359 ohci->eds_scheduled--;
David Howells7d12e782006-10-05 14:55:46 +0100360 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
363 switch (ed->state) {
364 case ED_UNLINK: /* wait for hw to finish? */
365 /* major IRQ delivery trouble loses INTR_SF too... */
366 if (limit-- == 0) {
Mike Nuss89a0fd12007-08-01 13:24:30 -0700367 ohci_warn(ohci, "ED unlink timeout\n");
368 if (quirk_zfmicro(ohci)) {
369 ohci_warn(ohci, "Attempting ZF TD recovery\n");
370 ohci->ed_to_check = ed;
371 ohci->zf_delay = 2;
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 goto sanitize;
374 }
375 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700376 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 goto rescan;
378 case ED_IDLE: /* fully unlinked */
379 if (list_empty (&ed->td_list)) {
380 td_free (ohci, ed->dummy);
381 ed_free (ohci, ed);
382 break;
383 }
384 /* else FALL THROUGH */
385 default:
386 /* caller was supposed to have unlinked any requests;
387 * that's not our job. can't recover; must leak ed.
388 */
389 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
390 ed, ep->desc.bEndpointAddress, ed->state,
391 list_empty (&ed->td_list) ? "" : " (has tds)");
392 td_free (ohci, ed->dummy);
393 break;
394 }
395 ep->hcpriv = NULL;
396 spin_unlock_irqrestore (&ohci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
399static int ohci_get_frame (struct usb_hcd *hcd)
400{
401 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
402
403 return ohci_frame_no(ohci);
404}
405
406static void ohci_usb_reset (struct ohci_hcd *ohci)
407{
408 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
409 ohci->hc_control &= OHCI_CTRL_RWC;
410 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
Alan Sternb7463c72011-11-17 16:41:56 -0500411 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700414/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700415 * other cases where the next software may expect clean state from the
416 * "firmware". this is bus-neutral, unlike shutdown() methods.
417 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700418static void
419ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700420{
421 struct ohci_hcd *ohci;
422
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700423 ohci = hcd_to_ohci (hcd);
Alan Sternc6187592011-11-17 16:41:45 -0500424 ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
Alan Stern3df71692010-09-10 16:37:05 -0400425
Alan Sternc6187592011-11-17 16:41:45 -0500426 /* Software reset, after which the controller goes into SUSPEND */
427 ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
428 ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */
429 udelay(10);
Alan Stern3df71692010-09-10 16:37:05 -0400430
Alan Sternc6187592011-11-17 16:41:45 -0500431 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
David Brownellf4df0e32005-04-23 12:49:16 -0700432}
433
Mike Nuss89a0fd12007-08-01 13:24:30 -0700434static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
435{
436 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
437 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
438 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
439 && !list_empty(&ed->td_list);
440}
441
442/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
443 * an interrupt TD but neglects to add it to the donelist. On systems with
444 * this chipset, we need to periodically check the state of the queues to look
445 * for such "lost" TDs.
446 */
447static void unlink_watchdog_func(unsigned long _ohci)
448{
David Brownellda6fb572007-10-24 17:23:42 -0700449 unsigned long flags;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700450 unsigned max;
451 unsigned seen_count = 0;
452 unsigned i;
453 struct ed **seen = NULL;
454 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
455
456 spin_lock_irqsave(&ohci->lock, flags);
457 max = ohci->eds_scheduled;
458 if (!max)
459 goto done;
460
461 if (ohci->ed_to_check)
462 goto out;
463
464 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
465 if (!seen)
466 goto out;
467
468 for (i = 0; i < NUM_INTS; i++) {
469 struct ed *ed = ohci->periodic[i];
470
471 while (ed) {
472 unsigned temp;
473
474 /* scan this branch of the periodic schedule tree */
475 for (temp = 0; temp < seen_count; temp++) {
476 if (seen[temp] == ed) {
477 /* we've checked it and what's after */
478 ed = NULL;
479 break;
480 }
481 }
482 if (!ed)
483 break;
484 seen[seen_count++] = ed;
485 if (!check_ed(ohci, ed)) {
486 ed = ed->ed_next;
487 continue;
488 }
489
490 /* HC's TD list is empty, but HCD sees at least one
491 * TD that's not been sent through the donelist.
492 */
493 ohci->ed_to_check = ed;
494 ohci->zf_delay = 2;
495
496 /* The HC may wait until the next frame to report the
497 * TD as done through the donelist and INTR_WDH. (We
498 * just *assume* it's not a multi-TD interrupt URB;
499 * those could defer the IRQ more than one frame, using
500 * DI...) Check again after the next INTR_SF.
501 */
502 ohci_writel(ohci, OHCI_INTR_SF,
503 &ohci->regs->intrstatus);
504 ohci_writel(ohci, OHCI_INTR_SF,
505 &ohci->regs->intrenable);
506
507 /* flush those writes */
508 (void) ohci_readl(ohci, &ohci->regs->control);
509
510 goto out;
511 }
512 }
513out:
514 kfree(seen);
515 if (ohci->eds_scheduled)
Richard Kennedy9cebcdc2008-03-28 14:50:30 -0700516 mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700517done:
518 spin_unlock_irqrestore(&ohci->lock, flags);
519}
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521/*-------------------------------------------------------------------------*
522 * HC functions
523 *-------------------------------------------------------------------------*/
524
525/* init memory, and kick BIOS/SMM off */
526
527static int ohci_init (struct ohci_hcd *ohci)
528{
529 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800530 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Alan Stern6f651262014-07-17 16:30:01 -0400532 /* Accept arbitrarily long scatter-gather lists */
533 hcd->self.sg_tablesize = ~0;
534
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400535 if (distrust_firmware)
536 ohci->flags |= OHCI_QUIRK_HUB_POWER;
537
Alan Sternb7463c72011-11-17 16:41:56 -0500538 ohci->rh_state = OHCI_RH_HALTED;
David Brownell6a9062f2006-01-23 15:28:07 -0800539 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
David Brownell6a9062f2006-01-23 15:28:07 -0800541 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
542 * was never needed for most non-PCI systems ... remove the code?
543 */
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#ifndef IR_DISABLE
546 /* SMM owns the HC? not for long! */
547 if (!no_handshake && ohci_readl (ohci,
548 &ohci->regs->control) & OHCI_CTRL_IR) {
549 u32 temp;
550
551 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
552
553 /* this timeout is arbitrary. we make it long, so systems
554 * depending on usb keyboards may be usable even if the
555 * BIOS/SMM code seems pretty broken.
556 */
557 temp = 500; /* arbitrary: five seconds */
558
559 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
560 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
561 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
562 msleep (10);
563 if (--temp == 0) {
564 ohci_err (ohci, "USB HC takeover failed!"
565 " (BIOS/SMM bug)\n");
566 return -EBUSY;
567 }
568 }
569 ohci_usb_reset (ohci);
570 }
571#endif
572
573 /* Disable HC interrupts */
574 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800575
576 /* flush the writes, and save key bits like RWC */
577 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
578 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
David Brownellfdd13b32005-08-31 11:52:57 -0700580 /* Read the number of ports unless overridden */
581 if (ohci->num_ports == 0)
582 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if (ohci->hcca)
585 return 0;
586
David Brownell6a9062f2006-01-23 15:28:07 -0800587 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Vladimir Zapolskiy44285242014-07-03 21:37:41 +0300588 sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 if (!ohci->hcca)
590 return -ENOMEM;
591
592 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800593 ohci_stop (hcd);
594 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800595 create_debug_files (ohci);
596 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
601/*-------------------------------------------------------------------------*/
602
603/* Start an OHCI controller, set the BUS operational
604 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800605 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 */
607static int ohci_run (struct ohci_hcd *ohci)
608{
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400609 u32 mask, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800611 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Alan Sternb7463c72011-11-17 16:41:56 -0500613 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 /* boot firmware should have set this up (5.1.1.3.1) */
616 if (first) {
617
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400618 val = ohci_readl (ohci, &ohci->regs->fminterval);
619 ohci->fminterval = val & 0x3fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 if (ohci->fminterval != FI)
621 ohci_dbg (ohci, "fminterval delta %d\n",
622 ohci->fminterval - FI);
623 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
624 /* also: power/overcurrent flags in roothub.a */
625 }
626
Alan Stern6fd90862008-12-17 17:20:38 -0500627 /* Reset USB nearly "by the book". RemoteWakeupConnected has
628 * to be checked in case boot firmware (BIOS/SMM/...) has set up
629 * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
630 * If the bus glue detected wakeup capability then it should
Alan Sternbcca06e2009-01-13 11:35:54 -0500631 * already be enabled; if so we'll just enable it again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 */
Alan Sternbcca06e2009-01-13 11:35:54 -0500633 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
634 device_set_wakeup_capable(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
637 case OHCI_USB_OPER:
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400638 val = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 break;
640 case OHCI_USB_SUSPEND:
641 case OHCI_USB_RESUME:
642 ohci->hc_control &= OHCI_CTRL_RWC;
643 ohci->hc_control |= OHCI_USB_RESUME;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400644 val = 10 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 break;
646 // case OHCI_USB_RESET:
647 default:
648 ohci->hc_control &= OHCI_CTRL_RWC;
649 ohci->hc_control |= OHCI_USB_RESET;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400650 val = 50 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 break;
652 }
653 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
654 // flush the writes
655 (void) ohci_readl (ohci, &ohci->regs->control);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400656 msleep(val);
Alan Stern383975d2007-05-04 11:52:40 -0400657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
659
660 /* 2msec timelimit here means no irqs/preempt */
661 spin_lock_irq (&ohci->lock);
662
663retry:
664 /* HC Reset requires max 10 us delay */
665 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400666 val = 30; /* ... allow extra time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400668 if (--val == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 spin_unlock_irq (&ohci->lock);
670 ohci_err (ohci, "USB HC reset timed out!\n");
671 return -1;
672 }
673 udelay (1);
674 }
675
676 /* now we're in the SUSPEND state ... must go OPERATIONAL
677 * within 2msec else HC enters RESUME
678 *
679 * ... but some hardware won't init fmInterval "by the book"
680 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
681 * this if we write fmInterval after we're OPERATIONAL.
682 * Unclear about ALi, ServerWorks, and others ... this could
683 * easily be a longstanding bug in chip init on Linux.
684 */
685 if (ohci->flags & OHCI_QUIRK_INITRESET) {
686 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
687 // flush those writes
688 (void) ohci_readl (ohci, &ohci->regs->control);
689 }
690
691 /* Tell the controller where the control and bulk lists are
692 * The lists are empty now. */
693 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
694 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
695
696 /* a reset clears this */
697 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
698
699 periodic_reinit (ohci);
700
701 /* some OHCI implementations are finicky about how they init.
702 * bogus values here mean not even enumeration could work.
703 */
704 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
705 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
706 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
707 ohci->flags |= OHCI_QUIRK_INITRESET;
708 ohci_dbg (ohci, "enabling initreset quirk\n");
709 goto retry;
710 }
711 spin_unlock_irq (&ohci->lock);
712 ohci_err (ohci, "init err (%08x %04x)\n",
713 ohci_readl (ohci, &ohci->regs->fminterval),
714 ohci_readl (ohci, &ohci->regs->periodicstart));
715 return -EOVERFLOW;
716 }
717
David Brownelld4139842006-08-04 11:31:55 -0700718 /* use rhsc irqs after khubd is fully initialized */
Alan Stern541c7d42010-06-22 16:39:10 -0400719 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
David Brownelld4139842006-08-04 11:31:55 -0700720 hcd->uses_new_polling = 1;
721
722 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700724 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
725 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
Alan Sternb7463c72011-11-17 16:41:56 -0500726 ohci->rh_state = OHCI_RH_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 /* wake on ConnectStatusChange, matching external hubs */
729 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
730
731 /* Choose the interrupts we care about now, others later on demand */
732 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700733 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 ohci_writel (ohci, mask, &ohci->regs->intrenable);
735
736 /* handle root hub init quirks ... */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400737 val = roothub_a (ohci);
738 val &= ~(RH_A_PSM | RH_A_OCPM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
740 /* NSC 87560 and maybe others */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400741 val |= RH_A_NOCP;
742 val &= ~(RH_A_POTPGT | RH_A_NPS);
743 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400744 } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
745 (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 /* hub power always on; required for AMD-756 and some
747 * Mac platforms. ganged overcurrent reporting, if any.
748 */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400749 val |= RH_A_NPS;
750 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 }
752 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400753 ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 &ohci->regs->roothub.b);
755 // flush those writes
756 (void) ohci_readl (ohci, &ohci->regs->control);
757
David Brownelld4139842006-08-04 11:31:55 -0700758 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 spin_unlock_irq (&ohci->lock);
760
761 // POTPGT delay is bits 24-31, in 2 ms units.
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400762 mdelay ((val >> 23) & 0x1fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Mike Nuss89a0fd12007-08-01 13:24:30 -0700764 if (quirk_zfmicro(ohci)) {
765 /* Create timer to watch for bad queue state on ZF Micro */
766 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
767 (unsigned long) ohci);
768
769 ohci->eds_scheduled = 0;
770 ohci->ed_to_check = NULL;
771 }
772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 ohci_dump (ohci, 1);
774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 return 0;
776}
777
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530778/* ohci_setup routine for generic controller initialization */
779
780int ohci_setup(struct usb_hcd *hcd)
781{
782 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
783
784 ohci_hcd_init(ohci);
785
786 return ohci_init(ohci);
787}
788EXPORT_SYMBOL_GPL(ohci_setup);
789
790/* ohci_start routine for generic controller start of all OHCI bus glue */
791static int ohci_start(struct usb_hcd *hcd)
792{
793 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
794 int ret;
795
796 ret = ohci_run(ohci);
797 if (ret < 0) {
798 ohci_err(ohci, "can't start\n");
799 ohci_stop(hcd);
800 }
801 return ret;
802}
803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804/*-------------------------------------------------------------------------*/
805
806/* an interrupt happens */
807
David Howells7d12e782006-10-05 14:55:46 +0100808static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
810 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
811 struct ohci_regs __iomem *regs = ohci->regs;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700812 int ints;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800814 /* Read interrupt status (and flush pending writes). We ignore the
815 * optimization of checking the LSB of hcca->done_head; it doesn't
816 * work on all systems (edge triggering for OHCI can be a factor).
Mike Nuss89a0fd12007-08-01 13:24:30 -0700817 */
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800818 ints = ohci_readl(ohci, &regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800820 /* Check for an all 1's result which is a typical consequence
821 * of dead, unclocked, or unplugged (CardBus...) devices
822 */
823 if (ints == ~(u32)0) {
Alan Sternb7463c72011-11-17 16:41:56 -0500824 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 ohci_dbg (ohci, "device removed!\n");
Alan Stern69fff592011-05-17 17:27:12 -0400826 usb_hc_died(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return IRQ_HANDLED;
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800828 }
829
830 /* We only care about interrupts that are enabled */
831 ints &= ohci_readl(ohci, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 /* interrupt for some other device? */
Alan Sternb7463c72011-11-17 16:41:56 -0500834 if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 if (ints & OHCI_INTR_UE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 // e.g. due to PCI Master/Target Abort
Mike Nuss89a0fd12007-08-01 13:24:30 -0700839 if (quirk_nec(ohci)) {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200840 /* Workaround for a silicon bug in some NEC chips used
841 * in Apple's PowerBooks. Adapted from Darwin code.
842 */
843 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
844
845 ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
846
847 schedule_work (&ohci->nec_work);
848 } else {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200849 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
Alan Sternb7463c72011-11-17 16:41:56 -0500850 ohci->rh_state = OHCI_RH_HALTED;
Alan Stern69fff592011-05-17 17:27:12 -0400851 usb_hc_died(hcd);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 ohci_dump (ohci, 1);
855 ohci_usb_reset (ohci);
856 }
857
Alan Stern583cead2006-10-24 12:04:22 -0400858 if (ints & OHCI_INTR_RHSC) {
Oliver Neukumd2c42542013-11-18 13:22:58 +0100859 ohci_dbg(ohci, "rhsc\n");
Alan Stern583cead2006-10-24 12:04:22 -0400860 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
861 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
862 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400863
864 /* NOTE: Vendors didn't always make the same implementation
865 * choices for RHSC. Many followed the spec; RHSC triggers
866 * on an edge, like setting and maybe clearing a port status
867 * change bit. With others it's level-triggered, active
868 * until khubd clears all the port status change bits. We'll
869 * always disable it here and rely on polling until khubd
870 * re-enables it.
871 */
872 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400873 usb_hcd_poll_rh_status(hcd);
874 }
875
876 /* For connect and disconnect events, we expect the controller
877 * to turn on RHSC along with RD. But for remote wakeup events
878 * this might not happen.
879 */
880 else if (ints & OHCI_INTR_RD) {
Oliver Neukumd2c42542013-11-18 13:22:58 +0100881 ohci_dbg(ohci, "resume detect\n");
Alan Stern583cead2006-10-24 12:04:22 -0400882 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern541c7d42010-06-22 16:39:10 -0400883 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
Alan Stern8d1a2432006-09-26 14:46:16 -0400884 if (ohci->autostop) {
885 spin_lock (&ohci->lock);
886 ohci_rh_resume (ohci);
887 spin_unlock (&ohci->lock);
888 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700889 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 }
891
892 if (ints & OHCI_INTR_WDH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100894 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 spin_unlock (&ohci->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
David Brownelldd9048a2006-12-05 03:18:31 -0800897
Mike Nuss89a0fd12007-08-01 13:24:30 -0700898 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
899 spin_lock(&ohci->lock);
900 if (ohci->ed_to_check) {
901 struct ed *ed = ohci->ed_to_check;
902
903 if (check_ed(ohci, ed)) {
904 /* HC thinks the TD list is empty; HCD knows
905 * at least one TD is outstanding
906 */
907 if (--ohci->zf_delay == 0) {
908 struct td *td = list_entry(
909 ed->td_list.next,
910 struct td, td_list);
911 ohci_warn(ohci,
912 "Reclaiming orphan TD %p\n",
913 td);
914 takeback_td(ohci, td);
915 ohci->ed_to_check = NULL;
916 }
917 } else
918 ohci->ed_to_check = NULL;
919 }
920 spin_unlock(&ohci->lock);
921 }
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 /* could track INTR_SO to reduce available PCI/... bandwidth */
924
925 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
926 * when there's still unlinking to be done (next frame).
927 */
928 spin_lock (&ohci->lock);
929 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100930 finish_unlinks (ohci, ohci_frame_no(ohci));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700931 if ((ints & OHCI_INTR_SF) != 0
932 && !ohci->ed_rm_list
933 && !ohci->ed_to_check
Alan Sternb7463c72011-11-17 16:41:56 -0500934 && ohci->rh_state == OHCI_RH_RUNNING)
David Brownelldd9048a2006-12-05 03:18:31 -0800935 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 spin_unlock (&ohci->lock);
937
Alan Sternb7463c72011-11-17 16:41:56 -0500938 if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800940 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 // flush those writes
942 (void) ohci_readl (ohci, &ohci->regs->control);
943 }
944
945 return IRQ_HANDLED;
946}
947
948/*-------------------------------------------------------------------------*/
949
950static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800951{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 ohci_dump (ohci, 1);
955
Tejun Heo569ff2d2010-12-24 16:14:20 +0100956 if (quirk_nec(ohci))
Tejun Heo43829732012-08-20 14:51:24 -0700957 flush_work(&ohci->nec_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
caizhiyong435932f2013-07-26 07:12:14 +0000960 ohci_usb_reset(ohci);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700961 free_irq(hcd->irq, hcd);
Felipe Balbicd704692012-02-29 16:46:23 +0200962 hcd->irq = 0;
Pete Zaitcev71795c12006-09-18 22:57:22 -0700963
Mike Nuss89a0fd12007-08-01 13:24:30 -0700964 if (quirk_zfmicro(ohci))
965 del_timer(&ohci->unlink_watchdog);
Libin Yangab1666c2008-08-08 15:03:31 +0800966 if (quirk_amdiso(ohci))
Andiry Xuad935622011-03-01 14:57:05 +0800967 usb_amd_dev_put();
Mike Nuss89a0fd12007-08-01 13:24:30 -0700968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 ohci_mem_cleanup (ohci);
971 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800972 dma_free_coherent (hcd->self.controller,
973 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 ohci->hcca, ohci->hcca_dma);
975 ohci->hcca = NULL;
976 ohci->hcca_dma = 0;
977 }
978}
979
980/*-------------------------------------------------------------------------*/
981
David Brownellda6fb572007-10-24 17:23:42 -0700982#if defined(CONFIG_PM) || defined(CONFIG_PCI)
983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984/* must not be called from interrupt context */
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530985int ohci_restart(struct ohci_hcd *ohci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
987 int temp;
988 int i;
989 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530991 ohci_init(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 spin_lock_irq(&ohci->lock);
Alan Sternb7463c72011-11-17 16:41:56 -0500993 ohci->rh_state = OHCI_RH_HALTED;
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200994
995 /* Recycle any "live" eds/tds (and urbs). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 if (!list_empty (&ohci->pending))
997 ohci_dbg(ohci, "abort schedule...\n");
998 list_for_each_entry (priv, &ohci->pending, pending) {
999 struct urb *urb = priv->td[0]->urb;
1000 struct ed *ed = priv->ed;
1001
1002 switch (ed->state) {
1003 case ED_OPER:
1004 ed->state = ED_UNLINK;
1005 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
1006 ed_deschedule (ohci, ed);
1007
1008 ed->ed_next = ohci->ed_rm_list;
1009 ed->ed_prev = NULL;
1010 ohci->ed_rm_list = ed;
1011 /* FALLTHROUGH */
1012 case ED_UNLINK:
1013 break;
1014 default:
1015 ohci_dbg(ohci, "bogus ed %p state %d\n",
1016 ed, ed->state);
1017 }
1018
Alan Stern55d84962007-08-24 15:40:34 -04001019 if (!urb->unlinked)
1020 urb->unlinked = -ESHUTDOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 }
David Howells7d12e782006-10-05 14:55:46 +01001022 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 spin_unlock_irq(&ohci->lock);
1024
1025 /* paranoia, in case that didn't work: */
1026
1027 /* empty the interrupt branches */
1028 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
1029 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -08001030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 /* no EDs to remove */
1032 ohci->ed_rm_list = NULL;
1033
David Brownelldd9048a2006-12-05 03:18:31 -08001034 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 ohci->ed_controltail = NULL;
1036 ohci->ed_bulktail = NULL;
1037
1038 if ((temp = ohci_run (ohci)) < 0) {
1039 ohci_err (ohci, "can't restart, %d\n", temp);
1040 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
Alan Stern383975d2007-05-04 11:52:40 -04001042 ohci_dbg(ohci, "restart complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 return 0;
1044}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301045EXPORT_SYMBOL_GPL(ohci_restart);
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001046
David Brownellda6fb572007-10-24 17:23:42 -07001047#endif
1048
Florian Fainellicd1965d2012-10-08 15:11:27 +02001049#ifdef CONFIG_PM
1050
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301051int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001052{
1053 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
1054 unsigned long flags;
Majunath Goudare1bffbf2013-11-13 17:40:16 +05301055 int rc = 0;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001056
Florian Fainellid4ae47d2012-10-08 15:11:28 +02001057 /* Disable irq emission and mark HW unaccessible. Use
Florian Fainellicd1965d2012-10-08 15:11:27 +02001058 * the spinlock to properly synchronize with possible pending
1059 * RH suspend or resume activity.
1060 */
1061 spin_lock_irqsave (&ohci->lock, flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001062 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
1063 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
1064
1065 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001066 spin_unlock_irqrestore (&ohci->lock, flags);
1067
Majunath Goudare1bffbf2013-11-13 17:40:16 +05301068 synchronize_irq(hcd->irq);
1069
1070 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
1071 ohci_resume(hcd, false);
1072 rc = -EBUSY;
1073 }
1074 return rc;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001075}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301076EXPORT_SYMBOL_GPL(ohci_suspend);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001077
1078
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301079int ohci_resume(struct usb_hcd *hcd, bool hibernated)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001080{
Florian Fainellicfa49b42012-10-08 15:11:29 +02001081 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
1082 int port;
1083 bool need_reinit = false;
1084
Florian Fainellicd1965d2012-10-08 15:11:27 +02001085 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1086
1087 /* Make sure resume from hibernation re-enumerates everything */
1088 if (hibernated)
Florian Fainellicfa49b42012-10-08 15:11:29 +02001089 ohci_usb_reset(ohci);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001090
Florian Fainellicfa49b42012-10-08 15:11:29 +02001091 /* See if the controller is already running or has been reset */
1092 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
1093 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
1094 need_reinit = true;
1095 } else {
1096 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
1097 case OHCI_USB_OPER:
1098 case OHCI_USB_RESET:
1099 need_reinit = true;
1100 }
1101 }
1102
1103 /* If needed, reinitialize and suspend the root hub */
1104 if (need_reinit) {
1105 spin_lock_irq(&ohci->lock);
1106 ohci_rh_resume(ohci);
1107 ohci_rh_suspend(ohci, 0);
1108 spin_unlock_irq(&ohci->lock);
1109 }
1110
1111 /* Normally just turn on port power and enable interrupts */
1112 else {
1113 ohci_dbg(ohci, "powerup ports\n");
1114 for (port = 0; port < ohci->num_ports; port++)
1115 ohci_writel(ohci, RH_PS_PPS,
1116 &ohci->regs->roothub.portstatus[port]);
1117
1118 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
1119 ohci_readl(ohci, &ohci->regs->intrenable);
1120 msleep(20);
1121 }
1122
1123 usb_hcd_resume_root_hub(hcd);
1124
Florian Fainellicd1965d2012-10-08 15:11:27 +02001125 return 0;
1126}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301127EXPORT_SYMBOL_GPL(ohci_resume);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001128
1129#endif
1130
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001131/*-------------------------------------------------------------------------*/
1132
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301133/*
1134 * Generic structure: This gets copied for platform drivers so that
1135 * individual entries can be overridden as needed.
1136 */
1137
1138static const struct hc_driver ohci_hc_driver = {
1139 .description = hcd_name,
1140 .product_desc = "OHCI Host Controller",
1141 .hcd_priv_size = sizeof(struct ohci_hcd),
1142
1143 /*
1144 * generic hardware linkage
1145 */
1146 .irq = ohci_irq,
1147 .flags = HCD_MEMORY | HCD_USB11,
1148
1149 /*
1150 * basic lifecycle operations
1151 */
1152 .reset = ohci_setup,
1153 .start = ohci_start,
1154 .stop = ohci_stop,
1155 .shutdown = ohci_shutdown,
1156
1157 /*
1158 * managing i/o requests and associated device resources
1159 */
1160 .urb_enqueue = ohci_urb_enqueue,
1161 .urb_dequeue = ohci_urb_dequeue,
1162 .endpoint_disable = ohci_endpoint_disable,
1163
1164 /*
1165 * scheduling support
1166 */
1167 .get_frame_number = ohci_get_frame,
1168
1169 /*
1170 * root hub support
1171 */
1172 .hub_status_data = ohci_hub_status_data,
1173 .hub_control = ohci_hub_control,
1174#ifdef CONFIG_PM
1175 .bus_suspend = ohci_bus_suspend,
1176 .bus_resume = ohci_bus_resume,
1177#endif
1178 .start_port_reset = ohci_start_port_reset,
1179};
1180
1181void ohci_init_driver(struct hc_driver *drv,
1182 const struct ohci_driver_overrides *over)
1183{
1184 /* Copy the generic table to drv and then apply the overrides */
1185 *drv = ohci_hc_driver;
1186
Kevin Hilmanc80ad6d2013-09-27 08:10:32 -07001187 if (over) {
1188 drv->product_desc = over->product_desc;
1189 drv->hcd_priv_size += over->extra_priv_size;
1190 if (over->reset)
1191 drv->reset = over->reset;
1192 }
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301193}
1194EXPORT_SYMBOL_GPL(ohci_init_driver);
1195
1196/*-------------------------------------------------------------------------*/
1197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198MODULE_AUTHOR (DRIVER_AUTHOR);
Alan Stern2b70f072008-10-02 11:47:15 -04001199MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200MODULE_LICENSE ("GPL");
1201
Eric Miao6381fad2008-06-02 10:05:30 +08001202#if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001204#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205#endif
1206
Arnd Bergmann068413e2014-05-08 15:52:21 +02001207#ifdef CONFIG_USB_OHCI_HCD_DAVINCI
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001208#include "ohci-da8xx.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001209#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001210#endif
1211
Sylvain Munaut495a6782006-12-13 21:09:55 +01001212#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1213#include "ohci-ppc-of.c"
1214#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1215#endif
1216
Geoff Levand6a6c9572007-01-15 20:12:10 -08001217#ifdef CONFIG_PPC_PS3
1218#include "ohci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001219#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
Geoff Levand6a6c9572007-01-15 20:12:10 -08001220#endif
1221
Magnus Dammf54aab62008-01-23 15:58:46 +09001222#ifdef CONFIG_MFD_SM501
1223#include "ohci-sm501.c"
Ben Dooks3ee38d82008-06-08 17:20:11 +01001224#define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
Magnus Dammf54aab62008-01-23 15:58:46 +09001225#endif
1226
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001227#ifdef CONFIG_MFD_TC6393XB
1228#include "ohci-tmio.c"
1229#define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
1230#endif
1231
Lars-Peter Clausen22490712010-06-19 04:08:24 +00001232#ifdef CONFIG_MACH_JZ4740
1233#include "ohci-jz4740.c"
1234#define PLATFORM_DRIVER ohci_hcd_jz4740_driver
1235#endif
1236
David Daney1643acc2010-10-08 14:47:52 -07001237#ifdef CONFIG_USB_OCTEON_OHCI
1238#include "ohci-octeon.c"
1239#define PLATFORM_DRIVER ohci_octeon_driver
1240#endif
1241
Chris Metcalf47fc28b2012-05-09 13:58:14 -04001242#ifdef CONFIG_TILE_USB
1243#include "ohci-tilegx.c"
1244#define PLATFORM_DRIVER ohci_hcd_tilegx_driver
1245#endif
1246
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001247static int __init ohci_hcd_mod_init(void)
1248{
1249 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001250
1251 if (usb_disabled())
1252 return -ENODEV;
1253
Alan Stern2b70f072008-10-02 11:47:15 -04001254 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001255 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1256 sizeof (struct ed), sizeof (struct td));
Alan Stern9beeee62008-10-02 11:48:13 -04001257 set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001258
Greg Kroah-Hartman485f4f32009-04-24 15:14:38 -07001259 ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
Tony Jones684c19e2007-09-11 14:07:31 -07001260 if (!ohci_debug_root) {
1261 retval = -ENOENT;
1262 goto error_debug;
1263 }
Tony Jones684c19e2007-09-11 14:07:31 -07001264
Geoff Levand6a6c9572007-01-15 20:12:10 -08001265#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001266 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1267 if (retval < 0)
1268 goto error_ps3;
Geoff Levand6a6c9572007-01-15 20:12:10 -08001269#endif
1270
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001271#ifdef PLATFORM_DRIVER
1272 retval = platform_driver_register(&PLATFORM_DRIVER);
1273 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001274 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001275#endif
1276
Sylvain Munaut495a6782006-12-13 21:09:55 +01001277#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001278 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001279 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001280 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +01001281#endif
1282
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001283#ifdef SA1111_DRIVER
1284 retval = sa1111_driver_register(&SA1111_DRIVER);
1285 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001286 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001287#endif
1288
Ben Dooks3ee38d82008-06-08 17:20:11 +01001289#ifdef SM501_OHCI_DRIVER
1290 retval = platform_driver_register(&SM501_OHCI_DRIVER);
1291 if (retval < 0)
1292 goto error_sm501;
1293#endif
1294
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001295#ifdef TMIO_OHCI_DRIVER
1296 retval = platform_driver_register(&TMIO_OHCI_DRIVER);
1297 if (retval < 0)
1298 goto error_tmio;
1299#endif
1300
Arnd Bergmann80978042013-04-25 19:29:04 +02001301#ifdef DAVINCI_PLATFORM_DRIVER
1302 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
1303 if (retval < 0)
1304 goto error_davinci;
1305#endif
1306
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001307 return retval;
1308
1309 /* Error path */
Arnd Bergmann80978042013-04-25 19:29:04 +02001310#ifdef DAVINCI_PLATFORM_DRIVER
1311 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1312 error_davinci:
1313#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001314#ifdef TMIO_OHCI_DRIVER
1315 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1316 error_tmio:
1317#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001318#ifdef SM501_OHCI_DRIVER
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001319 platform_driver_unregister(&SM501_OHCI_DRIVER);
Ben Dooks3ee38d82008-06-08 17:20:11 +01001320 error_sm501:
1321#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001322#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001323 sa1111_driver_unregister(&SA1111_DRIVER);
1324 error_sa1111:
1325#endif
1326#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001327 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001328 error_of_platform:
1329#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001330#ifdef PLATFORM_DRIVER
1331 platform_driver_unregister(&PLATFORM_DRIVER);
1332 error_platform:
Anand Gadiyar968b4482010-05-10 21:56:12 +05301333#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001334#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001335 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001336 error_ps3:
1337#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001338 debugfs_remove(ohci_debug_root);
1339 ohci_debug_root = NULL;
1340 error_debug:
Tony Jones684c19e2007-09-11 14:07:31 -07001341
Alan Stern9beeee62008-10-02 11:48:13 -04001342 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001343 return retval;
1344}
1345module_init(ohci_hcd_mod_init);
1346
1347static void __exit ohci_hcd_mod_exit(void)
1348{
Arnd Bergmann80978042013-04-25 19:29:04 +02001349#ifdef DAVINCI_PLATFORM_DRIVER
1350 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1351#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001352#ifdef TMIO_OHCI_DRIVER
1353 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1354#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001355#ifdef SM501_OHCI_DRIVER
1356 platform_driver_unregister(&SM501_OHCI_DRIVER);
1357#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001358#ifdef SA1111_DRIVER
1359 sa1111_driver_unregister(&SA1111_DRIVER);
1360#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001361#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001362 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001363#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001364#ifdef PLATFORM_DRIVER
1365 platform_driver_unregister(&PLATFORM_DRIVER);
1366#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001367#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001368 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001369#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001370 debugfs_remove(ohci_debug_root);
Alan Stern9beeee62008-10-02 11:48:13 -04001371 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001372}
1373module_exit(ohci_hcd_mod_exit);
1374