ehci-hcd.c 35 KB

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