blob: 20a632d09f93cd2af4753b1cc1ef4aec9f419cfe [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#ifdef CONFIG_PCI
Libin Yanga1f17a872009-11-04 14:55:18 +080084static void sb800_prefetch(struct ohci_hcd *ohci, int on);
Libin Yangab1666c2008-08-08 15:03:31 +080085#else
Libin Yanga1f17a872009-11-04 14:55:18 +080086static inline void sb800_prefetch(struct ohci_hcd *ohci, int on)
87{
88 return;
89}
Libin Yangab1666c2008-08-08 15:03:31 +080090#endif
91
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#include "ohci-hub.c"
94#include "ohci-dbg.c"
95#include "ohci-mem.c"
96#include "ohci-q.c"
97
98
99/*
100 * On architectures with edge-triggered interrupts we must never return
101 * IRQ_NONE.
102 */
103#if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
104#define IRQ_NOTMINE IRQ_HANDLED
105#else
106#define IRQ_NOTMINE IRQ_NONE
107#endif
108
109
110/* Some boards misreport power switching/overcurrent */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030111static bool distrust_firmware = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112module_param (distrust_firmware, bool, 0);
113MODULE_PARM_DESC (distrust_firmware,
114 "true to distrust firmware power/overcurrent setup");
115
116/* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030117static bool no_handshake = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118module_param (no_handshake, bool, 0);
119MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
120
121/*-------------------------------------------------------------------------*/
122
123/*
124 * queue up an urb for anything except the root hub
125 */
126static int ohci_urb_enqueue (
127 struct usb_hcd *hcd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400129 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130) {
131 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
132 struct ed *ed;
133 urb_priv_t *urb_priv;
134 unsigned int pipe = urb->pipe;
135 int i, size = 0;
136 unsigned long flags;
137 int retval = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#ifdef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -0400140 urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif
David Brownelldd9048a2006-12-05 03:18:31 -0800142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 /* every endpoint has a ed, locate and maybe (re)initialize it */
Alan Sterne9df41c2007-08-08 11:48:02 -0400144 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return -ENOMEM;
146
147 /* for the private part of the URB we need the number of TDs (size) */
148 switch (ed->type) {
149 case PIPE_CONTROL:
150 /* td_submit_urb() doesn't yet handle these */
151 if (urb->transfer_buffer_length > 4096)
152 return -EMSGSIZE;
153
154 /* 1 TD for setup, 1 for ACK, plus ... */
155 size = 2;
156 /* FALLTHROUGH */
157 // case PIPE_INTERRUPT:
158 // case PIPE_BULK:
159 default:
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300160 /* one TD for every 4096 Bytes (can be up to 8K) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 size += urb->transfer_buffer_length / 4096;
162 /* ... and for any remaining bytes ... */
163 if ((urb->transfer_buffer_length % 4096) != 0)
164 size++;
165 /* ... and maybe a zero length packet to wrap it up */
166 if (size == 0)
167 size++;
168 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
169 && (urb->transfer_buffer_length
170 % usb_maxpacket (urb->dev, pipe,
171 usb_pipeout (pipe))) == 0)
172 size++;
173 break;
174 case PIPE_ISOCHRONOUS: /* number of packets from URB */
175 size = urb->number_of_packets;
176 break;
177 }
178
179 /* allocate the private part of the URB */
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700180 urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 mem_flags);
182 if (!urb_priv)
183 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 INIT_LIST_HEAD (&urb_priv->pending);
185 urb_priv->length = size;
David Brownelldd9048a2006-12-05 03:18:31 -0800186 urb_priv->ed = ed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 /* allocate the TDs (deferring hash chain updates) */
189 for (i = 0; i < size; i++) {
190 urb_priv->td [i] = td_alloc (ohci, mem_flags);
191 if (!urb_priv->td [i]) {
192 urb_priv->length = i;
193 urb_free_priv (ohci, urb_priv);
194 return -ENOMEM;
195 }
David Brownelldd9048a2006-12-05 03:18:31 -0800196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 spin_lock_irqsave (&ohci->lock, flags);
199
200 /* don't submit to a dead HC */
Alan Stern541c7d42010-06-22 16:39:10 -0400201 if (!HCD_HW_ACCESSIBLE(hcd)) {
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100202 retval = -ENODEV;
203 goto fail;
204 }
Alan Sternb7463c72011-11-17 16:41:56 -0500205 if (ohci->rh_state != OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 retval = -ENODEV;
207 goto fail;
208 }
Alan Sterne9df41c2007-08-08 11:48:02 -0400209 retval = usb_hcd_link_urb_to_ep(hcd, urb);
210 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 /* schedule the ed if needed */
214 if (ed->state == ED_IDLE) {
215 retval = ed_schedule (ohci, ed);
Alan Sterne9df41c2007-08-08 11:48:02 -0400216 if (retval < 0) {
217 usb_hcd_unlink_urb_from_ep(hcd, urb);
218 goto fail;
219 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 if (ed->type == PIPE_ISOCHRONOUS) {
221 u16 frame = ohci_frame_no(ohci);
222
223 /* delay a few frames before the first TD */
224 frame += max_t (u16, 8, ed->interval);
225 frame &= ~(ed->interval - 1);
226 frame |= ed->branch;
227 urb->start_frame = frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400229 } else if (ed->type == PIPE_ISOCHRONOUS) {
Alan Sterne19440172013-05-14 13:57:19 -0400230 u16 next = ohci_frame_no(ohci) + 1;
Alan Stern6a41b4d2012-10-01 10:32:15 -0400231 u16 frame = ed->last_iso + ed->interval;
232
233 /* Behind the scheduling threshold? */
234 if (unlikely(tick_before(frame, next))) {
235
236 /* USB_ISO_ASAP: Round up to the first available slot */
Alan Stern815fa7b2013-05-14 13:57:51 -0400237 if (urb->transfer_flags & URB_ISO_ASAP) {
Alan Stern6a41b4d2012-10-01 10:32:15 -0400238 frame += (next - frame + ed->interval - 1) &
239 -ed->interval;
240
241 /*
242 * Not ASAP: Use the next slot in the stream. If
243 * the entire URB falls before the threshold, fail.
244 */
Alan Stern815fa7b2013-05-14 13:57:51 -0400245 } else {
246 if (tick_before(frame + ed->interval *
Alan Stern6a41b4d2012-10-01 10:32:15 -0400247 (urb->number_of_packets - 1), next)) {
Alan Stern815fa7b2013-05-14 13:57:51 -0400248 retval = -EXDEV;
249 usb_hcd_unlink_urb_from_ep(hcd, urb);
250 goto fail;
251 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400252
Alan Stern815fa7b2013-05-14 13:57:51 -0400253 /*
254 * Some OHCI hardware doesn't handle late TDs
255 * correctly. After retiring them it proceeds
256 * to the next ED instead of the next TD.
257 * Therefore we have to omit the late TDs
258 * entirely.
259 */
260 urb_priv->td_cnt = DIV_ROUND_UP(
261 (u16) (next - frame),
262 ed->interval);
263 }
Alan Stern6a41b4d2012-10-01 10:32:15 -0400264 }
265 urb->start_frame = frame;
266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 /* fill the TDs and link them to the ed; and
269 * enable that part of the schedule, if needed
270 * and update count of queued periodic urbs
271 */
272 urb->hcpriv = urb_priv;
273 td_submit_urb (ohci, urb);
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275fail:
276 if (retval)
277 urb_free_priv (ohci, urb_priv);
278 spin_unlock_irqrestore (&ohci->lock, flags);
279 return retval;
280}
281
282/*
Alan Stern55d84962007-08-24 15:40:34 -0400283 * decouple the URB from the HC queues (TDs, urb_priv).
284 * reporting is always done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 * asynchronously, and we might be dealing with an urb that's
286 * partially transferred, or an ED with other urbs being unlinked.
287 */
Alan Sterne9df41c2007-08-08 11:48:02 -0400288static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
291 unsigned long flags;
Alan Sterne9df41c2007-08-08 11:48:02 -0400292 int rc;
David Brownelldd9048a2006-12-05 03:18:31 -0800293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294#ifdef OHCI_VERBOSE_DEBUG
Alan Stern55d84962007-08-24 15:40:34 -0400295 urb_print(urb, "UNLINK", 1, status);
David Brownelldd9048a2006-12-05 03:18:31 -0800296#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 spin_lock_irqsave (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400299 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
300 if (rc) {
301 ; /* Do nothing */
Alan Sternb7463c72011-11-17 16:41:56 -0500302 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 urb_priv_t *urb_priv;
304
305 /* Unless an IRQ completed the unlink while it was being
306 * handed to us, flag it for unlink and giveback, and force
307 * some upcoming INTR_SF to call finish_unlinks()
308 */
309 urb_priv = urb->hcpriv;
310 if (urb_priv) {
311 if (urb_priv->ed->state == ED_OPER)
312 start_ed_unlink (ohci, urb_priv->ed);
313 }
314 } else {
315 /*
316 * with HC dead, we won't respect hc queue pointers
317 * any more ... just clean up every urb's memory.
318 */
319 if (urb->hcpriv)
Alan Stern55d84962007-08-24 15:40:34 -0400320 finish_urb(ohci, urb, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 }
322 spin_unlock_irqrestore (&ohci->lock, flags);
Alan Sterne9df41c2007-08-08 11:48:02 -0400323 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
326/*-------------------------------------------------------------------------*/
327
328/* frees config/altsetting state for endpoints,
329 * including ED memory, dummy TD, and bulk/intr data toggle
330 */
331
332static void
333ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
334{
335 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
336 unsigned long flags;
337 struct ed *ed = ep->hcpriv;
338 unsigned limit = 1000;
339
340 /* ASSERT: any requests/urbs are being unlinked */
341 /* ASSERT: nobody can be submitting urbs for this any more */
342
343 if (!ed)
344 return;
345
346rescan:
347 spin_lock_irqsave (&ohci->lock, flags);
348
Alan Sternb7463c72011-11-17 16:41:56 -0500349 if (ohci->rh_state != OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350sanitize:
351 ed->state = ED_IDLE;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700352 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
353 ohci->eds_scheduled--;
David Howells7d12e782006-10-05 14:55:46 +0100354 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356
357 switch (ed->state) {
358 case ED_UNLINK: /* wait for hw to finish? */
359 /* major IRQ delivery trouble loses INTR_SF too... */
360 if (limit-- == 0) {
Mike Nuss89a0fd12007-08-01 13:24:30 -0700361 ohci_warn(ohci, "ED unlink timeout\n");
362 if (quirk_zfmicro(ohci)) {
363 ohci_warn(ohci, "Attempting ZF TD recovery\n");
364 ohci->ed_to_check = ed;
365 ohci->zf_delay = 2;
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 goto sanitize;
368 }
369 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700370 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 goto rescan;
372 case ED_IDLE: /* fully unlinked */
373 if (list_empty (&ed->td_list)) {
374 td_free (ohci, ed->dummy);
375 ed_free (ohci, ed);
376 break;
377 }
378 /* else FALL THROUGH */
379 default:
380 /* caller was supposed to have unlinked any requests;
381 * that's not our job. can't recover; must leak ed.
382 */
383 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
384 ed, ep->desc.bEndpointAddress, ed->state,
385 list_empty (&ed->td_list) ? "" : " (has tds)");
386 td_free (ohci, ed->dummy);
387 break;
388 }
389 ep->hcpriv = NULL;
390 spin_unlock_irqrestore (&ohci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
393static int ohci_get_frame (struct usb_hcd *hcd)
394{
395 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
396
397 return ohci_frame_no(ohci);
398}
399
400static void ohci_usb_reset (struct ohci_hcd *ohci)
401{
402 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
403 ohci->hc_control &= OHCI_CTRL_RWC;
404 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
Alan Sternb7463c72011-11-17 16:41:56 -0500405 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406}
407
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700408/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700409 * other cases where the next software may expect clean state from the
410 * "firmware". this is bus-neutral, unlike shutdown() methods.
411 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700412static void
413ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700414{
415 struct ohci_hcd *ohci;
416
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700417 ohci = hcd_to_ohci (hcd);
Alan Sternc6187592011-11-17 16:41:45 -0500418 ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
Alan Stern3df71692010-09-10 16:37:05 -0400419
Alan Sternc6187592011-11-17 16:41:45 -0500420 /* Software reset, after which the controller goes into SUSPEND */
421 ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
422 ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */
423 udelay(10);
Alan Stern3df71692010-09-10 16:37:05 -0400424
Alan Sternc6187592011-11-17 16:41:45 -0500425 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
David Brownellf4df0e32005-04-23 12:49:16 -0700426}
427
Mike Nuss89a0fd12007-08-01 13:24:30 -0700428static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
429{
430 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
431 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
432 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
433 && !list_empty(&ed->td_list);
434}
435
436/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
437 * an interrupt TD but neglects to add it to the donelist. On systems with
438 * this chipset, we need to periodically check the state of the queues to look
439 * for such "lost" TDs.
440 */
441static void unlink_watchdog_func(unsigned long _ohci)
442{
David Brownellda6fb572007-10-24 17:23:42 -0700443 unsigned long flags;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700444 unsigned max;
445 unsigned seen_count = 0;
446 unsigned i;
447 struct ed **seen = NULL;
448 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
449
450 spin_lock_irqsave(&ohci->lock, flags);
451 max = ohci->eds_scheduled;
452 if (!max)
453 goto done;
454
455 if (ohci->ed_to_check)
456 goto out;
457
458 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
459 if (!seen)
460 goto out;
461
462 for (i = 0; i < NUM_INTS; i++) {
463 struct ed *ed = ohci->periodic[i];
464
465 while (ed) {
466 unsigned temp;
467
468 /* scan this branch of the periodic schedule tree */
469 for (temp = 0; temp < seen_count; temp++) {
470 if (seen[temp] == ed) {
471 /* we've checked it and what's after */
472 ed = NULL;
473 break;
474 }
475 }
476 if (!ed)
477 break;
478 seen[seen_count++] = ed;
479 if (!check_ed(ohci, ed)) {
480 ed = ed->ed_next;
481 continue;
482 }
483
484 /* HC's TD list is empty, but HCD sees at least one
485 * TD that's not been sent through the donelist.
486 */
487 ohci->ed_to_check = ed;
488 ohci->zf_delay = 2;
489
490 /* The HC may wait until the next frame to report the
491 * TD as done through the donelist and INTR_WDH. (We
492 * just *assume* it's not a multi-TD interrupt URB;
493 * those could defer the IRQ more than one frame, using
494 * DI...) Check again after the next INTR_SF.
495 */
496 ohci_writel(ohci, OHCI_INTR_SF,
497 &ohci->regs->intrstatus);
498 ohci_writel(ohci, OHCI_INTR_SF,
499 &ohci->regs->intrenable);
500
501 /* flush those writes */
502 (void) ohci_readl(ohci, &ohci->regs->control);
503
504 goto out;
505 }
506 }
507out:
508 kfree(seen);
509 if (ohci->eds_scheduled)
Richard Kennedy9cebcdc2008-03-28 14:50:30 -0700510 mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700511done:
512 spin_unlock_irqrestore(&ohci->lock, flags);
513}
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515/*-------------------------------------------------------------------------*
516 * HC functions
517 *-------------------------------------------------------------------------*/
518
519/* init memory, and kick BIOS/SMM off */
520
521static int ohci_init (struct ohci_hcd *ohci)
522{
523 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800524 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400526 if (distrust_firmware)
527 ohci->flags |= OHCI_QUIRK_HUB_POWER;
528
Alan Sternb7463c72011-11-17 16:41:56 -0500529 ohci->rh_state = OHCI_RH_HALTED;
David Brownell6a9062f2006-01-23 15:28:07 -0800530 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
David Brownell6a9062f2006-01-23 15:28:07 -0800532 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
533 * was never needed for most non-PCI systems ... remove the code?
534 */
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536#ifndef IR_DISABLE
537 /* SMM owns the HC? not for long! */
538 if (!no_handshake && ohci_readl (ohci,
539 &ohci->regs->control) & OHCI_CTRL_IR) {
540 u32 temp;
541
542 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
543
544 /* this timeout is arbitrary. we make it long, so systems
545 * depending on usb keyboards may be usable even if the
546 * BIOS/SMM code seems pretty broken.
547 */
548 temp = 500; /* arbitrary: five seconds */
549
550 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
551 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
552 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
553 msleep (10);
554 if (--temp == 0) {
555 ohci_err (ohci, "USB HC takeover failed!"
556 " (BIOS/SMM bug)\n");
557 return -EBUSY;
558 }
559 }
560 ohci_usb_reset (ohci);
561 }
562#endif
563
564 /* Disable HC interrupts */
565 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800566
567 /* flush the writes, and save key bits like RWC */
568 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
569 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
David Brownellfdd13b32005-08-31 11:52:57 -0700571 /* Read the number of ports unless overridden */
572 if (ohci->num_ports == 0)
573 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (ohci->hcca)
576 return 0;
577
David Brownell6a9062f2006-01-23 15:28:07 -0800578 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
580 if (!ohci->hcca)
581 return -ENOMEM;
582
583 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800584 ohci_stop (hcd);
585 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800586 create_debug_files (ohci);
587 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
592/*-------------------------------------------------------------------------*/
593
594/* Start an OHCI controller, set the BUS operational
595 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800596 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 */
598static int ohci_run (struct ohci_hcd *ohci)
599{
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400600 u32 mask, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800602 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Alan Sternb7463c72011-11-17 16:41:56 -0500604 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 /* boot firmware should have set this up (5.1.1.3.1) */
607 if (first) {
608
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400609 val = ohci_readl (ohci, &ohci->regs->fminterval);
610 ohci->fminterval = val & 0x3fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 if (ohci->fminterval != FI)
612 ohci_dbg (ohci, "fminterval delta %d\n",
613 ohci->fminterval - FI);
614 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
615 /* also: power/overcurrent flags in roothub.a */
616 }
617
Alan Stern6fd90862008-12-17 17:20:38 -0500618 /* Reset USB nearly "by the book". RemoteWakeupConnected has
619 * to be checked in case boot firmware (BIOS/SMM/...) has set up
620 * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
621 * If the bus glue detected wakeup capability then it should
Alan Sternbcca06e2009-01-13 11:35:54 -0500622 * already be enabled; if so we'll just enable it again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 */
Alan Sternbcca06e2009-01-13 11:35:54 -0500624 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
625 device_set_wakeup_capable(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
628 case OHCI_USB_OPER:
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400629 val = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 break;
631 case OHCI_USB_SUSPEND:
632 case OHCI_USB_RESUME:
633 ohci->hc_control &= OHCI_CTRL_RWC;
634 ohci->hc_control |= OHCI_USB_RESUME;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400635 val = 10 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 break;
637 // case OHCI_USB_RESET:
638 default:
639 ohci->hc_control &= OHCI_CTRL_RWC;
640 ohci->hc_control |= OHCI_USB_RESET;
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400641 val = 50 /* msec wait */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 break;
643 }
644 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
645 // flush the writes
646 (void) ohci_readl (ohci, &ohci->regs->control);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400647 msleep(val);
Alan Stern383975d2007-05-04 11:52:40 -0400648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
650
651 /* 2msec timelimit here means no irqs/preempt */
652 spin_lock_irq (&ohci->lock);
653
654retry:
655 /* HC Reset requires max 10 us delay */
656 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400657 val = 30; /* ... allow extra time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400659 if (--val == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 spin_unlock_irq (&ohci->lock);
661 ohci_err (ohci, "USB HC reset timed out!\n");
662 return -1;
663 }
664 udelay (1);
665 }
666
667 /* now we're in the SUSPEND state ... must go OPERATIONAL
668 * within 2msec else HC enters RESUME
669 *
670 * ... but some hardware won't init fmInterval "by the book"
671 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
672 * this if we write fmInterval after we're OPERATIONAL.
673 * Unclear about ALi, ServerWorks, and others ... this could
674 * easily be a longstanding bug in chip init on Linux.
675 */
676 if (ohci->flags & OHCI_QUIRK_INITRESET) {
677 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
678 // flush those writes
679 (void) ohci_readl (ohci, &ohci->regs->control);
680 }
681
682 /* Tell the controller where the control and bulk lists are
683 * The lists are empty now. */
684 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
685 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
686
687 /* a reset clears this */
688 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
689
690 periodic_reinit (ohci);
691
692 /* some OHCI implementations are finicky about how they init.
693 * bogus values here mean not even enumeration could work.
694 */
695 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
696 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
697 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
698 ohci->flags |= OHCI_QUIRK_INITRESET;
699 ohci_dbg (ohci, "enabling initreset quirk\n");
700 goto retry;
701 }
702 spin_unlock_irq (&ohci->lock);
703 ohci_err (ohci, "init err (%08x %04x)\n",
704 ohci_readl (ohci, &ohci->regs->fminterval),
705 ohci_readl (ohci, &ohci->regs->periodicstart));
706 return -EOVERFLOW;
707 }
708
David Brownelld4139842006-08-04 11:31:55 -0700709 /* use rhsc irqs after khubd is fully initialized */
Alan Stern541c7d42010-06-22 16:39:10 -0400710 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
David Brownelld4139842006-08-04 11:31:55 -0700711 hcd->uses_new_polling = 1;
712
713 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700715 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
716 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
Alan Sternb7463c72011-11-17 16:41:56 -0500717 ohci->rh_state = OHCI_RH_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 /* wake on ConnectStatusChange, matching external hubs */
720 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
721
722 /* Choose the interrupts we care about now, others later on demand */
723 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700724 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 ohci_writel (ohci, mask, &ohci->regs->intrenable);
726
727 /* handle root hub init quirks ... */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400728 val = roothub_a (ohci);
729 val &= ~(RH_A_PSM | RH_A_OCPM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
731 /* NSC 87560 and maybe others */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400732 val |= RH_A_NOCP;
733 val &= ~(RH_A_POTPGT | RH_A_NPS);
734 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Dmitry Baryshkov1133cd82008-07-06 23:35:01 +0400735 } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
736 (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 /* hub power always on; required for AMD-756 and some
738 * Mac platforms. ganged overcurrent reporting, if any.
739 */
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400740 val |= RH_A_NPS;
741 ohci_writel (ohci, val, &ohci->regs->roothub.a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
743 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400744 ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 &ohci->regs->roothub.b);
746 // flush those writes
747 (void) ohci_readl (ohci, &ohci->regs->control);
748
David Brownelld4139842006-08-04 11:31:55 -0700749 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 spin_unlock_irq (&ohci->lock);
751
752 // POTPGT delay is bits 24-31, in 2 ms units.
H Hartley Sweeten96f90a82009-04-22 16:18:59 -0400753 mdelay ((val >> 23) & 0x1fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Mike Nuss89a0fd12007-08-01 13:24:30 -0700755 if (quirk_zfmicro(ohci)) {
756 /* Create timer to watch for bad queue state on ZF Micro */
757 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
758 (unsigned long) ohci);
759
760 ohci->eds_scheduled = 0;
761 ohci->ed_to_check = NULL;
762 }
763
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 ohci_dump (ohci, 1);
765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 return 0;
767}
768
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530769/* ohci_setup routine for generic controller initialization */
770
771int ohci_setup(struct usb_hcd *hcd)
772{
773 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
774
775 ohci_hcd_init(ohci);
776
777 return ohci_init(ohci);
778}
779EXPORT_SYMBOL_GPL(ohci_setup);
780
781/* ohci_start routine for generic controller start of all OHCI bus glue */
782static int ohci_start(struct usb_hcd *hcd)
783{
784 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
785 int ret;
786
787 ret = ohci_run(ohci);
788 if (ret < 0) {
789 ohci_err(ohci, "can't start\n");
790 ohci_stop(hcd);
791 }
792 return ret;
793}
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795/*-------------------------------------------------------------------------*/
796
797/* an interrupt happens */
798
David Howells7d12e782006-10-05 14:55:46 +0100799static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
801 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
802 struct ohci_regs __iomem *regs = ohci->regs;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700803 int ints;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800805 /* Read interrupt status (and flush pending writes). We ignore the
806 * optimization of checking the LSB of hcca->done_head; it doesn't
807 * work on all systems (edge triggering for OHCI can be a factor).
Mike Nuss89a0fd12007-08-01 13:24:30 -0700808 */
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800809 ints = ohci_readl(ohci, &regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800811 /* Check for an all 1's result which is a typical consequence
812 * of dead, unclocked, or unplugged (CardBus...) devices
813 */
814 if (ints == ~(u32)0) {
Alan Sternb7463c72011-11-17 16:41:56 -0500815 ohci->rh_state = OHCI_RH_HALTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 ohci_dbg (ohci, "device removed!\n");
Alan Stern69fff592011-05-17 17:27:12 -0400817 usb_hc_died(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 return IRQ_HANDLED;
Benjamin Herrenschmidt565227c2007-12-06 13:28:25 -0800819 }
820
821 /* We only care about interrupts that are enabled */
822 ints &= ohci_readl(ohci, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 /* interrupt for some other device? */
Alan Sternb7463c72011-11-17 16:41:56 -0500825 if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 if (ints & OHCI_INTR_UE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 // e.g. due to PCI Master/Target Abort
Mike Nuss89a0fd12007-08-01 13:24:30 -0700830 if (quirk_nec(ohci)) {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200831 /* Workaround for a silicon bug in some NEC chips used
832 * in Apple's PowerBooks. Adapted from Darwin code.
833 */
834 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
835
836 ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
837
838 schedule_work (&ohci->nec_work);
839 } else {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200840 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
Alan Sternb7463c72011-11-17 16:41:56 -0500841 ohci->rh_state = OHCI_RH_HALTED;
Alan Stern69fff592011-05-17 17:27:12 -0400842 usb_hc_died(hcd);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 ohci_dump (ohci, 1);
846 ohci_usb_reset (ohci);
847 }
848
Alan Stern583cead2006-10-24 12:04:22 -0400849 if (ints & OHCI_INTR_RHSC) {
850 ohci_vdbg(ohci, "rhsc\n");
851 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
852 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
853 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400854
855 /* NOTE: Vendors didn't always make the same implementation
856 * choices for RHSC. Many followed the spec; RHSC triggers
857 * on an edge, like setting and maybe clearing a port status
858 * change bit. With others it's level-triggered, active
859 * until khubd clears all the port status change bits. We'll
860 * always disable it here and rely on polling until khubd
861 * re-enables it.
862 */
863 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400864 usb_hcd_poll_rh_status(hcd);
865 }
866
867 /* For connect and disconnect events, we expect the controller
868 * to turn on RHSC along with RD. But for remote wakeup events
869 * this might not happen.
870 */
871 else if (ints & OHCI_INTR_RD) {
872 ohci_vdbg(ohci, "resume detect\n");
873 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern541c7d42010-06-22 16:39:10 -0400874 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
Alan Stern8d1a2432006-09-26 14:46:16 -0400875 if (ohci->autostop) {
876 spin_lock (&ohci->lock);
877 ohci_rh_resume (ohci);
878 spin_unlock (&ohci->lock);
879 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700880 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
882
883 if (ints & OHCI_INTR_WDH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100885 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 spin_unlock (&ohci->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 }
David Brownelldd9048a2006-12-05 03:18:31 -0800888
Mike Nuss89a0fd12007-08-01 13:24:30 -0700889 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
890 spin_lock(&ohci->lock);
891 if (ohci->ed_to_check) {
892 struct ed *ed = ohci->ed_to_check;
893
894 if (check_ed(ohci, ed)) {
895 /* HC thinks the TD list is empty; HCD knows
896 * at least one TD is outstanding
897 */
898 if (--ohci->zf_delay == 0) {
899 struct td *td = list_entry(
900 ed->td_list.next,
901 struct td, td_list);
902 ohci_warn(ohci,
903 "Reclaiming orphan TD %p\n",
904 td);
905 takeback_td(ohci, td);
906 ohci->ed_to_check = NULL;
907 }
908 } else
909 ohci->ed_to_check = NULL;
910 }
911 spin_unlock(&ohci->lock);
912 }
913
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 /* could track INTR_SO to reduce available PCI/... bandwidth */
915
916 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
917 * when there's still unlinking to be done (next frame).
918 */
919 spin_lock (&ohci->lock);
920 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100921 finish_unlinks (ohci, ohci_frame_no(ohci));
Mike Nuss89a0fd12007-08-01 13:24:30 -0700922 if ((ints & OHCI_INTR_SF) != 0
923 && !ohci->ed_rm_list
924 && !ohci->ed_to_check
Alan Sternb7463c72011-11-17 16:41:56 -0500925 && ohci->rh_state == OHCI_RH_RUNNING)
David Brownelldd9048a2006-12-05 03:18:31 -0800926 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 spin_unlock (&ohci->lock);
928
Alan Sternb7463c72011-11-17 16:41:56 -0500929 if (ohci->rh_state == OHCI_RH_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800931 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 // flush those writes
933 (void) ohci_readl (ohci, &ohci->regs->control);
934 }
935
936 return IRQ_HANDLED;
937}
938
939/*-------------------------------------------------------------------------*/
940
941static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800942{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 ohci_dump (ohci, 1);
946
Tejun Heo569ff2d2010-12-24 16:14:20 +0100947 if (quirk_nec(ohci))
Tejun Heo43829732012-08-20 14:51:24 -0700948 flush_work(&ohci->nec_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 ohci_usb_reset (ohci);
951 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700952 free_irq(hcd->irq, hcd);
Felipe Balbicd704692012-02-29 16:46:23 +0200953 hcd->irq = 0;
Pete Zaitcev71795c12006-09-18 22:57:22 -0700954
Mike Nuss89a0fd12007-08-01 13:24:30 -0700955 if (quirk_zfmicro(ohci))
956 del_timer(&ohci->unlink_watchdog);
Libin Yangab1666c2008-08-08 15:03:31 +0800957 if (quirk_amdiso(ohci))
Andiry Xuad935622011-03-01 14:57:05 +0800958 usb_amd_dev_put();
Mike Nuss89a0fd12007-08-01 13:24:30 -0700959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 ohci_mem_cleanup (ohci);
962 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800963 dma_free_coherent (hcd->self.controller,
964 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 ohci->hcca, ohci->hcca_dma);
966 ohci->hcca = NULL;
967 ohci->hcca_dma = 0;
968 }
969}
970
971/*-------------------------------------------------------------------------*/
972
David Brownellda6fb572007-10-24 17:23:42 -0700973#if defined(CONFIG_PM) || defined(CONFIG_PCI)
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975/* must not be called from interrupt context */
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530976int ohci_restart(struct ohci_hcd *ohci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
978 int temp;
979 int i;
980 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Manjunath Goudar95e44d42013-05-28 18:34:49 +0530982 ohci_init(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 spin_lock_irq(&ohci->lock);
Alan Sternb7463c72011-11-17 16:41:56 -0500984 ohci->rh_state = OHCI_RH_HALTED;
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200985
986 /* Recycle any "live" eds/tds (and urbs). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 if (!list_empty (&ohci->pending))
988 ohci_dbg(ohci, "abort schedule...\n");
989 list_for_each_entry (priv, &ohci->pending, pending) {
990 struct urb *urb = priv->td[0]->urb;
991 struct ed *ed = priv->ed;
992
993 switch (ed->state) {
994 case ED_OPER:
995 ed->state = ED_UNLINK;
996 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
997 ed_deschedule (ohci, ed);
998
999 ed->ed_next = ohci->ed_rm_list;
1000 ed->ed_prev = NULL;
1001 ohci->ed_rm_list = ed;
1002 /* FALLTHROUGH */
1003 case ED_UNLINK:
1004 break;
1005 default:
1006 ohci_dbg(ohci, "bogus ed %p state %d\n",
1007 ed, ed->state);
1008 }
1009
Alan Stern55d84962007-08-24 15:40:34 -04001010 if (!urb->unlinked)
1011 urb->unlinked = -ESHUTDOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
David Howells7d12e782006-10-05 14:55:46 +01001013 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 spin_unlock_irq(&ohci->lock);
1015
1016 /* paranoia, in case that didn't work: */
1017
1018 /* empty the interrupt branches */
1019 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
1020 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -08001021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 /* no EDs to remove */
1023 ohci->ed_rm_list = NULL;
1024
David Brownelldd9048a2006-12-05 03:18:31 -08001025 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 ohci->ed_controltail = NULL;
1027 ohci->ed_bulktail = NULL;
1028
1029 if ((temp = ohci_run (ohci)) < 0) {
1030 ohci_err (ohci, "can't restart, %d\n", temp);
1031 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 }
Alan Stern383975d2007-05-04 11:52:40 -04001033 ohci_dbg(ohci, "restart complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 return 0;
1035}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301036EXPORT_SYMBOL_GPL(ohci_restart);
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001037
David Brownellda6fb572007-10-24 17:23:42 -07001038#endif
1039
Florian Fainellicd1965d2012-10-08 15:11:27 +02001040#ifdef CONFIG_PM
1041
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301042int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001043{
1044 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
1045 unsigned long flags;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001046
Florian Fainellid4ae47d2012-10-08 15:11:28 +02001047 /* Disable irq emission and mark HW unaccessible. Use
Florian Fainellicd1965d2012-10-08 15:11:27 +02001048 * the spinlock to properly synchronize with possible pending
1049 * RH suspend or resume activity.
1050 */
1051 spin_lock_irqsave (&ohci->lock, flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001052 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
1053 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
1054
1055 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001056 spin_unlock_irqrestore (&ohci->lock, flags);
1057
Florian Fainellid4ae47d2012-10-08 15:11:28 +02001058 return 0;
Florian Fainellicd1965d2012-10-08 15:11:27 +02001059}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301060EXPORT_SYMBOL_GPL(ohci_suspend);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001061
1062
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301063int ohci_resume(struct usb_hcd *hcd, bool hibernated)
Florian Fainellicd1965d2012-10-08 15:11:27 +02001064{
Florian Fainellicfa49b42012-10-08 15:11:29 +02001065 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
1066 int port;
1067 bool need_reinit = false;
1068
Florian Fainellicd1965d2012-10-08 15:11:27 +02001069 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1070
1071 /* Make sure resume from hibernation re-enumerates everything */
1072 if (hibernated)
Florian Fainellicfa49b42012-10-08 15:11:29 +02001073 ohci_usb_reset(ohci);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001074
Florian Fainellicfa49b42012-10-08 15:11:29 +02001075 /* See if the controller is already running or has been reset */
1076 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
1077 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
1078 need_reinit = true;
1079 } else {
1080 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
1081 case OHCI_USB_OPER:
1082 case OHCI_USB_RESET:
1083 need_reinit = true;
1084 }
1085 }
1086
1087 /* If needed, reinitialize and suspend the root hub */
1088 if (need_reinit) {
1089 spin_lock_irq(&ohci->lock);
1090 ohci_rh_resume(ohci);
1091 ohci_rh_suspend(ohci, 0);
1092 spin_unlock_irq(&ohci->lock);
1093 }
1094
1095 /* Normally just turn on port power and enable interrupts */
1096 else {
1097 ohci_dbg(ohci, "powerup ports\n");
1098 for (port = 0; port < ohci->num_ports; port++)
1099 ohci_writel(ohci, RH_PS_PPS,
1100 &ohci->regs->roothub.portstatus[port]);
1101
1102 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
1103 ohci_readl(ohci, &ohci->regs->intrenable);
1104 msleep(20);
1105 }
1106
1107 usb_hcd_resume_root_hub(hcd);
1108
Florian Fainellicd1965d2012-10-08 15:11:27 +02001109 return 0;
1110}
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301111EXPORT_SYMBOL_GPL(ohci_resume);
Florian Fainellicd1965d2012-10-08 15:11:27 +02001112
1113#endif
1114
Michael Hanselmannd576bb92007-05-31 23:34:27 +02001115/*-------------------------------------------------------------------------*/
1116
Manjunath Goudar95e44d42013-05-28 18:34:49 +05301117/*
1118 * Generic structure: This gets copied for platform drivers so that
1119 * individual entries can be overridden as needed.
1120 */
1121
1122static const struct hc_driver ohci_hc_driver = {
1123 .description = hcd_name,
1124 .product_desc = "OHCI Host Controller",
1125 .hcd_priv_size = sizeof(struct ohci_hcd),
1126
1127 /*
1128 * generic hardware linkage
1129 */
1130 .irq = ohci_irq,
1131 .flags = HCD_MEMORY | HCD_USB11,
1132
1133 /*
1134 * basic lifecycle operations
1135 */
1136 .reset = ohci_setup,
1137 .start = ohci_start,
1138 .stop = ohci_stop,
1139 .shutdown = ohci_shutdown,
1140
1141 /*
1142 * managing i/o requests and associated device resources
1143 */
1144 .urb_enqueue = ohci_urb_enqueue,
1145 .urb_dequeue = ohci_urb_dequeue,
1146 .endpoint_disable = ohci_endpoint_disable,
1147
1148 /*
1149 * scheduling support
1150 */
1151 .get_frame_number = ohci_get_frame,
1152
1153 /*
1154 * root hub support
1155 */
1156 .hub_status_data = ohci_hub_status_data,
1157 .hub_control = ohci_hub_control,
1158#ifdef CONFIG_PM
1159 .bus_suspend = ohci_bus_suspend,
1160 .bus_resume = ohci_bus_resume,
1161#endif
1162 .start_port_reset = ohci_start_port_reset,
1163};
1164
1165void ohci_init_driver(struct hc_driver *drv,
1166 const struct ohci_driver_overrides *over)
1167{
1168 /* Copy the generic table to drv and then apply the overrides */
1169 *drv = ohci_hc_driver;
1170
1171 drv->product_desc = over->product_desc;
1172 drv->hcd_priv_size += over->extra_priv_size;
1173 if (over->reset)
1174 drv->reset = over->reset;
1175}
1176EXPORT_SYMBOL_GPL(ohci_init_driver);
1177
1178/*-------------------------------------------------------------------------*/
1179
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180MODULE_AUTHOR (DRIVER_AUTHOR);
Alan Stern2b70f072008-10-02 11:47:15 -04001181MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182MODULE_LICENSE ("GPL");
1183
1184#ifdef CONFIG_PCI
1185#include "ohci-pci.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001186#define PCI_DRIVER ohci_pci_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187#endif
1188
Eric Miao6381fad2008-06-02 10:05:30 +08001189#if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001191#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192#endif
1193
Kukjin Kimb130d5c2012-02-03 14:29:23 +09001194#if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX)
Ben Dooks3eb0c5f2005-07-29 12:18:03 -07001195#include "ohci-s3c2410.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001196#define S3C2410_PLATFORM_DRIVER ohci_hcd_s3c2410_driver
Ben Dooks3eb0c5f2005-07-29 12:18:03 -07001197#endif
1198
Jingoo Han62194242011-12-23 11:20:54 +09001199#ifdef CONFIG_USB_OHCI_EXYNOS
1200#include "ohci-exynos.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001201#define EXYNOS_PLATFORM_DRIVER exynos_ohci_driver
Jingoo Han62194242011-12-23 11:20:54 +09001202#endif
1203
Anand Gadiyar968b4482010-05-10 21:56:12 +05301204#ifdef CONFIG_USB_OHCI_HCD_OMAP1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205#include "ohci-omap.c"
Anand Gadiyar968b4482010-05-10 21:56:12 +05301206#define OMAP1_PLATFORM_DRIVER ohci_hcd_omap_driver
1207#endif
1208
1209#ifdef CONFIG_USB_OHCI_HCD_OMAP3
1210#include "ohci-omap3.c"
1211#define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212#endif
1213
eric miaoe77ec182007-12-12 09:07:47 +08001214#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215#include "ohci-pxa27x.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001216#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217#endif
1218
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001219#ifdef CONFIG_ARCH_EP93XX
1220#include "ohci-ep93xx.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001221#define EP93XX_PLATFORM_DRIVER ohci_hcd_ep93xx_driver
Lennert Buytenheka5b74742006-06-23 23:02:01 +02001222#endif
1223
Andrew Victor58a0cd72006-12-01 14:51:13 +01001224#ifdef CONFIG_ARCH_AT91
Andrew Victor39a269c2006-01-22 10:32:13 -08001225#include "ohci-at91.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001226#define AT91_PLATFORM_DRIVER ohci_hcd_at91_driver
Andrew Victor39a269c2006-01-22 10:32:13 -08001227#endif
1228
Roland Stigged684f052012-08-26 16:30:37 +02001229#ifdef CONFIG_ARCH_LPC32XX
Roland Stigge32abd562012-03-12 22:54:49 +01001230#include "ohci-nxp.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001231#define NXP_PLATFORM_DRIVER usb_hcd_nxp_driver
Vitaly Wool60bbfc82006-06-29 18:28:18 +04001232#endif
1233
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001234#ifdef CONFIG_ARCH_DAVINCI_DA8XX
1235#include "ohci-da8xx.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001236#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
Sergei Shtylyovefe7daf2010-02-12 23:52:34 +04001237#endif
1238
Sylvain Munaut495a6782006-12-13 21:09:55 +01001239#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1240#include "ohci-ppc-of.c"
1241#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1242#endif
1243
Deepak Sikric8c38de2010-11-10 14:33:18 +05301244#ifdef CONFIG_PLAT_SPEAR
1245#include "ohci-spear.c"
Arnd Bergmann80978042013-04-25 19:29:04 +02001246#define SPEAR_PLATFORM_DRIVER spear_ohci_hcd_driver
Deepak Sikric8c38de2010-11-10 14:33:18 +05301247#endif
1248
Geoff Levand6a6c9572007-01-15 20:12:10 -08001249#ifdef CONFIG_PPC_PS3
1250#include "ohci-ps3.c"
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001251#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
Geoff Levand6a6c9572007-01-15 20:12:10 -08001252#endif
1253
Magnus Dammf54aab62008-01-23 15:58:46 +09001254#ifdef CONFIG_MFD_SM501
1255#include "ohci-sm501.c"
Ben Dooks3ee38d82008-06-08 17:20:11 +01001256#define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
Magnus Dammf54aab62008-01-23 15:58:46 +09001257#endif
1258
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001259#ifdef CONFIG_MFD_TC6393XB
1260#include "ohci-tmio.c"
1261#define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
1262#endif
1263
Lars-Peter Clausen22490712010-06-19 04:08:24 +00001264#ifdef CONFIG_MACH_JZ4740
1265#include "ohci-jz4740.c"
1266#define PLATFORM_DRIVER ohci_hcd_jz4740_driver
1267#endif
1268
David Daney1643acc2010-10-08 14:47:52 -07001269#ifdef CONFIG_USB_OCTEON_OHCI
1270#include "ohci-octeon.c"
1271#define PLATFORM_DRIVER ohci_octeon_driver
1272#endif
1273
Chris Metcalf47fc28b2012-05-09 13:58:14 -04001274#ifdef CONFIG_TILE_USB
1275#include "ohci-tilegx.c"
1276#define PLATFORM_DRIVER ohci_hcd_tilegx_driver
1277#endif
1278
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +01001279#ifdef CONFIG_USB_OHCI_HCD_PLATFORM
1280#include "ohci-platform.c"
1281#define PLATFORM_DRIVER ohci_platform_driver
1282#endif
1283
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001284#if !defined(PCI_DRIVER) && \
1285 !defined(PLATFORM_DRIVER) && \
Anand Gadiyar968b4482010-05-10 21:56:12 +05301286 !defined(OMAP1_PLATFORM_DRIVER) && \
1287 !defined(OMAP3_PLATFORM_DRIVER) && \
Sylvain Munaut495a6782006-12-13 21:09:55 +01001288 !defined(OF_PLATFORM_DRIVER) && \
Geoff Levand6a6c9572007-01-15 20:12:10 -08001289 !defined(SA1111_DRIVER) && \
Michael Bueschc604e852007-10-09 23:47:17 -07001290 !defined(PS3_SYSTEM_BUS_DRIVER) && \
Ben Dooks3ee38d82008-06-08 17:20:11 +01001291 !defined(SM501_OHCI_DRIVER) && \
Arnd Bergmann80978042013-04-25 19:29:04 +02001292 !defined(TMIO_OHCI_DRIVER) && \
1293 !defined(S3C2410_PLATFORM_DRIVER) && \
1294 !defined(EXYNOS_PLATFORM_DRIVER) && \
1295 !defined(EP93XX_PLATFORM_DRIVER) && \
1296 !defined(AT91_PLATFORM_DRIVER) && \
1297 !defined(NXP_PLATFORM_DRIVER) && \
1298 !defined(DAVINCI_PLATFORM_DRIVER) && \
1299 !defined(SPEAR_PLATFORM_DRIVER)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300#error "missing bus glue for ohci-hcd"
1301#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001302
1303static int __init ohci_hcd_mod_init(void)
1304{
1305 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001306
1307 if (usb_disabled())
1308 return -ENODEV;
1309
Alan Stern2b70f072008-10-02 11:47:15 -04001310 printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001311 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1312 sizeof (struct ed), sizeof (struct td));
Alan Stern9beeee62008-10-02 11:48:13 -04001313 set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001314
Tony Jones684c19e2007-09-11 14:07:31 -07001315#ifdef DEBUG
Greg Kroah-Hartman485f4f32009-04-24 15:14:38 -07001316 ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
Tony Jones684c19e2007-09-11 14:07:31 -07001317 if (!ohci_debug_root) {
1318 retval = -ENOENT;
1319 goto error_debug;
1320 }
1321#endif
1322
Geoff Levand6a6c9572007-01-15 20:12:10 -08001323#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001324 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1325 if (retval < 0)
1326 goto error_ps3;
Geoff Levand6a6c9572007-01-15 20:12:10 -08001327#endif
1328
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001329#ifdef PLATFORM_DRIVER
1330 retval = platform_driver_register(&PLATFORM_DRIVER);
1331 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001332 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001333#endif
1334
Anand Gadiyar968b4482010-05-10 21:56:12 +05301335#ifdef OMAP1_PLATFORM_DRIVER
1336 retval = platform_driver_register(&OMAP1_PLATFORM_DRIVER);
1337 if (retval < 0)
1338 goto error_omap1_platform;
1339#endif
1340
1341#ifdef OMAP3_PLATFORM_DRIVER
1342 retval = platform_driver_register(&OMAP3_PLATFORM_DRIVER);
1343 if (retval < 0)
1344 goto error_omap3_platform;
1345#endif
1346
Sylvain Munaut495a6782006-12-13 21:09:55 +01001347#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001348 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001349 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001350 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +01001351#endif
1352
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001353#ifdef SA1111_DRIVER
1354 retval = sa1111_driver_register(&SA1111_DRIVER);
1355 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001356 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001357#endif
1358
1359#ifdef PCI_DRIVER
1360 retval = pci_register_driver(&PCI_DRIVER);
1361 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001362 goto error_pci;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001363#endif
1364
Ben Dooks3ee38d82008-06-08 17:20:11 +01001365#ifdef SM501_OHCI_DRIVER
1366 retval = platform_driver_register(&SM501_OHCI_DRIVER);
1367 if (retval < 0)
1368 goto error_sm501;
1369#endif
1370
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001371#ifdef TMIO_OHCI_DRIVER
1372 retval = platform_driver_register(&TMIO_OHCI_DRIVER);
1373 if (retval < 0)
1374 goto error_tmio;
1375#endif
1376
Arnd Bergmann80978042013-04-25 19:29:04 +02001377#ifdef S3C2410_PLATFORM_DRIVER
1378 retval = platform_driver_register(&S3C2410_PLATFORM_DRIVER);
1379 if (retval < 0)
1380 goto error_s3c2410;
1381#endif
1382
1383#ifdef EXYNOS_PLATFORM_DRIVER
1384 retval = platform_driver_register(&EXYNOS_PLATFORM_DRIVER);
1385 if (retval < 0)
1386 goto error_exynos;
1387#endif
1388
1389#ifdef EP93XX_PLATFORM_DRIVER
1390 retval = platform_driver_register(&EP93XX_PLATFORM_DRIVER);
1391 if (retval < 0)
1392 goto error_ep93xx;
1393#endif
1394
1395#ifdef AT91_PLATFORM_DRIVER
1396 retval = platform_driver_register(&AT91_PLATFORM_DRIVER);
1397 if (retval < 0)
1398 goto error_at91;
1399#endif
1400
1401#ifdef NXP_PLATFORM_DRIVER
1402 retval = platform_driver_register(&NXP_PLATFORM_DRIVER);
1403 if (retval < 0)
1404 goto error_nxp;
1405#endif
1406
1407#ifdef DAVINCI_PLATFORM_DRIVER
1408 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
1409 if (retval < 0)
1410 goto error_davinci;
1411#endif
1412
1413#ifdef SPEAR_PLATFORM_DRIVER
1414 retval = platform_driver_register(&SPEAR_PLATFORM_DRIVER);
1415 if (retval < 0)
1416 goto error_spear;
1417#endif
1418
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001419 return retval;
1420
1421 /* Error path */
Arnd Bergmann80978042013-04-25 19:29:04 +02001422#ifdef SPEAR_PLATFORM_DRIVER
1423 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1424 error_spear:
1425#endif
1426#ifdef DAVINCI_PLATFORM_DRIVER
1427 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1428 error_davinci:
1429#endif
1430#ifdef NXP_PLATFORM_DRIVER
1431 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1432 error_nxp:
1433#endif
1434#ifdef AT91_PLATFORM_DRIVER
1435 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1436 error_at91:
1437#endif
1438#ifdef EP93XX_PLATFORM_DRIVER
1439 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1440 error_ep93xx:
1441#endif
1442#ifdef EXYNOS_PLATFORM_DRIVER
1443 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1444 error_exynos:
1445#endif
1446#ifdef S3C2410_PLATFORM_DRIVER
1447 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1448 error_s3c2410:
1449#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001450#ifdef TMIO_OHCI_DRIVER
1451 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1452 error_tmio:
1453#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001454#ifdef SM501_OHCI_DRIVER
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001455 platform_driver_unregister(&SM501_OHCI_DRIVER);
Ben Dooks3ee38d82008-06-08 17:20:11 +01001456 error_sm501:
1457#endif
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001458#ifdef PCI_DRIVER
Michael Bueschc604e852007-10-09 23:47:17 -07001459 pci_unregister_driver(&PCI_DRIVER);
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001460 error_pci:
Sylvain Munaut495a6782006-12-13 21:09:55 +01001461#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001462#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001463 sa1111_driver_unregister(&SA1111_DRIVER);
1464 error_sa1111:
1465#endif
1466#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001467 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -08001468 error_of_platform:
1469#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001470#ifdef OMAP3_PLATFORM_DRIVER
1471 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1472 error_omap3_platform:
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001473#endif
Anand Gadiyar968b4482010-05-10 21:56:12 +05301474#ifdef OMAP1_PLATFORM_DRIVER
1475 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1476 error_omap1_platform:
1477#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001478#ifdef PLATFORM_DRIVER
1479 platform_driver_unregister(&PLATFORM_DRIVER);
1480 error_platform:
Anand Gadiyar968b4482010-05-10 21:56:12 +05301481#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001482#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001483 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001484 error_ps3:
1485#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001486#ifdef DEBUG
1487 debugfs_remove(ohci_debug_root);
1488 ohci_debug_root = NULL;
1489 error_debug:
1490#endif
1491
Alan Stern9beeee62008-10-02 11:48:13 -04001492 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001493 return retval;
1494}
1495module_init(ohci_hcd_mod_init);
1496
1497static void __exit ohci_hcd_mod_exit(void)
1498{
Arnd Bergmann80978042013-04-25 19:29:04 +02001499#ifdef SPEAR_PLATFORM_DRIVER
1500 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1501#endif
1502#ifdef DAVINCI_PLATFORM_DRIVER
1503 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1504#endif
1505#ifdef NXP_PLATFORM_DRIVER
1506 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1507#endif
1508#ifdef AT91_PLATFORM_DRIVER
1509 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1510#endif
1511#ifdef EP93XX_PLATFORM_DRIVER
1512 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1513#endif
1514#ifdef EXYNOS_PLATFORM_DRIVER
1515 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1516#endif
1517#ifdef S3C2410_PLATFORM_DRIVER
1518 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1519#endif
Dmitry Baryshkov78c73412008-10-08 16:14:23 +04001520#ifdef TMIO_OHCI_DRIVER
1521 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1522#endif
Ben Dooks3ee38d82008-06-08 17:20:11 +01001523#ifdef SM501_OHCI_DRIVER
1524 platform_driver_unregister(&SM501_OHCI_DRIVER);
1525#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001526#ifdef PCI_DRIVER
1527 pci_unregister_driver(&PCI_DRIVER);
1528#endif
1529#ifdef SA1111_DRIVER
1530 sa1111_driver_unregister(&SA1111_DRIVER);
1531#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001532#ifdef OF_PLATFORM_DRIVER
Grant Likelyd35fb642011-02-22 21:08:34 -07001533 platform_driver_unregister(&OF_PLATFORM_DRIVER);
Sylvain Munaut495a6782006-12-13 21:09:55 +01001534#endif
Keshava Munegowdaffb67482010-09-14 04:40:01 +05301535#ifdef OMAP3_PLATFORM_DRIVER
1536 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1537#endif
Arnd Bergmann80978042013-04-25 19:29:04 +02001538#ifdef OMAP1_PLATFORM_DRIVER
1539 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1540#endif
1541#ifdef PLATFORM_DRIVER
1542 platform_driver_unregister(&PLATFORM_DRIVER);
1543#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001544#ifdef PS3_SYSTEM_BUS_DRIVER
Geoff Levand7a4eb7f2007-06-05 20:04:35 -07001545 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001546#endif
Tony Jones684c19e2007-09-11 14:07:31 -07001547#ifdef DEBUG
1548 debugfs_remove(ohci_debug_root);
1549#endif
Alan Stern9beeee62008-10-02 11:48:13 -04001550 clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001551}
1552module_exit(ohci_hcd_mod_exit);
1553