ohci-hub.c 16 KB

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