ehci-hcd.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  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. return;
  336. ehci->scanning = 1;
  337. if (ehci->async_count)
  338. scan_async(ehci);
  339. if (ehci->next_uframe != -1)
  340. scan_periodic (ehci);
  341. ehci->scanning = 0;
  342. /* the IO watchdog guards against hardware or driver bugs that
  343. * misplace IRQs, and should let us run completely without IRQs.
  344. * such lossage has been observed on both VT6202 and VT8235.
  345. */
  346. if (ehci->rh_state == EHCI_RH_RUNNING &&
  347. (ehci->async->qh_next.ptr != NULL ||
  348. ehci->periodic_count != 0))
  349. timer_action (ehci, TIMER_IO_WATCHDOG);
  350. }
  351. /*
  352. * Called when the ehci_hcd module is removed.
  353. */
  354. static void ehci_stop (struct usb_hcd *hcd)
  355. {
  356. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  357. ehci_dbg (ehci, "stop\n");
  358. /* no more interrupts ... */
  359. del_timer_sync (&ehci->watchdog);
  360. spin_lock_irq(&ehci->lock);
  361. ehci->enabled_hrtimer_events = 0;
  362. ehci_quiesce(ehci);
  363. ehci_silence_controller(ehci);
  364. ehci_reset (ehci);
  365. spin_unlock_irq(&ehci->lock);
  366. hrtimer_cancel(&ehci->hrtimer);
  367. remove_sysfs_files(ehci);
  368. remove_debug_files (ehci);
  369. /* root hub is shut down separately (first, when possible) */
  370. spin_lock_irq (&ehci->lock);
  371. if (ehci->async)
  372. ehci_work (ehci);
  373. end_free_itds(ehci);
  374. spin_unlock_irq (&ehci->lock);
  375. ehci_mem_cleanup (ehci);
  376. if (ehci->amd_pll_fix == 1)
  377. usb_amd_dev_put();
  378. #ifdef EHCI_STATS
  379. ehci_dbg(ehci, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
  380. ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
  381. ehci->stats.lost_iaa);
  382. ehci_dbg (ehci, "complete %ld unlink %ld\n",
  383. ehci->stats.complete, ehci->stats.unlink);
  384. #endif
  385. dbg_status (ehci, "ehci_stop completed",
  386. ehci_readl(ehci, &ehci->regs->status));
  387. }
  388. /* one-time init, only for memory state */
  389. static int ehci_init(struct usb_hcd *hcd)
  390. {
  391. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  392. u32 temp;
  393. int retval;
  394. u32 hcc_params;
  395. struct ehci_qh_hw *hw;
  396. spin_lock_init(&ehci->lock);
  397. /*
  398. * keep io watchdog by default, those good HCDs could turn off it later
  399. */
  400. ehci->need_io_watchdog = 1;
  401. init_timer(&ehci->watchdog);
  402. ehci->watchdog.function = ehci_watchdog;
  403. ehci->watchdog.data = (unsigned long) ehci;
  404. hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  405. ehci->hrtimer.function = ehci_hrtimer_func;
  406. ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
  407. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  408. /*
  409. * by default set standard 80% (== 100 usec/uframe) max periodic
  410. * bandwidth as required by USB 2.0
  411. */
  412. ehci->uframe_periodic_max = 100;
  413. /*
  414. * hw default: 1K periodic list heads, one per frame.
  415. * periodic_size can shrink by USBCMD update if hcc_params allows.
  416. */
  417. ehci->periodic_size = DEFAULT_I_TDPS;
  418. INIT_LIST_HEAD(&ehci->cached_itd_list);
  419. INIT_LIST_HEAD(&ehci->cached_sitd_list);
  420. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  421. /* periodic schedule size can be smaller than default */
  422. switch (EHCI_TUNE_FLS) {
  423. case 0: ehci->periodic_size = 1024; break;
  424. case 1: ehci->periodic_size = 512; break;
  425. case 2: ehci->periodic_size = 256; break;
  426. default: BUG();
  427. }
  428. }
  429. if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
  430. return retval;
  431. /* controllers may cache some of the periodic schedule ... */
  432. if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
  433. ehci->i_thresh = 2 + 8;
  434. else // N microframes cached
  435. ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
  436. ehci->next_uframe = -1;
  437. ehci->clock_frame = -1;
  438. /*
  439. * dedicate a qh for the async ring head, since we couldn't unlink
  440. * a 'real' qh without stopping the async schedule [4.8]. use it
  441. * as the 'reclamation list head' too.
  442. * its dummy is used in hw_alt_next of many tds, to prevent the qh
  443. * from automatically advancing to the next td after short reads.
  444. */
  445. ehci->async->qh_next.qh = NULL;
  446. hw = ehci->async->hw;
  447. hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
  448. hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
  449. #if defined(CONFIG_PPC_PS3)
  450. hw->hw_info1 |= cpu_to_hc32(ehci, QH_INACTIVATE);
  451. #endif
  452. hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
  453. hw->hw_qtd_next = EHCI_LIST_END(ehci);
  454. ehci->async->qh_state = QH_STATE_LINKED;
  455. hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
  456. /* clear interrupt enables, set irq latency */
  457. if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
  458. log2_irq_thresh = 0;
  459. temp = 1 << (16 + log2_irq_thresh);
  460. if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
  461. ehci->has_ppcd = 1;
  462. ehci_dbg(ehci, "enable per-port change event\n");
  463. temp |= CMD_PPCEE;
  464. }
  465. if (HCC_CANPARK(hcc_params)) {
  466. /* HW default park == 3, on hardware that supports it (like
  467. * NVidia and ALI silicon), maximizes throughput on the async
  468. * schedule by avoiding QH fetches between transfers.
  469. *
  470. * With fast usb storage devices and NForce2, "park" seems to
  471. * make problems: throughput reduction (!), data errors...
  472. */
  473. if (park) {
  474. park = min(park, (unsigned) 3);
  475. temp |= CMD_PARK;
  476. temp |= park << 8;
  477. }
  478. ehci_dbg(ehci, "park %d\n", park);
  479. }
  480. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  481. /* periodic schedule size can be smaller than default */
  482. temp &= ~(3 << 2);
  483. temp |= (EHCI_TUNE_FLS << 2);
  484. }
  485. if (HCC_LPM(hcc_params)) {
  486. /* support link power management EHCI 1.1 addendum */
  487. ehci_dbg(ehci, "support lpm\n");
  488. ehci->has_lpm = 1;
  489. if (hird > 0xf) {
  490. ehci_dbg(ehci, "hird %d invalid, use default 0",
  491. hird);
  492. hird = 0;
  493. }
  494. temp |= hird << 24;
  495. }
  496. ehci->command = temp;
  497. /* Accept arbitrarily long scatter-gather lists */
  498. if (!(hcd->driver->flags & HCD_LOCAL_MEM))
  499. hcd->self.sg_tablesize = ~0;
  500. return 0;
  501. }
  502. /* start HC running; it's halted, ehci_init() has been run (once) */
  503. static int ehci_run (struct usb_hcd *hcd)
  504. {
  505. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  506. u32 temp;
  507. u32 hcc_params;
  508. hcd->uses_new_polling = 1;
  509. /* EHCI spec section 4.1 */
  510. ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  511. ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
  512. /*
  513. * hcc_params controls whether ehci->regs->segment must (!!!)
  514. * be used; it constrains QH/ITD/SITD and QTD locations.
  515. * pci_pool consistent memory always uses segment zero.
  516. * streaming mappings for I/O buffers, like pci_map_single(),
  517. * can return segments above 4GB, if the device allows.
  518. *
  519. * NOTE: the dma mask is visible through dma_supported(), so
  520. * drivers can pass this info along ... like NETIF_F_HIGHDMA,
  521. * Scsi_Host.highmem_io, and so forth. It's readonly to all
  522. * host side drivers though.
  523. */
  524. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  525. if (HCC_64BIT_ADDR(hcc_params)) {
  526. ehci_writel(ehci, 0, &ehci->regs->segment);
  527. #if 0
  528. // this is deeply broken on almost all architectures
  529. if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
  530. ehci_info(ehci, "enabled 64bit DMA\n");
  531. #endif
  532. }
  533. // Philips, Intel, and maybe others need CMD_RUN before the
  534. // root hub will detect new devices (why?); NEC doesn't
  535. ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
  536. ehci->command |= CMD_RUN;
  537. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  538. dbg_cmd (ehci, "init", ehci->command);
  539. /*
  540. * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
  541. * are explicitly handed to companion controller(s), so no TT is
  542. * involved with the root hub. (Except where one is integrated,
  543. * and there's no companion controller unless maybe for USB OTG.)
  544. *
  545. * Turning on the CF flag will transfer ownership of all ports
  546. * from the companions to the EHCI controller. If any of the
  547. * companions are in the middle of a port reset at the time, it
  548. * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
  549. * guarantees that no resets are in progress. After we set CF,
  550. * a short delay lets the hardware catch up; new resets shouldn't
  551. * be started before the port switching actions could complete.
  552. */
  553. down_write(&ehci_cf_port_reset_rwsem);
  554. ehci->rh_state = EHCI_RH_RUNNING;
  555. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  556. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  557. msleep(5);
  558. up_write(&ehci_cf_port_reset_rwsem);
  559. ehci->last_periodic_enable = ktime_get_real();
  560. temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  561. ehci_info (ehci,
  562. "USB %x.%x started, EHCI %x.%02x%s\n",
  563. ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
  564. temp >> 8, temp & 0xff,
  565. ignore_oc ? ", overcurrent ignored" : "");
  566. ehci_writel(ehci, INTR_MASK,
  567. &ehci->regs->intr_enable); /* Turn On Interrupts */
  568. /* GRR this is run-once init(), being done every time the HC starts.
  569. * So long as they're part of class devices, we can't do it init()
  570. * since the class device isn't created that early.
  571. */
  572. create_debug_files(ehci);
  573. create_sysfs_files(ehci);
  574. return 0;
  575. }
  576. static int ehci_setup(struct usb_hcd *hcd)
  577. {
  578. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  579. int retval;
  580. ehci->regs = (void __iomem *)ehci->caps +
  581. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  582. dbg_hcs_params(ehci, "reset");
  583. dbg_hcc_params(ehci, "reset");
  584. /* cache this readonly data; minimize chip reads */
  585. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  586. ehci->sbrn = HCD_USB2;
  587. /* data structure init */
  588. retval = ehci_init(hcd);
  589. if (retval)
  590. return retval;
  591. retval = ehci_halt(ehci);
  592. if (retval)
  593. return retval;
  594. if (ehci_is_TDI(ehci))
  595. tdi_reset(ehci);
  596. ehci_reset(ehci);
  597. return 0;
  598. }
  599. /*-------------------------------------------------------------------------*/
  600. static irqreturn_t ehci_irq (struct usb_hcd *hcd)
  601. {
  602. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  603. u32 status, masked_status, pcd_status = 0, cmd;
  604. int bh;
  605. spin_lock (&ehci->lock);
  606. status = ehci_readl(ehci, &ehci->regs->status);
  607. /* e.g. cardbus physical eject */
  608. if (status == ~(u32) 0) {
  609. ehci_dbg (ehci, "device removed\n");
  610. goto dead;
  611. }
  612. /*
  613. * We don't use STS_FLR, but some controllers don't like it to
  614. * remain on, so mask it out along with the other status bits.
  615. */
  616. masked_status = status & (INTR_MASK | STS_FLR);
  617. /* Shared IRQ? */
  618. if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
  619. spin_unlock(&ehci->lock);
  620. return IRQ_NONE;
  621. }
  622. /* clear (just) interrupts */
  623. ehci_writel(ehci, masked_status, &ehci->regs->status);
  624. cmd = ehci_readl(ehci, &ehci->regs->command);
  625. bh = 0;
  626. #ifdef VERBOSE_DEBUG
  627. /* unrequested/ignored: Frame List Rollover */
  628. dbg_status (ehci, "irq", status);
  629. #endif
  630. /* INT, ERR, and IAA interrupt rates can be throttled */
  631. /* normal [4.15.1.2] or error [4.15.1.1] completion */
  632. if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
  633. if (likely ((status & STS_ERR) == 0))
  634. COUNT (ehci->stats.normal);
  635. else
  636. COUNT (ehci->stats.error);
  637. bh = 1;
  638. }
  639. /* complete the unlinking of some qh [4.15.2.3] */
  640. if (status & STS_IAA) {
  641. /* Turn off the IAA watchdog */
  642. ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG);
  643. /*
  644. * Mild optimization: Allow another IAAD to reset the
  645. * hrtimer, if one occurs before the next expiration.
  646. * In theory we could always cancel the hrtimer, but
  647. * tests show that about half the time it will be reset
  648. * for some other event anyway.
  649. */
  650. if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG)
  651. ++ehci->next_hrtimer_event;
  652. /* guard against (alleged) silicon errata */
  653. if (cmd & CMD_IAAD)
  654. ehci_dbg(ehci, "IAA with IAAD still set?\n");
  655. if (ehci->async_iaa) {
  656. COUNT(ehci->stats.iaa);
  657. end_unlink_async(ehci);
  658. } else
  659. ehci_dbg(ehci, "IAA with nothing unlinked?\n");
  660. }
  661. /* remote wakeup [4.3.1] */
  662. if (status & STS_PCD) {
  663. unsigned i = HCS_N_PORTS (ehci->hcs_params);
  664. u32 ppcd = 0;
  665. /* kick root hub later */
  666. pcd_status = status;
  667. /* resume root hub? */
  668. if (ehci->rh_state == EHCI_RH_SUSPENDED)
  669. usb_hcd_resume_root_hub(hcd);
  670. /* get per-port change detect bits */
  671. if (ehci->has_ppcd)
  672. ppcd = status >> 16;
  673. while (i--) {
  674. int pstatus;
  675. /* leverage per-port change bits feature */
  676. if (ehci->has_ppcd && !(ppcd & (1 << i)))
  677. continue;
  678. pstatus = ehci_readl(ehci,
  679. &ehci->regs->port_status[i]);
  680. if (pstatus & PORT_OWNER)
  681. continue;
  682. if (!(test_bit(i, &ehci->suspended_ports) &&
  683. ((pstatus & PORT_RESUME) ||
  684. !(pstatus & PORT_SUSPEND)) &&
  685. (pstatus & PORT_PE) &&
  686. ehci->reset_done[i] == 0))
  687. continue;
  688. /* start 20 msec resume signaling from this port,
  689. * and make khubd collect PORT_STAT_C_SUSPEND to
  690. * stop that signaling. Use 5 ms extra for safety,
  691. * like usb_port_resume() does.
  692. */
  693. ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
  694. set_bit(i, &ehci->resuming_ports);
  695. ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
  696. mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
  697. }
  698. }
  699. /* PCI errors [4.15.2.4] */
  700. if (unlikely ((status & STS_FATAL) != 0)) {
  701. ehci_err(ehci, "fatal error\n");
  702. dbg_cmd(ehci, "fatal", cmd);
  703. dbg_status(ehci, "fatal", status);
  704. dead:
  705. usb_hc_died(hcd);
  706. /* Don't let the controller do anything more */
  707. ehci->rh_state = EHCI_RH_STOPPING;
  708. ehci->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
  709. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  710. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  711. ehci_handle_controller_death(ehci);
  712. /* Handle completions when the controller stops */
  713. bh = 0;
  714. }
  715. if (bh)
  716. ehci_work (ehci);
  717. spin_unlock (&ehci->lock);
  718. if (pcd_status)
  719. usb_hcd_poll_rh_status(hcd);
  720. return IRQ_HANDLED;
  721. }
  722. /*-------------------------------------------------------------------------*/
  723. /*
  724. * non-error returns are a promise to giveback() the urb later
  725. * we drop ownership so next owner (or urb unlink) can get it
  726. *
  727. * urb + dev is in hcd.self.controller.urb_list
  728. * we're queueing TDs onto software and hardware lists
  729. *
  730. * hcd-specific init for hcpriv hasn't been done yet
  731. *
  732. * NOTE: control, bulk, and interrupt share the same code to append TDs
  733. * to a (possibly active) QH, and the same QH scanning code.
  734. */
  735. static int ehci_urb_enqueue (
  736. struct usb_hcd *hcd,
  737. struct urb *urb,
  738. gfp_t mem_flags
  739. ) {
  740. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  741. struct list_head qtd_list;
  742. INIT_LIST_HEAD (&qtd_list);
  743. switch (usb_pipetype (urb->pipe)) {
  744. case PIPE_CONTROL:
  745. /* qh_completions() code doesn't handle all the fault cases
  746. * in multi-TD control transfers. Even 1KB is rare anyway.
  747. */
  748. if (urb->transfer_buffer_length > (16 * 1024))
  749. return -EMSGSIZE;
  750. /* FALLTHROUGH */
  751. /* case PIPE_BULK: */
  752. default:
  753. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  754. return -ENOMEM;
  755. return submit_async(ehci, urb, &qtd_list, mem_flags);
  756. case PIPE_INTERRUPT:
  757. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  758. return -ENOMEM;
  759. return intr_submit(ehci, urb, &qtd_list, mem_flags);
  760. case PIPE_ISOCHRONOUS:
  761. if (urb->dev->speed == USB_SPEED_HIGH)
  762. return itd_submit (ehci, urb, mem_flags);
  763. else
  764. return sitd_submit (ehci, urb, mem_flags);
  765. }
  766. }
  767. /* remove from hardware lists
  768. * completions normally happen asynchronously
  769. */
  770. static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  771. {
  772. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  773. struct ehci_qh *qh;
  774. unsigned long flags;
  775. int rc;
  776. spin_lock_irqsave (&ehci->lock, flags);
  777. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  778. if (rc)
  779. goto done;
  780. switch (usb_pipetype (urb->pipe)) {
  781. // case PIPE_CONTROL:
  782. // case PIPE_BULK:
  783. default:
  784. qh = (struct ehci_qh *) urb->hcpriv;
  785. if (!qh)
  786. break;
  787. switch (qh->qh_state) {
  788. case QH_STATE_LINKED:
  789. case QH_STATE_COMPLETING:
  790. start_unlink_async(ehci, qh);
  791. break;
  792. case QH_STATE_UNLINK:
  793. case QH_STATE_UNLINK_WAIT:
  794. /* already started */
  795. break;
  796. case QH_STATE_IDLE:
  797. /* QH might be waiting for a Clear-TT-Buffer */
  798. qh_completions(ehci, qh);
  799. break;
  800. }
  801. break;
  802. case PIPE_INTERRUPT:
  803. qh = (struct ehci_qh *) urb->hcpriv;
  804. if (!qh)
  805. break;
  806. switch (qh->qh_state) {
  807. case QH_STATE_LINKED:
  808. case QH_STATE_COMPLETING:
  809. start_unlink_intr(ehci, qh);
  810. break;
  811. case QH_STATE_IDLE:
  812. qh_completions (ehci, qh);
  813. break;
  814. default:
  815. ehci_dbg (ehci, "bogus qh %p state %d\n",
  816. qh, qh->qh_state);
  817. goto done;
  818. }
  819. break;
  820. case PIPE_ISOCHRONOUS:
  821. // itd or sitd ...
  822. // wait till next completion, do it then.
  823. // completion irqs can wait up to 1024 msec,
  824. break;
  825. }
  826. done:
  827. spin_unlock_irqrestore (&ehci->lock, flags);
  828. return rc;
  829. }
  830. /*-------------------------------------------------------------------------*/
  831. // bulk qh holds the data toggle
  832. static void
  833. ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  834. {
  835. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  836. unsigned long flags;
  837. struct ehci_qh *qh, *tmp;
  838. /* ASSERT: any requests/urbs are being unlinked */
  839. /* ASSERT: nobody can be submitting urbs for this any more */
  840. rescan:
  841. spin_lock_irqsave (&ehci->lock, flags);
  842. qh = ep->hcpriv;
  843. if (!qh)
  844. goto done;
  845. /* endpoints can be iso streams. for now, we don't
  846. * accelerate iso completions ... so spin a while.
  847. */
  848. if (qh->hw == NULL) {
  849. struct ehci_iso_stream *stream = ep->hcpriv;
  850. if (!list_empty(&stream->td_list))
  851. goto idle_timeout;
  852. /* BUG_ON(!list_empty(&stream->free_list)); */
  853. kfree(stream);
  854. goto done;
  855. }
  856. if (ehci->rh_state < EHCI_RH_RUNNING)
  857. qh->qh_state = QH_STATE_IDLE;
  858. switch (qh->qh_state) {
  859. case QH_STATE_LINKED:
  860. case QH_STATE_COMPLETING:
  861. for (tmp = ehci->async->qh_next.qh;
  862. tmp && tmp != qh;
  863. tmp = tmp->qh_next.qh)
  864. continue;
  865. /* periodic qh self-unlinks on empty, and a COMPLETING qh
  866. * may already be unlinked.
  867. */
  868. if (tmp)
  869. start_unlink_async(ehci, qh);
  870. /* FALL THROUGH */
  871. case QH_STATE_UNLINK: /* wait for hw to finish? */
  872. case QH_STATE_UNLINK_WAIT:
  873. idle_timeout:
  874. spin_unlock_irqrestore (&ehci->lock, flags);
  875. schedule_timeout_uninterruptible(1);
  876. goto rescan;
  877. case QH_STATE_IDLE: /* fully unlinked */
  878. if (qh->clearing_tt)
  879. goto idle_timeout;
  880. if (list_empty (&qh->qtd_list)) {
  881. qh_destroy(ehci, qh);
  882. break;
  883. }
  884. /* else FALL THROUGH */
  885. default:
  886. /* caller was supposed to have unlinked any requests;
  887. * that's not our job. just leak this memory.
  888. */
  889. ehci_err (ehci, "qh %p (#%02x) state %d%s\n",
  890. qh, ep->desc.bEndpointAddress, qh->qh_state,
  891. list_empty (&qh->qtd_list) ? "" : "(has tds)");
  892. break;
  893. }
  894. done:
  895. ep->hcpriv = NULL;
  896. spin_unlock_irqrestore (&ehci->lock, flags);
  897. }
  898. static void
  899. ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  900. {
  901. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  902. struct ehci_qh *qh;
  903. int eptype = usb_endpoint_type(&ep->desc);
  904. int epnum = usb_endpoint_num(&ep->desc);
  905. int is_out = usb_endpoint_dir_out(&ep->desc);
  906. unsigned long flags;
  907. if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
  908. return;
  909. spin_lock_irqsave(&ehci->lock, flags);
  910. qh = ep->hcpriv;
  911. /* For Bulk and Interrupt endpoints we maintain the toggle state
  912. * in the hardware; the toggle bits in udev aren't used at all.
  913. * When an endpoint is reset by usb_clear_halt() we must reset
  914. * the toggle bit in the QH.
  915. */
  916. if (qh) {
  917. usb_settoggle(qh->dev, epnum, is_out, 0);
  918. if (!list_empty(&qh->qtd_list)) {
  919. WARN_ONCE(1, "clear_halt for a busy endpoint\n");
  920. } else if (qh->qh_state == QH_STATE_LINKED ||
  921. qh->qh_state == QH_STATE_COMPLETING) {
  922. /* The toggle value in the QH can't be updated
  923. * while the QH is active. Unlink it now;
  924. * re-linking will call qh_refresh().
  925. */
  926. if (eptype == USB_ENDPOINT_XFER_BULK)
  927. start_unlink_async(ehci, qh);
  928. else
  929. start_unlink_intr(ehci, qh);
  930. }
  931. }
  932. spin_unlock_irqrestore(&ehci->lock, flags);
  933. }
  934. static int ehci_get_frame (struct usb_hcd *hcd)
  935. {
  936. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  937. return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size;
  938. }
  939. /*-------------------------------------------------------------------------*/
  940. #ifdef CONFIG_PM
  941. /* suspend/resume, section 4.3 */
  942. /* These routines handle the generic parts of controller suspend/resume */
  943. static int __maybe_unused ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  944. {
  945. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  946. if (time_before(jiffies, ehci->next_statechange))
  947. msleep(10);
  948. /*
  949. * Root hub was already suspended. Disable IRQ emission and
  950. * mark HW unaccessible. The PM and USB cores make sure that
  951. * the root hub is either suspended or stopped.
  952. */
  953. ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
  954. spin_lock_irq(&ehci->lock);
  955. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  956. (void) ehci_readl(ehci, &ehci->regs->intr_enable);
  957. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  958. spin_unlock_irq(&ehci->lock);
  959. return 0;
  960. }
  961. /* Returns 0 if power was preserved, 1 if power was lost */
  962. static int __maybe_unused ehci_resume(struct usb_hcd *hcd, bool hibernated)
  963. {
  964. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  965. if (time_before(jiffies, ehci->next_statechange))
  966. msleep(100);
  967. /* Mark hardware accessible again as we are back to full power by now */
  968. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  969. /*
  970. * If CF is still set and we aren't resuming from hibernation
  971. * then we maintained suspend power.
  972. * Just undo the effect of ehci_suspend().
  973. */
  974. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
  975. !hibernated) {
  976. int mask = INTR_MASK;
  977. ehci_prepare_ports_for_controller_resume(ehci);
  978. if (!hcd->self.root_hub->do_remote_wakeup)
  979. mask &= ~STS_PCD;
  980. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  981. ehci_readl(ehci, &ehci->regs->intr_enable);
  982. return 0;
  983. }
  984. /*
  985. * Else reset, to cope with power loss or resume from hibernation
  986. * having let the firmware kick in during reboot.
  987. */
  988. usb_root_hub_lost_power(hcd->self.root_hub);
  989. (void) ehci_halt(ehci);
  990. (void) ehci_reset(ehci);
  991. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  992. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  993. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  994. /* here we "know" root ports should always stay powered */
  995. ehci_port_power(ehci, 1);
  996. ehci->rh_state = EHCI_RH_SUSPENDED;
  997. return 1;
  998. }
  999. #endif
  1000. /*-------------------------------------------------------------------------*/
  1001. /*
  1002. * The EHCI in ChipIdea HDRC cannot be a separate module or device,
  1003. * because its registers (and irq) are shared between host/gadget/otg
  1004. * functions and in order to facilitate role switching we cannot
  1005. * give the ehci driver exclusive access to those.
  1006. */
  1007. #ifndef CHIPIDEA_EHCI
  1008. MODULE_DESCRIPTION(DRIVER_DESC);
  1009. MODULE_AUTHOR (DRIVER_AUTHOR);
  1010. MODULE_LICENSE ("GPL");
  1011. #ifdef CONFIG_PCI
  1012. #include "ehci-pci.c"
  1013. #define PCI_DRIVER ehci_pci_driver
  1014. #endif
  1015. #ifdef CONFIG_USB_EHCI_FSL
  1016. #include "ehci-fsl.c"
  1017. #define PLATFORM_DRIVER ehci_fsl_driver
  1018. #endif
  1019. #ifdef CONFIG_USB_EHCI_MXC
  1020. #include "ehci-mxc.c"
  1021. #define PLATFORM_DRIVER ehci_mxc_driver
  1022. #endif
  1023. #ifdef CONFIG_USB_EHCI_SH
  1024. #include "ehci-sh.c"
  1025. #define PLATFORM_DRIVER ehci_hcd_sh_driver
  1026. #endif
  1027. #ifdef CONFIG_MIPS_ALCHEMY
  1028. #include "ehci-au1xxx.c"
  1029. #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
  1030. #endif
  1031. #ifdef CONFIG_USB_EHCI_HCD_OMAP
  1032. #include "ehci-omap.c"
  1033. #define PLATFORM_DRIVER ehci_hcd_omap_driver
  1034. #endif
  1035. #ifdef CONFIG_PPC_PS3
  1036. #include "ehci-ps3.c"
  1037. #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
  1038. #endif
  1039. #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
  1040. #include "ehci-ppc-of.c"
  1041. #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
  1042. #endif
  1043. #ifdef CONFIG_XPS_USB_HCD_XILINX
  1044. #include "ehci-xilinx-of.c"
  1045. #define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
  1046. #endif
  1047. #ifdef CONFIG_PLAT_ORION
  1048. #include "ehci-orion.c"
  1049. #define PLATFORM_DRIVER ehci_orion_driver
  1050. #endif
  1051. #ifdef CONFIG_ARCH_IXP4XX
  1052. #include "ehci-ixp4xx.c"
  1053. #define PLATFORM_DRIVER ixp4xx_ehci_driver
  1054. #endif
  1055. #ifdef CONFIG_USB_W90X900_EHCI
  1056. #include "ehci-w90x900.c"
  1057. #define PLATFORM_DRIVER ehci_hcd_w90x900_driver
  1058. #endif
  1059. #ifdef CONFIG_ARCH_AT91
  1060. #include "ehci-atmel.c"
  1061. #define PLATFORM_DRIVER ehci_atmel_driver
  1062. #endif
  1063. #ifdef CONFIG_USB_OCTEON_EHCI
  1064. #include "ehci-octeon.c"
  1065. #define PLATFORM_DRIVER ehci_octeon_driver
  1066. #endif
  1067. #ifdef CONFIG_USB_CNS3XXX_EHCI
  1068. #include "ehci-cns3xxx.c"
  1069. #define PLATFORM_DRIVER cns3xxx_ehci_driver
  1070. #endif
  1071. #ifdef CONFIG_ARCH_VT8500
  1072. #include "ehci-vt8500.c"
  1073. #define PLATFORM_DRIVER vt8500_ehci_driver
  1074. #endif
  1075. #ifdef CONFIG_PLAT_SPEAR
  1076. #include "ehci-spear.c"
  1077. #define PLATFORM_DRIVER spear_ehci_hcd_driver
  1078. #endif
  1079. #ifdef CONFIG_USB_EHCI_MSM
  1080. #include "ehci-msm.c"
  1081. #define PLATFORM_DRIVER ehci_msm_driver
  1082. #endif
  1083. #ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
  1084. #include "ehci-pmcmsp.c"
  1085. #define PLATFORM_DRIVER ehci_hcd_msp_driver
  1086. #endif
  1087. #ifdef CONFIG_USB_EHCI_TEGRA
  1088. #include "ehci-tegra.c"
  1089. #define PLATFORM_DRIVER tegra_ehci_driver
  1090. #endif
  1091. #ifdef CONFIG_USB_EHCI_S5P
  1092. #include "ehci-s5p.c"
  1093. #define PLATFORM_DRIVER s5p_ehci_driver
  1094. #endif
  1095. #ifdef CONFIG_SPARC_LEON
  1096. #include "ehci-grlib.c"
  1097. #define PLATFORM_DRIVER ehci_grlib_driver
  1098. #endif
  1099. #ifdef CONFIG_CPU_XLR
  1100. #include "ehci-xls.c"
  1101. #define PLATFORM_DRIVER ehci_xls_driver
  1102. #endif
  1103. #ifdef CONFIG_USB_EHCI_MV
  1104. #include "ehci-mv.c"
  1105. #define PLATFORM_DRIVER ehci_mv_driver
  1106. #endif
  1107. #ifdef CONFIG_MACH_LOONGSON1
  1108. #include "ehci-ls1x.c"
  1109. #define PLATFORM_DRIVER ehci_ls1x_driver
  1110. #endif
  1111. #ifdef CONFIG_MIPS_SEAD3
  1112. #include "ehci-sead3.c"
  1113. #define PLATFORM_DRIVER ehci_hcd_sead3_driver
  1114. #endif
  1115. #ifdef CONFIG_USB_EHCI_HCD_PLATFORM
  1116. #include "ehci-platform.c"
  1117. #define PLATFORM_DRIVER ehci_platform_driver
  1118. #endif
  1119. #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
  1120. !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
  1121. !defined(XILINX_OF_PLATFORM_DRIVER)
  1122. #error "missing bus glue for ehci-hcd"
  1123. #endif
  1124. static int __init ehci_hcd_init(void)
  1125. {
  1126. int retval = 0;
  1127. if (usb_disabled())
  1128. return -ENODEV;
  1129. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  1130. set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1131. if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
  1132. test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
  1133. printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
  1134. " before uhci_hcd and ohci_hcd, not after\n");
  1135. pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  1136. hcd_name,
  1137. sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  1138. sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  1139. #ifdef DEBUG
  1140. ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
  1141. if (!ehci_debug_root) {
  1142. retval = -ENOENT;
  1143. goto err_debug;
  1144. }
  1145. #endif
  1146. #ifdef PLATFORM_DRIVER
  1147. retval = platform_driver_register(&PLATFORM_DRIVER);
  1148. if (retval < 0)
  1149. goto clean0;
  1150. #endif
  1151. #ifdef PCI_DRIVER
  1152. retval = pci_register_driver(&PCI_DRIVER);
  1153. if (retval < 0)
  1154. goto clean1;
  1155. #endif
  1156. #ifdef PS3_SYSTEM_BUS_DRIVER
  1157. retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1158. if (retval < 0)
  1159. goto clean2;
  1160. #endif
  1161. #ifdef OF_PLATFORM_DRIVER
  1162. retval = platform_driver_register(&OF_PLATFORM_DRIVER);
  1163. if (retval < 0)
  1164. goto clean3;
  1165. #endif
  1166. #ifdef XILINX_OF_PLATFORM_DRIVER
  1167. retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
  1168. if (retval < 0)
  1169. goto clean4;
  1170. #endif
  1171. return retval;
  1172. #ifdef XILINX_OF_PLATFORM_DRIVER
  1173. /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
  1174. clean4:
  1175. #endif
  1176. #ifdef OF_PLATFORM_DRIVER
  1177. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1178. clean3:
  1179. #endif
  1180. #ifdef PS3_SYSTEM_BUS_DRIVER
  1181. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1182. clean2:
  1183. #endif
  1184. #ifdef PCI_DRIVER
  1185. pci_unregister_driver(&PCI_DRIVER);
  1186. clean1:
  1187. #endif
  1188. #ifdef PLATFORM_DRIVER
  1189. platform_driver_unregister(&PLATFORM_DRIVER);
  1190. clean0:
  1191. #endif
  1192. #ifdef DEBUG
  1193. debugfs_remove(ehci_debug_root);
  1194. ehci_debug_root = NULL;
  1195. err_debug:
  1196. #endif
  1197. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1198. return retval;
  1199. }
  1200. module_init(ehci_hcd_init);
  1201. static void __exit ehci_hcd_cleanup(void)
  1202. {
  1203. #ifdef XILINX_OF_PLATFORM_DRIVER
  1204. platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
  1205. #endif
  1206. #ifdef OF_PLATFORM_DRIVER
  1207. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1208. #endif
  1209. #ifdef PLATFORM_DRIVER
  1210. platform_driver_unregister(&PLATFORM_DRIVER);
  1211. #endif
  1212. #ifdef PCI_DRIVER
  1213. pci_unregister_driver(&PCI_DRIVER);
  1214. #endif
  1215. #ifdef PS3_SYSTEM_BUS_DRIVER
  1216. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1217. #endif
  1218. #ifdef DEBUG
  1219. debugfs_remove(ehci_debug_root);
  1220. #endif
  1221. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1222. }
  1223. module_exit(ehci_hcd_cleanup);
  1224. #endif /* CHIPIDEA_EHCI */