ohci-hub.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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 = ohci->num_ports;
  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 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. /* undocumented erratum seen on at least rev D */
  277. if ((ohci->flags & OHCI_QUIRK_AMD756)
  278. && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) {
  279. ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n",
  280. ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP);
  281. /* retry later; "should not happen" */
  282. goto done;
  283. }
  284. /* init status */
  285. if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC))
  286. buf [0] = changed = 1;
  287. else
  288. buf [0] = 0;
  289. if (ohci->num_ports > 7) {
  290. buf [1] = 0;
  291. length++;
  292. }
  293. /* look at each port */
  294. for (i = 0; i < ohci->num_ports; i++) {
  295. u32 status = roothub_portstatus (ohci, i);
  296. if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
  297. | RH_PS_OCIC | RH_PS_PRSC)) {
  298. changed = 1;
  299. if (i < 7)
  300. buf [0] |= 1 << (i + 1);
  301. else
  302. buf [1] |= 1 << (i - 7);
  303. continue;
  304. }
  305. /* can suspend if no ports are enabled; or if all all
  306. * enabled ports are suspended AND remote wakeup is on.
  307. */
  308. if (!(status & RH_PS_CCS))
  309. continue;
  310. if ((status & RH_PS_PSS) && hcd->remote_wakeup)
  311. continue;
  312. can_suspend = 0;
  313. }
  314. done:
  315. spin_unlock_irqrestore (&ohci->lock, flags);
  316. #ifdef CONFIG_PM
  317. /* save power by suspending idle root hubs;
  318. * INTR_RD wakes us when there's work
  319. * NOTE: if we can do this, we don't need a root hub timer!
  320. */
  321. if (can_suspend
  322. && !changed
  323. && !ohci->ed_rm_list
  324. && ((OHCI_CTRL_HCFS | OHCI_SCHED_ENABLES)
  325. & ohci->hc_control)
  326. == OHCI_USB_OPER
  327. && time_after (jiffies, ohci->next_statechange)
  328. && usb_trylock_device (hcd->self.root_hub)
  329. ) {
  330. ohci_vdbg (ohci, "autosuspend\n");
  331. (void) ohci_hub_suspend (hcd);
  332. hcd->state = HC_STATE_RUNNING;
  333. usb_unlock_device (hcd->self.root_hub);
  334. }
  335. #endif
  336. return changed ? length : 0;
  337. }
  338. /*-------------------------------------------------------------------------*/
  339. static void
  340. ohci_hub_descriptor (
  341. struct ohci_hcd *ohci,
  342. struct usb_hub_descriptor *desc
  343. ) {
  344. u32 rh = roothub_a (ohci);
  345. u16 temp;
  346. desc->bDescriptorType = 0x29;
  347. desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24;
  348. desc->bHubContrCurrent = 0;
  349. desc->bNbrPorts = ohci->num_ports;
  350. temp = 1 + (ohci->num_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. memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
  365. desc->bitmap [0] = rh & RH_B_DR;
  366. if (ohci->num_ports > 7) {
  367. desc->bitmap [1] = (rh & RH_B_DR) >> 8;
  368. desc->bitmap [2] = 0xff;
  369. } else
  370. desc->bitmap [1] = 0xff;
  371. }
  372. /*-------------------------------------------------------------------------*/
  373. #ifdef CONFIG_USB_OTG
  374. static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port)
  375. {
  376. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  377. u32 status;
  378. if (!port)
  379. return -EINVAL;
  380. port--;
  381. /* start port reset before HNP protocol times out */
  382. status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]);
  383. if (!(status & RH_PS_CCS))
  384. return -ENODEV;
  385. /* khubd will finish the reset later */
  386. ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]);
  387. return 0;
  388. }
  389. static void start_hnp(struct ohci_hcd *ohci);
  390. #else
  391. #define ohci_start_port_reset NULL
  392. #endif
  393. /*-------------------------------------------------------------------------*/
  394. /* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling,
  395. * not necessarily continuous ... to guard against resume signaling.
  396. * The short timeout is safe for non-root hubs, and is backward-compatible
  397. * with earlier Linux hosts.
  398. */
  399. #ifdef CONFIG_USB_SUSPEND
  400. #define PORT_RESET_MSEC 50
  401. #else
  402. #define PORT_RESET_MSEC 10
  403. #endif
  404. /* this timer value might be vendor-specific ... */
  405. #define PORT_RESET_HW_MSEC 10
  406. /* wrap-aware logic morphed from <linux/jiffies.h> */
  407. #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
  408. /* called from some task, normally khubd */
  409. static inline void root_port_reset (struct ohci_hcd *ohci, unsigned port)
  410. {
  411. __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
  412. u32 temp;
  413. u16 now = ohci_readl(ohci, &ohci->regs->fmnumber);
  414. u16 reset_done = now + PORT_RESET_MSEC;
  415. /* build a "continuous enough" reset signal, with up to
  416. * 3msec gap between pulses. scheduler HZ==100 must work;
  417. * this might need to be deadline-scheduled.
  418. */
  419. do {
  420. /* spin until any current reset finishes */
  421. for (;;) {
  422. temp = ohci_readl (ohci, portstat);
  423. if (!(temp & RH_PS_PRS))
  424. break;
  425. udelay (500);
  426. }
  427. if (!(temp & RH_PS_CCS))
  428. break;
  429. if (temp & RH_PS_PRSC)
  430. ohci_writel (ohci, RH_PS_PRSC, portstat);
  431. /* start the next reset, sleep till it's probably done */
  432. ohci_writel (ohci, RH_PS_PRS, portstat);
  433. msleep(PORT_RESET_HW_MSEC);
  434. now = ohci_readl(ohci, &ohci->regs->fmnumber);
  435. } while (tick_before(now, reset_done));
  436. /* caller synchronizes using PRSC */
  437. }
  438. static int ohci_hub_control (
  439. struct usb_hcd *hcd,
  440. u16 typeReq,
  441. u16 wValue,
  442. u16 wIndex,
  443. char *buf,
  444. u16 wLength
  445. ) {
  446. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  447. int ports = hcd_to_bus (hcd)->root_hub->maxchild;
  448. u32 temp;
  449. int retval = 0;
  450. switch (typeReq) {
  451. case ClearHubFeature:
  452. switch (wValue) {
  453. case C_HUB_OVER_CURRENT:
  454. ohci_writel (ohci, RH_HS_OCIC,
  455. &ohci->regs->roothub.status);
  456. case C_HUB_LOCAL_POWER:
  457. break;
  458. default:
  459. goto error;
  460. }
  461. break;
  462. case ClearPortFeature:
  463. if (!wIndex || wIndex > ports)
  464. goto error;
  465. wIndex--;
  466. switch (wValue) {
  467. case USB_PORT_FEAT_ENABLE:
  468. temp = RH_PS_CCS;
  469. break;
  470. case USB_PORT_FEAT_C_ENABLE:
  471. temp = RH_PS_PESC;
  472. break;
  473. case USB_PORT_FEAT_SUSPEND:
  474. temp = RH_PS_POCI;
  475. if ((ohci->hc_control & OHCI_CTRL_HCFS)
  476. != OHCI_USB_OPER)
  477. schedule_work (&ohci->rh_resume);
  478. break;
  479. case USB_PORT_FEAT_C_SUSPEND:
  480. temp = RH_PS_PSSC;
  481. break;
  482. case USB_PORT_FEAT_POWER:
  483. temp = RH_PS_LSDA;
  484. break;
  485. case USB_PORT_FEAT_C_CONNECTION:
  486. temp = RH_PS_CSC;
  487. break;
  488. case USB_PORT_FEAT_C_OVER_CURRENT:
  489. temp = RH_PS_OCIC;
  490. break;
  491. case USB_PORT_FEAT_C_RESET:
  492. temp = RH_PS_PRSC;
  493. break;
  494. default:
  495. goto error;
  496. }
  497. ohci_writel (ohci, temp,
  498. &ohci->regs->roothub.portstatus [wIndex]);
  499. // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]);
  500. break;
  501. case GetHubDescriptor:
  502. ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf);
  503. break;
  504. case GetHubStatus:
  505. temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE);
  506. *(__le32 *) buf = cpu_to_le32 (temp);
  507. break;
  508. case GetPortStatus:
  509. if (!wIndex || wIndex > ports)
  510. goto error;
  511. wIndex--;
  512. temp = roothub_portstatus (ohci, wIndex);
  513. *(__le32 *) buf = cpu_to_le32 (temp);
  514. #ifndef OHCI_VERBOSE_DEBUG
  515. if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
  516. #endif
  517. dbg_port (ohci, "GetStatus", wIndex, temp);
  518. break;
  519. case SetHubFeature:
  520. switch (wValue) {
  521. case C_HUB_OVER_CURRENT:
  522. // FIXME: this can be cleared, yes?
  523. case C_HUB_LOCAL_POWER:
  524. break;
  525. default:
  526. goto error;
  527. }
  528. break;
  529. case SetPortFeature:
  530. if (!wIndex || wIndex > ports)
  531. goto error;
  532. wIndex--;
  533. switch (wValue) {
  534. case USB_PORT_FEAT_SUSPEND:
  535. #ifdef CONFIG_USB_OTG
  536. if (hcd->self.otg_port == (wIndex + 1)
  537. && hcd->self.b_hnp_enable)
  538. start_hnp(ohci);
  539. else
  540. #endif
  541. ohci_writel (ohci, RH_PS_PSS,
  542. &ohci->regs->roothub.portstatus [wIndex]);
  543. break;
  544. case USB_PORT_FEAT_POWER:
  545. ohci_writel (ohci, RH_PS_PPS,
  546. &ohci->regs->roothub.portstatus [wIndex]);
  547. break;
  548. case USB_PORT_FEAT_RESET:
  549. root_port_reset (ohci, wIndex);
  550. break;
  551. default:
  552. goto error;
  553. }
  554. break;
  555. default:
  556. error:
  557. /* "protocol stall" on error */
  558. retval = -EPIPE;
  559. }
  560. return retval;
  561. }