ohci-hub.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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_rh_suspend (struct ohci_hcd *ohci, int autostop)
  50. __releases(ohci->lock)
  51. __acquires(ohci->lock)
  52. {
  53. int status = 0;
  54. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  55. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  56. case OHCI_USB_RESUME:
  57. ohci_dbg (ohci, "resume/suspend?\n");
  58. ohci->hc_control &= ~OHCI_CTRL_HCFS;
  59. ohci->hc_control |= OHCI_USB_RESET;
  60. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  61. (void) ohci_readl (ohci, &ohci->regs->control);
  62. /* FALL THROUGH */
  63. case OHCI_USB_RESET:
  64. status = -EBUSY;
  65. ohci_dbg (ohci, "needs reinit!\n");
  66. goto done;
  67. case OHCI_USB_SUSPEND:
  68. if (!ohci->autostop) {
  69. ohci_dbg (ohci, "already suspended\n");
  70. goto done;
  71. }
  72. }
  73. ohci_dbg (ohci, "%s root hub\n",
  74. autostop ? "auto-stop" : "suspend");
  75. /* First stop any processing */
  76. if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) {
  77. ohci->hc_control &= ~OHCI_SCHED_ENABLES;
  78. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  79. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  80. ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus);
  81. /* sched disables take effect on the next frame,
  82. * then the last WDH could take 6+ msec
  83. */
  84. ohci_dbg (ohci, "stopping schedules ...\n");
  85. ohci->autostop = 0;
  86. spin_unlock_irq (&ohci->lock);
  87. msleep (8);
  88. spin_lock_irq (&ohci->lock);
  89. }
  90. dl_done_list (ohci);
  91. finish_unlinks (ohci, ohci_frame_no(ohci));
  92. /* maybe resume can wake root hub */
  93. if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev) ||
  94. autostop)
  95. ohci->hc_control |= OHCI_CTRL_RWE;
  96. else {
  97. ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable);
  98. ohci->hc_control &= ~OHCI_CTRL_RWE;
  99. }
  100. /* Suspend hub ... this is the "global (to this bus) suspend" mode,
  101. * which doesn't imply ports will first be individually suspended.
  102. */
  103. ohci->hc_control &= ~OHCI_CTRL_HCFS;
  104. ohci->hc_control |= OHCI_USB_SUSPEND;
  105. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  106. (void) ohci_readl (ohci, &ohci->regs->control);
  107. /* no resumes until devices finish suspending */
  108. if (!autostop) {
  109. ohci->next_statechange = jiffies + msecs_to_jiffies (5);
  110. ohci->autostop = 0;
  111. }
  112. done:
  113. return status;
  114. }
  115. static inline struct ed *find_head (struct ed *ed)
  116. {
  117. /* for bulk and control lists */
  118. while (ed->ed_prev)
  119. ed = ed->ed_prev;
  120. return ed;
  121. }
  122. /* caller has locked the root hub */
  123. static int ohci_rh_resume (struct ohci_hcd *ohci)
  124. __releases(ohci->lock)
  125. __acquires(ohci->lock)
  126. {
  127. struct usb_hcd *hcd = ohci_to_hcd (ohci);
  128. u32 temp, enables;
  129. int status = -EINPROGRESS;
  130. int autostopped = ohci->autostop;
  131. ohci->autostop = 0;
  132. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  133. if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
  134. /* this can happen after resuming a swsusp snapshot */
  135. if (hcd->state == HC_STATE_RESUMING) {
  136. ohci_dbg (ohci, "BIOS/SMM active, control %03x\n",
  137. ohci->hc_control);
  138. status = -EBUSY;
  139. /* this happens when pmcore resumes HC then root */
  140. } else {
  141. ohci_dbg (ohci, "duplicate resume\n");
  142. status = 0;
  143. }
  144. } else switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  145. case OHCI_USB_SUSPEND:
  146. ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES);
  147. ohci->hc_control |= OHCI_USB_RESUME;
  148. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  149. (void) ohci_readl (ohci, &ohci->regs->control);
  150. ohci_dbg (ohci, "%s root hub\n",
  151. autostopped ? "auto-start" : "resume");
  152. break;
  153. case OHCI_USB_RESUME:
  154. /* HCFS changes sometime after INTR_RD */
  155. ohci_dbg(ohci, "%swakeup root hub\n",
  156. autostopped ? "auto-" : "");
  157. break;
  158. case OHCI_USB_OPER:
  159. /* this can happen after resuming a swsusp snapshot */
  160. ohci_dbg (ohci, "snapshot resume? reinit\n");
  161. status = -EBUSY;
  162. break;
  163. default: /* RESET, we lost power */
  164. ohci_dbg (ohci, "lost power\n");
  165. status = -EBUSY;
  166. }
  167. if (status == -EBUSY) {
  168. if (!autostopped) {
  169. spin_unlock_irq (&ohci->lock);
  170. (void) ohci_init (ohci);
  171. status = ohci_restart (ohci);
  172. usb_root_hub_lost_power(hcd->self.root_hub);
  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. if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
  366. goto done;
  367. /* undocumented erratum seen on at least rev D */
  368. if ((ohci->flags & OHCI_QUIRK_AMD756)
  369. && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) {
  370. ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n",
  371. ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP);
  372. /* retry later; "should not happen" */
  373. goto done;
  374. }
  375. /* init status */
  376. if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC))
  377. buf [0] = changed = 1;
  378. else
  379. buf [0] = 0;
  380. if (ohci->num_ports > 7) {
  381. buf [1] = 0;
  382. length++;
  383. }
  384. /* look at each port */
  385. for (i = 0; i < ohci->num_ports; i++) {
  386. u32 status = roothub_portstatus (ohci, i);
  387. /* can't autostop if ports are connected */
  388. any_connected |= (status & RH_PS_CCS);
  389. if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
  390. | RH_PS_OCIC | RH_PS_PRSC)) {
  391. changed = 1;
  392. if (i < 7)
  393. buf [0] |= 1 << (i + 1);
  394. else
  395. buf [1] |= 1 << (i - 7);
  396. }
  397. }
  398. hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed,
  399. any_connected);
  400. done:
  401. spin_unlock_irqrestore (&ohci->lock, flags);
  402. return changed ? length : 0;
  403. }
  404. /*-------------------------------------------------------------------------*/
  405. static void
  406. ohci_hub_descriptor (
  407. struct ohci_hcd *ohci,
  408. struct usb_hub_descriptor *desc
  409. ) {
  410. u32 rh = roothub_a (ohci);
  411. u16 temp;
  412. desc->bDescriptorType = 0x29;
  413. desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24;
  414. desc->bHubContrCurrent = 0;
  415. desc->bNbrPorts = ohci->num_ports;
  416. temp = 1 + (ohci->num_ports / 8);
  417. desc->bDescLength = 7 + 2 * temp;
  418. temp = 0;
  419. if (rh & RH_A_NPS) /* no power switching? */
  420. temp |= 0x0002;
  421. if (rh & RH_A_PSM) /* per-port power switching? */
  422. temp |= 0x0001;
  423. if (rh & RH_A_NOCP) /* no overcurrent reporting? */
  424. temp |= 0x0010;
  425. else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */
  426. temp |= 0x0008;
  427. desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp);
  428. /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
  429. rh = roothub_b (ohci);
  430. memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
  431. desc->bitmap [0] = rh & RH_B_DR;
  432. if (ohci->num_ports > 7) {
  433. desc->bitmap [1] = (rh & RH_B_DR) >> 8;
  434. desc->bitmap [2] = 0xff;
  435. } else
  436. desc->bitmap [1] = 0xff;
  437. }
  438. /*-------------------------------------------------------------------------*/
  439. #ifdef CONFIG_USB_OTG
  440. static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port)
  441. {
  442. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  443. u32 status;
  444. if (!port)
  445. return -EINVAL;
  446. port--;
  447. /* start port reset before HNP protocol times out */
  448. status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]);
  449. if (!(status & RH_PS_CCS))
  450. return -ENODEV;
  451. /* khubd will finish the reset later */
  452. ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]);
  453. return 0;
  454. }
  455. static void start_hnp(struct ohci_hcd *ohci);
  456. #else
  457. #define ohci_start_port_reset NULL
  458. #endif
  459. /*-------------------------------------------------------------------------*/
  460. /* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling,
  461. * not necessarily continuous ... to guard against resume signaling.
  462. * The short timeout is safe for non-root hubs, and is backward-compatible
  463. * with earlier Linux hosts.
  464. */
  465. #ifdef CONFIG_USB_SUSPEND
  466. #define PORT_RESET_MSEC 50
  467. #else
  468. #define PORT_RESET_MSEC 10
  469. #endif
  470. /* this timer value might be vendor-specific ... */
  471. #define PORT_RESET_HW_MSEC 10
  472. /* wrap-aware logic morphed from <linux/jiffies.h> */
  473. #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
  474. /* called from some task, normally khubd */
  475. static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
  476. {
  477. __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
  478. u32 temp;
  479. u16 now = ohci_readl(ohci, &ohci->regs->fmnumber);
  480. u16 reset_done = now + PORT_RESET_MSEC;
  481. /* build a "continuous enough" reset signal, with up to
  482. * 3msec gap between pulses. scheduler HZ==100 must work;
  483. * this might need to be deadline-scheduled.
  484. */
  485. do {
  486. /* spin until any current reset finishes */
  487. for (;;) {
  488. temp = ohci_readl (ohci, portstat);
  489. /* handle e.g. CardBus eject */
  490. if (temp == ~(u32)0)
  491. return -ESHUTDOWN;
  492. if (!(temp & RH_PS_PRS))
  493. break;
  494. udelay (500);
  495. }
  496. if (!(temp & RH_PS_CCS))
  497. break;
  498. if (temp & RH_PS_PRSC)
  499. ohci_writel (ohci, RH_PS_PRSC, portstat);
  500. /* start the next reset, sleep till it's probably done */
  501. ohci_writel (ohci, RH_PS_PRS, portstat);
  502. msleep(PORT_RESET_HW_MSEC);
  503. now = ohci_readl(ohci, &ohci->regs->fmnumber);
  504. } while (tick_before(now, reset_done));
  505. /* caller synchronizes using PRSC */
  506. return 0;
  507. }
  508. static int ohci_hub_control (
  509. struct usb_hcd *hcd,
  510. u16 typeReq,
  511. u16 wValue,
  512. u16 wIndex,
  513. char *buf,
  514. u16 wLength
  515. ) {
  516. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  517. int ports = hcd_to_bus (hcd)->root_hub->maxchild;
  518. u32 temp;
  519. int retval = 0;
  520. if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
  521. return -ESHUTDOWN;
  522. switch (typeReq) {
  523. case ClearHubFeature:
  524. switch (wValue) {
  525. case C_HUB_OVER_CURRENT:
  526. ohci_writel (ohci, RH_HS_OCIC,
  527. &ohci->regs->roothub.status);
  528. case C_HUB_LOCAL_POWER:
  529. break;
  530. default:
  531. goto error;
  532. }
  533. break;
  534. case ClearPortFeature:
  535. if (!wIndex || wIndex > ports)
  536. goto error;
  537. wIndex--;
  538. switch (wValue) {
  539. case USB_PORT_FEAT_ENABLE:
  540. temp = RH_PS_CCS;
  541. break;
  542. case USB_PORT_FEAT_C_ENABLE:
  543. temp = RH_PS_PESC;
  544. break;
  545. case USB_PORT_FEAT_SUSPEND:
  546. temp = RH_PS_POCI;
  547. break;
  548. case USB_PORT_FEAT_C_SUSPEND:
  549. temp = RH_PS_PSSC;
  550. break;
  551. case USB_PORT_FEAT_POWER:
  552. temp = RH_PS_LSDA;
  553. break;
  554. case USB_PORT_FEAT_C_CONNECTION:
  555. temp = RH_PS_CSC;
  556. break;
  557. case USB_PORT_FEAT_C_OVER_CURRENT:
  558. temp = RH_PS_OCIC;
  559. break;
  560. case USB_PORT_FEAT_C_RESET:
  561. temp = RH_PS_PRSC;
  562. break;
  563. default:
  564. goto error;
  565. }
  566. ohci_writel (ohci, temp,
  567. &ohci->regs->roothub.portstatus [wIndex]);
  568. // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]);
  569. break;
  570. case GetHubDescriptor:
  571. ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf);
  572. break;
  573. case GetHubStatus:
  574. temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE);
  575. put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
  576. break;
  577. case GetPortStatus:
  578. if (!wIndex || wIndex > ports)
  579. goto error;
  580. wIndex--;
  581. temp = roothub_portstatus (ohci, wIndex);
  582. put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
  583. #ifndef OHCI_VERBOSE_DEBUG
  584. if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
  585. #endif
  586. dbg_port (ohci, "GetStatus", wIndex, temp);
  587. break;
  588. case SetHubFeature:
  589. switch (wValue) {
  590. case C_HUB_OVER_CURRENT:
  591. // FIXME: this can be cleared, yes?
  592. case C_HUB_LOCAL_POWER:
  593. break;
  594. default:
  595. goto error;
  596. }
  597. break;
  598. case SetPortFeature:
  599. if (!wIndex || wIndex > ports)
  600. goto error;
  601. wIndex--;
  602. switch (wValue) {
  603. case USB_PORT_FEAT_SUSPEND:
  604. #ifdef CONFIG_USB_OTG
  605. if (hcd->self.otg_port == (wIndex + 1)
  606. && hcd->self.b_hnp_enable)
  607. start_hnp(ohci);
  608. else
  609. #endif
  610. ohci_writel (ohci, RH_PS_PSS,
  611. &ohci->regs->roothub.portstatus [wIndex]);
  612. break;
  613. case USB_PORT_FEAT_POWER:
  614. ohci_writel (ohci, RH_PS_PPS,
  615. &ohci->regs->roothub.portstatus [wIndex]);
  616. break;
  617. case USB_PORT_FEAT_RESET:
  618. retval = root_port_reset (ohci, wIndex);
  619. break;
  620. default:
  621. goto error;
  622. }
  623. break;
  624. default:
  625. error:
  626. /* "protocol stall" on error */
  627. retval = -EPIPE;
  628. }
  629. return retval;
  630. }