ohci-hub.c 17 KB

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