ehci-hub.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. /*
  2. * Copyright (C) 2001-2004 by David Brownell
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /* this file is part of ehci-hcd.c */
  19. /*-------------------------------------------------------------------------*/
  20. /*
  21. * EHCI Root Hub ... the nonsharable stuff
  22. *
  23. * Registers don't need cpu_to_le32, that happens transparently
  24. */
  25. /*-------------------------------------------------------------------------*/
  26. //#include <linux/usb/otg.h>
  27. #include <usb_host_hub.h>
  28. #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
  29. static void unlink_empty_async_suspended(struct ehci_hcd *ehci);
  30. //static int persist_enabled_on_companion(struct usb_device *udev, void *unused)
  31. //{
  32. // return !udev->maxchild && udev->persist_enabled &&
  33. // udev->bus->root_hub->speed < USB_SPEED_HIGH;
  34. //}
  35. //
  36. ///* After a power loss, ports that were owned by the companion must be
  37. // * reset so that the companion can still own them.
  38. // */
  39. //static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
  40. //{
  41. // u32 __iomem *reg;
  42. // u32 status;
  43. // int port;
  44. // __le32 buf;
  45. // struct hc_gen_hcd * *hcd = ehci_to_hcd(ehci);
  46. //
  47. // if (!ehci->owned_ports)
  48. // return;
  49. //
  50. // /*
  51. // * USB 1.1 devices are mostly HIDs, which don't need to persist across
  52. // * suspends. If we ensure that none of our companion's devices have
  53. // * persist_enabled (by looking through all USB 1.1 buses in the system),
  54. // * we can skip this and avoid slowing resume down. Devices without
  55. // * persist will just get reenumerated shortly after resume anyway.
  56. // */
  57. // if (!usb_for_each_dev(NULL, persist_enabled_on_companion))
  58. // return;
  59. //
  60. // /* Make sure the ports are powered */
  61. // port = HCS_N_PORTS(ehci->hcs_params);
  62. // while (port--) {
  63. // if (usb_test_bit(port, &ehci->owned_ports)) {
  64. // reg = &ehci->regs->port_status[port];
  65. // status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
  66. // if (!(status & PORT_POWER))
  67. // ehci_port_power(ehci, port, true);
  68. // }
  69. // }
  70. //
  71. // /* Give the connections some time to appear */
  72. // hal_msleep(20);
  73. //
  74. // spin_lock_irq(&ehci->lock);
  75. // port = HCS_N_PORTS(ehci->hcs_params);
  76. // while (port--) {
  77. // if (usb_test_bit(port, &ehci->owned_ports)) {
  78. // reg = &ehci->regs->port_status[port];
  79. // status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
  80. //
  81. // /* Port already owned by companion? */
  82. // if (status & PORT_OWNER)
  83. // usb_clear_bit(port, &ehci->owned_ports);
  84. // else if (usb_test_bit(port, &ehci->companion_ports))
  85. // ehci_writel(ehci, status & ~PORT_PE, reg);
  86. // else {
  87. // spin_unlock_irq(&ehci->lock);
  88. // ehci_hub_control(hcd, SetPortFeature,
  89. // USB_PORT_FEAT_RESET, port + 1,
  90. // NULL, 0);
  91. // spin_lock_irq(&ehci->lock);
  92. // }
  93. // }
  94. // }
  95. // spin_unlock_irq(&ehci->lock);
  96. //
  97. // if (!ehci->owned_ports)
  98. // return;
  99. // hal_msleep(90); /* Wait for resets to complete */
  100. //
  101. // spin_lock_irq(&ehci->lock);
  102. // port = HCS_N_PORTS(ehci->hcs_params);
  103. // while (port--) {
  104. // if (usb_test_bit(port, &ehci->owned_ports)) {
  105. // spin_unlock_irq(&ehci->lock);
  106. // ehci_hub_control(hcd, GetPortStatus,
  107. // 0, port + 1,
  108. // (char *) &buf, sizeof(buf));
  109. // spin_lock_irq(&ehci->lock);
  110. //
  111. // /* The companion should now own the port,
  112. // * but if something went wrong the port must not
  113. // * remain enabled.
  114. // */
  115. // reg = &ehci->regs->port_status[port];
  116. // status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
  117. // if (status & PORT_OWNER)
  118. // ehci_writel(ehci, status | PORT_CSC, reg);
  119. // else {
  120. // ehci_dbg("failed handover port %d: %x\n",
  121. // port + 1, status);
  122. // ehci_writel(ehci, status & ~PORT_PE, reg);
  123. // }
  124. // }
  125. // }
  126. //
  127. // ehci->owned_ports = 0;
  128. // spin_unlock_irq(&ehci->lock);
  129. //}
  130. //static int ehci_port_change(struct ehci_hcd *ehci)
  131. //{
  132. // int i = HCS_N_PORTS(ehci->hcs_params);
  133. //
  134. // /* First check if the controller indicates a change event */
  135. //
  136. // if (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)
  137. // return 1;
  138. //
  139. // /*
  140. // * Not all controllers appear to update this while going from D3 to D0,
  141. // * so check the individual port status registers as well
  142. // */
  143. //
  144. // while (i--)
  145. // if (ehci_readl(ehci, &ehci->regs->port_status[i]) & PORT_CSC)
  146. // return 1;
  147. //
  148. // return 0;
  149. //}
  150. //void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
  151. // bool suspending, bool do_wakeup)
  152. //{
  153. // int port;
  154. // u32 temp;
  155. //
  156. // /* If remote wakeup is enabled for the root hub but disabled
  157. // * for the controller, we must adjust all the port wakeup flags
  158. // * when the controller is suspended or resumed. In all other
  159. // * cases they don't need to be changed.
  160. // */
  161. // if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
  162. // return;
  163. //
  164. // spin_lock_irq(&ehci->lock);
  165. //
  166. // /* clear phy low-power mode before changing wakeup flags */
  167. // if (ehci->has_tdi_phy_lpm) {
  168. // port = HCS_N_PORTS(ehci->hcs_params);
  169. // while (port--) {
  170. // u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
  171. //
  172. // temp = ehci_readl(ehci, hostpc_reg);
  173. // ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
  174. // }
  175. // spin_unlock_irq(&ehci->lock);
  176. // hal_msleep(5);
  177. // spin_lock_irq(&ehci->lock);
  178. // }
  179. //
  180. // port = HCS_N_PORTS(ehci->hcs_params);
  181. // while (port--) {
  182. // u32 __iomem *reg = &ehci->regs->port_status[port];
  183. // u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
  184. // u32 t2 = t1 & ~PORT_WAKE_BITS;
  185. //
  186. // /* If we are suspending the controller, clear the flags.
  187. // * If we are resuming the controller, set the wakeup flags.
  188. // */
  189. // if (!suspending) {
  190. // if (t1 & PORT_CONNECT)
  191. // t2 |= PORT_WKOC_E | PORT_WKDISC_E;
  192. // else
  193. // t2 |= PORT_WKOC_E | PORT_WKCONN_E;
  194. // }
  195. // ehci_writel(ehci, t2, reg);
  196. // }
  197. //
  198. // /* enter phy low-power mode again */
  199. // if (ehci->has_tdi_phy_lpm) {
  200. // port = HCS_N_PORTS(ehci->hcs_params);
  201. // while (port--) {
  202. // u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
  203. //
  204. // temp = ehci_readl(ehci, hostpc_reg);
  205. // ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
  206. // }
  207. // }
  208. //
  209. // /* Does the root hub have a port wakeup pending? */
  210. // if (!suspending && ehci_port_change(ehci))
  211. // usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
  212. //
  213. // spin_unlock_irq(&ehci->lock);
  214. //}
  215. //EXPORT_SYMBOL_GPL(ehci_adjust_port_wakeup_flags);
  216. int ehci_bus_suspend (struct hc_gen_dev *hcd)
  217. {
  218. __inf("ERR: Not support suspend.\n");
  219. return 0;
  220. }
  221. int ehci_bus_resume (struct hc_gen_dev *hcd)
  222. {
  223. __inf("ERR: Not support resume.\n");
  224. return 0;
  225. }
  226. //static int ehci_bus_suspend (struct hc_gen_hcd **hcd)
  227. //{
  228. // struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  229. // int port;
  230. // int mask;
  231. // int changed;
  232. // bool fs_idle_delay;
  233. //
  234. // ehci_dbg("suspend root hub\n");
  235. //
  236. // if (time_before (jiffies, ehci->next_statechange))
  237. // hal_msleep(5);
  238. //
  239. // /* stop the schedules */
  240. // ehci_quiesce(ehci);
  241. //
  242. // spin_lock_irq (&ehci->lock);
  243. // if (ehci->rh_state < EHCI_RH_RUNNING)
  244. // goto done;
  245. //
  246. // /* Once the controller is stopped, port resumes that are already
  247. // * in progress won't complete. Hence if remote wakeup is enabled
  248. // * for the root hub and any ports are in the middle of a resume or
  249. // * remote wakeup, we must fail the suspend.
  250. // */
  251. // if (hcd->self.root_hub->do_remote_wakeup) {
  252. // if (ehci->resuming_ports) {
  253. // spin_unlock_irq(&ehci->lock);
  254. // ehci_dbg("suspend failed because a port is resuming\n");
  255. // return -EBUSY;
  256. // }
  257. // }
  258. //
  259. // /* Unlike other USB host controller types, EHCI doesn't have
  260. // * any notion of "global" or bus-wide suspend. The driver has
  261. // * to manually suspend all the active unsuspended ports, and
  262. // * then manually resume them in the bus_resume() routine.
  263. // */
  264. // ehci->bus_suspended = 0;
  265. // ehci->owned_ports = 0;
  266. // changed = 0;
  267. // fs_idle_delay = false;
  268. // port = HCS_N_PORTS(ehci->hcs_params);
  269. // while (port--) {
  270. // u32 __iomem *reg = &ehci->regs->port_status [port];
  271. // u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
  272. // u32 t2 = t1 & ~PORT_WAKE_BITS;
  273. //
  274. // /* keep track of which ports we suspend */
  275. // if (t1 & PORT_OWNER)
  276. // usb_set_bit(port, &ehci->owned_ports);
  277. // else if ((t1 & PORT_PE) && !(t1 & PORT_SUSPEND)) {
  278. // t2 |= PORT_SUSPEND;
  279. // usb_set_bit(port, &ehci->bus_suspended);
  280. // }
  281. //
  282. // /* enable remote wakeup on all ports, if told to do so */
  283. // if (hcd->self.root_hub->do_remote_wakeup) {
  284. // /* only enable appropriate wake bits, otherwise the
  285. // * hardware can not go phy low power mode. If a race
  286. // * condition happens here(connection change during bits
  287. // * set), the port change detection will finally fix it.
  288. // */
  289. // if (t1 & PORT_CONNECT)
  290. // t2 |= PORT_WKOC_E | PORT_WKDISC_E;
  291. // else
  292. // t2 |= PORT_WKOC_E | PORT_WKCONN_E;
  293. // }
  294. //
  295. // if (t1 != t2) {
  296. // /*
  297. // * On some controllers, Wake-On-Disconnect will
  298. // * generate false wakeup signals until the bus
  299. // * switches over to full-speed idle. For their
  300. // * sake, add a delay if we need one.
  301. // */
  302. // if ((t2 & PORT_WKDISC_E) &&
  303. // ehci_port_speed(ehci, t2) ==
  304. // USB_PORT_STAT_HIGH_SPEED)
  305. // fs_idle_delay = true;
  306. // ehci_writel(ehci, t2, reg);
  307. // changed = 1;
  308. // }
  309. // }
  310. // spin_unlock_irq(&ehci->lock);
  311. //
  312. // if ((changed && ehci->has_tdi_phy_lpm) || fs_idle_delay) {
  313. // /*
  314. // * Wait for HCD to enter low-power mode or for the bus
  315. // * to switch to full-speed idle.
  316. // */
  317. // usleep_range(5000, 5500);
  318. // }
  319. //
  320. // if (changed && ehci->has_tdi_phy_lpm) {
  321. // spin_lock_irq(&ehci->lock);
  322. // port = HCS_N_PORTS(ehci->hcs_params);
  323. // while (port--) {
  324. // u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
  325. // u32 t3;
  326. //
  327. // t3 = ehci_readl(ehci, hostpc_reg);
  328. // ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
  329. // t3 = ehci_readl(ehci, hostpc_reg);
  330. // ehci_dbg("Port %d phy low-power mode %s\n",
  331. // port, (t3 & HOSTPC_PHCD) ?
  332. // "succeeded" : "failed");
  333. // }
  334. // spin_unlock_irq(&ehci->lock);
  335. // }
  336. //
  337. // /* Apparently some devices need a >= 1-uframe delay here */
  338. // if (ehci->bus_suspended)
  339. // udelay(150);
  340. //
  341. // /* turn off now-idle HC */
  342. // ehci_halt (ehci);
  343. //
  344. // spin_lock_irq(&ehci->lock);
  345. // if (ehci->enabled_hrtimer_events & BIT(EHCI_HRTIMER_POLL_DEAD))
  346. // ehci_handle_controller_death(ehci);
  347. // if (ehci->rh_state != EHCI_RH_RUNNING)
  348. // goto done;
  349. // ehci->rh_state = EHCI_RH_SUSPENDED;
  350. //
  351. // unlink_empty_async_suspended(ehci);
  352. //
  353. // /* Any IAA cycle that started before the suspend is now invalid */
  354. // end_iaa_cycle(ehci);
  355. // ehci_handle_start_intr_unlinks(ehci);
  356. // ehci_handle_intr_unlinks(ehci);
  357. // end_free_itds(ehci);
  358. //
  359. // /* allow remote wakeup */
  360. // mask = INTR_MASK;
  361. // if (!hcd->self.root_hub->do_remote_wakeup)
  362. // mask &= ~STS_PCD;
  363. // ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  364. // ehci_readl(ehci, &ehci->regs->intr_enable);
  365. //
  366. // done:
  367. // ehci->next_statechange = jiffies + msecs_to_jiffies(10);
  368. // ehci->enabled_hrtimer_events = 0;
  369. // ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
  370. // spin_unlock_irq (&ehci->lock);
  371. //
  372. // hrtimer_cancel(&ehci->hrtimer);
  373. // return 0;
  374. //}
  375. /* caller has locked the root hub, and should reset/reinit on error */
  376. //static int ehci_bus_resume (struct hc_gen_hcd **hcd)
  377. //{
  378. // struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  379. // u32 temp;
  380. // u32 power_okay;
  381. // int i;
  382. // unsigned long resume_needed = 0;
  383. //
  384. // if (time_before (jiffies, ehci->next_statechange))
  385. // hal_msleep(5);
  386. // spin_lock_irq (&ehci->lock);
  387. // if (!HCD_HW_ACCESSIBLE(hcd) || ehci->shutdown)
  388. // goto shutdown;
  389. //
  390. // if (unlikely(ehci->debug)) {
  391. // if (!dbgp_reset_prep(hcd))
  392. // ehci->debug = NULL;
  393. // else
  394. // dbgp_external_startup(hcd);
  395. // }
  396. //
  397. // /* Ideally and we've got a real resume here, and no port's power
  398. // * was lost. (For PCI, that means Vaux was maintained.) But we
  399. // * could instead be restoring a swsusp snapshot -- so that BIOS was
  400. // * the last user of the controller, not reset/pm hardware keeping
  401. // * state we gave to it.
  402. // */
  403. // power_okay = ehci_readl(ehci, &ehci->regs->intr_enable);
  404. // ehci_dbg("resume root hub%s\n",
  405. // power_okay ? "" : " after power loss");
  406. //
  407. // /* at least some APM implementations will try to deliver
  408. // * IRQs right away, so delay them until we're ready.
  409. // */
  410. // ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  411. //
  412. // /* re-init operational registers */
  413. // ehci_writel(ehci, 0, &ehci->regs->segment);
  414. // ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  415. // ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
  416. //
  417. // /* restore CMD_RUN, framelist size, and irq threshold */
  418. // ehci->command |= CMD_RUN;
  419. // ehci_writel(ehci, ehci->command, &ehci->regs->command);
  420. // ehci->rh_state = EHCI_RH_RUNNING;
  421. //
  422. // /*
  423. // * According to Bugzilla #8190, the port status for some controllers
  424. // * will be wrong without a delay. At their wrong status, the port
  425. // * is enabled, but not suspended neither resumed.
  426. // */
  427. // i = HCS_N_PORTS(ehci->hcs_params);
  428. // while (i--) {
  429. // temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
  430. // if ((temp & PORT_PE) &&
  431. // !(temp & (PORT_SUSPEND | PORT_RESUME))) {
  432. // ehci_dbg("Port status(0x%x) is wrong\n", temp);
  433. // spin_unlock_irq(&ehci->lock);
  434. // hal_msleep(8);
  435. // spin_lock_irq(&ehci->lock);
  436. // break;
  437. // }
  438. // }
  439. //
  440. // if (ehci->shutdown)
  441. // goto shutdown;
  442. //
  443. // /* clear phy low-power mode before resume */
  444. // if (ehci->bus_suspended && ehci->has_tdi_phy_lpm) {
  445. // i = HCS_N_PORTS(ehci->hcs_params);
  446. // while (i--) {
  447. // if (usb_test_bit(i, &ehci->bus_suspended)) {
  448. // u32 __iomem *hostpc_reg =
  449. // &ehci->regs->hostpc[i];
  450. //
  451. // temp = ehci_readl(ehci, hostpc_reg);
  452. // ehci_writel(ehci, temp & ~HOSTPC_PHCD,
  453. // hostpc_reg);
  454. // }
  455. // }
  456. // spin_unlock_irq(&ehci->lock);
  457. // hal_msleep(5);
  458. // spin_lock_irq(&ehci->lock);
  459. // if (ehci->shutdown)
  460. // goto shutdown;
  461. // }
  462. //
  463. // /* manually resume the ports we suspended during bus_suspend() */
  464. // i = HCS_N_PORTS (ehci->hcs_params);
  465. // while (i--) {
  466. // temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
  467. // temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
  468. // if (usb_test_bit(i, &ehci->bus_suspended) &&
  469. // (temp & PORT_SUSPEND)) {
  470. // temp |= PORT_RESUME;
  471. // usb_set_bit(i, &resume_needed);
  472. // }
  473. // ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
  474. // }
  475. //
  476. // /*
  477. // * hal_msleep for USB_RESUME_TIMEOUT ms only if code is trying to resume
  478. // * port
  479. // */
  480. // if (resume_needed) {
  481. // spin_unlock_irq(&ehci->lock);
  482. // hal_msleep(USB_RESUME_TIMEOUT);
  483. // spin_lock_irq(&ehci->lock);
  484. // if (ehci->shutdown)
  485. // goto shutdown;
  486. // }
  487. //
  488. // i = HCS_N_PORTS (ehci->hcs_params);
  489. // while (i--) {
  490. // temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
  491. // if (usb_test_bit(i, &resume_needed)) {
  492. // temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
  493. // ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
  494. // }
  495. // }
  496. //
  497. // ehci->next_statechange = jiffies + msecs_to_jiffies(5);
  498. // spin_unlock_irq(&ehci->lock);
  499. //
  500. // ehci_handover_companion_ports(ehci);
  501. //
  502. // /* Now we can safely re-enable irqs */
  503. // spin_lock_irq(&ehci->lock);
  504. // if (ehci->shutdown)
  505. // goto shutdown;
  506. // ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
  507. // (void) ehci_readl(ehci, &ehci->regs->intr_enable);
  508. // spin_unlock_irq(&ehci->lock);
  509. //
  510. // return 0;
  511. //
  512. // shutdown:
  513. // spin_unlock_irq(&ehci->lock);
  514. // return -ESHUTDOWN;
  515. //}
  516. //
  517. //#else
  518. //
  519. //#define ehci_bus_suspend NULL
  520. //#define ehci_bus_resume NULL
  521. //
  522. //#endif /* CONFIG_PM */
  523. /*-------------------------------------------------------------------------*/
  524. /*
  525. * Sets the owner of a port
  526. */
  527. static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
  528. {
  529. //u32 __iomem *status_reg;
  530. u32 port_status;
  531. int try;
  532. //status_reg = &ehci->regs->port_status[portnum];
  533. /*
  534. * The controller won't set the OWNER bit if the port is
  535. * enabled, so this loop will sometimes require at least two
  536. * iterations: one to disable the port and one to set OWNER.
  537. */
  538. for (try = 4; try > 0; --try) {
  539. hal_spin_lock(&ehci->lock);
  540. port_status = ehci_readl(ehci,
  541. &ehci->regs->port_status[portnum]);
  542. if ((port_status & PORT_OWNER) == new_owner
  543. || (port_status & (PORT_OWNER | PORT_CONNECT))
  544. == 0)
  545. try = 0;
  546. else {
  547. port_status ^= PORT_OWNER;
  548. port_status &= ~(PORT_PE | PORT_RWC_BITS);
  549. ehci_writel(ehci, port_status,
  550. &ehci->regs->port_status[portnum]);
  551. }
  552. hal_spin_unlock(&ehci->lock);
  553. if (try > 1)
  554. hal_msleep(5);
  555. }
  556. }
  557. /*-------------------------------------------------------------------------*/
  558. static int check_reset_complete (
  559. struct ehci_hcd *ehci,
  560. int index,
  561. u32 *status_reg,
  562. int port_status
  563. ) {
  564. if (!(port_status & PORT_CONNECT))
  565. return port_status;
  566. /* if reset finished and it's still not enabled -- handoff */
  567. if (!(port_status & PORT_PE)) {
  568. /* with integrated TT, there's nobody to hand it to! */
  569. //if (ehci_is_TDI(ehci)) {
  570. // ehci_dbg("Failed to enable port %d on root hub TT\n",
  571. // index+1);
  572. // return port_status;
  573. //}
  574. ehci_dbg("port %d full speed --> companion\n",
  575. index + 1);
  576. // what happens if HCS_N_CC(params) == 0 ?
  577. port_status |= PORT_OWNER;
  578. port_status &= ~PORT_RWC_BITS;
  579. ehci_writel(ehci, port_status, status_reg);
  580. /* ensure 440EPX ohci controller state is operational */
  581. if (ehci->has_amcc_usb23)
  582. set_ohci_hcfs(ehci, 1);
  583. } else {
  584. ehci_dbg("port %d reset complete, port enabled\n",
  585. index + 1);
  586. /* ensure 440EPx ohci controller state is suspended */
  587. if (ehci->has_amcc_usb23)
  588. set_ohci_hcfs(ehci, 0);
  589. }
  590. return port_status;
  591. }
  592. /*-------------------------------------------------------------------------*/
  593. /* build "status change" packet (one or two bytes) from HC registers */
  594. int ehci_hub_status_data (struct hc_gen_dev *hcd, char *buf)
  595. {
  596. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  597. u32 temp, status;
  598. u32 mask;
  599. int ports, i, retval = 1;
  600. unsigned long flags;
  601. u32 ppcd = ~0;
  602. /* init status to no-changes */
  603. buf [0] = 0;
  604. ports = HCS_N_PORTS (ehci->hcs_params);
  605. if (ports > 7) {
  606. buf [1] = 0;
  607. retval++;
  608. }
  609. /* Inform the core about resumes-in-progress by returning
  610. * a non-zero value even if there are no status changes.
  611. */
  612. status = ehci->resuming_ports;
  613. /* Some boards (mostly VIA?) report bogus overcurrent indications,
  614. * causing massive log spam unless we completely ignore them. It
  615. * may be relevant that VIA VT8235 controllers, where PORT_POWER is
  616. * always set, seem to clear PORT_OCC and PORT_CSC when writing to
  617. * PORT_POWER; that's surprising, but maybe within-spec.
  618. */
  619. //if (!ignore_oc)
  620. // mask = PORT_CSC | PORT_PEC | PORT_OCC;
  621. //else
  622. mask = PORT_CSC | PORT_PEC;
  623. // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
  624. /* no hub change reports (bit 0) for now (power, ...) */
  625. /* port N changes (bit N)? */
  626. flags = hal_spin_lock_irqsave(&ehci->lock);
  627. /* get per-port change detect bits */
  628. if (ehci->has_ppcd)
  629. ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16;
  630. for (i = 0; i < ports; i++) {
  631. /* leverage per-port change bits feature */
  632. if (ppcd & (1 << i))
  633. temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
  634. else
  635. temp = 0;
  636. /*
  637. * Return status information even for ports with OWNER set.
  638. * Otherwise hub_wq wouldn't see the disconnect event when a
  639. * high-speed device is switched over to the companion
  640. * controller by the user.
  641. */
  642. if ((temp & mask) != 0 || usb_test_bit(i, (volatile uint32_t *)&ehci->port_c_suspend)) {
  643. //|| (ehci->reset_done[i] && time_after_eq(
  644. // jiffies, ehci->reset_done[i]))) {
  645. if (i < 7)
  646. buf [0] |= 1 << (i + 1);
  647. else
  648. buf [1] |= 1 << (i - 7);
  649. status = STS_PCD;
  650. }
  651. }
  652. /* If a resume is in progress, make sure it can finish */
  653. /*
  654. if (ehci->resuming_ports)
  655. mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(25));
  656. */
  657. hal_spin_unlock_irqrestore (&ehci->lock, flags);
  658. return status ? retval : 0;
  659. }
  660. /*-------------------------------------------------------------------------*/
  661. static void
  662. ehci_hub_descriptor (
  663. struct ehci_hcd *ehci,
  664. struct usb_hub_descriptor *desc
  665. ) {
  666. int ports = HCS_N_PORTS (ehci->hcs_params);
  667. u16 temp;
  668. desc->bDescriptorType = USB_DT_HUB;
  669. desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */
  670. desc->bHubContrCurrent = 0;
  671. desc->bNbrPorts = ports;
  672. temp = 1 + (ports / 8);
  673. desc->bDescLength = 7 + 2 * temp;
  674. /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
  675. memset(&desc->DeviceRemovable[0], 0, temp);
  676. memset(&desc->DeviceRemovable[temp], 0xff, temp);
  677. //temp = HUB_CHAR_INDV_PORT_OCPM; /* per-port overcurrent reporting */
  678. //if (HCS_PPC (ehci->hcs_params))
  679. // temp |= HUB_CHAR_INDV_PORT_LPSM; /* per-port power control */
  680. //else
  681. // temp |= HUB_CHAR_NO_LPSM; /* no power switching */
  682. #if 0
  683. // re-enable when we support USB_PORT_FEAT_INDICATOR below.
  684. if (HCS_INDICATOR (ehci->hcs_params))
  685. temp |= HUB_CHAR_PORTIND; /* per-port indicators (LEDs) */
  686. #endif
  687. desc->wHubCharacteristics = cpu_to_le16(temp);
  688. }
  689. /*-------------------------------------------------------------------------*/
  690. int ehci_hub_control(
  691. struct hc_gen_dev *hcd,
  692. u16 typeReq,
  693. u16 wValue,
  694. u16 wIndex,
  695. char *buf,
  696. u16 wLength
  697. ) {
  698. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  699. int ports = HCS_N_PORTS (ehci->hcs_params);
  700. u32 *status_reg, *hostpc_reg;
  701. u32 temp, temp1, status;
  702. uint32_t flags;
  703. int retval = 0;
  704. unsigned selector;
  705. /*
  706. * Avoid underflow while calculating (wIndex & 0xff) - 1.
  707. * The compiler might deduce that wIndex can never be 0 and then
  708. * optimize away the tests for !wIndex below.
  709. */
  710. temp = wIndex & 0xff;
  711. temp -= (temp > 0);
  712. status_reg = &ehci->regs->port_status[temp];
  713. hostpc_reg = &ehci->regs->hostpc[temp];
  714. //printf("[%s %d] typeReq = 0x%x, wValue = 0x%x, wIndex = 0x%x, wLength = 0x%x, status_reg = 0x%lx\n", __func__, __LINE__,
  715. // typeReq, wValue, wIndex, wLength, ehci_readl(ehci, status_reg));
  716. /*
  717. * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
  718. * HCS_INDICATOR may say we can change LEDs to off/amber/green.
  719. * (track current state ourselves) ... blink for diagnostics,
  720. * power, "this is the one", etc. EHCI spec supports this.
  721. */
  722. flags = hal_spin_lock_irqsave(&ehci->lock);
  723. switch (typeReq) {
  724. case ClearHubFeature:
  725. switch (wValue) {
  726. case C_HUB_LOCAL_POWER:
  727. case C_HUB_OVER_CURRENT:
  728. /* no hub-wide feature/status flags */
  729. break;
  730. default:
  731. goto error;
  732. }
  733. break;
  734. case ClearPortFeature:
  735. if (!wIndex || wIndex > ports)
  736. goto error;
  737. wIndex--;
  738. temp = ehci_readl(ehci, status_reg);
  739. temp &= ~PORT_RWC_BITS;
  740. /*
  741. * Even if OWNER is set, so the port is owned by the
  742. * companion controller, hub_wq needs to be able to clear
  743. * the port-change status bits (especially
  744. * USB_PORT_STAT_C_CONNECTION).
  745. */
  746. switch (wValue) {
  747. case USB_PORT_FEAT_ENABLE:
  748. ehci_writel(ehci, temp & ~PORT_PE, status_reg);
  749. break;
  750. case USB_PORT_FEAT_C_ENABLE:
  751. ehci_writel(ehci, temp | PORT_PEC, status_reg);
  752. break;
  753. case USB_PORT_FEAT_SUSPEND:
  754. if (temp & PORT_RESET)
  755. goto error;
  756. if (ehci->no_selective_suspend)
  757. break;
  758. if (!(temp & PORT_SUSPEND))
  759. break;
  760. if ((temp & PORT_PE) == 0)
  761. goto error;
  762. /* clear phy low-power mode before resume */
  763. if (ehci->has_tdi_phy_lpm) {
  764. temp1 = ehci_readl(ehci, hostpc_reg);
  765. ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
  766. hostpc_reg);
  767. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  768. hal_msleep(5);/* wait to leave low-power mode */
  769. flags = hal_spin_lock_irqsave(&ehci->lock);
  770. }
  771. /* resume signaling for 20 msec */
  772. temp &= ~PORT_WAKE_BITS;
  773. ehci_writel(ehci, temp | PORT_RESUME, status_reg);
  774. //ehci->reset_done[wIndex] = jiffies
  775. // + msecs_to_jiffies(USB_RESUME_TIMEOUT);
  776. usb_set_bit(wIndex, (volatile uint32_t *)&ehci->resuming_ports);
  777. usb_hcd_start_port_resume(&hcd->self, wIndex);
  778. break;
  779. case USB_PORT_FEAT_C_SUSPEND:
  780. usb_clear_bit(wIndex, (volatile uint32_t *)&ehci->port_c_suspend);
  781. break;
  782. case USB_PORT_FEAT_POWER:
  783. if (HCS_PPC(ehci->hcs_params)) {
  784. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  785. ehci_port_power(ehci, wIndex, false);
  786. flags = hal_spin_lock_irqsave(&ehci->lock);
  787. }
  788. break;
  789. case USB_PORT_FEAT_C_CONNECTION:
  790. ehci_writel(ehci, temp | PORT_CSC, status_reg);
  791. break;
  792. case USB_PORT_FEAT_C_OVER_CURRENT:
  793. ehci_writel(ehci, temp | PORT_OCC, status_reg);
  794. break;
  795. case USB_PORT_FEAT_C_RESET:
  796. /* GetPortStatus clears reset */
  797. break;
  798. default:
  799. goto error;
  800. }
  801. ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */
  802. break;
  803. case GetHubDescriptor:
  804. ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *)
  805. buf);
  806. break;
  807. case GetHubStatus:
  808. /* no hub-wide feature/status flags */
  809. memset (buf, 0, 4);
  810. //cpu_to_le32s ((u32 *) buf);
  811. break;
  812. case GetPortStatus:
  813. if (!wIndex || wIndex > ports)
  814. goto error;
  815. wIndex--;
  816. status = 0;
  817. temp = ehci_readl(ehci, status_reg);
  818. // wPortChange bits
  819. if (temp & PORT_CSC)
  820. status |= USB_PORT_STAT_C_CONNECTION << 16;
  821. if (temp & PORT_PEC)
  822. status |= USB_PORT_STAT_C_ENABLE << 16;
  823. //if ((temp & PORT_OCC) && !ignore_oc){
  824. // status |= USB_PORT_STAT_C_OVERCURRENT << 16;
  825. // /*
  826. // * Hubs should disable port power on over-current.
  827. // * However, not all EHCI implementations do this
  828. // * automatically, even if they _do_ support per-port
  829. // * power switching; they're allowed to just limit the
  830. // * current. hub_wq will turn the power back on.
  831. // */
  832. // if (((temp & PORT_OC) || (ehci->need_oc_pp_cycle))
  833. // && HCS_PPC(ehci->hcs_params)) {
  834. // spin_unlock_irqrestore(&ehci->lock, flags);
  835. // ehci_port_power(ehci, wIndex, false);
  836. // spin_lock_irqsave(&ehci->lock, flags);
  837. // temp = ehci_readl(ehci, status_reg);
  838. // }
  839. //}
  840. /* no reset or resume pending */
  841. if (!ehci->reset_done[wIndex]) {
  842. /* Remote Wakeup received? */
  843. // if (temp & PORT_RESUME) {
  844. // /* resume signaling for 20 msec */
  845. // ehci->reset_done[wIndex] = jiffies
  846. // + msecs_to_jiffies(20);
  847. // usb_hcd_start_port_resume(&hcd->self, wIndex);
  848. // usb_set_bit(wIndex, &ehci->resuming_ports);
  849. // /* check the port again */
  850. // mod_timer(&ehci_to_hcd(ehci)->rh_timer,
  851. // ehci->reset_done[wIndex]);
  852. // }
  853. /* reset or resume not yet complete */
  854. //} else if (!time_after_eq(jiffies, ehci->reset_done[wIndex])) {
  855. // ; /* wait until it is complete */
  856. /* resume completed */
  857. } else if (usb_test_bit(wIndex, (volatile uint32_t *)&ehci->resuming_ports)) {
  858. // usb_clear_bit(wIndex, &ehci->suspended_ports);
  859. // usb_set_bit(wIndex, &ehci->port_c_suspend);
  860. // ehci->reset_done[wIndex] = 0;
  861. // usb_hcd_end_port_resume(&hcd->self, wIndex);
  862. // /* stop resume signaling */
  863. // temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
  864. // ehci_writel(ehci, temp, status_reg);
  865. // usb_clear_bit(wIndex, &ehci->resuming_ports);
  866. // retval = ehci_handshake(ehci, status_reg,
  867. // PORT_RESUME, 0, 2000 /* 2msec */);
  868. // if (retval != 0) {
  869. // ehci_dbg("port %d resume error %d\n",
  870. // wIndex + 1, retval);
  871. // goto error;
  872. // }
  873. // temp = ehci_readl(ehci, status_reg);
  874. /* whoever resets must GetPortStatus to complete it!! */
  875. } else {
  876. /* FIXME: we need to implement time_after_eq or
  877. * something similar to wait reset complete.
  878. */
  879. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  880. hal_msleep(50);
  881. flags = hal_spin_lock_irqsave(&ehci->lock);
  882. status |= USB_PORT_STAT_C_RESET << 16;
  883. ehci->reset_done [wIndex] = 0;
  884. /* force reset to complete */
  885. ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
  886. status_reg);
  887. /* REVISIT: some hardware needs 550+ usec to clear
  888. * this bit; seems too long to spin routinely...
  889. */
  890. retval = ehci_handshake(ehci, status_reg,
  891. PORT_RESET, 0, 1000);
  892. if (retval != 0) {
  893. ehci_err ("port %d reset error %d\n",
  894. wIndex + 1, retval);
  895. goto error;
  896. }
  897. /* see what we found out */
  898. temp = check_reset_complete (ehci, wIndex, status_reg,
  899. ehci_readl(ehci, status_reg));
  900. }
  901. /* transfer dedicated ports to the companion hc */
  902. if ((temp & PORT_CONNECT) &&
  903. usb_test_bit(wIndex, (volatile uint32_t *)&ehci->companion_ports)) {
  904. temp &= ~PORT_RWC_BITS;
  905. temp |= PORT_OWNER;
  906. ehci_writel(ehci, temp, status_reg);
  907. ehci_dbg("port %d --> companion\n", wIndex + 1);
  908. temp = ehci_readl(ehci, status_reg);
  909. }
  910. /*
  911. * Even if OWNER is set, there's no harm letting hub_wq
  912. * see the wPortStatus values (they should all be 0 except
  913. * for PORT_POWER anyway).
  914. */
  915. if (temp & PORT_CONNECT) {
  916. status |= USB_PORT_STAT_CONNECTION;
  917. // status may be from integrated TT
  918. if (ehci->has_hostpc) {
  919. temp1 = ehci_readl(ehci, hostpc_reg);
  920. //status |= ehci_port_speed(ehci, temp1);
  921. status |= USB_PORT_STAT_HIGH_SPEED;
  922. } else
  923. //status |= ehci_port_speed(ehci, temp);
  924. status |= USB_PORT_STAT_HIGH_SPEED;
  925. }
  926. if (temp & PORT_PE)
  927. status |= USB_PORT_STAT_ENABLE;
  928. /* maybe the port was unsuspended without our knowledge */
  929. //if (temp & (PORT_SUSPEND|PORT_RESUME)) {
  930. // status |= USB_PORT_STAT_SUSPEND;
  931. //} else if (usb_test_bit(wIndex, &ehci->suspended_ports)) {
  932. // usb_clear_bit(wIndex, &ehci->suspended_ports);
  933. // usb_clear_bit(wIndex, &ehci->resuming_ports);
  934. // ehci->reset_done[wIndex] = 0;
  935. // if (temp & PORT_PE)
  936. // usb_set_bit(wIndex, &ehci->port_c_suspend);
  937. // usb_hcd_end_port_resume(&hcd->self, wIndex);
  938. //}
  939. if (temp & PORT_OC)
  940. status |= USB_PORT_STAT_OVERCURRENT;
  941. if (temp & PORT_RESET)
  942. status |= USB_PORT_STAT_RESET;
  943. if (temp & PORT_POWER)
  944. status |= USB_PORT_STAT_POWER;
  945. if (usb_test_bit(wIndex, (volatile uint32_t *)&ehci->port_c_suspend))
  946. status |= USB_PORT_STAT_C_SUSPEND << 16;
  947. //if (status & ~0xffff) /* only if wPortChange is interesting */
  948. //ehci_dbg("GetStatus", wIndex + 1, temp);
  949. //put_unaligned_le32(status, buf);
  950. *(u32 *)buf = status;
  951. break;
  952. case SetHubFeature:
  953. switch (wValue) {
  954. case C_HUB_LOCAL_POWER:
  955. case C_HUB_OVER_CURRENT:
  956. /* no hub-wide feature/status flags */
  957. break;
  958. default:
  959. goto error;
  960. }
  961. break;
  962. case SetPortFeature:
  963. selector = wIndex >> 8;
  964. wIndex &= 0xff;
  965. //if (unlikely(ehci->debug)) {
  966. // /* If the debug port is active any port
  967. // * feature requests should get denied */
  968. // if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) &&
  969. // (readl(&ehci->debug->control) & DBGP_ENABLED)) {
  970. // retval = -ENODEV;
  971. // goto error_exit;
  972. // }
  973. //}
  974. if (!wIndex || wIndex > ports)
  975. goto error;
  976. wIndex--;
  977. temp = ehci_readl(ehci, status_reg);
  978. if (temp & PORT_OWNER)
  979. break;
  980. temp &= ~PORT_RWC_BITS;
  981. switch (wValue) {
  982. case USB_PORT_FEAT_SUSPEND:
  983. if (ehci->no_selective_suspend)
  984. break;
  985. if ((temp & PORT_PE) == 0
  986. || (temp & PORT_RESET) != 0)
  987. goto error;
  988. /* After above check the port must be connected.
  989. * Set appropriate bit thus could put phy into low power
  990. * mode if we have tdi_phy_lpm feature
  991. */
  992. temp &= ~PORT_WKCONN_E;
  993. temp |= PORT_WKDISC_E | PORT_WKOC_E;
  994. ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
  995. if (ehci->has_tdi_phy_lpm) {
  996. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  997. hal_msleep(5);/* 5ms for HCD enter low pwr mode */
  998. flags = hal_spin_lock_irqsave(&ehci->lock);
  999. temp1 = ehci_readl(ehci, hostpc_reg);
  1000. ehci_writel(ehci, temp1 | HOSTPC_PHCD,
  1001. hostpc_reg);
  1002. temp1 = ehci_readl(ehci, hostpc_reg);
  1003. ehci_dbg("Port%d phy low pwr mode %s\n",
  1004. wIndex, (temp1 & HOSTPC_PHCD) ?
  1005. "succeeded" : "failed");
  1006. }
  1007. usb_set_bit(wIndex, (volatile uint32_t *)&ehci->suspended_ports);
  1008. break;
  1009. case USB_PORT_FEAT_POWER:
  1010. //if (HCS_PPC(ehci->hcs_params)) {
  1011. // hal_spin_unlock_irqrestore(flags);
  1012. // ehci_port_power(ehci, wIndex, true);
  1013. // flags = hal_spin_lock_irqsave();
  1014. //}
  1015. break;
  1016. case USB_PORT_FEAT_RESET:
  1017. if (temp & (PORT_SUSPEND|PORT_RESUME))
  1018. goto error;
  1019. /* line status bits may report this as low speed,
  1020. * which can be fine if this root hub has a
  1021. * transaction translator built in.
  1022. */
  1023. if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
  1024. && PORT_USB11 (temp)) {
  1025. ehci_dbg("port %d low speed --> companion\n",
  1026. wIndex + 1);
  1027. temp |= PORT_OWNER;
  1028. } else {
  1029. temp |= PORT_RESET;
  1030. temp &= ~PORT_PE;
  1031. /*
  1032. * caller must wait, then call GetPortStatus
  1033. * usb 2.0 spec says 50 ms resets on root
  1034. */
  1035. ehci->reset_done [wIndex] = 50;
  1036. /*
  1037. * Force full-speed connect for FSL high-speed
  1038. * erratum; disable HS Chirp by setting PFSC bit
  1039. */
  1040. if (ehci_has_fsl_hs_errata(ehci))
  1041. temp |= (1 << PORTSC_FSL_PFSC);
  1042. }
  1043. ehci_writel(ehci, temp, status_reg);
  1044. break;
  1045. /* For downstream facing ports (these): one hub port is put
  1046. * into test mode according to USB2 11.24.2.13, then the hub
  1047. * must be reset (which for root hub now means rmmod+modprobe,
  1048. * or else system reboot). See EHCI 2.3.9 and 4.14 for info
  1049. * about the EHCI-specific stuff.
  1050. */
  1051. case USB_PORT_FEAT_TEST:
  1052. //if (!selector || selector > 5)
  1053. // goto error;
  1054. //hal_spin_unlock_irqrestore(flags);
  1055. //ehci_quiesce(ehci);
  1056. //flags = hal_spin_lock_irqsave();
  1057. ///* Put all enabled ports into suspend */
  1058. //while (ports--) {
  1059. // u32 __iomem *sreg =
  1060. // &ehci->regs->port_status[ports];
  1061. // temp = ehci_readl(ehci, sreg) & ~PORT_RWC_BITS;
  1062. // if (temp & PORT_PE)
  1063. // ehci_writel(ehci, temp | PORT_SUSPEND,
  1064. // sreg);
  1065. //}
  1066. //hal_spin_unlock_irqrestore(flags);
  1067. //ehci_halt(ehci);
  1068. //flags = hal_spin_lock_irqsave();
  1069. //temp = ehci_readl(ehci, status_reg);
  1070. //temp |= selector << 16;
  1071. //ehci_writel(ehci, temp, status_reg);
  1072. break;
  1073. default:
  1074. goto error;
  1075. }
  1076. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  1077. break;
  1078. default:
  1079. error:
  1080. /* "stall" on error */
  1081. retval = -EPIPE;
  1082. }
  1083. error_exit:
  1084. hal_spin_unlock_irqrestore(&ehci->lock, flags);
  1085. return retval;
  1086. }
  1087. static void ehci_relinquish_port(struct hc_gen_dev *hcd, int portnum)
  1088. {
  1089. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  1090. set_owner(ehci, --portnum, PORT_OWNER);
  1091. }
  1092. static int ehci_port_handed_over(struct hc_gen_dev *hcd, int portnum)
  1093. {
  1094. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  1095. u32 *reg;
  1096. reg = &ehci->regs->port_status[portnum - 1];
  1097. return ehci_readl(ehci, reg) & PORT_OWNER;
  1098. }
  1099. static int ehci_port_power(struct ehci_hcd *ehci, int portnum, bool enable)
  1100. {
  1101. struct hc_gen_dev *hcd = ehci_to_hcd(ehci);
  1102. u32 *status_reg = &ehci->regs->port_status[portnum];
  1103. u32 temp = ehci_readl(ehci, status_reg) & ~PORT_RWC_BITS;
  1104. if (enable)
  1105. ehci_writel(ehci, temp | PORT_POWER, status_reg);
  1106. else
  1107. ehci_writel(ehci, temp & ~PORT_POWER, status_reg);
  1108. //if (hcd->driver->port_power)
  1109. // hcd->driver->port_power(hcd, portnum, enable);
  1110. return 0;
  1111. }