ohci-hub.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
  6. *
  7. * This file is licenced under GPL
  8. */
  9. /*-------------------------------------------------------------------------*/
  10. /*
  11. * OHCI Root Hub ... the nonsharable stuff
  12. */
  13. #define dbg_port(hc,label,num,value) \
  14. ohci_dbg (hc, \
  15. "%s roothub.portstatus [%d] " \
  16. "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
  17. label, num, temp, \
  18. (temp & RH_PS_PRSC) ? " PRSC" : "", \
  19. (temp & RH_PS_OCIC) ? " OCIC" : "", \
  20. (temp & RH_PS_PSSC) ? " PSSC" : "", \
  21. (temp & RH_PS_PESC) ? " PESC" : "", \
  22. (temp & RH_PS_CSC) ? " CSC" : "", \
  23. \
  24. (temp & RH_PS_LSDA) ? " LSDA" : "", \
  25. (temp & RH_PS_PPS) ? " PPS" : "", \
  26. (temp & RH_PS_PRS) ? " PRS" : "", \
  27. (temp & RH_PS_POCI) ? " POCI" : "", \
  28. (temp & RH_PS_PSS) ? " PSS" : "", \
  29. \
  30. (temp & RH_PS_PES) ? " PES" : "", \
  31. (temp & RH_PS_CCS) ? " CCS" : "" \
  32. );
  33. /*-------------------------------------------------------------------------*/
  34. #if defined(CONFIG_USB_SUSPEND) || defined(CONFIG_PM)
  35. #define OHCI_SCHED_ENABLES \
  36. (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
  37. static void dl_done_list (struct ohci_hcd *, struct pt_regs *);
  38. static void finish_unlinks (struct ohci_hcd *, u16 , struct pt_regs *);
  39. static int ohci_restart (struct ohci_hcd *ohci);
  40. static int ohci_hub_suspend (struct usb_hcd *hcd)
  41. {
  42. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  43. int status = 0;
  44. unsigned long flags;
  45. spin_lock_irqsave (&ohci->lock, flags);
  46. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  47. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  48. case OHCI_USB_RESUME:
  49. ohci_dbg (ohci, "resume/suspend?\n");
  50. ohci->hc_control &= ~OHCI_CTRL_HCFS;
  51. ohci->hc_control |= OHCI_USB_RESET;
  52. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  53. (void) ohci_readl (ohci, &ohci->regs->control);
  54. /* FALL THROUGH */
  55. case OHCI_USB_RESET:
  56. status = -EBUSY;
  57. ohci_dbg (ohci, "needs reinit!\n");
  58. goto done;
  59. case OHCI_USB_SUSPEND:
  60. ohci_dbg (ohci, "already suspended\n");
  61. goto done;
  62. }
  63. ohci_dbg (ohci, "suspend root hub\n");
  64. /* First stop any processing */
  65. hcd->state = HC_STATE_QUIESCING;
  66. if (ohci->hc_control & OHCI_SCHED_ENABLES) {
  67. int limit;
  68. ohci->hc_control &= ~OHCI_SCHED_ENABLES;
  69. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  70. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  71. ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus);
  72. /* sched disables take effect on the next frame,
  73. * then the last WDH could take 6+ msec
  74. */
  75. ohci_dbg (ohci, "stopping schedules ...\n");
  76. limit = 2000;
  77. while (limit > 0) {
  78. udelay (250);
  79. limit =- 250;
  80. if (ohci_readl (ohci, &ohci->regs->intrstatus)
  81. & OHCI_INTR_SF)
  82. break;
  83. }
  84. dl_done_list (ohci, NULL);
  85. mdelay (7);
  86. }
  87. dl_done_list (ohci, NULL);
  88. finish_unlinks (ohci, ohci_frame_no(ohci), NULL);
  89. ohci_writel (ohci, ohci_readl (ohci, &ohci->regs->intrstatus),
  90. &ohci->regs->intrstatus);
  91. /* maybe resume can wake root hub */
  92. if (hcd->remote_wakeup)
  93. ohci->hc_control |= OHCI_CTRL_RWE;
  94. else
  95. ohci->hc_control &= ~OHCI_CTRL_RWE;
  96. /* Suspend hub */
  97. ohci->hc_control &= ~OHCI_CTRL_HCFS;
  98. ohci->hc_control |= OHCI_USB_SUSPEND;
  99. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  100. (void) ohci_readl (ohci, &ohci->regs->control);
  101. /* no resumes until devices finish suspending */
  102. ohci->next_statechange = jiffies + msecs_to_jiffies (5);
  103. done:
  104. if (status == 0)
  105. hcd->state = HC_STATE_SUSPENDED;
  106. spin_unlock_irqrestore (&ohci->lock, flags);
  107. return status;
  108. }
  109. static inline struct ed *find_head (struct ed *ed)
  110. {
  111. /* for bulk and control lists */
  112. while (ed->ed_prev)
  113. ed = ed->ed_prev;
  114. return ed;
  115. }
  116. /* caller has locked the root hub */
  117. static int ohci_hub_resume (struct usb_hcd *hcd)
  118. {
  119. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  120. u32 temp, enables;
  121. int status = -EINPROGRESS;
  122. if (time_before (jiffies, ohci->next_statechange))
  123. msleep(5);
  124. spin_lock_irq (&ohci->lock);
  125. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  126. if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
  127. /* this can happen after suspend-to-disk */
  128. if (hcd->state == HC_STATE_RESUMING) {
  129. ohci_dbg (ohci, "BIOS/SMM active, control %03x\n",
  130. ohci->hc_control);
  131. status = -EBUSY;
  132. /* this happens when pmcore resumes HC then root */
  133. } else {
  134. ohci_dbg (ohci, "duplicate resume\n");
  135. status = 0;
  136. }
  137. } else switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  138. case OHCI_USB_SUSPEND:
  139. ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES);
  140. ohci->hc_control |= OHCI_USB_RESUME;
  141. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  142. (void) ohci_readl (ohci, &ohci->regs->control);
  143. ohci_dbg (ohci, "resume root hub\n");
  144. break;
  145. case OHCI_USB_RESUME:
  146. /* HCFS changes sometime after INTR_RD */
  147. ohci_info (ohci, "wakeup\n");
  148. break;
  149. case OHCI_USB_OPER:
  150. ohci_dbg (ohci, "already resumed\n");
  151. status = 0;
  152. break;
  153. default: /* RESET, we lost power */
  154. ohci_dbg (ohci, "root hub hardware reset\n");
  155. status = -EBUSY;
  156. }
  157. spin_unlock_irq (&ohci->lock);
  158. if (status == -EBUSY) {
  159. (void) ohci_init (ohci);
  160. return ohci_restart (ohci);
  161. }
  162. if (status != -EINPROGRESS)
  163. return status;
  164. temp = roothub_a (ohci) & RH_A_NDP;
  165. enables = 0;
  166. while (temp--) {
  167. u32 stat = ohci_readl (ohci,
  168. &ohci->regs->roothub.portstatus [temp]);
  169. /* force global, not selective, resume */
  170. if (!(stat & RH_PS_PSS))
  171. continue;
  172. ohci_writel (ohci, RH_PS_POCI,
  173. &ohci->regs->roothub.portstatus [temp]);
  174. }
  175. /* Some controllers (lucent erratum) need extra-long delays */
  176. hcd->state = HC_STATE_RESUMING;
  177. mdelay (20 /* usb 11.5.1.10 */ + 15);
  178. temp = ohci_readl (ohci, &ohci->regs->control);
  179. temp &= OHCI_CTRL_HCFS;
  180. if (temp != OHCI_USB_RESUME) {
  181. ohci_err (ohci, "controller won't resume\n");
  182. return -EBUSY;
  183. }
  184. /* disable old schedule state, reinit from scratch */
  185. ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
  186. ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent);
  187. ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
  188. ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent);
  189. ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent);
  190. ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
  191. /* Sometimes PCI D3 suspend trashes frame timings ... */
  192. periodic_reinit (ohci);
  193. /* interrupts might have been disabled */
  194. ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable);
  195. if (ohci->ed_rm_list)
  196. ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
  197. ohci_writel (ohci, ohci_readl (ohci, &ohci->regs->intrstatus),
  198. &ohci->regs->intrstatus);
  199. /* Then re-enable operations */
  200. ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control);
  201. (void) ohci_readl (ohci, &ohci->regs->control);
  202. msleep (3);
  203. temp = OHCI_CONTROL_INIT | OHCI_USB_OPER;
  204. if (hcd->can_wakeup)
  205. temp |= OHCI_CTRL_RWC;
  206. ohci->hc_control = temp;
  207. ohci_writel (ohci, temp, &ohci->regs->control);
  208. (void) ohci_readl (ohci, &ohci->regs->control);
  209. /* TRSMRCY */
  210. msleep (10);
  211. /* keep it alive for ~5x suspend + resume costs */
  212. ohci->next_statechange = jiffies + msecs_to_jiffies (250);
  213. /* maybe turn schedules back on */
  214. enables = 0;
  215. temp = 0;
  216. if (!ohci->ed_rm_list) {
  217. if (ohci->ed_controltail) {
  218. ohci_writel (ohci,
  219. find_head (ohci->ed_controltail)->dma,
  220. &ohci->regs->ed_controlhead);
  221. enables |= OHCI_CTRL_CLE;
  222. temp |= OHCI_CLF;
  223. }
  224. if (ohci->ed_bulktail) {
  225. ohci_writel (ohci, find_head (ohci->ed_bulktail)->dma,
  226. &ohci->regs->ed_bulkhead);
  227. enables |= OHCI_CTRL_BLE;
  228. temp |= OHCI_BLF;
  229. }
  230. }
  231. if (hcd->self.bandwidth_isoc_reqs || hcd->self.bandwidth_int_reqs)
  232. enables |= OHCI_CTRL_PLE|OHCI_CTRL_IE;
  233. if (enables) {
  234. ohci_dbg (ohci, "restarting schedules ... %08x\n", enables);
  235. ohci->hc_control |= enables;
  236. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  237. if (temp)
  238. ohci_writel (ohci, temp, &ohci->regs->cmdstatus);
  239. (void) ohci_readl (ohci, &ohci->regs->control);
  240. }
  241. hcd->state = HC_STATE_RUNNING;
  242. return 0;
  243. }
  244. static void ohci_rh_resume (void *_hcd)
  245. {
  246. struct usb_hcd *hcd = _hcd;
  247. usb_lock_device (hcd->self.root_hub);
  248. (void) ohci_hub_resume (hcd);
  249. usb_unlock_device (hcd->self.root_hub);
  250. }
  251. #else
  252. static void ohci_rh_resume (void *_hcd)
  253. {
  254. struct ohci_hcd *ohci = hcd_to_ohci (_hcd);
  255. ohci_dbg(ohci, "rh_resume ??\n");
  256. }
  257. #endif /* CONFIG_USB_SUSPEND || CONFIG_PM */
  258. /*-------------------------------------------------------------------------*/
  259. /* build "status change" packet (one or two bytes) from HC registers */
  260. static int
  261. ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
  262. {
  263. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  264. int ports, i, changed = 0, length = 1;
  265. int can_suspend = hcd->can_wakeup;
  266. unsigned long flags;
  267. spin_lock_irqsave (&ohci->lock, flags);
  268. /* handle autosuspended root: finish resuming before
  269. * letting khubd or root hub timer see state changes.
  270. */
  271. if ((ohci->hc_control & OHCI_CTRL_HCFS) != OHCI_USB_OPER
  272. || !HC_IS_RUNNING(hcd->state)) {
  273. can_suspend = 0;
  274. goto done;
  275. }
  276. ports = roothub_a (ohci) & RH_A_NDP;
  277. if (ports > MAX_ROOT_PORTS) {
  278. ohci_err (ohci, "bogus NDP=%d, rereads as NDP=%d\n", ports,
  279. ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP);
  280. /* retry later; "should not happen" */
  281. goto done;
  282. }
  283. /* init status */
  284. if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC))
  285. buf [0] = changed = 1;
  286. else
  287. buf [0] = 0;
  288. if (ports > 7) {
  289. buf [1] = 0;
  290. length++;
  291. }
  292. /* look at each port */
  293. for (i = 0; i < ports; i++) {
  294. u32 status = roothub_portstatus (ohci, i);
  295. if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
  296. | RH_PS_OCIC | RH_PS_PRSC)) {
  297. changed = 1;
  298. if (i < 7)
  299. buf [0] |= 1 << (i + 1);
  300. else
  301. buf [1] |= 1 << (i - 7);
  302. continue;
  303. }
  304. /* can suspend if no ports are enabled; or if all all
  305. * enabled ports are suspended AND remote wakeup is on.
  306. */
  307. if (!(status & RH_PS_CCS))
  308. continue;
  309. if ((status & RH_PS_PSS) && hcd->remote_wakeup)
  310. continue;
  311. can_suspend = 0;
  312. }
  313. done:
  314. spin_unlock_irqrestore (&ohci->lock, flags);
  315. #ifdef CONFIG_PM
  316. /* save power by suspending idle root hubs;
  317. * INTR_RD wakes us when there's work
  318. * NOTE: if we can do this, we don't need a root hub timer!
  319. */
  320. if (can_suspend
  321. && !changed
  322. && !ohci->ed_rm_list
  323. && ((OHCI_CTRL_HCFS | OHCI_SCHED_ENABLES)
  324. & ohci->hc_control)
  325. == OHCI_USB_OPER
  326. && time_after (jiffies, ohci->next_statechange)
  327. && usb_trylock_device (hcd->self.root_hub)
  328. ) {
  329. ohci_vdbg (ohci, "autosuspend\n");
  330. (void) ohci_hub_suspend (hcd);
  331. hcd->state = HC_STATE_RUNNING;
  332. usb_unlock_device (hcd->self.root_hub);
  333. }
  334. #endif
  335. return changed ? length : 0;
  336. }
  337. /*-------------------------------------------------------------------------*/
  338. static void
  339. ohci_hub_descriptor (
  340. struct ohci_hcd *ohci,
  341. struct usb_hub_descriptor *desc
  342. ) {
  343. u32 rh = roothub_a (ohci);
  344. int ports = rh & RH_A_NDP;
  345. u16 temp;
  346. desc->bDescriptorType = 0x29;
  347. desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24;
  348. desc->bHubContrCurrent = 0;
  349. desc->bNbrPorts = ports;
  350. temp = 1 + (ports / 8);
  351. desc->bDescLength = 7 + 2 * temp;
  352. temp = 0;
  353. if (rh & RH_A_NPS) /* no power switching? */
  354. temp |= 0x0002;
  355. if (rh & RH_A_PSM) /* per-port power switching? */
  356. temp |= 0x0001;
  357. if (rh & RH_A_NOCP) /* no overcurrent reporting? */
  358. temp |= 0x0010;
  359. else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */
  360. temp |= 0x0008;
  361. desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp);
  362. /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
  363. rh = roothub_b (ohci);
  364. desc->bitmap [0] = rh & RH_B_DR;
  365. if (ports > 7) {
  366. desc->bitmap [1] = (rh & RH_B_DR) >> 8;
  367. desc->bitmap [2] = desc->bitmap [3] = 0xff;
  368. } else
  369. desc->bitmap [1] = 0xff;
  370. }
  371. /*-------------------------------------------------------------------------*/
  372. #ifdef CONFIG_USB_OTG
  373. static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port)
  374. {
  375. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  376. u32 status;
  377. if (!port)
  378. return -EINVAL;
  379. port--;
  380. /* start port reset before HNP protocol times out */
  381. status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]);
  382. if (!(status & RH_PS_CCS))
  383. return -ENODEV;
  384. /* khubd will finish the reset later */
  385. ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]);
  386. return 0;
  387. }
  388. static void start_hnp(struct ohci_hcd *ohci);
  389. #else
  390. #define ohci_start_port_reset NULL
  391. #endif
  392. /*-------------------------------------------------------------------------*/
  393. /* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling,
  394. * not necessarily continuous ... to guard against resume signaling.
  395. * The short timeout is safe for non-root hubs, and is backward-compatible
  396. * with earlier Linux hosts.
  397. */
  398. #ifdef CONFIG_USB_SUSPEND
  399. #define PORT_RESET_MSEC 50
  400. #else
  401. #define PORT_RESET_MSEC 10
  402. #endif
  403. /* this timer value might be vendor-specific ... */
  404. #define PORT_RESET_HW_MSEC 10
  405. /* wrap-aware logic morphed from <linux/jiffies.h> */
  406. #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
  407. /* called from some task, normally khubd */
  408. static inline void root_port_reset (struct ohci_hcd *ohci, unsigned port)
  409. {
  410. __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
  411. u32 temp;
  412. u16 now = ohci_readl(ohci, &ohci->regs->fmnumber);
  413. u16 reset_done = now + PORT_RESET_MSEC;
  414. /* build a "continuous enough" reset signal, with up to
  415. * 3msec gap between pulses. scheduler HZ==100 must work;
  416. * this might need to be deadline-scheduled.
  417. */
  418. do {
  419. /* spin until any current reset finishes */
  420. for (;;) {
  421. temp = ohci_readl (ohci, portstat);
  422. if (!(temp & RH_PS_PRS))
  423. break;
  424. udelay (500);
  425. }
  426. if (!(temp & RH_PS_CCS))
  427. break;
  428. if (temp & RH_PS_PRSC)
  429. ohci_writel (ohci, RH_PS_PRSC, portstat);
  430. /* start the next reset, sleep till it's probably done */
  431. ohci_writel (ohci, RH_PS_PRS, portstat);
  432. msleep(PORT_RESET_HW_MSEC);
  433. now = ohci_readl(ohci, &ohci->regs->fmnumber);
  434. } while (tick_before(now, reset_done));
  435. /* caller synchronizes using PRSC */
  436. }
  437. static int ohci_hub_control (
  438. struct usb_hcd *hcd,
  439. u16 typeReq,
  440. u16 wValue,
  441. u16 wIndex,
  442. char *buf,
  443. u16 wLength
  444. ) {
  445. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  446. int ports = hcd_to_bus (hcd)->root_hub->maxchild;
  447. u32 temp;
  448. int retval = 0;
  449. switch (typeReq) {
  450. case ClearHubFeature:
  451. switch (wValue) {
  452. case C_HUB_OVER_CURRENT:
  453. ohci_writel (ohci, RH_HS_OCIC,
  454. &ohci->regs->roothub.status);
  455. case C_HUB_LOCAL_POWER:
  456. break;
  457. default:
  458. goto error;
  459. }
  460. break;
  461. case ClearPortFeature:
  462. if (!wIndex || wIndex > ports)
  463. goto error;
  464. wIndex--;
  465. switch (wValue) {
  466. case USB_PORT_FEAT_ENABLE:
  467. temp = RH_PS_CCS;
  468. break;
  469. case USB_PORT_FEAT_C_ENABLE:
  470. temp = RH_PS_PESC;
  471. break;
  472. case USB_PORT_FEAT_SUSPEND:
  473. temp = RH_PS_POCI;
  474. if ((ohci->hc_control & OHCI_CTRL_HCFS)
  475. != OHCI_USB_OPER)
  476. schedule_work (&ohci->rh_resume);
  477. break;
  478. case USB_PORT_FEAT_C_SUSPEND:
  479. temp = RH_PS_PSSC;
  480. break;
  481. case USB_PORT_FEAT_POWER:
  482. temp = RH_PS_LSDA;
  483. break;
  484. case USB_PORT_FEAT_C_CONNECTION:
  485. temp = RH_PS_CSC;
  486. break;
  487. case USB_PORT_FEAT_C_OVER_CURRENT:
  488. temp = RH_PS_OCIC;
  489. break;
  490. case USB_PORT_FEAT_C_RESET:
  491. temp = RH_PS_PRSC;
  492. break;
  493. default:
  494. goto error;
  495. }
  496. ohci_writel (ohci, temp,
  497. &ohci->regs->roothub.portstatus [wIndex]);
  498. // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]);
  499. break;
  500. case GetHubDescriptor:
  501. ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf);
  502. break;
  503. case GetHubStatus:
  504. temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE);
  505. *(__le32 *) buf = cpu_to_le32 (temp);
  506. break;
  507. case GetPortStatus:
  508. if (!wIndex || wIndex > ports)
  509. goto error;
  510. wIndex--;
  511. temp = roothub_portstatus (ohci, wIndex);
  512. *(__le32 *) buf = cpu_to_le32 (temp);
  513. #ifndef OHCI_VERBOSE_DEBUG
  514. if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
  515. #endif
  516. dbg_port (ohci, "GetStatus", wIndex, temp);
  517. break;
  518. case SetHubFeature:
  519. switch (wValue) {
  520. case C_HUB_OVER_CURRENT:
  521. // FIXME: this can be cleared, yes?
  522. case C_HUB_LOCAL_POWER:
  523. break;
  524. default:
  525. goto error;
  526. }
  527. break;
  528. case SetPortFeature:
  529. if (!wIndex || wIndex > ports)
  530. goto error;
  531. wIndex--;
  532. switch (wValue) {
  533. case USB_PORT_FEAT_SUSPEND:
  534. #ifdef CONFIG_USB_OTG
  535. if (hcd->self.otg_port == (wIndex + 1)
  536. && hcd->self.b_hnp_enable)
  537. start_hnp(ohci);
  538. else
  539. #endif
  540. ohci_writel (ohci, RH_PS_PSS,
  541. &ohci->regs->roothub.portstatus [wIndex]);
  542. break;
  543. case USB_PORT_FEAT_POWER:
  544. ohci_writel (ohci, RH_PS_PPS,
  545. &ohci->regs->roothub.portstatus [wIndex]);
  546. break;
  547. case USB_PORT_FEAT_RESET:
  548. root_port_reset (ohci, wIndex);
  549. break;
  550. default:
  551. goto error;
  552. }
  553. break;
  554. default:
  555. error:
  556. /* "protocol stall" on error */
  557. retval = -EPIPE;
  558. }
  559. return retval;
  560. }