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