Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * [ 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 Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 11 | * |
| 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * This file is licenced under the GPL. |
| 19 | */ |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/errno.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/timer.h> |
| 32 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/usb.h> |
David Brownell | 3a16f7b | 2006-06-29 12:27:23 -0700 | [diff] [blame] | 34 | #include <linux/usb/otg.h> |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 35 | #include <linux/dma-mapping.h> |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 36 | #include <linux/dmapool.h> |
| 37 | #include <linux/reboot.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include <asm/io.h> |
| 40 | #include <asm/irq.h> |
| 41 | #include <asm/system.h> |
| 42 | #include <asm/unaligned.h> |
| 43 | #include <asm/byteorder.h> |
Ishizaki Kou | 48fda45 | 2007-02-14 16:04:17 +0900 | [diff] [blame] | 44 | #ifdef CONFIG_PPC_PS3 |
| 45 | #include <asm/firmware.h> |
| 46 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 48 | #include "../core/hcd.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 50 | #define DRIVER_VERSION "2006 August 04" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell" |
| 52 | #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver" |
| 53 | |
| 54 | /*-------------------------------------------------------------------------*/ |
| 55 | |
Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 56 | #undef OHCI_VERBOSE_DEBUG /* not always helpful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | /* For initializing controller (mask in an HCFS mode too) */ |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 59 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define OHCI_INTR_INIT \ |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 61 | (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \ |
| 62 | | OHCI_INTR_RD | OHCI_INTR_WDH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #ifdef __hppa__ |
| 65 | /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */ |
| 66 | #define IR_DISABLE |
| 67 | #endif |
| 68 | |
| 69 | #ifdef CONFIG_ARCH_OMAP |
| 70 | /* OMAP doesn't support IR (no SMM; not needed) */ |
| 71 | #define IR_DISABLE |
| 72 | #endif |
| 73 | |
| 74 | /*-------------------------------------------------------------------------*/ |
| 75 | |
| 76 | static const char hcd_name [] = "ohci_hcd"; |
| 77 | |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 78 | #define STATECHANGE_DELAY msecs_to_jiffies(300) |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #include "ohci.h" |
| 81 | |
| 82 | static void ohci_dump (struct ohci_hcd *ohci, int verbose); |
| 83 | static int ohci_init (struct ohci_hcd *ohci); |
| 84 | static void ohci_stop (struct usb_hcd *hcd); |
| 85 | |
| 86 | #include "ohci-hub.c" |
| 87 | #include "ohci-dbg.c" |
| 88 | #include "ohci-mem.c" |
| 89 | #include "ohci-q.c" |
| 90 | |
| 91 | |
| 92 | /* |
| 93 | * On architectures with edge-triggered interrupts we must never return |
| 94 | * IRQ_NONE. |
| 95 | */ |
| 96 | #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */ |
| 97 | #define IRQ_NOTMINE IRQ_HANDLED |
| 98 | #else |
| 99 | #define IRQ_NOTMINE IRQ_NONE |
| 100 | #endif |
| 101 | |
| 102 | |
| 103 | /* Some boards misreport power switching/overcurrent */ |
| 104 | static int distrust_firmware = 1; |
| 105 | module_param (distrust_firmware, bool, 0); |
| 106 | MODULE_PARM_DESC (distrust_firmware, |
| 107 | "true to distrust firmware power/overcurrent setup"); |
| 108 | |
| 109 | /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */ |
| 110 | static int no_handshake = 0; |
| 111 | module_param (no_handshake, bool, 0); |
| 112 | MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake"); |
| 113 | |
| 114 | /*-------------------------------------------------------------------------*/ |
| 115 | |
| 116 | /* |
| 117 | * queue up an urb for anything except the root hub |
| 118 | */ |
| 119 | static int ohci_urb_enqueue ( |
| 120 | struct usb_hcd *hcd, |
| 121 | struct usb_host_endpoint *ep, |
| 122 | struct urb *urb, |
Al Viro | 55016f1 | 2005-10-21 03:21:58 -0400 | [diff] [blame] | 123 | gfp_t mem_flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | ) { |
| 125 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 126 | struct ed *ed; |
| 127 | urb_priv_t *urb_priv; |
| 128 | unsigned int pipe = urb->pipe; |
| 129 | int i, size = 0; |
| 130 | unsigned long flags; |
| 131 | int retval = 0; |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #ifdef OHCI_VERBOSE_DEBUG |
| 134 | urb_print (urb, "SUB", usb_pipein (pipe)); |
| 135 | #endif |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* every endpoint has a ed, locate and maybe (re)initialize it */ |
| 138 | if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval))) |
| 139 | return -ENOMEM; |
| 140 | |
| 141 | /* for the private part of the URB we need the number of TDs (size) */ |
| 142 | switch (ed->type) { |
| 143 | case PIPE_CONTROL: |
| 144 | /* td_submit_urb() doesn't yet handle these */ |
| 145 | if (urb->transfer_buffer_length > 4096) |
| 146 | return -EMSGSIZE; |
| 147 | |
| 148 | /* 1 TD for setup, 1 for ACK, plus ... */ |
| 149 | size = 2; |
| 150 | /* FALLTHROUGH */ |
| 151 | // case PIPE_INTERRUPT: |
| 152 | // case PIPE_BULK: |
| 153 | default: |
| 154 | /* one TD for every 4096 Bytes (can be upto 8K) */ |
| 155 | size += urb->transfer_buffer_length / 4096; |
| 156 | /* ... and for any remaining bytes ... */ |
| 157 | if ((urb->transfer_buffer_length % 4096) != 0) |
| 158 | size++; |
| 159 | /* ... and maybe a zero length packet to wrap it up */ |
| 160 | if (size == 0) |
| 161 | size++; |
| 162 | else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0 |
| 163 | && (urb->transfer_buffer_length |
| 164 | % usb_maxpacket (urb->dev, pipe, |
| 165 | usb_pipeout (pipe))) == 0) |
| 166 | size++; |
| 167 | break; |
| 168 | case PIPE_ISOCHRONOUS: /* number of packets from URB */ |
| 169 | size = urb->number_of_packets; |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | /* allocate the private part of the URB */ |
| 174 | urb_priv = kmalloc (sizeof (urb_priv_t) + size * sizeof (struct td *), |
| 175 | mem_flags); |
| 176 | if (!urb_priv) |
| 177 | return -ENOMEM; |
| 178 | memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (struct td *)); |
| 179 | INIT_LIST_HEAD (&urb_priv->pending); |
| 180 | urb_priv->length = size; |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 181 | urb_priv->ed = ed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | /* allocate the TDs (deferring hash chain updates) */ |
| 184 | for (i = 0; i < size; i++) { |
| 185 | urb_priv->td [i] = td_alloc (ohci, mem_flags); |
| 186 | if (!urb_priv->td [i]) { |
| 187 | urb_priv->length = i; |
| 188 | urb_free_priv (ohci, urb_priv); |
| 189 | return -ENOMEM; |
| 190 | } |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | spin_lock_irqsave (&ohci->lock, flags); |
| 194 | |
| 195 | /* don't submit to a dead HC */ |
Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 196 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { |
| 197 | retval = -ENODEV; |
| 198 | goto fail; |
| 199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | if (!HC_IS_RUNNING(hcd->state)) { |
| 201 | retval = -ENODEV; |
| 202 | goto fail; |
| 203 | } |
| 204 | |
| 205 | /* in case of unlink-during-submit */ |
| 206 | spin_lock (&urb->lock); |
| 207 | if (urb->status != -EINPROGRESS) { |
| 208 | spin_unlock (&urb->lock); |
| 209 | urb->hcpriv = urb_priv; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 210 | finish_urb (ohci, urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | retval = 0; |
| 212 | goto fail; |
| 213 | } |
| 214 | |
| 215 | /* schedule the ed if needed */ |
| 216 | if (ed->state == ED_IDLE) { |
| 217 | retval = ed_schedule (ohci, ed); |
| 218 | if (retval < 0) |
| 219 | goto fail0; |
| 220 | 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; |
| 228 | |
| 229 | /* yes, only URB_ISO_ASAP is supported, and |
| 230 | * urb->start_frame is never used as input. |
| 231 | */ |
| 232 | } |
| 233 | } else if (ed->type == PIPE_ISOCHRONOUS) |
| 234 | urb->start_frame = ed->last_iso + ed->interval; |
| 235 | |
| 236 | /* fill the TDs and link them to the ed; and |
| 237 | * enable that part of the schedule, if needed |
| 238 | * and update count of queued periodic urbs |
| 239 | */ |
| 240 | urb->hcpriv = urb_priv; |
| 241 | td_submit_urb (ohci, urb); |
| 242 | |
| 243 | fail0: |
| 244 | spin_unlock (&urb->lock); |
| 245 | fail: |
| 246 | if (retval) |
| 247 | urb_free_priv (ohci, urb_priv); |
| 248 | spin_unlock_irqrestore (&ohci->lock, flags); |
| 249 | return retval; |
| 250 | } |
| 251 | |
| 252 | /* |
| 253 | * decouple the URB from the HC queues (TDs, urb_priv); it's |
| 254 | * already marked using urb->status. reporting is always done |
| 255 | * asynchronously, and we might be dealing with an urb that's |
| 256 | * partially transferred, or an ED with other urbs being unlinked. |
| 257 | */ |
| 258 | static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) |
| 259 | { |
| 260 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 261 | unsigned long flags; |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | #ifdef OHCI_VERBOSE_DEBUG |
| 264 | urb_print (urb, "UNLINK", 1); |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 265 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | spin_lock_irqsave (&ohci->lock, flags); |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 268 | if (HC_IS_RUNNING(hcd->state)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | urb_priv_t *urb_priv; |
| 270 | |
| 271 | /* Unless an IRQ completed the unlink while it was being |
| 272 | * handed to us, flag it for unlink and giveback, and force |
| 273 | * some upcoming INTR_SF to call finish_unlinks() |
| 274 | */ |
| 275 | urb_priv = urb->hcpriv; |
| 276 | if (urb_priv) { |
| 277 | if (urb_priv->ed->state == ED_OPER) |
| 278 | start_ed_unlink (ohci, urb_priv->ed); |
| 279 | } |
| 280 | } else { |
| 281 | /* |
| 282 | * with HC dead, we won't respect hc queue pointers |
| 283 | * any more ... just clean up every urb's memory. |
| 284 | */ |
| 285 | if (urb->hcpriv) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 286 | finish_urb (ohci, urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | spin_unlock_irqrestore (&ohci->lock, flags); |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /*-------------------------------------------------------------------------*/ |
| 293 | |
| 294 | /* frees config/altsetting state for endpoints, |
| 295 | * including ED memory, dummy TD, and bulk/intr data toggle |
| 296 | */ |
| 297 | |
| 298 | static void |
| 299 | ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep) |
| 300 | { |
| 301 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 302 | unsigned long flags; |
| 303 | struct ed *ed = ep->hcpriv; |
| 304 | unsigned limit = 1000; |
| 305 | |
| 306 | /* ASSERT: any requests/urbs are being unlinked */ |
| 307 | /* ASSERT: nobody can be submitting urbs for this any more */ |
| 308 | |
| 309 | if (!ed) |
| 310 | return; |
| 311 | |
| 312 | rescan: |
| 313 | spin_lock_irqsave (&ohci->lock, flags); |
| 314 | |
| 315 | if (!HC_IS_RUNNING (hcd->state)) { |
| 316 | sanitize: |
| 317 | ed->state = ED_IDLE; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 318 | finish_unlinks (ohci, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | switch (ed->state) { |
| 322 | case ED_UNLINK: /* wait for hw to finish? */ |
| 323 | /* major IRQ delivery trouble loses INTR_SF too... */ |
| 324 | if (limit-- == 0) { |
| 325 | ohci_warn (ohci, "IRQ INTR_SF lossage\n"); |
| 326 | goto sanitize; |
| 327 | } |
| 328 | spin_unlock_irqrestore (&ohci->lock, flags); |
Nishanth Aravamudan | 22c4386 | 2005-08-15 11:30:11 -0700 | [diff] [blame] | 329 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | goto rescan; |
| 331 | case ED_IDLE: /* fully unlinked */ |
| 332 | if (list_empty (&ed->td_list)) { |
| 333 | td_free (ohci, ed->dummy); |
| 334 | ed_free (ohci, ed); |
| 335 | break; |
| 336 | } |
| 337 | /* else FALL THROUGH */ |
| 338 | default: |
| 339 | /* caller was supposed to have unlinked any requests; |
| 340 | * that's not our job. can't recover; must leak ed. |
| 341 | */ |
| 342 | ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n", |
| 343 | ed, ep->desc.bEndpointAddress, ed->state, |
| 344 | list_empty (&ed->td_list) ? "" : " (has tds)"); |
| 345 | td_free (ohci, ed->dummy); |
| 346 | break; |
| 347 | } |
| 348 | ep->hcpriv = NULL; |
| 349 | spin_unlock_irqrestore (&ohci->lock, flags); |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | static int ohci_get_frame (struct usb_hcd *hcd) |
| 354 | { |
| 355 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 356 | |
| 357 | return ohci_frame_no(ohci); |
| 358 | } |
| 359 | |
| 360 | static void ohci_usb_reset (struct ohci_hcd *ohci) |
| 361 | { |
| 362 | ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); |
| 363 | ohci->hc_control &= OHCI_CTRL_RWC; |
| 364 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); |
| 365 | } |
| 366 | |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 367 | /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 368 | * other cases where the next software may expect clean state from the |
| 369 | * "firmware". this is bus-neutral, unlike shutdown() methods. |
| 370 | */ |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 371 | static void |
| 372 | ohci_shutdown (struct usb_hcd *hcd) |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 373 | { |
| 374 | struct ohci_hcd *ohci; |
| 375 | |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 376 | ohci = hcd_to_ohci (hcd); |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 377 | ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
| 378 | ohci_usb_reset (ohci); |
| 379 | /* flush the writes */ |
| 380 | (void) ohci_readl (ohci, &ohci->regs->control); |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /*-------------------------------------------------------------------------* |
| 384 | * HC functions |
| 385 | *-------------------------------------------------------------------------*/ |
| 386 | |
| 387 | /* init memory, and kick BIOS/SMM off */ |
| 388 | |
| 389 | static int ohci_init (struct ohci_hcd *ohci) |
| 390 | { |
| 391 | int ret; |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 392 | struct usb_hcd *hcd = ohci_to_hcd(ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
| 394 | disable (ohci); |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 395 | ohci->regs = hcd->regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 397 | /* REVISIT this BIOS handshake is now moved into PCI "quirks", and |
| 398 | * was never needed for most non-PCI systems ... remove the code? |
| 399 | */ |
| 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | #ifndef IR_DISABLE |
| 402 | /* SMM owns the HC? not for long! */ |
| 403 | if (!no_handshake && ohci_readl (ohci, |
| 404 | &ohci->regs->control) & OHCI_CTRL_IR) { |
| 405 | u32 temp; |
| 406 | |
| 407 | ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n"); |
| 408 | |
| 409 | /* this timeout is arbitrary. we make it long, so systems |
| 410 | * depending on usb keyboards may be usable even if the |
| 411 | * BIOS/SMM code seems pretty broken. |
| 412 | */ |
| 413 | temp = 500; /* arbitrary: five seconds */ |
| 414 | |
| 415 | ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable); |
| 416 | ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus); |
| 417 | while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) { |
| 418 | msleep (10); |
| 419 | if (--temp == 0) { |
| 420 | ohci_err (ohci, "USB HC takeover failed!" |
| 421 | " (BIOS/SMM bug)\n"); |
| 422 | return -EBUSY; |
| 423 | } |
| 424 | } |
| 425 | ohci_usb_reset (ohci); |
| 426 | } |
| 427 | #endif |
| 428 | |
| 429 | /* Disable HC interrupts */ |
| 430 | ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 431 | |
| 432 | /* flush the writes, and save key bits like RWC */ |
| 433 | if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC) |
| 434 | ohci->hc_control |= OHCI_CTRL_RWC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 436 | /* Read the number of ports unless overridden */ |
| 437 | if (ohci->num_ports == 0) |
| 438 | ohci->num_ports = roothub_a(ohci) & RH_A_NDP; |
| 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | if (ohci->hcca) |
| 441 | return 0; |
| 442 | |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 443 | ohci->hcca = dma_alloc_coherent (hcd->self.controller, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | sizeof *ohci->hcca, &ohci->hcca_dma, 0); |
| 445 | if (!ohci->hcca) |
| 446 | return -ENOMEM; |
| 447 | |
| 448 | if ((ret = ohci_mem_init (ohci)) < 0) |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 449 | ohci_stop (hcd); |
| 450 | else { |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 451 | create_debug_files (ohci); |
| 452 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
| 454 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /*-------------------------------------------------------------------------*/ |
| 458 | |
| 459 | /* Start an OHCI controller, set the BUS operational |
| 460 | * resets USB and controller |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 461 | * enable interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | */ |
| 463 | static int ohci_run (struct ohci_hcd *ohci) |
| 464 | { |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 465 | u32 mask, temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | int first = ohci->fminterval == 0; |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 467 | struct usb_hcd *hcd = ohci_to_hcd(ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
| 469 | disable (ohci); |
| 470 | |
| 471 | /* boot firmware should have set this up (5.1.1.3.1) */ |
| 472 | if (first) { |
| 473 | |
| 474 | temp = ohci_readl (ohci, &ohci->regs->fminterval); |
| 475 | ohci->fminterval = temp & 0x3fff; |
| 476 | if (ohci->fminterval != FI) |
| 477 | ohci_dbg (ohci, "fminterval delta %d\n", |
| 478 | ohci->fminterval - FI); |
| 479 | ohci->fminterval |= FSMP (ohci->fminterval) << 16; |
| 480 | /* also: power/overcurrent flags in roothub.a */ |
| 481 | } |
| 482 | |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 483 | /* Reset USB nearly "by the book". RemoteWakeupConnected was |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 484 | * saved if boot firmware (BIOS/SMM/...) told us it's connected, |
| 485 | * or if bus glue did the same (e.g. for PCI add-in cards with |
| 486 | * PCI PM support). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | */ |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 488 | if ((ohci->hc_control & OHCI_CTRL_RWC) != 0 |
| 489 | && !device_may_wakeup(hcd->self.controller)) |
| 490 | device_init_wakeup(hcd->self.controller, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | switch (ohci->hc_control & OHCI_CTRL_HCFS) { |
| 493 | case OHCI_USB_OPER: |
| 494 | temp = 0; |
| 495 | break; |
| 496 | case OHCI_USB_SUSPEND: |
| 497 | case OHCI_USB_RESUME: |
| 498 | ohci->hc_control &= OHCI_CTRL_RWC; |
| 499 | ohci->hc_control |= OHCI_USB_RESUME; |
| 500 | temp = 10 /* msec wait */; |
| 501 | break; |
| 502 | // case OHCI_USB_RESET: |
| 503 | default: |
| 504 | ohci->hc_control &= OHCI_CTRL_RWC; |
| 505 | ohci->hc_control |= OHCI_USB_RESET; |
| 506 | temp = 50 /* msec wait */; |
| 507 | break; |
| 508 | } |
| 509 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); |
| 510 | // flush the writes |
| 511 | (void) ohci_readl (ohci, &ohci->regs->control); |
| 512 | msleep(temp); |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame^] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | memset (ohci->hcca, 0, sizeof (struct ohci_hcca)); |
| 515 | |
| 516 | /* 2msec timelimit here means no irqs/preempt */ |
| 517 | spin_lock_irq (&ohci->lock); |
| 518 | |
| 519 | retry: |
| 520 | /* HC Reset requires max 10 us delay */ |
| 521 | ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus); |
| 522 | temp = 30; /* ... allow extra time */ |
| 523 | while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) { |
| 524 | if (--temp == 0) { |
| 525 | spin_unlock_irq (&ohci->lock); |
| 526 | ohci_err (ohci, "USB HC reset timed out!\n"); |
| 527 | return -1; |
| 528 | } |
| 529 | udelay (1); |
| 530 | } |
| 531 | |
| 532 | /* now we're in the SUSPEND state ... must go OPERATIONAL |
| 533 | * within 2msec else HC enters RESUME |
| 534 | * |
| 535 | * ... but some hardware won't init fmInterval "by the book" |
| 536 | * (SiS, OPTi ...), so reset again instead. SiS doesn't need |
| 537 | * this if we write fmInterval after we're OPERATIONAL. |
| 538 | * Unclear about ALi, ServerWorks, and others ... this could |
| 539 | * easily be a longstanding bug in chip init on Linux. |
| 540 | */ |
| 541 | if (ohci->flags & OHCI_QUIRK_INITRESET) { |
| 542 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); |
| 543 | // flush those writes |
| 544 | (void) ohci_readl (ohci, &ohci->regs->control); |
| 545 | } |
| 546 | |
| 547 | /* Tell the controller where the control and bulk lists are |
| 548 | * The lists are empty now. */ |
| 549 | ohci_writel (ohci, 0, &ohci->regs->ed_controlhead); |
| 550 | ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead); |
| 551 | |
| 552 | /* a reset clears this */ |
| 553 | ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca); |
| 554 | |
| 555 | periodic_reinit (ohci); |
| 556 | |
| 557 | /* some OHCI implementations are finicky about how they init. |
| 558 | * bogus values here mean not even enumeration could work. |
| 559 | */ |
| 560 | if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0 |
| 561 | || !ohci_readl (ohci, &ohci->regs->periodicstart)) { |
| 562 | if (!(ohci->flags & OHCI_QUIRK_INITRESET)) { |
| 563 | ohci->flags |= OHCI_QUIRK_INITRESET; |
| 564 | ohci_dbg (ohci, "enabling initreset quirk\n"); |
| 565 | goto retry; |
| 566 | } |
| 567 | spin_unlock_irq (&ohci->lock); |
| 568 | ohci_err (ohci, "init err (%08x %04x)\n", |
| 569 | ohci_readl (ohci, &ohci->regs->fminterval), |
| 570 | ohci_readl (ohci, &ohci->regs->periodicstart)); |
| 571 | return -EOVERFLOW; |
| 572 | } |
| 573 | |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 574 | /* use rhsc irqs after khubd is fully initialized */ |
| 575 | hcd->poll_rh = 1; |
| 576 | hcd->uses_new_polling = 1; |
| 577 | |
| 578 | /* start controller operations */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | ohci->hc_control &= OHCI_CTRL_RWC; |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 580 | ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER; |
| 581 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 582 | hcd->state = HC_STATE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
| 584 | /* wake on ConnectStatusChange, matching external hubs */ |
| 585 | ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status); |
| 586 | |
| 587 | /* Choose the interrupts we care about now, others later on demand */ |
| 588 | mask = OHCI_INTR_INIT; |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 589 | ohci_writel (ohci, ~0, &ohci->regs->intrstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | ohci_writel (ohci, mask, &ohci->regs->intrenable); |
| 591 | |
| 592 | /* handle root hub init quirks ... */ |
| 593 | temp = roothub_a (ohci); |
| 594 | temp &= ~(RH_A_PSM | RH_A_OCPM); |
| 595 | if (ohci->flags & OHCI_QUIRK_SUPERIO) { |
| 596 | /* NSC 87560 and maybe others */ |
| 597 | temp |= RH_A_NOCP; |
| 598 | temp &= ~(RH_A_POTPGT | RH_A_NPS); |
| 599 | ohci_writel (ohci, temp, &ohci->regs->roothub.a); |
| 600 | } else if ((ohci->flags & OHCI_QUIRK_AMD756) || distrust_firmware) { |
| 601 | /* hub power always on; required for AMD-756 and some |
| 602 | * Mac platforms. ganged overcurrent reporting, if any. |
| 603 | */ |
| 604 | temp |= RH_A_NPS; |
| 605 | ohci_writel (ohci, temp, &ohci->regs->roothub.a); |
| 606 | } |
| 607 | ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status); |
| 608 | ohci_writel (ohci, (temp & RH_A_NPS) ? 0 : RH_B_PPCM, |
| 609 | &ohci->regs->roothub.b); |
| 610 | // flush those writes |
| 611 | (void) ohci_readl (ohci, &ohci->regs->control); |
| 612 | |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 613 | ohci->next_statechange = jiffies + STATECHANGE_DELAY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | spin_unlock_irq (&ohci->lock); |
| 615 | |
| 616 | // POTPGT delay is bits 24-31, in 2 ms units. |
| 617 | mdelay ((temp >> 23) & 0x1fe); |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 618 | hcd->state = HC_STATE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
| 620 | ohci_dump (ohci, 1); |
| 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | /*-------------------------------------------------------------------------*/ |
| 626 | |
| 627 | /* an interrupt happens */ |
| 628 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 629 | static irqreturn_t ohci_irq (struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
| 631 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 632 | struct ohci_regs __iomem *regs = ohci->regs; |
| 633 | int ints; |
| 634 | |
| 635 | /* we can eliminate a (slow) ohci_readl() |
| 636 | if _only_ WDH caused this irq */ |
| 637 | if ((ohci->hcca->done_head != 0) |
| 638 | && ! (hc32_to_cpup (ohci, &ohci->hcca->done_head) |
| 639 | & 0x01)) { |
| 640 | ints = OHCI_INTR_WDH; |
| 641 | |
| 642 | /* cardbus/... hardware gone before remove() */ |
| 643 | } else if ((ints = ohci_readl (ohci, ®s->intrstatus)) == ~(u32)0) { |
| 644 | disable (ohci); |
| 645 | ohci_dbg (ohci, "device removed!\n"); |
| 646 | return IRQ_HANDLED; |
| 647 | |
| 648 | /* interrupt for some other device? */ |
| 649 | } else if ((ints &= ohci_readl (ohci, ®s->intrenable)) == 0) { |
| 650 | return IRQ_NOTMINE; |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | if (ints & OHCI_INTR_UE) { |
| 654 | disable (ohci); |
| 655 | ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n"); |
| 656 | // e.g. due to PCI Master/Target Abort |
| 657 | |
| 658 | ohci_dump (ohci, 1); |
| 659 | ohci_usb_reset (ohci); |
| 660 | } |
| 661 | |
Alan Stern | 583cead | 2006-10-24 12:04:22 -0400 | [diff] [blame] | 662 | if (ints & OHCI_INTR_RHSC) { |
| 663 | ohci_vdbg(ohci, "rhsc\n"); |
| 664 | ohci->next_statechange = jiffies + STATECHANGE_DELAY; |
| 665 | ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC, |
| 666 | ®s->intrstatus); |
Alan Stern | 052ac01 | 2006-10-27 10:33:11 -0400 | [diff] [blame] | 667 | |
| 668 | /* NOTE: Vendors didn't always make the same implementation |
| 669 | * choices for RHSC. Many followed the spec; RHSC triggers |
| 670 | * on an edge, like setting and maybe clearing a port status |
| 671 | * change bit. With others it's level-triggered, active |
| 672 | * until khubd clears all the port status change bits. We'll |
| 673 | * always disable it here and rely on polling until khubd |
| 674 | * re-enables it. |
| 675 | */ |
| 676 | ohci_writel(ohci, OHCI_INTR_RHSC, ®s->intrdisable); |
Alan Stern | 583cead | 2006-10-24 12:04:22 -0400 | [diff] [blame] | 677 | usb_hcd_poll_rh_status(hcd); |
| 678 | } |
| 679 | |
| 680 | /* For connect and disconnect events, we expect the controller |
| 681 | * to turn on RHSC along with RD. But for remote wakeup events |
| 682 | * this might not happen. |
| 683 | */ |
| 684 | else if (ints & OHCI_INTR_RD) { |
| 685 | ohci_vdbg(ohci, "resume detect\n"); |
| 686 | ohci_writel(ohci, OHCI_INTR_RD, ®s->intrstatus); |
Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 687 | hcd->poll_rh = 1; |
| 688 | if (ohci->autostop) { |
| 689 | spin_lock (&ohci->lock); |
| 690 | ohci_rh_resume (ohci); |
| 691 | spin_unlock (&ohci->lock); |
| 692 | } else |
David Brownell | f197b2c | 2005-09-22 22:42:53 -0700 | [diff] [blame] | 693 | usb_hcd_resume_root_hub(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | if (ints & OHCI_INTR_WDH) { |
| 697 | if (HC_IS_RUNNING(hcd->state)) |
Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 698 | ohci_writel (ohci, OHCI_INTR_WDH, ®s->intrdisable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | spin_lock (&ohci->lock); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 700 | dl_done_list (ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | spin_unlock (&ohci->lock); |
| 702 | if (HC_IS_RUNNING(hcd->state)) |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 703 | ohci_writel (ohci, OHCI_INTR_WDH, ®s->intrenable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | } |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | /* could track INTR_SO to reduce available PCI/... bandwidth */ |
| 707 | |
| 708 | /* handle any pending URB/ED unlinks, leaving INTR_SF enabled |
| 709 | * when there's still unlinking to be done (next frame). |
| 710 | */ |
| 711 | spin_lock (&ohci->lock); |
| 712 | if (ohci->ed_rm_list) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 713 | finish_unlinks (ohci, ohci_frame_no(ohci)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list |
| 715 | && HC_IS_RUNNING(hcd->state)) |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 716 | ohci_writel (ohci, OHCI_INTR_SF, ®s->intrdisable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | spin_unlock (&ohci->lock); |
| 718 | |
| 719 | if (HC_IS_RUNNING(hcd->state)) { |
| 720 | ohci_writel (ohci, ints, ®s->intrstatus); |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 721 | ohci_writel (ohci, OHCI_INTR_MIE, ®s->intrenable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | // flush those writes |
| 723 | (void) ohci_readl (ohci, &ohci->regs->control); |
| 724 | } |
| 725 | |
| 726 | return IRQ_HANDLED; |
| 727 | } |
| 728 | |
| 729 | /*-------------------------------------------------------------------------*/ |
| 730 | |
| 731 | static void ohci_stop (struct usb_hcd *hcd) |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 732 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | ohci_dump (ohci, 1); |
| 736 | |
| 737 | flush_scheduled_work(); |
| 738 | |
| 739 | ohci_usb_reset (ohci); |
| 740 | ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
Pete Zaitcev | 71795c1 | 2006-09-18 22:57:22 -0700 | [diff] [blame] | 741 | free_irq(hcd->irq, hcd); |
| 742 | hcd->irq = -1; |
| 743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | remove_debug_files (ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | ohci_mem_cleanup (ohci); |
| 746 | if (ohci->hcca) { |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 747 | dma_free_coherent (hcd->self.controller, |
| 748 | sizeof *ohci->hcca, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | ohci->hcca, ohci->hcca_dma); |
| 750 | ohci->hcca = NULL; |
| 751 | ohci->hcca_dma = 0; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | /*-------------------------------------------------------------------------*/ |
| 756 | |
| 757 | /* must not be called from interrupt context */ |
| 758 | |
David Brownell | 8ad7fe1 | 2005-09-13 19:59:11 -0700 | [diff] [blame] | 759 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
| 761 | static int ohci_restart (struct ohci_hcd *ohci) |
| 762 | { |
| 763 | int temp; |
| 764 | int i; |
| 765 | struct urb_priv *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
| 767 | /* mark any devices gone, so they do nothing till khubd disconnects. |
| 768 | * recycle any "live" eds/tds (and urbs) right away. |
| 769 | * later, khubd disconnect processing will recycle the other state, |
| 770 | * (either as disconnect/reconnect, or maybe someday as a reset). |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 771 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | spin_lock_irq(&ohci->lock); |
| 773 | disable (ohci); |
Alan Stern | 1c50c31 | 2005-11-14 11:45:38 -0500 | [diff] [blame] | 774 | usb_root_hub_lost_power(ohci_to_hcd(ohci)->self.root_hub); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | if (!list_empty (&ohci->pending)) |
| 776 | ohci_dbg(ohci, "abort schedule...\n"); |
| 777 | list_for_each_entry (priv, &ohci->pending, pending) { |
| 778 | struct urb *urb = priv->td[0]->urb; |
| 779 | struct ed *ed = priv->ed; |
| 780 | |
| 781 | switch (ed->state) { |
| 782 | case ED_OPER: |
| 783 | ed->state = ED_UNLINK; |
| 784 | ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE); |
| 785 | ed_deschedule (ohci, ed); |
| 786 | |
| 787 | ed->ed_next = ohci->ed_rm_list; |
| 788 | ed->ed_prev = NULL; |
| 789 | ohci->ed_rm_list = ed; |
| 790 | /* FALLTHROUGH */ |
| 791 | case ED_UNLINK: |
| 792 | break; |
| 793 | default: |
| 794 | ohci_dbg(ohci, "bogus ed %p state %d\n", |
| 795 | ed, ed->state); |
| 796 | } |
| 797 | |
| 798 | spin_lock (&urb->lock); |
| 799 | urb->status = -ESHUTDOWN; |
| 800 | spin_unlock (&urb->lock); |
| 801 | } |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 802 | finish_unlinks (ohci, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | spin_unlock_irq(&ohci->lock); |
| 804 | |
| 805 | /* paranoia, in case that didn't work: */ |
| 806 | |
| 807 | /* empty the interrupt branches */ |
| 808 | for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0; |
| 809 | for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0; |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | /* no EDs to remove */ |
| 812 | ohci->ed_rm_list = NULL; |
| 813 | |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 814 | /* empty control and bulk lists */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | ohci->ed_controltail = NULL; |
| 816 | ohci->ed_bulktail = NULL; |
| 817 | |
| 818 | if ((temp = ohci_run (ohci)) < 0) { |
| 819 | ohci_err (ohci, "can't restart, %d\n", temp); |
| 820 | return temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | } |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame^] | 822 | ohci_dbg(ohci, "restart complete\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | return 0; |
| 824 | } |
| 825 | #endif |
| 826 | |
| 827 | /*-------------------------------------------------------------------------*/ |
| 828 | |
| 829 | #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC |
| 830 | |
| 831 | MODULE_AUTHOR (DRIVER_AUTHOR); |
| 832 | MODULE_DESCRIPTION (DRIVER_INFO); |
| 833 | MODULE_LICENSE ("GPL"); |
| 834 | |
| 835 | #ifdef CONFIG_PCI |
| 836 | #include "ohci-pci.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 837 | #define PCI_DRIVER ohci_pci_driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | #endif |
| 839 | |
| 840 | #ifdef CONFIG_SA1111 |
| 841 | #include "ohci-sa1111.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 842 | #define SA1111_DRIVER ohci_hcd_sa1111_driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | #endif |
| 844 | |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 845 | #ifdef CONFIG_ARCH_S3C2410 |
| 846 | #include "ohci-s3c2410.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 847 | #define PLATFORM_DRIVER ohci_hcd_s3c2410_driver |
Ben Dooks | 3eb0c5f | 2005-07-29 12:18:03 -0700 | [diff] [blame] | 848 | #endif |
| 849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | #ifdef CONFIG_ARCH_OMAP |
| 851 | #include "ohci-omap.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 852 | #define PLATFORM_DRIVER ohci_hcd_omap_driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | #endif |
| 854 | |
| 855 | #ifdef CONFIG_ARCH_LH7A404 |
| 856 | #include "ohci-lh7a404.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 857 | #define PLATFORM_DRIVER ohci_hcd_lh7a404_driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | #endif |
| 859 | |
| 860 | #ifdef CONFIG_PXA27x |
| 861 | #include "ohci-pxa27x.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 862 | #define PLATFORM_DRIVER ohci_hcd_pxa27x_driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | #endif |
| 864 | |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 865 | #ifdef CONFIG_ARCH_EP93XX |
| 866 | #include "ohci-ep93xx.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 867 | #define PLATFORM_DRIVER ohci_hcd_ep93xx_driver |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 868 | #endif |
| 869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | #ifdef CONFIG_SOC_AU1X00 |
| 871 | #include "ohci-au1xxx.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 872 | #define PLATFORM_DRIVER ohci_hcd_au1xxx_driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | #endif |
| 874 | |
Vitaly Wool | 5151d04 | 2006-10-09 01:32:00 -0700 | [diff] [blame] | 875 | #ifdef CONFIG_PNX8550 |
| 876 | #include "ohci-pnx8550.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 877 | #define PLATFORM_DRIVER ohci_hcd_pnx8550_driver |
Vitaly Wool | 5151d04 | 2006-10-09 01:32:00 -0700 | [diff] [blame] | 878 | #endif |
| 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | #ifdef CONFIG_USB_OHCI_HCD_PPC_SOC |
| 881 | #include "ohci-ppc-soc.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 882 | #define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | #endif |
| 884 | |
Andrew Victor | 58a0cd7 | 2006-12-01 14:51:13 +0100 | [diff] [blame] | 885 | #ifdef CONFIG_ARCH_AT91 |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 886 | #include "ohci-at91.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 887 | #define PLATFORM_DRIVER ohci_hcd_at91_driver |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 888 | #endif |
| 889 | |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 890 | #ifdef CONFIG_ARCH_PNX4008 |
| 891 | #include "ohci-pnx4008.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 892 | #define PLATFORM_DRIVER usb_hcd_pnx4008_driver |
Vitaly Wool | 60bbfc8 | 2006-06-29 18:28:18 +0400 | [diff] [blame] | 893 | #endif |
| 894 | |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 895 | |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 896 | #ifdef CONFIG_USB_OHCI_HCD_PPC_OF |
| 897 | #include "ohci-ppc-of.c" |
| 898 | #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver |
| 899 | #endif |
| 900 | |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 901 | #ifdef CONFIG_PPC_PS3 |
| 902 | #include "ohci-ps3.c" |
| 903 | #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_sb_driver |
| 904 | #endif |
| 905 | |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 906 | #if !defined(PCI_DRIVER) && \ |
| 907 | !defined(PLATFORM_DRIVER) && \ |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 908 | !defined(OF_PLATFORM_DRIVER) && \ |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 909 | !defined(SA1111_DRIVER) && \ |
| 910 | !defined(PS3_SYSTEM_BUS_DRIVER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | #error "missing bus glue for ohci-hcd" |
| 912 | #endif |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 913 | |
| 914 | static int __init ohci_hcd_mod_init(void) |
| 915 | { |
| 916 | int retval = 0; |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 917 | |
| 918 | if (usb_disabled()) |
| 919 | return -ENODEV; |
| 920 | |
| 921 | printk (KERN_DEBUG "%s: " DRIVER_INFO "\n", hcd_name); |
| 922 | pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name, |
| 923 | sizeof (struct ed), sizeof (struct td)); |
| 924 | |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 925 | #ifdef PS3_SYSTEM_BUS_DRIVER |
Ishizaki Kou | 48fda45 | 2007-02-14 16:04:17 +0900 | [diff] [blame] | 926 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) { |
| 927 | retval = ps3_system_bus_driver_register( |
| 928 | &PS3_SYSTEM_BUS_DRIVER); |
| 929 | if (retval < 0) |
| 930 | goto error_ps3; |
| 931 | } |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 932 | #endif |
| 933 | |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 934 | #ifdef PLATFORM_DRIVER |
| 935 | retval = platform_driver_register(&PLATFORM_DRIVER); |
| 936 | if (retval < 0) |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 937 | goto error_platform; |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 938 | #endif |
| 939 | |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 940 | #ifdef OF_PLATFORM_DRIVER |
| 941 | retval = of_register_platform_driver(&OF_PLATFORM_DRIVER); |
| 942 | if (retval < 0) |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 943 | goto error_of_platform; |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 944 | #endif |
| 945 | |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 946 | #ifdef SA1111_DRIVER |
| 947 | retval = sa1111_driver_register(&SA1111_DRIVER); |
| 948 | if (retval < 0) |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 949 | goto error_sa1111; |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 950 | #endif |
| 951 | |
| 952 | #ifdef PCI_DRIVER |
| 953 | retval = pci_register_driver(&PCI_DRIVER); |
| 954 | if (retval < 0) |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 955 | goto error_pci; |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 956 | #endif |
| 957 | |
| 958 | return retval; |
| 959 | |
| 960 | /* Error path */ |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 961 | #ifdef PCI_DRIVER |
| 962 | error_pci: |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 963 | #endif |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 964 | #ifdef SA1111_DRIVER |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 965 | sa1111_driver_unregister(&SA1111_DRIVER); |
| 966 | error_sa1111: |
| 967 | #endif |
| 968 | #ifdef OF_PLATFORM_DRIVER |
| 969 | of_unregister_platform_driver(&OF_PLATFORM_DRIVER); |
| 970 | error_of_platform: |
| 971 | #endif |
| 972 | #ifdef PLATFORM_DRIVER |
| 973 | platform_driver_unregister(&PLATFORM_DRIVER); |
| 974 | error_platform: |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 975 | #endif |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 976 | #ifdef PS3_SYSTEM_BUS_DRIVER |
Ishizaki Kou | 48fda45 | 2007-02-14 16:04:17 +0900 | [diff] [blame] | 977 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) |
| 978 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 979 | error_ps3: |
| 980 | #endif |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 981 | return retval; |
| 982 | } |
| 983 | module_init(ohci_hcd_mod_init); |
| 984 | |
| 985 | static void __exit ohci_hcd_mod_exit(void) |
| 986 | { |
| 987 | #ifdef PCI_DRIVER |
| 988 | pci_unregister_driver(&PCI_DRIVER); |
| 989 | #endif |
| 990 | #ifdef SA1111_DRIVER |
| 991 | sa1111_driver_unregister(&SA1111_DRIVER); |
| 992 | #endif |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 993 | #ifdef OF_PLATFORM_DRIVER |
| 994 | of_unregister_platform_driver(&OF_PLATFORM_DRIVER); |
| 995 | #endif |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 996 | #ifdef PLATFORM_DRIVER |
| 997 | platform_driver_unregister(&PLATFORM_DRIVER); |
| 998 | #endif |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 999 | #ifdef PS3_SYSTEM_BUS_DRIVER |
Ishizaki Kou | 48fda45 | 2007-02-14 16:04:17 +0900 | [diff] [blame] | 1000 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) |
| 1001 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 1002 | #endif |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1003 | } |
| 1004 | module_exit(ohci_hcd_mod_exit); |
| 1005 | |