ohci-hub.c 18 KB

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