ehci-hub.c 23 KB

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