ehci-hcd.c 36 KB

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