ehci-hcd.c 39 KB

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