ehci-hcd.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. /*
  2. * Copyright (c) 2000-2004 by David Brownell
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/pci.h>
  20. #include <linux/dmapool.h>
  21. #include <linux/kernel.h>
  22. #include <linux/delay.h>
  23. #include <linux/ioport.h>
  24. #include <linux/sched.h>
  25. #include <linux/slab.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/errno.h>
  28. #include <linux/init.h>
  29. #include <linux/timer.h>
  30. #include <linux/list.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/reboot.h>
  33. #include <linux/usb.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/debugfs.h>
  37. #include "../core/hcd.h"
  38. #include <asm/byteorder.h>
  39. #include <asm/io.h>
  40. #include <asm/irq.h>
  41. #include <asm/system.h>
  42. #include <asm/unaligned.h>
  43. /*-------------------------------------------------------------------------*/
  44. /*
  45. * EHCI hc_driver implementation ... experimental, incomplete.
  46. * Based on the final 1.0 register interface specification.
  47. *
  48. * USB 2.0 shows up in upcoming www.pcmcia.org technology.
  49. * First was PCMCIA, like ISA; then CardBus, which is PCI.
  50. * Next comes "CardBay", using USB 2.0 signals.
  51. *
  52. * Contains additional contributions by Brad Hards, Rory Bolt, and others.
  53. * Special thanks to Intel and VIA for providing host controllers to
  54. * test this driver on, and Cypress (including In-System Design) for
  55. * providing early devices for those host controllers to talk to!
  56. */
  57. #define DRIVER_AUTHOR "David Brownell"
  58. #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
  59. static const char hcd_name [] = "ehci_hcd";
  60. #undef VERBOSE_DEBUG
  61. #undef EHCI_URB_TRACE
  62. #ifdef DEBUG
  63. #define EHCI_STATS
  64. #endif
  65. /* magic numbers that can affect system performance */
  66. #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
  67. #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
  68. #define EHCI_TUNE_RL_TT 0
  69. #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
  70. #define EHCI_TUNE_MULT_TT 1
  71. #define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
  72. #define EHCI_IAA_MSECS 10 /* arbitrary */
  73. #define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
  74. #define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
  75. #define EHCI_SHRINK_FRAMES 5 /* async qh unlink delay */
  76. /* Initial IRQ latency: faster than hw default */
  77. static int log2_irq_thresh = 0; // 0 to 6
  78. module_param (log2_irq_thresh, int, S_IRUGO);
  79. MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
  80. /* initial park setting: slower than hw default */
  81. static unsigned park = 0;
  82. module_param (park, uint, S_IRUGO);
  83. MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
  84. /* for flakey hardware, ignore overcurrent indicators */
  85. static int ignore_oc = 0;
  86. module_param (ignore_oc, bool, S_IRUGO);
  87. MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
  88. #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
  89. /*-------------------------------------------------------------------------*/
  90. #include "ehci.h"
  91. #include "ehci-dbg.c"
  92. /*-------------------------------------------------------------------------*/
  93. static void
  94. timer_action(struct ehci_hcd *ehci, enum ehci_timer_action action)
  95. {
  96. /* Don't override timeouts which shrink or (later) disable
  97. * the async ring; just the I/O watchdog. Note that if a
  98. * SHRINK were pending, OFF would never be requested.
  99. */
  100. if (timer_pending(&ehci->watchdog)
  101. && ((BIT(TIMER_ASYNC_SHRINK) | BIT(TIMER_ASYNC_OFF))
  102. & ehci->actions))
  103. return;
  104. if (!test_and_set_bit(action, &ehci->actions)) {
  105. unsigned long t;
  106. switch (action) {
  107. case TIMER_IO_WATCHDOG:
  108. t = EHCI_IO_JIFFIES;
  109. break;
  110. case TIMER_ASYNC_OFF:
  111. t = EHCI_ASYNC_JIFFIES;
  112. break;
  113. /* case TIMER_ASYNC_SHRINK: */
  114. default:
  115. /* add a jiffie since we synch against the
  116. * 8 KHz uframe counter.
  117. */
  118. t = DIV_ROUND_UP(EHCI_SHRINK_FRAMES * HZ, 1000) + 1;
  119. break;
  120. }
  121. mod_timer(&ehci->watchdog, t + jiffies);
  122. }
  123. }
  124. /*-------------------------------------------------------------------------*/
  125. /*
  126. * handshake - spin reading hc until handshake completes or fails
  127. * @ptr: address of hc register to be read
  128. * @mask: bits to look at in result of read
  129. * @done: value of those bits when handshake succeeds
  130. * @usec: timeout in microseconds
  131. *
  132. * Returns negative errno, or zero on success
  133. *
  134. * Success happens when the "mask" bits have the specified value (hardware
  135. * handshake done). There are two failure modes: "usec" have passed (major
  136. * hardware flakeout), or the register reads as all-ones (hardware removed).
  137. *
  138. * That last failure should_only happen in cases like physical cardbus eject
  139. * before driver shutdown. But it also seems to be caused by bugs in cardbus
  140. * bridge shutdown: shutting down the bridge before the devices using it.
  141. */
  142. static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
  143. u32 mask, u32 done, int usec)
  144. {
  145. u32 result;
  146. do {
  147. result = ehci_readl(ehci, ptr);
  148. if (result == ~(u32)0) /* card removed */
  149. return -ENODEV;
  150. result &= mask;
  151. if (result == done)
  152. return 0;
  153. udelay (1);
  154. usec--;
  155. } while (usec > 0);
  156. return -ETIMEDOUT;
  157. }
  158. /* force HC to halt state from unknown (EHCI spec section 2.3) */
  159. static int ehci_halt (struct ehci_hcd *ehci)
  160. {
  161. u32 temp = ehci_readl(ehci, &ehci->regs->status);
  162. /* disable any irqs left enabled by previous code */
  163. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  164. if ((temp & STS_HALT) != 0)
  165. return 0;
  166. temp = ehci_readl(ehci, &ehci->regs->command);
  167. temp &= ~CMD_RUN;
  168. ehci_writel(ehci, temp, &ehci->regs->command);
  169. return handshake (ehci, &ehci->regs->status,
  170. STS_HALT, STS_HALT, 16 * 125);
  171. }
  172. static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr,
  173. u32 mask, u32 done, int usec)
  174. {
  175. int error;
  176. error = handshake(ehci, ptr, mask, done, usec);
  177. if (error) {
  178. ehci_halt(ehci);
  179. ehci_to_hcd(ehci)->state = HC_STATE_HALT;
  180. ehci_err(ehci, "force halt; handhake %p %08x %08x -> %d\n",
  181. ptr, mask, done, error);
  182. }
  183. return error;
  184. }
  185. /* put TDI/ARC silicon into EHCI mode */
  186. static void tdi_reset (struct ehci_hcd *ehci)
  187. {
  188. u32 __iomem *reg_ptr;
  189. u32 tmp;
  190. reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE);
  191. tmp = ehci_readl(ehci, reg_ptr);
  192. tmp |= USBMODE_CM_HC;
  193. /* The default byte access to MMR space is LE after
  194. * controller reset. Set the required endian mode
  195. * for transfer buffers to match the host microprocessor
  196. */
  197. if (ehci_big_endian_mmio(ehci))
  198. tmp |= USBMODE_BE;
  199. ehci_writel(ehci, tmp, reg_ptr);
  200. }
  201. /* reset a non-running (STS_HALT == 1) controller */
  202. static int ehci_reset (struct ehci_hcd *ehci)
  203. {
  204. int retval;
  205. u32 command = ehci_readl(ehci, &ehci->regs->command);
  206. command |= CMD_RESET;
  207. dbg_cmd (ehci, "reset", command);
  208. ehci_writel(ehci, command, &ehci->regs->command);
  209. ehci_to_hcd(ehci)->state = HC_STATE_HALT;
  210. ehci->next_statechange = jiffies;
  211. retval = handshake (ehci, &ehci->regs->command,
  212. CMD_RESET, 0, 250 * 1000);
  213. if (retval)
  214. return retval;
  215. if (ehci_is_TDI(ehci))
  216. tdi_reset (ehci);
  217. return retval;
  218. }
  219. /* idle the controller (from running) */
  220. static void ehci_quiesce (struct ehci_hcd *ehci)
  221. {
  222. u32 temp;
  223. #ifdef DEBUG
  224. if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))
  225. BUG ();
  226. #endif
  227. /* wait for any schedule enables/disables to take effect */
  228. temp = ehci_readl(ehci, &ehci->regs->command) << 10;
  229. temp &= STS_ASS | STS_PSS;
  230. if (handshake_on_error_set_halt(ehci, &ehci->regs->status,
  231. STS_ASS | STS_PSS, temp, 16 * 125))
  232. return;
  233. /* then disable anything that's still active */
  234. temp = ehci_readl(ehci, &ehci->regs->command);
  235. temp &= ~(CMD_ASE | CMD_IAAD | CMD_PSE);
  236. ehci_writel(ehci, temp, &ehci->regs->command);
  237. /* hardware can take 16 microframes to turn off ... */
  238. handshake_on_error_set_halt(ehci, &ehci->regs->status,
  239. STS_ASS | STS_PSS, 0, 16 * 125);
  240. }
  241. /*-------------------------------------------------------------------------*/
  242. static void end_unlink_async(struct ehci_hcd *ehci);
  243. static void ehci_work(struct ehci_hcd *ehci);
  244. #include "ehci-hub.c"
  245. #include "ehci-mem.c"
  246. #include "ehci-q.c"
  247. #include "ehci-sched.c"
  248. /*-------------------------------------------------------------------------*/
  249. static void ehci_iaa_watchdog(unsigned long param)
  250. {
  251. struct ehci_hcd *ehci = (struct ehci_hcd *) param;
  252. unsigned long flags;
  253. spin_lock_irqsave (&ehci->lock, flags);
  254. /* Lost IAA irqs wedge things badly; seen first with a vt8235.
  255. * So we need this watchdog, but must protect it against both
  256. * (a) SMP races against real IAA firing and retriggering, and
  257. * (b) clean HC shutdown, when IAA watchdog was pending.
  258. */
  259. if (ehci->reclaim
  260. && !timer_pending(&ehci->iaa_watchdog)
  261. && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
  262. u32 cmd, status;
  263. /* If we get here, IAA is *REALLY* late. It's barely
  264. * conceivable that the system is so busy that CMD_IAAD
  265. * is still legitimately set, so let's be sure it's
  266. * clear before we read STS_IAA. (The HC should clear
  267. * CMD_IAAD when it sets STS_IAA.)
  268. */
  269. cmd = ehci_readl(ehci, &ehci->regs->command);
  270. if (cmd & CMD_IAAD)
  271. ehci_writel(ehci, cmd & ~CMD_IAAD,
  272. &ehci->regs->command);
  273. /* If IAA is set here it either legitimately triggered
  274. * before we cleared IAAD above (but _way_ late, so we'll
  275. * still count it as lost) ... or a silicon erratum:
  276. * - VIA seems to set IAA without triggering the IRQ;
  277. * - IAAD potentially cleared without setting IAA.
  278. */
  279. status = ehci_readl(ehci, &ehci->regs->status);
  280. if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
  281. COUNT (ehci->stats.lost_iaa);
  282. ehci_writel(ehci, STS_IAA, &ehci->regs->status);
  283. }
  284. ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n",
  285. status, cmd);
  286. end_unlink_async(ehci);
  287. }
  288. spin_unlock_irqrestore(&ehci->lock, flags);
  289. }
  290. static void ehci_watchdog(unsigned long param)
  291. {
  292. struct ehci_hcd *ehci = (struct ehci_hcd *) param;
  293. unsigned long flags;
  294. spin_lock_irqsave(&ehci->lock, flags);
  295. /* stop async processing after it's idled a bit */
  296. if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
  297. start_unlink_async (ehci, ehci->async);
  298. /* ehci could run by timer, without IRQs ... */
  299. ehci_work (ehci);
  300. spin_unlock_irqrestore (&ehci->lock, flags);
  301. }
  302. /* On some systems, leaving remote wakeup enabled prevents system shutdown.
  303. * The firmware seems to think that powering off is a wakeup event!
  304. * This routine turns off remote wakeup and everything else, on all ports.
  305. */
  306. static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
  307. {
  308. int port = HCS_N_PORTS(ehci->hcs_params);
  309. while (port--)
  310. ehci_writel(ehci, PORT_RWC_BITS,
  311. &ehci->regs->port_status[port]);
  312. }
  313. /*
  314. * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
  315. * Should be called with ehci->lock held.
  316. */
  317. static void ehci_silence_controller(struct ehci_hcd *ehci)
  318. {
  319. ehci_halt(ehci);
  320. ehci_turn_off_all_ports(ehci);
  321. /* make BIOS/etc use companion controller during reboot */
  322. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  323. /* unblock posted writes */
  324. ehci_readl(ehci, &ehci->regs->configured_flag);
  325. }
  326. /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
  327. * This forcibly disables dma and IRQs, helping kexec and other cases
  328. * where the next system software may expect clean state.
  329. */
  330. static void ehci_shutdown(struct usb_hcd *hcd)
  331. {
  332. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  333. del_timer_sync(&ehci->watchdog);
  334. del_timer_sync(&ehci->iaa_watchdog);
  335. spin_lock_irq(&ehci->lock);
  336. ehci_silence_controller(ehci);
  337. spin_unlock_irq(&ehci->lock);
  338. }
  339. static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
  340. {
  341. unsigned port;
  342. if (!HCS_PPC (ehci->hcs_params))
  343. return;
  344. ehci_dbg (ehci, "...power%s ports...\n", is_on ? "up" : "down");
  345. for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; )
  346. (void) ehci_hub_control(ehci_to_hcd(ehci),
  347. is_on ? SetPortFeature : ClearPortFeature,
  348. USB_PORT_FEAT_POWER,
  349. port--, NULL, 0);
  350. /* Flush those writes */
  351. ehci_readl(ehci, &ehci->regs->command);
  352. msleep(20);
  353. }
  354. /*-------------------------------------------------------------------------*/
  355. /*
  356. * ehci_work is called from some interrupts, timers, and so on.
  357. * it calls driver completion functions, after dropping ehci->lock.
  358. */
  359. static void ehci_work (struct ehci_hcd *ehci)
  360. {
  361. timer_action_done (ehci, TIMER_IO_WATCHDOG);
  362. /* another CPU may drop ehci->lock during a schedule scan while
  363. * it reports urb completions. this flag guards against bogus
  364. * attempts at re-entrant schedule scanning.
  365. */
  366. if (ehci->scanning)
  367. return;
  368. ehci->scanning = 1;
  369. scan_async (ehci);
  370. if (ehci->next_uframe != -1)
  371. scan_periodic (ehci);
  372. ehci->scanning = 0;
  373. /* the IO watchdog guards against hardware or driver bugs that
  374. * misplace IRQs, and should let us run completely without IRQs.
  375. * such lossage has been observed on both VT6202 and VT8235.
  376. */
  377. if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) &&
  378. (ehci->async->qh_next.ptr != NULL ||
  379. ehci->periodic_sched != 0))
  380. timer_action (ehci, TIMER_IO_WATCHDOG);
  381. }
  382. /*
  383. * Called when the ehci_hcd module is removed.
  384. */
  385. static void ehci_stop (struct usb_hcd *hcd)
  386. {
  387. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  388. ehci_dbg (ehci, "stop\n");
  389. /* no more interrupts ... */
  390. del_timer_sync (&ehci->watchdog);
  391. del_timer_sync(&ehci->iaa_watchdog);
  392. spin_lock_irq(&ehci->lock);
  393. if (HC_IS_RUNNING (hcd->state))
  394. ehci_quiesce (ehci);
  395. ehci_silence_controller(ehci);
  396. ehci_reset (ehci);
  397. spin_unlock_irq(&ehci->lock);
  398. remove_companion_file(ehci);
  399. remove_debug_files (ehci);
  400. /* root hub is shut down separately (first, when possible) */
  401. spin_lock_irq (&ehci->lock);
  402. if (ehci->async)
  403. ehci_work (ehci);
  404. spin_unlock_irq (&ehci->lock);
  405. ehci_mem_cleanup (ehci);
  406. #ifdef EHCI_STATS
  407. ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
  408. ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
  409. ehci->stats.lost_iaa);
  410. ehci_dbg (ehci, "complete %ld unlink %ld\n",
  411. ehci->stats.complete, ehci->stats.unlink);
  412. #endif
  413. dbg_status (ehci, "ehci_stop completed",
  414. ehci_readl(ehci, &ehci->regs->status));
  415. }
  416. /* one-time init, only for memory state */
  417. static int ehci_init(struct usb_hcd *hcd)
  418. {
  419. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  420. u32 temp;
  421. int retval;
  422. u32 hcc_params;
  423. spin_lock_init(&ehci->lock);
  424. init_timer(&ehci->watchdog);
  425. ehci->watchdog.function = ehci_watchdog;
  426. ehci->watchdog.data = (unsigned long) ehci;
  427. init_timer(&ehci->iaa_watchdog);
  428. ehci->iaa_watchdog.function = ehci_iaa_watchdog;
  429. ehci->iaa_watchdog.data = (unsigned long) ehci;
  430. /*
  431. * hw default: 1K periodic list heads, one per frame.
  432. * periodic_size can shrink by USBCMD update if hcc_params allows.
  433. */
  434. ehci->periodic_size = DEFAULT_I_TDPS;
  435. INIT_LIST_HEAD(&ehci->cached_itd_list);
  436. if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
  437. return retval;
  438. /* controllers may cache some of the periodic schedule ... */
  439. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  440. if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
  441. ehci->i_thresh = 8;
  442. else // N microframes cached
  443. ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
  444. ehci->reclaim = NULL;
  445. ehci->next_uframe = -1;
  446. ehci->clock_frame = -1;
  447. /*
  448. * dedicate a qh for the async ring head, since we couldn't unlink
  449. * a 'real' qh without stopping the async schedule [4.8]. use it
  450. * as the 'reclamation list head' too.
  451. * its dummy is used in hw_alt_next of many tds, to prevent the qh
  452. * from automatically advancing to the next td after short reads.
  453. */
  454. ehci->async->qh_next.qh = NULL;
  455. ehci->async->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
  456. ehci->async->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
  457. ehci->async->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
  458. ehci->async->hw_qtd_next = EHCI_LIST_END(ehci);
  459. ehci->async->qh_state = QH_STATE_LINKED;
  460. ehci->async->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
  461. /* clear interrupt enables, set irq latency */
  462. if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
  463. log2_irq_thresh = 0;
  464. temp = 1 << (16 + log2_irq_thresh);
  465. if (HCC_CANPARK(hcc_params)) {
  466. /* HW default park == 3, on hardware that supports it (like
  467. * NVidia and ALI silicon), maximizes throughput on the async
  468. * schedule by avoiding QH fetches between transfers.
  469. *
  470. * With fast usb storage devices and NForce2, "park" seems to
  471. * make problems: throughput reduction (!), data errors...
  472. */
  473. if (park) {
  474. park = min(park, (unsigned) 3);
  475. temp |= CMD_PARK;
  476. temp |= park << 8;
  477. }
  478. ehci_dbg(ehci, "park %d\n", park);
  479. }
  480. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  481. /* periodic schedule size can be smaller than default */
  482. temp &= ~(3 << 2);
  483. temp |= (EHCI_TUNE_FLS << 2);
  484. switch (EHCI_TUNE_FLS) {
  485. case 0: ehci->periodic_size = 1024; break;
  486. case 1: ehci->periodic_size = 512; break;
  487. case 2: ehci->periodic_size = 256; break;
  488. default: BUG();
  489. }
  490. }
  491. ehci->command = temp;
  492. return 0;
  493. }
  494. /* start HC running; it's halted, ehci_init() has been run (once) */
  495. static int ehci_run (struct usb_hcd *hcd)
  496. {
  497. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  498. int retval;
  499. u32 temp;
  500. u32 hcc_params;
  501. hcd->uses_new_polling = 1;
  502. hcd->poll_rh = 0;
  503. /* EHCI spec section 4.1 */
  504. if ((retval = ehci_reset(ehci)) != 0) {
  505. ehci_mem_cleanup(ehci);
  506. return retval;
  507. }
  508. ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  509. ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
  510. /*
  511. * hcc_params controls whether ehci->regs->segment must (!!!)
  512. * be used; it constrains QH/ITD/SITD and QTD locations.
  513. * pci_pool consistent memory always uses segment zero.
  514. * streaming mappings for I/O buffers, like pci_map_single(),
  515. * can return segments above 4GB, if the device allows.
  516. *
  517. * NOTE: the dma mask is visible through dma_supported(), so
  518. * drivers can pass this info along ... like NETIF_F_HIGHDMA,
  519. * Scsi_Host.highmem_io, and so forth. It's readonly to all
  520. * host side drivers though.
  521. */
  522. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  523. if (HCC_64BIT_ADDR(hcc_params)) {
  524. ehci_writel(ehci, 0, &ehci->regs->segment);
  525. #if 0
  526. // this is deeply broken on almost all architectures
  527. if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
  528. ehci_info(ehci, "enabled 64bit DMA\n");
  529. #endif
  530. }
  531. // Philips, Intel, and maybe others need CMD_RUN before the
  532. // root hub will detect new devices (why?); NEC doesn't
  533. ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
  534. ehci->command |= CMD_RUN;
  535. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  536. dbg_cmd (ehci, "init", ehci->command);
  537. /*
  538. * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
  539. * are explicitly handed to companion controller(s), so no TT is
  540. * involved with the root hub. (Except where one is integrated,
  541. * and there's no companion controller unless maybe for USB OTG.)
  542. *
  543. * Turning on the CF flag will transfer ownership of all ports
  544. * from the companions to the EHCI controller. If any of the
  545. * companions are in the middle of a port reset at the time, it
  546. * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
  547. * guarantees that no resets are in progress. After we set CF,
  548. * a short delay lets the hardware catch up; new resets shouldn't
  549. * be started before the port switching actions could complete.
  550. */
  551. down_write(&ehci_cf_port_reset_rwsem);
  552. hcd->state = HC_STATE_RUNNING;
  553. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  554. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  555. msleep(5);
  556. up_write(&ehci_cf_port_reset_rwsem);
  557. temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
  558. ehci_info (ehci,
  559. "USB %x.%x started, EHCI %x.%02x%s\n",
  560. ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
  561. temp >> 8, temp & 0xff,
  562. ignore_oc ? ", overcurrent ignored" : "");
  563. ehci_writel(ehci, INTR_MASK,
  564. &ehci->regs->intr_enable); /* Turn On Interrupts */
  565. /* GRR this is run-once init(), being done every time the HC starts.
  566. * So long as they're part of class devices, we can't do it init()
  567. * since the class device isn't created that early.
  568. */
  569. create_debug_files(ehci);
  570. create_companion_file(ehci);
  571. return 0;
  572. }
  573. /*-------------------------------------------------------------------------*/
  574. static irqreturn_t ehci_irq (struct usb_hcd *hcd)
  575. {
  576. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  577. u32 status, masked_status, pcd_status = 0, cmd;
  578. int bh;
  579. spin_lock (&ehci->lock);
  580. status = ehci_readl(ehci, &ehci->regs->status);
  581. /* e.g. cardbus physical eject */
  582. if (status == ~(u32) 0) {
  583. ehci_dbg (ehci, "device removed\n");
  584. goto dead;
  585. }
  586. masked_status = status & INTR_MASK;
  587. if (!masked_status) { /* irq sharing? */
  588. spin_unlock(&ehci->lock);
  589. return IRQ_NONE;
  590. }
  591. /* clear (just) interrupts */
  592. ehci_writel(ehci, masked_status, &ehci->regs->status);
  593. cmd = ehci_readl(ehci, &ehci->regs->command);
  594. bh = 0;
  595. #ifdef VERBOSE_DEBUG
  596. /* unrequested/ignored: Frame List Rollover */
  597. dbg_status (ehci, "irq", status);
  598. #endif
  599. /* INT, ERR, and IAA interrupt rates can be throttled */
  600. /* normal [4.15.1.2] or error [4.15.1.1] completion */
  601. if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
  602. if (likely ((status & STS_ERR) == 0))
  603. COUNT (ehci->stats.normal);
  604. else
  605. COUNT (ehci->stats.error);
  606. bh = 1;
  607. }
  608. /* complete the unlinking of some qh [4.15.2.3] */
  609. if (status & STS_IAA) {
  610. /* guard against (alleged) silicon errata */
  611. if (cmd & CMD_IAAD) {
  612. ehci_writel(ehci, cmd & ~CMD_IAAD,
  613. &ehci->regs->command);
  614. ehci_dbg(ehci, "IAA with IAAD still set?\n");
  615. }
  616. if (ehci->reclaim) {
  617. COUNT(ehci->stats.reclaim);
  618. end_unlink_async(ehci);
  619. } else
  620. ehci_dbg(ehci, "IAA with nothing to reclaim?\n");
  621. }
  622. /* remote wakeup [4.3.1] */
  623. if (status & STS_PCD) {
  624. unsigned i = HCS_N_PORTS (ehci->hcs_params);
  625. /* kick root hub later */
  626. pcd_status = status;
  627. /* resume root hub? */
  628. if (!(cmd & CMD_RUN))
  629. usb_hcd_resume_root_hub(hcd);
  630. while (i--) {
  631. int pstatus = ehci_readl(ehci,
  632. &ehci->regs->port_status [i]);
  633. if (pstatus & PORT_OWNER)
  634. continue;
  635. if (!(test_bit(i, &ehci->suspended_ports) &&
  636. ((pstatus & PORT_RESUME) ||
  637. !(pstatus & PORT_SUSPEND)) &&
  638. (pstatus & PORT_PE) &&
  639. ehci->reset_done[i] == 0))
  640. continue;
  641. /* start 20 msec resume signaling from this port,
  642. * and make khubd collect PORT_STAT_C_SUSPEND to
  643. * stop that signaling.
  644. */
  645. ehci->reset_done [i] = jiffies + msecs_to_jiffies (20);
  646. ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
  647. mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
  648. }
  649. }
  650. /* PCI errors [4.15.2.4] */
  651. if (unlikely ((status & STS_FATAL) != 0)) {
  652. ehci_err(ehci, "fatal error\n");
  653. dbg_cmd(ehci, "fatal", cmd);
  654. dbg_status(ehci, "fatal", status);
  655. ehci_halt(ehci);
  656. dead:
  657. ehci_reset(ehci);
  658. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  659. /* generic layer kills/unlinks all urbs, then
  660. * uses ehci_stop to clean up the rest
  661. */
  662. bh = 1;
  663. }
  664. if (bh)
  665. ehci_work (ehci);
  666. spin_unlock (&ehci->lock);
  667. if (pcd_status)
  668. usb_hcd_poll_rh_status(hcd);
  669. return IRQ_HANDLED;
  670. }
  671. /*-------------------------------------------------------------------------*/
  672. /*
  673. * non-error returns are a promise to giveback() the urb later
  674. * we drop ownership so next owner (or urb unlink) can get it
  675. *
  676. * urb + dev is in hcd.self.controller.urb_list
  677. * we're queueing TDs onto software and hardware lists
  678. *
  679. * hcd-specific init for hcpriv hasn't been done yet
  680. *
  681. * NOTE: control, bulk, and interrupt share the same code to append TDs
  682. * to a (possibly active) QH, and the same QH scanning code.
  683. */
  684. static int ehci_urb_enqueue (
  685. struct usb_hcd *hcd,
  686. struct urb *urb,
  687. gfp_t mem_flags
  688. ) {
  689. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  690. struct list_head qtd_list;
  691. INIT_LIST_HEAD (&qtd_list);
  692. switch (usb_pipetype (urb->pipe)) {
  693. case PIPE_CONTROL:
  694. /* qh_completions() code doesn't handle all the fault cases
  695. * in multi-TD control transfers. Even 1KB is rare anyway.
  696. */
  697. if (urb->transfer_buffer_length > (16 * 1024))
  698. return -EMSGSIZE;
  699. /* FALLTHROUGH */
  700. /* case PIPE_BULK: */
  701. default:
  702. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  703. return -ENOMEM;
  704. return submit_async(ehci, urb, &qtd_list, mem_flags);
  705. case PIPE_INTERRUPT:
  706. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  707. return -ENOMEM;
  708. return intr_submit(ehci, urb, &qtd_list, mem_flags);
  709. case PIPE_ISOCHRONOUS:
  710. if (urb->dev->speed == USB_SPEED_HIGH)
  711. return itd_submit (ehci, urb, mem_flags);
  712. else
  713. return sitd_submit (ehci, urb, mem_flags);
  714. }
  715. }
  716. static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
  717. {
  718. /* failfast */
  719. if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim)
  720. end_unlink_async(ehci);
  721. /* if it's not linked then there's nothing to do */
  722. if (qh->qh_state != QH_STATE_LINKED)
  723. ;
  724. /* defer till later if busy */
  725. else if (ehci->reclaim) {
  726. struct ehci_qh *last;
  727. for (last = ehci->reclaim;
  728. last->reclaim;
  729. last = last->reclaim)
  730. continue;
  731. qh->qh_state = QH_STATE_UNLINK_WAIT;
  732. last->reclaim = qh;
  733. /* start IAA cycle */
  734. } else
  735. start_unlink_async (ehci, qh);
  736. }
  737. /* remove from hardware lists
  738. * completions normally happen asynchronously
  739. */
  740. static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  741. {
  742. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  743. struct ehci_qh *qh;
  744. unsigned long flags;
  745. int rc;
  746. spin_lock_irqsave (&ehci->lock, flags);
  747. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  748. if (rc)
  749. goto done;
  750. switch (usb_pipetype (urb->pipe)) {
  751. // case PIPE_CONTROL:
  752. // case PIPE_BULK:
  753. default:
  754. qh = (struct ehci_qh *) urb->hcpriv;
  755. if (!qh)
  756. break;
  757. switch (qh->qh_state) {
  758. case QH_STATE_LINKED:
  759. case QH_STATE_COMPLETING:
  760. unlink_async(ehci, qh);
  761. break;
  762. case QH_STATE_UNLINK:
  763. case QH_STATE_UNLINK_WAIT:
  764. /* already started */
  765. break;
  766. case QH_STATE_IDLE:
  767. WARN_ON(1);
  768. break;
  769. }
  770. break;
  771. case PIPE_INTERRUPT:
  772. qh = (struct ehci_qh *) urb->hcpriv;
  773. if (!qh)
  774. break;
  775. switch (qh->qh_state) {
  776. case QH_STATE_LINKED:
  777. intr_deschedule (ehci, qh);
  778. /* FALL THROUGH */
  779. case QH_STATE_IDLE:
  780. qh_completions (ehci, qh);
  781. break;
  782. default:
  783. ehci_dbg (ehci, "bogus qh %p state %d\n",
  784. qh, qh->qh_state);
  785. goto done;
  786. }
  787. /* reschedule QH iff another request is queued */
  788. if (!list_empty (&qh->qtd_list)
  789. && HC_IS_RUNNING (hcd->state)) {
  790. rc = qh_schedule(ehci, qh);
  791. /* An error here likely indicates handshake failure
  792. * or no space left in the schedule. Neither fault
  793. * should happen often ...
  794. *
  795. * FIXME kill the now-dysfunctional queued urbs
  796. */
  797. if (rc != 0)
  798. ehci_err(ehci,
  799. "can't reschedule qh %p, err %d",
  800. qh, rc);
  801. }
  802. break;
  803. case PIPE_ISOCHRONOUS:
  804. // itd or sitd ...
  805. // wait till next completion, do it then.
  806. // completion irqs can wait up to 1024 msec,
  807. break;
  808. }
  809. done:
  810. spin_unlock_irqrestore (&ehci->lock, flags);
  811. return rc;
  812. }
  813. /*-------------------------------------------------------------------------*/
  814. // bulk qh holds the data toggle
  815. static void
  816. ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  817. {
  818. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  819. unsigned long flags;
  820. struct ehci_qh *qh, *tmp;
  821. /* ASSERT: any requests/urbs are being unlinked */
  822. /* ASSERT: nobody can be submitting urbs for this any more */
  823. rescan:
  824. spin_lock_irqsave (&ehci->lock, flags);
  825. qh = ep->hcpriv;
  826. if (!qh)
  827. goto done;
  828. /* endpoints can be iso streams. for now, we don't
  829. * accelerate iso completions ... so spin a while.
  830. */
  831. if (qh->hw_info1 == 0) {
  832. ehci_vdbg (ehci, "iso delay\n");
  833. goto idle_timeout;
  834. }
  835. if (!HC_IS_RUNNING (hcd->state))
  836. qh->qh_state = QH_STATE_IDLE;
  837. switch (qh->qh_state) {
  838. case QH_STATE_LINKED:
  839. for (tmp = ehci->async->qh_next.qh;
  840. tmp && tmp != qh;
  841. tmp = tmp->qh_next.qh)
  842. continue;
  843. /* periodic qh self-unlinks on empty */
  844. if (!tmp)
  845. goto nogood;
  846. unlink_async (ehci, qh);
  847. /* FALL THROUGH */
  848. case QH_STATE_UNLINK: /* wait for hw to finish? */
  849. case QH_STATE_UNLINK_WAIT:
  850. idle_timeout:
  851. spin_unlock_irqrestore (&ehci->lock, flags);
  852. schedule_timeout_uninterruptible(1);
  853. goto rescan;
  854. case QH_STATE_IDLE: /* fully unlinked */
  855. if (qh->clearing_tt)
  856. goto idle_timeout;
  857. if (list_empty (&qh->qtd_list)) {
  858. qh_put (qh);
  859. break;
  860. }
  861. /* else FALL THROUGH */
  862. default:
  863. nogood:
  864. /* caller was supposed to have unlinked any requests;
  865. * that's not our job. just leak this memory.
  866. */
  867. ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
  868. qh, ep->desc.bEndpointAddress, qh->qh_state,
  869. list_empty (&qh->qtd_list) ? "" : "(has tds)");
  870. break;
  871. }
  872. ep->hcpriv = NULL;
  873. done:
  874. spin_unlock_irqrestore (&ehci->lock, flags);
  875. return;
  876. }
  877. static void
  878. ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  879. {
  880. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  881. struct ehci_qh *qh;
  882. int eptype = usb_endpoint_type(&ep->desc);
  883. int epnum = usb_endpoint_num(&ep->desc);
  884. int is_out = usb_endpoint_dir_out(&ep->desc);
  885. unsigned long flags;
  886. if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
  887. return;
  888. spin_lock_irqsave(&ehci->lock, flags);
  889. qh = ep->hcpriv;
  890. /* For Bulk and Interrupt endpoints we maintain the toggle state
  891. * in the hardware; the toggle bits in udev aren't used at all.
  892. * When an endpoint is reset by usb_clear_halt() we must reset
  893. * the toggle bit in the QH.
  894. */
  895. if (qh) {
  896. usb_settoggle(qh->dev, epnum, is_out, 0);
  897. if (!list_empty(&qh->qtd_list)) {
  898. WARN_ONCE(1, "clear_halt for a busy endpoint\n");
  899. } else if (qh->qh_state == QH_STATE_LINKED) {
  900. /* The toggle value in the QH can't be updated
  901. * while the QH is active. Unlink it now;
  902. * re-linking will call qh_refresh().
  903. */
  904. if (eptype == USB_ENDPOINT_XFER_BULK) {
  905. unlink_async(ehci, qh);
  906. } else {
  907. intr_deschedule(ehci, qh);
  908. (void) qh_schedule(ehci, qh);
  909. }
  910. }
  911. }
  912. spin_unlock_irqrestore(&ehci->lock, flags);
  913. }
  914. static int ehci_get_frame (struct usb_hcd *hcd)
  915. {
  916. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  917. return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) %
  918. ehci->periodic_size;
  919. }
  920. /*-------------------------------------------------------------------------*/
  921. MODULE_DESCRIPTION(DRIVER_DESC);
  922. MODULE_AUTHOR (DRIVER_AUTHOR);
  923. MODULE_LICENSE ("GPL");
  924. #ifdef CONFIG_PCI
  925. #include "ehci-pci.c"
  926. #define PCI_DRIVER ehci_pci_driver
  927. #endif
  928. #ifdef CONFIG_USB_EHCI_FSL
  929. #include "ehci-fsl.c"
  930. #define PLATFORM_DRIVER ehci_fsl_driver
  931. #endif
  932. #ifdef CONFIG_SOC_AU1200
  933. #include "ehci-au1xxx.c"
  934. #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
  935. #endif
  936. #ifdef CONFIG_PPC_PS3
  937. #include "ehci-ps3.c"
  938. #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
  939. #endif
  940. #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
  941. #include "ehci-ppc-of.c"
  942. #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
  943. #endif
  944. #ifdef CONFIG_PLAT_ORION
  945. #include "ehci-orion.c"
  946. #define PLATFORM_DRIVER ehci_orion_driver
  947. #endif
  948. #ifdef CONFIG_ARCH_IXP4XX
  949. #include "ehci-ixp4xx.c"
  950. #define PLATFORM_DRIVER ixp4xx_ehci_driver
  951. #endif
  952. #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
  953. !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER)
  954. #error "missing bus glue for ehci-hcd"
  955. #endif
  956. static int __init ehci_hcd_init(void)
  957. {
  958. int retval = 0;
  959. if (usb_disabled())
  960. return -ENODEV;
  961. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  962. set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  963. if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
  964. test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
  965. printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
  966. " before uhci_hcd and ohci_hcd, not after\n");
  967. pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  968. hcd_name,
  969. sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  970. sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  971. #ifdef DEBUG
  972. ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
  973. if (!ehci_debug_root) {
  974. retval = -ENOENT;
  975. goto err_debug;
  976. }
  977. #endif
  978. #ifdef PLATFORM_DRIVER
  979. retval = platform_driver_register(&PLATFORM_DRIVER);
  980. if (retval < 0)
  981. goto clean0;
  982. #endif
  983. #ifdef PCI_DRIVER
  984. retval = pci_register_driver(&PCI_DRIVER);
  985. if (retval < 0)
  986. goto clean1;
  987. #endif
  988. #ifdef PS3_SYSTEM_BUS_DRIVER
  989. retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  990. if (retval < 0)
  991. goto clean2;
  992. #endif
  993. #ifdef OF_PLATFORM_DRIVER
  994. retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
  995. if (retval < 0)
  996. goto clean3;
  997. #endif
  998. return retval;
  999. #ifdef OF_PLATFORM_DRIVER
  1000. /* of_unregister_platform_driver(&OF_PLATFORM_DRIVER); */
  1001. clean3:
  1002. #endif
  1003. #ifdef PS3_SYSTEM_BUS_DRIVER
  1004. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1005. clean2:
  1006. #endif
  1007. #ifdef PCI_DRIVER
  1008. pci_unregister_driver(&PCI_DRIVER);
  1009. clean1:
  1010. #endif
  1011. #ifdef PLATFORM_DRIVER
  1012. platform_driver_unregister(&PLATFORM_DRIVER);
  1013. clean0:
  1014. #endif
  1015. #ifdef DEBUG
  1016. debugfs_remove(ehci_debug_root);
  1017. ehci_debug_root = NULL;
  1018. err_debug:
  1019. #endif
  1020. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1021. return retval;
  1022. }
  1023. module_init(ehci_hcd_init);
  1024. static void __exit ehci_hcd_cleanup(void)
  1025. {
  1026. #ifdef OF_PLATFORM_DRIVER
  1027. of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
  1028. #endif
  1029. #ifdef PLATFORM_DRIVER
  1030. platform_driver_unregister(&PLATFORM_DRIVER);
  1031. #endif
  1032. #ifdef PCI_DRIVER
  1033. pci_unregister_driver(&PCI_DRIVER);
  1034. #endif
  1035. #ifdef PS3_SYSTEM_BUS_DRIVER
  1036. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1037. #endif
  1038. #ifdef DEBUG
  1039. debugfs_remove(ehci_debug_root);
  1040. #endif
  1041. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1042. }
  1043. module_exit(ehci_hcd_cleanup);