blob: 8f6b695af6a470c5f5d5a5ca6a278e3a1186dfcc [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400220 } else if (ed->type == PIPE_ISOCHRONOUS) {
Alan Sterne19440172013-05-14 13:57:19 -0400221 u16 next = ohci_frame_no(ohci) + 1;
Alan Stern6a41b4d2012-10-01 10:32:15 -0400222 u16 frame = ed->last_iso + ed->interval;
223
224 /* Behind the scheduling threshold? */
225 if (unlikely(tick_before(frame, next))) {
226
227 /* USB_ISO_ASAP: Round up to the first available slot */
Alan Stern815fa7b2013-05-14 13:57:51 -0400228 if (urb->transfer_flags & URB_ISO_ASAP) {
Alan Stern6a41b4d2012-10-01 10:32:15 -0400229 frame += (next - frame + ed->interval - 1) &
230 -ed->interval;
231
232 /*
233 * Not ASAP: Use the next slot in the stream. If
234 * the entire URB falls before the threshold, fail.
235 */
Alan Stern815fa7b2013-05-14 13:57:51 -0400236 } else {
237 if (tick_before(frame + ed->interval *
Alan Stern6a41b4d2012-10-01 10:32:15 -0400238 (urb->number_of_packets - 1), next)) {
Alan Stern815fa7b2013-05-14 13:57:51 -0400239 retval = -EXDEV;
240 usb_hcd_unlink_urb_from_ep(hcd, urb);
241 goto fail;
242 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400243
Alan Stern815fa7b2013-05-14 13:57:51 -0400244 /*
245 * Some OHCI hardware doesn't handle late TDs
246 * correctly. After retiring them it proceeds
247 * to the next ED instead of the next TD.
248 * Therefore we have to omit the late TDs
249 * entirely.
250 */
251 urb_priv->td_cnt = DIV_ROUND_UP(
252 (u16) (next - frame),
253 ed->interval);
254 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400255 }
256 urb->start_frame = frame;
257 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 /* fill the TDs and link them to the ed; and
260 * enable that part of the schedule, if needed
261 * and update count of queued periodic urbs
262 */
263 urb->hcpriv = urb_priv;
264 td_submit_urb (ohci, urb);
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266fail:
267 if (retval)
268 urb_free_priv (ohci, urb_priv);
269 spin_unlock_irqrestore (&ohci->lock, flags);
270 return retval;
271}
272
273/*
Alan Stern55d84962007-08-24 15:40:34 -0400274 * decouple the URB from the HC queues (TDs, urb_priv).
275 * reporting is always done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 * asynchronously, and we might be dealing with an urb that's
277 * partially transferred, or an ED with other urbs being unlinked.
278 */
Alan Sterne9df41c2007-08-08 11:48:02 -0400279static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
281 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
282 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400283 int rc;
David Brownelldd9048a2006-12-05 03:18:31 -0800284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285#ifdef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -0400286 urb_print(urb, "UNLINK", 1, status);
David Brownelldd9048a2006-12-05 03:18:31 -0800287#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 spin_lock_irqsave (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400290 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
291 if (rc) {
292 ; /* Do nothing */
Alan Sternb7463c72011-11-17 16:41:56 -0500293 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 urb_priv_t *urb_priv;
295
296 /* Unless an IRQ completed the unlink while it was being
297 * handed to us, flag it for unlink and giveback, and force
298 * some upcoming INTR_SF to call finish_unlinks()
299 */
300 urb_priv = urb->hcpriv;
301 if (urb_priv) {
302 if (urb_priv->ed->state == ED_OPER)
303 start_ed_unlink (ohci, urb_priv->ed);
304 }
305 } else {
306 /*
307 * with HC dead, we won't respect hc queue pointers
308 * any more ... just clean up every urb's memory.
309 */
310 if (urb->hcpriv)
Alan Stern55d84962007-08-24 15:40:34 -0400311 finish_urb(ohci, urb, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 }
313 spin_unlock_irqrestore (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400314 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
317/*-------------------------------------------------------------------------*/
318
319/* frees config/altsetting state for endpoints,
320 * including ED memory, dummy TD, and bulk/intr data toggle
321 */
322
323static void
324ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
325{
326 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
327 unsigned long flags;
328 struct ed *ed = ep->hcpriv;
329 unsigned limit = 1000;
330
331 /* ASSERT: any requests/urbs are being unlinked */
332 /* ASSERT: nobody can be submitting urbs for this any more */
333
334 if (!ed)
335 return;
336
337rescan:
338 spin_lock_irqsave (&ohci->lock, flags);
339
Alan Sternb7463c72011-11-17 16:41:56 -0500340 if (ohci->rh_state != OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341sanitize:
342 ed->state = ED_IDLE;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700343 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
344 ohci->eds_scheduled--;
David Howells7d12e782006-10-05 14:55:46 +0100345 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347
348 switch (ed->state) {
349 case ED_UNLINK: /* wait for hw to finish? */
350 /* major IRQ delivery trouble loses INTR_SF too... */
351 if (limit-- == 0) {
Mike Nuss89a0fd12007-08-01 13:24:30 -0700352 ohci_warn(ohci, "ED unlink timeout\n");
353 if (quirk_zfmicro(ohci)) {
354 ohci_warn(ohci, "Attempting ZF TD recovery\n");
355 ohci->ed_to_check = ed;
356 ohci->zf_delay = 2;
357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 goto sanitize;
359 }
360 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700361 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 goto rescan;
363 case ED_IDLE: /* fully unlinked */
364 if (list_empty (&ed->td_list)) {
365 td_free (ohci, ed->dummy);
366 ed_free (ohci, ed);
367 break;
368 }
369 /* else FALL THROUGH */
370 default:
371 /* caller was supposed to have unlinked any requests;
372 * that's not our job. can't recover; must leak ed.
373 */
374 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
375 ed, ep->desc.bEndpointAddress, ed->state,
376 list_empty (&ed->td_list) ? "" : " (has tds)");
377 td_free (ohci, ed->dummy);
378 break;
379 }
380 ep->hcpriv = NULL;
381 spin_unlock_irqrestore (&ohci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
384static int ohci_get_frame (struct usb_hcd *hcd)
385{
386 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
387
388 return ohci_frame_no(ohci);
389}
390
391static void ohci_usb_reset (struct ohci_hcd *ohci)
392{
393 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
394 ohci->hc_control &= OHCI_CTRL_RWC;
395 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
Alan Sternb7463c72011-11-17 16:41:56 -0500396 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700399/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700400 * other cases where the next software may expect clean state from the
401 * "firmware". this is bus-neutral, unlike shutdown() methods.
402 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700403static void
404ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700405{
406 struct ohci_hcd *ohci;
407
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700408 ohci = hcd_to_ohci (hcd);
Alan Sternc6187592011-11-17 16:41:45 -0500409 ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
Alan Stern3df71692010-09-10 16:37:05 -0400410
Alan Sternc6187592011-11-17 16:41:45 -0500411 /* Software reset, after which the controller goes into SUSPEND */
412 ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
413 ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */
414 udelay(10);
Alan Stern3df71692010-09-10 16:37:05 -0400415
Alan Sternc6187592011-11-17 16:41:45 -0500416 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
David Brownellf4df0e32005-04-23 12:49:16 -0700417}
418
Mike Nuss89a0fd12007-08-01 13:24:30 -0700419static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
420{
421 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
422 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
423 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
424 && !list_empty(&ed->td_list);
425}
426
427/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
428 * an interrupt TD but neglects to add it to the donelist. On systems with
429 * this chipset, we need to periodically check the state of the queues to look
430 * for such "lost" TDs.
431 */
432static void unlink_watchdog_func(unsigned long _ohci)
433{
David Brownellda6fb572007-10-24 17:23:42 -0700434 unsigned long flags;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700435 unsigned max;
436 unsigned seen_count = 0;
437 unsigned i;
438 struct ed **seen = NULL;
439 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
440
441 spin_lock_irqsave(&ohci->lock, flags);
442 max = ohci->eds_scheduled;
443 if (!max)
444 goto done;
445
446 if (ohci->ed_to_check)
447 goto out;
448
449 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
450 if (!seen)
451 goto out;
452
453 for (i = 0; i < NUM_INTS; i++) {
454 struct ed *ed = ohci->periodic[i];
455
456 while (ed) {
457 unsigned temp;
458
459 /* scan this branch of the periodic schedule tree */
460 for (temp = 0; temp < seen_count; temp++) {
461 if (seen[temp] == ed) {
462 /* we've checked it and what's after */
463 ed = NULL;
464 break;
465 }
466 }
467 if (!ed)
468 break;
469 seen[seen_count++] = ed;
470 if (!check_ed(ohci, ed)) {
471 ed = ed->ed_next;
472 continue;
473 }
474
475 /* HC's TD list is empty, but HCD sees at least one
476 * TD that's not been sent through the donelist.
477 */
478 ohci->ed_to_check = ed;
479 ohci->zf_delay = 2;
480
481 /* The HC may wait until the next frame to report the
482 * TD as done through the donelist and INTR_WDH. (We
483 * just *assume* it's not a multi-TD interrupt URB;
484 * those could defer the IRQ more than one frame, using
485 * DI...) Check again after the next INTR_SF.
486 */
487 ohci_writel(ohci, OHCI_INTR_SF,
488 &ohci->regs->intrstatus);
489 ohci_writel(ohci, OHCI_INTR_SF,
490 &ohci->regs->intrenable);
491
492 /* flush those writes */
493 (void) ohci_readl(ohci, &ohci->regs->control);
494
495 goto out;
496 }
497 }
498out:
499 kfree(seen);
500 if (ohci->eds_scheduled)
Richard Kennedy9cebcdc2008-03-28 14:50:30 -0700501 mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700502done:
503 spin_unlock_irqrestore(&ohci->lock, flags);
504}
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506/*-------------------------------------------------------------------------*
507 * HC functions
508 *-------------------------------------------------------------------------*/
509
510/* init memory, and kick BIOS/SMM off */
511
512static int ohci_init (struct ohci_hcd *ohci)
513{
514 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800515 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400517 if (distrust_firmware)
518 ohci->flags |= OHCI_QUIRK_HUB_POWER;
519
Alan Sternb7463c72011-11-17 16:41:56 -0500520 ohci->rh_state = OHCI_RH_HALTED;
David Brownell6a9062f2006-01-23 15:28:07 -0800521 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
David Brownell6a9062f2006-01-23 15:28:07 -0800523 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
524 * was never needed for most non-PCI systems ... remove the code?
525 */
526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#ifndef IR_DISABLE
528 /* SMM owns the HC? not for long! */
529 if (!no_handshake && ohci_readl (ohci,
530 &ohci->regs->control) & OHCI_CTRL_IR) {
531 u32 temp;
532
533 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
534
535 /* this timeout is arbitrary. we make it long, so systems
536 * depending on usb keyboards may be usable even if the
537 * BIOS/SMM code seems pretty broken.
538 */
539 temp = 500; /* arbitrary: five seconds */
540
541 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
542 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
543 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
544 msleep (10);
545 if (--temp == 0) {
546 ohci_err (ohci, "USB HC takeover failed!"
547 " (BIOS/SMM bug)\n");
548 return -EBUSY;
549 }
550 }
551 ohci_usb_reset (ohci);
552 }
553#endif
554
555 /* Disable HC interrupts */
556 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800557
558 /* flush the writes, and save key bits like RWC */
559 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
560 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
David Brownellfdd13b32005-08-31 11:52:57 -0700562 /* Read the number of ports unless overridden */
563 if (ohci->num_ports == 0)
564 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 if (ohci->hcca)
567 return 0;
568
David Brownell6a9062f2006-01-23 15:28:07 -0800569 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
571 if (!ohci->hcca)
572 return -ENOMEM;
573
574 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800575 ohci_stop (hcd);
576 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800577 create_debug_files (ohci);
578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
582
583/*-------------------------------------------------------------------------*/
584
585/* Start an OHCI controller, set the BUS operational
586 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800587 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 */
589static int ohci_run (struct ohci_hcd *ohci)
590{
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400591 u32 mask, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800593 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Alan Sternb7463c72011-11-17 16:41:56 -0500595 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 /* boot firmware should have set this up (5.1.1.3.1) */
598 if (first) {
599
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400600 val = ohci_readl (ohci, &ohci->regs->fminterval);
601 ohci->fminterval = val & 0x3fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 if (ohci->fminterval != FI)
603 ohci_dbg (ohci, "fminterval delta %d\n",
604 ohci->fminterval - FI);
605 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
606 /* also: power/overcurrent flags in roothub.a */
607 }
608
Alan Stern6fd90862008-12-17 17:20:38 -0500609 /* Reset USB nearly "by the book". RemoteWakeupConnected has
610 * to be checked in case boot firmware (BIOS/SMM/...) has set up
611 * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
612 * If the bus glue detected wakeup capability then it should
Alan Sternbcca06e2009-01-13 11:35:54 -0500613 * already be enabled; if so we'll just enable it again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 */
Alan Sternbcca06e2009-01-13 11:35:54 -0500615 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
616 device_set_wakeup_capable(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
619 case OHCI_USB_OPER:
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400620 val = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 break;
622 case OHCI_USB_SUSPEND:
623 case OHCI_USB_RESUME:
624 ohci->hc_control &= OHCI_CTRL_RWC;
625 ohci->hc_control |= OHCI_USB_RESUME;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400626 val = 10 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 break;
628 // case OHCI_USB_RESET:
629 default:
630 ohci->hc_control &= OHCI_CTRL_RWC;
631 ohci->hc_control |= OHCI_USB_RESET;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400632 val = 50 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 break;
634 }
635 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
636 // flush the writes
637 (void) ohci_readl (ohci, &ohci->regs->control);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400638 msleep(val);
Alan Stern383975d2007-05-04 11:52:40 -0400639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
641
642 /* 2msec timelimit here means no irqs/preempt */
643 spin_lock_irq (&ohci->lock);
644
645retry:
646 /* HC Reset requires max 10 us delay */
647 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400648 val = 30; /* ... allow extra time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400650 if (--val == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 spin_unlock_irq (&ohci->lock);
652 ohci_err (ohci, "USB HC reset timed out!\n");
653 return -1;
654 }
655 udelay (1);
656 }
657
658 /* now we're in the SUSPEND state ... must go OPERATIONAL
659 * within 2msec else HC enters RESUME
660 *
661 * ... but some hardware won't init fmInterval "by the book"
662 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
663 * this if we write fmInterval after we're OPERATIONAL.
664 * Unclear about ALi, ServerWorks, and others ... this could
665 * easily be a longstanding bug in chip init on Linux.
666 */
667 if (ohci->flags & OHCI_QUIRK_INITRESET) {
668 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
669 // flush those writes
670 (void) ohci_readl (ohci, &ohci->regs->control);
671 }
672
673 /* Tell the controller where the control and bulk lists are
674 * The lists are empty now. */
675 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
676 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
677
678 /* a reset clears this */
679 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
680
681 periodic_reinit (ohci);
682
683 /* some OHCI implementations are finicky about how they init.
684 * bogus values here mean not even enumeration could work.
685 */
686 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
687 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
688 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
689 ohci->flags |= OHCI_QUIRK_INITRESET;
690 ohci_dbg (ohci, "enabling initreset quirk\n");
691 goto retry;
692 }
693 spin_unlock_irq (&ohci->lock);
694 ohci_err (ohci, "init err (%08x %04x)\n",
695 ohci_readl (ohci, &ohci->regs->fminterval),
696 ohci_readl (ohci, &ohci->regs->periodicstart));
697 return -EOVERFLOW;
698 }
699
David Brownelld4139842006-08-04 11:31:55 -0700700 /* use rhsc irqs after khubd is fully initialized */
Alan Stern541c7d42010-06-22 16:39:10 -0400701 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
David Brownelld4139842006-08-04 11:31:55 -0700702 hcd->uses_new_polling = 1;
703
704 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700706 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
707 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
Alan Sternb7463c72011-11-17 16:41:56 -0500708 ohci->rh_state = OHCI_RH_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 /* wake on ConnectStatusChange, matching external hubs */
711 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
712
713 /* Choose the interrupts we care about now, others later on demand */
714 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700715 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 ohci_writel (ohci, mask, &ohci->regs->intrenable);
717
718 /* handle root hub init quirks ... */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400719 val = roothub_a (ohci);
720 val &= ~(RH_A_PSM | RH_A_OCPM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
722 /* NSC 87560 and maybe others */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400723 val |= RH_A_NOCP;
724 val &= ~(RH_A_POTPGT | RH_A_NPS);
725 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400726 } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
727 (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 /* hub power always on; required for AMD-756 and some
729 * Mac platforms. ganged overcurrent reporting, if any.
730 */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400731 val |= RH_A_NPS;
732 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 }
734 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400735 ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 &ohci->regs->roothub.b);
737 // flush those writes
738 (void) ohci_readl (ohci, &ohci->regs->control);
739
David Brownelld4139842006-08-04 11:31:55 -0700740 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 spin_unlock_irq (&ohci->lock);
742
743 // POTPGT delay is bits 24-31, in 2 ms units.
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400744 mdelay ((val >> 23) & 0x1fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Mike Nuss89a0fd12007-08-01 13:24:30 -0700746 if (quirk_zfmicro(ohci)) {
747 /* Create timer to watch for bad queue state on ZF Micro */
748 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
749 (unsigned long) ohci);
750
751 ohci->eds_scheduled = 0;
752 ohci->ed_to_check = NULL;
753 }
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 ohci_dump (ohci, 1);
756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 return 0;
758}
759
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530760/* ohci_setup routine for generic controller initialization */
761
762int ohci_setup(struct usb_hcd *hcd)
763{
764 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
765
766 ohci_hcd_init(ohci);
767
768 return ohci_init(ohci);
769}
770EXPORT_SYMBOL_GPL(ohci_setup);
771
772/* ohci_start routine for generic controller start of all OHCI bus glue */
773static int ohci_start(struct usb_hcd *hcd)
774{
775 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
776 int ret;
777
778 ret = ohci_run(ohci);
779 if (ret < 0) {
780 ohci_err(ohci, "can't start\n");
781 ohci_stop(hcd);
782 }
783 return ret;
784}
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786/*-------------------------------------------------------------------------*/
787
788/* an interrupt happens */
789
David Howells7d12e782006-10-05 14:55:46 +0100790static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
792 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
793 struct ohci_regs __iomem *regs = ohci->regs;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700794 int ints;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800796 /* Read interrupt status (and flush pending writes). We ignore the
797 * optimization of checking the LSB of hcca->done_head; it doesn't
798 * work on all systems (edge triggering for OHCI can be a factor).
Mike Nuss89a0fd12007-08-01 13:24:30 -0700799 */
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800800 ints = ohci_readl(ohci, &regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800802 /* Check for an all 1's result which is a typical consequence
803 * of dead, unclocked, or unplugged (CardBus...) devices
804 */
805 if (ints == ~(u32)0) {
Alan Sternb7463c72011-11-17 16:41:56 -0500806 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 ohci_dbg (ohci, "device removed!\n");
Alan Stern69fff592011-05-17 17:27:12 -0400808 usb_hc_died(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 return IRQ_HANDLED;
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800810 }
811
812 /* We only care about interrupts that are enabled */
813 ints &= ohci_readl(ohci, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 /* interrupt for some other device? */
Alan Sternb7463c72011-11-17 16:41:56 -0500816 if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 if (ints & OHCI_INTR_UE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 // e.g. due to PCI Master/Target Abort
Mike Nuss89a0fd12007-08-01 13:24:30 -0700821 if (quirk_nec(ohci)) {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200822 /* Workaround for a silicon bug in some NEC chips used
823 * in Apple's PowerBooks. Adapted from Darwin code.
824 */
825 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
826
827 ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
828
829 schedule_work (&ohci->nec_work);
830 } else {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200831 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
Alan Sternb7463c72011-11-17 16:41:56 -0500832 ohci->rh_state = OHCI_RH_HALTED;
Alan Stern69fff592011-05-17 17:27:12 -0400833 usb_hc_died(hcd);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 ohci_dump (ohci, 1);
837 ohci_usb_reset (ohci);
838 }
839
Alan Stern583cead2006-10-24 12:04:22 -0400840 if (ints & OHCI_INTR_RHSC) {
841 ohci_vdbg(ohci, "rhsc\n");
842 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
843 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
844 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400845
846 /* NOTE: Vendors didn't always make the same implementation
847 * choices for RHSC. Many followed the spec; RHSC triggers
848 * on an edge, like setting and maybe clearing a port status
849 * change bit. With others it's level-triggered, active
850 * until khubd clears all the port status change bits. We'll
851 * always disable it here and rely on polling until khubd
852 * re-enables it.
853 */
854 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400855 usb_hcd_poll_rh_status(hcd);
856 }
857
858 /* For connect and disconnect events, we expect the controller
859 * to turn on RHSC along with RD. But for remote wakeup events
860 * this might not happen.
861 */
862 else if (ints & OHCI_INTR_RD) {
863 ohci_vdbg(ohci, "resume detect\n");
864 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern541c7d42010-06-22 16:39:10 -0400865 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
Alan Stern8d1a2432006-09-26 14:46:16 -0400866 if (ohci->autostop) {
867 spin_lock (&ohci->lock);
868 ohci_rh_resume (ohci);
869 spin_unlock (&ohci->lock);
870 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700871 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
873
874 if (ints & OHCI_INTR_WDH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100876 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 spin_unlock (&ohci->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 }
David Brownelldd9048a2006-12-05 03:18:31 -0800879
Mike Nuss89a0fd12007-08-01 13:24:30 -0700880 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
881 spin_lock(&ohci->lock);
882 if (ohci->ed_to_check) {
883 struct ed *ed = ohci->ed_to_check;
884
885 if (check_ed(ohci, ed)) {
886 /* HC thinks the TD list is empty; HCD knows
887 * at least one TD is outstanding
888 */
889 if (--ohci->zf_delay == 0) {
890 struct td *td = list_entry(
891 ed->td_list.next,
892 struct td, td_list);
893 ohci_warn(ohci,
894 "Reclaiming orphan TD %p\n",
895 td);
896 takeback_td(ohci, td);
897 ohci->ed_to_check = NULL;
898 }
899 } else
900 ohci->ed_to_check = NULL;
901 }
902 spin_unlock(&ohci->lock);
903 }
904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 /* could track INTR_SO to reduce available PCI/... bandwidth */
906
907 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
908 * when there's still unlinking to be done (next frame).
909 */
910 spin_lock (&ohci->lock);
911 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100912 finish_unlinks (ohci, ohci_frame_no(ohci));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700913 if ((ints & OHCI_INTR_SF) != 0
914 && !ohci->ed_rm_list
915 && !ohci->ed_to_check
Alan Sternb7463c72011-11-17 16:41:56 -0500916 && ohci->rh_state == OHCI_RH_RUNNING)
David Brownelldd9048a2006-12-05 03:18:31 -0800917 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 spin_unlock (&ohci->lock);
919
Alan Sternb7463c72011-11-17 16:41:56 -0500920 if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800922 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 // flush those writes
924 (void) ohci_readl (ohci, &ohci->regs->control);
925 }
926
927 return IRQ_HANDLED;
928}
929
930/*-------------------------------------------------------------------------*/
931
932static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800933{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 ohci_dump (ohci, 1);
937
Tejun Heo569ff2d2010-12-24 16:14:20 +0100938 if (quirk_nec(ohci))
Tejun Heo43829732012-08-20 14:51:24 -0700939 flush_work(&ohci->nec_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
caizhiyong435932f2013-07-26 07:12:14 +0000942 ohci_usb_reset(ohci);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700943 free_irq(hcd->irq, hcd);
Felipe Balbicd704692012-02-29 16:46:23 +0200944 hcd->irq = 0;
Pete Zaitcev71795c12006-09-18 22:57:22 -0700945
Mike Nuss89a0fd12007-08-01 13:24:30 -0700946 if (quirk_zfmicro(ohci))
947 del_timer(&ohci->unlink_watchdog);
Libin Yangab1666c2008-08-08 15:03:31 +0800948 if (quirk_amdiso(ohci))
Andiry Xuad935622011-03-01 14:57:05 +0800949 usb_amd_dev_put();
Mike Nuss89a0fd12007-08-01 13:24:30 -0700950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 ohci_mem_cleanup (ohci);
953 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800954 dma_free_coherent (hcd->self.controller,
955 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 ohci->hcca, ohci->hcca_dma);
957 ohci->hcca = NULL;
958 ohci->hcca_dma = 0;
959 }
960}
961
962/*-------------------------------------------------------------------------*/
963
David Brownellda6fb572007-10-24 17:23:42 -0700964#if defined(CONFIG_PM) || defined(CONFIG_PCI)
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966/* must not be called from interrupt context */
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530967int ohci_restart(struct ohci_hcd *ohci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
969 int temp;
970 int i;
971 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530973 ohci_init(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 spin_lock_irq(&ohci->lock);
Alan Sternb7463c72011-11-17 16:41:56 -0500975 ohci->rh_state = OHCI_RH_HALTED;
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200976
977 /* Recycle any "live" eds/tds (and urbs). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 if (!list_empty (&ohci->pending))
979 ohci_dbg(ohci, "abort schedule...\n");
980 list_for_each_entry (priv, &ohci->pending, pending) {
981 struct urb *urb = priv->td[0]->urb;
982 struct ed *ed = priv->ed;
983
984 switch (ed->state) {
985 case ED_OPER:
986 ed->state = ED_UNLINK;
987 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
988 ed_deschedule (ohci, ed);
989
990 ed->ed_next = ohci->ed_rm_list;
991 ed->ed_prev = NULL;
992 ohci->ed_rm_list = ed;
993 /* FALLTHROUGH */
994 case ED_UNLINK:
995 break;
996 default:
997 ohci_dbg(ohci, "bogus ed %p state %d\n",
998 ed, ed->state);
999 }
1000
Alan Stern55d84962007-08-24 15:40:34 -04001001 if (!urb->unlinked)
1002 urb->unlinked = -ESHUTDOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
David Howells7d12e782006-10-05 14:55:46 +01001004 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 spin_unlock_irq(&ohci->lock);
1006
1007 /* paranoia, in case that didn't work: */
1008
1009 /* empty the interrupt branches */
1010 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
1011 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -08001012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 /* no EDs to remove */
1014 ohci->ed_rm_list = NULL;
1015
David Brownelldd9048a2006-12-05 03:18:31 -08001016 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 ohci->ed_controltail = NULL;
1018 ohci->ed_bulktail = NULL;
1019
1020 if ((temp = ohci_run (ohci)) < 0) {
1021 ohci_err (ohci, "can't restart, %d\n", temp);
1022 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
Alan Stern383975d2007-05-04 11:52:40 -04001024 ohci_dbg(ohci, "restart complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 return 0;
1026}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301027EXPORT_SYMBOL_GPL(ohci_restart);
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001028
David Brownellda6fb572007-10-24 17:23:42 -07001029#endif
1030
Florian Fainellicd1965d2012-10-08 15:11:27 +02001031#ifdef CONFIG_PM
1032
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301033int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001034{
1035 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
1036 unsigned long flags;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001037
Florian Fainellid4ae47d2012-10-08 15:11:28 +02001038 /* Disable irq emission and mark HW unaccessible. Use
Florian Fainellicd1965d2012-10-08 15:11:27 +02001039 * the spinlock to properly synchronize with possible pending
1040 * RH suspend or resume activity.
1041 */
1042 spin_lock_irqsave (&ohci->lock, flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001043 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
1044 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
1045
1046 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001047 spin_unlock_irqrestore (&ohci->lock, flags);
1048
Florian Fainellid4ae47d2012-10-08 15:11:28 +02001049 return 0;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001050}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301051EXPORT_SYMBOL_GPL(ohci_suspend);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001052
1053
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301054int ohci_resume(struct usb_hcd *hcd, bool hibernated)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001055{
Florian Fainellicfa49b42012-10-08 15:11:29 +02001056 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
1057 int port;
1058 bool need_reinit = false;
1059
Florian Fainellicd1965d2012-10-08 15:11:27 +02001060 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1061
1062 /* Make sure resume from hibernation re-enumerates everything */
1063 if (hibernated)
Florian Fainellicfa49b42012-10-08 15:11:29 +02001064 ohci_usb_reset(ohci);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001065
Florian Fainellicfa49b42012-10-08 15:11:29 +02001066 /* See if the controller is already running or has been reset */
1067 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
1068 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
1069 need_reinit = true;
1070 } else {
1071 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
1072 case OHCI_USB_OPER:
1073 case OHCI_USB_RESET:
1074 need_reinit = true;
1075 }
1076 }
1077
1078 /* If needed, reinitialize and suspend the root hub */
1079 if (need_reinit) {
1080 spin_lock_irq(&ohci->lock);
1081 ohci_rh_resume(ohci);
1082 ohci_rh_suspend(ohci, 0);
1083 spin_unlock_irq(&ohci->lock);
1084 }
1085
1086 /* Normally just turn on port power and enable interrupts */
1087 else {
1088 ohci_dbg(ohci, "powerup ports\n");
1089 for (port = 0; port < ohci->num_ports; port++)
1090 ohci_writel(ohci, RH_PS_PPS,
1091 &ohci->regs->roothub.portstatus[port]);
1092
1093 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
1094 ohci_readl(ohci, &ohci->regs->intrenable);
1095 msleep(20);
1096 }
1097
1098 usb_hcd_resume_root_hub(hcd);
1099
Florian Fainellicd1965d2012-10-08 15:11:27 +02001100 return 0;
1101}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301102EXPORT_SYMBOL_GPL(ohci_resume);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001103
1104#endif
1105
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001106/*-------------------------------------------------------------------------*/
1107
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301108/*
1109 * Generic structure: This gets copied for platform drivers so that
1110 * individual entries can be overridden as needed.
1111 */
1112
1113static const struct hc_driver ohci_hc_driver = {
1114 .description = hcd_name,
1115 .product_desc = "OHCI Host Controller",
1116 .hcd_priv_size = sizeof(struct ohci_hcd),
1117
1118 /*
1119 * generic hardware linkage
1120 */
1121 .irq = ohci_irq,
1122 .flags = HCD_MEMORY | HCD_USB11,
1123
1124 /*
1125 * basic lifecycle operations
1126 */
1127 .reset = ohci_setup,
1128 .start = ohci_start,
1129 .stop = ohci_stop,
1130 .shutdown = ohci_shutdown,
1131
1132 /*
1133 * managing i/o requests and associated device resources
1134 */
1135 .urb_enqueue = ohci_urb_enqueue,
1136 .urb_dequeue = ohci_urb_dequeue,
1137 .endpoint_disable = ohci_endpoint_disable,
1138
1139 /*
1140 * scheduling support
1141 */
1142 .get_frame_number = ohci_get_frame,
1143
1144 /*
1145 * root hub support
1146 */
1147 .hub_status_data = ohci_hub_status_data,
1148 .hub_control = ohci_hub_control,
1149#ifdef CONFIG_PM
1150 .bus_suspend = ohci_bus_suspend,
1151 .bus_resume = ohci_bus_resume,
1152#endif
1153 .start_port_reset = ohci_start_port_reset,
1154};
1155
1156void ohci_init_driver(struct hc_driver *drv,
1157 const struct ohci_driver_overrides *over)
1158{
1159 /* Copy the generic table to drv and then apply the overrides */
1160 *drv = ohci_hc_driver;
1161
1162 drv->product_desc = over->product_desc;
1163 drv->hcd_priv_size += over->extra_priv_size;
1164 if (over->reset)
1165 drv->reset = over->reset;
1166}
1167EXPORT_SYMBOL_GPL(ohci_init_driver);
1168
1169/*-------------------------------------------------------------------------*/
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171MODULE_AUTHOR (DRIVER_AUTHOR);
Alan Stern2b70f072008-10-02 11:47:15 -04001172MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173MODULE_LICENSE ("GPL");
1174
Eric Miao6381fad2008-06-02 10:05:30 +08001175#if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001177#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178#endif
1179
Kukjin Kimb130d5c2012-02-03 14:29:23 +09001180#if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX)
Ben Dooks3eb0c5f2005-07-29 12:18:03 -07001181#include "ohci-s3c2410.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001182#define S3C2410_PLATFORM_DRIVER ohci_hcd_s3c2410_driver
Ben Dooks3eb0c5f2005-07-29 12:18:03 -07001183#endif
1184
Jingoo Han62194242011-12-23 11:20:54 +09001185#ifdef CONFIG_USB_OHCI_EXYNOS
1186#include "ohci-exynos.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001187#define EXYNOS_PLATFORM_DRIVER exynos_ohci_driver
Jingoo Han62194242011-12-23 11:20:54 +09001188#endif
1189
Anand Gadiyar968b4482010-05-10 21:56:12 +05301190#ifdef CONFIG_USB_OHCI_HCD_OMAP1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191#include "ohci-omap.c"
Anand Gadiyar968b4482010-05-10 21:56:12 +05301192#define OMAP1_PLATFORM_DRIVER ohci_hcd_omap_driver
1193#endif
1194
1195#ifdef CONFIG_USB_OHCI_HCD_OMAP3
1196#include "ohci-omap3.c"
1197#define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198#endif
1199
eric miaoe77ec182007-12-12 09:07:47 +08001200#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201#include "ohci-pxa27x.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001202#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203#endif
1204
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001205#ifdef CONFIG_ARCH_EP93XX
1206#include "ohci-ep93xx.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001207#define EP93XX_PLATFORM_DRIVER ohci_hcd_ep93xx_driver
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001208#endif
1209
Andrew Victor58a0cd72006-12-01 14:51:13 +01001210#ifdef CONFIG_ARCH_AT91
Andrew Victor39a269c2006-01-22 10:32:13 -08001211#include "ohci-at91.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001212#define AT91_PLATFORM_DRIVER ohci_hcd_at91_driver
Andrew Victor39a269c2006-01-22 10:32:13 -08001213#endif
1214
Roland Stigged684f052012-08-26 16:30:37 +02001215#ifdef CONFIG_ARCH_LPC32XX
Roland Stigge32abd562012-03-12 22:54:49 +01001216#include "ohci-nxp.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001217#define NXP_PLATFORM_DRIVER usb_hcd_nxp_driver
Vitaly Wool60bbfc82006-06-29 18:28:18 +04001218#endif
1219
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001220#ifdef CONFIG_ARCH_DAVINCI_DA8XX
1221#include "ohci-da8xx.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001222#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001223#endif
1224
Sylvain Munaut495a6782006-12-13 21:09:55 +01001225#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1226#include "ohci-ppc-of.c"
1227#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1228#endif
1229
Deepak Sikric8c38de2010-11-10 14:33:18 +05301230#ifdef CONFIG_PLAT_SPEAR
1231#include "ohci-spear.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001232#define SPEAR_PLATFORM_DRIVER spear_ohci_hcd_driver
Deepak Sikric8c38de2010-11-10 14:33:18 +05301233#endif
1234
Geoff Levand6a6c9572007-01-15 20:12:10 -08001235#ifdef CONFIG_PPC_PS3
1236#include "ohci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001237#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
Geoff Levand6a6c9572007-01-15 20:12:10 -08001238#endif
1239
Magnus Dammf54aab62008-01-23 15:58:46 +09001240#ifdef CONFIG_MFD_SM501
1241#include "ohci-sm501.c"
Ben Dooks3ee38d82008-06-08 17:20:11 +01001242#define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
Magnus Dammf54aab62008-01-23 15:58:46 +09001243#endif
1244
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001245#ifdef CONFIG_MFD_TC6393XB
1246#include "ohci-tmio.c"
1247#define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
1248#endif
1249
Lars-Peter Clausen22490712010-06-19 04:08:24 +00001250#ifdef CONFIG_MACH_JZ4740
1251#include "ohci-jz4740.c"
1252#define PLATFORM_DRIVER ohci_hcd_jz4740_driver
1253#endif
1254
David Daney1643acc2010-10-08 14:47:52 -07001255#ifdef CONFIG_USB_OCTEON_OHCI
1256#include "ohci-octeon.c"
1257#define PLATFORM_DRIVER ohci_octeon_driver
1258#endif
1259
Chris Metcalf47fc28b2012-05-09 13:58:14 -04001260#ifdef CONFIG_TILE_USB
1261#include "ohci-tilegx.c"
1262#define PLATFORM_DRIVER ohci_hcd_tilegx_driver
1263#endif
1264
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001265static int __init ohci_hcd_mod_init(void)
1266{
1267 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001268
1269 if (usb_disabled())
1270 return -ENODEV;
1271
Alan Stern2b70f072008-10-02 11:47:15 -04001272 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001273 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1274 sizeof (struct ed), sizeof (struct td));
Alan Stern9beeee62008-10-02 11:48:13 -04001275 set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001276
Tony Jones684c19e2007-09-11 14:07:31 -07001277#ifdef DEBUG
Greg Kroah-Hartman485f4f32009-04-24 15:14:38 -07001278 ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
Tony Jones684c19e2007-09-11 14:07:31 -07001279 if (!ohci_debug_root) {
1280 retval = -ENOENT;
1281 goto error_debug;
1282 }
1283#endif
1284
Geoff Levand6a6c9572007-01-15 20:12:10 -08001285#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001286 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1287 if (retval < 0)
1288 goto error_ps3;
Geoff Levand6a6c9572007-01-15 20:12:10 -08001289#endif
1290
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001291#ifdef PLATFORM_DRIVER
1292 retval = platform_driver_register(&PLATFORM_DRIVER);
1293 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001294 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001295#endif
1296
Anand Gadiyar968b4482010-05-10 21:56:12 +05301297#ifdef OMAP1_PLATFORM_DRIVER
1298 retval = platform_driver_register(&OMAP1_PLATFORM_DRIVER);
1299 if (retval < 0)
1300 goto error_omap1_platform;
1301#endif
1302
1303#ifdef OMAP3_PLATFORM_DRIVER
1304 retval = platform_driver_register(&OMAP3_PLATFORM_DRIVER);
1305 if (retval < 0)
1306 goto error_omap3_platform;
1307#endif
1308
Sylvain Munaut495a6782006-12-13 21:09:55 +01001309#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001310 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001311 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001312 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +01001313#endif
1314
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001315#ifdef SA1111_DRIVER
1316 retval = sa1111_driver_register(&SA1111_DRIVER);
1317 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001318 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001319#endif
1320
Ben Dooks3ee38d82008-06-08 17:20:11 +01001321#ifdef SM501_OHCI_DRIVER
1322 retval = platform_driver_register(&SM501_OHCI_DRIVER);
1323 if (retval < 0)
1324 goto error_sm501;
1325#endif
1326
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001327#ifdef TMIO_OHCI_DRIVER
1328 retval = platform_driver_register(&TMIO_OHCI_DRIVER);
1329 if (retval < 0)
1330 goto error_tmio;
1331#endif
1332
Arnd Bergmann80978042013-04-25 19:29:04 +02001333#ifdef S3C2410_PLATFORM_DRIVER
1334 retval = platform_driver_register(&S3C2410_PLATFORM_DRIVER);
1335 if (retval < 0)
1336 goto error_s3c2410;
1337#endif
1338
1339#ifdef EXYNOS_PLATFORM_DRIVER
1340 retval = platform_driver_register(&EXYNOS_PLATFORM_DRIVER);
1341 if (retval < 0)
1342 goto error_exynos;
1343#endif
1344
1345#ifdef EP93XX_PLATFORM_DRIVER
1346 retval = platform_driver_register(&EP93XX_PLATFORM_DRIVER);
1347 if (retval < 0)
1348 goto error_ep93xx;
1349#endif
1350
1351#ifdef AT91_PLATFORM_DRIVER
1352 retval = platform_driver_register(&AT91_PLATFORM_DRIVER);
1353 if (retval < 0)
1354 goto error_at91;
1355#endif
1356
1357#ifdef NXP_PLATFORM_DRIVER
1358 retval = platform_driver_register(&NXP_PLATFORM_DRIVER);
1359 if (retval < 0)
1360 goto error_nxp;
1361#endif
1362
1363#ifdef DAVINCI_PLATFORM_DRIVER
1364 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
1365 if (retval < 0)
1366 goto error_davinci;
1367#endif
1368
1369#ifdef SPEAR_PLATFORM_DRIVER
1370 retval = platform_driver_register(&SPEAR_PLATFORM_DRIVER);
1371 if (retval < 0)
1372 goto error_spear;
1373#endif
1374
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001375 return retval;
1376
1377 /* Error path */
Arnd Bergmann80978042013-04-25 19:29:04 +02001378#ifdef SPEAR_PLATFORM_DRIVER
1379 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1380 error_spear:
1381#endif
1382#ifdef DAVINCI_PLATFORM_DRIVER
1383 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1384 error_davinci:
1385#endif
1386#ifdef NXP_PLATFORM_DRIVER
1387 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1388 error_nxp:
1389#endif
1390#ifdef AT91_PLATFORM_DRIVER
1391 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1392 error_at91:
1393#endif
1394#ifdef EP93XX_PLATFORM_DRIVER
1395 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1396 error_ep93xx:
1397#endif
1398#ifdef EXYNOS_PLATFORM_DRIVER
1399 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1400 error_exynos:
1401#endif
1402#ifdef S3C2410_PLATFORM_DRIVER
1403 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1404 error_s3c2410:
1405#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001406#ifdef TMIO_OHCI_DRIVER
1407 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1408 error_tmio:
1409#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001410#ifdef SM501_OHCI_DRIVER
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001411 platform_driver_unregister(&SM501_OHCI_DRIVER);
Ben Dooks3ee38d82008-06-08 17:20:11 +01001412 error_sm501:
1413#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001414#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001415 sa1111_driver_unregister(&SA1111_DRIVER);
1416 error_sa1111:
1417#endif
1418#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001419 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001420 error_of_platform:
1421#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001422#ifdef OMAP3_PLATFORM_DRIVER
1423 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1424 error_omap3_platform:
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001425#endif
Anand Gadiyar968b4482010-05-10 21:56:12 +05301426#ifdef OMAP1_PLATFORM_DRIVER
1427 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1428 error_omap1_platform:
1429#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001430#ifdef PLATFORM_DRIVER
1431 platform_driver_unregister(&PLATFORM_DRIVER);
1432 error_platform:
Anand Gadiyar968b4482010-05-10 21:56:12 +05301433#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001434#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001435 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001436 error_ps3:
1437#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001438#ifdef DEBUG
1439 debugfs_remove(ohci_debug_root);
1440 ohci_debug_root = NULL;
1441 error_debug:
1442#endif
1443
Alan Stern9beeee62008-10-02 11:48:13 -04001444 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001445 return retval;
1446}
1447module_init(ohci_hcd_mod_init);
1448
1449static void __exit ohci_hcd_mod_exit(void)
1450{
Arnd Bergmann80978042013-04-25 19:29:04 +02001451#ifdef SPEAR_PLATFORM_DRIVER
1452 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1453#endif
1454#ifdef DAVINCI_PLATFORM_DRIVER
1455 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1456#endif
1457#ifdef NXP_PLATFORM_DRIVER
1458 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1459#endif
1460#ifdef AT91_PLATFORM_DRIVER
1461 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1462#endif
1463#ifdef EP93XX_PLATFORM_DRIVER
1464 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1465#endif
1466#ifdef EXYNOS_PLATFORM_DRIVER
1467 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1468#endif
1469#ifdef S3C2410_PLATFORM_DRIVER
1470 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1471#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001472#ifdef TMIO_OHCI_DRIVER
1473 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1474#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001475#ifdef SM501_OHCI_DRIVER
1476 platform_driver_unregister(&SM501_OHCI_DRIVER);
1477#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001478#ifdef SA1111_DRIVER
1479 sa1111_driver_unregister(&SA1111_DRIVER);
1480#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001481#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001482 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001483#endif
Keshava Munegowdaffb67482010-09-14 04:40:01 +05301484#ifdef OMAP3_PLATFORM_DRIVER
1485 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1486#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001487#ifdef OMAP1_PLATFORM_DRIVER
1488 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1489#endif
1490#ifdef PLATFORM_DRIVER
1491 platform_driver_unregister(&PLATFORM_DRIVER);
1492#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001493#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001494 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001495#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001496#ifdef DEBUG
1497 debugfs_remove(ohci_debug_root);
1498#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001499 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001500}
1501module_exit(ohci_hcd_mod_exit);
1502