ehci-hub.c 35 KB

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