ohci-hub.c 18 KB

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