ehci-hcd.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  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. /* Initial IRQ latency: faster than hw default */
  85. static int log2_irq_thresh = 0; // 0 to 6
  86. module_param (log2_irq_thresh, int, S_IRUGO);
  87. MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
  88. /* initial park setting: slower than hw default */
  89. static unsigned park = 0;
  90. module_param (park, uint, S_IRUGO);
  91. MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
  92. /* for flakey hardware, ignore overcurrent indicators */
  93. static bool ignore_oc = 0;
  94. module_param (ignore_oc, bool, S_IRUGO);
  95. MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
  96. /* for link power management(LPM) feature */
  97. static unsigned int hird;
  98. module_param(hird, int, S_IRUGO);
  99. MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us");
  100. #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
  101. /*-------------------------------------------------------------------------*/
  102. #include "ehci.h"
  103. #include "pci-quirks.h"
  104. /*
  105. * The MosChip MCS9990 controller updates its microframe counter
  106. * a little before the frame counter, and occasionally we will read
  107. * the invalid intermediate value. Avoid problems by checking the
  108. * microframe number (the low-order 3 bits); if they are 0 then
  109. * re-read the register to get the correct value.
  110. */
  111. static unsigned ehci_moschip_read_frame_index(struct ehci_hcd *ehci)
  112. {
  113. unsigned uf;
  114. uf = ehci_readl(ehci, &ehci->regs->frame_index);
  115. if (unlikely((uf & 7) == 0))
  116. uf = ehci_readl(ehci, &ehci->regs->frame_index);
  117. return uf;
  118. }
  119. static inline unsigned ehci_read_frame_index(struct ehci_hcd *ehci)
  120. {
  121. if (ehci->frame_index_bug)
  122. return ehci_moschip_read_frame_index(ehci);
  123. return ehci_readl(ehci, &ehci->regs->frame_index);
  124. }
  125. #include "ehci-dbg.c"
  126. /*-------------------------------------------------------------------------*/
  127. /*
  128. * handshake - spin reading hc until handshake completes or fails
  129. * @ptr: address of hc register to be read
  130. * @mask: bits to look at in result of read
  131. * @done: value of those bits when handshake succeeds
  132. * @usec: timeout in microseconds
  133. *
  134. * Returns negative errno, or zero on success
  135. *
  136. * Success happens when the "mask" bits have the specified value (hardware
  137. * handshake done). There are two failure modes: "usec" have passed (major
  138. * hardware flakeout), or the register reads as all-ones (hardware removed).
  139. *
  140. * That last failure should_only happen in cases like physical cardbus eject
  141. * before driver shutdown. But it also seems to be caused by bugs in cardbus
  142. * bridge shutdown: shutting down the bridge before the devices using it.
  143. */
  144. static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
  145. u32 mask, u32 done, int usec)
  146. {
  147. u32 result;
  148. do {
  149. result = ehci_readl(ehci, ptr);
  150. if (result == ~(u32)0) /* card removed */
  151. return -ENODEV;
  152. result &= mask;
  153. if (result == done)
  154. return 0;
  155. udelay (1);
  156. usec--;
  157. } while (usec > 0);
  158. return -ETIMEDOUT;
  159. }
  160. /* check TDI/ARC silicon is in host mode */
  161. static int tdi_in_host_mode (struct ehci_hcd *ehci)
  162. {
  163. u32 tmp;
  164. tmp = ehci_readl(ehci, &ehci->regs->usbmode);
  165. return (tmp & 3) == USBMODE_CM_HC;
  166. }
  167. /*
  168. * Force HC to halt state from unknown (EHCI spec section 2.3).
  169. * Must be called with interrupts enabled and the lock not held.
  170. */
  171. static int ehci_halt (struct ehci_hcd *ehci)
  172. {
  173. u32 temp;
  174. spin_lock_irq(&ehci->lock);
  175. /* disable any irqs left enabled by previous code */
  176. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  177. if (ehci_is_TDI(ehci) && !tdi_in_host_mode(ehci)) {
  178. spin_unlock_irq(&ehci->lock);
  179. return 0;
  180. }
  181. /*
  182. * This routine gets called during probe before ehci->command
  183. * has been initialized, so we can't rely on its value.
  184. */
  185. ehci->command &= ~CMD_RUN;
  186. temp = ehci_readl(ehci, &ehci->regs->command);
  187. temp &= ~(CMD_RUN | CMD_IAAD);
  188. ehci_writel(ehci, temp, &ehci->regs->command);
  189. spin_unlock_irq(&ehci->lock);
  190. synchronize_irq(ehci_to_hcd(ehci)->irq);
  191. return handshake(ehci, &ehci->regs->status,
  192. STS_HALT, STS_HALT, 16 * 125);
  193. }
  194. /* put TDI/ARC silicon into EHCI mode */
  195. static void tdi_reset (struct ehci_hcd *ehci)
  196. {
  197. u32 tmp;
  198. tmp = ehci_readl(ehci, &ehci->regs->usbmode);
  199. tmp |= USBMODE_CM_HC;
  200. /* The default byte access to MMR space is LE after
  201. * controller reset. Set the required endian mode
  202. * for transfer buffers to match the host microprocessor
  203. */
  204. if (ehci_big_endian_mmio(ehci))
  205. tmp |= USBMODE_BE;
  206. ehci_writel(ehci, tmp, &ehci->regs->usbmode);
  207. }
  208. /*
  209. * Reset a non-running (STS_HALT == 1) controller.
  210. * Must be called with interrupts enabled and the lock not held.
  211. */
  212. static int ehci_reset (struct ehci_hcd *ehci)
  213. {
  214. int retval;
  215. u32 command = ehci_readl(ehci, &ehci->regs->command);
  216. /* If the EHCI debug controller is active, special care must be
  217. * taken before and after a host controller reset */
  218. if (ehci->debug && !dbgp_reset_prep(ehci_to_hcd(ehci)))
  219. ehci->debug = NULL;
  220. command |= CMD_RESET;
  221. dbg_cmd (ehci, "reset", command);
  222. ehci_writel(ehci, command, &ehci->regs->command);
  223. ehci->rh_state = EHCI_RH_HALTED;
  224. ehci->next_statechange = jiffies;
  225. retval = handshake (ehci, &ehci->regs->command,
  226. CMD_RESET, 0, 250 * 1000);
  227. if (ehci->has_hostpc) {
  228. ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
  229. &ehci->regs->usbmode_ex);
  230. ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning);
  231. }
  232. if (retval)
  233. return retval;
  234. if (ehci_is_TDI(ehci))
  235. tdi_reset (ehci);
  236. if (ehci->debug)
  237. dbgp_external_startup(ehci_to_hcd(ehci));
  238. ehci->port_c_suspend = ehci->suspended_ports =
  239. ehci->resuming_ports = 0;
  240. return retval;
  241. }
  242. /*
  243. * Idle the controller (turn off the schedules).
  244. * Must be called with interrupts enabled and the lock not held.
  245. */
  246. static void ehci_quiesce (struct ehci_hcd *ehci)
  247. {
  248. u32 temp;
  249. if (ehci->rh_state != EHCI_RH_RUNNING)
  250. return;
  251. /* wait for any schedule enables/disables to take effect */
  252. temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
  253. handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, temp, 16 * 125);
  254. /* then disable anything that's still active */
  255. spin_lock_irq(&ehci->lock);
  256. ehci->command &= ~(CMD_ASE | CMD_PSE);
  257. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  258. spin_unlock_irq(&ehci->lock);
  259. /* hardware can take 16 microframes to turn off ... */
  260. handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, 0, 16 * 125);
  261. }
  262. /*-------------------------------------------------------------------------*/
  263. static void end_unlink_async(struct ehci_hcd *ehci);
  264. static void unlink_empty_async(struct ehci_hcd *ehci);
  265. static void ehci_work(struct ehci_hcd *ehci);
  266. static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
  267. static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
  268. #include "ehci-timer.c"
  269. #include "ehci-hub.c"
  270. #include "ehci-lpm.c"
  271. #include "ehci-mem.c"
  272. #include "ehci-q.c"
  273. #include "ehci-sched.c"
  274. #include "ehci-sysfs.c"
  275. /*-------------------------------------------------------------------------*/
  276. /* On some systems, leaving remote wakeup enabled prevents system shutdown.
  277. * The firmware seems to think that powering off is a wakeup event!
  278. * This routine turns off remote wakeup and everything else, on all ports.
  279. */
  280. static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
  281. {
  282. int port = HCS_N_PORTS(ehci->hcs_params);
  283. while (port--)
  284. ehci_writel(ehci, PORT_RWC_BITS,
  285. &ehci->regs->port_status[port]);
  286. }
  287. /*
  288. * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
  289. * Must be called with interrupts enabled and the lock not held.
  290. */
  291. static void ehci_silence_controller(struct ehci_hcd *ehci)
  292. {
  293. ehci_halt(ehci);
  294. spin_lock_irq(&ehci->lock);
  295. ehci->rh_state = EHCI_RH_HALTED;
  296. ehci_turn_off_all_ports(ehci);
  297. /* make BIOS/etc use companion controller during reboot */
  298. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  299. /* unblock posted writes */
  300. ehci_readl(ehci, &ehci->regs->configured_flag);
  301. spin_unlock_irq(&ehci->lock);
  302. }
  303. /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
  304. * This forcibly disables dma and IRQs, helping kexec and other cases
  305. * where the next system software may expect clean state.
  306. */
  307. static void ehci_shutdown(struct usb_hcd *hcd)
  308. {
  309. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  310. spin_lock_irq(&ehci->lock);
  311. ehci->shutdown = true;
  312. ehci->rh_state = EHCI_RH_STOPPING;
  313. ehci->enabled_hrtimer_events = 0;
  314. spin_unlock_irq(&ehci->lock);
  315. ehci_silence_controller(ehci);
  316. hrtimer_cancel(&ehci->hrtimer);
  317. }
  318. static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
  319. {
  320. unsigned port;
  321. if (!HCS_PPC (ehci->hcs_params))
  322. return;
  323. ehci_dbg (ehci, "...power%s ports...\n", is_on ? "up" : "down");
  324. for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; )
  325. (void) ehci_hub_control(ehci_to_hcd(ehci),
  326. is_on ? SetPortFeature : ClearPortFeature,
  327. USB_PORT_FEAT_POWER,
  328. port--, NULL, 0);
  329. /* Flush those writes */
  330. ehci_readl(ehci, &ehci->regs->command);
  331. msleep(20);
  332. }
  333. /*-------------------------------------------------------------------------*/
  334. /*
  335. * ehci_work is called from some interrupts, timers, and so on.
  336. * it calls driver completion functions, after dropping ehci->lock.
  337. */
  338. static void ehci_work (struct ehci_hcd *ehci)
  339. {
  340. /* another CPU may drop ehci->lock during a schedule scan while
  341. * it reports urb completions. this flag guards against bogus
  342. * attempts at re-entrant schedule scanning.
  343. */
  344. if (ehci->scanning) {
  345. ehci->need_rescan = true;
  346. return;
  347. }
  348. ehci->scanning = true;
  349. rescan:
  350. ehci->need_rescan = false;
  351. if (ehci->async_count)
  352. scan_async(ehci);
  353. if (ehci->intr_count > 0)
  354. scan_intr(ehci);
  355. if (ehci->isoc_count > 0)
  356. scan_isoc(ehci);
  357. if (ehci->need_rescan)
  358. goto rescan;
  359. ehci->scanning = false;
  360. /* the IO watchdog guards against hardware or driver bugs that
  361. * misplace IRQs, and should let us run completely without IRQs.
  362. * such lossage has been observed on both VT6202 and VT8235.
  363. */
  364. turn_on_io_watchdog(ehci);
  365. }
  366. /*
  367. * Called when the ehci_hcd module is removed.
  368. */
  369. static void ehci_stop (struct usb_hcd *hcd)
  370. {
  371. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  372. ehci_dbg (ehci, "stop\n");
  373. /* no more interrupts ... */
  374. spin_lock_irq(&ehci->lock);
  375. ehci->enabled_hrtimer_events = 0;
  376. spin_unlock_irq(&ehci->lock);
  377. ehci_quiesce(ehci);
  378. ehci_silence_controller(ehci);
  379. ehci_reset (ehci);
  380. hrtimer_cancel(&ehci->hrtimer);
  381. remove_sysfs_files(ehci);
  382. remove_debug_files (ehci);
  383. /* root hub is shut down separately (first, when possible) */
  384. spin_lock_irq (&ehci->lock);
  385. end_free_itds(ehci);
  386. spin_unlock_irq (&ehci->lock);
  387. ehci_mem_cleanup (ehci);
  388. if (ehci->amd_pll_fix == 1)
  389. usb_amd_dev_put();
  390. #ifdef EHCI_STATS
  391. ehci_dbg(ehci, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
  392. ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
  393. ehci->stats.lost_iaa);
  394. ehci_dbg (ehci, "complete %ld unlink %ld\n",
  395. ehci->stats.complete, ehci->stats.unlink);
  396. #endif
  397. dbg_status (ehci, "ehci_stop completed",
  398. ehci_readl(ehci, &ehci->regs->status));
  399. }
  400. /* one-time init, only for memory state */
  401. static int ehci_init(struct usb_hcd *hcd)
  402. {
  403. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  404. u32 temp;
  405. int retval;
  406. u32 hcc_params;
  407. struct ehci_qh_hw *hw;
  408. spin_lock_init(&ehci->lock);
  409. /*
  410. * keep io watchdog by default, those good HCDs could turn off it later
  411. */
  412. ehci->need_io_watchdog = 1;
  413. hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  414. ehci->hrtimer.function = ehci_hrtimer_func;
  415. ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
  416. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  417. /*
  418. * by default set standard 80% (== 100 usec/uframe) max periodic
  419. * bandwidth as required by USB 2.0
  420. */
  421. ehci->uframe_periodic_max = 100;
  422. /*
  423. * hw default: 1K periodic list heads, one per frame.
  424. * periodic_size can shrink by USBCMD update if hcc_params allows.
  425. */
  426. ehci->periodic_size = DEFAULT_I_TDPS;
  427. INIT_LIST_HEAD(&ehci->intr_qh_list);
  428. INIT_LIST_HEAD(&ehci->cached_itd_list);
  429. INIT_LIST_HEAD(&ehci->cached_sitd_list);
  430. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  431. /* periodic schedule size can be smaller than default */
  432. switch (EHCI_TUNE_FLS) {
  433. case 0: ehci->periodic_size = 1024; break;
  434. case 1: ehci->periodic_size = 512; break;
  435. case 2: ehci->periodic_size = 256; break;
  436. default: BUG();
  437. }
  438. }
  439. if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
  440. return retval;
  441. /* controllers may cache some of the periodic schedule ... */
  442. if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
  443. ehci->i_thresh = 0;
  444. else // N microframes cached
  445. ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
  446. /*
  447. * dedicate a qh for the async ring head, since we couldn't unlink
  448. * a 'real' qh without stopping the async schedule [4.8]. use it
  449. * as the 'reclamation list head' too.
  450. * its dummy is used in hw_alt_next of many tds, to prevent the qh
  451. * from automatically advancing to the next td after short reads.
  452. */
  453. ehci->async->qh_next.qh = NULL;
  454. hw = ehci->async->hw;
  455. hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
  456. hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
  457. #if defined(CONFIG_PPC_PS3)
  458. hw->hw_info1 |= cpu_to_hc32(ehci, QH_INACTIVATE);
  459. #endif
  460. hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
  461. hw->hw_qtd_next = EHCI_LIST_END(ehci);
  462. ehci->async->qh_state = QH_STATE_LINKED;
  463. hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
  464. /* clear interrupt enables, set irq latency */
  465. if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
  466. log2_irq_thresh = 0;
  467. temp = 1 << (16 + log2_irq_thresh);
  468. if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
  469. ehci->has_ppcd = 1;
  470. ehci_dbg(ehci, "enable per-port change event\n");
  471. temp |= CMD_PPCEE;
  472. }
  473. if (HCC_CANPARK(hcc_params)) {
  474. /* HW default park == 3, on hardware that supports it (like
  475. * NVidia and ALI silicon), maximizes throughput on the async
  476. * schedule by avoiding QH fetches between transfers.
  477. *
  478. * With fast usb storage devices and NForce2, "park" seems to
  479. * make problems: throughput reduction (!), data errors...
  480. */
  481. if (park) {
  482. park = min(park, (unsigned) 3);
  483. temp |= CMD_PARK;
  484. temp |= park << 8;
  485. }
  486. ehci_dbg(ehci, "park %d\n", park);
  487. }
  488. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  489. /* periodic schedule size can be smaller than default */
  490. temp &= ~(3 << 2);
  491. temp |= (EHCI_TUNE_FLS << 2);
  492. }
  493. if (HCC_LPM(hcc_params)) {
  494. /* support link power management EHCI 1.1 addendum */
  495. ehci_dbg(ehci, "support lpm\n");
  496. ehci->has_lpm = 1;
  497. if (hird > 0xf) {
  498. ehci_dbg(ehci, "hird %d invalid, use default 0",
  499. hird);
  500. hird = 0;
  501. }
  502. temp |= hird << 24;
  503. }
  504. ehci->command = temp;
  505. /* Accept arbitrarily long scatter-gather lists */
  506. if (!(hcd->driver->flags & HCD_LOCAL_MEM))
  507. hcd->self.sg_tablesize = ~0;
  508. return 0;
  509. }
  510. /* start HC running; it's halted, ehci_init() has been run (once) */
  511. static int ehci_run (struct usb_hcd *hcd)
  512. {
  513. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  514. u32 temp;
  515. u32 hcc_params;
  516. hcd->uses_new_polling = 1;
  517. /* EHCI spec section 4.1 */
  518. ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  519. ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
  520. /*
  521. * hcc_params controls whether ehci->regs->segment must (!!!)
  522. * be used; it constrains QH/ITD/SITD and QTD locations.
  523. * pci_pool consistent memory always uses segment zero.
  524. * streaming mappings for I/O buffers, like pci_map_single(),
  525. * can return segments above 4GB, if the device allows.
  526. *
  527. * NOTE: the dma mask is visible through dma_supported(), so
  528. * drivers can pass this info along ... like NETIF_F_HIGHDMA,
  529. * Scsi_Host.highmem_io, and so forth. It's readonly to all
  530. * host side drivers though.
  531. */
  532. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  533. if (HCC_64BIT_ADDR(hcc_params)) {
  534. ehci_writel(ehci, 0, &ehci->regs->segment);
  535. #if 0
  536. // this is deeply broken on almost all architectures
  537. if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
  538. ehci_info(ehci, "enabled 64bit DMA\n");
  539. #endif
  540. }
  541. // Philips, Intel, and maybe others need CMD_RUN before the
  542. // root hub will detect new devices (why?); NEC doesn't
  543. ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
  544. ehci->command |= CMD_RUN;
  545. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  546. dbg_cmd (ehci, "init", ehci->command);
  547. /*
  548. * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
  549. * are explicitly handed to companion controller(s), so no TT is
  550. * involved with the root hub. (Except where one is integrated,
  551. * and there's no companion controller unless maybe for USB OTG.)
  552. *
  553. * Turning on the CF flag will transfer ownership of all ports
  554. * from the companions to the EHCI controller. If any of the
  555. * companions are in the middle of a port reset at the time, it
  556. * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
  557. * guarantees that no resets are in progress. After we set CF,
  558. * a short delay lets the hardware catch up; new resets shouldn't
  559. * be started before the port switching actions could complete.
  560. */
  561. down_write(&ehci_cf_port_reset_rwsem);
  562. ehci->rh_state = EHCI_RH_RUNNING;
  563. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  564. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  565. msleep(5);
  566. up_write(&ehci_cf_port_reset_rwsem);
  567. ehci->last_periodic_enable = ktime_get_real();
  568. temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  569. ehci_info (ehci,
  570. "USB %x.%x started, EHCI %x.%02x%s\n",
  571. ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
  572. temp >> 8, temp & 0xff,
  573. ignore_oc ? ", overcurrent ignored" : "");
  574. ehci_writel(ehci, INTR_MASK,
  575. &ehci->regs->intr_enable); /* Turn On Interrupts */
  576. /* GRR this is run-once init(), being done every time the HC starts.
  577. * So long as they're part of class devices, we can't do it init()
  578. * since the class device isn't created that early.
  579. */
  580. create_debug_files(ehci);
  581. create_sysfs_files(ehci);
  582. return 0;
  583. }
  584. static int ehci_setup(struct usb_hcd *hcd)
  585. {
  586. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  587. int retval;
  588. ehci->regs = (void __iomem *)ehci->caps +
  589. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  590. dbg_hcs_params(ehci, "reset");
  591. dbg_hcc_params(ehci, "reset");
  592. /* cache this readonly data; minimize chip reads */
  593. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  594. ehci->sbrn = HCD_USB2;
  595. /* data structure init */
  596. retval = ehci_init(hcd);
  597. if (retval)
  598. return retval;
  599. retval = ehci_halt(ehci);
  600. if (retval)
  601. return retval;
  602. if (ehci_is_TDI(ehci))
  603. tdi_reset(ehci);
  604. ehci_reset(ehci);
  605. return 0;
  606. }
  607. /*-------------------------------------------------------------------------*/
  608. static irqreturn_t ehci_irq (struct usb_hcd *hcd)
  609. {
  610. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  611. u32 status, masked_status, pcd_status = 0, cmd;
  612. int bh;
  613. spin_lock (&ehci->lock);
  614. status = ehci_readl(ehci, &ehci->regs->status);
  615. /* e.g. cardbus physical eject */
  616. if (status == ~(u32) 0) {
  617. ehci_dbg (ehci, "device removed\n");
  618. goto dead;
  619. }
  620. /*
  621. * We don't use STS_FLR, but some controllers don't like it to
  622. * remain on, so mask it out along with the other status bits.
  623. */
  624. masked_status = status & (INTR_MASK | STS_FLR);
  625. /* Shared IRQ? */
  626. if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
  627. spin_unlock(&ehci->lock);
  628. return IRQ_NONE;
  629. }
  630. /* clear (just) interrupts */
  631. ehci_writel(ehci, masked_status, &ehci->regs->status);
  632. cmd = ehci_readl(ehci, &ehci->regs->command);
  633. bh = 0;
  634. #ifdef VERBOSE_DEBUG
  635. /* unrequested/ignored: Frame List Rollover */
  636. dbg_status (ehci, "irq", status);
  637. #endif
  638. /* INT, ERR, and IAA interrupt rates can be throttled */
  639. /* normal [4.15.1.2] or error [4.15.1.1] completion */
  640. if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
  641. if (likely ((status & STS_ERR) == 0))
  642. COUNT (ehci->stats.normal);
  643. else
  644. COUNT (ehci->stats.error);
  645. bh = 1;
  646. }
  647. /* complete the unlinking of some qh [4.15.2.3] */
  648. if (status & STS_IAA) {
  649. /* Turn off the IAA watchdog */
  650. ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG);
  651. /*
  652. * Mild optimization: Allow another IAAD to reset the
  653. * hrtimer, if one occurs before the next expiration.
  654. * In theory we could always cancel the hrtimer, but
  655. * tests show that about half the time it will be reset
  656. * for some other event anyway.
  657. */
  658. if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG)
  659. ++ehci->next_hrtimer_event;
  660. /* guard against (alleged) silicon errata */
  661. if (cmd & CMD_IAAD)
  662. ehci_dbg(ehci, "IAA with IAAD still set?\n");
  663. if (ehci->async_iaa) {
  664. COUNT(ehci->stats.iaa);
  665. end_unlink_async(ehci);
  666. } else
  667. ehci_dbg(ehci, "IAA with nothing unlinked?\n");
  668. }
  669. /* remote wakeup [4.3.1] */
  670. if (status & STS_PCD) {
  671. unsigned i = HCS_N_PORTS (ehci->hcs_params);
  672. u32 ppcd = 0;
  673. /* kick root hub later */
  674. pcd_status = status;
  675. /* resume root hub? */
  676. if (ehci->rh_state == EHCI_RH_SUSPENDED)
  677. usb_hcd_resume_root_hub(hcd);
  678. /* get per-port change detect bits */
  679. if (ehci->has_ppcd)
  680. ppcd = status >> 16;
  681. while (i--) {
  682. int pstatus;
  683. /* leverage per-port change bits feature */
  684. if (ehci->has_ppcd && !(ppcd & (1 << i)))
  685. continue;
  686. pstatus = ehci_readl(ehci,
  687. &ehci->regs->port_status[i]);
  688. if (pstatus & PORT_OWNER)
  689. continue;
  690. if (!(test_bit(i, &ehci->suspended_ports) &&
  691. ((pstatus & PORT_RESUME) ||
  692. !(pstatus & PORT_SUSPEND)) &&
  693. (pstatus & PORT_PE) &&
  694. ehci->reset_done[i] == 0))
  695. continue;
  696. /* start 20 msec resume signaling from this port,
  697. * and make khubd collect PORT_STAT_C_SUSPEND to
  698. * stop that signaling. Use 5 ms extra for safety,
  699. * like usb_port_resume() does.
  700. */
  701. ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
  702. set_bit(i, &ehci->resuming_ports);
  703. ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
  704. mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
  705. }
  706. }
  707. /* PCI errors [4.15.2.4] */
  708. if (unlikely ((status & STS_FATAL) != 0)) {
  709. ehci_err(ehci, "fatal error\n");
  710. dbg_cmd(ehci, "fatal", cmd);
  711. dbg_status(ehci, "fatal", status);
  712. dead:
  713. usb_hc_died(hcd);
  714. /* Don't let the controller do anything more */
  715. ehci->shutdown = true;
  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. if (ehci->shutdown)
  979. return 0; /* Controller is dead */
  980. /*
  981. * If CF is still set and we aren't resuming from hibernation
  982. * then we maintained suspend power.
  983. * Just undo the effect of ehci_suspend().
  984. */
  985. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
  986. !hibernated) {
  987. int mask = INTR_MASK;
  988. ehci_prepare_ports_for_controller_resume(ehci);
  989. spin_lock_irq(&ehci->lock);
  990. if (ehci->shutdown)
  991. goto skip;
  992. if (!hcd->self.root_hub->do_remote_wakeup)
  993. mask &= ~STS_PCD;
  994. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  995. ehci_readl(ehci, &ehci->regs->intr_enable);
  996. skip:
  997. spin_unlock_irq(&ehci->lock);
  998. return 0;
  999. }
  1000. /*
  1001. * Else reset, to cope with power loss or resume from hibernation
  1002. * having let the firmware kick in during reboot.
  1003. */
  1004. usb_root_hub_lost_power(hcd->self.root_hub);
  1005. (void) ehci_halt(ehci);
  1006. (void) ehci_reset(ehci);
  1007. spin_lock_irq(&ehci->lock);
  1008. if (ehci->shutdown)
  1009. goto skip;
  1010. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  1011. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  1012. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  1013. ehci->rh_state = EHCI_RH_SUSPENDED;
  1014. spin_unlock_irq(&ehci->lock);
  1015. /* here we "know" root ports should always stay powered */
  1016. ehci_port_power(ehci, 1);
  1017. return 1;
  1018. }
  1019. #endif
  1020. /*-------------------------------------------------------------------------*/
  1021. /*
  1022. * The EHCI in ChipIdea HDRC cannot be a separate module or device,
  1023. * because its registers (and irq) are shared between host/gadget/otg
  1024. * functions and in order to facilitate role switching we cannot
  1025. * give the ehci driver exclusive access to those.
  1026. */
  1027. #ifndef CHIPIDEA_EHCI
  1028. MODULE_DESCRIPTION(DRIVER_DESC);
  1029. MODULE_AUTHOR (DRIVER_AUTHOR);
  1030. MODULE_LICENSE ("GPL");
  1031. #ifdef CONFIG_PCI
  1032. #include "ehci-pci.c"
  1033. #define PCI_DRIVER ehci_pci_driver
  1034. #endif
  1035. #ifdef CONFIG_USB_EHCI_FSL
  1036. #include "ehci-fsl.c"
  1037. #define PLATFORM_DRIVER ehci_fsl_driver
  1038. #endif
  1039. #ifdef CONFIG_USB_EHCI_MXC
  1040. #include "ehci-mxc.c"
  1041. #define PLATFORM_DRIVER ehci_mxc_driver
  1042. #endif
  1043. #ifdef CONFIG_USB_EHCI_SH
  1044. #include "ehci-sh.c"
  1045. #define PLATFORM_DRIVER ehci_hcd_sh_driver
  1046. #endif
  1047. #ifdef CONFIG_USB_EHCI_HCD_OMAP
  1048. #include "ehci-omap.c"
  1049. #define PLATFORM_DRIVER ehci_hcd_omap_driver
  1050. #endif
  1051. #ifdef CONFIG_PPC_PS3
  1052. #include "ehci-ps3.c"
  1053. #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
  1054. #endif
  1055. #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
  1056. #include "ehci-ppc-of.c"
  1057. #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
  1058. #endif
  1059. #ifdef CONFIG_XPS_USB_HCD_XILINX
  1060. #include "ehci-xilinx-of.c"
  1061. #define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
  1062. #endif
  1063. #ifdef CONFIG_PLAT_ORION
  1064. #include "ehci-orion.c"
  1065. #define PLATFORM_DRIVER ehci_orion_driver
  1066. #endif
  1067. #ifdef CONFIG_USB_W90X900_EHCI
  1068. #include "ehci-w90x900.c"
  1069. #define PLATFORM_DRIVER ehci_hcd_w90x900_driver
  1070. #endif
  1071. #ifdef CONFIG_ARCH_AT91
  1072. #include "ehci-atmel.c"
  1073. #define PLATFORM_DRIVER ehci_atmel_driver
  1074. #endif
  1075. #ifdef CONFIG_USB_OCTEON_EHCI
  1076. #include "ehci-octeon.c"
  1077. #define PLATFORM_DRIVER ehci_octeon_driver
  1078. #endif
  1079. #ifdef CONFIG_ARCH_VT8500
  1080. #include "ehci-vt8500.c"
  1081. #define PLATFORM_DRIVER vt8500_ehci_driver
  1082. #endif
  1083. #ifdef CONFIG_PLAT_SPEAR
  1084. #include "ehci-spear.c"
  1085. #define PLATFORM_DRIVER spear_ehci_hcd_driver
  1086. #endif
  1087. #ifdef CONFIG_USB_EHCI_MSM
  1088. #include "ehci-msm.c"
  1089. #define PLATFORM_DRIVER ehci_msm_driver
  1090. #endif
  1091. #ifdef CONFIG_TILE_USB
  1092. #include "ehci-tilegx.c"
  1093. #define PLATFORM_DRIVER ehci_hcd_tilegx_driver
  1094. #endif
  1095. #ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
  1096. #include "ehci-pmcmsp.c"
  1097. #define PLATFORM_DRIVER ehci_hcd_msp_driver
  1098. #endif
  1099. #ifdef CONFIG_USB_EHCI_TEGRA
  1100. #include "ehci-tegra.c"
  1101. #define PLATFORM_DRIVER tegra_ehci_driver
  1102. #endif
  1103. #ifdef CONFIG_USB_EHCI_S5P
  1104. #include "ehci-s5p.c"
  1105. #define PLATFORM_DRIVER s5p_ehci_driver
  1106. #endif
  1107. #ifdef CONFIG_SPARC_LEON
  1108. #include "ehci-grlib.c"
  1109. #define PLATFORM_DRIVER ehci_grlib_driver
  1110. #endif
  1111. #ifdef CONFIG_USB_EHCI_MV
  1112. #include "ehci-mv.c"
  1113. #define PLATFORM_DRIVER ehci_mv_driver
  1114. #endif
  1115. #ifdef CONFIG_MIPS_SEAD3
  1116. #include "ehci-sead3.c"
  1117. #define PLATFORM_DRIVER ehci_hcd_sead3_driver
  1118. #endif
  1119. #ifdef CONFIG_USB_EHCI_HCD_PLATFORM
  1120. #include "ehci-platform.c"
  1121. #define PLATFORM_DRIVER ehci_platform_driver
  1122. #endif
  1123. #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
  1124. !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
  1125. !defined(XILINX_OF_PLATFORM_DRIVER)
  1126. #error "missing bus glue for ehci-hcd"
  1127. #endif
  1128. static int __init ehci_hcd_init(void)
  1129. {
  1130. int retval = 0;
  1131. if (usb_disabled())
  1132. return -ENODEV;
  1133. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  1134. set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1135. if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
  1136. test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
  1137. printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
  1138. " before uhci_hcd and ohci_hcd, not after\n");
  1139. pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  1140. hcd_name,
  1141. sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  1142. sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  1143. #ifdef DEBUG
  1144. ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
  1145. if (!ehci_debug_root) {
  1146. retval = -ENOENT;
  1147. goto err_debug;
  1148. }
  1149. #endif
  1150. #ifdef PLATFORM_DRIVER
  1151. retval = platform_driver_register(&PLATFORM_DRIVER);
  1152. if (retval < 0)
  1153. goto clean0;
  1154. #endif
  1155. #ifdef PCI_DRIVER
  1156. retval = pci_register_driver(&PCI_DRIVER);
  1157. if (retval < 0)
  1158. goto clean1;
  1159. #endif
  1160. #ifdef PS3_SYSTEM_BUS_DRIVER
  1161. retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1162. if (retval < 0)
  1163. goto clean2;
  1164. #endif
  1165. #ifdef OF_PLATFORM_DRIVER
  1166. retval = platform_driver_register(&OF_PLATFORM_DRIVER);
  1167. if (retval < 0)
  1168. goto clean3;
  1169. #endif
  1170. #ifdef XILINX_OF_PLATFORM_DRIVER
  1171. retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
  1172. if (retval < 0)
  1173. goto clean4;
  1174. #endif
  1175. return retval;
  1176. #ifdef XILINX_OF_PLATFORM_DRIVER
  1177. /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
  1178. clean4:
  1179. #endif
  1180. #ifdef OF_PLATFORM_DRIVER
  1181. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1182. clean3:
  1183. #endif
  1184. #ifdef PS3_SYSTEM_BUS_DRIVER
  1185. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1186. clean2:
  1187. #endif
  1188. #ifdef PCI_DRIVER
  1189. pci_unregister_driver(&PCI_DRIVER);
  1190. clean1:
  1191. #endif
  1192. #ifdef PLATFORM_DRIVER
  1193. platform_driver_unregister(&PLATFORM_DRIVER);
  1194. clean0:
  1195. #endif
  1196. #ifdef DEBUG
  1197. debugfs_remove(ehci_debug_root);
  1198. ehci_debug_root = NULL;
  1199. err_debug:
  1200. #endif
  1201. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1202. return retval;
  1203. }
  1204. module_init(ehci_hcd_init);
  1205. static void __exit ehci_hcd_cleanup(void)
  1206. {
  1207. #ifdef XILINX_OF_PLATFORM_DRIVER
  1208. platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
  1209. #endif
  1210. #ifdef OF_PLATFORM_DRIVER
  1211. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1212. #endif
  1213. #ifdef PLATFORM_DRIVER
  1214. platform_driver_unregister(&PLATFORM_DRIVER);
  1215. #endif
  1216. #ifdef PCI_DRIVER
  1217. pci_unregister_driver(&PCI_DRIVER);
  1218. #endif
  1219. #ifdef PS3_SYSTEM_BUS_DRIVER
  1220. ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1221. #endif
  1222. #ifdef DEBUG
  1223. debugfs_remove(ehci_debug_root);
  1224. #endif
  1225. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1226. }
  1227. module_exit(ehci_hcd_cleanup);
  1228. #endif /* CHIPIDEA_EHCI */