blob: f0d29eda3c6da72ede3d82a2937e1d3ccbf98de8 [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>
29#include <linux/smp_lock.h>
30#include <linux/errno.h>
31#include <linux/init.h>
32#include <linux/timer.h>
33#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/usb.h>
David Brownell3a16f7b2006-06-29 12:27:23 -070035#include <linux/usb/otg.h>
David Brownelldd9048a2006-12-05 03:18:31 -080036#include <linux/dma-mapping.h>
David Brownellf4df0e32005-04-23 12:49:16 -070037#include <linux/dmapool.h>
38#include <linux/reboot.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);
86
87#include "ohci-hub.c"
88#include "ohci-dbg.c"
89#include "ohci-mem.c"
90#include "ohci-q.c"
91
92
93/*
94 * On architectures with edge-triggered interrupts we must never return
95 * IRQ_NONE.
96 */
97#if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
98#define IRQ_NOTMINE IRQ_HANDLED
99#else
100#define IRQ_NOTMINE IRQ_NONE
101#endif
102
103
104/* Some boards misreport power switching/overcurrent */
105static int distrust_firmware = 1;
106module_param (distrust_firmware, bool, 0);
107MODULE_PARM_DESC (distrust_firmware,
108 "true to distrust firmware power/overcurrent setup");
109
110/* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
111static int no_handshake = 0;
112module_param (no_handshake, bool, 0);
113MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
114
115/*-------------------------------------------------------------------------*/
116
117/*
118 * queue up an urb for anything except the root hub
119 */
120static int ohci_urb_enqueue (
121 struct usb_hcd *hcd,
122 struct usb_host_endpoint *ep,
123 struct urb *urb,
Al Viro55016f12005-10-21 03:21:58 -0400124 gfp_t mem_flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125) {
126 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
127 struct ed *ed;
128 urb_priv_t *urb_priv;
129 unsigned int pipe = urb->pipe;
130 int i, size = 0;
131 unsigned long flags;
132 int retval = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#ifdef OHCI_VERBOSE_DEBUG
135 urb_print (urb, "SUB", usb_pipein (pipe));
136#endif
David Brownelldd9048a2006-12-05 03:18:31 -0800137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 /* every endpoint has a ed, locate and maybe (re)initialize it */
139 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval)))
140 return -ENOMEM;
141
142 /* for the private part of the URB we need the number of TDs (size) */
143 switch (ed->type) {
144 case PIPE_CONTROL:
145 /* td_submit_urb() doesn't yet handle these */
146 if (urb->transfer_buffer_length > 4096)
147 return -EMSGSIZE;
148
149 /* 1 TD for setup, 1 for ACK, plus ... */
150 size = 2;
151 /* FALLTHROUGH */
152 // case PIPE_INTERRUPT:
153 // case PIPE_BULK:
154 default:
155 /* one TD for every 4096 Bytes (can be upto 8K) */
156 size += urb->transfer_buffer_length / 4096;
157 /* ... and for any remaining bytes ... */
158 if ((urb->transfer_buffer_length % 4096) != 0)
159 size++;
160 /* ... and maybe a zero length packet to wrap it up */
161 if (size == 0)
162 size++;
163 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
164 && (urb->transfer_buffer_length
165 % usb_maxpacket (urb->dev, pipe,
166 usb_pipeout (pipe))) == 0)
167 size++;
168 break;
169 case PIPE_ISOCHRONOUS: /* number of packets from URB */
170 size = urb->number_of_packets;
171 break;
172 }
173
174 /* allocate the private part of the URB */
175 urb_priv = kmalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
176 mem_flags);
177 if (!urb_priv)
178 return -ENOMEM;
179 memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (struct td *));
180 INIT_LIST_HEAD (&urb_priv->pending);
181 urb_priv->length = size;
David Brownelldd9048a2006-12-05 03:18:31 -0800182 urb_priv->ed = ed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 /* allocate the TDs (deferring hash chain updates) */
185 for (i = 0; i < size; i++) {
186 urb_priv->td [i] = td_alloc (ohci, mem_flags);
187 if (!urb_priv->td [i]) {
188 urb_priv->length = i;
189 urb_free_priv (ohci, urb_priv);
190 return -ENOMEM;
191 }
David Brownelldd9048a2006-12-05 03:18:31 -0800192 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 spin_lock_irqsave (&ohci->lock, flags);
195
196 /* don't submit to a dead HC */
Benjamin Herrenschmidt8de98402005-11-25 09:59:46 +1100197 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
198 retval = -ENODEV;
199 goto fail;
200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 if (!HC_IS_RUNNING(hcd->state)) {
202 retval = -ENODEV;
203 goto fail;
204 }
205
206 /* in case of unlink-during-submit */
207 spin_lock (&urb->lock);
208 if (urb->status != -EINPROGRESS) {
209 spin_unlock (&urb->lock);
210 urb->hcpriv = urb_priv;
David Howells7d12e782006-10-05 14:55:46 +0100211 finish_urb (ohci, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 retval = 0;
213 goto fail;
214 }
215
216 /* schedule the ed if needed */
217 if (ed->state == ED_IDLE) {
218 retval = ed_schedule (ohci, ed);
219 if (retval < 0)
220 goto fail0;
221 if (ed->type == PIPE_ISOCHRONOUS) {
222 u16 frame = ohci_frame_no(ohci);
223
224 /* delay a few frames before the first TD */
225 frame += max_t (u16, 8, ed->interval);
226 frame &= ~(ed->interval - 1);
227 frame |= ed->branch;
228 urb->start_frame = frame;
229
230 /* yes, only URB_ISO_ASAP is supported, and
231 * urb->start_frame is never used as input.
232 */
233 }
234 } else if (ed->type == PIPE_ISOCHRONOUS)
235 urb->start_frame = ed->last_iso + ed->interval;
236
237 /* fill the TDs and link them to the ed; and
238 * enable that part of the schedule, if needed
239 * and update count of queued periodic urbs
240 */
241 urb->hcpriv = urb_priv;
242 td_submit_urb (ohci, urb);
243
244fail0:
245 spin_unlock (&urb->lock);
246fail:
247 if (retval)
248 urb_free_priv (ohci, urb_priv);
249 spin_unlock_irqrestore (&ohci->lock, flags);
250 return retval;
251}
252
253/*
254 * decouple the URB from the HC queues (TDs, urb_priv); it's
255 * already marked using urb->status. reporting is always done
256 * asynchronously, and we might be dealing with an urb that's
257 * partially transferred, or an ED with other urbs being unlinked.
258 */
259static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
260{
261 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
262 unsigned long flags;
David Brownelldd9048a2006-12-05 03:18:31 -0800263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#ifdef OHCI_VERBOSE_DEBUG
265 urb_print (urb, "UNLINK", 1);
David Brownelldd9048a2006-12-05 03:18:31 -0800266#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 spin_lock_irqsave (&ohci->lock, flags);
David Brownelldd9048a2006-12-05 03:18:31 -0800269 if (HC_IS_RUNNING(hcd->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 urb_priv_t *urb_priv;
271
272 /* Unless an IRQ completed the unlink while it was being
273 * handed to us, flag it for unlink and giveback, and force
274 * some upcoming INTR_SF to call finish_unlinks()
275 */
276 urb_priv = urb->hcpriv;
277 if (urb_priv) {
278 if (urb_priv->ed->state == ED_OPER)
279 start_ed_unlink (ohci, urb_priv->ed);
280 }
281 } else {
282 /*
283 * with HC dead, we won't respect hc queue pointers
284 * any more ... just clean up every urb's memory.
285 */
286 if (urb->hcpriv)
David Howells7d12e782006-10-05 14:55:46 +0100287 finish_urb (ohci, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
289 spin_unlock_irqrestore (&ohci->lock, flags);
290 return 0;
291}
292
293/*-------------------------------------------------------------------------*/
294
295/* frees config/altsetting state for endpoints,
296 * including ED memory, dummy TD, and bulk/intr data toggle
297 */
298
299static void
300ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
301{
302 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
303 unsigned long flags;
304 struct ed *ed = ep->hcpriv;
305 unsigned limit = 1000;
306
307 /* ASSERT: any requests/urbs are being unlinked */
308 /* ASSERT: nobody can be submitting urbs for this any more */
309
310 if (!ed)
311 return;
312
313rescan:
314 spin_lock_irqsave (&ohci->lock, flags);
315
316 if (!HC_IS_RUNNING (hcd->state)) {
317sanitize:
318 ed->state = ED_IDLE;
David Howells7d12e782006-10-05 14:55:46 +0100319 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
321
322 switch (ed->state) {
323 case ED_UNLINK: /* wait for hw to finish? */
324 /* major IRQ delivery trouble loses INTR_SF too... */
325 if (limit-- == 0) {
326 ohci_warn (ohci, "IRQ INTR_SF lossage\n");
327 goto sanitize;
328 }
329 spin_unlock_irqrestore (&ohci->lock, flags);
Nishanth Aravamudan22c43862005-08-15 11:30:11 -0700330 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 goto rescan;
332 case ED_IDLE: /* fully unlinked */
333 if (list_empty (&ed->td_list)) {
334 td_free (ohci, ed->dummy);
335 ed_free (ohci, ed);
336 break;
337 }
338 /* else FALL THROUGH */
339 default:
340 /* caller was supposed to have unlinked any requests;
341 * that's not our job. can't recover; must leak ed.
342 */
343 ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
344 ed, ep->desc.bEndpointAddress, ed->state,
345 list_empty (&ed->td_list) ? "" : " (has tds)");
346 td_free (ohci, ed->dummy);
347 break;
348 }
349 ep->hcpriv = NULL;
350 spin_unlock_irqrestore (&ohci->lock, flags);
351 return;
352}
353
354static int ohci_get_frame (struct usb_hcd *hcd)
355{
356 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
357
358 return ohci_frame_no(ohci);
359}
360
361static void ohci_usb_reset (struct ohci_hcd *ohci)
362{
363 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
364 ohci->hc_control &= OHCI_CTRL_RWC;
365 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
366}
367
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700368/* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
David Brownellf4df0e32005-04-23 12:49:16 -0700369 * other cases where the next software may expect clean state from the
370 * "firmware". this is bus-neutral, unlike shutdown() methods.
371 */
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700372static void
373ohci_shutdown (struct usb_hcd *hcd)
David Brownellf4df0e32005-04-23 12:49:16 -0700374{
375 struct ohci_hcd *ohci;
376
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700377 ohci = hcd_to_ohci (hcd);
David Brownellf4df0e32005-04-23 12:49:16 -0700378 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
379 ohci_usb_reset (ohci);
380 /* flush the writes */
381 (void) ohci_readl (ohci, &ohci->regs->control);
David Brownellf4df0e32005-04-23 12:49:16 -0700382}
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384/*-------------------------------------------------------------------------*
385 * HC functions
386 *-------------------------------------------------------------------------*/
387
388/* init memory, and kick BIOS/SMM off */
389
390static int ohci_init (struct ohci_hcd *ohci)
391{
392 int ret;
David Brownell6a9062f2006-01-23 15:28:07 -0800393 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 disable (ohci);
David Brownell6a9062f2006-01-23 15:28:07 -0800396 ohci->regs = hcd->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
David Brownell6a9062f2006-01-23 15:28:07 -0800398 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
399 * was never needed for most non-PCI systems ... remove the code?
400 */
401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402#ifndef IR_DISABLE
403 /* SMM owns the HC? not for long! */
404 if (!no_handshake && ohci_readl (ohci,
405 &ohci->regs->control) & OHCI_CTRL_IR) {
406 u32 temp;
407
408 ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
409
410 /* this timeout is arbitrary. we make it long, so systems
411 * depending on usb keyboards may be usable even if the
412 * BIOS/SMM code seems pretty broken.
413 */
414 temp = 500; /* arbitrary: five seconds */
415
416 ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
417 ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
418 while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
419 msleep (10);
420 if (--temp == 0) {
421 ohci_err (ohci, "USB HC takeover failed!"
422 " (BIOS/SMM bug)\n");
423 return -EBUSY;
424 }
425 }
426 ohci_usb_reset (ohci);
427 }
428#endif
429
430 /* Disable HC interrupts */
431 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
David Brownell6a9062f2006-01-23 15:28:07 -0800432
433 /* flush the writes, and save key bits like RWC */
434 if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
435 ohci->hc_control |= OHCI_CTRL_RWC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
David Brownellfdd13b32005-08-31 11:52:57 -0700437 /* Read the number of ports unless overridden */
438 if (ohci->num_ports == 0)
439 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (ohci->hcca)
442 return 0;
443
David Brownell6a9062f2006-01-23 15:28:07 -0800444 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
446 if (!ohci->hcca)
447 return -ENOMEM;
448
449 if ((ret = ohci_mem_init (ohci)) < 0)
David Brownell6a9062f2006-01-23 15:28:07 -0800450 ohci_stop (hcd);
451 else {
David Brownell6a9062f2006-01-23 15:28:07 -0800452 create_debug_files (ohci);
453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
457
458/*-------------------------------------------------------------------------*/
459
460/* Start an OHCI controller, set the BUS operational
461 * resets USB and controller
David Brownelldd9048a2006-12-05 03:18:31 -0800462 * enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 */
464static int ohci_run (struct ohci_hcd *ohci)
465{
David Brownelldd9048a2006-12-05 03:18:31 -0800466 u32 mask, temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 int first = ohci->fminterval == 0;
David Brownell6a9062f2006-01-23 15:28:07 -0800468 struct usb_hcd *hcd = ohci_to_hcd(ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 disable (ohci);
471
472 /* boot firmware should have set this up (5.1.1.3.1) */
473 if (first) {
474
475 temp = ohci_readl (ohci, &ohci->regs->fminterval);
476 ohci->fminterval = temp & 0x3fff;
477 if (ohci->fminterval != FI)
478 ohci_dbg (ohci, "fminterval delta %d\n",
479 ohci->fminterval - FI);
480 ohci->fminterval |= FSMP (ohci->fminterval) << 16;
481 /* also: power/overcurrent flags in roothub.a */
482 }
483
David Brownelldd9048a2006-12-05 03:18:31 -0800484 /* Reset USB nearly "by the book". RemoteWakeupConnected was
David Brownell6a9062f2006-01-23 15:28:07 -0800485 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
486 * or if bus glue did the same (e.g. for PCI add-in cards with
487 * PCI PM support).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 ohci_dbg (ohci, "resetting from state '%s', control = 0x%x\n",
490 hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS),
David Brownell6a9062f2006-01-23 15:28:07 -0800491 ohci_readl (ohci, &ohci->regs->control));
492 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0
493 && !device_may_wakeup(hcd->self.controller))
494 device_init_wakeup(hcd->self.controller, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
497 case OHCI_USB_OPER:
498 temp = 0;
499 break;
500 case OHCI_USB_SUSPEND:
501 case OHCI_USB_RESUME:
502 ohci->hc_control &= OHCI_CTRL_RWC;
503 ohci->hc_control |= OHCI_USB_RESUME;
504 temp = 10 /* msec wait */;
505 break;
506 // case OHCI_USB_RESET:
507 default:
508 ohci->hc_control &= OHCI_CTRL_RWC;
509 ohci->hc_control |= OHCI_USB_RESET;
510 temp = 50 /* msec wait */;
511 break;
512 }
513 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
514 // flush the writes
515 (void) ohci_readl (ohci, &ohci->regs->control);
516 msleep(temp);
517 temp = roothub_a (ohci);
518 if (!(temp & RH_A_NPS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 /* power down each port */
David Brownellfdd13b32005-08-31 11:52:57 -0700520 for (temp = 0; temp < ohci->num_ports; temp++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 ohci_writel (ohci, RH_PS_LSDA,
522 &ohci->regs->roothub.portstatus [temp]);
523 }
524 // flush those writes
525 (void) ohci_readl (ohci, &ohci->regs->control);
526 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
527
528 /* 2msec timelimit here means no irqs/preempt */
529 spin_lock_irq (&ohci->lock);
530
531retry:
532 /* HC Reset requires max 10 us delay */
533 ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
534 temp = 30; /* ... allow extra time */
535 while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
536 if (--temp == 0) {
537 spin_unlock_irq (&ohci->lock);
538 ohci_err (ohci, "USB HC reset timed out!\n");
539 return -1;
540 }
541 udelay (1);
542 }
543
544 /* now we're in the SUSPEND state ... must go OPERATIONAL
545 * within 2msec else HC enters RESUME
546 *
547 * ... but some hardware won't init fmInterval "by the book"
548 * (SiS, OPTi ...), so reset again instead. SiS doesn't need
549 * this if we write fmInterval after we're OPERATIONAL.
550 * Unclear about ALi, ServerWorks, and others ... this could
551 * easily be a longstanding bug in chip init on Linux.
552 */
553 if (ohci->flags & OHCI_QUIRK_INITRESET) {
554 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
555 // flush those writes
556 (void) ohci_readl (ohci, &ohci->regs->control);
557 }
558
559 /* Tell the controller where the control and bulk lists are
560 * The lists are empty now. */
561 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
562 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
563
564 /* a reset clears this */
565 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
566
567 periodic_reinit (ohci);
568
569 /* some OHCI implementations are finicky about how they init.
570 * bogus values here mean not even enumeration could work.
571 */
572 if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
573 || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
574 if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
575 ohci->flags |= OHCI_QUIRK_INITRESET;
576 ohci_dbg (ohci, "enabling initreset quirk\n");
577 goto retry;
578 }
579 spin_unlock_irq (&ohci->lock);
580 ohci_err (ohci, "init err (%08x %04x)\n",
581 ohci_readl (ohci, &ohci->regs->fminterval),
582 ohci_readl (ohci, &ohci->regs->periodicstart));
583 return -EOVERFLOW;
584 }
585
David Brownelld4139842006-08-04 11:31:55 -0700586 /* use rhsc irqs after khubd is fully initialized */
587 hcd->poll_rh = 1;
588 hcd->uses_new_polling = 1;
589
590 /* start controller operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 ohci->hc_control &= OHCI_CTRL_RWC;
David Brownelld4139842006-08-04 11:31:55 -0700592 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
593 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
David Brownell6a9062f2006-01-23 15:28:07 -0800594 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 /* wake on ConnectStatusChange, matching external hubs */
597 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
598
599 /* Choose the interrupts we care about now, others later on demand */
600 mask = OHCI_INTR_INIT;
David Brownelld4139842006-08-04 11:31:55 -0700601 ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 ohci_writel (ohci, mask, &ohci->regs->intrenable);
603
604 /* handle root hub init quirks ... */
605 temp = roothub_a (ohci);
606 temp &= ~(RH_A_PSM | RH_A_OCPM);
607 if (ohci->flags & OHCI_QUIRK_SUPERIO) {
608 /* NSC 87560 and maybe others */
609 temp |= RH_A_NOCP;
610 temp &= ~(RH_A_POTPGT | RH_A_NPS);
611 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
612 } else if ((ohci->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
613 /* hub power always on; required for AMD-756 and some
614 * Mac platforms. ganged overcurrent reporting, if any.
615 */
616 temp |= RH_A_NPS;
617 ohci_writel (ohci, temp, &ohci->regs->roothub.a);
618 }
619 ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
620 ohci_writel (ohci, (temp & RH_A_NPS) ? 0 : RH_B_PPCM,
621 &ohci->regs->roothub.b);
622 // flush those writes
623 (void) ohci_readl (ohci, &ohci->regs->control);
624
David Brownelld4139842006-08-04 11:31:55 -0700625 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 spin_unlock_irq (&ohci->lock);
627
628 // POTPGT delay is bits 24-31, in 2 ms units.
629 mdelay ((temp >> 23) & 0x1fe);
David Brownell6a9062f2006-01-23 15:28:07 -0800630 hcd->state = HC_STATE_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 ohci_dump (ohci, 1);
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 return 0;
635}
636
637/*-------------------------------------------------------------------------*/
638
639/* an interrupt happens */
640
David Howells7d12e782006-10-05 14:55:46 +0100641static irqreturn_t ohci_irq (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642{
643 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
644 struct ohci_regs __iomem *regs = ohci->regs;
645 int ints;
646
647 /* we can eliminate a (slow) ohci_readl()
648 if _only_ WDH caused this irq */
649 if ((ohci->hcca->done_head != 0)
650 && ! (hc32_to_cpup (ohci, &ohci->hcca->done_head)
651 & 0x01)) {
652 ints = OHCI_INTR_WDH;
653
654 /* cardbus/... hardware gone before remove() */
655 } else if ((ints = ohci_readl (ohci, &regs->intrstatus)) == ~(u32)0) {
656 disable (ohci);
657 ohci_dbg (ohci, "device removed!\n");
658 return IRQ_HANDLED;
659
660 /* interrupt for some other device? */
661 } else if ((ints &= ohci_readl (ohci, &regs->intrenable)) == 0) {
662 return IRQ_NOTMINE;
David Brownelld4139842006-08-04 11:31:55 -0700663 }
664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 if (ints & OHCI_INTR_UE) {
666 disable (ohci);
667 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
668 // e.g. due to PCI Master/Target Abort
669
670 ohci_dump (ohci, 1);
671 ohci_usb_reset (ohci);
672 }
673
Alan Stern583cead2006-10-24 12:04:22 -0400674 if (ints & OHCI_INTR_RHSC) {
675 ohci_vdbg(ohci, "rhsc\n");
676 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
677 ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
678 &regs->intrstatus);
Alan Stern052ac012006-10-27 10:33:11 -0400679
680 /* NOTE: Vendors didn't always make the same implementation
681 * choices for RHSC. Many followed the spec; RHSC triggers
682 * on an edge, like setting and maybe clearing a port status
683 * change bit. With others it's level-triggered, active
684 * until khubd clears all the port status change bits. We'll
685 * always disable it here and rely on polling until khubd
686 * re-enables it.
687 */
688 ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
Alan Stern583cead2006-10-24 12:04:22 -0400689 usb_hcd_poll_rh_status(hcd);
690 }
691
692 /* For connect and disconnect events, we expect the controller
693 * to turn on RHSC along with RD. But for remote wakeup events
694 * this might not happen.
695 */
696 else if (ints & OHCI_INTR_RD) {
697 ohci_vdbg(ohci, "resume detect\n");
698 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
Alan Stern8d1a2432006-09-26 14:46:16 -0400699 hcd->poll_rh = 1;
700 if (ohci->autostop) {
701 spin_lock (&ohci->lock);
702 ohci_rh_resume (ohci);
703 spin_unlock (&ohci->lock);
704 } else
David Brownellf197b2c2005-09-22 22:42:53 -0700705 usb_hcd_resume_root_hub(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 }
707
708 if (ints & OHCI_INTR_WDH) {
709 if (HC_IS_RUNNING(hcd->state))
Alan Stern8d1a2432006-09-26 14:46:16 -0400710 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 spin_lock (&ohci->lock);
David Howells7d12e782006-10-05 14:55:46 +0100712 dl_done_list (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 spin_unlock (&ohci->lock);
714 if (HC_IS_RUNNING(hcd->state))
David Brownelldd9048a2006-12-05 03:18:31 -0800715 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
David Brownelldd9048a2006-12-05 03:18:31 -0800717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 /* could track INTR_SO to reduce available PCI/... bandwidth */
719
720 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
721 * when there's still unlinking to be done (next frame).
722 */
723 spin_lock (&ohci->lock);
724 if (ohci->ed_rm_list)
David Howells7d12e782006-10-05 14:55:46 +0100725 finish_unlinks (ohci, ohci_frame_no(ohci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
727 && HC_IS_RUNNING(hcd->state))
David Brownelldd9048a2006-12-05 03:18:31 -0800728 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 spin_unlock (&ohci->lock);
730
731 if (HC_IS_RUNNING(hcd->state)) {
732 ohci_writel (ohci, ints, &regs->intrstatus);
David Brownelldd9048a2006-12-05 03:18:31 -0800733 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 // flush those writes
735 (void) ohci_readl (ohci, &ohci->regs->control);
736 }
737
738 return IRQ_HANDLED;
739}
740
741/*-------------------------------------------------------------------------*/
742
743static void ohci_stop (struct usb_hcd *hcd)
David Brownelldd9048a2006-12-05 03:18:31 -0800744{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
746
747 ohci_dbg (ohci, "stop %s controller (state 0x%02x)\n",
748 hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS),
749 hcd->state);
750 ohci_dump (ohci, 1);
751
752 flush_scheduled_work();
753
754 ohci_usb_reset (ohci);
755 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
Pete Zaitcev71795c12006-09-18 22:57:22 -0700756 free_irq(hcd->irq, hcd);
757 hcd->irq = -1;
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 remove_debug_files (ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 ohci_mem_cleanup (ohci);
761 if (ohci->hcca) {
David Brownelldd9048a2006-12-05 03:18:31 -0800762 dma_free_coherent (hcd->self.controller,
763 sizeof *ohci->hcca,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 ohci->hcca, ohci->hcca_dma);
765 ohci->hcca = NULL;
766 ohci->hcca_dma = 0;
767 }
768}
769
770/*-------------------------------------------------------------------------*/
771
772/* must not be called from interrupt context */
773
David Brownell8ad7fe12005-09-13 19:59:11 -0700774#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776static int ohci_restart (struct ohci_hcd *ohci)
777{
778 int temp;
779 int i;
780 struct urb_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
782 /* mark any devices gone, so they do nothing till khubd disconnects.
783 * recycle any "live" eds/tds (and urbs) right away.
784 * later, khubd disconnect processing will recycle the other state,
785 * (either as disconnect/reconnect, or maybe someday as a reset).
David Brownelldd9048a2006-12-05 03:18:31 -0800786 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 spin_lock_irq(&ohci->lock);
788 disable (ohci);
Alan Stern1c50c312005-11-14 11:45:38 -0500789 usb_root_hub_lost_power(ohci_to_hcd(ohci)->self.root_hub);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 if (!list_empty (&ohci->pending))
791 ohci_dbg(ohci, "abort schedule...\n");
792 list_for_each_entry (priv, &ohci->pending, pending) {
793 struct urb *urb = priv->td[0]->urb;
794 struct ed *ed = priv->ed;
795
796 switch (ed->state) {
797 case ED_OPER:
798 ed->state = ED_UNLINK;
799 ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
800 ed_deschedule (ohci, ed);
801
802 ed->ed_next = ohci->ed_rm_list;
803 ed->ed_prev = NULL;
804 ohci->ed_rm_list = ed;
805 /* FALLTHROUGH */
806 case ED_UNLINK:
807 break;
808 default:
809 ohci_dbg(ohci, "bogus ed %p state %d\n",
810 ed, ed->state);
811 }
812
813 spin_lock (&urb->lock);
814 urb->status = -ESHUTDOWN;
815 spin_unlock (&urb->lock);
816 }
David Howells7d12e782006-10-05 14:55:46 +0100817 finish_unlinks (ohci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 spin_unlock_irq(&ohci->lock);
819
820 /* paranoia, in case that didn't work: */
821
822 /* empty the interrupt branches */
823 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
824 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
David Brownelldd9048a2006-12-05 03:18:31 -0800825
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 /* no EDs to remove */
827 ohci->ed_rm_list = NULL;
828
David Brownelldd9048a2006-12-05 03:18:31 -0800829 /* empty control and bulk lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 ohci->ed_controltail = NULL;
831 ohci->ed_bulktail = NULL;
832
833 if ((temp = ohci_run (ohci)) < 0) {
834 ohci_err (ohci, "can't restart, %d\n", temp);
835 return temp;
836 } else {
837 /* here we "know" root ports should always stay powered,
838 * and that if we try to turn them back on the root hub
839 * will respond to CSC processing.
840 */
David Brownellfdd13b32005-08-31 11:52:57 -0700841 i = ohci->num_ports;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 while (i--)
843 ohci_writel (ohci, RH_PS_PSS,
David Brownell839ab1d2006-04-26 14:39:11 -0700844 &ohci->regs->roothub.portstatus [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 ohci_dbg (ohci, "restart complete\n");
846 }
847 return 0;
848}
849#endif
850
851/*-------------------------------------------------------------------------*/
852
853#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
854
855MODULE_AUTHOR (DRIVER_AUTHOR);
856MODULE_DESCRIPTION (DRIVER_INFO);
857MODULE_LICENSE ("GPL");
858
859#ifdef CONFIG_PCI
860#include "ohci-pci.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100861#define PCI_DRIVER ohci_pci_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862#endif
863
864#ifdef CONFIG_SA1111
865#include "ohci-sa1111.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100866#define SA1111_DRIVER ohci_hcd_sa1111_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867#endif
868
Ben Dooks3eb0c5f2005-07-29 12:18:03 -0700869#ifdef CONFIG_ARCH_S3C2410
870#include "ohci-s3c2410.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100871#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
Ben Dooks3eb0c5f2005-07-29 12:18:03 -0700872#endif
873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874#ifdef CONFIG_ARCH_OMAP
875#include "ohci-omap.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100876#define PLATFORM_DRIVER ohci_hcd_omap_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877#endif
878
879#ifdef CONFIG_ARCH_LH7A404
880#include "ohci-lh7a404.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100881#define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882#endif
883
884#ifdef CONFIG_PXA27x
885#include "ohci-pxa27x.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100886#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887#endif
888
Lennert Buytenheka5b74742006-06-23 23:02:01 +0200889#ifdef CONFIG_ARCH_EP93XX
890#include "ohci-ep93xx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100891#define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
Lennert Buytenheka5b74742006-06-23 23:02:01 +0200892#endif
893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894#ifdef CONFIG_SOC_AU1X00
895#include "ohci-au1xxx.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100896#define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897#endif
898
Vitaly Wool5151d042006-10-09 01:32:00 -0700899#ifdef CONFIG_PNX8550
900#include "ohci-pnx8550.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100901#define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
Vitaly Wool5151d042006-10-09 01:32:00 -0700902#endif
903
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904#ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
905#include "ohci-ppc-soc.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100906#define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907#endif
908
Andrew Victor58a0cd72006-12-01 14:51:13 +0100909#ifdef CONFIG_ARCH_AT91
Andrew Victor39a269c2006-01-22 10:32:13 -0800910#include "ohci-at91.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100911#define PLATFORM_DRIVER ohci_hcd_at91_driver
Andrew Victor39a269c2006-01-22 10:32:13 -0800912#endif
913
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400914#ifdef CONFIG_ARCH_PNX4008
915#include "ohci-pnx4008.c"
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100916#define PLATFORM_DRIVER usb_hcd_pnx4008_driver
Vitaly Wool60bbfc82006-06-29 18:28:18 +0400917#endif
918
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100919
Sylvain Munaut495a6782006-12-13 21:09:55 +0100920#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
921#include "ohci-ppc-of.c"
922#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
923#endif
924
Geoff Levand6a6c9572007-01-15 20:12:10 -0800925#ifdef CONFIG_PPC_PS3
926#include "ohci-ps3.c"
927#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_sb_driver
928#endif
929
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100930#if !defined(PCI_DRIVER) && \
931 !defined(PLATFORM_DRIVER) && \
Sylvain Munaut495a6782006-12-13 21:09:55 +0100932 !defined(OF_PLATFORM_DRIVER) && \
Geoff Levand6a6c9572007-01-15 20:12:10 -0800933 !defined(SA1111_DRIVER) && \
934 !defined(PS3_SYSTEM_BUS_DRIVER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935#error "missing bus glue for ohci-hcd"
936#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100937
938static int __init ohci_hcd_mod_init(void)
939{
940 int retval = 0;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100941
942 if (usb_disabled())
943 return -ENODEV;
944
945 printk (KERN_DEBUG "%s: " DRIVER_INFO "\n", hcd_name);
946 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
947 sizeof (struct ed), sizeof (struct td));
948
Geoff Levand6a6c9572007-01-15 20:12:10 -0800949#ifdef PS3_SYSTEM_BUS_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +0900950 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
951 retval = ps3_system_bus_driver_register(
952 &PS3_SYSTEM_BUS_DRIVER);
953 if (retval < 0)
954 goto error_ps3;
955 }
Geoff Levand6a6c9572007-01-15 20:12:10 -0800956#endif
957
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100958#ifdef PLATFORM_DRIVER
959 retval = platform_driver_register(&PLATFORM_DRIVER);
960 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800961 goto error_platform;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100962#endif
963
Sylvain Munaut495a6782006-12-13 21:09:55 +0100964#ifdef OF_PLATFORM_DRIVER
965 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
966 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800967 goto error_of_platform;
Sylvain Munaut495a6782006-12-13 21:09:55 +0100968#endif
969
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100970#ifdef SA1111_DRIVER
971 retval = sa1111_driver_register(&SA1111_DRIVER);
972 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800973 goto error_sa1111;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100974#endif
975
976#ifdef PCI_DRIVER
977 retval = pci_register_driver(&PCI_DRIVER);
978 if (retval < 0)
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800979 goto error_pci;
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100980#endif
981
982 return retval;
983
984 /* Error path */
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800985#ifdef PCI_DRIVER
986 error_pci:
Sylvain Munaut495a6782006-12-13 21:09:55 +0100987#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100988#ifdef SA1111_DRIVER
Benjamin Herrenschmidtde447432007-01-15 20:12:06 -0800989 sa1111_driver_unregister(&SA1111_DRIVER);
990 error_sa1111:
991#endif
992#ifdef OF_PLATFORM_DRIVER
993 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
994 error_of_platform:
995#endif
996#ifdef PLATFORM_DRIVER
997 platform_driver_unregister(&PLATFORM_DRIVER);
998 error_platform:
Sylvain Munaut5e16fab2006-12-13 21:09:54 +0100999#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001000#ifdef PS3_SYSTEM_BUS_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +09001001 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1002 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001003 error_ps3:
1004#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001005 return retval;
1006}
1007module_init(ohci_hcd_mod_init);
1008
1009static void __exit ohci_hcd_mod_exit(void)
1010{
1011#ifdef PCI_DRIVER
1012 pci_unregister_driver(&PCI_DRIVER);
1013#endif
1014#ifdef SA1111_DRIVER
1015 sa1111_driver_unregister(&SA1111_DRIVER);
1016#endif
Sylvain Munaut495a6782006-12-13 21:09:55 +01001017#ifdef OF_PLATFORM_DRIVER
1018 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1019#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001020#ifdef PLATFORM_DRIVER
1021 platform_driver_unregister(&PLATFORM_DRIVER);
1022#endif
Geoff Levand6a6c9572007-01-15 20:12:10 -08001023#ifdef PS3_SYSTEM_BUS_DRIVER
Ishizaki Kou48fda452007-02-14 16:04:17 +09001024 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1025 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
Geoff Levand6a6c9572007-01-15 20:12:10 -08001026#endif
Sylvain Munaut5e16fab2006-12-13 21:09:54 +01001027}
1028module_exit(ohci_hcd_mod_exit);
1029