blob: 44717fab7435cebe7afa684bdc044611b18507e7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
David Brownelldd9048a2006-12-05 03:18:31 -08006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * [ Initialisation is based on Linus' ]
8 * [ uhci code and gregs ohci fragments ]
9 * [ (C) Copyright 1999 Linus Torvalds ]
10 * [ (C) Copyright 1999 Gregory P. Smith]
David Brownelldd9048a2006-12-05 03:18:31 -080011 *
12 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
14 * interfaces (though some non-x86 Intel chips use it). It supports
15 * smarter hardware than UHCI. A download link for the spec available
16 * through the http://www.usb.org website.
17 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * This file is licenced under the GPL.
19 */
David Brownelldd9048a2006-12-05 03:18:31 -080020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/pci.h>
24#include <linux/kernel.h>
25#include <linux/delay.h>
26#include <linux/ioport.h>
27#include <linux/sched.h>
28#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/errno.h>
30#include <linux/init.h>
31#include <linux/timer.h>
32#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/usb.h>
David Brownell3a16f7b2006-06-29 12:27:23 -070034#include <linux/usb/otg.h>
David Brownelldd9048a2006-12-05 03:18:31 -080035#include <linux/dma-mapping.h>
David Brownellf4df0e32005-04-23 12:49:16 -070036#include <linux/dmapool.h>
37#include <linux/reboot.h>
Michael Hanselmannd576bb92007-05-31 23:34:27 +020038#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#include <asm/io.h>
41#include <asm/irq.h>
42#include <asm/system.h>
43#include <asm/unaligned.h>
44#include <asm/byteorder.h>
Ishizaki Kou48fda452007-02-14 16:04:17 +090045#ifdef CONFIG_PPC_PS3
46#include <asm/firmware.h>
47#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
David Brownellf4df0e32005-04-23 12:49:16 -070049#include "../core/hcd.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
David Brownelld4139842006-08-04 11:31:55 -070051#define DRIVER_VERSION "2006 August 04"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
53#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
54
55/*-------------------------------------------------------------------------*/
56
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +110057#undef OHCI_VERBOSE_DEBUG /* not always helpful */
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59/* For initializing controller (mask in an HCFS mode too) */
David Brownelld4139842006-08-04 11:31:55 -070060#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#define OHCI_INTR_INIT \
David Brownelld4139842006-08-04 11:31:55 -070062 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
63 | OHCI_INTR_RD | OHCI_INTR_WDH)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65#ifdef __hppa__
66/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
67#define IR_DISABLE
68#endif
69
70#ifdef CONFIG_ARCH_OMAP
71/* OMAP doesn't support IR (no SMM; not needed) */
72#define IR_DISABLE
73#endif
74
75/*-------------------------------------------------------------------------*/
76
77static const char hcd_name [] = "ohci_hcd";
78
David Brownelld4139842006-08-04 11:31:55 -070079#define STATECHANGE_DELAY msecs_to_jiffies(300)
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#include "ohci.h"
82
83static void ohci_dump (struct ohci_hcd *ohci, int verbose);
84static int ohci_init (struct ohci_hcd *ohci);
85static void ohci_stop (struct usb_hcd *hcd);
Michael Hanselmannd576bb92007-05-31 23:34:27 +020086static int ohci_restart (struct ohci_hcd *ohci);
87static void ohci_quirk_nec_worker (struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89#include "ohci-hub.c"
90#include "ohci-dbg.c"
91#include "ohci-mem.c"
92#include "ohci-q.c"
93
94
95/*
96 * On architectures with edge-triggered interrupts we must never return
97 * IRQ_NONE.
98 */
99#if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
100#define IRQ_NOTMINE IRQ_HANDLED
101#else
102#define IRQ_NOTMINE IRQ_NONE
103#endif
104
105
106/* Some boards misreport power switching/overcurrent */
107static int distrust_firmware = 1;
108module_param (distrust_firmware, bool, 0);
109MODULE_PARM_DESC (distrust_firmware,
110 "true to distrust firmware power/overcurrent setup");
111
112/* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
113static int no_handshake = 0;
114module_param (no_handshake, bool, 0);
115MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
116
117/*-------------------------------------------------------------------------*/
118
119/*
120 * queue up an urb for anything except the root hub
121 */
122static int ohci_urb_enqueue (
123 struct usb_hcd *hcd,
124 struct usb_host_endpoint *ep,
125 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400126 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127) {
128 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
129 struct ed *ed;
130 urb_priv_t *urb_priv;
131 unsigned int pipe = urb->pipe;
132 int i, size = 0;
133 unsigned long flags;
134 int retval = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#ifdef OHCI_VERBOSE_DEBUG
137 urb_print (urb, "SUB", usb_pipein (pipe));
138#endif
David Brownelldd9048a2006-12-05 03:18:31 -0800139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /* every endpoint has a ed, locate and maybe (re)initialize it */
141 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval)))
142 return -ENOMEM;
143
144 /* for the private part of the URB we need the number of TDs (size) */
145 switch (ed->type) {
146 case PIPE_CONTROL:
147 /* td_submit_urb() doesn't yet handle these */
148 if (urb->transfer_buffer_length > 4096)
149 return -EMSGSIZE;
150
151 /* 1 TD for setup, 1 for ACK, plus ... */
152 size = 2;
153 /* FALLTHROUGH */
154 // case PIPE_INTERRUPT:
155 // case PIPE_BULK:
156 default:
157 /* one TD for every 4096 Bytes (can be upto 8K) */
158 size += urb->transfer_buffer_length / 4096;
159 /* ... and for any remaining bytes ... */
160 if ((urb->transfer_buffer_length % 4096) != 0)
161 size++;
162 /* ... and maybe a zero length packet to wrap it up */
163 if (size == 0)
164 size++;
165 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
166 && (urb->transfer_buffer_length
167 % usb_maxpacket (urb->dev, pipe,
168 usb_pipeout (pipe))) == 0)
169 size++;
170 break;
171 case PIPE_ISOCHRONOUS: /* number of packets from URB */
172 size = urb->number_of_packets;
173 break;
174 }
175
176 /* allocate the private part of the URB */
177 urb_priv = kmalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
178 mem_flags);
179 if (!urb_priv)
180 return -ENOMEM;
181 memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (struct td *));
182 INIT_LIST_HEAD (&urb_priv->pending);
183 urb_priv->length = size;
David Brownelldd9048a2006-12-05 03:18:31 -0800184 urb_priv->ed = ed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 /* allocate the TDs (deferring hash chain updates) */
187 for (i = 0; i < size; i++) {
188 urb_priv->td [i] = td_alloc (ohci, mem_flags);
189 if (!urb_priv->td [i]) {
190 urb_priv->length = i;
191 urb_free_priv (ohci, urb_priv);
192 return -ENOMEM;
193 }
David Brownelldd9048a2006-12-05 03:18:31 -0800194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 spin_lock_irqsave (&ohci->lock, flags);
197
198 /* don't submit to a dead HC */
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100199 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
200 retval = -ENODEV;
201 goto fail;
202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 if (!HC_IS_RUNNING(hcd->state)) {
204 retval = -ENODEV;
205 goto fail;
206 }
207
208 /* in case of unlink-during-submit */
209 spin_lock (&urb->lock);
210 if (urb->status != -EINPROGRESS) {
211 spin_unlock (&urb->lock);
212 urb->hcpriv = urb_priv;
David Howells7d12e782006-10-05 14:55:46 +0100213 finish_urb (ohci, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 retval = 0;
215 goto fail;
216 }
217
218 /* schedule the ed if needed */
219 if (ed->state == ED_IDLE) {
220 retval = ed_schedule (ohci, ed);
221 if (retval < 0)
222 goto fail0;
223 if (ed->type == PIPE_ISOCHRONOUS) {
224 u16 frame = ohci_frame_no(ohci);
225
226 /* delay a few frames before the first TD */
227 frame += max_t (u16, 8, ed->interval);
228 frame &= ~(ed->interval - 1);
229 frame |= ed->branch;
230 urb->start_frame = frame;
231
232 /* yes, only URB_ISO_ASAP is supported, and
233 * urb->start_frame is never used as input.
234 */
235 }
236 } else if (ed->type == PIPE_ISOCHRONOUS)
237 urb->start_frame = ed->last_iso + ed->interval;
238
239 /* fill the TDs and link them to the ed; and
240 * enable that part of the schedule, if needed
241 * and update count of queued periodic urbs
242 */
243 urb->hcpriv = urb_priv;
244 td_submit_urb (ohci, urb);
245
246fail0:
247 spin_unlock (&urb->lock);
248fail:
249 if (retval)
250 urb_free_priv (ohci, urb_priv);
251 spin_unlock_irqrestore (&ohci->lock, flags);
252 return retval;
253}
254
255/*
256 * decouple the URB from the HC queues (TDs, urb_priv); it's
257 * already marked using urb->status. reporting is always done
258 * asynchronously, and we might be dealing with an urb that's
259 * partially transferred, or an ED with other urbs being unlinked.
260 */
261static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
262{
263 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
264 unsigned long flags;
David Brownelldd9048a2006-12-05 03:18:31 -0800265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#ifdef OHCI_VERBOSE_DEBUG
267 urb_print (urb, "UNLINK", 1);
David Brownelldd9048a2006-12-05 03:18:31 -0800268#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 spin_lock_irqsave (&ohci->lock, flags);
David Brownelldd9048a2006-12-05 03:18:31 -0800271 if (HC_IS_RUNNING(hcd->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 urb_priv_t *urb_priv;
273
274 /* Unless an IRQ completed the unlink while it was being
275 * handed to us, flag it for unlink and giveback, and force
276 * some upcoming INTR_SF to call finish_unlinks()
277 */
278 urb_priv = urb->hcpriv;
279 if (urb_priv) {
280 if (urb_priv->ed->state == ED_OPER)
281 start_ed_unlink (ohci, urb_priv->ed);
282 }
283 } else {
284 /*
285 * with HC dead, we won't respect hc queue pointers
286 * any more ... just clean up every urb's memory.
287 */
288 if (urb->hcpriv)
David Howells7d12e782006-10-05 14:55:46 +0100289 finish_urb (ohci, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
291 spin_unlock_irqrestore (&ohci->lock, flags);
292 return 0;
293}
294
295/*-------------------------------------------------------------------------*/
296
297/* frees config/altsetting state for endpoints,
298 * including ED memory, dummy TD, and bulk/intr data toggle
299 */
300
301static void
302ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
303{
304 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
305 unsigned long flags;
306 struct ed *ed = ep->hcpriv;
307 unsigned limit = 1000;
308
309 /* ASSERT: any requests/urbs are being unlinked */
310 /* ASSERT: nobody can be submitting urbs for this any more */
311
312 if (!ed)
313 return;
314
315rescan:
316 spin_lock_irqsave (&ohci->lock, flags);
317
318 if (!HC_IS_RUNNING (hcd->state)) {
319sanitize:
320 ed->state = ED_IDLE;
David Howells7d12e782006-10-05 14:55:46 +0100321 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323
324 switch (ed->state) {
325 case ED_UNLINK: /* wait for hw to finish? */
326 /* major IRQ delivery trouble loses INTR_SF too... */
327 if (limit-- == 0) {
328 ohci_warn (ohci, "IRQ INTR_SF lossage\n");
329 goto sanitize;
330 }
331 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700332 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 goto rescan;
334 case ED_IDLE: /* fully unlinked */
335 if (list_empty (&ed->td_list)) {
336 td_free (ohci, ed->dummy);
337 ed_free (ohci, ed);
338 break;
339 }
340 /* else FALL THROUGH */
341 default:
342 /* caller was supposed to have unlinked any requests;
343 * that's not our job. can't recover; must leak ed.
344 */
345 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
346 ed, ep->desc.bEndpointAddress, ed->state,
347 list_empty (&ed->td_list) ? "" : " (has tds)");
348 td_free (ohci, ed->dummy);
349 break;
350 }
351 ep->hcpriv = NULL;
352 spin_unlock_irqrestore (&ohci->lock, flags);
353 return;
354}
355
356static int ohci_get_frame (struct usb_hcd *hcd)
357{
358 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
359
360 return ohci_frame_no(ohci);
361}
362
363static void ohci_usb_reset (struct ohci_hcd *ohci)
364{
365 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
366 ohci->hc_control &= OHCI_CTRL_RWC;
367 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
368}
369
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700370/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700371 * other cases where the next software may expect clean state from the
372 * "firmware". this is bus-neutral, unlike shutdown() methods.
373 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700374static void
375ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700376{
377 struct ohci_hcd *ohci;
378
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700379 ohci = hcd_to_ohci (hcd);
David Brownellf4df0e32005-04-23 12:49:16 -0700380 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
381 ohci_usb_reset (ohci);
382 /* flush the writes */
383 (void) ohci_readl (ohci, &ohci->regs->control);
David Brownellf4df0e32005-04-23 12:49:16 -0700384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386/*-------------------------------------------------------------------------*
387 * HC functions
388 *-------------------------------------------------------------------------*/
389
390/* init memory, and kick BIOS/SMM off */
391
392static int ohci_init (struct ohci_hcd *ohci)
393{
394 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800395 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 disable (ohci);
David Brownell6a9062f2006-01-23 15:28:07 -0800398 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
David Brownell6a9062f2006-01-23 15:28:07 -0800400 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
401 * was never needed for most non-PCI systems ... remove the code?
402 */
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#ifndef IR_DISABLE
405 /* SMM owns the HC? not for long! */
406 if (!no_handshake && ohci_readl (ohci,
407 &ohci->regs->control) & OHCI_CTRL_IR) {
408 u32 temp;
409
410 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
411
412 /* this timeout is arbitrary. we make it long, so systems
413 * depending on usb keyboards may be usable even if the
414 * BIOS/SMM code seems pretty broken.
415 */
416 temp = 500; /* arbitrary: five seconds */
417
418 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
419 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
420 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
421 msleep (10);
422 if (--temp == 0) {
423 ohci_err (ohci, "USB HC takeover failed!"
424 " (BIOS/SMM bug)\n");
425 return -EBUSY;
426 }
427 }
428 ohci_usb_reset (ohci);
429 }
430#endif
431
432 /* Disable HC interrupts */
433 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800434
435 /* flush the writes, and save key bits like RWC */
436 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
437 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
David Brownellfdd13b32005-08-31 11:52:57 -0700439 /* Read the number of ports unless overridden */
440 if (ohci->num_ports == 0)
441 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 if (ohci->hcca)
444 return 0;
445
David Brownell6a9062f2006-01-23 15:28:07 -0800446 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
448 if (!ohci->hcca)
449 return -ENOMEM;
450
451 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800452 ohci_stop (hcd);
453 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800454 create_debug_files (ohci);
455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
460/*-------------------------------------------------------------------------*/
461
462/* Start an OHCI controller, set the BUS operational
463 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800464 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 */
466static int ohci_run (struct ohci_hcd *ohci)
467{
David Brownelldd9048a2006-12-05 03:18:31 -0800468 u32 mask, temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800470 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
472 disable (ohci);
473
474 /* boot firmware should have set this up (5.1.1.3.1) */
475 if (first) {
476
477 temp = ohci_readl (ohci, &ohci->regs->fminterval);
478 ohci->fminterval = temp & 0x3fff;
479 if (ohci->fminterval != FI)
480 ohci_dbg (ohci, "fminterval delta %d\n",
481 ohci->fminterval - FI);
482 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
483 /* also: power/overcurrent flags in roothub.a */
484 }
485
David Brownelldd9048a2006-12-05 03:18:31 -0800486 /* Reset USB nearly "by the book". RemoteWakeupConnected was
David Brownell6a9062f2006-01-23 15:28:07 -0800487 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
488 * or if bus glue did the same (e.g. for PCI add-in cards with
489 * PCI PM support).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 */
David Brownell6a9062f2006-01-23 15:28:07 -0800491 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0
492 && !device_may_wakeup(hcd->self.controller))
493 device_init_wakeup(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
496 case OHCI_USB_OPER:
497 temp = 0;
498 break;
499 case OHCI_USB_SUSPEND:
500 case OHCI_USB_RESUME:
501 ohci->hc_control &= OHCI_CTRL_RWC;
502 ohci->hc_control |= OHCI_USB_RESUME;
503 temp = 10 /* msec wait */;
504 break;
505 // case OHCI_USB_RESET:
506 default:
507 ohci->hc_control &= OHCI_CTRL_RWC;
508 ohci->hc_control |= OHCI_USB_RESET;
509 temp = 50 /* msec wait */;
510 break;
511 }
512 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
513 // flush the writes
514 (void) ohci_readl (ohci, &ohci->regs->control);
515 msleep(temp);
Alan Stern383975d2007-05-04 11:52:40 -0400516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
518
519 /* 2msec timelimit here means no irqs/preempt */
520 spin_lock_irq (&ohci->lock);
521
522retry:
523 /* HC Reset requires max 10 us delay */
524 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
525 temp = 30; /* ... allow extra time */
526 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
527 if (--temp == 0) {
528 spin_unlock_irq (&ohci->lock);
529 ohci_err (ohci, "USB HC reset timed out!\n");
530 return -1;
531 }
532 udelay (1);
533 }
534
535 /* now we're in the SUSPEND state ... must go OPERATIONAL
536 * within 2msec else HC enters RESUME
537 *
538 * ... but some hardware won't init fmInterval "by the book"
539 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
540 * this if we write fmInterval after we're OPERATIONAL.
541 * Unclear about ALi, ServerWorks, and others ... this could
542 * easily be a longstanding bug in chip init on Linux.
543 */
544 if (ohci->flags & OHCI_QUIRK_INITRESET) {
545 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
546 // flush those writes
547 (void) ohci_readl (ohci, &ohci->regs->control);
548 }
549
550 /* Tell the controller where the control and bulk lists are
551 * The lists are empty now. */
552 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
553 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
554
555 /* a reset clears this */
556 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
557
558 periodic_reinit (ohci);
559
560 /* some OHCI implementations are finicky about how they init.
561 * bogus values here mean not even enumeration could work.
562 */
563 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
564 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
565 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
566 ohci->flags |= OHCI_QUIRK_INITRESET;
567 ohci_dbg (ohci, "enabling initreset quirk\n");
568 goto retry;
569 }
570 spin_unlock_irq (&ohci->lock);
571 ohci_err (ohci, "init err (%08x %04x)\n",
572 ohci_readl (ohci, &ohci->regs->fminterval),
573 ohci_readl (ohci, &ohci->regs->periodicstart));
574 return -EOVERFLOW;
575 }
576
David Brownelld4139842006-08-04 11:31:55 -0700577 /* use rhsc irqs after khubd is fully initialized */
578 hcd->poll_rh = 1;
579 hcd->uses_new_polling = 1;
580
581 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700583 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
584 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
David Brownell6a9062f2006-01-23 15:28:07 -0800585 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 /* wake on ConnectStatusChange, matching external hubs */
588 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
589
590 /* Choose the interrupts we care about now, others later on demand */
591 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700592 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 ohci_writel (ohci, mask, &ohci->regs->intrenable);
594
595 /* handle root hub init quirks ... */
596 temp = roothub_a (ohci);
597 temp &= ~(RH_A_PSM | RH_A_OCPM);
598 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
599 /* NSC 87560 and maybe others */
600 temp |= RH_A_NOCP;
601 temp &= ~(RH_A_POTPGT | RH_A_NPS);
602 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
603 } else if ((ohci->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
604 /* hub power always on; required for AMD-756 and some
605 * Mac platforms. ganged overcurrent reporting, if any.
606 */
607 temp |= RH_A_NPS;
608 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
609 }
610 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
611 ohci_writel (ohci, (temp & RH_A_NPS) ? 0 : RH_B_PPCM,
612 &ohci->regs->roothub.b);
613 // flush those writes
614 (void) ohci_readl (ohci, &ohci->regs->control);
615
David Brownelld4139842006-08-04 11:31:55 -0700616 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 spin_unlock_irq (&ohci->lock);
618
619 // POTPGT delay is bits 24-31, in 2 ms units.
620 mdelay ((temp >> 23) & 0x1fe);
David Brownell6a9062f2006-01-23 15:28:07 -0800621 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 ohci_dump (ohci, 1);
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return 0;
626}
627
628/*-------------------------------------------------------------------------*/
629
630/* an interrupt happens */
631
David Howells7d12e782006-10-05 14:55:46 +0100632static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
634 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
635 struct ohci_regs __iomem *regs = ohci->regs;
636 int ints;
637
638 /* we can eliminate a (slow) ohci_readl()
639 if _only_ WDH caused this irq */
640 if ((ohci->hcca->done_head != 0)
641 && ! (hc32_to_cpup (ohci, &ohci->hcca->done_head)
642 & 0x01)) {
643 ints = OHCI_INTR_WDH;
644
645 /* cardbus/... hardware gone before remove() */
646 } else if ((ints = ohci_readl (ohci, &regs->intrstatus)) == ~(u32)0) {
647 disable (ohci);
648 ohci_dbg (ohci, "device removed!\n");
649 return IRQ_HANDLED;
650
651 /* interrupt for some other device? */
652 } else if ((ints &= ohci_readl (ohci, &regs->intrenable)) == 0) {
653 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700654 }
655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 if (ints & OHCI_INTR_UE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 // e.g. due to PCI Master/Target Abort
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200658 if (ohci->flags & OHCI_QUIRK_NEC) {
659 /* Workaround for a silicon bug in some NEC chips used
660 * in Apple's PowerBooks. Adapted from Darwin code.
661 */
662 ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
663
664 ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
665
666 schedule_work (&ohci->nec_work);
667 } else {
668 disable (ohci);
669 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672 ohci_dump (ohci, 1);
673 ohci_usb_reset (ohci);
674 }
675
Alan Stern583cead2006-10-24 12:04:22 -0400676 if (ints & OHCI_INTR_RHSC) {
677 ohci_vdbg(ohci, "rhsc\n");
678 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
679 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
680 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400681
682 /* NOTE: Vendors didn't always make the same implementation
683 * choices for RHSC. Many followed the spec; RHSC triggers
684 * on an edge, like setting and maybe clearing a port status
685 * change bit. With others it's level-triggered, active
686 * until khubd clears all the port status change bits. We'll
687 * always disable it here and rely on polling until khubd
688 * re-enables it.
689 */
690 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400691 usb_hcd_poll_rh_status(hcd);
692 }
693
694 /* For connect and disconnect events, we expect the controller
695 * to turn on RHSC along with RD. But for remote wakeup events
696 * this might not happen.
697 */
698 else if (ints & OHCI_INTR_RD) {
699 ohci_vdbg(ohci, "resume detect\n");
700 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern8d1a2432006-09-26 14:46:16 -0400701 hcd->poll_rh = 1;
702 if (ohci->autostop) {
703 spin_lock (&ohci->lock);
704 ohci_rh_resume (ohci);
705 spin_unlock (&ohci->lock);
706 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700707 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 }
709
710 if (ints & OHCI_INTR_WDH) {
711 if (HC_IS_RUNNING(hcd->state))
Alan Stern8d1a2432006-09-26 14:46:16 -0400712 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100714 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 spin_unlock (&ohci->lock);
716 if (HC_IS_RUNNING(hcd->state))
David Brownelldd9048a2006-12-05 03:18:31 -0800717 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 }
David Brownelldd9048a2006-12-05 03:18:31 -0800719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 /* could track INTR_SO to reduce available PCI/... bandwidth */
721
722 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
723 * when there's still unlinking to be done (next frame).
724 */
725 spin_lock (&ohci->lock);
726 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100727 finish_unlinks (ohci, ohci_frame_no(ohci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
729 && HC_IS_RUNNING(hcd->state))
David Brownelldd9048a2006-12-05 03:18:31 -0800730 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 spin_unlock (&ohci->lock);
732
733 if (HC_IS_RUNNING(hcd->state)) {
734 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800735 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 // flush those writes
737 (void) ohci_readl (ohci, &ohci->regs->control);
738 }
739
740 return IRQ_HANDLED;
741}
742
743/*-------------------------------------------------------------------------*/
744
745static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800746{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 ohci_dump (ohci, 1);
750
751 flush_scheduled_work();
752
753 ohci_usb_reset (ohci);
754 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700755 free_irq(hcd->irq, hcd);
756 hcd->irq = -1;
757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 ohci_mem_cleanup (ohci);
760 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800761 dma_free_coherent (hcd->self.controller,
762 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 ohci->hcca, ohci->hcca_dma);
764 ohci->hcca = NULL;
765 ohci->hcca_dma = 0;
766 }
767}
768
769/*-------------------------------------------------------------------------*/
770
771/* must not be called from interrupt context */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772static int ohci_restart (struct ohci_hcd *ohci)
773{
774 int temp;
775 int i;
776 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 spin_lock_irq(&ohci->lock);
779 disable (ohci);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200780
781 /* Recycle any "live" eds/tds (and urbs). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 if (!list_empty (&ohci->pending))
783 ohci_dbg(ohci, "abort schedule...\n");
784 list_for_each_entry (priv, &ohci->pending, pending) {
785 struct urb *urb = priv->td[0]->urb;
786 struct ed *ed = priv->ed;
787
788 switch (ed->state) {
789 case ED_OPER:
790 ed->state = ED_UNLINK;
791 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
792 ed_deschedule (ohci, ed);
793
794 ed->ed_next = ohci->ed_rm_list;
795 ed->ed_prev = NULL;
796 ohci->ed_rm_list = ed;
797 /* FALLTHROUGH */
798 case ED_UNLINK:
799 break;
800 default:
801 ohci_dbg(ohci, "bogus ed %p state %d\n",
802 ed, ed->state);
803 }
804
805 spin_lock (&urb->lock);
806 urb->status = -ESHUTDOWN;
807 spin_unlock (&urb->lock);
808 }
David Howells7d12e782006-10-05 14:55:46 +0100809 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 spin_unlock_irq(&ohci->lock);
811
812 /* paranoia, in case that didn't work: */
813
814 /* empty the interrupt branches */
815 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
816 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 /* no EDs to remove */
819 ohci->ed_rm_list = NULL;
820
David Brownelldd9048a2006-12-05 03:18:31 -0800821 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 ohci->ed_controltail = NULL;
823 ohci->ed_bulktail = NULL;
824
825 if ((temp = ohci_run (ohci)) < 0) {
826 ohci_err (ohci, "can't restart, %d\n", temp);
827 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
Alan Stern383975d2007-05-04 11:52:40 -0400829 ohci_dbg(ohci, "restart complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 return 0;
831}
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200832
833/*-------------------------------------------------------------------------*/
834
835/* NEC workaround */
836static void ohci_quirk_nec_worker(struct work_struct *work)
837{
838 struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work);
839 int status;
840
841 status = ohci_init(ohci);
842 if (status != 0) {
843 ohci_err(ohci, "Restarting NEC controller failed "
844 "in ohci_init, %d\n", status);
845 return;
846 }
847
848 status = ohci_restart(ohci);
849 if (status != 0)
850 ohci_err(ohci, "Restarting NEC controller failed "
851 "in ohci_restart, %d\n", status);
852}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854/*-------------------------------------------------------------------------*/
855
856#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
857
858MODULE_AUTHOR (DRIVER_AUTHOR);
859MODULE_DESCRIPTION (DRIVER_INFO);
860MODULE_LICENSE ("GPL");
861
862#ifdef CONFIG_PCI
863#include "ohci-pci.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100864#define PCI_DRIVER ohci_pci_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865#endif
866
867#ifdef CONFIG_SA1111
868#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100869#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870#endif
871
Ben Dooks3eb0c5f2005-07-29 12:18:03 -0700872#ifdef CONFIG_ARCH_S3C2410
873#include "ohci-s3c2410.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100874#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
Ben Dooks3eb0c5f2005-07-29 12:18:03 -0700875#endif
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877#ifdef CONFIG_ARCH_OMAP
878#include "ohci-omap.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100879#define PLATFORM_DRIVER ohci_hcd_omap_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880#endif
881
882#ifdef CONFIG_ARCH_LH7A404
883#include "ohci-lh7a404.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100884#define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885#endif
886
887#ifdef CONFIG_PXA27x
888#include "ohci-pxa27x.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100889#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890#endif
891
Lennert Buytenheka5b74742006-06-23 23:02:01 +0200892#ifdef CONFIG_ARCH_EP93XX
893#include "ohci-ep93xx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100894#define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
Lennert Buytenheka5b74742006-06-23 23:02:01 +0200895#endif
896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897#ifdef CONFIG_SOC_AU1X00
898#include "ohci-au1xxx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100899#define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900#endif
901
Vitaly Wool5151d042006-10-09 01:32:00 -0700902#ifdef CONFIG_PNX8550
903#include "ohci-pnx8550.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100904#define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
Vitaly Wool5151d042006-10-09 01:32:00 -0700905#endif
906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907#ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
908#include "ohci-ppc-soc.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100909#define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910#endif
911
Andrew Victor58a0cd72006-12-01 14:51:13 +0100912#ifdef CONFIG_ARCH_AT91
Andrew Victor39a269c2006-01-22 10:32:13 -0800913#include "ohci-at91.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100914#define PLATFORM_DRIVER ohci_hcd_at91_driver
Andrew Victor39a269c2006-01-22 10:32:13 -0800915#endif
916
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400917#ifdef CONFIG_ARCH_PNX4008
918#include "ohci-pnx4008.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100919#define PLATFORM_DRIVER usb_hcd_pnx4008_driver
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400920#endif
921
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100922
Sylvain Munaut495a6782006-12-13 21:09:55 +0100923#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
924#include "ohci-ppc-of.c"
925#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
926#endif
927
Geoff Levand6a6c9572007-01-15 20:12:10 -0800928#ifdef CONFIG_PPC_PS3
929#include "ohci-ps3.c"
930#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_sb_driver
931#endif
932
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100933#if !defined(PCI_DRIVER) && \
934 !defined(PLATFORM_DRIVER) && \
Sylvain Munaut495a6782006-12-13 21:09:55 +0100935 !defined(OF_PLATFORM_DRIVER) && \
Geoff Levand6a6c9572007-01-15 20:12:10 -0800936 !defined(SA1111_DRIVER) && \
937 !defined(PS3_SYSTEM_BUS_DRIVER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938#error "missing bus glue for ohci-hcd"
939#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100940
941static int __init ohci_hcd_mod_init(void)
942{
943 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100944
945 if (usb_disabled())
946 return -ENODEV;
947
948 printk (KERN_DEBUG "%s: " DRIVER_INFO "\n", hcd_name);
949 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
950 sizeof (struct ed), sizeof (struct td));
951
Geoff Levand6a6c9572007-01-15 20:12:10 -0800952#ifdef PS3_SYSTEM_BUS_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +0900953 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
954 retval = ps3_system_bus_driver_register(
955 &PS3_SYSTEM_BUS_DRIVER);
956 if (retval < 0)
957 goto error_ps3;
958 }
Geoff Levand6a6c9572007-01-15 20:12:10 -0800959#endif
960
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100961#ifdef PLATFORM_DRIVER
962 retval = platform_driver_register(&PLATFORM_DRIVER);
963 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800964 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100965#endif
966
Sylvain Munaut495a6782006-12-13 21:09:55 +0100967#ifdef OF_PLATFORM_DRIVER
968 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
969 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800970 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +0100971#endif
972
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100973#ifdef SA1111_DRIVER
974 retval = sa1111_driver_register(&SA1111_DRIVER);
975 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800976 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100977#endif
978
979#ifdef PCI_DRIVER
980 retval = pci_register_driver(&PCI_DRIVER);
981 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800982 goto error_pci;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100983#endif
984
985 return retval;
986
987 /* Error path */
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800988#ifdef PCI_DRIVER
989 error_pci:
Sylvain Munaut495a6782006-12-13 21:09:55 +0100990#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100991#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800992 sa1111_driver_unregister(&SA1111_DRIVER);
993 error_sa1111:
994#endif
995#ifdef OF_PLATFORM_DRIVER
996 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
997 error_of_platform:
998#endif
999#ifdef PLATFORM_DRIVER
1000 platform_driver_unregister(&PLATFORM_DRIVER);
1001 error_platform:
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001002#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001003#ifdef PS3_SYSTEM_BUS_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +09001004 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1005 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001006 error_ps3:
1007#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001008 return retval;
1009}
1010module_init(ohci_hcd_mod_init);
1011
1012static void __exit ohci_hcd_mod_exit(void)
1013{
1014#ifdef PCI_DRIVER
1015 pci_unregister_driver(&PCI_DRIVER);
1016#endif
1017#ifdef SA1111_DRIVER
1018 sa1111_driver_unregister(&SA1111_DRIVER);
1019#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001020#ifdef OF_PLATFORM_DRIVER
1021 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1022#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001023#ifdef PLATFORM_DRIVER
1024 platform_driver_unregister(&PLATFORM_DRIVER);
1025#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001026#ifdef PS3_SYSTEM_BUS_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +09001027 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1028 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001029#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001030}
1031module_exit(ohci_hcd_mod_exit);
1032