Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Alan Stern | 578333a | 2011-06-15 16:32:46 -0400 | [diff] [blame] | 2 | * Open Host Controller Interface (OHCI) driver for USB. |
| 3 | * |
| 4 | * Maintainer: Alan Stern <stern@rowland.harvard.edu> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> |
| 7 | * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * [ Initialisation is based on Linus' ] |
| 10 | * [ uhci code and gregs ohci fragments ] |
| 11 | * [ (C) Copyright 1999 Linus Torvalds ] |
| 12 | * [ (C) Copyright 1999 Gregory P. Smith] |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 13 | * |
| 14 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller |
| 16 | * interfaces (though some non-x86 Intel chips use it). It supports |
| 17 | * smarter hardware than UHCI. A download link for the spec available |
| 18 | * through the http://www.usb.org website. |
| 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * This file is licenced under the GPL. |
| 21 | */ |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/moduleparam.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <linux/sched.h> |
| 30 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/errno.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/timer.h> |
| 34 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/usb.h> |
David Brownell | 3a16f7b | 2006-06-29 12:27:23 -0700 | [diff] [blame] | 36 | #include <linux/usb/otg.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 37 | #include <linux/usb/hcd.h> |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 38 | #include <linux/dma-mapping.h> |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 39 | #include <linux/dmapool.h> |
Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 40 | #include <linux/workqueue.h> |
Tony Jones | 684c19e | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 41 | #include <linux/debugfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #include <asm/io.h> |
| 44 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/unaligned.h> |
| 46 | #include <asm/byteorder.h> |
| 47 | |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell" |
| 50 | #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver" |
| 51 | |
| 52 | /*-------------------------------------------------------------------------*/ |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* For initializing controller (mask in an HCFS mode too) */ |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 55 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define OHCI_INTR_INIT \ |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 57 | (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \ |
| 58 | | OHCI_INTR_RD | OHCI_INTR_WDH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | #ifdef __hppa__ |
| 61 | /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */ |
| 62 | #define IR_DISABLE |
| 63 | #endif |
| 64 | |
| 65 | #ifdef CONFIG_ARCH_OMAP |
| 66 | /* OMAP doesn't support IR (no SMM; not needed) */ |
| 67 | #define IR_DISABLE |
| 68 | #endif |
| 69 | |
| 70 | /*-------------------------------------------------------------------------*/ |
| 71 | |
| 72 | static const char hcd_name [] = "ohci_hcd"; |
| 73 | |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 74 | #define STATECHANGE_DELAY msecs_to_jiffies(300) |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #include "ohci.h" |
Andiry Xu | ad93562 | 2011-03-01 14:57:05 +0800 | [diff] [blame] | 77 | #include "pci-quirks.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | static void ohci_dump (struct ohci_hcd *ohci, int verbose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static void ohci_stop (struct usb_hcd *hcd); |
Libin Yang | ab1666c | 2008-08-08 15:03:31 +0800 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #include "ohci-hub.c" |
| 83 | #include "ohci-dbg.c" |
| 84 | #include "ohci-mem.c" |
| 85 | #include "ohci-q.c" |
| 86 | |
| 87 | |
| 88 | /* |
| 89 | * On architectures with edge-triggered interrupts we must never return |
| 90 | * IRQ_NONE. |
| 91 | */ |
| 92 | #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */ |
| 93 | #define IRQ_NOTMINE IRQ_HANDLED |
| 94 | #else |
| 95 | #define IRQ_NOTMINE IRQ_NONE |
| 96 | #endif |
| 97 | |
| 98 | |
| 99 | /* Some boards misreport power switching/overcurrent */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 100 | static bool distrust_firmware = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | module_param (distrust_firmware, bool, 0); |
| 102 | MODULE_PARM_DESC (distrust_firmware, |
| 103 | "true to distrust firmware power/overcurrent setup"); |
| 104 | |
| 105 | /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 106 | static bool no_handshake = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | module_param (no_handshake, bool, 0); |
| 108 | MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake"); |
| 109 | |
| 110 | /*-------------------------------------------------------------------------*/ |
| 111 | |
Alan Stern | 6f65126 | 2014-07-17 16:30:01 -0400 | [diff] [blame^] | 112 | static int number_of_tds(struct urb *urb) |
| 113 | { |
| 114 | int len, i, num, this_sg_len; |
| 115 | struct scatterlist *sg; |
| 116 | |
| 117 | len = urb->transfer_buffer_length; |
| 118 | i = urb->num_mapped_sgs; |
| 119 | |
| 120 | if (len > 0 && i > 0) { /* Scatter-gather transfer */ |
| 121 | num = 0; |
| 122 | sg = urb->sg; |
| 123 | for (;;) { |
| 124 | this_sg_len = min_t(int, sg_dma_len(sg), len); |
| 125 | num += DIV_ROUND_UP(this_sg_len, 4096); |
| 126 | len -= this_sg_len; |
| 127 | if (--i <= 0 || len <= 0) |
| 128 | break; |
| 129 | sg = sg_next(sg); |
| 130 | } |
| 131 | |
| 132 | } else { /* Non-SG transfer */ |
| 133 | /* one TD for every 4096 Bytes (could be up to 8K) */ |
| 134 | num = DIV_ROUND_UP(len, 4096); |
| 135 | } |
| 136 | return num; |
| 137 | } |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | /* |
| 140 | * queue up an urb for anything except the root hub |
| 141 | */ |
| 142 | static int ohci_urb_enqueue ( |
| 143 | struct usb_hcd *hcd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | struct urb *urb, |
Al Viro | 55016f1 | 2005-10-21 03:21:58 -0400 | [diff] [blame] | 145 | gfp_t mem_flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | ) { |
| 147 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 148 | struct ed *ed; |
| 149 | urb_priv_t *urb_priv; |
| 150 | unsigned int pipe = urb->pipe; |
| 151 | int i, size = 0; |
| 152 | unsigned long flags; |
| 153 | int retval = 0; |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* every endpoint has a ed, locate and maybe (re)initialize it */ |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 156 | if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return -ENOMEM; |
| 158 | |
| 159 | /* for the private part of the URB we need the number of TDs (size) */ |
| 160 | switch (ed->type) { |
| 161 | case PIPE_CONTROL: |
| 162 | /* td_submit_urb() doesn't yet handle these */ |
| 163 | if (urb->transfer_buffer_length > 4096) |
| 164 | return -EMSGSIZE; |
| 165 | |
| 166 | /* 1 TD for setup, 1 for ACK, plus ... */ |
| 167 | size = 2; |
| 168 | /* FALLTHROUGH */ |
| 169 | // case PIPE_INTERRUPT: |
| 170 | // case PIPE_BULK: |
| 171 | default: |
Alan Stern | 6f65126 | 2014-07-17 16:30:01 -0400 | [diff] [blame^] | 172 | size += number_of_tds(urb); |
| 173 | /* maybe a zero-length packet to wrap it up */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (size == 0) |
| 175 | size++; |
| 176 | else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0 |
| 177 | && (urb->transfer_buffer_length |
| 178 | % usb_maxpacket (urb->dev, pipe, |
| 179 | usb_pipeout (pipe))) == 0) |
| 180 | size++; |
| 181 | break; |
| 182 | case PIPE_ISOCHRONOUS: /* number of packets from URB */ |
| 183 | size = urb->number_of_packets; |
| 184 | break; |
| 185 | } |
| 186 | |
| 187 | /* allocate the private part of the URB */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 188 | urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | mem_flags); |
| 190 | if (!urb_priv) |
| 191 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | INIT_LIST_HEAD (&urb_priv->pending); |
| 193 | urb_priv->length = size; |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 194 | urb_priv->ed = ed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | /* allocate the TDs (deferring hash chain updates) */ |
| 197 | for (i = 0; i < size; i++) { |
| 198 | urb_priv->td [i] = td_alloc (ohci, mem_flags); |
| 199 | if (!urb_priv->td [i]) { |
| 200 | urb_priv->length = i; |
| 201 | urb_free_priv (ohci, urb_priv); |
| 202 | return -ENOMEM; |
| 203 | } |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 204 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | spin_lock_irqsave (&ohci->lock, flags); |
| 207 | |
| 208 | /* don't submit to a dead HC */ |
Alan Stern | 541c7d4 | 2010-06-22 16:39:10 -0400 | [diff] [blame] | 209 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 210 | retval = -ENODEV; |
| 211 | goto fail; |
| 212 | } |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 213 | if (ohci->rh_state != OHCI_RH_RUNNING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | retval = -ENODEV; |
| 215 | goto fail; |
| 216 | } |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 217 | retval = usb_hcd_link_urb_to_ep(hcd, urb); |
| 218 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | /* schedule the ed if needed */ |
| 222 | if (ed->state == ED_IDLE) { |
| 223 | retval = ed_schedule (ohci, ed); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 224 | if (retval < 0) { |
| 225 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
| 226 | goto fail; |
| 227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | if (ed->type == PIPE_ISOCHRONOUS) { |
| 229 | u16 frame = ohci_frame_no(ohci); |
| 230 | |
| 231 | /* delay a few frames before the first TD */ |
| 232 | frame += max_t (u16, 8, ed->interval); |
| 233 | frame &= ~(ed->interval - 1); |
| 234 | frame |= ed->branch; |
| 235 | urb->start_frame = frame; |
Alan Stern | a869342 | 2013-09-24 15:46:45 -0400 | [diff] [blame] | 236 | ed->last_iso = frame + ed->interval * (size - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
Alan Stern | 6a41b4d | 2012-10-01 10:32:15 -0400 | [diff] [blame] | 238 | } else if (ed->type == PIPE_ISOCHRONOUS) { |
Alan Stern | e1944017 | 2013-05-14 13:57:19 -0400 | [diff] [blame] | 239 | u16 next = ohci_frame_no(ohci) + 1; |
Alan Stern | 6a41b4d | 2012-10-01 10:32:15 -0400 | [diff] [blame] | 240 | u16 frame = ed->last_iso + ed->interval; |
Alan Stern | a869342 | 2013-09-24 15:46:45 -0400 | [diff] [blame] | 241 | u16 length = ed->interval * (size - 1); |
Alan Stern | 6a41b4d | 2012-10-01 10:32:15 -0400 | [diff] [blame] | 242 | |
| 243 | /* Behind the scheduling threshold? */ |
| 244 | if (unlikely(tick_before(frame, next))) { |
| 245 | |
Alan Stern | a869342 | 2013-09-24 15:46:45 -0400 | [diff] [blame] | 246 | /* URB_ISO_ASAP: Round up to the first available slot */ |
Alan Stern | 815fa7b | 2013-05-14 13:57:51 -0400 | [diff] [blame] | 247 | if (urb->transfer_flags & URB_ISO_ASAP) { |
Alan Stern | 6a41b4d | 2012-10-01 10:32:15 -0400 | [diff] [blame] | 248 | frame += (next - frame + ed->interval - 1) & |
| 249 | -ed->interval; |
| 250 | |
| 251 | /* |
Alan Stern | a869342 | 2013-09-24 15:46:45 -0400 | [diff] [blame] | 252 | * Not ASAP: Use the next slot in the stream, |
| 253 | * no matter what. |
Alan Stern | 6a41b4d | 2012-10-01 10:32:15 -0400 | [diff] [blame] | 254 | */ |
Alan Stern | 815fa7b | 2013-05-14 13:57:51 -0400 | [diff] [blame] | 255 | } else { |
Alan Stern | 815fa7b | 2013-05-14 13:57:51 -0400 | [diff] [blame] | 256 | /* |
| 257 | * Some OHCI hardware doesn't handle late TDs |
| 258 | * correctly. After retiring them it proceeds |
| 259 | * to the next ED instead of the next TD. |
| 260 | * Therefore we have to omit the late TDs |
| 261 | * entirely. |
| 262 | */ |
| 263 | urb_priv->td_cnt = DIV_ROUND_UP( |
| 264 | (u16) (next - frame), |
| 265 | ed->interval); |
Alan Stern | a869342 | 2013-09-24 15:46:45 -0400 | [diff] [blame] | 266 | if (urb_priv->td_cnt >= urb_priv->length) { |
| 267 | ++urb_priv->td_cnt; /* Mark it */ |
| 268 | ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n", |
| 269 | urb, frame, length, |
| 270 | next); |
| 271 | } |
Alan Stern | 815fa7b | 2013-05-14 13:57:51 -0400 | [diff] [blame] | 272 | } |
Alan Stern | 6a41b4d | 2012-10-01 10:32:15 -0400 | [diff] [blame] | 273 | } |
| 274 | urb->start_frame = frame; |
Alan Stern | a869342 | 2013-09-24 15:46:45 -0400 | [diff] [blame] | 275 | ed->last_iso = frame + length; |
Alan Stern | 6a41b4d | 2012-10-01 10:32:15 -0400 | [diff] [blame] | 276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | /* fill the TDs and link them to the ed; and |
| 279 | * enable that part of the schedule, if needed |
| 280 | * and update count of queued periodic urbs |
| 281 | */ |
| 282 | urb->hcpriv = urb_priv; |
| 283 | td_submit_urb (ohci, urb); |
| 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | fail: |
| 286 | if (retval) |
| 287 | urb_free_priv (ohci, urb_priv); |
| 288 | spin_unlock_irqrestore (&ohci->lock, flags); |
| 289 | return retval; |
| 290 | } |
| 291 | |
| 292 | /* |
Alan Stern | 55d8496 | 2007-08-24 15:40:34 -0400 | [diff] [blame] | 293 | * decouple the URB from the HC queues (TDs, urb_priv). |
| 294 | * reporting is always done |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | * asynchronously, and we might be dealing with an urb that's |
| 296 | * partially transferred, or an ED with other urbs being unlinked. |
| 297 | */ |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 298 | static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { |
| 300 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 301 | unsigned long flags; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 302 | int rc; |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | spin_lock_irqsave (&ohci->lock, flags); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 305 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); |
| 306 | if (rc) { |
| 307 | ; /* Do nothing */ |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 308 | } else if (ohci->rh_state == OHCI_RH_RUNNING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | urb_priv_t *urb_priv; |
| 310 | |
| 311 | /* Unless an IRQ completed the unlink while it was being |
| 312 | * handed to us, flag it for unlink and giveback, and force |
| 313 | * some upcoming INTR_SF to call finish_unlinks() |
| 314 | */ |
| 315 | urb_priv = urb->hcpriv; |
| 316 | if (urb_priv) { |
| 317 | if (urb_priv->ed->state == ED_OPER) |
| 318 | start_ed_unlink (ohci, urb_priv->ed); |
| 319 | } |
| 320 | } else { |
| 321 | /* |
| 322 | * with HC dead, we won't respect hc queue pointers |
| 323 | * any more ... just clean up every urb's memory. |
| 324 | */ |
| 325 | if (urb->hcpriv) |
Alan Stern | 55d8496 | 2007-08-24 15:40:34 -0400 | [diff] [blame] | 326 | finish_urb(ohci, urb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | spin_unlock_irqrestore (&ohci->lock, flags); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 329 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /*-------------------------------------------------------------------------*/ |
| 333 | |
| 334 | /* frees config/altsetting state for endpoints, |
| 335 | * including ED memory, dummy TD, and bulk/intr data toggle |
| 336 | */ |
| 337 | |
| 338 | static void |
| 339 | ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep) |
| 340 | { |
| 341 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 342 | unsigned long flags; |
| 343 | struct ed *ed = ep->hcpriv; |
| 344 | unsigned limit = 1000; |
| 345 | |
| 346 | /* ASSERT: any requests/urbs are being unlinked */ |
| 347 | /* ASSERT: nobody can be submitting urbs for this any more */ |
| 348 | |
| 349 | if (!ed) |
| 350 | return; |
| 351 | |
| 352 | rescan: |
| 353 | spin_lock_irqsave (&ohci->lock, flags); |
| 354 | |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 355 | if (ohci->rh_state != OHCI_RH_RUNNING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | sanitize: |
| 357 | ed->state = ED_IDLE; |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 358 | if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT) |
| 359 | ohci->eds_scheduled--; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 360 | finish_unlinks (ohci, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | switch (ed->state) { |
| 364 | case ED_UNLINK: /* wait for hw to finish? */ |
| 365 | /* major IRQ delivery trouble loses INTR_SF too... */ |
| 366 | if (limit-- == 0) { |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 367 | ohci_warn(ohci, "ED unlink timeout\n"); |
| 368 | if (quirk_zfmicro(ohci)) { |
| 369 | ohci_warn(ohci, "Attempting ZF TD recovery\n"); |
| 370 | ohci->ed_to_check = ed; |
| 371 | ohci->zf_delay = 2; |
| 372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | goto sanitize; |
| 374 | } |
| 375 | spin_unlock_irqrestore (&ohci->lock, flags); |
Nishanth Aravamudan | 22c4386 | 2005-08-15 11:30:11 -0700 | [diff] [blame] | 376 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | goto rescan; |
| 378 | case ED_IDLE: /* fully unlinked */ |
| 379 | if (list_empty (&ed->td_list)) { |
| 380 | td_free (ohci, ed->dummy); |
| 381 | ed_free (ohci, ed); |
| 382 | break; |
| 383 | } |
| 384 | /* else FALL THROUGH */ |
| 385 | default: |
| 386 | /* caller was supposed to have unlinked any requests; |
| 387 | * that's not our job. can't recover; must leak ed. |
| 388 | */ |
| 389 | ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n", |
| 390 | ed, ep->desc.bEndpointAddress, ed->state, |
| 391 | list_empty (&ed->td_list) ? "" : " (has tds)"); |
| 392 | td_free (ohci, ed->dummy); |
| 393 | break; |
| 394 | } |
| 395 | ep->hcpriv = NULL; |
| 396 | spin_unlock_irqrestore (&ohci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static int ohci_get_frame (struct usb_hcd *hcd) |
| 400 | { |
| 401 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 402 | |
| 403 | return ohci_frame_no(ohci); |
| 404 | } |
| 405 | |
| 406 | static void ohci_usb_reset (struct ohci_hcd *ohci) |
| 407 | { |
| 408 | ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); |
| 409 | ohci->hc_control &= OHCI_CTRL_RWC; |
| 410 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 411 | ohci->rh_state = OHCI_RH_HALTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 414 | /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 415 | * other cases where the next software may expect clean state from the |
| 416 | * "firmware". this is bus-neutral, unlike shutdown() methods. |
| 417 | */ |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 418 | static void |
| 419 | ohci_shutdown (struct usb_hcd *hcd) |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 420 | { |
| 421 | struct ohci_hcd *ohci; |
| 422 | |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 423 | ohci = hcd_to_ohci (hcd); |
Alan Stern | c618759 | 2011-11-17 16:41:45 -0500 | [diff] [blame] | 424 | ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable); |
Alan Stern | 3df7169 | 2010-09-10 16:37:05 -0400 | [diff] [blame] | 425 | |
Alan Stern | c618759 | 2011-11-17 16:41:45 -0500 | [diff] [blame] | 426 | /* Software reset, after which the controller goes into SUSPEND */ |
| 427 | ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus); |
| 428 | ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */ |
| 429 | udelay(10); |
Alan Stern | 3df7169 | 2010-09-10 16:37:05 -0400 | [diff] [blame] | 430 | |
Alan Stern | c618759 | 2011-11-17 16:41:45 -0500 | [diff] [blame] | 431 | ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval); |
David Brownell | f4df0e3 | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 434 | static int check_ed(struct ohci_hcd *ohci, struct ed *ed) |
| 435 | { |
| 436 | return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0 |
| 437 | && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK) |
| 438 | == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK) |
| 439 | && !list_empty(&ed->td_list); |
| 440 | } |
| 441 | |
| 442 | /* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes |
| 443 | * an interrupt TD but neglects to add it to the donelist. On systems with |
| 444 | * this chipset, we need to periodically check the state of the queues to look |
| 445 | * for such "lost" TDs. |
| 446 | */ |
| 447 | static void unlink_watchdog_func(unsigned long _ohci) |
| 448 | { |
David Brownell | da6fb57 | 2007-10-24 17:23:42 -0700 | [diff] [blame] | 449 | unsigned long flags; |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 450 | unsigned max; |
| 451 | unsigned seen_count = 0; |
| 452 | unsigned i; |
| 453 | struct ed **seen = NULL; |
| 454 | struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci; |
| 455 | |
| 456 | spin_lock_irqsave(&ohci->lock, flags); |
| 457 | max = ohci->eds_scheduled; |
| 458 | if (!max) |
| 459 | goto done; |
| 460 | |
| 461 | if (ohci->ed_to_check) |
| 462 | goto out; |
| 463 | |
| 464 | seen = kcalloc(max, sizeof *seen, GFP_ATOMIC); |
| 465 | if (!seen) |
| 466 | goto out; |
| 467 | |
| 468 | for (i = 0; i < NUM_INTS; i++) { |
| 469 | struct ed *ed = ohci->periodic[i]; |
| 470 | |
| 471 | while (ed) { |
| 472 | unsigned temp; |
| 473 | |
| 474 | /* scan this branch of the periodic schedule tree */ |
| 475 | for (temp = 0; temp < seen_count; temp++) { |
| 476 | if (seen[temp] == ed) { |
| 477 | /* we've checked it and what's after */ |
| 478 | ed = NULL; |
| 479 | break; |
| 480 | } |
| 481 | } |
| 482 | if (!ed) |
| 483 | break; |
| 484 | seen[seen_count++] = ed; |
| 485 | if (!check_ed(ohci, ed)) { |
| 486 | ed = ed->ed_next; |
| 487 | continue; |
| 488 | } |
| 489 | |
| 490 | /* HC's TD list is empty, but HCD sees at least one |
| 491 | * TD that's not been sent through the donelist. |
| 492 | */ |
| 493 | ohci->ed_to_check = ed; |
| 494 | ohci->zf_delay = 2; |
| 495 | |
| 496 | /* The HC may wait until the next frame to report the |
| 497 | * TD as done through the donelist and INTR_WDH. (We |
| 498 | * just *assume* it's not a multi-TD interrupt URB; |
| 499 | * those could defer the IRQ more than one frame, using |
| 500 | * DI...) Check again after the next INTR_SF. |
| 501 | */ |
| 502 | ohci_writel(ohci, OHCI_INTR_SF, |
| 503 | &ohci->regs->intrstatus); |
| 504 | ohci_writel(ohci, OHCI_INTR_SF, |
| 505 | &ohci->regs->intrenable); |
| 506 | |
| 507 | /* flush those writes */ |
| 508 | (void) ohci_readl(ohci, &ohci->regs->control); |
| 509 | |
| 510 | goto out; |
| 511 | } |
| 512 | } |
| 513 | out: |
| 514 | kfree(seen); |
| 515 | if (ohci->eds_scheduled) |
Richard Kennedy | 9cebcdc | 2008-03-28 14:50:30 -0700 | [diff] [blame] | 516 | mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ)); |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 517 | done: |
| 518 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 519 | } |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /*-------------------------------------------------------------------------* |
| 522 | * HC functions |
| 523 | *-------------------------------------------------------------------------*/ |
| 524 | |
| 525 | /* init memory, and kick BIOS/SMM off */ |
| 526 | |
| 527 | static int ohci_init (struct ohci_hcd *ohci) |
| 528 | { |
| 529 | int ret; |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 530 | struct usb_hcd *hcd = ohci_to_hcd(ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Alan Stern | 6f65126 | 2014-07-17 16:30:01 -0400 | [diff] [blame^] | 532 | /* Accept arbitrarily long scatter-gather lists */ |
| 533 | hcd->self.sg_tablesize = ~0; |
| 534 | |
Dmitry Baryshkov | 1133cd8 | 2008-07-06 23:35:01 +0400 | [diff] [blame] | 535 | if (distrust_firmware) |
| 536 | ohci->flags |= OHCI_QUIRK_HUB_POWER; |
| 537 | |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 538 | ohci->rh_state = OHCI_RH_HALTED; |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 539 | ohci->regs = hcd->regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 541 | /* REVISIT this BIOS handshake is now moved into PCI "quirks", and |
| 542 | * was never needed for most non-PCI systems ... remove the code? |
| 543 | */ |
| 544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | #ifndef IR_DISABLE |
| 546 | /* SMM owns the HC? not for long! */ |
| 547 | if (!no_handshake && ohci_readl (ohci, |
| 548 | &ohci->regs->control) & OHCI_CTRL_IR) { |
| 549 | u32 temp; |
| 550 | |
| 551 | ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n"); |
| 552 | |
| 553 | /* this timeout is arbitrary. we make it long, so systems |
| 554 | * depending on usb keyboards may be usable even if the |
| 555 | * BIOS/SMM code seems pretty broken. |
| 556 | */ |
| 557 | temp = 500; /* arbitrary: five seconds */ |
| 558 | |
| 559 | ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable); |
| 560 | ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus); |
| 561 | while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) { |
| 562 | msleep (10); |
| 563 | if (--temp == 0) { |
| 564 | ohci_err (ohci, "USB HC takeover failed!" |
| 565 | " (BIOS/SMM bug)\n"); |
| 566 | return -EBUSY; |
| 567 | } |
| 568 | } |
| 569 | ohci_usb_reset (ohci); |
| 570 | } |
| 571 | #endif |
| 572 | |
| 573 | /* Disable HC interrupts */ |
| 574 | ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 575 | |
| 576 | /* flush the writes, and save key bits like RWC */ |
| 577 | if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC) |
| 578 | ohci->hc_control |= OHCI_CTRL_RWC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 580 | /* Read the number of ports unless overridden */ |
| 581 | if (ohci->num_ports == 0) |
| 582 | ohci->num_ports = roothub_a(ohci) & RH_A_NDP; |
| 583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | if (ohci->hcca) |
| 585 | return 0; |
| 586 | |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 587 | ohci->hcca = dma_alloc_coherent (hcd->self.controller, |
Vladimir Zapolskiy | 4428524 | 2014-07-03 21:37:41 +0300 | [diff] [blame] | 588 | sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | if (!ohci->hcca) |
| 590 | return -ENOMEM; |
| 591 | |
| 592 | if ((ret = ohci_mem_init (ohci)) < 0) |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 593 | ohci_stop (hcd); |
| 594 | else { |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 595 | create_debug_files (ohci); |
| 596 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /*-------------------------------------------------------------------------*/ |
| 602 | |
| 603 | /* Start an OHCI controller, set the BUS operational |
| 604 | * resets USB and controller |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 605 | * enable interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | */ |
| 607 | static int ohci_run (struct ohci_hcd *ohci) |
| 608 | { |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 609 | u32 mask, val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | int first = ohci->fminterval == 0; |
David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 611 | struct usb_hcd *hcd = ohci_to_hcd(ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 613 | ohci->rh_state = OHCI_RH_HALTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
| 615 | /* boot firmware should have set this up (5.1.1.3.1) */ |
| 616 | if (first) { |
| 617 | |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 618 | val = ohci_readl (ohci, &ohci->regs->fminterval); |
| 619 | ohci->fminterval = val & 0x3fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | if (ohci->fminterval != FI) |
| 621 | ohci_dbg (ohci, "fminterval delta %d\n", |
| 622 | ohci->fminterval - FI); |
| 623 | ohci->fminterval |= FSMP (ohci->fminterval) << 16; |
| 624 | /* also: power/overcurrent flags in roothub.a */ |
| 625 | } |
| 626 | |
Alan Stern | 6fd9086 | 2008-12-17 17:20:38 -0500 | [diff] [blame] | 627 | /* Reset USB nearly "by the book". RemoteWakeupConnected has |
| 628 | * to be checked in case boot firmware (BIOS/SMM/...) has set up |
| 629 | * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM). |
| 630 | * If the bus glue detected wakeup capability then it should |
Alan Stern | bcca06e | 2009-01-13 11:35:54 -0500 | [diff] [blame] | 631 | * already be enabled; if so we'll just enable it again. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | */ |
Alan Stern | bcca06e | 2009-01-13 11:35:54 -0500 | [diff] [blame] | 633 | if ((ohci->hc_control & OHCI_CTRL_RWC) != 0) |
| 634 | device_set_wakeup_capable(hcd->self.controller, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | switch (ohci->hc_control & OHCI_CTRL_HCFS) { |
| 637 | case OHCI_USB_OPER: |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 638 | val = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | break; |
| 640 | case OHCI_USB_SUSPEND: |
| 641 | case OHCI_USB_RESUME: |
| 642 | ohci->hc_control &= OHCI_CTRL_RWC; |
| 643 | ohci->hc_control |= OHCI_USB_RESUME; |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 644 | val = 10 /* msec wait */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | break; |
| 646 | // case OHCI_USB_RESET: |
| 647 | default: |
| 648 | ohci->hc_control &= OHCI_CTRL_RWC; |
| 649 | ohci->hc_control |= OHCI_USB_RESET; |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 650 | val = 50 /* msec wait */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | break; |
| 652 | } |
| 653 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); |
| 654 | // flush the writes |
| 655 | (void) ohci_readl (ohci, &ohci->regs->control); |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 656 | msleep(val); |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | memset (ohci->hcca, 0, sizeof (struct ohci_hcca)); |
| 659 | |
| 660 | /* 2msec timelimit here means no irqs/preempt */ |
| 661 | spin_lock_irq (&ohci->lock); |
| 662 | |
| 663 | retry: |
| 664 | /* HC Reset requires max 10 us delay */ |
| 665 | ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus); |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 666 | val = 30; /* ... allow extra time */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) { |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 668 | if (--val == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | spin_unlock_irq (&ohci->lock); |
| 670 | ohci_err (ohci, "USB HC reset timed out!\n"); |
| 671 | return -1; |
| 672 | } |
| 673 | udelay (1); |
| 674 | } |
| 675 | |
| 676 | /* now we're in the SUSPEND state ... must go OPERATIONAL |
| 677 | * within 2msec else HC enters RESUME |
| 678 | * |
| 679 | * ... but some hardware won't init fmInterval "by the book" |
| 680 | * (SiS, OPTi ...), so reset again instead. SiS doesn't need |
| 681 | * this if we write fmInterval after we're OPERATIONAL. |
| 682 | * Unclear about ALi, ServerWorks, and others ... this could |
| 683 | * easily be a longstanding bug in chip init on Linux. |
| 684 | */ |
| 685 | if (ohci->flags & OHCI_QUIRK_INITRESET) { |
| 686 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); |
| 687 | // flush those writes |
| 688 | (void) ohci_readl (ohci, &ohci->regs->control); |
| 689 | } |
| 690 | |
| 691 | /* Tell the controller where the control and bulk lists are |
| 692 | * The lists are empty now. */ |
| 693 | ohci_writel (ohci, 0, &ohci->regs->ed_controlhead); |
| 694 | ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead); |
| 695 | |
| 696 | /* a reset clears this */ |
| 697 | ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca); |
| 698 | |
| 699 | periodic_reinit (ohci); |
| 700 | |
| 701 | /* some OHCI implementations are finicky about how they init. |
| 702 | * bogus values here mean not even enumeration could work. |
| 703 | */ |
| 704 | if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0 |
| 705 | || !ohci_readl (ohci, &ohci->regs->periodicstart)) { |
| 706 | if (!(ohci->flags & OHCI_QUIRK_INITRESET)) { |
| 707 | ohci->flags |= OHCI_QUIRK_INITRESET; |
| 708 | ohci_dbg (ohci, "enabling initreset quirk\n"); |
| 709 | goto retry; |
| 710 | } |
| 711 | spin_unlock_irq (&ohci->lock); |
| 712 | ohci_err (ohci, "init err (%08x %04x)\n", |
| 713 | ohci_readl (ohci, &ohci->regs->fminterval), |
| 714 | ohci_readl (ohci, &ohci->regs->periodicstart)); |
| 715 | return -EOVERFLOW; |
| 716 | } |
| 717 | |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 718 | /* use rhsc irqs after khubd is fully initialized */ |
Alan Stern | 541c7d4 | 2010-06-22 16:39:10 -0400 | [diff] [blame] | 719 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 720 | hcd->uses_new_polling = 1; |
| 721 | |
| 722 | /* start controller operations */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | ohci->hc_control &= OHCI_CTRL_RWC; |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 724 | ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER; |
| 725 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 726 | ohci->rh_state = OHCI_RH_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
| 728 | /* wake on ConnectStatusChange, matching external hubs */ |
| 729 | ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status); |
| 730 | |
| 731 | /* Choose the interrupts we care about now, others later on demand */ |
| 732 | mask = OHCI_INTR_INIT; |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 733 | ohci_writel (ohci, ~0, &ohci->regs->intrstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | ohci_writel (ohci, mask, &ohci->regs->intrenable); |
| 735 | |
| 736 | /* handle root hub init quirks ... */ |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 737 | val = roothub_a (ohci); |
| 738 | val &= ~(RH_A_PSM | RH_A_OCPM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | if (ohci->flags & OHCI_QUIRK_SUPERIO) { |
| 740 | /* NSC 87560 and maybe others */ |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 741 | val |= RH_A_NOCP; |
| 742 | val &= ~(RH_A_POTPGT | RH_A_NPS); |
| 743 | ohci_writel (ohci, val, &ohci->regs->roothub.a); |
Dmitry Baryshkov | 1133cd8 | 2008-07-06 23:35:01 +0400 | [diff] [blame] | 744 | } else if ((ohci->flags & OHCI_QUIRK_AMD756) || |
| 745 | (ohci->flags & OHCI_QUIRK_HUB_POWER)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | /* hub power always on; required for AMD-756 and some |
| 747 | * Mac platforms. ganged overcurrent reporting, if any. |
| 748 | */ |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 749 | val |= RH_A_NPS; |
| 750 | ohci_writel (ohci, val, &ohci->regs->roothub.a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status); |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 753 | ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | &ohci->regs->roothub.b); |
| 755 | // flush those writes |
| 756 | (void) ohci_readl (ohci, &ohci->regs->control); |
| 757 | |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 758 | ohci->next_statechange = jiffies + STATECHANGE_DELAY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | spin_unlock_irq (&ohci->lock); |
| 760 | |
| 761 | // POTPGT delay is bits 24-31, in 2 ms units. |
H Hartley Sweeten | 96f90a8 | 2009-04-22 16:18:59 -0400 | [diff] [blame] | 762 | mdelay ((val >> 23) & 0x1fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 764 | if (quirk_zfmicro(ohci)) { |
| 765 | /* Create timer to watch for bad queue state on ZF Micro */ |
| 766 | setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func, |
| 767 | (unsigned long) ohci); |
| 768 | |
| 769 | ohci->eds_scheduled = 0; |
| 770 | ohci->ed_to_check = NULL; |
| 771 | } |
| 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | ohci_dump (ohci, 1); |
| 774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | return 0; |
| 776 | } |
| 777 | |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 778 | /* ohci_setup routine for generic controller initialization */ |
| 779 | |
| 780 | int ohci_setup(struct usb_hcd *hcd) |
| 781 | { |
| 782 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 783 | |
| 784 | ohci_hcd_init(ohci); |
| 785 | |
| 786 | return ohci_init(ohci); |
| 787 | } |
| 788 | EXPORT_SYMBOL_GPL(ohci_setup); |
| 789 | |
| 790 | /* ohci_start routine for generic controller start of all OHCI bus glue */ |
| 791 | static int ohci_start(struct usb_hcd *hcd) |
| 792 | { |
| 793 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 794 | int ret; |
| 795 | |
| 796 | ret = ohci_run(ohci); |
| 797 | if (ret < 0) { |
| 798 | ohci_err(ohci, "can't start\n"); |
| 799 | ohci_stop(hcd); |
| 800 | } |
| 801 | return ret; |
| 802 | } |
| 803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | /*-------------------------------------------------------------------------*/ |
| 805 | |
| 806 | /* an interrupt happens */ |
| 807 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 808 | static irqreturn_t ohci_irq (struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | { |
| 810 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 811 | struct ohci_regs __iomem *regs = ohci->regs; |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 812 | int ints; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | |
Benjamin Herrenschmidt | 565227c | 2007-12-06 13:28:25 -0800 | [diff] [blame] | 814 | /* Read interrupt status (and flush pending writes). We ignore the |
| 815 | * optimization of checking the LSB of hcca->done_head; it doesn't |
| 816 | * work on all systems (edge triggering for OHCI can be a factor). |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 817 | */ |
Benjamin Herrenschmidt | 565227c | 2007-12-06 13:28:25 -0800 | [diff] [blame] | 818 | ints = ohci_readl(ohci, ®s->intrstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
Benjamin Herrenschmidt | 565227c | 2007-12-06 13:28:25 -0800 | [diff] [blame] | 820 | /* Check for an all 1's result which is a typical consequence |
| 821 | * of dead, unclocked, or unplugged (CardBus...) devices |
| 822 | */ |
| 823 | if (ints == ~(u32)0) { |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 824 | ohci->rh_state = OHCI_RH_HALTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | ohci_dbg (ohci, "device removed!\n"); |
Alan Stern | 69fff59 | 2011-05-17 17:27:12 -0400 | [diff] [blame] | 826 | usb_hc_died(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | return IRQ_HANDLED; |
Benjamin Herrenschmidt | 565227c | 2007-12-06 13:28:25 -0800 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /* We only care about interrupts that are enabled */ |
| 831 | ints &= ohci_readl(ohci, ®s->intrenable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
| 833 | /* interrupt for some other device? */ |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 834 | if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | return IRQ_NOTMINE; |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | if (ints & OHCI_INTR_UE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | // e.g. due to PCI Master/Target Abort |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 839 | if (quirk_nec(ohci)) { |
Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 840 | /* Workaround for a silicon bug in some NEC chips used |
| 841 | * in Apple's PowerBooks. Adapted from Darwin code. |
| 842 | */ |
| 843 | ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n"); |
| 844 | |
| 845 | ohci_writel (ohci, OHCI_INTR_UE, ®s->intrdisable); |
| 846 | |
| 847 | schedule_work (&ohci->nec_work); |
| 848 | } else { |
Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 849 | ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n"); |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 850 | ohci->rh_state = OHCI_RH_HALTED; |
Alan Stern | 69fff59 | 2011-05-17 17:27:12 -0400 | [diff] [blame] | 851 | usb_hc_died(hcd); |
Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 852 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
| 854 | ohci_dump (ohci, 1); |
| 855 | ohci_usb_reset (ohci); |
| 856 | } |
| 857 | |
Alan Stern | 583cead | 2006-10-24 12:04:22 -0400 | [diff] [blame] | 858 | if (ints & OHCI_INTR_RHSC) { |
Oliver Neukum | d2c4254 | 2013-11-18 13:22:58 +0100 | [diff] [blame] | 859 | ohci_dbg(ohci, "rhsc\n"); |
Alan Stern | 583cead | 2006-10-24 12:04:22 -0400 | [diff] [blame] | 860 | ohci->next_statechange = jiffies + STATECHANGE_DELAY; |
| 861 | ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC, |
| 862 | ®s->intrstatus); |
Alan Stern | 052ac01 | 2006-10-27 10:33:11 -0400 | [diff] [blame] | 863 | |
| 864 | /* NOTE: Vendors didn't always make the same implementation |
| 865 | * choices for RHSC. Many followed the spec; RHSC triggers |
| 866 | * on an edge, like setting and maybe clearing a port status |
| 867 | * change bit. With others it's level-triggered, active |
| 868 | * until khubd clears all the port status change bits. We'll |
| 869 | * always disable it here and rely on polling until khubd |
| 870 | * re-enables it. |
| 871 | */ |
| 872 | ohci_writel(ohci, OHCI_INTR_RHSC, ®s->intrdisable); |
Alan Stern | 583cead | 2006-10-24 12:04:22 -0400 | [diff] [blame] | 873 | usb_hcd_poll_rh_status(hcd); |
| 874 | } |
| 875 | |
| 876 | /* For connect and disconnect events, we expect the controller |
| 877 | * to turn on RHSC along with RD. But for remote wakeup events |
| 878 | * this might not happen. |
| 879 | */ |
| 880 | else if (ints & OHCI_INTR_RD) { |
Oliver Neukum | d2c4254 | 2013-11-18 13:22:58 +0100 | [diff] [blame] | 881 | ohci_dbg(ohci, "resume detect\n"); |
Alan Stern | 583cead | 2006-10-24 12:04:22 -0400 | [diff] [blame] | 882 | ohci_writel(ohci, OHCI_INTR_RD, ®s->intrstatus); |
Alan Stern | 541c7d4 | 2010-06-22 16:39:10 -0400 | [diff] [blame] | 883 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 884 | if (ohci->autostop) { |
| 885 | spin_lock (&ohci->lock); |
| 886 | ohci_rh_resume (ohci); |
| 887 | spin_unlock (&ohci->lock); |
| 888 | } else |
David Brownell | f197b2c | 2005-09-22 22:42:53 -0700 | [diff] [blame] | 889 | usb_hcd_resume_root_hub(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | if (ints & OHCI_INTR_WDH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | spin_lock (&ohci->lock); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 894 | dl_done_list (ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | spin_unlock (&ohci->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | } |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 897 | |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 898 | if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) { |
| 899 | spin_lock(&ohci->lock); |
| 900 | if (ohci->ed_to_check) { |
| 901 | struct ed *ed = ohci->ed_to_check; |
| 902 | |
| 903 | if (check_ed(ohci, ed)) { |
| 904 | /* HC thinks the TD list is empty; HCD knows |
| 905 | * at least one TD is outstanding |
| 906 | */ |
| 907 | if (--ohci->zf_delay == 0) { |
| 908 | struct td *td = list_entry( |
| 909 | ed->td_list.next, |
| 910 | struct td, td_list); |
| 911 | ohci_warn(ohci, |
| 912 | "Reclaiming orphan TD %p\n", |
| 913 | td); |
| 914 | takeback_td(ohci, td); |
| 915 | ohci->ed_to_check = NULL; |
| 916 | } |
| 917 | } else |
| 918 | ohci->ed_to_check = NULL; |
| 919 | } |
| 920 | spin_unlock(&ohci->lock); |
| 921 | } |
| 922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | /* could track INTR_SO to reduce available PCI/... bandwidth */ |
| 924 | |
| 925 | /* handle any pending URB/ED unlinks, leaving INTR_SF enabled |
| 926 | * when there's still unlinking to be done (next frame). |
| 927 | */ |
| 928 | spin_lock (&ohci->lock); |
| 929 | if (ohci->ed_rm_list) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 930 | finish_unlinks (ohci, ohci_frame_no(ohci)); |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 931 | if ((ints & OHCI_INTR_SF) != 0 |
| 932 | && !ohci->ed_rm_list |
| 933 | && !ohci->ed_to_check |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 934 | && ohci->rh_state == OHCI_RH_RUNNING) |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 935 | ohci_writel (ohci, OHCI_INTR_SF, ®s->intrdisable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | spin_unlock (&ohci->lock); |
| 937 | |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 938 | if (ohci->rh_state == OHCI_RH_RUNNING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | ohci_writel (ohci, ints, ®s->intrstatus); |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 940 | ohci_writel (ohci, OHCI_INTR_MIE, ®s->intrenable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | // flush those writes |
| 942 | (void) ohci_readl (ohci, &ohci->regs->control); |
| 943 | } |
| 944 | |
| 945 | return IRQ_HANDLED; |
| 946 | } |
| 947 | |
| 948 | /*-------------------------------------------------------------------------*/ |
| 949 | |
| 950 | static void ohci_stop (struct usb_hcd *hcd) |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 951 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | ohci_dump (ohci, 1); |
| 955 | |
Tejun Heo | 569ff2d | 2010-12-24 16:14:20 +0100 | [diff] [blame] | 956 | if (quirk_nec(ohci)) |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 957 | flush_work(&ohci->nec_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
caizhiyong | 435932f | 2013-07-26 07:12:14 +0000 | [diff] [blame] | 960 | ohci_usb_reset(ohci); |
Pete Zaitcev | 71795c1 | 2006-09-18 22:57:22 -0700 | [diff] [blame] | 961 | free_irq(hcd->irq, hcd); |
Felipe Balbi | cd70469 | 2012-02-29 16:46:23 +0200 | [diff] [blame] | 962 | hcd->irq = 0; |
Pete Zaitcev | 71795c1 | 2006-09-18 22:57:22 -0700 | [diff] [blame] | 963 | |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 964 | if (quirk_zfmicro(ohci)) |
| 965 | del_timer(&ohci->unlink_watchdog); |
Libin Yang | ab1666c | 2008-08-08 15:03:31 +0800 | [diff] [blame] | 966 | if (quirk_amdiso(ohci)) |
Andiry Xu | ad93562 | 2011-03-01 14:57:05 +0800 | [diff] [blame] | 967 | usb_amd_dev_put(); |
Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | remove_debug_files (ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | ohci_mem_cleanup (ohci); |
| 971 | if (ohci->hcca) { |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 972 | dma_free_coherent (hcd->self.controller, |
| 973 | sizeof *ohci->hcca, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | ohci->hcca, ohci->hcca_dma); |
| 975 | ohci->hcca = NULL; |
| 976 | ohci->hcca_dma = 0; |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | /*-------------------------------------------------------------------------*/ |
| 981 | |
David Brownell | da6fb57 | 2007-10-24 17:23:42 -0700 | [diff] [blame] | 982 | #if defined(CONFIG_PM) || defined(CONFIG_PCI) |
| 983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | /* must not be called from interrupt context */ |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 985 | int ohci_restart(struct ohci_hcd *ohci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | { |
| 987 | int temp; |
| 988 | int i; |
| 989 | struct urb_priv *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 991 | ohci_init(ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | spin_lock_irq(&ohci->lock); |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 993 | ohci->rh_state = OHCI_RH_HALTED; |
Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 994 | |
| 995 | /* Recycle any "live" eds/tds (and urbs). */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | if (!list_empty (&ohci->pending)) |
| 997 | ohci_dbg(ohci, "abort schedule...\n"); |
| 998 | list_for_each_entry (priv, &ohci->pending, pending) { |
| 999 | struct urb *urb = priv->td[0]->urb; |
| 1000 | struct ed *ed = priv->ed; |
| 1001 | |
| 1002 | switch (ed->state) { |
| 1003 | case ED_OPER: |
| 1004 | ed->state = ED_UNLINK; |
| 1005 | ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE); |
| 1006 | ed_deschedule (ohci, ed); |
| 1007 | |
| 1008 | ed->ed_next = ohci->ed_rm_list; |
| 1009 | ed->ed_prev = NULL; |
| 1010 | ohci->ed_rm_list = ed; |
| 1011 | /* FALLTHROUGH */ |
| 1012 | case ED_UNLINK: |
| 1013 | break; |
| 1014 | default: |
| 1015 | ohci_dbg(ohci, "bogus ed %p state %d\n", |
| 1016 | ed, ed->state); |
| 1017 | } |
| 1018 | |
Alan Stern | 55d8496 | 2007-08-24 15:40:34 -0400 | [diff] [blame] | 1019 | if (!urb->unlinked) |
| 1020 | urb->unlinked = -ESHUTDOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1022 | finish_unlinks (ohci, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | spin_unlock_irq(&ohci->lock); |
| 1024 | |
| 1025 | /* paranoia, in case that didn't work: */ |
| 1026 | |
| 1027 | /* empty the interrupt branches */ |
| 1028 | for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0; |
| 1029 | 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] | 1030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | /* no EDs to remove */ |
| 1032 | ohci->ed_rm_list = NULL; |
| 1033 | |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 1034 | /* empty control and bulk lists */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | ohci->ed_controltail = NULL; |
| 1036 | ohci->ed_bulktail = NULL; |
| 1037 | |
| 1038 | if ((temp = ohci_run (ohci)) < 0) { |
| 1039 | ohci_err (ohci, "can't restart, %d\n", temp); |
| 1040 | return temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 1042 | ohci_dbg(ohci, "restart complete\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | return 0; |
| 1044 | } |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 1045 | EXPORT_SYMBOL_GPL(ohci_restart); |
Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 1046 | |
David Brownell | da6fb57 | 2007-10-24 17:23:42 -0700 | [diff] [blame] | 1047 | #endif |
| 1048 | |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1049 | #ifdef CONFIG_PM |
| 1050 | |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 1051 | int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup) |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1052 | { |
| 1053 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 1054 | unsigned long flags; |
Majunath Goudar | e1bffbf | 2013-11-13 17:40:16 +0530 | [diff] [blame] | 1055 | int rc = 0; |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1056 | |
Florian Fainelli | d4ae47d | 2012-10-08 15:11:28 +0200 | [diff] [blame] | 1057 | /* Disable irq emission and mark HW unaccessible. Use |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1058 | * the spinlock to properly synchronize with possible pending |
| 1059 | * RH suspend or resume activity. |
| 1060 | */ |
| 1061 | spin_lock_irqsave (&ohci->lock, flags); |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1062 | ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
| 1063 | (void)ohci_readl(ohci, &ohci->regs->intrdisable); |
| 1064 | |
| 1065 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1066 | spin_unlock_irqrestore (&ohci->lock, flags); |
| 1067 | |
Majunath Goudar | e1bffbf | 2013-11-13 17:40:16 +0530 | [diff] [blame] | 1068 | synchronize_irq(hcd->irq); |
| 1069 | |
| 1070 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) { |
| 1071 | ohci_resume(hcd, false); |
| 1072 | rc = -EBUSY; |
| 1073 | } |
| 1074 | return rc; |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1075 | } |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 1076 | EXPORT_SYMBOL_GPL(ohci_suspend); |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1077 | |
| 1078 | |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 1079 | int ohci_resume(struct usb_hcd *hcd, bool hibernated) |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1080 | { |
Florian Fainelli | cfa49b4 | 2012-10-08 15:11:29 +0200 | [diff] [blame] | 1081 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 1082 | int port; |
| 1083 | bool need_reinit = false; |
| 1084 | |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1085 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 1086 | |
| 1087 | /* Make sure resume from hibernation re-enumerates everything */ |
| 1088 | if (hibernated) |
Florian Fainelli | cfa49b4 | 2012-10-08 15:11:29 +0200 | [diff] [blame] | 1089 | ohci_usb_reset(ohci); |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1090 | |
Florian Fainelli | cfa49b4 | 2012-10-08 15:11:29 +0200 | [diff] [blame] | 1091 | /* See if the controller is already running or has been reset */ |
| 1092 | ohci->hc_control = ohci_readl(ohci, &ohci->regs->control); |
| 1093 | if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { |
| 1094 | need_reinit = true; |
| 1095 | } else { |
| 1096 | switch (ohci->hc_control & OHCI_CTRL_HCFS) { |
| 1097 | case OHCI_USB_OPER: |
| 1098 | case OHCI_USB_RESET: |
| 1099 | need_reinit = true; |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | /* If needed, reinitialize and suspend the root hub */ |
| 1104 | if (need_reinit) { |
| 1105 | spin_lock_irq(&ohci->lock); |
| 1106 | ohci_rh_resume(ohci); |
| 1107 | ohci_rh_suspend(ohci, 0); |
| 1108 | spin_unlock_irq(&ohci->lock); |
| 1109 | } |
| 1110 | |
| 1111 | /* Normally just turn on port power and enable interrupts */ |
| 1112 | else { |
| 1113 | ohci_dbg(ohci, "powerup ports\n"); |
| 1114 | for (port = 0; port < ohci->num_ports; port++) |
| 1115 | ohci_writel(ohci, RH_PS_PPS, |
| 1116 | &ohci->regs->roothub.portstatus[port]); |
| 1117 | |
| 1118 | ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable); |
| 1119 | ohci_readl(ohci, &ohci->regs->intrenable); |
| 1120 | msleep(20); |
| 1121 | } |
| 1122 | |
| 1123 | usb_hcd_resume_root_hub(hcd); |
| 1124 | |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1125 | return 0; |
| 1126 | } |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 1127 | EXPORT_SYMBOL_GPL(ohci_resume); |
Florian Fainelli | cd1965d | 2012-10-08 15:11:27 +0200 | [diff] [blame] | 1128 | |
| 1129 | #endif |
| 1130 | |
Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 1131 | /*-------------------------------------------------------------------------*/ |
| 1132 | |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 1133 | /* |
| 1134 | * Generic structure: This gets copied for platform drivers so that |
| 1135 | * individual entries can be overridden as needed. |
| 1136 | */ |
| 1137 | |
| 1138 | static const struct hc_driver ohci_hc_driver = { |
| 1139 | .description = hcd_name, |
| 1140 | .product_desc = "OHCI Host Controller", |
| 1141 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 1142 | |
| 1143 | /* |
| 1144 | * generic hardware linkage |
| 1145 | */ |
| 1146 | .irq = ohci_irq, |
| 1147 | .flags = HCD_MEMORY | HCD_USB11, |
| 1148 | |
| 1149 | /* |
| 1150 | * basic lifecycle operations |
| 1151 | */ |
| 1152 | .reset = ohci_setup, |
| 1153 | .start = ohci_start, |
| 1154 | .stop = ohci_stop, |
| 1155 | .shutdown = ohci_shutdown, |
| 1156 | |
| 1157 | /* |
| 1158 | * managing i/o requests and associated device resources |
| 1159 | */ |
| 1160 | .urb_enqueue = ohci_urb_enqueue, |
| 1161 | .urb_dequeue = ohci_urb_dequeue, |
| 1162 | .endpoint_disable = ohci_endpoint_disable, |
| 1163 | |
| 1164 | /* |
| 1165 | * scheduling support |
| 1166 | */ |
| 1167 | .get_frame_number = ohci_get_frame, |
| 1168 | |
| 1169 | /* |
| 1170 | * root hub support |
| 1171 | */ |
| 1172 | .hub_status_data = ohci_hub_status_data, |
| 1173 | .hub_control = ohci_hub_control, |
| 1174 | #ifdef CONFIG_PM |
| 1175 | .bus_suspend = ohci_bus_suspend, |
| 1176 | .bus_resume = ohci_bus_resume, |
| 1177 | #endif |
| 1178 | .start_port_reset = ohci_start_port_reset, |
| 1179 | }; |
| 1180 | |
| 1181 | void ohci_init_driver(struct hc_driver *drv, |
| 1182 | const struct ohci_driver_overrides *over) |
| 1183 | { |
| 1184 | /* Copy the generic table to drv and then apply the overrides */ |
| 1185 | *drv = ohci_hc_driver; |
| 1186 | |
Kevin Hilman | c80ad6d | 2013-09-27 08:10:32 -0700 | [diff] [blame] | 1187 | if (over) { |
| 1188 | drv->product_desc = over->product_desc; |
| 1189 | drv->hcd_priv_size += over->extra_priv_size; |
| 1190 | if (over->reset) |
| 1191 | drv->reset = over->reset; |
| 1192 | } |
Manjunath Goudar | 95e44d4 | 2013-05-28 18:34:49 +0530 | [diff] [blame] | 1193 | } |
| 1194 | EXPORT_SYMBOL_GPL(ohci_init_driver); |
| 1195 | |
| 1196 | /*-------------------------------------------------------------------------*/ |
| 1197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | MODULE_AUTHOR (DRIVER_AUTHOR); |
Alan Stern | 2b70f07 | 2008-10-02 11:47:15 -0400 | [diff] [blame] | 1199 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | MODULE_LICENSE ("GPL"); |
| 1201 | |
Eric Miao | 6381fad | 2008-06-02 10:05:30 +0800 | [diff] [blame] | 1202 | #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | #include "ohci-sa1111.c" |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1204 | #define SA1111_DRIVER ohci_hcd_sa1111_driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | #endif |
| 1206 | |
Arnd Bergmann | 068413e | 2014-05-08 15:52:21 +0200 | [diff] [blame] | 1207 | #ifdef CONFIG_USB_OHCI_HCD_DAVINCI |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 1208 | #include "ohci-da8xx.c" |
Arnd Bergmann | 8097804 | 2013-04-25 19:29:04 +0200 | [diff] [blame] | 1209 | #define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver |
Sergei Shtylyov | efe7daf | 2010-02-12 23:52:34 +0400 | [diff] [blame] | 1210 | #endif |
| 1211 | |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 1212 | #ifdef CONFIG_USB_OHCI_HCD_PPC_OF |
| 1213 | #include "ohci-ppc-of.c" |
| 1214 | #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver |
| 1215 | #endif |
| 1216 | |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 1217 | #ifdef CONFIG_PPC_PS3 |
| 1218 | #include "ohci-ps3.c" |
Geoff Levand | 7a4eb7f | 2007-06-05 20:04:35 -0700 | [diff] [blame] | 1219 | #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 1220 | #endif |
| 1221 | |
Magnus Damm | f54aab6 | 2008-01-23 15:58:46 +0900 | [diff] [blame] | 1222 | #ifdef CONFIG_MFD_SM501 |
| 1223 | #include "ohci-sm501.c" |
Ben Dooks | 3ee38d8 | 2008-06-08 17:20:11 +0100 | [diff] [blame] | 1224 | #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver |
Magnus Damm | f54aab6 | 2008-01-23 15:58:46 +0900 | [diff] [blame] | 1225 | #endif |
| 1226 | |
Dmitry Baryshkov | 78c7341 | 2008-10-08 16:14:23 +0400 | [diff] [blame] | 1227 | #ifdef CONFIG_MFD_TC6393XB |
| 1228 | #include "ohci-tmio.c" |
| 1229 | #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver |
| 1230 | #endif |
| 1231 | |
Lars-Peter Clausen | 2249071 | 2010-06-19 04:08:24 +0000 | [diff] [blame] | 1232 | #ifdef CONFIG_MACH_JZ4740 |
| 1233 | #include "ohci-jz4740.c" |
| 1234 | #define PLATFORM_DRIVER ohci_hcd_jz4740_driver |
| 1235 | #endif |
| 1236 | |
David Daney | 1643acc | 2010-10-08 14:47:52 -0700 | [diff] [blame] | 1237 | #ifdef CONFIG_USB_OCTEON_OHCI |
| 1238 | #include "ohci-octeon.c" |
| 1239 | #define PLATFORM_DRIVER ohci_octeon_driver |
| 1240 | #endif |
| 1241 | |
Chris Metcalf | 47fc28b | 2012-05-09 13:58:14 -0400 | [diff] [blame] | 1242 | #ifdef CONFIG_TILE_USB |
| 1243 | #include "ohci-tilegx.c" |
| 1244 | #define PLATFORM_DRIVER ohci_hcd_tilegx_driver |
| 1245 | #endif |
| 1246 | |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1247 | static int __init ohci_hcd_mod_init(void) |
| 1248 | { |
| 1249 | int retval = 0; |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1250 | |
| 1251 | if (usb_disabled()) |
| 1252 | return -ENODEV; |
| 1253 | |
Alan Stern | 2b70f07 | 2008-10-02 11:47:15 -0400 | [diff] [blame] | 1254 | printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name); |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1255 | pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name, |
| 1256 | sizeof (struct ed), sizeof (struct td)); |
Alan Stern | 9beeee6 | 2008-10-02 11:48:13 -0400 | [diff] [blame] | 1257 | set_bit(USB_OHCI_LOADED, &usb_hcds_loaded); |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1258 | |
Greg Kroah-Hartman | 485f4f3 | 2009-04-24 15:14:38 -0700 | [diff] [blame] | 1259 | ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root); |
Tony Jones | 684c19e | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1260 | if (!ohci_debug_root) { |
| 1261 | retval = -ENOENT; |
| 1262 | goto error_debug; |
| 1263 | } |
Tony Jones | 684c19e | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1264 | |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 1265 | #ifdef PS3_SYSTEM_BUS_DRIVER |
Geoff Levand | 7a4eb7f | 2007-06-05 20:04:35 -0700 | [diff] [blame] | 1266 | retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER); |
| 1267 | if (retval < 0) |
| 1268 | goto error_ps3; |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 1269 | #endif |
| 1270 | |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1271 | #ifdef PLATFORM_DRIVER |
| 1272 | retval = platform_driver_register(&PLATFORM_DRIVER); |
| 1273 | if (retval < 0) |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 1274 | goto error_platform; |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1275 | #endif |
| 1276 | |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 1277 | #ifdef OF_PLATFORM_DRIVER |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 1278 | retval = platform_driver_register(&OF_PLATFORM_DRIVER); |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 1279 | if (retval < 0) |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 1280 | goto error_of_platform; |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 1281 | #endif |
| 1282 | |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1283 | #ifdef SA1111_DRIVER |
| 1284 | retval = sa1111_driver_register(&SA1111_DRIVER); |
| 1285 | if (retval < 0) |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 1286 | goto error_sa1111; |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1287 | #endif |
| 1288 | |
Ben Dooks | 3ee38d8 | 2008-06-08 17:20:11 +0100 | [diff] [blame] | 1289 | #ifdef SM501_OHCI_DRIVER |
| 1290 | retval = platform_driver_register(&SM501_OHCI_DRIVER); |
| 1291 | if (retval < 0) |
| 1292 | goto error_sm501; |
| 1293 | #endif |
| 1294 | |
Dmitry Baryshkov | 78c7341 | 2008-10-08 16:14:23 +0400 | [diff] [blame] | 1295 | #ifdef TMIO_OHCI_DRIVER |
| 1296 | retval = platform_driver_register(&TMIO_OHCI_DRIVER); |
| 1297 | if (retval < 0) |
| 1298 | goto error_tmio; |
| 1299 | #endif |
| 1300 | |
Arnd Bergmann | 8097804 | 2013-04-25 19:29:04 +0200 | [diff] [blame] | 1301 | #ifdef DAVINCI_PLATFORM_DRIVER |
| 1302 | retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER); |
| 1303 | if (retval < 0) |
| 1304 | goto error_davinci; |
| 1305 | #endif |
| 1306 | |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1307 | return retval; |
| 1308 | |
| 1309 | /* Error path */ |
Arnd Bergmann | 8097804 | 2013-04-25 19:29:04 +0200 | [diff] [blame] | 1310 | #ifdef DAVINCI_PLATFORM_DRIVER |
| 1311 | platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); |
| 1312 | error_davinci: |
| 1313 | #endif |
Dmitry Baryshkov | 78c7341 | 2008-10-08 16:14:23 +0400 | [diff] [blame] | 1314 | #ifdef TMIO_OHCI_DRIVER |
| 1315 | platform_driver_unregister(&TMIO_OHCI_DRIVER); |
| 1316 | error_tmio: |
| 1317 | #endif |
Ben Dooks | 3ee38d8 | 2008-06-08 17:20:11 +0100 | [diff] [blame] | 1318 | #ifdef SM501_OHCI_DRIVER |
Dmitry Baryshkov | 78c7341 | 2008-10-08 16:14:23 +0400 | [diff] [blame] | 1319 | platform_driver_unregister(&SM501_OHCI_DRIVER); |
Ben Dooks | 3ee38d8 | 2008-06-08 17:20:11 +0100 | [diff] [blame] | 1320 | error_sm501: |
| 1321 | #endif |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1322 | #ifdef SA1111_DRIVER |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 1323 | sa1111_driver_unregister(&SA1111_DRIVER); |
| 1324 | error_sa1111: |
| 1325 | #endif |
| 1326 | #ifdef OF_PLATFORM_DRIVER |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 1327 | platform_driver_unregister(&OF_PLATFORM_DRIVER); |
Benjamin Herrenschmidt | de44743 | 2007-01-15 20:12:06 -0800 | [diff] [blame] | 1328 | error_of_platform: |
| 1329 | #endif |
Arnd Bergmann | 8097804 | 2013-04-25 19:29:04 +0200 | [diff] [blame] | 1330 | #ifdef PLATFORM_DRIVER |
| 1331 | platform_driver_unregister(&PLATFORM_DRIVER); |
| 1332 | error_platform: |
Anand Gadiyar | 968b448 | 2010-05-10 21:56:12 +0530 | [diff] [blame] | 1333 | #endif |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 1334 | #ifdef PS3_SYSTEM_BUS_DRIVER |
Geoff Levand | 7a4eb7f | 2007-06-05 20:04:35 -0700 | [diff] [blame] | 1335 | ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 1336 | error_ps3: |
| 1337 | #endif |
Tony Jones | 684c19e | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1338 | debugfs_remove(ohci_debug_root); |
| 1339 | ohci_debug_root = NULL; |
| 1340 | error_debug: |
Tony Jones | 684c19e | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1341 | |
Alan Stern | 9beeee6 | 2008-10-02 11:48:13 -0400 | [diff] [blame] | 1342 | clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded); |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1343 | return retval; |
| 1344 | } |
| 1345 | module_init(ohci_hcd_mod_init); |
| 1346 | |
| 1347 | static void __exit ohci_hcd_mod_exit(void) |
| 1348 | { |
Arnd Bergmann | 8097804 | 2013-04-25 19:29:04 +0200 | [diff] [blame] | 1349 | #ifdef DAVINCI_PLATFORM_DRIVER |
| 1350 | platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); |
| 1351 | #endif |
Dmitry Baryshkov | 78c7341 | 2008-10-08 16:14:23 +0400 | [diff] [blame] | 1352 | #ifdef TMIO_OHCI_DRIVER |
| 1353 | platform_driver_unregister(&TMIO_OHCI_DRIVER); |
| 1354 | #endif |
Ben Dooks | 3ee38d8 | 2008-06-08 17:20:11 +0100 | [diff] [blame] | 1355 | #ifdef SM501_OHCI_DRIVER |
| 1356 | platform_driver_unregister(&SM501_OHCI_DRIVER); |
| 1357 | #endif |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1358 | #ifdef SA1111_DRIVER |
| 1359 | sa1111_driver_unregister(&SA1111_DRIVER); |
| 1360 | #endif |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 1361 | #ifdef OF_PLATFORM_DRIVER |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 1362 | platform_driver_unregister(&OF_PLATFORM_DRIVER); |
Sylvain Munaut | 495a678 | 2006-12-13 21:09:55 +0100 | [diff] [blame] | 1363 | #endif |
Arnd Bergmann | 8097804 | 2013-04-25 19:29:04 +0200 | [diff] [blame] | 1364 | #ifdef PLATFORM_DRIVER |
| 1365 | platform_driver_unregister(&PLATFORM_DRIVER); |
| 1366 | #endif |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 1367 | #ifdef PS3_SYSTEM_BUS_DRIVER |
Geoff Levand | 7a4eb7f | 2007-06-05 20:04:35 -0700 | [diff] [blame] | 1368 | ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
Geoff Levand | 6a6c957 | 2007-01-15 20:12:10 -0800 | [diff] [blame] | 1369 | #endif |
Tony Jones | 684c19e | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1370 | debugfs_remove(ohci_debug_root); |
Alan Stern | 9beeee6 | 2008-10-02 11:48:13 -0400 | [diff] [blame] | 1371 | clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded); |
Sylvain Munaut | 5e16fab | 2006-12-13 21:09:54 +0100 | [diff] [blame] | 1372 | } |
| 1373 | module_exit(ohci_hcd_mod_exit); |
| 1374 | |