ohci-hub.c 18 KB

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