ehci-hub.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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. /* msleep for 20ms only if code is trying to resume port */
  408. if (resume_needed) {
  409. spin_unlock_irq(&ehci->lock);
  410. msleep(20);
  411. spin_lock_irq(&ehci->lock);
  412. if (ehci->shutdown)
  413. goto shutdown;
  414. }
  415. i = HCS_N_PORTS (ehci->hcs_params);
  416. while (i--) {
  417. temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
  418. if (test_bit(i, &resume_needed)) {
  419. temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
  420. ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
  421. }
  422. }
  423. ehci->next_statechange = jiffies + msecs_to_jiffies(5);
  424. spin_unlock_irq(&ehci->lock);
  425. ehci_handover_companion_ports(ehci);
  426. /* Now we can safely re-enable irqs */
  427. spin_lock_irq(&ehci->lock);
  428. if (ehci->shutdown)
  429. goto shutdown;
  430. ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
  431. (void) ehci_readl(ehci, &ehci->regs->intr_enable);
  432. spin_unlock_irq(&ehci->lock);
  433. return 0;
  434. shutdown:
  435. spin_unlock_irq(&ehci->lock);
  436. return -ESHUTDOWN;
  437. }
  438. #else
  439. #define ehci_bus_suspend NULL
  440. #define ehci_bus_resume NULL
  441. #endif /* CONFIG_PM */
  442. /*-------------------------------------------------------------------------*/
  443. /*
  444. * Sets the owner of a port
  445. */
  446. static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
  447. {
  448. u32 __iomem *status_reg;
  449. u32 port_status;
  450. int try;
  451. status_reg = &ehci->regs->port_status[portnum];
  452. /*
  453. * The controller won't set the OWNER bit if the port is
  454. * enabled, so this loop will sometimes require at least two
  455. * iterations: one to disable the port and one to set OWNER.
  456. */
  457. for (try = 4; try > 0; --try) {
  458. spin_lock_irq(&ehci->lock);
  459. port_status = ehci_readl(ehci, status_reg);
  460. if ((port_status & PORT_OWNER) == new_owner
  461. || (port_status & (PORT_OWNER | PORT_CONNECT))
  462. == 0)
  463. try = 0;
  464. else {
  465. port_status ^= PORT_OWNER;
  466. port_status &= ~(PORT_PE | PORT_RWC_BITS);
  467. ehci_writel(ehci, port_status, status_reg);
  468. }
  469. spin_unlock_irq(&ehci->lock);
  470. if (try > 1)
  471. msleep(5);
  472. }
  473. }
  474. /*-------------------------------------------------------------------------*/
  475. static int check_reset_complete (
  476. struct ehci_hcd *ehci,
  477. int index,
  478. u32 __iomem *status_reg,
  479. int port_status
  480. ) {
  481. if (!(port_status & PORT_CONNECT))
  482. return port_status;
  483. /* if reset finished and it's still not enabled -- handoff */
  484. if (!(port_status & PORT_PE)) {
  485. /* with integrated TT, there's nobody to hand it to! */
  486. if (ehci_is_TDI(ehci)) {
  487. ehci_dbg (ehci,
  488. "Failed to enable port %d on root hub TT\n",
  489. index+1);
  490. return port_status;
  491. }
  492. ehci_dbg (ehci, "port %d full speed --> companion\n",
  493. index + 1);
  494. // what happens if HCS_N_CC(params) == 0 ?
  495. port_status |= PORT_OWNER;
  496. port_status &= ~PORT_RWC_BITS;
  497. ehci_writel(ehci, port_status, status_reg);
  498. /* ensure 440EPX ohci controller state is operational */
  499. if (ehci->has_amcc_usb23)
  500. set_ohci_hcfs(ehci, 1);
  501. } else {
  502. ehci_dbg(ehci, "port %d reset complete, port enabled\n",
  503. index + 1);
  504. /* ensure 440EPx ohci controller state is suspended */
  505. if (ehci->has_amcc_usb23)
  506. set_ohci_hcfs(ehci, 0);
  507. }
  508. return port_status;
  509. }
  510. /*-------------------------------------------------------------------------*/
  511. /* build "status change" packet (one or two bytes) from HC registers */
  512. static int
  513. ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
  514. {
  515. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  516. u32 temp, status;
  517. u32 mask;
  518. int ports, i, retval = 1;
  519. unsigned long flags;
  520. u32 ppcd = ~0;
  521. /* init status to no-changes */
  522. buf [0] = 0;
  523. ports = HCS_N_PORTS (ehci->hcs_params);
  524. if (ports > 7) {
  525. buf [1] = 0;
  526. retval++;
  527. }
  528. /* Inform the core about resumes-in-progress by returning
  529. * a non-zero value even if there are no status changes.
  530. */
  531. status = ehci->resuming_ports;
  532. /* Some boards (mostly VIA?) report bogus overcurrent indications,
  533. * causing massive log spam unless we completely ignore them. It
  534. * may be relevant that VIA VT8235 controllers, where PORT_POWER is
  535. * always set, seem to clear PORT_OCC and PORT_CSC when writing to
  536. * PORT_POWER; that's surprising, but maybe within-spec.
  537. */
  538. if (!ignore_oc)
  539. mask = PORT_CSC | PORT_PEC | PORT_OCC;
  540. else
  541. mask = PORT_CSC | PORT_PEC;
  542. // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
  543. /* no hub change reports (bit 0) for now (power, ...) */
  544. /* port N changes (bit N)? */
  545. spin_lock_irqsave (&ehci->lock, flags);
  546. /* get per-port change detect bits */
  547. if (ehci->has_ppcd)
  548. ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16;
  549. for (i = 0; i < ports; i++) {
  550. /* leverage per-port change bits feature */
  551. if (ppcd & (1 << i))
  552. temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
  553. else
  554. temp = 0;
  555. /*
  556. * Return status information even for ports with OWNER set.
  557. * Otherwise khubd wouldn't see the disconnect event when a
  558. * high-speed device is switched over to the companion
  559. * controller by the user.
  560. */
  561. if ((temp & mask) != 0 || test_bit(i, &ehci->port_c_suspend)
  562. || (ehci->reset_done[i] && time_after_eq(
  563. jiffies, ehci->reset_done[i]))) {
  564. if (i < 7)
  565. buf [0] |= 1 << (i + 1);
  566. else
  567. buf [1] |= 1 << (i - 7);
  568. status = STS_PCD;
  569. }
  570. }
  571. /* If a resume is in progress, make sure it can finish */
  572. if (ehci->resuming_ports)
  573. mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(25));
  574. spin_unlock_irqrestore (&ehci->lock, flags);
  575. return status ? retval : 0;
  576. }
  577. /*-------------------------------------------------------------------------*/
  578. static void
  579. ehci_hub_descriptor (
  580. struct ehci_hcd *ehci,
  581. struct usb_hub_descriptor *desc
  582. ) {
  583. int ports = HCS_N_PORTS (ehci->hcs_params);
  584. u16 temp;
  585. desc->bDescriptorType = 0x29;
  586. desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */
  587. desc->bHubContrCurrent = 0;
  588. desc->bNbrPorts = ports;
  589. temp = 1 + (ports / 8);
  590. desc->bDescLength = 7 + 2 * temp;
  591. /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
  592. memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
  593. memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
  594. temp = 0x0008; /* per-port overcurrent reporting */
  595. if (HCS_PPC (ehci->hcs_params))
  596. temp |= 0x0001; /* per-port power control */
  597. else
  598. temp |= 0x0002; /* no power switching */
  599. #if 0
  600. // re-enable when we support USB_PORT_FEAT_INDICATOR below.
  601. if (HCS_INDICATOR (ehci->hcs_params))
  602. temp |= 0x0080; /* per-port indicators (LEDs) */
  603. #endif
  604. desc->wHubCharacteristics = cpu_to_le16(temp);
  605. }
  606. /*-------------------------------------------------------------------------*/
  607. #ifdef CONFIG_USB_HCD_TEST_MODE
  608. #define EHSET_TEST_SINGLE_STEP_SET_FEATURE 0x06
  609. static void usb_ehset_completion(struct urb *urb)
  610. {
  611. struct completion *done = urb->context;
  612. complete(done);
  613. }
  614. static int submit_single_step_set_feature(
  615. struct usb_hcd *hcd,
  616. struct urb *urb,
  617. int is_setup
  618. );
  619. /*
  620. * Allocate and initialize a control URB. This request will be used by the
  621. * EHSET SINGLE_STEP_SET_FEATURE test in which the DATA and STATUS stages
  622. * of the GetDescriptor request are sent 15 seconds after the SETUP stage.
  623. * Return NULL if failed.
  624. */
  625. static struct urb *request_single_step_set_feature_urb(
  626. struct usb_device *udev,
  627. void *dr,
  628. void *buf,
  629. struct completion *done
  630. ) {
  631. struct urb *urb;
  632. struct usb_hcd *hcd = bus_to_hcd(udev->bus);
  633. struct usb_host_endpoint *ep;
  634. urb = usb_alloc_urb(0, GFP_KERNEL);
  635. if (!urb)
  636. return NULL;
  637. urb->pipe = usb_rcvctrlpipe(udev, 0);
  638. ep = (usb_pipein(urb->pipe) ? udev->ep_in : udev->ep_out)
  639. [usb_pipeendpoint(urb->pipe)];
  640. if (!ep) {
  641. usb_free_urb(urb);
  642. return NULL;
  643. }
  644. urb->ep = ep;
  645. urb->dev = udev;
  646. urb->setup_packet = (void *)dr;
  647. urb->transfer_buffer = buf;
  648. urb->transfer_buffer_length = USB_DT_DEVICE_SIZE;
  649. urb->complete = usb_ehset_completion;
  650. urb->status = -EINPROGRESS;
  651. urb->actual_length = 0;
  652. urb->transfer_flags = URB_DIR_IN;
  653. usb_get_urb(urb);
  654. atomic_inc(&urb->use_count);
  655. atomic_inc(&urb->dev->urbnum);
  656. urb->setup_dma = dma_map_single(
  657. hcd->self.controller,
  658. urb->setup_packet,
  659. sizeof(struct usb_ctrlrequest),
  660. DMA_TO_DEVICE);
  661. urb->transfer_dma = dma_map_single(
  662. hcd->self.controller,
  663. urb->transfer_buffer,
  664. urb->transfer_buffer_length,
  665. DMA_FROM_DEVICE);
  666. urb->context = done;
  667. return urb;
  668. }
  669. static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
  670. {
  671. int retval = -ENOMEM;
  672. struct usb_ctrlrequest *dr;
  673. struct urb *urb;
  674. struct usb_device *udev;
  675. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  676. struct usb_device_descriptor *buf;
  677. DECLARE_COMPLETION_ONSTACK(done);
  678. /* Obtain udev of the rhub's child port */
  679. udev = usb_hub_find_child(hcd->self.root_hub, port);
  680. if (!udev) {
  681. ehci_err(ehci, "No device attached to the RootHub\n");
  682. return -ENODEV;
  683. }
  684. buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);
  685. if (!buf)
  686. return -ENOMEM;
  687. dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
  688. if (!dr) {
  689. kfree(buf);
  690. return -ENOMEM;
  691. }
  692. /* Fill Setup packet for GetDescriptor */
  693. dr->bRequestType = USB_DIR_IN;
  694. dr->bRequest = USB_REQ_GET_DESCRIPTOR;
  695. dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8);
  696. dr->wIndex = 0;
  697. dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE);
  698. urb = request_single_step_set_feature_urb(udev, dr, buf, &done);
  699. if (!urb)
  700. goto cleanup;
  701. /* Submit just the SETUP stage */
  702. retval = submit_single_step_set_feature(hcd, urb, 1);
  703. if (retval)
  704. goto out1;
  705. if (!wait_for_completion_timeout(&done, msecs_to_jiffies(2000))) {
  706. usb_kill_urb(urb);
  707. retval = -ETIMEDOUT;
  708. ehci_err(ehci, "%s SETUP stage timed out on ep0\n", __func__);
  709. goto out1;
  710. }
  711. msleep(15 * 1000);
  712. /* Complete remaining DATA and STATUS stages using the same URB */
  713. urb->status = -EINPROGRESS;
  714. usb_get_urb(urb);
  715. atomic_inc(&urb->use_count);
  716. atomic_inc(&urb->dev->urbnum);
  717. retval = submit_single_step_set_feature(hcd, urb, 0);
  718. if (!retval && !wait_for_completion_timeout(&done,
  719. msecs_to_jiffies(2000))) {
  720. usb_kill_urb(urb);
  721. retval = -ETIMEDOUT;
  722. ehci_err(ehci, "%s IN stage timed out on ep0\n", __func__);
  723. }
  724. out1:
  725. usb_free_urb(urb);
  726. cleanup:
  727. kfree(dr);
  728. kfree(buf);
  729. return retval;
  730. }
  731. #endif /* CONFIG_USB_HCD_TEST_MODE */
  732. /*-------------------------------------------------------------------------*/
  733. int ehci_hub_control(
  734. struct usb_hcd *hcd,
  735. u16 typeReq,
  736. u16 wValue,
  737. u16 wIndex,
  738. char *buf,
  739. u16 wLength
  740. ) {
  741. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  742. int ports = HCS_N_PORTS (ehci->hcs_params);
  743. u32 __iomem *status_reg = &ehci->regs->port_status[
  744. (wIndex & 0xff) - 1];
  745. u32 __iomem *hostpc_reg = &ehci->regs->hostpc[(wIndex & 0xff) - 1];
  746. u32 temp, temp1, status;
  747. unsigned long flags;
  748. int retval = 0;
  749. unsigned selector;
  750. /*
  751. * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
  752. * HCS_INDICATOR may say we can change LEDs to off/amber/green.
  753. * (track current state ourselves) ... blink for diagnostics,
  754. * power, "this is the one", etc. EHCI spec supports this.
  755. */
  756. spin_lock_irqsave (&ehci->lock, flags);
  757. switch (typeReq) {
  758. case ClearHubFeature:
  759. switch (wValue) {
  760. case C_HUB_LOCAL_POWER:
  761. case C_HUB_OVER_CURRENT:
  762. /* no hub-wide feature/status flags */
  763. break;
  764. default:
  765. goto error;
  766. }
  767. break;
  768. case ClearPortFeature:
  769. if (!wIndex || wIndex > ports)
  770. goto error;
  771. wIndex--;
  772. temp = ehci_readl(ehci, status_reg);
  773. temp &= ~PORT_RWC_BITS;
  774. /*
  775. * Even if OWNER is set, so the port is owned by the
  776. * companion controller, khubd needs to be able to clear
  777. * the port-change status bits (especially
  778. * USB_PORT_STAT_C_CONNECTION).
  779. */
  780. switch (wValue) {
  781. case USB_PORT_FEAT_ENABLE:
  782. ehci_writel(ehci, temp & ~PORT_PE, status_reg);
  783. break;
  784. case USB_PORT_FEAT_C_ENABLE:
  785. ehci_writel(ehci, temp | PORT_PEC, status_reg);
  786. break;
  787. case USB_PORT_FEAT_SUSPEND:
  788. if (temp & PORT_RESET)
  789. goto error;
  790. if (ehci->no_selective_suspend)
  791. break;
  792. #ifdef CONFIG_USB_OTG
  793. if ((hcd->self.otg_port == (wIndex + 1))
  794. && hcd->self.b_hnp_enable) {
  795. otg_start_hnp(hcd->phy->otg);
  796. break;
  797. }
  798. #endif
  799. if (!(temp & PORT_SUSPEND))
  800. break;
  801. if ((temp & PORT_PE) == 0)
  802. goto error;
  803. /* clear phy low-power mode before resume */
  804. if (ehci->has_tdi_phy_lpm) {
  805. temp1 = ehci_readl(ehci, hostpc_reg);
  806. ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
  807. hostpc_reg);
  808. spin_unlock_irqrestore(&ehci->lock, flags);
  809. msleep(5);/* wait to leave low-power mode */
  810. spin_lock_irqsave(&ehci->lock, flags);
  811. }
  812. /* resume signaling for 20 msec */
  813. temp &= ~PORT_WAKE_BITS;
  814. ehci_writel(ehci, temp | PORT_RESUME, status_reg);
  815. ehci->reset_done[wIndex] = jiffies
  816. + msecs_to_jiffies(20);
  817. set_bit(wIndex, &ehci->resuming_ports);
  818. usb_hcd_start_port_resume(&hcd->self, wIndex);
  819. break;
  820. case USB_PORT_FEAT_C_SUSPEND:
  821. clear_bit(wIndex, &ehci->port_c_suspend);
  822. break;
  823. case USB_PORT_FEAT_POWER:
  824. if (HCS_PPC (ehci->hcs_params))
  825. ehci_writel(ehci, temp & ~PORT_POWER,
  826. status_reg);
  827. break;
  828. case USB_PORT_FEAT_C_CONNECTION:
  829. ehci_writel(ehci, temp | PORT_CSC, status_reg);
  830. break;
  831. case USB_PORT_FEAT_C_OVER_CURRENT:
  832. ehci_writel(ehci, temp | PORT_OCC, status_reg);
  833. break;
  834. case USB_PORT_FEAT_C_RESET:
  835. /* GetPortStatus clears reset */
  836. break;
  837. default:
  838. goto error;
  839. }
  840. ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */
  841. break;
  842. case GetHubDescriptor:
  843. ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *)
  844. buf);
  845. break;
  846. case GetHubStatus:
  847. /* no hub-wide feature/status flags */
  848. memset (buf, 0, 4);
  849. //cpu_to_le32s ((u32 *) buf);
  850. break;
  851. case GetPortStatus:
  852. if (!wIndex || wIndex > ports)
  853. goto error;
  854. wIndex--;
  855. status = 0;
  856. temp = ehci_readl(ehci, status_reg);
  857. // wPortChange bits
  858. if (temp & PORT_CSC)
  859. status |= USB_PORT_STAT_C_CONNECTION << 16;
  860. if (temp & PORT_PEC)
  861. status |= USB_PORT_STAT_C_ENABLE << 16;
  862. if ((temp & PORT_OCC) && !ignore_oc){
  863. status |= USB_PORT_STAT_C_OVERCURRENT << 16;
  864. /*
  865. * Hubs should disable port power on over-current.
  866. * However, not all EHCI implementations do this
  867. * automatically, even if they _do_ support per-port
  868. * power switching; they're allowed to just limit the
  869. * current. khubd will turn the power back on.
  870. */
  871. if (((temp & PORT_OC) || (ehci->need_oc_pp_cycle))
  872. && HCS_PPC(ehci->hcs_params)) {
  873. ehci_writel(ehci,
  874. temp & ~(PORT_RWC_BITS | PORT_POWER),
  875. status_reg);
  876. temp = ehci_readl(ehci, status_reg);
  877. }
  878. }
  879. /* no reset or resume pending */
  880. if (!ehci->reset_done[wIndex]) {
  881. /* Remote Wakeup received? */
  882. if (temp & PORT_RESUME) {
  883. /* resume signaling for 20 msec */
  884. ehci->reset_done[wIndex] = jiffies
  885. + msecs_to_jiffies(20);
  886. usb_hcd_start_port_resume(&hcd->self, wIndex);
  887. set_bit(wIndex, &ehci->resuming_ports);
  888. /* check the port again */
  889. mod_timer(&ehci_to_hcd(ehci)->rh_timer,
  890. ehci->reset_done[wIndex]);
  891. }
  892. /* reset or resume not yet complete */
  893. } else if (!time_after_eq(jiffies, ehci->reset_done[wIndex])) {
  894. ; /* wait until it is complete */
  895. /* resume completed */
  896. } else if (test_bit(wIndex, &ehci->resuming_ports)) {
  897. clear_bit(wIndex, &ehci->suspended_ports);
  898. set_bit(wIndex, &ehci->port_c_suspend);
  899. ehci->reset_done[wIndex] = 0;
  900. usb_hcd_end_port_resume(&hcd->self, wIndex);
  901. /* stop resume signaling */
  902. temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
  903. ehci_writel(ehci, temp, status_reg);
  904. clear_bit(wIndex, &ehci->resuming_ports);
  905. retval = ehci_handshake(ehci, status_reg,
  906. PORT_RESUME, 0, 2000 /* 2msec */);
  907. if (retval != 0) {
  908. ehci_err(ehci, "port %d resume error %d\n",
  909. wIndex + 1, retval);
  910. goto error;
  911. }
  912. temp = ehci_readl(ehci, status_reg);
  913. /* whoever resets must GetPortStatus to complete it!! */
  914. } else {
  915. status |= USB_PORT_STAT_C_RESET << 16;
  916. ehci->reset_done [wIndex] = 0;
  917. /* force reset to complete */
  918. ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
  919. status_reg);
  920. /* REVISIT: some hardware needs 550+ usec to clear
  921. * this bit; seems too long to spin routinely...
  922. */
  923. retval = ehci_handshake(ehci, status_reg,
  924. PORT_RESET, 0, 1000);
  925. if (retval != 0) {
  926. ehci_err (ehci, "port %d reset error %d\n",
  927. wIndex + 1, retval);
  928. goto error;
  929. }
  930. /* see what we found out */
  931. temp = check_reset_complete (ehci, wIndex, status_reg,
  932. ehci_readl(ehci, status_reg));
  933. }
  934. /* transfer dedicated ports to the companion hc */
  935. if ((temp & PORT_CONNECT) &&
  936. test_bit(wIndex, &ehci->companion_ports)) {
  937. temp &= ~PORT_RWC_BITS;
  938. temp |= PORT_OWNER;
  939. ehci_writel(ehci, temp, status_reg);
  940. ehci_dbg(ehci, "port %d --> companion\n", wIndex + 1);
  941. temp = ehci_readl(ehci, status_reg);
  942. }
  943. /*
  944. * Even if OWNER is set, there's no harm letting khubd
  945. * see the wPortStatus values (they should all be 0 except
  946. * for PORT_POWER anyway).
  947. */
  948. if (temp & PORT_CONNECT) {
  949. status |= USB_PORT_STAT_CONNECTION;
  950. // status may be from integrated TT
  951. if (ehci->has_hostpc) {
  952. temp1 = ehci_readl(ehci, hostpc_reg);
  953. status |= ehci_port_speed(ehci, temp1);
  954. } else
  955. status |= ehci_port_speed(ehci, temp);
  956. }
  957. if (temp & PORT_PE)
  958. status |= USB_PORT_STAT_ENABLE;
  959. /* maybe the port was unsuspended without our knowledge */
  960. if (temp & (PORT_SUSPEND|PORT_RESUME)) {
  961. status |= USB_PORT_STAT_SUSPEND;
  962. } else if (test_bit(wIndex, &ehci->suspended_ports)) {
  963. clear_bit(wIndex, &ehci->suspended_ports);
  964. clear_bit(wIndex, &ehci->resuming_ports);
  965. ehci->reset_done[wIndex] = 0;
  966. if (temp & PORT_PE)
  967. set_bit(wIndex, &ehci->port_c_suspend);
  968. usb_hcd_end_port_resume(&hcd->self, wIndex);
  969. }
  970. if (temp & PORT_OC)
  971. status |= USB_PORT_STAT_OVERCURRENT;
  972. if (temp & PORT_RESET)
  973. status |= USB_PORT_STAT_RESET;
  974. if (temp & PORT_POWER)
  975. status |= USB_PORT_STAT_POWER;
  976. if (test_bit(wIndex, &ehci->port_c_suspend))
  977. status |= USB_PORT_STAT_C_SUSPEND << 16;
  978. if (status & ~0xffff) /* only if wPortChange is interesting */
  979. dbg_port(ehci, "GetStatus", wIndex + 1, temp);
  980. put_unaligned_le32(status, buf);
  981. break;
  982. case SetHubFeature:
  983. switch (wValue) {
  984. case C_HUB_LOCAL_POWER:
  985. case C_HUB_OVER_CURRENT:
  986. /* no hub-wide feature/status flags */
  987. break;
  988. default:
  989. goto error;
  990. }
  991. break;
  992. case SetPortFeature:
  993. selector = wIndex >> 8;
  994. wIndex &= 0xff;
  995. if (unlikely(ehci->debug)) {
  996. /* If the debug port is active any port
  997. * feature requests should get denied */
  998. if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) &&
  999. (readl(&ehci->debug->control) & DBGP_ENABLED)) {
  1000. retval = -ENODEV;
  1001. goto error_exit;
  1002. }
  1003. }
  1004. if (!wIndex || wIndex > ports)
  1005. goto error;
  1006. wIndex--;
  1007. temp = ehci_readl(ehci, status_reg);
  1008. if (temp & PORT_OWNER)
  1009. break;
  1010. temp &= ~PORT_RWC_BITS;
  1011. switch (wValue) {
  1012. case USB_PORT_FEAT_SUSPEND:
  1013. if (ehci->no_selective_suspend)
  1014. break;
  1015. if ((temp & PORT_PE) == 0
  1016. || (temp & PORT_RESET) != 0)
  1017. goto error;
  1018. /* After above check the port must be connected.
  1019. * Set appropriate bit thus could put phy into low power
  1020. * mode if we have tdi_phy_lpm feature
  1021. */
  1022. temp &= ~PORT_WKCONN_E;
  1023. temp |= PORT_WKDISC_E | PORT_WKOC_E;
  1024. ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
  1025. if (ehci->has_tdi_phy_lpm) {
  1026. spin_unlock_irqrestore(&ehci->lock, flags);
  1027. msleep(5);/* 5ms for HCD enter low pwr mode */
  1028. spin_lock_irqsave(&ehci->lock, flags);
  1029. temp1 = ehci_readl(ehci, hostpc_reg);
  1030. ehci_writel(ehci, temp1 | HOSTPC_PHCD,
  1031. hostpc_reg);
  1032. temp1 = ehci_readl(ehci, hostpc_reg);
  1033. ehci_dbg(ehci, "Port%d phy low pwr mode %s\n",
  1034. wIndex, (temp1 & HOSTPC_PHCD) ?
  1035. "succeeded" : "failed");
  1036. }
  1037. set_bit(wIndex, &ehci->suspended_ports);
  1038. break;
  1039. case USB_PORT_FEAT_POWER:
  1040. if (HCS_PPC (ehci->hcs_params))
  1041. ehci_writel(ehci, temp | PORT_POWER,
  1042. status_reg);
  1043. break;
  1044. case USB_PORT_FEAT_RESET:
  1045. if (temp & (PORT_SUSPEND|PORT_RESUME))
  1046. goto error;
  1047. /* line status bits may report this as low speed,
  1048. * which can be fine if this root hub has a
  1049. * transaction translator built in.
  1050. */
  1051. if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
  1052. && !ehci_is_TDI(ehci)
  1053. && PORT_USB11 (temp)) {
  1054. ehci_dbg (ehci,
  1055. "port %d low speed --> companion\n",
  1056. wIndex + 1);
  1057. temp |= PORT_OWNER;
  1058. } else {
  1059. temp |= PORT_RESET;
  1060. temp &= ~PORT_PE;
  1061. /*
  1062. * caller must wait, then call GetPortStatus
  1063. * usb 2.0 spec says 50 ms resets on root
  1064. */
  1065. ehci->reset_done [wIndex] = jiffies
  1066. + msecs_to_jiffies (50);
  1067. }
  1068. ehci_writel(ehci, temp, status_reg);
  1069. break;
  1070. /* For downstream facing ports (these): one hub port is put
  1071. * into test mode according to USB2 11.24.2.13, then the hub
  1072. * must be reset (which for root hub now means rmmod+modprobe,
  1073. * or else system reboot). See EHCI 2.3.9 and 4.14 for info
  1074. * about the EHCI-specific stuff.
  1075. */
  1076. case USB_PORT_FEAT_TEST:
  1077. #ifdef CONFIG_USB_HCD_TEST_MODE
  1078. if (selector == EHSET_TEST_SINGLE_STEP_SET_FEATURE) {
  1079. spin_unlock_irqrestore(&ehci->lock, flags);
  1080. retval = ehset_single_step_set_feature(hcd,
  1081. wIndex);
  1082. spin_lock_irqsave(&ehci->lock, flags);
  1083. break;
  1084. }
  1085. #endif
  1086. if (!selector || selector > 5)
  1087. goto error;
  1088. spin_unlock_irqrestore(&ehci->lock, flags);
  1089. ehci_quiesce(ehci);
  1090. spin_lock_irqsave(&ehci->lock, flags);
  1091. /* Put all enabled ports into suspend */
  1092. while (ports--) {
  1093. u32 __iomem *sreg =
  1094. &ehci->regs->port_status[ports];
  1095. temp = ehci_readl(ehci, sreg) & ~PORT_RWC_BITS;
  1096. if (temp & PORT_PE)
  1097. ehci_writel(ehci, temp | PORT_SUSPEND,
  1098. sreg);
  1099. }
  1100. spin_unlock_irqrestore(&ehci->lock, flags);
  1101. ehci_halt(ehci);
  1102. spin_lock_irqsave(&ehci->lock, flags);
  1103. temp = ehci_readl(ehci, status_reg);
  1104. temp |= selector << 16;
  1105. ehci_writel(ehci, temp, status_reg);
  1106. break;
  1107. default:
  1108. goto error;
  1109. }
  1110. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  1111. break;
  1112. default:
  1113. error:
  1114. /* "stall" on error */
  1115. retval = -EPIPE;
  1116. }
  1117. error_exit:
  1118. spin_unlock_irqrestore (&ehci->lock, flags);
  1119. return retval;
  1120. }
  1121. EXPORT_SYMBOL_GPL(ehci_hub_control);
  1122. static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum)
  1123. {
  1124. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  1125. if (ehci_is_TDI(ehci))
  1126. return;
  1127. set_owner(ehci, --portnum, PORT_OWNER);
  1128. }
  1129. static int ehci_port_handed_over(struct usb_hcd *hcd, int portnum)
  1130. {
  1131. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  1132. u32 __iomem *reg;
  1133. if (ehci_is_TDI(ehci))
  1134. return 0;
  1135. reg = &ehci->regs->port_status[portnum - 1];
  1136. return ehci_readl(ehci, reg) & PORT_OWNER;
  1137. }