ehci-hub.c 23 KB

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