ohci-hub.c 18 KB

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