ehci-hub.c 35 KB

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