ehci-hub.c 35 KB

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