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 | * Enhanced Host Controller Interface (EHCI) driver for USB. |
| 3 | * |
| 4 | * Maintainer: Alan Stern <stern@rowland.harvard.edu> |
| 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (c) 2000-2004 by David Brownell |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 16 | * for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software Foundation, |
| 20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/pci.h> |
| 25 | #include <linux/dmapool.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <linux/sched.h> |
Ming Lei | 3c04e20 | 2008-09-18 23:06:21 +0800 | [diff] [blame] | 30 | #include <linux/vmalloc.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> |
Oliver Neukum | ee4ecb8 | 2009-11-27 15:17:59 +0100 | [diff] [blame] | 34 | #include <linux/ktime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/list.h> |
| 36 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/usb.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 38 | #include <linux/usb/hcd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/moduleparam.h> |
| 40 | #include <linux/dma-mapping.h> |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 41 | #include <linux/debugfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Alek Du | aa4d834 | 2010-06-04 15:47:54 +0800 | [diff] [blame] | 43 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/byteorder.h> |
| 46 | #include <asm/io.h> |
| 47 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Geoff Levand | df7c1ca | 2011-11-30 16:40:57 -0800 | [diff] [blame] | 50 | #if defined(CONFIG_PPC_PS3) |
| 51 | #include <asm/firmware.h> |
| 52 | #endif |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /*-------------------------------------------------------------------------*/ |
| 55 | |
| 56 | /* |
| 57 | * EHCI hc_driver implementation ... experimental, incomplete. |
| 58 | * Based on the final 1.0 register interface specification. |
| 59 | * |
| 60 | * USB 2.0 shows up in upcoming www.pcmcia.org technology. |
| 61 | * First was PCMCIA, like ISA; then CardBus, which is PCI. |
| 62 | * Next comes "CardBay", using USB 2.0 signals. |
| 63 | * |
| 64 | * Contains additional contributions by Brad Hards, Rory Bolt, and others. |
| 65 | * Special thanks to Intel and VIA for providing host controllers to |
| 66 | * test this driver on, and Cypress (including In-System Design) for |
| 67 | * providing early devices for those host controllers to talk to! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | */ |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #define DRIVER_AUTHOR "David Brownell" |
| 71 | #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver" |
| 72 | |
| 73 | static const char hcd_name [] = "ehci_hcd"; |
| 74 | |
| 75 | |
David Brownell | 9776afc | 2008-02-01 11:42:05 -0800 | [diff] [blame] | 76 | #undef VERBOSE_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #undef EHCI_URB_TRACE |
| 78 | |
| 79 | #ifdef DEBUG |
| 80 | #define EHCI_STATS |
| 81 | #endif |
| 82 | |
| 83 | /* magic numbers that can affect system performance */ |
| 84 | #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ |
| 85 | #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */ |
| 86 | #define EHCI_TUNE_RL_TT 0 |
| 87 | #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ |
| 88 | #define EHCI_TUNE_MULT_TT 1 |
Alan Stern | ffda080 | 2010-07-14 11:03:46 -0400 | [diff] [blame] | 89 | /* |
| 90 | * Some drivers think it's safe to schedule isochronous transfers more than |
| 91 | * 256 ms into the future (partly as a result of an old bug in the scheduling |
| 92 | * code). In an attempt to avoid trouble, we will use a minimum scheduling |
| 93 | * length of 512 frames instead of 256. |
| 94 | */ |
| 95 | #define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 97 | #define EHCI_IAA_MSECS 10 /* arbitrary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ |
| 99 | #define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ |
Alan Stern | 004c196 | 2011-07-05 12:34:05 -0400 | [diff] [blame] | 100 | #define EHCI_SHRINK_JIFFIES (DIV_ROUND_UP(HZ, 200) + 1) |
Ming Lei | fcda37c | 2011-09-05 21:05:57 +0800 | [diff] [blame] | 101 | /* 5-ms async qh unlink delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | /* Initial IRQ latency: faster than hw default */ |
| 104 | static int log2_irq_thresh = 0; // 0 to 6 |
| 105 | module_param (log2_irq_thresh, int, S_IRUGO); |
| 106 | MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes"); |
| 107 | |
| 108 | /* initial park setting: slower than hw default */ |
| 109 | static unsigned park = 0; |
| 110 | module_param (park, uint, S_IRUGO); |
| 111 | MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets"); |
| 112 | |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 113 | /* for flakey hardware, ignore overcurrent indicators */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 114 | static bool ignore_oc = 0; |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 115 | module_param (ignore_oc, bool, S_IRUGO); |
| 116 | MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications"); |
| 117 | |
Alek Du | 48f2497 | 2010-06-04 15:47:55 +0800 | [diff] [blame] | 118 | /* for link power management(LPM) feature */ |
| 119 | static unsigned int hird; |
| 120 | module_param(hird, int, S_IRUGO); |
Niels de Vos | cc55687 | 2011-05-31 23:00:10 +0100 | [diff] [blame] | 121 | MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us"); |
Alek Du | 48f2497 | 2010-06-04 15:47:55 +0800 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) |
| 124 | |
| 125 | /*-------------------------------------------------------------------------*/ |
| 126 | |
| 127 | #include "ehci.h" |
| 128 | #include "ehci-dbg.c" |
Andiry Xu | ad93562 | 2011-03-01 14:57:05 +0800 | [diff] [blame] | 129 | #include "pci-quirks.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /*-------------------------------------------------------------------------*/ |
| 132 | |
Alan Stern | bc29847 | 2009-02-11 14:26:38 -0500 | [diff] [blame] | 133 | static void |
| 134 | timer_action(struct ehci_hcd *ehci, enum ehci_timer_action action) |
| 135 | { |
| 136 | /* Don't override timeouts which shrink or (later) disable |
| 137 | * the async ring; just the I/O watchdog. Note that if a |
| 138 | * SHRINK were pending, OFF would never be requested. |
| 139 | */ |
| 140 | if (timer_pending(&ehci->watchdog) |
| 141 | && ((BIT(TIMER_ASYNC_SHRINK) | BIT(TIMER_ASYNC_OFF)) |
| 142 | & ehci->actions)) |
| 143 | return; |
| 144 | |
| 145 | if (!test_and_set_bit(action, &ehci->actions)) { |
| 146 | unsigned long t; |
| 147 | |
| 148 | switch (action) { |
| 149 | case TIMER_IO_WATCHDOG: |
Alek Du | 403dbd3 | 2009-07-13 17:30:41 +0800 | [diff] [blame] | 150 | if (!ehci->need_io_watchdog) |
| 151 | return; |
Alan Stern | bc29847 | 2009-02-11 14:26:38 -0500 | [diff] [blame] | 152 | t = EHCI_IO_JIFFIES; |
| 153 | break; |
| 154 | case TIMER_ASYNC_OFF: |
| 155 | t = EHCI_ASYNC_JIFFIES; |
| 156 | break; |
| 157 | /* case TIMER_ASYNC_SHRINK: */ |
| 158 | default: |
Alan Stern | 004c196 | 2011-07-05 12:34:05 -0400 | [diff] [blame] | 159 | t = EHCI_SHRINK_JIFFIES; |
Alan Stern | bc29847 | 2009-02-11 14:26:38 -0500 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | mod_timer(&ehci->watchdog, t + jiffies); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /*-------------------------------------------------------------------------*/ |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* |
| 169 | * handshake - spin reading hc until handshake completes or fails |
| 170 | * @ptr: address of hc register to be read |
| 171 | * @mask: bits to look at in result of read |
| 172 | * @done: value of those bits when handshake succeeds |
| 173 | * @usec: timeout in microseconds |
| 174 | * |
| 175 | * Returns negative errno, or zero on success |
| 176 | * |
| 177 | * Success happens when the "mask" bits have the specified value (hardware |
| 178 | * handshake done). There are two failure modes: "usec" have passed (major |
| 179 | * hardware flakeout), or the register reads as all-ones (hardware removed). |
| 180 | * |
| 181 | * That last failure should_only happen in cases like physical cardbus eject |
| 182 | * before driver shutdown. But it also seems to be caused by bugs in cardbus |
| 183 | * bridge shutdown: shutting down the bridge before the devices using it. |
| 184 | */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 185 | static int handshake (struct ehci_hcd *ehci, void __iomem *ptr, |
| 186 | u32 mask, u32 done, int usec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | u32 result; |
| 189 | |
| 190 | do { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 191 | result = ehci_readl(ehci, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | if (result == ~(u32)0) /* card removed */ |
| 193 | return -ENODEV; |
| 194 | result &= mask; |
| 195 | if (result == done) |
| 196 | return 0; |
| 197 | udelay (1); |
| 198 | usec--; |
| 199 | } while (usec > 0); |
| 200 | return -ETIMEDOUT; |
| 201 | } |
| 202 | |
Matthieu CASTET | 65fd427 | 2010-09-06 18:26:56 +0200 | [diff] [blame] | 203 | /* check TDI/ARC silicon is in host mode */ |
| 204 | static int tdi_in_host_mode (struct ehci_hcd *ehci) |
| 205 | { |
Matthieu CASTET | 65fd427 | 2010-09-06 18:26:56 +0200 | [diff] [blame] | 206 | u32 tmp; |
| 207 | |
Alan Stern | a46af4e | 2012-06-25 12:19:03 -0400 | [diff] [blame] | 208 | tmp = ehci_readl(ehci, &ehci->regs->usbmode); |
Matthieu CASTET | 65fd427 | 2010-09-06 18:26:56 +0200 | [diff] [blame] | 209 | return (tmp & 3) == USBMODE_CM_HC; |
| 210 | } |
| 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* force HC to halt state from unknown (EHCI spec section 2.3) */ |
| 213 | static int ehci_halt (struct ehci_hcd *ehci) |
| 214 | { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 215 | u32 temp = ehci_readl(ehci, &ehci->regs->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
David Brownell | 72f30b6 | 2005-09-27 10:19:39 -0700 | [diff] [blame] | 217 | /* disable any irqs left enabled by previous code */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 218 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); |
David Brownell | 72f30b6 | 2005-09-27 10:19:39 -0700 | [diff] [blame] | 219 | |
Matthieu CASTET | 65fd427 | 2010-09-06 18:26:56 +0200 | [diff] [blame] | 220 | if (ehci_is_TDI(ehci) && tdi_in_host_mode(ehci) == 0) { |
| 221 | return 0; |
| 222 | } |
| 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | if ((temp & STS_HALT) != 0) |
| 225 | return 0; |
| 226 | |
Alan Stern | 3d9545c | 2012-04-23 13:54:36 -0400 | [diff] [blame] | 227 | /* |
| 228 | * This routine gets called during probe before ehci->command |
| 229 | * has been initialized, so we can't rely on its value. |
| 230 | */ |
| 231 | ehci->command &= ~CMD_RUN; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 232 | temp = ehci_readl(ehci, &ehci->regs->command); |
Alan Stern | 3d9545c | 2012-04-23 13:54:36 -0400 | [diff] [blame] | 233 | temp &= ~(CMD_RUN | CMD_IAAD); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 234 | ehci_writel(ehci, temp, &ehci->regs->command); |
| 235 | return handshake (ehci, &ehci->regs->status, |
| 236 | STS_HALT, STS_HALT, 16 * 125); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Geoff Levand | df7c1ca | 2011-11-30 16:40:57 -0800 | [diff] [blame] | 239 | #if defined(CONFIG_USB_SUSPEND) && defined(CONFIG_PPC_PS3) |
| 240 | |
| 241 | /* |
| 242 | * The EHCI controller of the Cell Super Companion Chip used in the |
| 243 | * PS3 will stop the root hub after all root hub ports are suspended. |
| 244 | * When in this condition handshake will return -ETIMEDOUT. The |
| 245 | * STS_HLT bit will not be set, so inspection of the frame index is |
| 246 | * used here to test for the condition. If the condition is found |
| 247 | * return success to allow the USB suspend to complete. |
| 248 | */ |
| 249 | |
| 250 | static int handshake_for_broken_root_hub(struct ehci_hcd *ehci, |
| 251 | void __iomem *ptr, u32 mask, u32 done, |
| 252 | int usec) |
| 253 | { |
| 254 | unsigned int old_index; |
| 255 | int error; |
| 256 | |
| 257 | if (!firmware_has_feature(FW_FEATURE_PS3_LV1)) |
| 258 | return -ETIMEDOUT; |
| 259 | |
| 260 | old_index = ehci_read_frame_index(ehci); |
| 261 | |
| 262 | error = handshake(ehci, ptr, mask, done, usec); |
| 263 | |
| 264 | if (error == -ETIMEDOUT && ehci_read_frame_index(ehci) == old_index) |
| 265 | return 0; |
| 266 | |
| 267 | return error; |
| 268 | } |
| 269 | |
| 270 | #else |
| 271 | |
| 272 | static int handshake_for_broken_root_hub(struct ehci_hcd *ehci, |
| 273 | void __iomem *ptr, u32 mask, u32 done, |
| 274 | int usec) |
| 275 | { |
| 276 | return -ETIMEDOUT; |
| 277 | } |
| 278 | |
| 279 | #endif |
| 280 | |
David Brownell | 0bcfeb3 | 2008-08-26 14:43:46 -0700 | [diff] [blame] | 281 | static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr, |
| 282 | u32 mask, u32 done, int usec) |
| 283 | { |
| 284 | int error; |
| 285 | |
| 286 | error = handshake(ehci, ptr, mask, done, usec); |
Geoff Levand | df7c1ca | 2011-11-30 16:40:57 -0800 | [diff] [blame] | 287 | if (error == -ETIMEDOUT) |
| 288 | error = handshake_for_broken_root_hub(ehci, ptr, mask, done, |
| 289 | usec); |
| 290 | |
David Brownell | 0bcfeb3 | 2008-08-26 14:43:46 -0700 | [diff] [blame] | 291 | if (error) { |
| 292 | ehci_halt(ehci); |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 293 | ehci->rh_state = EHCI_RH_HALTED; |
Ozan Çağlayan | 65cb76b | 2009-10-13 08:37:09 +0300 | [diff] [blame] | 294 | ehci_err(ehci, "force halt; handshake %p %08x %08x -> %d\n", |
David Brownell | 0bcfeb3 | 2008-08-26 14:43:46 -0700 | [diff] [blame] | 295 | ptr, mask, done, error); |
| 296 | } |
| 297 | |
| 298 | return error; |
| 299 | } |
| 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /* put TDI/ARC silicon into EHCI mode */ |
| 302 | static void tdi_reset (struct ehci_hcd *ehci) |
| 303 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | u32 tmp; |
| 305 | |
Alan Stern | a46af4e | 2012-06-25 12:19:03 -0400 | [diff] [blame] | 306 | tmp = ehci_readl(ehci, &ehci->regs->usbmode); |
Vladimir Barinov | d23a137 | 2007-05-23 20:07:48 +0400 | [diff] [blame] | 307 | tmp |= USBMODE_CM_HC; |
| 308 | /* The default byte access to MMR space is LE after |
| 309 | * controller reset. Set the required endian mode |
| 310 | * for transfer buffers to match the host microprocessor |
| 311 | */ |
| 312 | if (ehci_big_endian_mmio(ehci)) |
| 313 | tmp |= USBMODE_BE; |
Alan Stern | a46af4e | 2012-06-25 12:19:03 -0400 | [diff] [blame] | 314 | ehci_writel(ehci, tmp, &ehci->regs->usbmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /* reset a non-running (STS_HALT == 1) controller */ |
| 318 | static int ehci_reset (struct ehci_hcd *ehci) |
| 319 | { |
| 320 | int retval; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 321 | u32 command = ehci_readl(ehci, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Jason Wessel | 8d053c7 | 2009-08-20 15:39:54 -0500 | [diff] [blame] | 323 | /* If the EHCI debug controller is active, special care must be |
| 324 | * taken before and after a host controller reset */ |
| 325 | if (ehci->debug && !dbgp_reset_prep()) |
| 326 | ehci->debug = NULL; |
| 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | command |= CMD_RESET; |
| 329 | dbg_cmd (ehci, "reset", command); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 330 | ehci_writel(ehci, command, &ehci->regs->command); |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 331 | ehci->rh_state = EHCI_RH_HALTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | ehci->next_statechange = jiffies; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 333 | retval = handshake (ehci, &ehci->regs->command, |
| 334 | CMD_RESET, 0, 250 * 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 336 | if (ehci->has_hostpc) { |
| 337 | ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS, |
Alan Stern | a46af4e | 2012-06-25 12:19:03 -0400 | [diff] [blame] | 338 | &ehci->regs->usbmode_ex); |
| 339 | ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning); |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | if (retval) |
| 342 | return retval; |
| 343 | |
| 344 | if (ehci_is_TDI(ehci)) |
| 345 | tdi_reset (ehci); |
| 346 | |
Jason Wessel | 8d053c7 | 2009-08-20 15:39:54 -0500 | [diff] [blame] | 347 | if (ehci->debug) |
| 348 | dbgp_external_startup(); |
| 349 | |
Alan Stern | a448e4d | 2012-04-03 15:24:30 -0400 | [diff] [blame] | 350 | ehci->port_c_suspend = ehci->suspended_ports = |
| 351 | ehci->resuming_ports = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return retval; |
| 353 | } |
| 354 | |
| 355 | /* idle the controller (from running) */ |
| 356 | static void ehci_quiesce (struct ehci_hcd *ehci) |
| 357 | { |
| 358 | u32 temp; |
| 359 | |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 360 | if (ehci->rh_state != EHCI_RH_RUNNING) |
Alan Stern | c0c53db | 2012-07-11 11:21:48 -0400 | [diff] [blame^] | 361 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | /* wait for any schedule enables/disables to take effect */ |
Alan Stern | 3d9545c | 2012-04-23 13:54:36 -0400 | [diff] [blame] | 364 | temp = (ehci->command << 10) & (STS_ASS | STS_PSS); |
Karsten Wiese | c765d4c | 2008-02-16 13:44:42 -0800 | [diff] [blame] | 365 | if (handshake_on_error_set_halt(ehci, &ehci->regs->status, |
| 366 | STS_ASS | STS_PSS, temp, 16 * 125)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | /* then disable anything that's still active */ |
Alan Stern | 3d9545c | 2012-04-23 13:54:36 -0400 | [diff] [blame] | 370 | ehci->command &= ~(CMD_ASE | CMD_PSE); |
| 371 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | /* hardware can take 16 microframes to turn off ... */ |
Karsten Wiese | c765d4c | 2008-02-16 13:44:42 -0800 | [diff] [blame] | 374 | handshake_on_error_set_halt(ehci, &ehci->regs->status, |
| 375 | STS_ASS | STS_PSS, 0, 16 * 125); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /*-------------------------------------------------------------------------*/ |
| 379 | |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 380 | static void end_unlink_async(struct ehci_hcd *ehci); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 381 | static void ehci_work(struct ehci_hcd *ehci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | #include "ehci-hub.c" |
Alek Du | 48f2497 | 2010-06-04 15:47:55 +0800 | [diff] [blame] | 384 | #include "ehci-lpm.c" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | #include "ehci-mem.c" |
| 386 | #include "ehci-q.c" |
| 387 | #include "ehci-sched.c" |
Kirill Smelkov | 4c67045 | 2011-07-03 20:36:56 +0400 | [diff] [blame] | 388 | #include "ehci-sysfs.c" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | /*-------------------------------------------------------------------------*/ |
| 391 | |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 392 | static void ehci_iaa_watchdog(unsigned long param) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | { |
| 394 | struct ehci_hcd *ehci = (struct ehci_hcd *) param; |
| 395 | unsigned long flags; |
| 396 | |
| 397 | spin_lock_irqsave (&ehci->lock, flags); |
| 398 | |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 399 | /* Lost IAA irqs wedge things badly; seen first with a vt8235. |
| 400 | * So we need this watchdog, but must protect it against both |
| 401 | * (a) SMP races against real IAA firing and retriggering, and |
| 402 | * (b) clean HC shutdown, when IAA watchdog was pending. |
| 403 | */ |
Alan Stern | 99ac5b1 | 2012-07-11 11:21:38 -0400 | [diff] [blame] | 404 | if (ehci->async_unlink |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 405 | && !timer_pending(&ehci->iaa_watchdog) |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 406 | && ehci->rh_state == EHCI_RH_RUNNING) { |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 407 | u32 cmd, status; |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 408 | |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 409 | /* If we get here, IAA is *REALLY* late. It's barely |
| 410 | * conceivable that the system is so busy that CMD_IAAD |
| 411 | * is still legitimately set, so let's be sure it's |
| 412 | * clear before we read STS_IAA. (The HC should clear |
| 413 | * CMD_IAAD when it sets STS_IAA.) |
| 414 | */ |
| 415 | cmd = ehci_readl(ehci, &ehci->regs->command); |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 416 | |
| 417 | /* If IAA is set here it either legitimately triggered |
| 418 | * before we cleared IAAD above (but _way_ late, so we'll |
| 419 | * still count it as lost) ... or a silicon erratum: |
| 420 | * - VIA seems to set IAA without triggering the IRQ; |
| 421 | * - IAAD potentially cleared without setting IAA. |
| 422 | */ |
| 423 | status = ehci_readl(ehci, &ehci->regs->status); |
| 424 | if ((status & STS_IAA) || !(cmd & CMD_IAAD)) { |
Greg Kroah-Hartman | 64f8979 | 2006-10-17 13:57:18 -0700 | [diff] [blame] | 425 | COUNT (ehci->stats.lost_iaa); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 426 | ehci_writel(ehci, STS_IAA, &ehci->regs->status); |
Greg Kroah-Hartman | 64f8979 | 2006-10-17 13:57:18 -0700 | [diff] [blame] | 427 | } |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 428 | |
| 429 | ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n", |
| 430 | status, cmd); |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 431 | end_unlink_async(ehci); |
Greg Kroah-Hartman | 64f8979 | 2006-10-17 13:57:18 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 434 | spin_unlock_irqrestore(&ehci->lock, flags); |
| 435 | } |
| 436 | |
| 437 | static void ehci_watchdog(unsigned long param) |
| 438 | { |
| 439 | struct ehci_hcd *ehci = (struct ehci_hcd *) param; |
| 440 | unsigned long flags; |
| 441 | |
| 442 | spin_lock_irqsave(&ehci->lock, flags); |
| 443 | |
| 444 | /* stop async processing after it's idled a bit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | if (test_bit (TIMER_ASYNC_OFF, &ehci->actions)) |
David Brownell | 26f953f | 2006-09-18 17:03:16 -0700 | [diff] [blame] | 446 | start_unlink_async (ehci, ehci->async); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | /* ehci could run by timer, without IRQs ... */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 449 | ehci_work (ehci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | spin_unlock_irqrestore (&ehci->lock, flags); |
| 452 | } |
| 453 | |
Alan Stern | 8903795 | 2007-02-13 14:55:27 -0500 | [diff] [blame] | 454 | /* On some systems, leaving remote wakeup enabled prevents system shutdown. |
| 455 | * The firmware seems to think that powering off is a wakeup event! |
| 456 | * This routine turns off remote wakeup and everything else, on all ports. |
| 457 | */ |
| 458 | static void ehci_turn_off_all_ports(struct ehci_hcd *ehci) |
| 459 | { |
| 460 | int port = HCS_N_PORTS(ehci->hcs_params); |
| 461 | |
| 462 | while (port--) |
| 463 | ehci_writel(ehci, PORT_RWC_BITS, |
| 464 | &ehci->regs->port_status[port]); |
| 465 | } |
| 466 | |
Sarah Sharp | 21da84a | 2008-04-08 14:30:18 -0700 | [diff] [blame] | 467 | /* |
| 468 | * Halt HC, turn off all ports, and let the BIOS use the companion controllers. |
| 469 | * Should be called with ehci->lock held. |
David Brownell | 72f30b6 | 2005-09-27 10:19:39 -0700 | [diff] [blame] | 470 | */ |
Sarah Sharp | 21da84a | 2008-04-08 14:30:18 -0700 | [diff] [blame] | 471 | static void ehci_silence_controller(struct ehci_hcd *ehci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
Sarah Sharp | 21da84a | 2008-04-08 14:30:18 -0700 | [diff] [blame] | 473 | ehci_halt(ehci); |
Alan Stern | 8903795 | 2007-02-13 14:55:27 -0500 | [diff] [blame] | 474 | ehci_turn_off_all_ports(ehci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | /* make BIOS/etc use companion controller during reboot */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 477 | ehci_writel(ehci, 0, &ehci->regs->configured_flag); |
Alan Stern | 8903795 | 2007-02-13 14:55:27 -0500 | [diff] [blame] | 478 | |
| 479 | /* unblock posted writes */ |
| 480 | ehci_readl(ehci, &ehci->regs->configured_flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Sarah Sharp | 21da84a | 2008-04-08 14:30:18 -0700 | [diff] [blame] | 483 | /* ehci_shutdown kick in for silicon on any bus (not just pci, etc). |
| 484 | * This forcibly disables dma and IRQs, helping kexec and other cases |
| 485 | * where the next system software may expect clean state. |
| 486 | */ |
| 487 | static void ehci_shutdown(struct usb_hcd *hcd) |
| 488 | { |
| 489 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 490 | |
| 491 | del_timer_sync(&ehci->watchdog); |
| 492 | del_timer_sync(&ehci->iaa_watchdog); |
| 493 | |
| 494 | spin_lock_irq(&ehci->lock); |
Alan Stern | c0c53db | 2012-07-11 11:21:48 -0400 | [diff] [blame^] | 495 | ehci->rh_state = EHCI_RH_STOPPING; |
Sarah Sharp | 21da84a | 2008-04-08 14:30:18 -0700 | [diff] [blame] | 496 | ehci_silence_controller(ehci); |
| 497 | spin_unlock_irq(&ehci->lock); |
| 498 | } |
| 499 | |
David Brownell | 56c1e26 | 2005-04-09 09:00:29 -0700 | [diff] [blame] | 500 | static void ehci_port_power (struct ehci_hcd *ehci, int is_on) |
| 501 | { |
| 502 | unsigned port; |
| 503 | |
| 504 | if (!HCS_PPC (ehci->hcs_params)) |
| 505 | return; |
| 506 | |
| 507 | ehci_dbg (ehci, "...power%s ports...\n", is_on ? "up" : "down"); |
| 508 | for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; ) |
| 509 | (void) ehci_hub_control(ehci_to_hcd(ehci), |
| 510 | is_on ? SetPortFeature : ClearPortFeature, |
| 511 | USB_PORT_FEAT_POWER, |
| 512 | port--, NULL, 0); |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 513 | /* Flush those writes */ |
| 514 | ehci_readl(ehci, &ehci->regs->command); |
David Brownell | 56c1e26 | 2005-04-09 09:00:29 -0700 | [diff] [blame] | 515 | msleep(20); |
| 516 | } |
| 517 | |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 518 | /*-------------------------------------------------------------------------*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 520 | /* |
| 521 | * ehci_work is called from some interrupts, timers, and so on. |
| 522 | * it calls driver completion functions, after dropping ehci->lock. |
| 523 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 524 | static void ehci_work (struct ehci_hcd *ehci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | { |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 526 | timer_action_done (ehci, TIMER_IO_WATCHDOG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 528 | /* another CPU may drop ehci->lock during a schedule scan while |
| 529 | * it reports urb completions. this flag guards against bogus |
| 530 | * attempts at re-entrant schedule scanning. |
| 531 | */ |
| 532 | if (ehci->scanning) |
| 533 | return; |
| 534 | ehci->scanning = 1; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 535 | scan_async (ehci); |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 536 | if (ehci->next_uframe != -1) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 537 | scan_periodic (ehci); |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 538 | ehci->scanning = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 540 | /* the IO watchdog guards against hardware or driver bugs that |
| 541 | * misplace IRQs, and should let us run completely without IRQs. |
| 542 | * such lossage has been observed on both VT6202 and VT8235. |
| 543 | */ |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 544 | if (ehci->rh_state == EHCI_RH_RUNNING && |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 545 | (ehci->async->qh_next.ptr != NULL || |
| 546 | ehci->periodic_sched != 0)) |
| 547 | timer_action (ehci, TIMER_IO_WATCHDOG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Sarah Sharp | 21da84a | 2008-04-08 14:30:18 -0700 | [diff] [blame] | 550 | /* |
| 551 | * Called when the ehci_hcd module is removed. |
| 552 | */ |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 553 | static void ehci_stop (struct usb_hcd *hcd) |
| 554 | { |
| 555 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 556 | |
| 557 | ehci_dbg (ehci, "stop\n"); |
| 558 | |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 559 | /* no more interrupts ... */ |
| 560 | del_timer_sync (&ehci->watchdog); |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 561 | del_timer_sync(&ehci->iaa_watchdog); |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 562 | |
| 563 | spin_lock_irq(&ehci->lock); |
Alan Stern | c0c53db | 2012-07-11 11:21:48 -0400 | [diff] [blame^] | 564 | ehci_quiesce(ehci); |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 565 | |
Sarah Sharp | 21da84a | 2008-04-08 14:30:18 -0700 | [diff] [blame] | 566 | ehci_silence_controller(ehci); |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 567 | ehci_reset (ehci); |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 568 | spin_unlock_irq(&ehci->lock); |
| 569 | |
Kirill Smelkov | 4c67045 | 2011-07-03 20:36:56 +0400 | [diff] [blame] | 570 | remove_sysfs_files(ehci); |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 571 | remove_debug_files (ehci); |
| 572 | |
| 573 | /* root hub is shut down separately (first, when possible) */ |
| 574 | spin_lock_irq (&ehci->lock); |
| 575 | if (ehci->async) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 576 | ehci_work (ehci); |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 577 | spin_unlock_irq (&ehci->lock); |
| 578 | ehci_mem_cleanup (ehci); |
| 579 | |
Andiry Xu | ad93562 | 2011-03-01 14:57:05 +0800 | [diff] [blame] | 580 | if (ehci->amd_pll_fix == 1) |
| 581 | usb_amd_dev_put(); |
Alex He | 0557029 | 2010-12-07 10:10:08 +0800 | [diff] [blame] | 582 | |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 583 | #ifdef EHCI_STATS |
Alan Stern | 99ac5b1 | 2012-07-11 11:21:38 -0400 | [diff] [blame] | 584 | ehci_dbg(ehci, "irq normal %ld err %ld iaa %ld (lost %ld)\n", |
| 585 | ehci->stats.normal, ehci->stats.error, ehci->stats.iaa, |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 586 | ehci->stats.lost_iaa); |
| 587 | ehci_dbg (ehci, "complete %ld unlink %ld\n", |
| 588 | ehci->stats.complete, ehci->stats.unlink); |
| 589 | #endif |
| 590 | |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 591 | dbg_status (ehci, "ehci_stop completed", |
| 592 | ehci_readl(ehci, &ehci->regs->status)); |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 593 | } |
| 594 | |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 595 | /* one-time init, only for memory state */ |
| 596 | static int ehci_init(struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | { |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 598 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | int retval; |
| 601 | u32 hcc_params; |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 602 | struct ehci_qh_hw *hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 604 | spin_lock_init(&ehci->lock); |
| 605 | |
Alek Du | 403dbd3 | 2009-07-13 17:30:41 +0800 | [diff] [blame] | 606 | /* |
| 607 | * keep io watchdog by default, those good HCDs could turn off it later |
| 608 | */ |
| 609 | ehci->need_io_watchdog = 1; |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 610 | init_timer(&ehci->watchdog); |
| 611 | ehci->watchdog.function = ehci_watchdog; |
| 612 | ehci->watchdog.data = (unsigned long) ehci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 614 | init_timer(&ehci->iaa_watchdog); |
| 615 | ehci->iaa_watchdog.function = ehci_iaa_watchdog; |
| 616 | ehci->iaa_watchdog.data = (unsigned long) ehci; |
| 617 | |
Alan Stern | f75593c | 2011-01-06 10:17:09 -0500 | [diff] [blame] | 618 | hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); |
| 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | /* |
Kirill Smelkov | cc62a7e | 2011-07-03 20:36:57 +0400 | [diff] [blame] | 621 | * by default set standard 80% (== 100 usec/uframe) max periodic |
| 622 | * bandwidth as required by USB 2.0 |
| 623 | */ |
| 624 | ehci->uframe_periodic_max = 100; |
| 625 | |
| 626 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | * hw default: 1K periodic list heads, one per frame. |
| 628 | * periodic_size can shrink by USBCMD update if hcc_params allows. |
| 629 | */ |
| 630 | ehci->periodic_size = DEFAULT_I_TDPS; |
Karsten Wiese | 9aa09d2 | 2009-02-08 16:07:58 -0800 | [diff] [blame] | 631 | INIT_LIST_HEAD(&ehci->cached_itd_list); |
Alan Stern | 0e5f231 | 2010-04-08 16:56:37 -0400 | [diff] [blame] | 632 | INIT_LIST_HEAD(&ehci->cached_sitd_list); |
Alan Stern | f75593c | 2011-01-06 10:17:09 -0500 | [diff] [blame] | 633 | |
Greg Kroah-Hartman | 8e19291 | 2012-05-21 08:54:43 -0700 | [diff] [blame] | 634 | if (HCC_PGM_FRAMELISTLEN(hcc_params)) { |
Alan Stern | f75593c | 2011-01-06 10:17:09 -0500 | [diff] [blame] | 635 | /* periodic schedule size can be smaller than default */ |
| 636 | switch (EHCI_TUNE_FLS) { |
| 637 | case 0: ehci->periodic_size = 1024; break; |
| 638 | case 1: ehci->periodic_size = 512; break; |
| 639 | case 2: ehci->periodic_size = 256; break; |
| 640 | default: BUG(); |
| 641 | } |
| 642 | } |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 643 | if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | return retval; |
| 645 | |
| 646 | /* controllers may cache some of the periodic schedule ... */ |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 647 | if (HCC_ISOC_CACHE(hcc_params)) // full frame cache |
Sarah Sharp | dccd574 | 2009-10-27 10:55:05 -0700 | [diff] [blame] | 648 | ehci->i_thresh = 2 + 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | else // N microframes cached |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 650 | ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | ehci->next_uframe = -1; |
Karsten Wiese | 9aa09d2 | 2009-02-08 16:07:58 -0800 | [diff] [blame] | 653 | ehci->clock_frame = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | /* |
| 656 | * dedicate a qh for the async ring head, since we couldn't unlink |
| 657 | * a 'real' qh without stopping the async schedule [4.8]. use it |
| 658 | * as the 'reclamation list head' too. |
| 659 | * its dummy is used in hw_alt_next of many tds, to prevent the qh |
| 660 | * from automatically advancing to the next td after short reads. |
| 661 | */ |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 662 | ehci->async->qh_next.qh = NULL; |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 663 | hw = ehci->async->hw; |
| 664 | hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma); |
| 665 | hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD); |
Ricardo Martins | 4f7a67e | 2012-05-22 18:02:03 +0100 | [diff] [blame] | 666 | #if defined(CONFIG_PPC_PS3) |
Alan Stern | 4c53de7 | 2012-07-11 11:21:32 -0400 | [diff] [blame] | 667 | hw->hw_info1 |= cpu_to_hc32(ehci, QH_INACTIVATE); |
Ricardo Martins | 4f7a67e | 2012-05-22 18:02:03 +0100 | [diff] [blame] | 668 | #endif |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 669 | hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT); |
| 670 | hw->hw_qtd_next = EHCI_LIST_END(ehci); |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 671 | ehci->async->qh_state = QH_STATE_LINKED; |
Alek Du | 3807e26 | 2009-07-14 07:23:29 +0800 | [diff] [blame] | 672 | hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | /* clear interrupt enables, set irq latency */ |
| 675 | if (log2_irq_thresh < 0 || log2_irq_thresh > 6) |
| 676 | log2_irq_thresh = 0; |
| 677 | temp = 1 << (16 + log2_irq_thresh); |
Alek Du | 5a9cdf3 | 2010-06-04 15:47:56 +0800 | [diff] [blame] | 678 | if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) { |
| 679 | ehci->has_ppcd = 1; |
| 680 | ehci_dbg(ehci, "enable per-port change event\n"); |
| 681 | temp |= CMD_PPCEE; |
| 682 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | if (HCC_CANPARK(hcc_params)) { |
| 684 | /* HW default park == 3, on hardware that supports it (like |
| 685 | * NVidia and ALI silicon), maximizes throughput on the async |
| 686 | * schedule by avoiding QH fetches between transfers. |
| 687 | * |
| 688 | * With fast usb storage devices and NForce2, "park" seems to |
| 689 | * make problems: throughput reduction (!), data errors... |
| 690 | */ |
| 691 | if (park) { |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 692 | park = min(park, (unsigned) 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | temp |= CMD_PARK; |
| 694 | temp |= park << 8; |
| 695 | } |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 696 | ehci_dbg(ehci, "park %d\n", park); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 698 | if (HCC_PGM_FRAMELISTLEN(hcc_params)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | /* periodic schedule size can be smaller than default */ |
| 700 | temp &= ~(3 << 2); |
| 701 | temp |= (EHCI_TUNE_FLS << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
Alek Du | 48f2497 | 2010-06-04 15:47:55 +0800 | [diff] [blame] | 703 | if (HCC_LPM(hcc_params)) { |
| 704 | /* support link power management EHCI 1.1 addendum */ |
| 705 | ehci_dbg(ehci, "support lpm\n"); |
| 706 | ehci->has_lpm = 1; |
| 707 | if (hird > 0xf) { |
| 708 | ehci_dbg(ehci, "hird %d invalid, use default 0", |
| 709 | hird); |
| 710 | hird = 0; |
| 711 | } |
| 712 | temp |= hird << 24; |
| 713 | } |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 714 | ehci->command = temp; |
| 715 | |
Alan Stern | 40f8db8 | 2009-11-06 12:29:40 -0500 | [diff] [blame] | 716 | /* Accept arbitrarily long scatter-gather lists */ |
Andrea Righi | 4307a28 | 2010-06-28 16:56:45 +0200 | [diff] [blame] | 717 | if (!(hcd->driver->flags & HCD_LOCAL_MEM)) |
| 718 | hcd->self.sg_tablesize = ~0; |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | /* start HC running; it's halted, ehci_init() has been run (once) */ |
| 723 | static int ehci_run (struct usb_hcd *hcd) |
| 724 | { |
| 725 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 726 | u32 temp; |
| 727 | u32 hcc_params; |
| 728 | |
Marcelo Tosatti | 1d619f1 | 2007-01-21 19:45:59 -0200 | [diff] [blame] | 729 | hcd->uses_new_polling = 1; |
Marcelo Tosatti | 1d619f1 | 2007-01-21 19:45:59 -0200 | [diff] [blame] | 730 | |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 731 | /* EHCI spec section 4.1 */ |
Geoff Levand | 876e0df | 2011-11-22 18:04:45 -0800 | [diff] [blame] | 732 | |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 733 | ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); |
| 734 | ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next); |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 735 | |
| 736 | /* |
| 737 | * hcc_params controls whether ehci->regs->segment must (!!!) |
| 738 | * be used; it constrains QH/ITD/SITD and QTD locations. |
| 739 | * pci_pool consistent memory always uses segment zero. |
| 740 | * streaming mappings for I/O buffers, like pci_map_single(), |
| 741 | * can return segments above 4GB, if the device allows. |
| 742 | * |
| 743 | * NOTE: the dma mask is visible through dma_supported(), so |
| 744 | * drivers can pass this info along ... like NETIF_F_HIGHDMA, |
| 745 | * Scsi_Host.highmem_io, and so forth. It's readonly to all |
| 746 | * host side drivers though. |
| 747 | */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 748 | hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 749 | if (HCC_64BIT_ADDR(hcc_params)) { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 750 | ehci_writel(ehci, 0, &ehci->regs->segment); |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 751 | #if 0 |
| 752 | // this is deeply broken on almost all architectures |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 753 | if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64))) |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 754 | ehci_info(ehci, "enabled 64bit DMA\n"); |
| 755 | #endif |
| 756 | } |
| 757 | |
| 758 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | // Philips, Intel, and maybe others need CMD_RUN before the |
| 760 | // root hub will detect new devices (why?); NEC doesn't |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 761 | ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); |
| 762 | ehci->command |= CMD_RUN; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 763 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 764 | dbg_cmd (ehci, "init", ehci->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | /* |
| 767 | * Start, enabling full USB 2.0 functionality ... usb 1.1 devices |
| 768 | * are explicitly handed to companion controller(s), so no TT is |
| 769 | * involved with the root hub. (Except where one is integrated, |
| 770 | * and there's no companion controller unless maybe for USB OTG.) |
Alan Stern | 32fe019 | 2007-10-10 16:27:07 -0400 | [diff] [blame] | 771 | * |
| 772 | * Turning on the CF flag will transfer ownership of all ports |
| 773 | * from the companions to the EHCI controller. If any of the |
| 774 | * companions are in the middle of a port reset at the time, it |
| 775 | * could cause trouble. Write-locking ehci_cf_port_reset_rwsem |
David Brownell | 1cb5265 | 2007-11-13 16:22:30 -0800 | [diff] [blame] | 776 | * guarantees that no resets are in progress. After we set CF, |
| 777 | * a short delay lets the hardware catch up; new resets shouldn't |
| 778 | * be started before the port switching actions could complete. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | */ |
Alan Stern | 32fe019 | 2007-10-10 16:27:07 -0400 | [diff] [blame] | 780 | down_write(&ehci_cf_port_reset_rwsem); |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 781 | ehci->rh_state = EHCI_RH_RUNNING; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 782 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); |
| 783 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ |
David Brownell | 1cb5265 | 2007-11-13 16:22:30 -0800 | [diff] [blame] | 784 | msleep(5); |
Alan Stern | 32fe019 | 2007-10-10 16:27:07 -0400 | [diff] [blame] | 785 | up_write(&ehci_cf_port_reset_rwsem); |
Oliver Neukum | ee4ecb8 | 2009-11-27 15:17:59 +0100 | [diff] [blame] | 786 | ehci->last_periodic_enable = ktime_get_real(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Jan Andersson | c430131 | 2011-05-03 20:11:57 +0200 | [diff] [blame] | 788 | temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | ehci_info (ehci, |
Alan Stern | 2b70f07 | 2008-10-02 11:47:15 -0400 | [diff] [blame] | 790 | "USB %x.%x started, EHCI %x.%02x%s\n", |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 791 | ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f), |
Alan Stern | 2b70f07 | 2008-10-02 11:47:15 -0400 | [diff] [blame] | 792 | temp >> 8, temp & 0xff, |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 793 | ignore_oc ? ", overcurrent ignored" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 795 | ehci_writel(ehci, INTR_MASK, |
| 796 | &ehci->regs->intr_enable); /* Turn On Interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
David Brownell | 1880752 | 2005-11-23 15:45:37 -0800 | [diff] [blame] | 798 | /* GRR this is run-once init(), being done every time the HC starts. |
| 799 | * So long as they're part of class devices, we can't do it init() |
| 800 | * since the class device isn't created that early. |
| 801 | */ |
| 802 | create_debug_files(ehci); |
Kirill Smelkov | 4c67045 | 2011-07-03 20:36:56 +0400 | [diff] [blame] | 803 | create_sysfs_files(ehci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
| 805 | return 0; |
| 806 | } |
| 807 | |
Alan Stern | 1a49e2a | 2012-07-09 15:55:14 -0400 | [diff] [blame] | 808 | static int ehci_setup(struct usb_hcd *hcd) |
Matthieu CASTET | 2093c6b | 2011-07-02 19:47:33 +0200 | [diff] [blame] | 809 | { |
| 810 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 811 | int retval; |
| 812 | |
| 813 | ehci->regs = (void __iomem *)ehci->caps + |
| 814 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 815 | dbg_hcs_params(ehci, "reset"); |
| 816 | dbg_hcc_params(ehci, "reset"); |
| 817 | |
| 818 | /* cache this readonly data; minimize chip reads */ |
| 819 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 820 | |
| 821 | ehci->sbrn = HCD_USB2; |
| 822 | |
Alan Stern | 631fe9d | 2012-07-11 11:21:09 -0400 | [diff] [blame] | 823 | /* data structure init */ |
| 824 | retval = ehci_init(hcd); |
Matthieu CASTET | 2093c6b | 2011-07-02 19:47:33 +0200 | [diff] [blame] | 825 | if (retval) |
| 826 | return retval; |
| 827 | |
Alan Stern | 631fe9d | 2012-07-11 11:21:09 -0400 | [diff] [blame] | 828 | retval = ehci_halt(ehci); |
Matthieu CASTET | 2093c6b | 2011-07-02 19:47:33 +0200 | [diff] [blame] | 829 | if (retval) |
| 830 | return retval; |
| 831 | |
Alan Stern | 1a49e2a | 2012-07-09 15:55:14 -0400 | [diff] [blame] | 832 | if (ehci_is_TDI(ehci)) |
| 833 | tdi_reset(ehci); |
| 834 | |
Matthieu CASTET | 2093c6b | 2011-07-02 19:47:33 +0200 | [diff] [blame] | 835 | ehci_reset(ehci); |
| 836 | |
| 837 | return 0; |
| 838 | } |
| 839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | /*-------------------------------------------------------------------------*/ |
| 841 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 842 | static irqreturn_t ehci_irq (struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | { |
| 844 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
Alan Stern | 67b2e02 | 2008-11-12 17:04:53 -0500 | [diff] [blame] | 845 | u32 status, masked_status, pcd_status = 0, cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | int bh; |
| 847 | |
| 848 | spin_lock (&ehci->lock); |
| 849 | |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 850 | status = ehci_readl(ehci, &ehci->regs->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
| 852 | /* e.g. cardbus physical eject */ |
| 853 | if (status == ~(u32) 0) { |
| 854 | ehci_dbg (ehci, "device removed\n"); |
| 855 | goto dead; |
| 856 | } |
| 857 | |
Alan Stern | 2fbe2bf | 2012-04-18 11:33:00 -0400 | [diff] [blame] | 858 | /* |
| 859 | * We don't use STS_FLR, but some controllers don't like it to |
| 860 | * remain on, so mask it out along with the other status bits. |
| 861 | */ |
| 862 | masked_status = status & (INTR_MASK | STS_FLR); |
| 863 | |
Alan Stern | 69fff59 | 2011-05-17 17:27:12 -0400 | [diff] [blame] | 864 | /* Shared IRQ? */ |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 865 | if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | spin_unlock(&ehci->lock); |
| 867 | return IRQ_NONE; |
| 868 | } |
| 869 | |
| 870 | /* clear (just) interrupts */ |
Alan Stern | 67b2e02 | 2008-11-12 17:04:53 -0500 | [diff] [blame] | 871 | ehci_writel(ehci, masked_status, &ehci->regs->status); |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 872 | cmd = ehci_readl(ehci, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | bh = 0; |
| 874 | |
David Brownell | 9776afc | 2008-02-01 11:42:05 -0800 | [diff] [blame] | 875 | #ifdef VERBOSE_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | /* unrequested/ignored: Frame List Rollover */ |
| 877 | dbg_status (ehci, "irq", status); |
| 878 | #endif |
| 879 | |
| 880 | /* INT, ERR, and IAA interrupt rates can be throttled */ |
| 881 | |
| 882 | /* normal [4.15.1.2] or error [4.15.1.1] completion */ |
| 883 | if (likely ((status & (STS_INT|STS_ERR)) != 0)) { |
| 884 | if (likely ((status & STS_ERR) == 0)) |
| 885 | COUNT (ehci->stats.normal); |
| 886 | else |
| 887 | COUNT (ehci->stats.error); |
| 888 | bh = 1; |
| 889 | } |
| 890 | |
| 891 | /* complete the unlinking of some qh [4.15.2.3] */ |
| 892 | if (status & STS_IAA) { |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 893 | /* guard against (alleged) silicon errata */ |
Alan Stern | 6feff1b | 2012-04-17 15:23:25 -0400 | [diff] [blame] | 894 | if (cmd & CMD_IAAD) |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 895 | ehci_dbg(ehci, "IAA with IAAD still set?\n"); |
Alan Stern | 99ac5b1 | 2012-07-11 11:21:38 -0400 | [diff] [blame] | 896 | if (ehci->async_unlink) { |
| 897 | COUNT(ehci->stats.iaa); |
David Brownell | e82cc12 | 2008-03-07 13:49:42 -0800 | [diff] [blame] | 898 | end_unlink_async(ehci); |
| 899 | } else |
Alan Stern | 99ac5b1 | 2012-07-11 11:21:38 -0400 | [diff] [blame] | 900 | ehci_dbg(ehci, "IAA with nothing unlinked?\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | /* remote wakeup [4.3.1] */ |
David Brownell | d97cc2f | 2005-12-22 17:05:18 -0800 | [diff] [blame] | 904 | if (status & STS_PCD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | unsigned i = HCS_N_PORTS (ehci->hcs_params); |
Alek Du | 5a9cdf3 | 2010-06-04 15:47:56 +0800 | [diff] [blame] | 906 | u32 ppcd = 0; |
David Brownell | d1b1842 | 2008-03-05 23:37:52 -0800 | [diff] [blame] | 907 | |
| 908 | /* kick root hub later */ |
Marcelo Tosatti | 1d619f1 | 2007-01-21 19:45:59 -0200 | [diff] [blame] | 909 | pcd_status = status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
| 911 | /* resume root hub? */ |
Alan Stern | dc75ce9 | 2012-04-17 15:24:15 -0400 | [diff] [blame] | 912 | if (ehci->rh_state == EHCI_RH_SUSPENDED) |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 913 | usb_hcd_resume_root_hub(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Alek Du | 5a9cdf3 | 2010-06-04 15:47:56 +0800 | [diff] [blame] | 915 | /* get per-port change detect bits */ |
| 916 | if (ehci->has_ppcd) |
| 917 | ppcd = status >> 16; |
| 918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | while (i--) { |
Alek Du | 5a9cdf3 | 2010-06-04 15:47:56 +0800 | [diff] [blame] | 920 | int pstatus; |
| 921 | |
| 922 | /* leverage per-port change bits feature */ |
| 923 | if (ehci->has_ppcd && !(ppcd & (1 << i))) |
| 924 | continue; |
| 925 | pstatus = ehci_readl(ehci, |
| 926 | &ehci->regs->port_status[i]); |
David Brownell | b972b68 | 2006-06-30 02:34:42 -0700 | [diff] [blame] | 927 | |
| 928 | if (pstatus & PORT_OWNER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | continue; |
Alan Stern | eafe5b9 | 2008-10-06 11:25:53 -0400 | [diff] [blame] | 930 | if (!(test_bit(i, &ehci->suspended_ports) && |
| 931 | ((pstatus & PORT_RESUME) || |
| 932 | !(pstatus & PORT_SUSPEND)) && |
| 933 | (pstatus & PORT_PE) && |
| 934 | ehci->reset_done[i] == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | continue; |
| 936 | |
| 937 | /* start 20 msec resume signaling from this port, |
| 938 | * and make khubd collect PORT_STAT_C_SUSPEND to |
Alan Stern | 49d0f07 | 2010-01-08 11:18:38 -0500 | [diff] [blame] | 939 | * stop that signaling. Use 5 ms extra for safety, |
| 940 | * like usb_port_resume() does. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | */ |
Alan Stern | 49d0f07 | 2010-01-08 11:18:38 -0500 | [diff] [blame] | 942 | ehci->reset_done[i] = jiffies + msecs_to_jiffies(25); |
Alan Stern | a448e4d | 2012-04-03 15:24:30 -0400 | [diff] [blame] | 943 | set_bit(i, &ehci->resuming_ports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | ehci_dbg (ehci, "port %d remote wakeup\n", i + 1); |
Alan Stern | 61e8b85 | 2007-04-09 11:52:31 -0400 | [diff] [blame] | 945 | mod_timer(&hcd->rh_timer, ehci->reset_done[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
| 949 | /* PCI errors [4.15.2.4] */ |
| 950 | if (unlikely ((status & STS_FATAL) != 0)) { |
Alan Stern | 67b2e02 | 2008-11-12 17:04:53 -0500 | [diff] [blame] | 951 | ehci_err(ehci, "fatal error\n"); |
Alan Stern | c0c53db | 2012-07-11 11:21:48 -0400 | [diff] [blame^] | 952 | ehci->rh_state = EHCI_RH_STOPPING; |
Alan Stern | eafe5b9 | 2008-10-06 11:25:53 -0400 | [diff] [blame] | 953 | dbg_cmd(ehci, "fatal", cmd); |
| 954 | dbg_status(ehci, "fatal", status); |
Alan Stern | 67b2e02 | 2008-11-12 17:04:53 -0500 | [diff] [blame] | 955 | ehci_halt(ehci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | dead: |
Alan Stern | 67b2e02 | 2008-11-12 17:04:53 -0500 | [diff] [blame] | 957 | ehci_reset(ehci); |
| 958 | ehci_writel(ehci, 0, &ehci->regs->configured_flag); |
Alan Stern | 69fff59 | 2011-05-17 17:27:12 -0400 | [diff] [blame] | 959 | usb_hc_died(hcd); |
Alan Stern | 67b2e02 | 2008-11-12 17:04:53 -0500 | [diff] [blame] | 960 | /* generic layer kills/unlinks all urbs, then |
| 961 | * uses ehci_stop to clean up the rest |
| 962 | */ |
| 963 | bh = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | if (bh) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 967 | ehci_work (ehci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | spin_unlock (&ehci->lock); |
David Brownell | d1b1842 | 2008-03-05 23:37:52 -0800 | [diff] [blame] | 969 | if (pcd_status) |
Marcelo Tosatti | 1d619f1 | 2007-01-21 19:45:59 -0200 | [diff] [blame] | 970 | usb_hcd_poll_rh_status(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | return IRQ_HANDLED; |
| 972 | } |
| 973 | |
| 974 | /*-------------------------------------------------------------------------*/ |
| 975 | |
| 976 | /* |
| 977 | * non-error returns are a promise to giveback() the urb later |
| 978 | * we drop ownership so next owner (or urb unlink) can get it |
| 979 | * |
| 980 | * urb + dev is in hcd.self.controller.urb_list |
| 981 | * we're queueing TDs onto software and hardware lists |
| 982 | * |
| 983 | * hcd-specific init for hcpriv hasn't been done yet |
| 984 | * |
| 985 | * NOTE: control, bulk, and interrupt share the same code to append TDs |
| 986 | * to a (possibly active) QH, and the same QH scanning code. |
| 987 | */ |
| 988 | static int ehci_urb_enqueue ( |
| 989 | struct usb_hcd *hcd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | struct urb *urb, |
Al Viro | 55016f1 | 2005-10-21 03:21:58 -0400 | [diff] [blame] | 991 | gfp_t mem_flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | ) { |
| 993 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 994 | struct list_head qtd_list; |
| 995 | |
| 996 | INIT_LIST_HEAD (&qtd_list); |
| 997 | |
| 998 | switch (usb_pipetype (urb->pipe)) { |
David Brownell | 25b70a8 | 2008-03-04 15:11:07 -0800 | [diff] [blame] | 999 | case PIPE_CONTROL: |
| 1000 | /* qh_completions() code doesn't handle all the fault cases |
| 1001 | * in multi-TD control transfers. Even 1KB is rare anyway. |
| 1002 | */ |
| 1003 | if (urb->transfer_buffer_length > (16 * 1024)) |
| 1004 | return -EMSGSIZE; |
| 1005 | /* FALLTHROUGH */ |
| 1006 | /* case PIPE_BULK: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | default: |
| 1008 | if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags)) |
| 1009 | return -ENOMEM; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1010 | return submit_async(ehci, urb, &qtd_list, mem_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
| 1012 | case PIPE_INTERRUPT: |
| 1013 | if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags)) |
| 1014 | return -ENOMEM; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1015 | return intr_submit(ehci, urb, &qtd_list, mem_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
| 1017 | case PIPE_ISOCHRONOUS: |
| 1018 | if (urb->dev->speed == USB_SPEED_HIGH) |
| 1019 | return itd_submit (ehci, urb, mem_flags); |
| 1020 | else |
| 1021 | return sitd_submit (ehci, urb, mem_flags); |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) |
| 1026 | { |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 1027 | /* failfast */ |
Alan Stern | c0c53db | 2012-07-11 11:21:48 -0400 | [diff] [blame^] | 1028 | if (ehci->rh_state < EHCI_RH_RUNNING && ehci->async_unlink) |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 1029 | end_unlink_async(ehci); |
| 1030 | |
Alan Stern | 3a44494 | 2009-08-19 12:22:06 -0400 | [diff] [blame] | 1031 | /* If the QH isn't linked then there's nothing we can do |
| 1032 | * unless we were called during a giveback, in which case |
| 1033 | * qh_completions() has to deal with it. |
| 1034 | */ |
| 1035 | if (qh->qh_state != QH_STATE_LINKED) { |
| 1036 | if (qh->qh_state == QH_STATE_COMPLETING) |
| 1037 | qh->needs_rescan = 1; |
| 1038 | return; |
| 1039 | } |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 1040 | |
| 1041 | /* defer till later if busy */ |
Alan Stern | 99ac5b1 | 2012-07-11 11:21:38 -0400 | [diff] [blame] | 1042 | if (ehci->async_unlink) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | qh->qh_state = QH_STATE_UNLINK_WAIT; |
Alan Stern | 2f5bb66 | 2012-07-11 11:21:43 -0400 | [diff] [blame] | 1044 | ehci->async_unlink_last->unlink_next = qh; |
| 1045 | ehci->async_unlink_last = qh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 1047 | /* start IAA cycle */ |
| 1048 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | start_unlink_async (ehci, qh); |
| 1050 | } |
| 1051 | |
| 1052 | /* remove from hardware lists |
| 1053 | * completions normally happen asynchronously |
| 1054 | */ |
| 1055 | |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1056 | static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | { |
| 1058 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 1059 | struct ehci_qh *qh; |
| 1060 | unsigned long flags; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1061 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
| 1063 | spin_lock_irqsave (&ehci->lock, flags); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1064 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); |
| 1065 | if (rc) |
| 1066 | goto done; |
| 1067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | switch (usb_pipetype (urb->pipe)) { |
| 1069 | // case PIPE_CONTROL: |
| 1070 | // case PIPE_BULK: |
| 1071 | default: |
| 1072 | qh = (struct ehci_qh *) urb->hcpriv; |
| 1073 | if (!qh) |
| 1074 | break; |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 1075 | switch (qh->qh_state) { |
| 1076 | case QH_STATE_LINKED: |
| 1077 | case QH_STATE_COMPLETING: |
| 1078 | unlink_async(ehci, qh); |
| 1079 | break; |
| 1080 | case QH_STATE_UNLINK: |
| 1081 | case QH_STATE_UNLINK_WAIT: |
| 1082 | /* already started */ |
| 1083 | break; |
| 1084 | case QH_STATE_IDLE: |
Alan Stern | 7a0f0d9 | 2009-07-31 10:40:22 -0400 | [diff] [blame] | 1085 | /* QH might be waiting for a Clear-TT-Buffer */ |
| 1086 | qh_completions(ehci, qh); |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 1087 | break; |
| 1088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | break; |
| 1090 | |
| 1091 | case PIPE_INTERRUPT: |
| 1092 | qh = (struct ehci_qh *) urb->hcpriv; |
| 1093 | if (!qh) |
| 1094 | break; |
| 1095 | switch (qh->qh_state) { |
| 1096 | case QH_STATE_LINKED: |
Alan Stern | a448c9d | 2009-08-19 12:22:44 -0400 | [diff] [blame] | 1097 | case QH_STATE_COMPLETING: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | intr_deschedule (ehci, qh); |
Alan Stern | a448c9d | 2009-08-19 12:22:44 -0400 | [diff] [blame] | 1099 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | case QH_STATE_IDLE: |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1101 | qh_completions (ehci, qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | break; |
| 1103 | default: |
| 1104 | ehci_dbg (ehci, "bogus qh %p state %d\n", |
| 1105 | qh, qh->qh_state); |
| 1106 | goto done; |
| 1107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | break; |
| 1109 | |
| 1110 | case PIPE_ISOCHRONOUS: |
| 1111 | // itd or sitd ... |
| 1112 | |
| 1113 | // wait till next completion, do it then. |
| 1114 | // completion irqs can wait up to 1024 msec, |
| 1115 | break; |
| 1116 | } |
| 1117 | done: |
| 1118 | spin_unlock_irqrestore (&ehci->lock, flags); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1119 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | /*-------------------------------------------------------------------------*/ |
| 1123 | |
| 1124 | // bulk qh holds the data toggle |
| 1125 | |
| 1126 | static void |
| 1127 | ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep) |
| 1128 | { |
| 1129 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 1130 | unsigned long flags; |
| 1131 | struct ehci_qh *qh, *tmp; |
| 1132 | |
| 1133 | /* ASSERT: any requests/urbs are being unlinked */ |
| 1134 | /* ASSERT: nobody can be submitting urbs for this any more */ |
| 1135 | |
| 1136 | rescan: |
| 1137 | spin_lock_irqsave (&ehci->lock, flags); |
| 1138 | qh = ep->hcpriv; |
| 1139 | if (!qh) |
| 1140 | goto done; |
| 1141 | |
| 1142 | /* endpoints can be iso streams. for now, we don't |
| 1143 | * accelerate iso completions ... so spin a while. |
| 1144 | */ |
Clemens Ladisch | 1082f57 | 2010-03-01 17:18:56 +0100 | [diff] [blame] | 1145 | if (qh->hw == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | ehci_vdbg (ehci, "iso delay\n"); |
| 1147 | goto idle_timeout; |
| 1148 | } |
| 1149 | |
Alan Stern | c0c53db | 2012-07-11 11:21:48 -0400 | [diff] [blame^] | 1150 | if (ehci->rh_state < EHCI_RH_RUNNING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | qh->qh_state = QH_STATE_IDLE; |
| 1152 | switch (qh->qh_state) { |
| 1153 | case QH_STATE_LINKED: |
Alan Stern | 3a44494 | 2009-08-19 12:22:06 -0400 | [diff] [blame] | 1154 | case QH_STATE_COMPLETING: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | for (tmp = ehci->async->qh_next.qh; |
| 1156 | tmp && tmp != qh; |
| 1157 | tmp = tmp->qh_next.qh) |
| 1158 | continue; |
Alan Stern | 02e2c51 | 2010-11-16 10:57:37 -0500 | [diff] [blame] | 1159 | /* periodic qh self-unlinks on empty, and a COMPLETING qh |
| 1160 | * may already be unlinked. |
| 1161 | */ |
| 1162 | if (tmp) |
| 1163 | unlink_async(ehci, qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | /* FALL THROUGH */ |
| 1165 | case QH_STATE_UNLINK: /* wait for hw to finish? */ |
Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 1166 | case QH_STATE_UNLINK_WAIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | idle_timeout: |
| 1168 | spin_unlock_irqrestore (&ehci->lock, flags); |
Nishanth Aravamudan | 22c4386 | 2005-08-15 11:30:11 -0700 | [diff] [blame] | 1169 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | goto rescan; |
| 1171 | case QH_STATE_IDLE: /* fully unlinked */ |
Alan Stern | 914b701 | 2009-06-29 10:47:30 -0400 | [diff] [blame] | 1172 | if (qh->clearing_tt) |
| 1173 | goto idle_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | if (list_empty (&qh->qtd_list)) { |
Alan Stern | c83e1a9 | 2012-07-11 11:21:25 -0400 | [diff] [blame] | 1175 | qh_destroy(ehci, qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | break; |
| 1177 | } |
| 1178 | /* else FALL THROUGH */ |
| 1179 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | /* caller was supposed to have unlinked any requests; |
| 1181 | * that's not our job. just leak this memory. |
| 1182 | */ |
| 1183 | ehci_err (ehci, "qh %p (#%02x) state %d%s\n", |
| 1184 | qh, ep->desc.bEndpointAddress, qh->qh_state, |
| 1185 | list_empty (&qh->qtd_list) ? "" : "(has tds)"); |
| 1186 | break; |
| 1187 | } |
| 1188 | ep->hcpriv = NULL; |
| 1189 | done: |
| 1190 | spin_unlock_irqrestore (&ehci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
Alan Stern | b18ffd4 | 2009-05-27 18:21:56 -0400 | [diff] [blame] | 1193 | static void |
| 1194 | ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep) |
| 1195 | { |
| 1196 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1197 | struct ehci_qh *qh; |
| 1198 | int eptype = usb_endpoint_type(&ep->desc); |
Alan Stern | a455212d | 2009-06-11 14:56:22 -0400 | [diff] [blame] | 1199 | int epnum = usb_endpoint_num(&ep->desc); |
| 1200 | int is_out = usb_endpoint_dir_out(&ep->desc); |
| 1201 | unsigned long flags; |
Alan Stern | b18ffd4 | 2009-05-27 18:21:56 -0400 | [diff] [blame] | 1202 | |
| 1203 | if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT) |
| 1204 | return; |
| 1205 | |
Alan Stern | a455212d | 2009-06-11 14:56:22 -0400 | [diff] [blame] | 1206 | spin_lock_irqsave(&ehci->lock, flags); |
Alan Stern | b18ffd4 | 2009-05-27 18:21:56 -0400 | [diff] [blame] | 1207 | qh = ep->hcpriv; |
| 1208 | |
| 1209 | /* For Bulk and Interrupt endpoints we maintain the toggle state |
| 1210 | * in the hardware; the toggle bits in udev aren't used at all. |
| 1211 | * When an endpoint is reset by usb_clear_halt() we must reset |
| 1212 | * the toggle bit in the QH. |
| 1213 | */ |
| 1214 | if (qh) { |
Alan Stern | a455212d | 2009-06-11 14:56:22 -0400 | [diff] [blame] | 1215 | usb_settoggle(qh->dev, epnum, is_out, 0); |
Alan Stern | b18ffd4 | 2009-05-27 18:21:56 -0400 | [diff] [blame] | 1216 | if (!list_empty(&qh->qtd_list)) { |
| 1217 | WARN_ONCE(1, "clear_halt for a busy endpoint\n"); |
Alan Stern | 3a44494 | 2009-08-19 12:22:06 -0400 | [diff] [blame] | 1218 | } else if (qh->qh_state == QH_STATE_LINKED || |
| 1219 | qh->qh_state == QH_STATE_COMPLETING) { |
Alan Stern | a455212d | 2009-06-11 14:56:22 -0400 | [diff] [blame] | 1220 | |
| 1221 | /* The toggle value in the QH can't be updated |
| 1222 | * while the QH is active. Unlink it now; |
| 1223 | * re-linking will call qh_refresh(). |
Alan Stern | b18ffd4 | 2009-05-27 18:21:56 -0400 | [diff] [blame] | 1224 | */ |
Alan Stern | a448c9d | 2009-08-19 12:22:44 -0400 | [diff] [blame] | 1225 | if (eptype == USB_ENDPOINT_XFER_BULK) |
Alan Stern | a455212d | 2009-06-11 14:56:22 -0400 | [diff] [blame] | 1226 | unlink_async(ehci, qh); |
Alan Stern | a448c9d | 2009-08-19 12:22:44 -0400 | [diff] [blame] | 1227 | else |
Alan Stern | a455212d | 2009-06-11 14:56:22 -0400 | [diff] [blame] | 1228 | intr_deschedule(ehci, qh); |
Alan Stern | b18ffd4 | 2009-05-27 18:21:56 -0400 | [diff] [blame] | 1229 | } |
| 1230 | } |
Alan Stern | a455212d | 2009-06-11 14:56:22 -0400 | [diff] [blame] | 1231 | spin_unlock_irqrestore(&ehci->lock, flags); |
Alan Stern | b18ffd4 | 2009-05-27 18:21:56 -0400 | [diff] [blame] | 1232 | } |
| 1233 | |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 1234 | static int ehci_get_frame (struct usb_hcd *hcd) |
| 1235 | { |
| 1236 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
Alan Stern | 68aa95d | 2011-10-12 10:39:14 -0400 | [diff] [blame] | 1237 | return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size; |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 1238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
| 1240 | /*-------------------------------------------------------------------------*/ |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 1241 | |
| 1242 | #ifdef CONFIG_PM |
| 1243 | |
| 1244 | /* suspend/resume, section 4.3 */ |
| 1245 | |
| 1246 | /* These routines handle the generic parts of controller suspend/resume */ |
| 1247 | |
| 1248 | static int __maybe_unused ehci_suspend(struct usb_hcd *hcd, bool do_wakeup) |
| 1249 | { |
| 1250 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1251 | |
| 1252 | if (time_before(jiffies, ehci->next_statechange)) |
| 1253 | msleep(10); |
| 1254 | |
| 1255 | /* |
| 1256 | * Root hub was already suspended. Disable IRQ emission and |
| 1257 | * mark HW unaccessible. The PM and USB cores make sure that |
| 1258 | * the root hub is either suspended or stopped. |
| 1259 | */ |
| 1260 | ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup); |
| 1261 | |
| 1262 | spin_lock_irq(&ehci->lock); |
| 1263 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); |
| 1264 | (void) ehci_readl(ehci, &ehci->regs->intr_enable); |
| 1265 | |
| 1266 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 1267 | spin_unlock_irq(&ehci->lock); |
| 1268 | |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
| 1272 | /* Returns 0 if power was preserved, 1 if power was lost */ |
| 1273 | static int __maybe_unused ehci_resume(struct usb_hcd *hcd, bool hibernated) |
| 1274 | { |
| 1275 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1276 | |
| 1277 | if (time_before(jiffies, ehci->next_statechange)) |
| 1278 | msleep(100); |
| 1279 | |
| 1280 | /* Mark hardware accessible again as we are back to full power by now */ |
| 1281 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 1282 | |
| 1283 | /* |
| 1284 | * If CF is still set and we aren't resuming from hibernation |
| 1285 | * then we maintained suspend power. |
| 1286 | * Just undo the effect of ehci_suspend(). |
| 1287 | */ |
| 1288 | if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF && |
| 1289 | !hibernated) { |
| 1290 | int mask = INTR_MASK; |
| 1291 | |
| 1292 | ehci_prepare_ports_for_controller_resume(ehci); |
| 1293 | if (!hcd->self.root_hub->do_remote_wakeup) |
| 1294 | mask &= ~STS_PCD; |
| 1295 | ehci_writel(ehci, mask, &ehci->regs->intr_enable); |
| 1296 | ehci_readl(ehci, &ehci->regs->intr_enable); |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | /* |
| 1301 | * Else reset, to cope with power loss or resume from hibernation |
| 1302 | * having let the firmware kick in during reboot. |
| 1303 | */ |
| 1304 | usb_root_hub_lost_power(hcd->self.root_hub); |
| 1305 | (void) ehci_halt(ehci); |
| 1306 | (void) ehci_reset(ehci); |
| 1307 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 1308 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
| 1309 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); |
| 1310 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ |
| 1311 | |
| 1312 | /* here we "know" root ports should always stay powered */ |
| 1313 | ehci_port_power(ehci, 1); |
| 1314 | |
| 1315 | ehci->rh_state = EHCI_RH_SUSPENDED; |
| 1316 | return 1; |
| 1317 | } |
| 1318 | |
| 1319 | #endif |
| 1320 | |
| 1321 | /*-------------------------------------------------------------------------*/ |
| 1322 | |
Alexander Shishkin | eb70e5a | 2012-05-11 17:25:54 +0300 | [diff] [blame] | 1323 | /* |
| 1324 | * The EHCI in ChipIdea HDRC cannot be a separate module or device, |
| 1325 | * because its registers (and irq) are shared between host/gadget/otg |
| 1326 | * functions and in order to facilitate role switching we cannot |
| 1327 | * give the ehci driver exclusive access to those. |
| 1328 | */ |
| 1329 | #ifndef CHIPIDEA_EHCI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | |
Alan Stern | 2b70f07 | 2008-10-02 11:47:15 -0400 | [diff] [blame] | 1331 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | MODULE_AUTHOR (DRIVER_AUTHOR); |
| 1333 | MODULE_LICENSE ("GPL"); |
| 1334 | |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 1335 | #ifdef CONFIG_PCI |
| 1336 | #include "ehci-pci.c" |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1337 | #define PCI_DRIVER ehci_pci_driver |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 1338 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | |
Li Yang | ba02978 | 2007-05-11 17:09:55 +0800 | [diff] [blame] | 1340 | #ifdef CONFIG_USB_EHCI_FSL |
Randy Vinson | 80cb9ae | 2006-01-20 13:53:38 -0800 | [diff] [blame] | 1341 | #include "ehci-fsl.c" |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1342 | #define PLATFORM_DRIVER ehci_fsl_driver |
Randy Vinson | 80cb9ae | 2006-01-20 13:53:38 -0800 | [diff] [blame] | 1343 | #endif |
| 1344 | |
Daniel Mack | 7e8d5cd | 2009-10-28 01:14:59 +0100 | [diff] [blame] | 1345 | #ifdef CONFIG_USB_EHCI_MXC |
| 1346 | #include "ehci-mxc.c" |
| 1347 | #define PLATFORM_DRIVER ehci_mxc_driver |
| 1348 | #endif |
| 1349 | |
Yoshihiro Shimoda | 60b0bf0 | 2011-03-01 16:58:37 +0900 | [diff] [blame] | 1350 | #ifdef CONFIG_USB_EHCI_SH |
Paul Mundt | 63c8455 | 2010-11-01 17:03:27 -0400 | [diff] [blame] | 1351 | #include "ehci-sh.c" |
| 1352 | #define PLATFORM_DRIVER ehci_hcd_sh_driver |
| 1353 | #endif |
| 1354 | |
Manuel Lauss | 376638603 | 2011-08-12 11:39:45 +0200 | [diff] [blame] | 1355 | #ifdef CONFIG_MIPS_ALCHEMY |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 1356 | #include "ehci-au1xxx.c" |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1357 | #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 1358 | #endif |
| 1359 | |
Keshava Munegowda | 7f124f4 | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 1360 | #ifdef CONFIG_USB_EHCI_HCD_OMAP |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 1361 | #include "ehci-omap.c" |
| 1362 | #define PLATFORM_DRIVER ehci_hcd_omap_driver |
| 1363 | #endif |
| 1364 | |
Geoff Levand | ad75a41 | 2007-01-15 20:11:47 -0800 | [diff] [blame] | 1365 | #ifdef CONFIG_PPC_PS3 |
| 1366 | #include "ehci-ps3.c" |
Geoff Levand | 7a4eb7f | 2007-06-05 20:04:35 -0700 | [diff] [blame] | 1367 | #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver |
Geoff Levand | ad75a41 | 2007-01-15 20:11:47 -0800 | [diff] [blame] | 1368 | #endif |
| 1369 | |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1370 | #ifdef CONFIG_USB_EHCI_HCD_PPC_OF |
| 1371 | #include "ehci-ppc-of.c" |
| 1372 | #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver |
| 1373 | #endif |
| 1374 | |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 1375 | #ifdef CONFIG_XPS_USB_HCD_XILINX |
| 1376 | #include "ehci-xilinx-of.c" |
Grant Likely | 1f23b2d | 2010-06-02 13:53:17 -0600 | [diff] [blame] | 1377 | #define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver |
Julie Zhu | 08d3c18 | 2009-09-21 16:08:19 -0600 | [diff] [blame] | 1378 | #endif |
| 1379 | |
Lennert Buytenhek | 705a752 | 2008-03-27 14:51:40 -0400 | [diff] [blame] | 1380 | #ifdef CONFIG_PLAT_ORION |
Tzachi Perelstein | e96ffe2 | 2007-12-01 11:07:04 -0500 | [diff] [blame] | 1381 | #include "ehci-orion.c" |
| 1382 | #define PLATFORM_DRIVER ehci_orion_driver |
| 1383 | #endif |
| 1384 | |
Vladimir Barinov | 91bc4d3 | 2007-12-30 15:21:11 -0800 | [diff] [blame] | 1385 | #ifdef CONFIG_ARCH_IXP4XX |
| 1386 | #include "ehci-ixp4xx.c" |
| 1387 | #define PLATFORM_DRIVER ixp4xx_ehci_driver |
| 1388 | #endif |
| 1389 | |
Wan ZongShun | 586dfc8 | 2009-06-13 09:14:28 +0800 | [diff] [blame] | 1390 | #ifdef CONFIG_USB_W90X900_EHCI |
| 1391 | #include "ehci-w90x900.c" |
| 1392 | #define PLATFORM_DRIVER ehci_hcd_w90x900_driver |
| 1393 | #endif |
| 1394 | |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 1395 | #ifdef CONFIG_ARCH_AT91 |
| 1396 | #include "ehci-atmel.c" |
| 1397 | #define PLATFORM_DRIVER ehci_atmel_driver |
| 1398 | #endif |
| 1399 | |
David Daney | 1643acc | 2010-10-08 14:47:52 -0700 | [diff] [blame] | 1400 | #ifdef CONFIG_USB_OCTEON_EHCI |
| 1401 | #include "ehci-octeon.c" |
| 1402 | #define PLATFORM_DRIVER ehci_octeon_driver |
| 1403 | #endif |
| 1404 | |
Mac Lin | 760efe6 | 2010-11-25 23:58:00 +0800 | [diff] [blame] | 1405 | #ifdef CONFIG_USB_CNS3XXX_EHCI |
| 1406 | #include "ehci-cns3xxx.c" |
| 1407 | #define PLATFORM_DRIVER cns3xxx_ehci_driver |
| 1408 | #endif |
| 1409 | |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 1410 | #ifdef CONFIG_ARCH_VT8500 |
| 1411 | #include "ehci-vt8500.c" |
| 1412 | #define PLATFORM_DRIVER vt8500_ehci_driver |
| 1413 | #endif |
| 1414 | |
Deepak Sikri | c8c38de | 2010-11-10 14:33:18 +0530 | [diff] [blame] | 1415 | #ifdef CONFIG_PLAT_SPEAR |
| 1416 | #include "ehci-spear.c" |
| 1417 | #define PLATFORM_DRIVER spear_ehci_hcd_driver |
| 1418 | #endif |
| 1419 | |
Pavankumar Kondeti | b0848ae | 2010-12-07 17:53:56 +0530 | [diff] [blame] | 1420 | #ifdef CONFIG_USB_EHCI_MSM |
| 1421 | #include "ehci-msm.c" |
| 1422 | #define PLATFORM_DRIVER ehci_msm_driver |
| 1423 | #endif |
| 1424 | |
Anoop | 22ced687 | 2011-02-24 19:26:28 +0530 | [diff] [blame] | 1425 | #ifdef CONFIG_USB_EHCI_HCD_PMC_MSP |
| 1426 | #include "ehci-pmcmsp.c" |
| 1427 | #define PLATFORM_DRIVER ehci_hcd_msp_driver |
| 1428 | #endif |
| 1429 | |
Benoit Goby | 79ad3b5 | 2011-03-09 16:28:56 -0800 | [diff] [blame] | 1430 | #ifdef CONFIG_USB_EHCI_TEGRA |
| 1431 | #include "ehci-tegra.c" |
| 1432 | #define PLATFORM_DRIVER tegra_ehci_driver |
| 1433 | #endif |
| 1434 | |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 1435 | #ifdef CONFIG_USB_EHCI_S5P |
| 1436 | #include "ehci-s5p.c" |
| 1437 | #define PLATFORM_DRIVER s5p_ehci_driver |
| 1438 | #endif |
| 1439 | |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 1440 | #ifdef CONFIG_SPARC_LEON |
| 1441 | #include "ehci-grlib.c" |
| 1442 | #define PLATFORM_DRIVER ehci_grlib_driver |
| 1443 | #endif |
| 1444 | |
Jayachandran C | 3af5154 | 2011-11-18 12:12:42 +0530 | [diff] [blame] | 1445 | #ifdef CONFIG_CPU_XLR |
Jayachandran C | 2310634 | 2011-08-05 01:28:22 +0530 | [diff] [blame] | 1446 | #include "ehci-xls.c" |
| 1447 | #define PLATFORM_DRIVER ehci_xls_driver |
| 1448 | #endif |
| 1449 | |
Neil Zhang | 3a082ec | 2011-12-20 13:20:23 +0800 | [diff] [blame] | 1450 | #ifdef CONFIG_USB_EHCI_MV |
| 1451 | #include "ehci-mv.c" |
| 1452 | #define PLATFORM_DRIVER ehci_mv_driver |
| 1453 | #endif |
| 1454 | |
Kelvin Cheung | f30cdbc | 2012-01-18 14:41:16 +0800 | [diff] [blame] | 1455 | #ifdef CONFIG_MACH_LOONGSON1 |
| 1456 | #include "ehci-ls1x.c" |
| 1457 | #define PLATFORM_DRIVER ehci_ls1x_driver |
| 1458 | #endif |
| 1459 | |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 1460 | #ifdef CONFIG_MIPS_SEAD3 |
| 1461 | #include "ehci-sead3.c" |
| 1462 | #define PLATFORM_DRIVER ehci_hcd_sead3_driver |
| 1463 | #endif |
| 1464 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 1465 | #ifdef CONFIG_USB_EHCI_HCD_PLATFORM |
| 1466 | #include "ehci-platform.c" |
| 1467 | #define PLATFORM_DRIVER ehci_platform_driver |
| 1468 | #endif |
| 1469 | |
Geoff Levand | ad75a41 | 2007-01-15 20:11:47 -0800 | [diff] [blame] | 1470 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ |
Grant Likely | 1f23b2d | 2010-06-02 13:53:17 -0600 | [diff] [blame] | 1471 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ |
| 1472 | !defined(XILINX_OF_PLATFORM_DRIVER) |
Matt Porter | 7ff71d6 | 2005-09-22 22:31:15 -0700 | [diff] [blame] | 1473 | #error "missing bus glue for ehci-hcd" |
| 1474 | #endif |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1475 | |
| 1476 | static int __init ehci_hcd_init(void) |
| 1477 | { |
| 1478 | int retval = 0; |
| 1479 | |
Alan Stern | 2b70f07 | 2008-10-02 11:47:15 -0400 | [diff] [blame] | 1480 | if (usb_disabled()) |
| 1481 | return -ENODEV; |
| 1482 | |
| 1483 | printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name); |
Alan Stern | 9beeee6 | 2008-10-02 11:48:13 -0400 | [diff] [blame] | 1484 | set_bit(USB_EHCI_LOADED, &usb_hcds_loaded); |
| 1485 | if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) || |
| 1486 | test_bit(USB_OHCI_LOADED, &usb_hcds_loaded)) |
| 1487 | printk(KERN_WARNING "Warning! ehci_hcd should always be loaded" |
| 1488 | " before uhci_hcd and ohci_hcd, not after\n"); |
| 1489 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1490 | pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n", |
| 1491 | hcd_name, |
| 1492 | sizeof(struct ehci_qh), sizeof(struct ehci_qtd), |
| 1493 | sizeof(struct ehci_itd), sizeof(struct ehci_sitd)); |
| 1494 | |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1495 | #ifdef DEBUG |
Greg Kroah-Hartman | 08f4e58 | 2009-04-24 15:13:18 -0700 | [diff] [blame] | 1496 | ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root); |
Alan Stern | 9beeee6 | 2008-10-02 11:48:13 -0400 | [diff] [blame] | 1497 | if (!ehci_debug_root) { |
| 1498 | retval = -ENOENT; |
| 1499 | goto err_debug; |
| 1500 | } |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1501 | #endif |
| 1502 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1503 | #ifdef PLATFORM_DRIVER |
| 1504 | retval = platform_driver_register(&PLATFORM_DRIVER); |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1505 | if (retval < 0) |
| 1506 | goto clean0; |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1507 | #endif |
| 1508 | |
| 1509 | #ifdef PCI_DRIVER |
| 1510 | retval = pci_register_driver(&PCI_DRIVER); |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1511 | if (retval < 0) |
| 1512 | goto clean1; |
Geoff Levand | ad75a41 | 2007-01-15 20:11:47 -0800 | [diff] [blame] | 1513 | #endif |
| 1514 | |
| 1515 | #ifdef PS3_SYSTEM_BUS_DRIVER |
Geoff Levand | 7a4eb7f | 2007-06-05 20:04:35 -0700 | [diff] [blame] | 1516 | retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER); |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1517 | if (retval < 0) |
| 1518 | goto clean2; |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1519 | #endif |
| 1520 | |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1521 | #ifdef OF_PLATFORM_DRIVER |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 1522 | retval = platform_driver_register(&OF_PLATFORM_DRIVER); |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1523 | if (retval < 0) |
| 1524 | goto clean3; |
| 1525 | #endif |
Grant Likely | 1f23b2d | 2010-06-02 13:53:17 -0600 | [diff] [blame] | 1526 | |
| 1527 | #ifdef XILINX_OF_PLATFORM_DRIVER |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 1528 | retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER); |
Grant Likely | 1f23b2d | 2010-06-02 13:53:17 -0600 | [diff] [blame] | 1529 | if (retval < 0) |
| 1530 | goto clean4; |
| 1531 | #endif |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1532 | return retval; |
| 1533 | |
Grant Likely | 1f23b2d | 2010-06-02 13:53:17 -0600 | [diff] [blame] | 1534 | #ifdef XILINX_OF_PLATFORM_DRIVER |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 1535 | /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */ |
Grant Likely | 1f23b2d | 2010-06-02 13:53:17 -0600 | [diff] [blame] | 1536 | clean4: |
| 1537 | #endif |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1538 | #ifdef OF_PLATFORM_DRIVER |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 1539 | platform_driver_unregister(&OF_PLATFORM_DRIVER); |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1540 | clean3: |
| 1541 | #endif |
| 1542 | #ifdef PS3_SYSTEM_BUS_DRIVER |
| 1543 | ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
| 1544 | clean2: |
| 1545 | #endif |
| 1546 | #ifdef PCI_DRIVER |
| 1547 | pci_unregister_driver(&PCI_DRIVER); |
| 1548 | clean1: |
| 1549 | #endif |
| 1550 | #ifdef PLATFORM_DRIVER |
| 1551 | platform_driver_unregister(&PLATFORM_DRIVER); |
| 1552 | clean0: |
| 1553 | #endif |
| 1554 | #ifdef DEBUG |
| 1555 | debugfs_remove(ehci_debug_root); |
| 1556 | ehci_debug_root = NULL; |
Alan Stern | 9beeee6 | 2008-10-02 11:48:13 -0400 | [diff] [blame] | 1557 | err_debug: |
Linus Torvalds | a9b6148 | 2008-10-20 14:23:29 -0700 | [diff] [blame] | 1558 | #endif |
Alan Stern | 9beeee6 | 2008-10-02 11:48:13 -0400 | [diff] [blame] | 1559 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1560 | return retval; |
| 1561 | } |
| 1562 | module_init(ehci_hcd_init); |
| 1563 | |
| 1564 | static void __exit ehci_hcd_cleanup(void) |
| 1565 | { |
Grant Likely | 1f23b2d | 2010-06-02 13:53:17 -0600 | [diff] [blame] | 1566 | #ifdef XILINX_OF_PLATFORM_DRIVER |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 1567 | platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); |
Grant Likely | 1f23b2d | 2010-06-02 13:53:17 -0600 | [diff] [blame] | 1568 | #endif |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1569 | #ifdef OF_PLATFORM_DRIVER |
Grant Likely | d35fb64 | 2011-02-22 21:08:34 -0700 | [diff] [blame] | 1570 | platform_driver_unregister(&OF_PLATFORM_DRIVER); |
Valentine Barshak | da0e8fb | 2007-12-30 15:28:50 -0800 | [diff] [blame] | 1571 | #endif |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1572 | #ifdef PLATFORM_DRIVER |
| 1573 | platform_driver_unregister(&PLATFORM_DRIVER); |
| 1574 | #endif |
| 1575 | #ifdef PCI_DRIVER |
| 1576 | pci_unregister_driver(&PCI_DRIVER); |
| 1577 | #endif |
Geoff Levand | ad75a41 | 2007-01-15 20:11:47 -0800 | [diff] [blame] | 1578 | #ifdef PS3_SYSTEM_BUS_DRIVER |
Geoff Levand | 7a4eb7f | 2007-06-05 20:04:35 -0700 | [diff] [blame] | 1579 | ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
Geoff Levand | ad75a41 | 2007-01-15 20:11:47 -0800 | [diff] [blame] | 1580 | #endif |
Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 1581 | #ifdef DEBUG |
| 1582 | debugfs_remove(ehci_debug_root); |
| 1583 | #endif |
Alan Stern | 9beeee6 | 2008-10-02 11:48:13 -0400 | [diff] [blame] | 1584 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 1585 | } |
| 1586 | module_exit(ehci_hcd_cleanup); |
| 1587 | |
Alexander Shishkin | eb70e5a | 2012-05-11 17:25:54 +0300 | [diff] [blame] | 1588 | #endif /* CHIPIDEA_EHCI */ |