ehci-hcd.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  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_PER_PORT_CHANGE_EVENT(hcc_params)) {
  493. ehci->has_ppcd = 1;
  494. ehci_dbg(ehci, "enable per-port change event\n");
  495. temp |= CMD_PPCEE;
  496. }
  497. if (HCC_CANPARK(hcc_params)) {
  498. /* HW default park == 3, on hardware that supports it (like
  499. * NVidia and ALI silicon), maximizes throughput on the async
  500. * schedule by avoiding QH fetches between transfers.
  501. *
  502. * With fast usb storage devices and NForce2, "park" seems to
  503. * make problems: throughput reduction (!), data errors...
  504. */
  505. if (park) {
  506. park = min(park, (unsigned) 3);
  507. temp |= CMD_PARK;
  508. temp |= park << 8;
  509. }
  510. ehci_dbg(ehci, "park %d\n", park);
  511. }
  512. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  513. /* periodic schedule size can be smaller than default */
  514. temp &= ~(3 << 2);
  515. temp |= (EHCI_TUNE_FLS << 2);
  516. switch (EHCI_TUNE_FLS) {
  517. case 0: ehci->periodic_size = 1024; break;
  518. case 1: ehci->periodic_size = 512; break;
  519. case 2: ehci->periodic_size = 256; break;
  520. default: BUG();
  521. }
  522. }
  523. if (HCC_LPM(hcc_params)) {
  524. /* support link power management EHCI 1.1 addendum */
  525. ehci_dbg(ehci, "support lpm\n");
  526. ehci->has_lpm = 1;
  527. if (hird > 0xf) {
  528. ehci_dbg(ehci, "hird %d invalid, use default 0",
  529. hird);
  530. hird = 0;
  531. }
  532. temp |= hird << 24;
  533. }
  534. ehci->command = temp;
  535. /* Accept arbitrarily long scatter-gather lists */
  536. hcd->self.sg_tablesize = ~0;
  537. return 0;
  538. }
  539. /* start HC running; it's halted, ehci_init() has been run (once) */
  540. static int ehci_run (struct usb_hcd *hcd)
  541. {
  542. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  543. int retval;
  544. u32 temp;
  545. u32 hcc_params;
  546. hcd->uses_new_polling = 1;
  547. hcd->poll_rh = 0;
  548. /* EHCI spec section 4.1 */
  549. if ((retval = ehci_reset(ehci)) != 0) {
  550. ehci_mem_cleanup(ehci);
  551. return retval;
  552. }
  553. ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  554. ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
  555. /*
  556. * hcc_params controls whether ehci->regs->segment must (!!!)
  557. * be used; it constrains QH/ITD/SITD and QTD locations.
  558. * pci_pool consistent memory always uses segment zero.
  559. * streaming mappings for I/O buffers, like pci_map_single(),
  560. * can return segments above 4GB, if the device allows.
  561. *
  562. * NOTE: the dma mask is visible through dma_supported(), so
  563. * drivers can pass this info along ... like NETIF_F_HIGHDMA,
  564. * Scsi_Host.highmem_io, and so forth. It's readonly to all
  565. * host side drivers though.
  566. */
  567. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  568. if (HCC_64BIT_ADDR(hcc_params)) {
  569. ehci_writel(ehci, 0, &ehci->regs->segment);
  570. #if 0
  571. // this is deeply broken on almost all architectures
  572. if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
  573. ehci_info(ehci, "enabled 64bit DMA\n");
  574. #endif
  575. }
  576. // Philips, Intel, and maybe others need CMD_RUN before the
  577. // root hub will detect new devices (why?); NEC doesn't
  578. ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
  579. ehci->command |= CMD_RUN;
  580. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  581. dbg_cmd (ehci, "init", ehci->command);
  582. /*
  583. * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
  584. * are explicitly handed to companion controller(s), so no TT is
  585. * involved with the root hub. (Except where one is integrated,
  586. * and there's no companion controller unless maybe for USB OTG.)
  587. *
  588. * Turning on the CF flag will transfer ownership of all ports
  589. * from the companions to the EHCI controller. If any of the
  590. * companions are in the middle of a port reset at the time, it
  591. * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
  592. * guarantees that no resets are in progress. After we set CF,
  593. * a short delay lets the hardware catch up; new resets shouldn't
  594. * be started before the port switching actions could complete.
  595. */
  596. down_write(&ehci_cf_port_reset_rwsem);
  597. hcd->state = HC_STATE_RUNNING;
  598. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  599. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  600. msleep(5);
  601. up_write(&ehci_cf_port_reset_rwsem);
  602. ehci->last_periodic_enable = ktime_get_real();
  603. temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
  604. ehci_info (ehci,
  605. "USB %x.%x started, EHCI %x.%02x%s\n",
  606. ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
  607. temp >> 8, temp & 0xff,
  608. ignore_oc ? ", overcurrent ignored" : "");
  609. ehci_writel(ehci, INTR_MASK,
  610. &ehci->regs->intr_enable); /* Turn On Interrupts */
  611. /* GRR this is run-once init(), being done every time the HC starts.
  612. * So long as they're part of class devices, we can't do it init()
  613. * since the class device isn't created that early.
  614. */
  615. create_debug_files(ehci);
  616. create_companion_file(ehci);
  617. return 0;
  618. }
  619. /*-------------------------------------------------------------------------*/
  620. static irqreturn_t ehci_irq (struct usb_hcd *hcd)
  621. {
  622. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  623. u32 status, masked_status, pcd_status = 0, cmd;
  624. int bh;
  625. spin_lock (&ehci->lock);
  626. status = ehci_readl(ehci, &ehci->regs->status);
  627. /* e.g. cardbus physical eject */
  628. if (status == ~(u32) 0) {
  629. ehci_dbg (ehci, "device removed\n");
  630. goto dead;
  631. }
  632. masked_status = status & INTR_MASK;
  633. if (!masked_status) { /* irq sharing? */
  634. spin_unlock(&ehci->lock);
  635. return IRQ_NONE;
  636. }
  637. /* clear (just) interrupts */
  638. ehci_writel(ehci, masked_status, &ehci->regs->status);
  639. cmd = ehci_readl(ehci, &ehci->regs->command);
  640. bh = 0;
  641. #ifdef VERBOSE_DEBUG
  642. /* unrequested/ignored: Frame List Rollover */
  643. dbg_status (ehci, "irq", status);
  644. #endif
  645. /* INT, ERR, and IAA interrupt rates can be throttled */
  646. /* normal [4.15.1.2] or error [4.15.1.1] completion */
  647. if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
  648. if (likely ((status & STS_ERR) == 0))
  649. COUNT (ehci->stats.normal);
  650. else
  651. COUNT (ehci->stats.error);
  652. bh = 1;
  653. }
  654. /* complete the unlinking of some qh [4.15.2.3] */
  655. if (status & STS_IAA) {
  656. /* guard against (alleged) silicon errata */
  657. if (cmd & CMD_IAAD) {
  658. ehci_writel(ehci, cmd & ~CMD_IAAD,
  659. &ehci->regs->command);
  660. ehci_dbg(ehci, "IAA with IAAD still set?\n");
  661. }
  662. if (ehci->reclaim) {
  663. COUNT(ehci->stats.reclaim);
  664. end_unlink_async(ehci);
  665. } else
  666. ehci_dbg(ehci, "IAA with nothing to reclaim?\n");
  667. }
  668. /* remote wakeup [4.3.1] */
  669. if (status & STS_PCD) {
  670. unsigned i = HCS_N_PORTS (ehci->hcs_params);
  671. u32 ppcd = 0;
  672. /* kick root hub later */
  673. pcd_status = status;
  674. /* resume root hub? */
  675. if (!(cmd & CMD_RUN))
  676. usb_hcd_resume_root_hub(hcd);
  677. /* get per-port change detect bits */
  678. if (ehci->has_ppcd)
  679. ppcd = status >> 16;
  680. while (i--) {
  681. int pstatus;
  682. /* leverage per-port change bits feature */
  683. if (ehci->has_ppcd && !(ppcd & (1 << i)))
  684. continue;
  685. pstatus = ehci_readl(ehci,
  686. &ehci->regs->port_status[i]);
  687. if (pstatus & PORT_OWNER)
  688. continue;
  689. if (!(test_bit(i, &ehci->suspended_ports) &&
  690. ((pstatus & PORT_RESUME) ||
  691. !(pstatus & PORT_SUSPEND)) &&
  692. (pstatus & PORT_PE) &&
  693. ehci->reset_done[i] == 0))
  694. continue;
  695. /* start 20 msec resume signaling from this port,
  696. * and make khubd collect PORT_STAT_C_SUSPEND to
  697. * stop that signaling. Use 5 ms extra for safety,
  698. * like usb_port_resume() does.
  699. */
  700. ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
  701. ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
  702. mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
  703. }
  704. }
  705. /* PCI errors [4.15.2.4] */
  706. if (unlikely ((status & STS_FATAL) != 0)) {
  707. ehci_err(ehci, "fatal error\n");
  708. dbg_cmd(ehci, "fatal", cmd);
  709. dbg_status(ehci, "fatal", status);
  710. ehci_halt(ehci);
  711. dead:
  712. ehci_reset(ehci);
  713. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  714. /* generic layer kills/unlinks all urbs, then
  715. * uses ehci_stop to clean up the rest
  716. */
  717. bh = 1;
  718. }
  719. if (bh)
  720. ehci_work (ehci);
  721. spin_unlock (&ehci->lock);
  722. if (pcd_status)
  723. usb_hcd_poll_rh_status(hcd);
  724. return IRQ_HANDLED;
  725. }
  726. /*-------------------------------------------------------------------------*/
  727. /*
  728. * non-error returns are a promise to giveback() the urb later
  729. * we drop ownership so next owner (or urb unlink) can get it
  730. *
  731. * urb + dev is in hcd.self.controller.urb_list
  732. * we're queueing TDs onto software and hardware lists
  733. *
  734. * hcd-specific init for hcpriv hasn't been done yet
  735. *
  736. * NOTE: control, bulk, and interrupt share the same code to append TDs
  737. * to a (possibly active) QH, and the same QH scanning code.
  738. */
  739. static int ehci_urb_enqueue (
  740. struct usb_hcd *hcd,
  741. struct urb *urb,
  742. gfp_t mem_flags
  743. ) {
  744. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  745. struct list_head qtd_list;
  746. INIT_LIST_HEAD (&qtd_list);
  747. switch (usb_pipetype (urb->pipe)) {
  748. case PIPE_CONTROL:
  749. /* qh_completions() code doesn't handle all the fault cases
  750. * in multi-TD control transfers. Even 1KB is rare anyway.
  751. */
  752. if (urb->transfer_buffer_length > (16 * 1024))
  753. return -EMSGSIZE;
  754. /* FALLTHROUGH */
  755. /* case PIPE_BULK: */
  756. default:
  757. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  758. return -ENOMEM;
  759. return submit_async(ehci, urb, &qtd_list, mem_flags);
  760. case PIPE_INTERRUPT:
  761. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  762. return -ENOMEM;
  763. return intr_submit(ehci, urb, &qtd_list, mem_flags);
  764. case PIPE_ISOCHRONOUS:
  765. if (urb->dev->speed == USB_SPEED_HIGH)
  766. return itd_submit (ehci, urb, mem_flags);
  767. else
  768. return sitd_submit (ehci, urb, mem_flags);
  769. }
  770. }
  771. static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
  772. {
  773. /* failfast */
  774. if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim)
  775. end_unlink_async(ehci);
  776. /* If the QH isn't linked then there's nothing we can do
  777. * unless we were called during a giveback, in which case
  778. * qh_completions() has to deal with it.
  779. */
  780. if (qh->qh_state != QH_STATE_LINKED) {
  781. if (qh->qh_state == QH_STATE_COMPLETING)
  782. qh->needs_rescan = 1;
  783. return;
  784. }
  785. /* defer till later if busy */
  786. if (ehci->reclaim) {
  787. struct ehci_qh *last;
  788. for (last = ehci->reclaim;
  789. last->reclaim;
  790. last = last->reclaim)
  791. continue;
  792. qh->qh_state = QH_STATE_UNLINK_WAIT;
  793. last->reclaim = qh;
  794. /* start IAA cycle */
  795. } else
  796. start_unlink_async (ehci, qh);
  797. }
  798. /* remove from hardware lists
  799. * completions normally happen asynchronously
  800. */
  801. static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  802. {
  803. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  804. struct ehci_qh *qh;
  805. unsigned long flags;
  806. int rc;
  807. spin_lock_irqsave (&ehci->lock, flags);
  808. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  809. if (rc)
  810. goto done;
  811. switch (usb_pipetype (urb->pipe)) {
  812. // case PIPE_CONTROL:
  813. // case PIPE_BULK:
  814. default:
  815. qh = (struct ehci_qh *) urb->hcpriv;
  816. if (!qh)
  817. break;
  818. switch (qh->qh_state) {
  819. case QH_STATE_LINKED:
  820. case QH_STATE_COMPLETING:
  821. unlink_async(ehci, qh);
  822. break;
  823. case QH_STATE_UNLINK:
  824. case QH_STATE_UNLINK_WAIT:
  825. /* already started */
  826. break;
  827. case QH_STATE_IDLE:
  828. /* QH might be waiting for a Clear-TT-Buffer */
  829. qh_completions(ehci, qh);
  830. break;
  831. }
  832. break;
  833. case PIPE_INTERRUPT:
  834. qh = (struct ehci_qh *) urb->hcpriv;
  835. if (!qh)
  836. break;
  837. switch (qh->qh_state) {
  838. case QH_STATE_LINKED:
  839. case QH_STATE_COMPLETING:
  840. intr_deschedule (ehci, qh);
  841. break;
  842. case QH_STATE_IDLE:
  843. qh_completions (ehci, qh);
  844. break;
  845. default:
  846. ehci_dbg (ehci, "bogus qh %p state %d\n",
  847. qh, qh->qh_state);
  848. goto done;
  849. }
  850. break;
  851. case PIPE_ISOCHRONOUS:
  852. // itd or sitd ...
  853. // wait till next completion, do it then.
  854. // completion irqs can wait up to 1024 msec,
  855. break;
  856. }
  857. done:
  858. spin_unlock_irqrestore (&ehci->lock, flags);
  859. return rc;
  860. }
  861. /*-------------------------------------------------------------------------*/
  862. // bulk qh holds the data toggle
  863. static void
  864. ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  865. {
  866. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  867. unsigned long flags;
  868. struct ehci_qh *qh, *tmp;
  869. /* ASSERT: any requests/urbs are being unlinked */
  870. /* ASSERT: nobody can be submitting urbs for this any more */
  871. rescan:
  872. spin_lock_irqsave (&ehci->lock, flags);
  873. qh = ep->hcpriv;
  874. if (!qh)
  875. goto done;
  876. /* endpoints can be iso streams. for now, we don't
  877. * accelerate iso completions ... so spin a while.
  878. */
  879. if (qh->hw == NULL) {
  880. ehci_vdbg (ehci, "iso delay\n");
  881. goto idle_timeout;
  882. }
  883. if (!HC_IS_RUNNING (hcd->state))
  884. qh->qh_state = QH_STATE_IDLE;
  885. switch (qh->qh_state) {
  886. case QH_STATE_LINKED:
  887. case QH_STATE_COMPLETING:
  888. for (tmp = ehci->async->qh_next.qh;
  889. tmp && tmp != qh;
  890. tmp = tmp->qh_next.qh)
  891. continue;
  892. /* periodic qh self-unlinks on empty */
  893. if (!tmp)
  894. goto nogood;
  895. unlink_async (ehci, qh);
  896. /* FALL THROUGH */
  897. case QH_STATE_UNLINK: /* wait for hw to finish? */
  898. case QH_STATE_UNLINK_WAIT:
  899. idle_timeout:
  900. spin_unlock_irqrestore (&ehci->lock, flags);
  901. schedule_timeout_uninterruptible(1);
  902. goto rescan;
  903. case QH_STATE_IDLE: /* fully unlinked */
  904. if (qh->clearing_tt)
  905. goto idle_timeout;
  906. if (list_empty (&qh->qtd_list)) {
  907. qh_put (qh);
  908. break;
  909. }
  910. /* else FALL THROUGH */
  911. default:
  912. nogood:
  913. /* caller was supposed to have unlinked any requests;
  914. * that's not our job. just leak this memory.
  915. */
  916. ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
  917. qh, ep->desc.bEndpointAddress, qh->qh_state,
  918. list_empty (&qh->qtd_list) ? "" : "(has tds)");
  919. break;
  920. }
  921. ep->hcpriv = NULL;
  922. done:
  923. spin_unlock_irqrestore (&ehci->lock, flags);
  924. return;
  925. }
  926. static void
  927. ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  928. {
  929. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  930. struct ehci_qh *qh;
  931. int eptype = usb_endpoint_type(&ep->desc);
  932. int epnum = usb_endpoint_num(&ep->desc);
  933. int is_out = usb_endpoint_dir_out(&ep->desc);
  934. unsigned long flags;
  935. if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
  936. return;
  937. spin_lock_irqsave(&ehci->lock, flags);
  938. qh = ep->hcpriv;
  939. /* For Bulk and Interrupt endpoints we maintain the toggle state
  940. * in the hardware; the toggle bits in udev aren't used at all.
  941. * When an endpoint is reset by usb_clear_halt() we must reset
  942. * the toggle bit in the QH.
  943. */
  944. if (qh) {
  945. usb_settoggle(qh->dev, epnum, is_out, 0);
  946. if (!list_empty(&qh->qtd_list)) {
  947. WARN_ONCE(1, "clear_halt for a busy endpoint\n");
  948. } else if (qh->qh_state == QH_STATE_LINKED ||
  949. qh->qh_state == QH_STATE_COMPLETING) {
  950. /* The toggle value in the QH can't be updated
  951. * while the QH is active. Unlink it now;
  952. * re-linking will call qh_refresh().
  953. */
  954. if (eptype == USB_ENDPOINT_XFER_BULK)
  955. unlink_async(ehci, qh);
  956. else
  957. intr_deschedule(ehci, qh);
  958. }
  959. }
  960. spin_unlock_irqrestore(&ehci->lock, flags);
  961. }
  962. static int ehci_get_frame (struct usb_hcd *hcd)
  963. {
  964. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  965. return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) %
  966. ehci->periodic_size;
  967. }
  968. /*-------------------------------------------------------------------------*/
  969. MODULE_DESCRIPTION(DRIVER_DESC);
  970. MODULE_AUTHOR (DRIVER_AUTHOR);
  971. MODULE_LICENSE ("GPL");
  972. #ifdef CONFIG_PCI
  973. #include "ehci-pci.c"
  974. #define PCI_DRIVER ehci_pci_driver
  975. #endif
  976. #ifdef CONFIG_USB_EHCI_FSL
  977. #include "ehci-fsl.c"
  978. #define PLATFORM_DRIVER ehci_fsl_driver
  979. #endif
  980. #ifdef CONFIG_USB_EHCI_MXC
  981. #include "ehci-mxc.c"
  982. #define PLATFORM_DRIVER ehci_mxc_driver
  983. #endif
  984. #ifdef CONFIG_SOC_AU1200
  985. #include "ehci-au1xxx.c"
  986. #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
  987. #endif
  988. #ifdef CONFIG_ARCH_OMAP3
  989. #include "ehci-omap.c"
  990. #define PLATFORM_DRIVER ehci_hcd_omap_driver
  991. #endif
  992. #ifdef CONFIG_PPC_PS3
  993. #include "ehci-ps3.c"
  994. #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
  995. #endif
  996. #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
  997. #include "ehci-ppc-of.c"
  998. #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
  999. #endif
  1000. #ifdef CONFIG_XPS_USB_HCD_XILINX
  1001. #include "ehci-xilinx-of.c"
  1002. #define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
  1003. #endif
  1004. #ifdef CONFIG_PLAT_ORION
  1005. #include "ehci-orion.c"
  1006. #define PLATFORM_DRIVER ehci_orion_driver
  1007. #endif
  1008. #ifdef CONFIG_ARCH_IXP4XX
  1009. #include "ehci-ixp4xx.c"
  1010. #define PLATFORM_DRIVER ixp4xx_ehci_driver
  1011. #endif
  1012. #ifdef CONFIG_USB_W90X900_EHCI
  1013. #include "ehci-w90x900.c"
  1014. #define PLATFORM_DRIVER ehci_hcd_w90x900_driver
  1015. #endif
  1016. #ifdef CONFIG_ARCH_AT91
  1017. #include "ehci-atmel.c"
  1018. #define PLATFORM_DRIVER ehci_atmel_driver
  1019. #endif
  1020. #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
  1021. !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
  1022. !defined(XILINX_OF_PLATFORM_DRIVER)
  1023. #error "missing bus glue for ehci-hcd"
  1024. #endif
  1025. static int __init ehci_hcd_init(void)
  1026. {
  1027. int retval = 0;
  1028. if (usb_disabled())
  1029. return -ENODEV;
  1030. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  1031. set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1032. if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
  1033. test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
  1034. printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
  1035. " before uhci_hcd and ohci_hcd, not after\n");
  1036. pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  1037. hcd_name,
  1038. sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  1039. sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  1040. #ifdef DEBUG
  1041. ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
  1042. if (!ehci_debug_root) {
  1043. retval = -ENOENT;
  1044. goto err_debug;
  1045. }
  1046. #endif
  1047. #ifdef PLATFORM_DRIVER
  1048. retval = platform_driver_register(&PLATFORM_DRIVER);
  1049. if (retval < 0)
  1050. goto clean0;
  1051. #endif
  1052. #ifdef PCI_DRIVER
  1053. retval = pci_register_driver(&PCI_DRIVER);
  1054. if (retval < 0)
  1055. goto clean1;
  1056. #endif
  1057. #ifdef PS3_SYSTEM_BUS_DRIVER
  1058. retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1059. if (retval < 0)
  1060. goto clean2;
  1061. #endif
  1062. #ifdef OF_PLATFORM_DRIVER
  1063. retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
  1064. if (retval < 0)
  1065. goto clean3;
  1066. #endif
  1067. #ifdef XILINX_OF_PLATFORM_DRIVER
  1068. retval = of_register_platform_driver(&XILINX_OF_PLATFORM_DRIVER);
  1069. if (retval < 0)
  1070. goto clean4;
  1071. #endif
  1072. return retval;
  1073. #ifdef XILINX_OF_PLATFORM_DRIVER
  1074. /* of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER); */
  1075. clean4:
  1076. #endif
  1077. #ifdef OF_PLATFORM_DRIVER
  1078. of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
  1079. clean3:
  1080. #endif
  1081. #ifdef PS3_SYSTEM_BUS_DRIVER
  1082. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1083. clean2:
  1084. #endif
  1085. #ifdef PCI_DRIVER
  1086. pci_unregister_driver(&PCI_DRIVER);
  1087. clean1:
  1088. #endif
  1089. #ifdef PLATFORM_DRIVER
  1090. platform_driver_unregister(&PLATFORM_DRIVER);
  1091. clean0:
  1092. #endif
  1093. #ifdef DEBUG
  1094. debugfs_remove(ehci_debug_root);
  1095. ehci_debug_root = NULL;
  1096. err_debug:
  1097. #endif
  1098. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1099. return retval;
  1100. }
  1101. module_init(ehci_hcd_init);
  1102. static void __exit ehci_hcd_cleanup(void)
  1103. {
  1104. #ifdef XILINX_OF_PLATFORM_DRIVER
  1105. of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER);
  1106. #endif
  1107. #ifdef OF_PLATFORM_DRIVER
  1108. of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
  1109. #endif
  1110. #ifdef PLATFORM_DRIVER
  1111. platform_driver_unregister(&PLATFORM_DRIVER);
  1112. #endif
  1113. #ifdef PCI_DRIVER
  1114. pci_unregister_driver(&PCI_DRIVER);
  1115. #endif
  1116. #ifdef PS3_SYSTEM_BUS_DRIVER
  1117. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1118. #endif
  1119. #ifdef DEBUG
  1120. debugfs_remove(ehci_debug_root);
  1121. #endif
  1122. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1123. }
  1124. module_exit(ehci_hcd_cleanup);