ehci-hcd.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  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 <stdint.h>
  23. #include <stdio.h>
  24. #include <hal_osal.h>
  25. //#include <aw_types.h>
  26. #include <aw_list.h>
  27. #include <interrupt.h>
  28. #include <usb_gen_hub.h>
  29. #include <sunxi_hal_common.h>
  30. #include "ehci.h"
  31. /*-------------------------------------------------------------------------*/
  32. /*
  33. * EHCI hc_driver implementation ... experimental, incomplete.
  34. * Based on the final 1.0 register interface specification.
  35. *
  36. * USB 2.0 shows up in upcoming www.pcmcia.org technology.
  37. * First was PCMCIA, like ISA; then CardBus, which is PCI.
  38. * Next comes "CardBay", using USB 2.0 signals.
  39. *
  40. * Contains additional contributions by Brad Hards, Rory Bolt, and others.
  41. * Special thanks to Intel and VIA for providing host controllers to
  42. * test this driver on, and Cypress (including In-System Design) for
  43. * providing early devices for those host controllers to talk to!
  44. */
  45. #define DRIVER_AUTHOR "David Brownell"
  46. #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
  47. static const char hcd_name [] = "ehci_hcd";
  48. uint32_t le32_to_cpu(uint32_t x);
  49. #undef EHCI_URB_TRACE
  50. /* magic numbers that can affect system performance */
  51. #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
  52. #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
  53. #define EHCI_TUNE_RL_TT 0
  54. #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
  55. #define EHCI_TUNE_MULT_TT 1
  56. /*
  57. * Some drivers think it's safe to schedule isochronous transfers more than
  58. * 256 ms into the future (partly as a result of an old bug in the scheduling
  59. * code). In an attempt to avoid trouble, we will use a minimum scheduling
  60. * length of 512 frames instead of 256.
  61. */
  62. #define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */
  63. /* Initial IRQ latency: faster than hw default */
  64. static int log2_irq_thresh = 0; // 0 to 6
  65. //module_param (log2_irq_thresh, int, S_IRUGO);
  66. //MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
  67. /* initial park setting: slower than hw default */
  68. static unsigned park = 0;
  69. //module_param (park, uint, S_IRUGO);
  70. //MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
  71. /* for flakey hardware, ignore overcurrent indicators */
  72. //static bool ignore_oc;
  73. //module_param (ignore_oc, bool, S_IRUGO);
  74. //MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
  75. //#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
  76. /*-------------------------------------------------------------------------*/
  77. #include "ehci.h"
  78. //#include "pci-quirks.h"
  79. static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE],
  80. struct ehci_tt *tt);
  81. /*
  82. * The MosChip MCS9990 controller updates its microframe counter
  83. * a little before the frame counter, and occasionally we will read
  84. * the invalid intermediate value. Avoid problems by checking the
  85. * microframe number (the low-order 3 bits); if they are 0 then
  86. * re-read the register to get the correct value.
  87. */
  88. static unsigned ehci_moschip_read_frame_index(struct ehci_hcd *ehci)
  89. {
  90. unsigned uf;
  91. uf = ehci_readl(ehci, &ehci->regs->frame_index);
  92. if (unlikely((uf & 7) == 0))
  93. uf = ehci_readl(ehci, &ehci->regs->frame_index);
  94. return uf;
  95. }
  96. static inline unsigned ehci_read_frame_index(struct ehci_hcd *ehci)
  97. {
  98. if (ehci->frame_index_bug)
  99. return ehci_moschip_read_frame_index(ehci);
  100. return ehci_readl(ehci, &ehci->regs->frame_index);
  101. }
  102. //#include "ehci-dbg.c"
  103. /*-------------------------------------------------------------------------*/
  104. /*
  105. * ehci_handshake - spin reading hc until handshake completes or fails
  106. * @ptr: address of hc register to be read
  107. * @mask: bits to look at in result of read
  108. * @done: value of those bits when handshake succeeds
  109. * @usec: timeout in microseconds
  110. *
  111. * Returns negative errno, or zero on success
  112. *
  113. * Success happens when the "mask" bits have the specified value (hardware
  114. * handshake done). There are two failure modes: "usec" have passed (major
  115. * hardware flakeout), or the register reads as all-ones (hardware removed).
  116. *
  117. * That last failure should_only happen in cases like physical cardbus eject
  118. * before driver shutdown. But it also seems to be caused by bugs in cardbus
  119. * bridge shutdown: shutting down the bridge before the devices using it.
  120. */
  121. int ehci_handshake(struct ehci_hcd *ehci, u32 *ptr,
  122. u32 mask, u32 done, int usec)
  123. {
  124. u32 result;
  125. do {
  126. result = ehci_readl(ehci, ptr);
  127. if (result == ~(u32)0) /* card removed */
  128. return -ENODEV;
  129. result &= mask;
  130. if (result == done)
  131. return 0;
  132. udelay (1);
  133. usec--;
  134. } while (usec > 0);
  135. return -ETIMEDOUT;
  136. }
  137. /* check TDI/ARC silicon is in host mode */
  138. static int tdi_in_host_mode (struct ehci_hcd *ehci)
  139. {
  140. u32 tmp;
  141. tmp = ehci_readl(ehci, &ehci->regs->usbmode);
  142. return (tmp & 3) == USBMODE_CM_HC;
  143. }
  144. /*
  145. * Force HC to halt state from unknown (EHCI spec section 2.3).
  146. * Must be called with interrupts enabled and the lock not held.
  147. */
  148. int ehci_halt (struct ehci_hcd *ehci)
  149. {
  150. u32 temp;
  151. uint32_t cpusr;
  152. hal_spin_lock(&ehci->lock);
  153. /* disable any irqs left enabled by previous code */
  154. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  155. //if (ehci_is_TDI(ehci) && !tdi_in_host_mode(ehci)) {
  156. // hal_spin_unlock_irqrestore(cpusr);
  157. // return 0;
  158. //}
  159. /*
  160. * This routine gets called during probe before ehci->command
  161. * has been initialized, so we can't rely on its value.
  162. */
  163. ehci->command &= ~CMD_RUN;
  164. temp = ehci_readl(ehci, &ehci->regs->command);
  165. temp &= ~(CMD_RUN | CMD_IAAD);
  166. ehci_writel(ehci, temp, &ehci->regs->command);
  167. hal_spin_unlock(&ehci->lock);
  168. //synchronize_irq(ehci_to_hcd(ehci)->irq);
  169. return ehci_handshake(ehci, &ehci->regs->status,
  170. STS_HALT, STS_HALT, 16 * 125);
  171. }
  172. /* put TDI/ARC silicon into EHCI mode */
  173. static void tdi_reset (struct ehci_hcd *ehci)
  174. {
  175. u32 tmp;
  176. tmp = ehci_readl(ehci, &ehci->regs->usbmode);
  177. tmp |= USBMODE_CM_HC;
  178. /* The default byte access to MMR space is LE after
  179. * controller reset. Set the required endian mode
  180. * for transfer buffers to match the host microprocessor
  181. */
  182. if (ehci_big_endian_mmio(ehci))
  183. tmp |= USBMODE_BE;
  184. ehci_writel(ehci, tmp, &ehci->regs->usbmode);
  185. }
  186. /*
  187. * Reset a non-running (STS_HALT == 1) controller.
  188. * Must be called with interrupts enabled and the lock not held.
  189. */
  190. int ehci_reset(struct ehci_hcd *ehci)
  191. {
  192. int retval;
  193. u32 command = ehci_readl(ehci, &ehci->regs->command);
  194. command |= CMD_RESET;
  195. //dbg_cmd (ehci, "reset", command);
  196. ehci_writel(ehci, command, &ehci->regs->command);
  197. ehci->rh_state = EHCI_RH_HALTED;
  198. //ehci->next_statechange = jiffies;
  199. retval = ehci_handshake(ehci, &ehci->regs->command,
  200. CMD_RESET, 0, 250 * 1000);
  201. if (ehci->has_hostpc) {
  202. ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
  203. &ehci->regs->usbmode_ex);
  204. ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning);
  205. }
  206. if (retval)
  207. return retval;
  208. //if (ehci_is_TDI(ehci))
  209. // tdi_reset (ehci);
  210. ehci->port_c_suspend = ehci->suspended_ports =
  211. ehci->resuming_ports = 0;
  212. return retval;
  213. }
  214. /*
  215. * Idle the controller (turn off the schedules).
  216. * Must be called with interrupts enabled and the lock not held.
  217. */
  218. static void ehci_quiesce (struct ehci_hcd *ehci)
  219. {
  220. u32 temp;
  221. uint32_t cpusr;
  222. if (ehci->rh_state != EHCI_RH_RUNNING)
  223. return;
  224. /* wait for any schedule enables/disables to take effect */
  225. temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
  226. ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, temp,
  227. 16 * 125);
  228. /* then disable anything that's still active */
  229. hal_spin_lock(&ehci->lock);
  230. ehci->command &= ~(CMD_ASE | CMD_PSE);
  231. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  232. hal_spin_unlock(&ehci->lock);
  233. /* hardware can take 16 microframes to turn off ... */
  234. ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, 0,
  235. 16 * 125);
  236. }
  237. /*-------------------------------------------------------------------------*/
  238. static void end_iaa_cycle(struct ehci_hcd *ehci);
  239. static void end_unlink_async(struct ehci_hcd *ehci);
  240. static void unlink_empty_async(struct ehci_hcd *ehci);
  241. void ehci_work(struct ehci_hcd *ehci);
  242. static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
  243. static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
  244. static int ehci_port_power(struct ehci_hcd *ehci, int portnum, bool enable);
  245. #define EHCI_QH_COMPLETIONS_DEBUG 0
  246. #if EHCI_QH_COMPLETIONS_DEBUG
  247. #define EHCI_DEBUG_PRINTF(format, args...) \
  248. printf("[%s:%d] " format "\n", __func__, __LINE__, ##args)
  249. #else
  250. #define EHCI_DEBUG_PRINTF(...)
  251. #endif
  252. #include "ehci-timer.c"
  253. #include "ehci-hub.c"
  254. #include "ehci-mem.c"
  255. #include "ehci-q.c"
  256. #include "ehci-sched.c"
  257. //#include "ehci-sysfs.c"
  258. /*-------------------------------------------------------------------------*/
  259. /* On some systems, leaving remote wakeup enabled prevents system shutdown.
  260. * The firmware seems to think that powering off is a wakeup event!
  261. * This routine turns off remote wakeup and everything else, on all ports.
  262. */
  263. static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
  264. {
  265. int port = HCS_N_PORTS(ehci->hcs_params);
  266. while (port--) {
  267. hal_spin_unlock(&ehci->lock);
  268. ehci_port_power(ehci, port, false);
  269. hal_spin_lock(&ehci->lock);
  270. ehci_writel(ehci, PORT_RWC_BITS,
  271. &ehci->regs->port_status[port]);
  272. }
  273. }
  274. /*
  275. * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
  276. * Must be called with interrupts enabled and the lock not held.
  277. */
  278. static void ehci_silence_controller(struct ehci_hcd *ehci)
  279. {
  280. ehci_halt(ehci);
  281. hal_spin_lock(&ehci->lock);
  282. ehci->rh_state = EHCI_RH_HALTED;
  283. ehci_turn_off_all_ports(ehci);
  284. /* make BIOS/etc use companion controller during reboot */
  285. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  286. /* unblock posted writes */
  287. ehci_readl(ehci, &ehci->regs->configured_flag);
  288. hal_spin_unlock(&ehci->lock);
  289. }
  290. /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
  291. * This forcibly disables dma and IRQs, helping kexec and other cases
  292. * where the next system software may expect clean state.
  293. */
  294. static void ehci_shutdown(struct hc_gen_dev *hcd)
  295. {
  296. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  297. /**
  298. * Protect the system from crashing at system shutdown in cases where
  299. * usb host is not added yet from OTG controller driver.
  300. * As ehci_setup() not done yet, so stop accessing registers or
  301. * variables initialized in ehci_setup()
  302. */
  303. if (!ehci->sbrn)
  304. return;
  305. hal_spin_lock(&ehci->lock);
  306. ehci->shutdown = true;
  307. ehci->rh_state = EHCI_RH_STOPPING;
  308. ehci->enabled_hrtimer_events = 0;
  309. hal_spin_unlock(&ehci->lock);
  310. ehci_silence_controller(ehci);
  311. osal_timer_stop(ehci->hrtimer);
  312. }
  313. /*-------------------------------------------------------------------------*/
  314. /*
  315. * ehci_work is called from some interrupts, timers, and so on.
  316. * it calls driver completion functions, after dropping ehci->lock.
  317. */
  318. void ehci_work (struct ehci_hcd *ehci)
  319. {
  320. /* another CPU may drop ehci->lock during a schedule scan while
  321. * it reports urb completions. this flag guards against bogus
  322. * attempts at re-entrant schedule scanning.
  323. */
  324. EHCI_DEBUG_PRINTF("ehci->scanning = %d, ehci->async_count = %u, ehci->intr_count = %u, ehci->isoc_count = %u",
  325. ehci->scanning, ehci->async_count, ehci->intr_count, ehci->isoc_count);
  326. if (ehci->scanning) {
  327. ehci->need_rescan = true;
  328. return;
  329. }
  330. ehci->scanning = true;
  331. rescan:
  332. ehci->need_rescan = false;
  333. if (ehci->async_count)
  334. scan_async(ehci);
  335. if (ehci->intr_count > 0)
  336. scan_intr(ehci);
  337. if (ehci->isoc_count > 0)
  338. scan_isoc(ehci);
  339. if (ehci->need_rescan)
  340. goto rescan;
  341. ehci->scanning = false;
  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. turn_on_io_watchdog(ehci);
  347. }
  348. /*
  349. * Called when the ehci_hcd module is removed.
  350. */
  351. void ehci_stop (struct hc_gen_dev *hcd)
  352. {
  353. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  354. ehci_dbg ("ehci stop\n");
  355. /* no more interrupts ... */
  356. //spin_lock_irq(&ehci->lock);
  357. hal_spin_lock (&ehci->lock);
  358. ehci->enabled_hrtimer_events = 0;
  359. hal_spin_unlock (&ehci->lock);
  360. //spin_unlock_irq(&ehci->lock);
  361. ehci_quiesce(ehci);
  362. ehci_silence_controller(ehci);
  363. ehci_reset (ehci);
  364. osal_timer_stop(ehci->hrtimer);
  365. //hrtimer_cancel(&ehci->hrtimer);
  366. //remove_sysfs_files(ehci);
  367. //remove_debug_files (ehci);
  368. /* root hub is shut down separately (first, when possible) */
  369. hal_spin_lock (&ehci->lock);
  370. end_free_itds(ehci);
  371. hal_spin_unlock (&ehci->lock);
  372. ehci_mem_cleanup (ehci);
  373. //if (ehci->amd_pll_fix == 1)
  374. // usb_amd_dev_put();
  375. //dbg_status (ehci, "ehci_stop completed",
  376. // ehci_readl(ehci, &ehci->regs->status));
  377. }
  378. /* one-time init, only for memory state */
  379. //static int ehci_init(struct usb_hcd *hcd)
  380. int ehci_init(struct hc_gen_dev *hcd)
  381. {
  382. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  383. u32 temp;
  384. int retval;
  385. u32 hcc_params;
  386. struct ehci_qh_hw *hw;
  387. //spin_lock_init(&ehci->lock);
  388. /*
  389. * keep io watchdog by default, those good HCDs could turn off it later
  390. */
  391. //ehci->need_io_watchdog = 1;
  392. //hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  393. //ehci->hrtimer.function = ehci_hrtimer_func;
  394. //ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
  395. ehci->hrtimer = osal_timer_create("hcd_hrtimer", ehci_hrtimer_func, (void*)ehci,
  396. 1, OSAL_TIMER_FLAG_ONE_SHOT);
  397. if (ehci->hrtimer == NULL)
  398. {
  399. hal_log_err("PANIC : create timer fail");
  400. }
  401. ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
  402. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  403. /*
  404. * by default set standard 80% (== 100 usec/uframe) max periodic
  405. * bandwidth as required by USB 2.0
  406. */
  407. ehci->uframe_periodic_max = 100;
  408. /*
  409. * hw default: 1K periodic list heads, one per frame.
  410. * periodic_size can shrink by USBCMD update if hcc_params allows.
  411. */
  412. ehci->periodic_size = DEFAULT_I_TDPS;
  413. INIT_LIST_HEAD(&ehci->async_unlink);
  414. INIT_LIST_HEAD(&ehci->async_idle);
  415. INIT_LIST_HEAD(&ehci->intr_unlink_wait);
  416. INIT_LIST_HEAD(&ehci->intr_unlink);
  417. INIT_LIST_HEAD(&ehci->intr_qh_list);
  418. INIT_LIST_HEAD(&ehci->cached_itd_list);
  419. INIT_LIST_HEAD(&ehci->cached_sitd_list);
  420. INIT_LIST_HEAD(&ehci->tt_list);
  421. INIT_LIST_HEAD(&ehci->wait_free_list);
  422. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  423. /* periodic schedule size can be smaller than default */
  424. switch (EHCI_TUNE_FLS) {
  425. case 0: ehci->periodic_size = 1024; break;
  426. case 1: ehci->periodic_size = 512; break;
  427. case 2: ehci->periodic_size = 256; break;
  428. default: ; //BUG();
  429. }
  430. }
  431. if ((retval = ehci_mem_init(ehci)) < 0)
  432. return retval;
  433. /* controllers may cache some of the periodic schedule ... */
  434. if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
  435. ehci->i_thresh = 0;
  436. else // N microframes cached
  437. ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
  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. //hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
  450. hw->hw_info1 = QH_HEAD;
  451. hw->hw_token = QTD_STS_HALT;
  452. hw->hw_qtd_next = EHCI_LIST_END(ehci);
  453. ehci->async->qh_state = QH_STATE_LINKED;
  454. //hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
  455. /* clear interrupt enables, set irq latency */
  456. if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
  457. log2_irq_thresh = 0;
  458. temp = 1 << (16 + log2_irq_thresh);
  459. if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
  460. ehci->has_ppcd = 1;
  461. ehci_dbg("enable per-port change event\n");
  462. temp |= CMD_PPCEE;
  463. }
  464. if (HCC_CANPARK(hcc_params)) {
  465. /* HW default park == 3, on hardware that supports it (like
  466. * NVidia and ALI silicon), maximizes throughput on the async
  467. * schedule by avoiding QH fetches between transfers.
  468. *
  469. * With fast usb storage devices and NForce2, "park" seems to
  470. * make problems: throughput reduction (!), data errors...
  471. */
  472. if (park) {
  473. park = min(park, (unsigned) 3);
  474. temp |= CMD_PARK;
  475. temp |= park << 8;
  476. }
  477. ehci_dbg("park %d\n", park);
  478. }
  479. if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
  480. /* periodic schedule size can be smaller than default */
  481. temp &= ~(3 << 2);
  482. temp |= (EHCI_TUNE_FLS << 2);
  483. }
  484. ehci->command = temp;
  485. /* Accept arbitrarily long scatter-gather lists */
  486. //if (!(hcd->driver->flags & HCD_LOCAL_MEM))
  487. // hcd->self.sg_tablesize = ~0;
  488. /* Prepare for unlinking active QHs */
  489. ehci->old_current = ~0;
  490. return 0;
  491. }
  492. /* start HC running; it's halted, ehci_init() has been run (once) */
  493. int ehci_run (struct hc_gen_dev *hcd)
  494. {
  495. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  496. u32 temp;
  497. u32 hcc_params;
  498. hcd->uses_new_polling = 1;
  499. /* EHCI spec section 4.1 */
  500. ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  501. ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
  502. /*
  503. * hcc_params controls whether ehci->regs->segment must (!!!)
  504. * be used; it constrains QH/ITD/SITD and QTD locations.
  505. * pci_pool consistent memory always uses segment zero.
  506. * streaming mappings for I/O buffers, like pci_map_single(),
  507. * can return segments above 4GB, if the device allows.
  508. *
  509. * NOTE: the dma mask is visible through dev->dma_mask, so
  510. * drivers can pass this info along ... like NETIF_F_HIGHDMA,
  511. * Scsi_Host.highmem_io, and so forth. It's readonly to all
  512. * host side drivers though.
  513. */
  514. hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
  515. if (HCC_64BIT_ADDR(hcc_params)) {
  516. //#ifdef CONFIG_ARM64
  517. // ehci_writel(ehci, ehci->periodic_dma >> 32,
  518. // &ehci->regs->segment);
  519. // /*
  520. // * this is deeply broken on almost all architectures
  521. // * but arm64 can use it so enable it
  522. // */
  523. // if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
  524. // ehci_info(ehci, "enabled 64bit DMA\n");
  525. //#else
  526. ehci_writel(ehci, 0, &ehci->regs->segment);
  527. //endif
  528. }
  529. // Philips, Intel, and maybe others need CMD_RUN before the
  530. // root hub will detect new devices (why?); NEC doesn't
  531. ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
  532. ehci->command |= CMD_RUN;
  533. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  534. //dbg_cmd (ehci, "init", ehci->command);
  535. /*
  536. * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
  537. * are explicitly handed to companion controller(s), so no TT is
  538. * involved with the root hub. (Except where one is integrated,
  539. * and there's no companion controller unless maybe for USB OTG.)
  540. *
  541. * Turning on the CF flag will transfer ownership of all ports
  542. * from the companions to the EHCI controller. If any of the
  543. * companions are in the middle of a port reset at the time, it
  544. * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
  545. * guarantees that no resets are in progress. After we set CF,
  546. * a short delay lets the hardware catch up; new resets shouldn't
  547. * be started before the port switching actions could complete.
  548. */
  549. //down_write(&ehci_cf_port_reset_rwsem);
  550. ehci->rh_state = EHCI_RH_RUNNING;
  551. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  552. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  553. hal_log_info("--ehci_run: cmd = 0x%x\n", ehci_readl(ehci, &ehci->regs->command));
  554. hal_msleep(5);
  555. //up_write(&ehci_cf_port_reset_rwsem);
  556. //ehci->last_periodic_enable = ktime_get_real();
  557. temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  558. //ehci_info ("USB %x.%x started, EHCI %x.%02x%s\n",
  559. // ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
  560. // temp >> 8, temp & 0xff,
  561. // ignore_oc ? ", overcurrent ignored" : "");
  562. hal_log_info("--ehci_run: hc_capbase = 0x%x\n", temp);
  563. ehci_info ("USB %x.%x started, EHCI %x.%02x%s\n",
  564. ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
  565. temp >> 8, temp & 0xff);
  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. return 0;
  573. }
  574. int ehci_setup(struct hc_gen_dev *hcd)
  575. {
  576. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  577. int retval;
  578. ehci->regs = (void *)ehci->caps +
  579. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  580. //dbg_hcs_params(ehci, "reset");
  581. //dbg_hcc_params(ehci, "reset");
  582. /* cache this readonly data; minimize chip reads */
  583. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  584. ehci->sbrn = 0x0020;//HCD_USB2;
  585. /* data structure init */
  586. retval = ehci_init(hcd);
  587. if (retval)
  588. return retval;
  589. retval = ehci_halt(ehci);
  590. if (retval) {
  591. ehci_mem_cleanup(ehci);
  592. return retval;
  593. }
  594. ehci_reset(ehci);
  595. return 0;
  596. }
  597. //EXPORT_SYMBOL_GPL(ehci_setup);
  598. /*-------------------------------------------------------------------------*/
  599. //irqreturn_t ehci_irq (struct hc_gen_dev *hcd)
  600. irqreturn_t ehci_irq_handler (int dummy, void *dev)
  601. {
  602. struct hc_gen_dev *hcd = (struct hc_gen_dev *)dev;
  603. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  604. u32 status, masked_status, pcd_status = 0, cmd;
  605. int bh;
  606. unsigned long flags;
  607. EHCI_DEBUG_PRINTF("");
  608. /*
  609. * For threadirqs option we use spin_lock_irqsave() variant to prevent
  610. * deadlock with ehci hrtimer callback, because hrtimer callbacks run
  611. * in interrupt context even when threadirqs is specified. We can go
  612. * back to spin_lock() variant when hrtimer callbacks become threaded.
  613. */
  614. flags = hal_spin_lock_irqsave(&ehci->lock);
  615. status = ehci_readl(ehci, &ehci->regs->status);
  616. /* e.g. cardbus physical eject */
  617. if (status == ~(u32) 0) {
  618. printf("device removed\n");
  619. goto dead;
  620. }
  621. /*
  622. * We don't use STS_FLR, but some controllers don't like it to
  623. * remain on, so mask it out along with the other status bits.
  624. */
  625. masked_status = status & (INTR_MASK | STS_FLR);
  626. /* Shared IRQ? */
  627. if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
  628. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  629. return IRQ_NONE;
  630. }
  631. /* clear (just) interrupts */
  632. ehci_writel(ehci, masked_status, &ehci->regs->status);
  633. cmd = ehci_readl(ehci, &ehci->regs->command);
  634. bh = 0;
  635. /* normal [4.15.1.2] or error [4.15.1.1] completion */
  636. if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
  637. if (likely ((status & STS_ERR) == 0))
  638. COUNT (ehci->stats.normal);
  639. else {
  640. COUNT (ehci->stats.error);
  641. }
  642. bh = 1;
  643. }
  644. /* complete the unlinking of some qh [4.15.2.3] */
  645. if (status & STS_IAA) {
  646. /* Turn off the IAA watchdog */
  647. ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG);
  648. /*
  649. * Mild optimization: Allow another IAAD to reset the
  650. * hrtimer, if one occurs before the next expiration.
  651. * In theory we could always cancel the hrtimer, but
  652. * tests show that about half the time it will be reset
  653. * for some other event anyway.
  654. */
  655. if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG)
  656. ++ehci->next_hrtimer_event;
  657. /* guard against (alleged) silicon errata */
  658. if (cmd & CMD_IAAD)
  659. hal_log_info("IAA with IAAD still set?\n");
  660. if (ehci->iaa_in_progress) {
  661. COUNT(ehci->stats.iaa);
  662. }
  663. hal_log_info("\033[41m WARN : STS_IAA!!!! \033[0m");
  664. // end_iaa_cycle(ehci);//for test
  665. }
  666. /* remote wakeup [4.3.1] */
  667. if (status & STS_PCD) {
  668. unsigned i = HCS_N_PORTS (ehci->hcs_params);
  669. u32 ppcd = ~0;
  670. {
  671. int pstatus0 = 0;
  672. pstatus0 = ehci_readl(ehci, &ehci->regs->port_status[0]);
  673. if ((pstatus0 & PORT_CONNECT) && (pstatus0 & PORT_CSC))
  674. printf("\nehci_irq: highspeed device connect \n\n");
  675. else if (!(pstatus0 & PORT_CONNECT) && (pstatus0 & PORT_CSC))
  676. printf("\nehci_irq: highspeed device disconnect \n\n");
  677. }
  678. /* kick root hub later */
  679. pcd_status = status;
  680. /* resume root hub? */
  681. //if (ehci->rh_state == EHCI_RH_SUSPENDED)
  682. // usb_hcd_resume_root_hub(hcd);
  683. /* get per-port change detect bits */
  684. if (ehci->has_ppcd)
  685. ppcd = status >> 16;
  686. while (i--) {
  687. int pstatus;
  688. /* leverage per-port change bits feature */
  689. if (!(ppcd & (1 << i)))
  690. continue;
  691. pstatus = ehci_readl(ehci,
  692. &ehci->regs->port_status[i]);
  693. if (pstatus & PORT_OWNER)
  694. continue;
  695. if (!(usb_test_bit(i, (volatile uint32_t *)&ehci->suspended_ports) &&
  696. ((pstatus & PORT_RESUME) ||
  697. !(pstatus & PORT_SUSPEND)) &&
  698. (pstatus & PORT_PE) &&
  699. ehci->reset_done[i] == 0))
  700. continue;
  701. /* start USB_RESUME_TIMEOUT msec resume signaling from
  702. * this port, and make hub_wq collect
  703. * PORT_STAT_C_SUSPEND to stop that signaling.
  704. */
  705. //ehci->reset_done[i] = jiffies +
  706. // msecs_to_jiffies(USB_RESUME_TIMEOUT);
  707. //set_bit(i, &ehci->resuming_ports);
  708. printf("port %d remote wakeup\n", i + 1);
  709. usb_hcd_start_port_resume(&hcd->self, i);
  710. //mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
  711. }
  712. }
  713. /* PCI errors [4.15.2.4] */
  714. if (unlikely ((status & STS_FATAL) != 0)) {
  715. hal_log_err("fatal error\n");
  716. //dbg_cmd(ehci, "fatal", cmd);
  717. //dbg_status(ehci, "fatal", status);
  718. dead:
  719. //usb_hc_died(hcd);
  720. /* Don't let the controller do anything more */
  721. ehci->shutdown = true;
  722. ehci->rh_state = EHCI_RH_STOPPING;
  723. ehci->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
  724. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  725. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  726. ehci_handle_controller_death(ehci);
  727. /* Handle completions when the controller stops */
  728. bh = 0;
  729. }
  730. if (bh)
  731. ehci_work (ehci);
  732. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  733. if (pcd_status)
  734. usb_hcd_poll_rh_status(hcd);
  735. return IRQ_HANDLED;
  736. }
  737. /*-------------------------------------------------------------------------*/
  738. /*
  739. * non-error returns are a promise to giveback() the urb later
  740. * we drop ownership so next owner (or urb unlink) can get it
  741. *
  742. * urb + dev is in hcd.self.controller.urb_list
  743. * we're queueing TDs onto software and hardware lists
  744. *
  745. * hcd-specific init for hcpriv hasn't been done yet
  746. *
  747. * NOTE: control, bulk, and interrupt share the same code to append TDs
  748. * to a (possibly active) QH, and the same QH scanning code.
  749. */
  750. // 从usb_submit_urb传下来的调用
  751. // 实现了EHCI这一层上HCD(host controller driver)与硬件的读写接口
  752. // 该函数被执行代表driver有数据要与usb交换(收或者发),driver的请求用urb传下来
  753. // EHCI与CPU的数据交换方式是通过在内存中建立一块共享的内存区域,通过DMA的方式实现的
  754. // 数据在usb设备和HC间传输不需要CPU的干预,但是需要CPU告诉HC共享区域的地址和长度信息(还有usb设备的信息)等
  755. // 那么CPU就会把共享内存区域的地址、长度等信息构造成HC能识别的表(iTD,QH,qTD等描述符),再把这些表交给HC
  756. // HC就会按这张表所记录的信息在指定的内存地址处进行数据的传输,传输完成后,以中断的方式通知CPU一次传输的完成
  757. int ehci_urb_enqueue (
  758. struct hc_gen_dev *hcd,
  759. struct urb *urb,
  760. unsigned mem_flags
  761. ) {
  762. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  763. struct list_head qtd_list;
  764. INIT_LIST_HEAD (&qtd_list);//用于管理EHCI中的qtd数据结构
  765. switch (usb_pipetype (urb->pipe)) {
  766. case PIPE_CONTROL:
  767. /* qh_completions() code doesn't handle all the fault cases
  768. * in multi-TD control transfers. Even 1KB is rare anyway.
  769. */
  770. if (urb->transfer_buffer_length > (16 * 1024))
  771. return -EMSGSIZE;
  772. /* FALLTHROUGH */
  773. /* case PIPE_BULK: */
  774. default:
  775. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  776. return -ENOMEM;
  777. return submit_async(ehci, urb, &qtd_list, mem_flags);
  778. case PIPE_INTERRUPT:
  779. if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
  780. return -ENOMEM;
  781. return intr_submit(ehci, urb, &qtd_list, mem_flags);
  782. case PIPE_ISOCHRONOUS:
  783. if (urb->dev->speed == USB_SPEED_HIGH)
  784. return itd_submit (ehci, urb, mem_flags);
  785. else
  786. return sitd_submit (ehci, urb, mem_flags);
  787. }
  788. }
  789. /* remove from hardware lists
  790. * completions normally happen asynchronously
  791. */
  792. int ehci_urb_dequeue(struct hc_gen_dev *hcd, struct urb *urb)
  793. {
  794. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  795. struct ehci_qh *qh;
  796. unsigned long flags;
  797. int rc;
  798. flags = hal_spin_lock_irqsave (&ehci->lock);
  799. rc = usb_hcd_check_unlink_urb(hcd, urb);
  800. if (rc)
  801. goto done;
  802. if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  803. /*
  804. * We don't expedite dequeue for isochronous URBs.
  805. * Just wait until they complete normally or their
  806. * time slot expires.
  807. */
  808. } else {
  809. qh = (struct ehci_qh *) urb->hcpriv;
  810. qh->unlink_reason |= QH_UNLINK_REQUESTED;
  811. switch (qh->qh_state) {
  812. case QH_STATE_LINKED:
  813. if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)
  814. start_unlink_intr(ehci, qh);
  815. else
  816. start_unlink_async(ehci, qh);
  817. break;
  818. case QH_STATE_COMPLETING:
  819. qh->dequeue_during_giveback = 1;
  820. break;
  821. case QH_STATE_UNLINK:
  822. case QH_STATE_UNLINK_WAIT:
  823. /* already started */
  824. break;
  825. case QH_STATE_IDLE:
  826. /* QH might be waiting for a Clear-TT-Buffer */
  827. qh_completions(ehci, qh);
  828. break;
  829. }
  830. }
  831. done:
  832. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  833. return rc;
  834. // return 0;
  835. }
  836. /*-------------------------------------------------------------------------*/
  837. // bulk qh holds the data toggle
  838. //ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  839. void ehci_endpoint_disable (struct hc_gen_dev *hcd, struct usb_host_virt_endpoint *ep)
  840. {
  841. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  842. unsigned long flags;
  843. struct ehci_qh *qh;
  844. /* ASSERT: any requests/urbs are being unlinked */
  845. /* ASSERT: nobody can be submitting urbs for this any more */
  846. rescan:
  847. flags = hal_spin_lock_irqsave (&ehci->lock);
  848. qh = ep->hcpriv;
  849. if (!qh)
  850. goto done;
  851. /* endpoints can be iso streams. for now, we don't
  852. * accelerate iso completions ... so spin a while.
  853. */
  854. if (qh->hw == NULL) {
  855. struct ehci_iso_stream *stream = ep->hcpriv;
  856. if (!list_empty(&stream->td_list))
  857. goto idle_timeout;
  858. /* BUG_ON(!list_empty(&stream->free_list)); */
  859. reserve_release_iso_bandwidth(ehci, stream, -1);
  860. hal_free(stream);
  861. goto done;
  862. }
  863. qh->unlink_reason |= QH_UNLINK_REQUESTED;
  864. switch (qh->qh_state) {
  865. case QH_STATE_LINKED:
  866. if (list_empty(&qh->qtd_list))
  867. qh->unlink_reason |= QH_UNLINK_QUEUE_EMPTY;
  868. //else
  869. // WARN_ON(1);
  870. if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_INT)
  871. start_unlink_async(ehci, qh);
  872. else
  873. start_unlink_intr(ehci, qh);
  874. /* FALL THROUGH */
  875. case QH_STATE_COMPLETING: /* already in unlinking */
  876. case QH_STATE_UNLINK: /* wait for hw to finish? */
  877. case QH_STATE_UNLINK_WAIT:
  878. idle_timeout:
  879. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  880. //schedule_timeout_uninterruptible(1);
  881. goto rescan;
  882. case QH_STATE_IDLE: /* fully unlinked */
  883. //if (qh->clearing_tt)
  884. // goto idle_timeout;
  885. if (list_empty (&qh->qtd_list)) {
  886. if (qh->ps.bw_uperiod)
  887. reserve_release_intr_bandwidth(ehci, qh, -1);
  888. qh_destroy(ehci, qh);
  889. break;
  890. }
  891. break;
  892. /* else FALL THROUGH */
  893. default:
  894. /* caller was supposed to have unlinked any requests;
  895. * that's not our job. just leak this memory.
  896. */
  897. ehci_err ("qh %p (#%02x) state %d%s\n",
  898. qh, ep->desc.bEndpointAddress, qh->qh_state,
  899. list_empty (&qh->qtd_list) ? "" : "(has tds)");
  900. break;
  901. }
  902. done:
  903. ep->hcpriv = NULL;
  904. hal_spin_unlock_irqrestore (&ehci->lock, flags);
  905. }
  906. static void
  907. ehci_endpoint_reset(struct hc_gen_dev *hcd, struct usb_host_virt_endpoint *ep)
  908. {
  909. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  910. struct ehci_qh *qh;
  911. int eptype = usb_endpoint_type(&ep->desc);
  912. int epnum = usb_endpoint_num(&ep->desc);
  913. int is_out = usb_endpoint_dir_out(&ep->desc);
  914. unsigned long flags;
  915. if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
  916. return;
  917. flags = hal_spin_lock_irqsave(&ehci->lock);
  918. qh = ep->hcpriv;
  919. /* For Bulk and Interrupt endpoints we maintain the toggle state
  920. * in the hardware; the toggle bits in udev aren't used at all.
  921. * When an endpoint is reset by usb_clear_halt() we must reset
  922. * the toggle bit in the QH.
  923. */
  924. if (qh) {
  925. if (!list_empty(&qh->qtd_list)) {
  926. ehci_warn("clear_halt for a busy endpoint\n");
  927. } else {
  928. /* The toggle value in the QH can't be updated
  929. * while the QH is active. Unlink it now;
  930. * re-linking will call qh_refresh().
  931. */
  932. usb_settoggle(qh->ps.udev, epnum, is_out, 0);
  933. qh->unlink_reason |= QH_UNLINK_REQUESTED;
  934. if (eptype == USB_ENDPOINT_XFER_BULK)
  935. start_unlink_async(ehci, qh);
  936. else
  937. start_unlink_intr(ehci, qh);
  938. }
  939. }
  940. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  941. }
  942. int ehci_get_frame (struct hc_gen_dev *hcd)
  943. {
  944. /*struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  945. return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size;
  946. */
  947. ehci_warn("PANIC : hcd_ops_get_frame() not support now");
  948. return 0;
  949. }
  950. /*-------------------------------------------------------------------------*/
  951. /* Device addition and removal */
  952. static void ehci_remove_device(struct hc_gen_dev *hcd, struct usb_host_virt_dev *udev)
  953. {
  954. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  955. //hal_spin_lock(&ehci->lock);
  956. //drop_tt(udev);
  957. //hal_spin_unlock(&ehci->lock);
  958. }
  959. /*-------------------------------------------------------------------------*/
  960. #ifdef CONFIG_PM
  961. /* suspend/resume, section 4.3 */
  962. /* These routines handle the generic parts of controller suspend/resume */
  963. int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  964. {
  965. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  966. if (time_before(jiffies, ehci->next_statechange))
  967. msleep(10);
  968. /*
  969. * Root hub was already suspended. Disable IRQ emission and
  970. * mark HW unaccessible. The PM and USB cores make sure that
  971. * the root hub is either suspended or stopped.
  972. */
  973. ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
  974. spin_lock_irq(&ehci->lock);
  975. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  976. (void) ehci_readl(ehci, &ehci->regs->intr_enable);
  977. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  978. spin_unlock_irq(&ehci->lock);
  979. synchronize_irq(hcd->irq);
  980. /* Check for race with a wakeup request */
  981. if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
  982. ehci_resume(hcd, false);
  983. return -EBUSY;
  984. }
  985. return 0;
  986. }
  987. EXPORT_SYMBOL_GPL(ehci_suspend);
  988. /* Returns 0 if power was preserved, 1 if power was lost */
  989. int ehci_resume(struct usb_hcd *hcd, bool force_reset)
  990. {
  991. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  992. if (time_before(jiffies, ehci->next_statechange))
  993. msleep(100);
  994. /* Mark hardware accessible again as we are back to full power by now */
  995. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  996. if (ehci->shutdown)
  997. return 0; /* Controller is dead */
  998. /*
  999. * If CF is still set and reset isn't forced
  1000. * then we maintained suspend power.
  1001. * Just undo the effect of ehci_suspend().
  1002. */
  1003. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
  1004. !force_reset) {
  1005. int mask = INTR_MASK;
  1006. ehci_prepare_ports_for_controller_resume(ehci);
  1007. spin_lock_irq(&ehci->lock);
  1008. if (ehci->shutdown)
  1009. goto skip;
  1010. if (!hcd->self.root_hub->do_remote_wakeup)
  1011. mask &= ~STS_PCD;
  1012. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  1013. ehci_readl(ehci, &ehci->regs->intr_enable);
  1014. skip:
  1015. spin_unlock_irq(&ehci->lock);
  1016. return 0;
  1017. }
  1018. /*
  1019. * Else reset, to cope with power loss or resume from hibernation
  1020. * having let the firmware kick in during reboot.
  1021. */
  1022. usb_root_hub_lost_power(hcd->self.root_hub);
  1023. (void) ehci_halt(ehci);
  1024. (void) ehci_reset(ehci);
  1025. spin_lock_irq(&ehci->lock);
  1026. if (ehci->shutdown)
  1027. goto skip;
  1028. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  1029. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  1030. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  1031. ehci->rh_state = EHCI_RH_SUSPENDED;
  1032. spin_unlock_irq(&ehci->lock);
  1033. return 1;
  1034. }
  1035. EXPORT_SYMBOL_GPL(ehci_resume);
  1036. #endif
  1037. /*-------------------------------------------------------------------------*/
  1038. //void ehci_init_driver(struct hc_driver *drv,
  1039. // const struct ehci_driver_overrides *over)
  1040. //{
  1041. // /* Copy the generic table to drv and then apply the overrides */
  1042. // *drv = ehci_hc_driver;
  1043. //
  1044. // if (over) {
  1045. // drv->hcd_priv_size += over->extra_priv_size;
  1046. // if (over->reset)
  1047. // drv->reset = over->reset;
  1048. // if (over->port_power)
  1049. // drv->port_power = over->port_power;
  1050. // }
  1051. //}
  1052. //EXPORT_SYMBOL_GPL(ehci_init_driver);
  1053. //
  1054. ///*-------------------------------------------------------------------------*/
  1055. //
  1056. //MODULE_DESCRIPTION(DRIVER_DESC);
  1057. //MODULE_AUTHOR (DRIVER_AUTHOR);
  1058. //MODULE_LICENSE ("GPL");
  1059. //static int ehci_hcd_init(void)
  1060. //{
  1061. // int retval = 0;
  1062. //
  1063. // if (usb_disabled())
  1064. // return -ENODEV;
  1065. //
  1066. // printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  1067. // set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1068. // if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
  1069. // test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
  1070. // printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
  1071. // " before uhci_hcd and ohci_hcd, not after\n");
  1072. //
  1073. // pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  1074. // hcd_name,
  1075. // sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  1076. // sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  1077. //
  1078. //#ifdef CONFIG_DYNAMIC_DEBUG
  1079. // ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
  1080. // if (!ehci_debug_root) {
  1081. // retval = -ENOENT;
  1082. // goto err_debug;
  1083. // }
  1084. //#endif
  1085. //
  1086. //#ifdef PLATFORM_DRIVER
  1087. // retval = platform_driver_register(&PLATFORM_DRIVER);
  1088. // if (retval < 0)
  1089. // goto clean0;
  1090. //#endif
  1091. //
  1092. //#ifdef PS3_SYSTEM_BUS_DRIVER
  1093. // retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1094. // if (retval < 0)
  1095. // goto clean2;
  1096. //#endif
  1097. //
  1098. //#ifdef OF_PLATFORM_DRIVER
  1099. // retval = platform_driver_register(&OF_PLATFORM_DRIVER);
  1100. // if (retval < 0)
  1101. // goto clean3;
  1102. //#endif
  1103. //
  1104. //#ifdef XILINX_OF_PLATFORM_DRIVER
  1105. // retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
  1106. // if (retval < 0)
  1107. // goto clean4;
  1108. //#endif
  1109. // return retval;
  1110. //
  1111. //#ifdef XILINX_OF_PLATFORM_DRIVER
  1112. // /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
  1113. //clean4:
  1114. //#endif
  1115. //#ifdef OF_PLATFORM_DRIVER
  1116. // platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1117. //clean3:
  1118. //#endif
  1119. //#ifdef PS3_SYSTEM_BUS_DRIVER
  1120. // ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1121. //clean2:
  1122. //#endif
  1123. //#ifdef PLATFORM_DRIVER
  1124. // platform_driver_unregister(&PLATFORM_DRIVER);
  1125. //clean0:
  1126. //#endif
  1127. //#ifdef CONFIG_DYNAMIC_DEBUG
  1128. // debugfs_remove(ehci_debug_root);
  1129. // ehci_debug_root = NULL;
  1130. //err_debug:
  1131. //#endif
  1132. // clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1133. // return retval;
  1134. //}
  1135. //module_init(ehci_hcd_init);
  1136. //static void ehci_hcd_cleanup(void)
  1137. //{
  1138. //#ifdef XILINX_OF_PLATFORM_DRIVER
  1139. // platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
  1140. //#endif
  1141. //#ifdef OF_PLATFORM_DRIVER
  1142. // platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1143. //#endif
  1144. //#ifdef PLATFORM_DRIVER
  1145. // platform_driver_unregister(&PLATFORM_DRIVER);
  1146. //#endif
  1147. //#ifdef PS3_SYSTEM_BUS_DRIVER
  1148. // ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1149. //#endif
  1150. //#ifdef CONFIG_DYNAMIC_DEBUG
  1151. // debugfs_remove(ehci_debug_root);
  1152. //#endif
  1153. // clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  1154. //}
  1155. //module_exit(ehci_hcd_cleanup);