ohci-hub.c 17 KB

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