ohci-hub.c 18 KB

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