ehci-hub.c 35 KB

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