ehci-hub.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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. #ifdef CONFIG_PM
  27. static int ehci_bus_suspend (struct usb_hcd *hcd)
  28. {
  29. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  30. int port;
  31. int mask;
  32. if (time_before (jiffies, ehci->next_statechange))
  33. msleep(5);
  34. port = HCS_N_PORTS (ehci->hcs_params);
  35. spin_lock_irq (&ehci->lock);
  36. /* stop schedules, clean any completed work */
  37. if (HC_IS_RUNNING(hcd->state)) {
  38. ehci_quiesce (ehci);
  39. hcd->state = HC_STATE_QUIESCING;
  40. }
  41. ehci->command = ehci_readl(ehci, &ehci->regs->command);
  42. if (ehci->reclaim)
  43. ehci->reclaim_ready = 1;
  44. ehci_work(ehci);
  45. /* Unlike other USB host controller types, EHCI doesn't have
  46. * any notion of "global" or bus-wide suspend. The driver has
  47. * to manually suspend all the active unsuspended ports, and
  48. * then manually resume them in the bus_resume() routine.
  49. */
  50. ehci->bus_suspended = 0;
  51. while (port--) {
  52. u32 __iomem *reg = &ehci->regs->port_status [port];
  53. u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
  54. u32 t2 = t1;
  55. /* keep track of which ports we suspend */
  56. if ((t1 & PORT_PE) && !(t1 & PORT_OWNER) &&
  57. !(t1 & PORT_SUSPEND)) {
  58. t2 |= PORT_SUSPEND;
  59. set_bit(port, &ehci->bus_suspended);
  60. }
  61. /* enable remote wakeup on all ports */
  62. if (device_may_wakeup(&hcd->self.root_hub->dev))
  63. t2 |= PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E;
  64. else
  65. t2 &= ~(PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E);
  66. if (t1 != t2) {
  67. ehci_vdbg (ehci, "port %d, %08x -> %08x\n",
  68. port + 1, t1, t2);
  69. ehci_writel(ehci, t2, reg);
  70. }
  71. }
  72. /* turn off now-idle HC */
  73. del_timer_sync (&ehci->watchdog);
  74. ehci_halt (ehci);
  75. hcd->state = HC_STATE_SUSPENDED;
  76. /* allow remote wakeup */
  77. mask = INTR_MASK;
  78. if (!device_may_wakeup(&hcd->self.root_hub->dev))
  79. mask &= ~STS_PCD;
  80. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  81. ehci_readl(ehci, &ehci->regs->intr_enable);
  82. ehci->next_statechange = jiffies + msecs_to_jiffies(10);
  83. spin_unlock_irq (&ehci->lock);
  84. return 0;
  85. }
  86. /* caller has locked the root hub, and should reset/reinit on error */
  87. static int ehci_bus_resume (struct usb_hcd *hcd)
  88. {
  89. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  90. u32 temp;
  91. int i;
  92. if (time_before (jiffies, ehci->next_statechange))
  93. msleep(5);
  94. spin_lock_irq (&ehci->lock);
  95. /* Ideally and we've got a real resume here, and no port's power
  96. * was lost. (For PCI, that means Vaux was maintained.) But we
  97. * could instead be restoring a swsusp snapshot -- so that BIOS was
  98. * the last user of the controller, not reset/pm hardware keeping
  99. * state we gave to it.
  100. */
  101. temp = ehci_readl(ehci, &ehci->regs->intr_enable);
  102. ehci_dbg(ehci, "resume root hub%s\n", temp ? "" : " after power loss");
  103. /* at least some APM implementations will try to deliver
  104. * IRQs right away, so delay them until we're ready.
  105. */
  106. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  107. /* re-init operational registers */
  108. ehci_writel(ehci, 0, &ehci->regs->segment);
  109. ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
  110. ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
  111. /* restore CMD_RUN, framelist size, and irq threshold */
  112. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  113. /* manually resume the ports we suspended during bus_suspend() */
  114. i = HCS_N_PORTS (ehci->hcs_params);
  115. while (i--) {
  116. temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
  117. temp &= ~(PORT_RWC_BITS
  118. | PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E);
  119. if (test_bit(i, &ehci->bus_suspended) &&
  120. (temp & PORT_SUSPEND)) {
  121. ehci->reset_done [i] = jiffies + msecs_to_jiffies (20);
  122. temp |= PORT_RESUME;
  123. }
  124. ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
  125. }
  126. i = HCS_N_PORTS (ehci->hcs_params);
  127. mdelay (20);
  128. while (i--) {
  129. temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
  130. if (test_bit(i, &ehci->bus_suspended) &&
  131. (temp & PORT_SUSPEND)) {
  132. temp &= ~(PORT_RWC_BITS | PORT_RESUME);
  133. ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
  134. ehci_vdbg (ehci, "resumed port %d\n", i + 1);
  135. }
  136. }
  137. (void) ehci_readl(ehci, &ehci->regs->command);
  138. /* maybe re-activate the schedule(s) */
  139. temp = 0;
  140. if (ehci->async->qh_next.qh)
  141. temp |= CMD_ASE;
  142. if (ehci->periodic_sched)
  143. temp |= CMD_PSE;
  144. if (temp) {
  145. ehci->command |= temp;
  146. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  147. }
  148. ehci->next_statechange = jiffies + msecs_to_jiffies(5);
  149. hcd->state = HC_STATE_RUNNING;
  150. /* Now we can safely re-enable irqs */
  151. ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
  152. spin_unlock_irq (&ehci->lock);
  153. return 0;
  154. }
  155. #else
  156. #define ehci_bus_suspend NULL
  157. #define ehci_bus_resume NULL
  158. #endif /* CONFIG_PM */
  159. /*-------------------------------------------------------------------------*/
  160. /* Display the ports dedicated to the companion controller */
  161. static ssize_t show_companion(struct class_device *class_dev, char *buf)
  162. {
  163. struct ehci_hcd *ehci;
  164. int nports, index, n;
  165. int count = PAGE_SIZE;
  166. char *ptr = buf;
  167. ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev)));
  168. nports = HCS_N_PORTS(ehci->hcs_params);
  169. for (index = 0; index < nports; ++index) {
  170. if (test_bit(index, &ehci->companion_ports)) {
  171. n = scnprintf(ptr, count, "%d\n", index + 1);
  172. ptr += n;
  173. count -= n;
  174. }
  175. }
  176. return ptr - buf;
  177. }
  178. /*
  179. * Dedicate or undedicate a port to the companion controller.
  180. * Syntax is "[-]portnum", where a leading '-' sign means
  181. * return control of the port to the EHCI controller.
  182. */
  183. static ssize_t store_companion(struct class_device *class_dev,
  184. const char *buf, size_t count)
  185. {
  186. struct ehci_hcd *ehci;
  187. int portnum, new_owner, try;
  188. u32 __iomem *status_reg;
  189. u32 port_status;
  190. ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev)));
  191. new_owner = PORT_OWNER; /* Owned by companion */
  192. if (sscanf(buf, "%d", &portnum) != 1)
  193. return -EINVAL;
  194. if (portnum < 0) {
  195. portnum = - portnum;
  196. new_owner = 0; /* Owned by EHCI */
  197. }
  198. if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
  199. return -ENOENT;
  200. status_reg = &ehci->regs->port_status[--portnum];
  201. if (new_owner)
  202. set_bit(portnum, &ehci->companion_ports);
  203. else
  204. clear_bit(portnum, &ehci->companion_ports);
  205. /*
  206. * The controller won't set the OWNER bit if the port is
  207. * enabled, so this loop will sometimes require at least two
  208. * iterations: one to disable the port and one to set OWNER.
  209. */
  210. for (try = 4; try > 0; --try) {
  211. spin_lock_irq(&ehci->lock);
  212. port_status = ehci_readl(ehci, status_reg);
  213. if ((port_status & PORT_OWNER) == new_owner
  214. || (port_status & (PORT_OWNER | PORT_CONNECT))
  215. == 0)
  216. try = 0;
  217. else {
  218. port_status ^= PORT_OWNER;
  219. port_status &= ~(PORT_PE | PORT_RWC_BITS);
  220. ehci_writel(ehci, port_status, status_reg);
  221. }
  222. spin_unlock_irq(&ehci->lock);
  223. if (try > 1)
  224. msleep(5);
  225. }
  226. return count;
  227. }
  228. static CLASS_DEVICE_ATTR(companion, 0644, show_companion, store_companion);
  229. static inline void create_companion_file(struct ehci_hcd *ehci)
  230. {
  231. int i;
  232. /* with integrated TT there is no companion! */
  233. if (!ehci_is_TDI(ehci))
  234. i = class_device_create_file(ehci_to_hcd(ehci)->self.class_dev,
  235. &class_device_attr_companion);
  236. }
  237. static inline void remove_companion_file(struct ehci_hcd *ehci)
  238. {
  239. /* with integrated TT there is no companion! */
  240. if (!ehci_is_TDI(ehci))
  241. class_device_remove_file(ehci_to_hcd(ehci)->self.class_dev,
  242. &class_device_attr_companion);
  243. }
  244. /*-------------------------------------------------------------------------*/
  245. static int check_reset_complete (
  246. struct ehci_hcd *ehci,
  247. int index,
  248. u32 __iomem *status_reg,
  249. int port_status
  250. ) {
  251. if (!(port_status & PORT_CONNECT)) {
  252. ehci->reset_done [index] = 0;
  253. return port_status;
  254. }
  255. /* if reset finished and it's still not enabled -- handoff */
  256. if (!(port_status & PORT_PE)) {
  257. /* with integrated TT, there's nobody to hand it to! */
  258. if (ehci_is_TDI(ehci)) {
  259. ehci_dbg (ehci,
  260. "Failed to enable port %d on root hub TT\n",
  261. index+1);
  262. return port_status;
  263. }
  264. ehci_dbg (ehci, "port %d full speed --> companion\n",
  265. index + 1);
  266. // what happens if HCS_N_CC(params) == 0 ?
  267. port_status |= PORT_OWNER;
  268. port_status &= ~PORT_RWC_BITS;
  269. ehci_writel(ehci, port_status, status_reg);
  270. } else
  271. ehci_dbg (ehci, "port %d high speed\n", index + 1);
  272. return port_status;
  273. }
  274. /*-------------------------------------------------------------------------*/
  275. /* build "status change" packet (one or two bytes) from HC registers */
  276. static int
  277. ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
  278. {
  279. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  280. u32 temp, status = 0;
  281. u32 mask;
  282. int ports, i, retval = 1;
  283. unsigned long flags;
  284. /* if !USB_SUSPEND, root hub timers won't get shut down ... */
  285. if (!HC_IS_RUNNING(hcd->state))
  286. return 0;
  287. /* init status to no-changes */
  288. buf [0] = 0;
  289. ports = HCS_N_PORTS (ehci->hcs_params);
  290. if (ports > 7) {
  291. buf [1] = 0;
  292. retval++;
  293. }
  294. /* Some boards (mostly VIA?) report bogus overcurrent indications,
  295. * causing massive log spam unless we completely ignore them. It
  296. * may be relevant that VIA VT8235 controlers, where PORT_POWER is
  297. * always set, seem to clear PORT_OCC and PORT_CSC when writing to
  298. * PORT_POWER; that's surprising, but maybe within-spec.
  299. */
  300. if (!ignore_oc)
  301. mask = PORT_CSC | PORT_PEC | PORT_OCC;
  302. else
  303. mask = PORT_CSC | PORT_PEC;
  304. // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
  305. /* no hub change reports (bit 0) for now (power, ...) */
  306. /* port N changes (bit N)? */
  307. spin_lock_irqsave (&ehci->lock, flags);
  308. for (i = 0; i < ports; i++) {
  309. temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
  310. /*
  311. * Return status information even for ports with OWNER set.
  312. * Otherwise khubd wouldn't see the disconnect event when a
  313. * high-speed device is switched over to the companion
  314. * controller by the user.
  315. */
  316. if (!(temp & PORT_CONNECT))
  317. ehci->reset_done [i] = 0;
  318. if ((temp & mask) != 0
  319. || ((temp & PORT_RESUME) != 0
  320. && time_after_eq(jiffies,
  321. ehci->reset_done[i]))) {
  322. if (i < 7)
  323. buf [0] |= 1 << (i + 1);
  324. else
  325. buf [1] |= 1 << (i - 7);
  326. status = STS_PCD;
  327. }
  328. }
  329. /* FIXME autosuspend idle root hubs */
  330. spin_unlock_irqrestore (&ehci->lock, flags);
  331. return status ? retval : 0;
  332. }
  333. /*-------------------------------------------------------------------------*/
  334. static void
  335. ehci_hub_descriptor (
  336. struct ehci_hcd *ehci,
  337. struct usb_hub_descriptor *desc
  338. ) {
  339. int ports = HCS_N_PORTS (ehci->hcs_params);
  340. u16 temp;
  341. desc->bDescriptorType = 0x29;
  342. desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */
  343. desc->bHubContrCurrent = 0;
  344. desc->bNbrPorts = ports;
  345. temp = 1 + (ports / 8);
  346. desc->bDescLength = 7 + 2 * temp;
  347. /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
  348. memset (&desc->bitmap [0], 0, temp);
  349. memset (&desc->bitmap [temp], 0xff, temp);
  350. temp = 0x0008; /* per-port overcurrent reporting */
  351. if (HCS_PPC (ehci->hcs_params))
  352. temp |= 0x0001; /* per-port power control */
  353. else
  354. temp |= 0x0002; /* no power switching */
  355. #if 0
  356. // re-enable when we support USB_PORT_FEAT_INDICATOR below.
  357. if (HCS_INDICATOR (ehci->hcs_params))
  358. temp |= 0x0080; /* per-port indicators (LEDs) */
  359. #endif
  360. desc->wHubCharacteristics = (__force __u16)cpu_to_le16 (temp);
  361. }
  362. /*-------------------------------------------------------------------------*/
  363. #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
  364. static int ehci_hub_control (
  365. struct usb_hcd *hcd,
  366. u16 typeReq,
  367. u16 wValue,
  368. u16 wIndex,
  369. char *buf,
  370. u16 wLength
  371. ) {
  372. struct ehci_hcd *ehci = hcd_to_ehci (hcd);
  373. int ports = HCS_N_PORTS (ehci->hcs_params);
  374. u32 __iomem *status_reg = &ehci->regs->port_status[wIndex - 1];
  375. u32 temp, status;
  376. unsigned long flags;
  377. int retval = 0;
  378. unsigned selector;
  379. /*
  380. * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
  381. * HCS_INDICATOR may say we can change LEDs to off/amber/green.
  382. * (track current state ourselves) ... blink for diagnostics,
  383. * power, "this is the one", etc. EHCI spec supports this.
  384. */
  385. spin_lock_irqsave (&ehci->lock, flags);
  386. switch (typeReq) {
  387. case ClearHubFeature:
  388. switch (wValue) {
  389. case C_HUB_LOCAL_POWER:
  390. case C_HUB_OVER_CURRENT:
  391. /* no hub-wide feature/status flags */
  392. break;
  393. default:
  394. goto error;
  395. }
  396. break;
  397. case ClearPortFeature:
  398. if (!wIndex || wIndex > ports)
  399. goto error;
  400. wIndex--;
  401. temp = ehci_readl(ehci, status_reg);
  402. /*
  403. * Even if OWNER is set, so the port is owned by the
  404. * companion controller, khubd needs to be able to clear
  405. * the port-change status bits (especially
  406. * USB_PORT_FEAT_C_CONNECTION).
  407. */
  408. switch (wValue) {
  409. case USB_PORT_FEAT_ENABLE:
  410. ehci_writel(ehci, temp & ~PORT_PE, status_reg);
  411. break;
  412. case USB_PORT_FEAT_C_ENABLE:
  413. ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_PEC,
  414. status_reg);
  415. break;
  416. case USB_PORT_FEAT_SUSPEND:
  417. if (temp & PORT_RESET)
  418. goto error;
  419. if (ehci->no_selective_suspend)
  420. break;
  421. if (temp & PORT_SUSPEND) {
  422. if ((temp & PORT_PE) == 0)
  423. goto error;
  424. /* resume signaling for 20 msec */
  425. temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
  426. ehci_writel(ehci, temp | PORT_RESUME,
  427. status_reg);
  428. ehci->reset_done [wIndex] = jiffies
  429. + msecs_to_jiffies (20);
  430. }
  431. break;
  432. case USB_PORT_FEAT_C_SUSPEND:
  433. /* we auto-clear this feature */
  434. break;
  435. case USB_PORT_FEAT_POWER:
  436. if (HCS_PPC (ehci->hcs_params))
  437. ehci_writel(ehci,
  438. temp & ~(PORT_RWC_BITS | PORT_POWER),
  439. status_reg);
  440. break;
  441. case USB_PORT_FEAT_C_CONNECTION:
  442. ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC,
  443. status_reg);
  444. break;
  445. case USB_PORT_FEAT_C_OVER_CURRENT:
  446. ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_OCC,
  447. status_reg);
  448. break;
  449. case USB_PORT_FEAT_C_RESET:
  450. /* GetPortStatus clears reset */
  451. break;
  452. default:
  453. goto error;
  454. }
  455. ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */
  456. break;
  457. case GetHubDescriptor:
  458. ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *)
  459. buf);
  460. break;
  461. case GetHubStatus:
  462. /* no hub-wide feature/status flags */
  463. memset (buf, 0, 4);
  464. //cpu_to_le32s ((u32 *) buf);
  465. break;
  466. case GetPortStatus:
  467. if (!wIndex || wIndex > ports)
  468. goto error;
  469. wIndex--;
  470. status = 0;
  471. temp = ehci_readl(ehci, status_reg);
  472. // wPortChange bits
  473. if (temp & PORT_CSC)
  474. status |= 1 << USB_PORT_FEAT_C_CONNECTION;
  475. if (temp & PORT_PEC)
  476. status |= 1 << USB_PORT_FEAT_C_ENABLE;
  477. if ((temp & PORT_OCC) && !ignore_oc)
  478. status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT;
  479. /* whoever resumes must GetPortStatus to complete it!! */
  480. if (temp & PORT_RESUME) {
  481. /* Remote Wakeup received? */
  482. if (!ehci->reset_done[wIndex]) {
  483. /* resume signaling for 20 msec */
  484. ehci->reset_done[wIndex] = jiffies
  485. + msecs_to_jiffies(20);
  486. /* check the port again */
  487. mod_timer(&ehci_to_hcd(ehci)->rh_timer,
  488. ehci->reset_done[wIndex]);
  489. }
  490. /* resume completed? */
  491. else if (time_after_eq(jiffies,
  492. ehci->reset_done[wIndex])) {
  493. status |= 1 << USB_PORT_FEAT_C_SUSPEND;
  494. ehci->reset_done[wIndex] = 0;
  495. /* stop resume signaling */
  496. temp = ehci_readl(ehci, status_reg);
  497. ehci_writel(ehci,
  498. temp & ~(PORT_RWC_BITS | PORT_RESUME),
  499. status_reg);
  500. retval = handshake(ehci, status_reg,
  501. PORT_RESUME, 0, 2000 /* 2msec */);
  502. if (retval != 0) {
  503. ehci_err(ehci,
  504. "port %d resume error %d\n",
  505. wIndex + 1, retval);
  506. goto error;
  507. }
  508. temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
  509. }
  510. }
  511. /* whoever resets must GetPortStatus to complete it!! */
  512. if ((temp & PORT_RESET)
  513. && time_after_eq(jiffies,
  514. ehci->reset_done[wIndex])) {
  515. status |= 1 << USB_PORT_FEAT_C_RESET;
  516. ehci->reset_done [wIndex] = 0;
  517. /* force reset to complete */
  518. ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
  519. status_reg);
  520. /* REVISIT: some hardware needs 550+ usec to clear
  521. * this bit; seems too long to spin routinely...
  522. */
  523. retval = handshake(ehci, status_reg,
  524. PORT_RESET, 0, 750);
  525. if (retval != 0) {
  526. ehci_err (ehci, "port %d reset error %d\n",
  527. wIndex + 1, retval);
  528. goto error;
  529. }
  530. /* see what we found out */
  531. temp = check_reset_complete (ehci, wIndex, status_reg,
  532. ehci_readl(ehci, status_reg));
  533. }
  534. /* transfer dedicated ports to the companion hc */
  535. if ((temp & PORT_CONNECT) &&
  536. test_bit(wIndex, &ehci->companion_ports)) {
  537. temp &= ~PORT_RWC_BITS;
  538. temp |= PORT_OWNER;
  539. ehci_writel(ehci, temp, status_reg);
  540. ehci_dbg(ehci, "port %d --> companion\n", wIndex + 1);
  541. temp = ehci_readl(ehci, status_reg);
  542. }
  543. /*
  544. * Even if OWNER is set, there's no harm letting khubd
  545. * see the wPortStatus values (they should all be 0 except
  546. * for PORT_POWER anyway).
  547. */
  548. if (temp & PORT_CONNECT) {
  549. status |= 1 << USB_PORT_FEAT_CONNECTION;
  550. // status may be from integrated TT
  551. status |= ehci_port_speed(ehci, temp);
  552. }
  553. if (temp & PORT_PE)
  554. status |= 1 << USB_PORT_FEAT_ENABLE;
  555. if (temp & (PORT_SUSPEND|PORT_RESUME))
  556. status |= 1 << USB_PORT_FEAT_SUSPEND;
  557. if (temp & PORT_OC)
  558. status |= 1 << USB_PORT_FEAT_OVER_CURRENT;
  559. if (temp & PORT_RESET)
  560. status |= 1 << USB_PORT_FEAT_RESET;
  561. if (temp & PORT_POWER)
  562. status |= 1 << USB_PORT_FEAT_POWER;
  563. #ifndef EHCI_VERBOSE_DEBUG
  564. if (status & ~0xffff) /* only if wPortChange is interesting */
  565. #endif
  566. dbg_port (ehci, "GetStatus", wIndex + 1, temp);
  567. // we "know" this alignment is good, caller used kmalloc()...
  568. *((__le32 *) buf) = cpu_to_le32 (status);
  569. break;
  570. case SetHubFeature:
  571. switch (wValue) {
  572. case C_HUB_LOCAL_POWER:
  573. case C_HUB_OVER_CURRENT:
  574. /* no hub-wide feature/status flags */
  575. break;
  576. default:
  577. goto error;
  578. }
  579. break;
  580. case SetPortFeature:
  581. selector = wIndex >> 8;
  582. wIndex &= 0xff;
  583. if (!wIndex || wIndex > ports)
  584. goto error;
  585. wIndex--;
  586. temp = ehci_readl(ehci, status_reg);
  587. if (temp & PORT_OWNER)
  588. break;
  589. temp &= ~PORT_RWC_BITS;
  590. switch (wValue) {
  591. case USB_PORT_FEAT_SUSPEND:
  592. if (ehci->no_selective_suspend)
  593. break;
  594. if ((temp & PORT_PE) == 0
  595. || (temp & PORT_RESET) != 0)
  596. goto error;
  597. if (device_may_wakeup(&hcd->self.root_hub->dev))
  598. temp |= PORT_WAKE_BITS;
  599. ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
  600. break;
  601. case USB_PORT_FEAT_POWER:
  602. if (HCS_PPC (ehci->hcs_params))
  603. ehci_writel(ehci, temp | PORT_POWER,
  604. status_reg);
  605. break;
  606. case USB_PORT_FEAT_RESET:
  607. if (temp & PORT_RESUME)
  608. goto error;
  609. /* line status bits may report this as low speed,
  610. * which can be fine if this root hub has a
  611. * transaction translator built in.
  612. */
  613. if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
  614. && !ehci_is_TDI(ehci)
  615. && PORT_USB11 (temp)) {
  616. ehci_dbg (ehci,
  617. "port %d low speed --> companion\n",
  618. wIndex + 1);
  619. temp |= PORT_OWNER;
  620. } else {
  621. ehci_vdbg (ehci, "port %d reset\n", wIndex + 1);
  622. temp |= PORT_RESET;
  623. temp &= ~PORT_PE;
  624. /*
  625. * caller must wait, then call GetPortStatus
  626. * usb 2.0 spec says 50 ms resets on root
  627. */
  628. ehci->reset_done [wIndex] = jiffies
  629. + msecs_to_jiffies (50);
  630. }
  631. ehci_writel(ehci, temp, status_reg);
  632. break;
  633. /* For downstream facing ports (these): one hub port is put
  634. * into test mode according to USB2 11.24.2.13, then the hub
  635. * must be reset (which for root hub now means rmmod+modprobe,
  636. * or else system reboot). See EHCI 2.3.9 and 4.14 for info
  637. * about the EHCI-specific stuff.
  638. */
  639. case USB_PORT_FEAT_TEST:
  640. if (!selector || selector > 5)
  641. goto error;
  642. ehci_quiesce(ehci);
  643. ehci_halt(ehci);
  644. temp |= selector << 16;
  645. ehci_writel(ehci, temp, status_reg);
  646. break;
  647. default:
  648. goto error;
  649. }
  650. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  651. break;
  652. default:
  653. error:
  654. /* "stall" on error */
  655. retval = -EPIPE;
  656. }
  657. spin_unlock_irqrestore (&ehci->lock, flags);
  658. return retval;
  659. }