11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * OHCI HCD (Host Controller Driver) for USB. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 51da177e4SLinus Torvalds * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * This file is licenced under GPL 81da177e4SLinus Torvalds */ 91da177e4SLinus Torvalds 101da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds /* 131da177e4SLinus Torvalds * OHCI Root Hub ... the nonsharable stuff 141da177e4SLinus Torvalds */ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #define dbg_port(hc,label,num,value) \ 171da177e4SLinus Torvalds ohci_dbg (hc, \ 181da177e4SLinus Torvalds "%s roothub.portstatus [%d] " \ 191da177e4SLinus Torvalds "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \ 201da177e4SLinus Torvalds label, num, temp, \ 211da177e4SLinus Torvalds (temp & RH_PS_PRSC) ? " PRSC" : "", \ 221da177e4SLinus Torvalds (temp & RH_PS_OCIC) ? " OCIC" : "", \ 231da177e4SLinus Torvalds (temp & RH_PS_PSSC) ? " PSSC" : "", \ 241da177e4SLinus Torvalds (temp & RH_PS_PESC) ? " PESC" : "", \ 251da177e4SLinus Torvalds (temp & RH_PS_CSC) ? " CSC" : "", \ 261da177e4SLinus Torvalds \ 271da177e4SLinus Torvalds (temp & RH_PS_LSDA) ? " LSDA" : "", \ 281da177e4SLinus Torvalds (temp & RH_PS_PPS) ? " PPS" : "", \ 291da177e4SLinus Torvalds (temp & RH_PS_PRS) ? " PRS" : "", \ 301da177e4SLinus Torvalds (temp & RH_PS_POCI) ? " POCI" : "", \ 311da177e4SLinus Torvalds (temp & RH_PS_PSS) ? " PSS" : "", \ 321da177e4SLinus Torvalds \ 331da177e4SLinus Torvalds (temp & RH_PS_PES) ? " PES" : "", \ 341da177e4SLinus Torvalds (temp & RH_PS_CCS) ? " CCS" : "" \ 351da177e4SLinus Torvalds ); 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds #define OHCI_SCHED_ENABLES \ 401da177e4SLinus Torvalds (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) 411da177e4SLinus Torvalds 42c6fcb85eSAlan Stern static void update_done_list(struct ohci_hcd *); 43cdb4dd15SAlan Stern static void ohci_work(struct ohci_hcd *); 441da177e4SLinus Torvalds 45b1878440SAlan Stern #ifdef CONFIG_PM 468d1a243bSAlan Stern static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) 478d1a243bSAlan Stern __releases(ohci->lock) 488d1a243bSAlan Stern __acquires(ohci->lock) 491da177e4SLinus Torvalds { 501da177e4SLinus Torvalds int status = 0; 518de98402SBenjamin Herrenschmidt 521da177e4SLinus Torvalds ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 531da177e4SLinus Torvalds switch (ohci->hc_control & OHCI_CTRL_HCFS) { 541da177e4SLinus Torvalds case OHCI_USB_RESUME: 551da177e4SLinus Torvalds ohci_dbg (ohci, "resume/suspend?\n"); 561da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_CTRL_HCFS; 571da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_RESET; 581da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 591da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 601da177e4SLinus Torvalds /* FALL THROUGH */ 611da177e4SLinus Torvalds case OHCI_USB_RESET: 621da177e4SLinus Torvalds status = -EBUSY; 631da177e4SLinus Torvalds ohci_dbg (ohci, "needs reinit!\n"); 641da177e4SLinus Torvalds goto done; 651da177e4SLinus Torvalds case OHCI_USB_SUSPEND: 668d1a243bSAlan Stern if (!ohci->autostop) { 671da177e4SLinus Torvalds ohci_dbg (ohci, "already suspended\n"); 681da177e4SLinus Torvalds goto done; 691da177e4SLinus Torvalds } 708d1a243bSAlan Stern } 718d1a243bSAlan Stern ohci_dbg (ohci, "%s root hub\n", 728d1a243bSAlan Stern autostop ? "auto-stop" : "suspend"); 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds /* First stop any processing */ 758d1a243bSAlan Stern if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) { 761da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_SCHED_ENABLES; 771da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 781da177e4SLinus Torvalds ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 791da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus); 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds /* sched disables take effect on the next frame, 821da177e4SLinus Torvalds * then the last WDH could take 6+ msec 831da177e4SLinus Torvalds */ 841da177e4SLinus Torvalds ohci_dbg (ohci, "stopping schedules ...\n"); 858d1a243bSAlan Stern ohci->autostop = 0; 868d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 878d1a243bSAlan Stern msleep (8); 888d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 891da177e4SLinus Torvalds } 90c6fcb85eSAlan Stern update_done_list(ohci); 91cdb4dd15SAlan Stern ohci_work(ohci); 921da177e4SLinus Torvalds 93c1db30a2SAlan Stern /* 94c1db30a2SAlan Stern * Some controllers don't handle "global" suspend properly if 95c1db30a2SAlan Stern * there are unsuspended ports. For these controllers, put all 96c1db30a2SAlan Stern * the enabled ports into suspend before suspending the root hub. 97c1db30a2SAlan Stern */ 98c1db30a2SAlan Stern if (ohci->flags & OHCI_QUIRK_GLOBAL_SUSPEND) { 99c1db30a2SAlan Stern __hc32 __iomem *portstat = ohci->regs->roothub.portstatus; 100c1db30a2SAlan Stern int i; 101c1db30a2SAlan Stern unsigned temp; 102c1db30a2SAlan Stern 103c1db30a2SAlan Stern for (i = 0; i < ohci->num_ports; (++i, ++portstat)) { 104c1db30a2SAlan Stern temp = ohci_readl(ohci, portstat); 105c1db30a2SAlan Stern if ((temp & (RH_PS_PES | RH_PS_PSS)) == 106c1db30a2SAlan Stern RH_PS_PES) 107c1db30a2SAlan Stern ohci_writel(ohci, RH_PS_PSS, portstat); 108c1db30a2SAlan Stern } 109c1db30a2SAlan Stern } 110c1db30a2SAlan Stern 1111da177e4SLinus Torvalds /* maybe resume can wake root hub */ 11258a97ffeSAlan Stern if (ohci_to_hcd(ohci)->self.root_hub->do_remote_wakeup || autostop) { 1131da177e4SLinus Torvalds ohci->hc_control |= OHCI_CTRL_RWE; 11458a97ffeSAlan Stern } else { 1155f47493cSAlan Stern ohci_writel(ohci, OHCI_INTR_RHSC | OHCI_INTR_RD, 1165f47493cSAlan Stern &ohci->regs->intrdisable); 1171da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_CTRL_RWE; 1181f7e1a3bSAlan Stern } 1191da177e4SLinus Torvalds 120f197b2c5SDavid Brownell /* Suspend hub ... this is the "global (to this bus) suspend" mode, 121f197b2c5SDavid Brownell * which doesn't imply ports will first be individually suspended. 122f197b2c5SDavid Brownell */ 1231da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_CTRL_HCFS; 1241da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_SUSPEND; 1251da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 1261da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds /* no resumes until devices finish suspending */ 1298d1a243bSAlan Stern if (!autostop) { 1301da177e4SLinus Torvalds ohci->next_statechange = jiffies + msecs_to_jiffies (5); 1318d1a243bSAlan Stern ohci->autostop = 0; 132b7463c71SAlan Stern ohci->rh_state = OHCI_RH_SUSPENDED; 1338d1a243bSAlan Stern } 134d413984aSDavid Brownell 1351da177e4SLinus Torvalds done: 1361da177e4SLinus Torvalds return status; 1371da177e4SLinus Torvalds } 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds static inline struct ed *find_head (struct ed *ed) 1401da177e4SLinus Torvalds { 1411da177e4SLinus Torvalds /* for bulk and control lists */ 1421da177e4SLinus Torvalds while (ed->ed_prev) 1431da177e4SLinus Torvalds ed = ed->ed_prev; 1441da177e4SLinus Torvalds return ed; 1451da177e4SLinus Torvalds } 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds /* caller has locked the root hub */ 1488d1a243bSAlan Stern static int ohci_rh_resume (struct ohci_hcd *ohci) 1498d1a243bSAlan Stern __releases(ohci->lock) 1508d1a243bSAlan Stern __acquires(ohci->lock) 1511da177e4SLinus Torvalds { 1528d1a243bSAlan Stern struct usb_hcd *hcd = ohci_to_hcd (ohci); 1531da177e4SLinus Torvalds u32 temp, enables; 1541da177e4SLinus Torvalds int status = -EINPROGRESS; 1558d1a243bSAlan Stern int autostopped = ohci->autostop; 1561da177e4SLinus Torvalds 1578d1a243bSAlan Stern ohci->autostop = 0; 1581da177e4SLinus Torvalds ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 161f197b2c5SDavid Brownell /* this can happen after resuming a swsusp snapshot */ 162b7463c71SAlan Stern if (ohci->rh_state != OHCI_RH_RUNNING) { 1631da177e4SLinus Torvalds ohci_dbg (ohci, "BIOS/SMM active, control %03x\n", 1641da177e4SLinus Torvalds ohci->hc_control); 1651da177e4SLinus Torvalds status = -EBUSY; 1661da177e4SLinus Torvalds /* this happens when pmcore resumes HC then root */ 1671da177e4SLinus Torvalds } else { 1681da177e4SLinus Torvalds ohci_dbg (ohci, "duplicate resume\n"); 1691da177e4SLinus Torvalds status = 0; 1701da177e4SLinus Torvalds } 1711da177e4SLinus Torvalds } else switch (ohci->hc_control & OHCI_CTRL_HCFS) { 1721da177e4SLinus Torvalds case OHCI_USB_SUSPEND: 1731da177e4SLinus Torvalds ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES); 1741da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_RESUME; 1751da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 1761da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 1778d1a243bSAlan Stern ohci_dbg (ohci, "%s root hub\n", 1788d1a243bSAlan Stern autostopped ? "auto-start" : "resume"); 1791da177e4SLinus Torvalds break; 1801da177e4SLinus Torvalds case OHCI_USB_RESUME: 1811da177e4SLinus Torvalds /* HCFS changes sometime after INTR_RD */ 1821b7be3c0SAlan Stern ohci_dbg(ohci, "%swakeup root hub\n", 183583ceadaSAlan Stern autostopped ? "auto-" : ""); 1841da177e4SLinus Torvalds break; 1851da177e4SLinus Torvalds case OHCI_USB_OPER: 186f197b2c5SDavid Brownell /* this can happen after resuming a swsusp snapshot */ 187f197b2c5SDavid Brownell ohci_dbg (ohci, "snapshot resume? reinit\n"); 188f197b2c5SDavid Brownell status = -EBUSY; 1891da177e4SLinus Torvalds break; 1901da177e4SLinus Torvalds default: /* RESET, we lost power */ 191f197b2c5SDavid Brownell ohci_dbg (ohci, "lost power\n"); 1921da177e4SLinus Torvalds status = -EBUSY; 1931da177e4SLinus Torvalds } 1941da177e4SLinus Torvalds if (status == -EBUSY) { 1958d1a243bSAlan Stern if (!autostopped) { 1968d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 1978d1a243bSAlan Stern status = ohci_restart (ohci); 198d576bb9fSMichael Hanselmann 199d576bb9fSMichael Hanselmann usb_root_hub_lost_power(hcd->self.root_hub); 200d576bb9fSMichael Hanselmann 2018d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 2021da177e4SLinus Torvalds } 2038d1a243bSAlan Stern return status; 2048d1a243bSAlan Stern } 2051da177e4SLinus Torvalds if (status != -EINPROGRESS) 2061da177e4SLinus Torvalds return status; 2078d1a243bSAlan Stern if (autostopped) 2088d1a243bSAlan Stern goto skip_resume; 2098d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds /* Some controllers (lucent erratum) need extra-long delays */ 212f197b2c5SDavid Brownell msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1); 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds temp = ohci_readl (ohci, &ohci->regs->control); 2151da177e4SLinus Torvalds temp &= OHCI_CTRL_HCFS; 2161da177e4SLinus Torvalds if (temp != OHCI_USB_RESUME) { 2171da177e4SLinus Torvalds ohci_err (ohci, "controller won't resume\n"); 218565402baSAlan Stern spin_lock_irq(&ohci->lock); 2191da177e4SLinus Torvalds return -EBUSY; 2201da177e4SLinus Torvalds } 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds /* disable old schedule state, reinit from scratch */ 2231da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_controlhead); 2241da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent); 2251da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead); 2261da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent); 2271da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent); 2281da177e4SLinus Torvalds ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca); 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds /* Sometimes PCI D3 suspend trashes frame timings ... */ 2311da177e4SLinus Torvalds periodic_reinit (ohci); 2321da177e4SLinus Torvalds 2337c71c6e6SAlan Stern /* 2347c71c6e6SAlan Stern * The following code is executed with ohci->lock held and 2357c71c6e6SAlan Stern * irqs disabled if and only if autostopped is true. This 2367c71c6e6SAlan Stern * will cause sparse to warn about a "context imbalance". 2378d1a243bSAlan Stern */ 2388d1a243bSAlan Stern skip_resume: 2391da177e4SLinus Torvalds /* interrupts might have been disabled */ 2401da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); 2411da177e4SLinus Torvalds if (ohci->ed_rm_list) 2421da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable); 2431da177e4SLinus Torvalds 2441da177e4SLinus Torvalds /* Then re-enable operations */ 2451da177e4SLinus Torvalds ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control); 2461da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 2478d1a243bSAlan Stern if (!autostopped) 2481da177e4SLinus Torvalds msleep (3); 2491da177e4SLinus Torvalds 2506a9062f3SDavid Brownell temp = ohci->hc_control; 2516a9062f3SDavid Brownell temp &= OHCI_CTRL_RWC; 2526a9062f3SDavid Brownell temp |= OHCI_CONTROL_INIT | OHCI_USB_OPER; 2531da177e4SLinus Torvalds ohci->hc_control = temp; 2541da177e4SLinus Torvalds ohci_writel (ohci, temp, &ohci->regs->control); 2551da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds /* TRSMRCY */ 2588d1a243bSAlan Stern if (!autostopped) { 2591da177e4SLinus Torvalds msleep (10); 2608d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 2618d1a243bSAlan Stern } 2628d1a243bSAlan Stern /* now ohci->lock is always held and irqs are always disabled */ 2631da177e4SLinus Torvalds 264d413984aSDavid Brownell /* keep it alive for more than ~5x suspend + resume costs */ 265d413984aSDavid Brownell ohci->next_statechange = jiffies + STATECHANGE_DELAY; 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds /* maybe turn schedules back on */ 2681da177e4SLinus Torvalds enables = 0; 2691da177e4SLinus Torvalds temp = 0; 2701da177e4SLinus Torvalds if (!ohci->ed_rm_list) { 2711da177e4SLinus Torvalds if (ohci->ed_controltail) { 2721da177e4SLinus Torvalds ohci_writel (ohci, 2731da177e4SLinus Torvalds find_head (ohci->ed_controltail)->dma, 2741da177e4SLinus Torvalds &ohci->regs->ed_controlhead); 2751da177e4SLinus Torvalds enables |= OHCI_CTRL_CLE; 2761da177e4SLinus Torvalds temp |= OHCI_CLF; 2771da177e4SLinus Torvalds } 2781da177e4SLinus Torvalds if (ohci->ed_bulktail) { 2791da177e4SLinus Torvalds ohci_writel (ohci, find_head (ohci->ed_bulktail)->dma, 2801da177e4SLinus Torvalds &ohci->regs->ed_bulkhead); 2811da177e4SLinus Torvalds enables |= OHCI_CTRL_BLE; 2821da177e4SLinus Torvalds temp |= OHCI_BLF; 2831da177e4SLinus Torvalds } 2841da177e4SLinus Torvalds } 2851da177e4SLinus Torvalds if (hcd->self.bandwidth_isoc_reqs || hcd->self.bandwidth_int_reqs) 2861da177e4SLinus Torvalds enables |= OHCI_CTRL_PLE|OHCI_CTRL_IE; 2871da177e4SLinus Torvalds if (enables) { 2881da177e4SLinus Torvalds ohci_dbg (ohci, "restarting schedules ... %08x\n", enables); 2891da177e4SLinus Torvalds ohci->hc_control |= enables; 2901da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 2911da177e4SLinus Torvalds if (temp) 2921da177e4SLinus Torvalds ohci_writel (ohci, temp, &ohci->regs->cmdstatus); 2931da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 2941da177e4SLinus Torvalds } 2951da177e4SLinus Torvalds 296b7463c71SAlan Stern ohci->rh_state = OHCI_RH_RUNNING; 2971da177e4SLinus Torvalds return 0; 2981da177e4SLinus Torvalds } 2991da177e4SLinus Torvalds 3008d1a243bSAlan Stern static int ohci_bus_suspend (struct usb_hcd *hcd) 3018d1a243bSAlan Stern { 3028d1a243bSAlan Stern struct ohci_hcd *ohci = hcd_to_ohci (hcd); 3038d1a243bSAlan Stern int rc; 3048d1a243bSAlan Stern 3058d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 3068d1a243bSAlan Stern 307541c7d43SAlan Stern if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) 3088d1a243bSAlan Stern rc = -ESHUTDOWN; 3098d1a243bSAlan Stern else 3108d1a243bSAlan Stern rc = ohci_rh_suspend (ohci, 0); 3118d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 312*81e38333SAlan Stern 313*81e38333SAlan Stern if (rc == 0) 314*81e38333SAlan Stern del_timer_sync(&ohci->io_watchdog); 3158d1a243bSAlan Stern return rc; 3168d1a243bSAlan Stern } 3178d1a243bSAlan Stern 3188d1a243bSAlan Stern static int ohci_bus_resume (struct usb_hcd *hcd) 3198d1a243bSAlan Stern { 3208d1a243bSAlan Stern struct ohci_hcd *ohci = hcd_to_ohci (hcd); 3218d1a243bSAlan Stern int rc; 3228d1a243bSAlan Stern 3238d1a243bSAlan Stern if (time_before (jiffies, ohci->next_statechange)) 3248d1a243bSAlan Stern msleep(5); 3258d1a243bSAlan Stern 3268d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 3278d1a243bSAlan Stern 328541c7d43SAlan Stern if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) 3298d1a243bSAlan Stern rc = -ESHUTDOWN; 3308d1a243bSAlan Stern else 3318d1a243bSAlan Stern rc = ohci_rh_resume (ohci); 3328d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 3338d1a243bSAlan Stern 3348d1a243bSAlan Stern /* poll until we know a device is connected or we autostop */ 3358d1a243bSAlan Stern if (rc == 0) 3368d1a243bSAlan Stern usb_hcd_poll_rh_status(hcd); 3378d1a243bSAlan Stern return rc; 3388d1a243bSAlan Stern } 3398d1a243bSAlan Stern 3401f9fc882SAlan Stern /* Carry out polling-, autostop-, and autoresume-related state changes */ 3411f9fc882SAlan Stern static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 34271b7497cSAlan Stern int any_connected, int rhsc_status) 3431f9fc882SAlan Stern { 3441f9fc882SAlan Stern int poll_rh = 1; 34571b7497cSAlan Stern int rhsc_enable; 3461f9fc882SAlan Stern 347ee0b9be8SAlan Stern /* Some broken controllers never turn off RHSC in the interrupt 3484a511bc3SAlan Stern * status register. For their sake we won't re-enable RHSC 3494a511bc3SAlan Stern * interrupts if the interrupt bit is already active. 350b5fb454fSAlan Stern */ 3514a511bc3SAlan Stern rhsc_enable = ohci_readl(ohci, &ohci->regs->intrenable) & 3524a511bc3SAlan Stern OHCI_INTR_RHSC; 3534a511bc3SAlan Stern 3544a511bc3SAlan Stern switch (ohci->hc_control & OHCI_CTRL_HCFS) { 3554a511bc3SAlan Stern case OHCI_USB_OPER: 3564a511bc3SAlan Stern /* If no status changes are pending, enable RHSC interrupts. */ 3574a511bc3SAlan Stern if (!rhsc_enable && !rhsc_status && !changed) { 3584a511bc3SAlan Stern rhsc_enable = OHCI_INTR_RHSC; 3594a511bc3SAlan Stern ohci_writel(ohci, rhsc_enable, &ohci->regs->intrenable); 360b5fb454fSAlan Stern } 361b5fb454fSAlan Stern 362b5fb454fSAlan Stern /* Keep on polling until we know a device is connected 363b5fb454fSAlan Stern * and RHSC is enabled, or until we autostop. 364b5fb454fSAlan Stern */ 3651f9fc882SAlan Stern if (!ohci->autostop) { 3661f9fc882SAlan Stern if (any_connected || 3671f9fc882SAlan Stern !device_may_wakeup(&ohci_to_hcd(ohci) 3681f9fc882SAlan Stern ->self.root_hub->dev)) { 3694a511bc3SAlan Stern if (rhsc_enable) 3701f9fc882SAlan Stern poll_rh = 0; 3711f9fc882SAlan Stern } else { 3721f9fc882SAlan Stern ohci->autostop = 1; 3731f9fc882SAlan Stern ohci->next_statechange = jiffies + HZ; 3741f9fc882SAlan Stern } 3751f9fc882SAlan Stern 3761f9fc882SAlan Stern /* if no devices have been attached for one second, autostop */ 3771f9fc882SAlan Stern } else { 3781f9fc882SAlan Stern if (changed || any_connected) { 3791f9fc882SAlan Stern ohci->autostop = 0; 3801f9fc882SAlan Stern ohci->next_statechange = jiffies + 3811f9fc882SAlan Stern STATECHANGE_DELAY; 3824a511bc3SAlan Stern } else if (time_after_eq(jiffies, 3831f9fc882SAlan Stern ohci->next_statechange) 3841f9fc882SAlan Stern && !ohci->ed_rm_list 3851f9fc882SAlan Stern && !(ohci->hc_control & 3861f9fc882SAlan Stern OHCI_SCHED_ENABLES)) { 3871f9fc882SAlan Stern ohci_rh_suspend(ohci, 1); 3884a511bc3SAlan Stern if (rhsc_enable) 389b5fb454fSAlan Stern poll_rh = 0; 3901f9fc882SAlan Stern } 3911f9fc882SAlan Stern } 3921f9fc882SAlan Stern break; 3931f9fc882SAlan Stern 3941f9fc882SAlan Stern case OHCI_USB_SUSPEND: 3951f9fc882SAlan Stern case OHCI_USB_RESUME: 3964a511bc3SAlan Stern /* if there is a port change, autostart or ask to be resumed */ 3971f9fc882SAlan Stern if (changed) { 3981f9fc882SAlan Stern if (ohci->autostop) 3991f9fc882SAlan Stern ohci_rh_resume(ohci); 4001f9fc882SAlan Stern else 4011f9fc882SAlan Stern usb_hcd_resume_root_hub(ohci_to_hcd(ohci)); 40271b7497cSAlan Stern 40371b7497cSAlan Stern /* If remote wakeup is disabled, stop polling */ 40471b7497cSAlan Stern } else if (!ohci->autostop && 40571b7497cSAlan Stern !ohci_to_hcd(ohci)->self.root_hub-> 40671b7497cSAlan Stern do_remote_wakeup) { 40771b7497cSAlan Stern poll_rh = 0; 40871b7497cSAlan Stern 4091f9fc882SAlan Stern } else { 41071b7497cSAlan Stern /* If no status changes are pending, 41171b7497cSAlan Stern * enable RHSC interrupts 41271b7497cSAlan Stern */ 41371b7497cSAlan Stern if (!rhsc_enable && !rhsc_status) { 4144a511bc3SAlan Stern rhsc_enable = OHCI_INTR_RHSC; 4154a511bc3SAlan Stern ohci_writel(ohci, rhsc_enable, 416b5fb454fSAlan Stern &ohci->regs->intrenable); 4174a511bc3SAlan Stern } 41871b7497cSAlan Stern /* Keep polling until RHSC is enabled */ 4194a511bc3SAlan Stern if (rhsc_enable) 4201f9fc882SAlan Stern poll_rh = 0; 4211f9fc882SAlan Stern } 4221f9fc882SAlan Stern break; 4231f9fc882SAlan Stern } 4241f9fc882SAlan Stern return poll_rh; 4251f9fc882SAlan Stern } 4261f9fc882SAlan Stern 4271f9fc882SAlan Stern #else /* CONFIG_PM */ 4281f9fc882SAlan Stern 4291f9fc882SAlan Stern static inline int ohci_rh_resume(struct ohci_hcd *ohci) 4301f9fc882SAlan Stern { 4311f9fc882SAlan Stern return 0; 4321f9fc882SAlan Stern } 4331f9fc882SAlan Stern 4341f9fc882SAlan Stern /* Carry out polling-related state changes. 4351f9fc882SAlan Stern * autostop isn't used when CONFIG_PM is turned off. 4361f9fc882SAlan Stern */ 4371f9fc882SAlan Stern static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 43871b7497cSAlan Stern int any_connected, int rhsc_status) 4391f9fc882SAlan Stern { 440b5fb454fSAlan Stern /* If RHSC is enabled, don't poll */ 44109ca8adbSLinus Torvalds if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC) 442b5fb454fSAlan Stern return 0; 443b5fb454fSAlan Stern 44471b7497cSAlan Stern /* If status changes are pending, continue polling. 44571b7497cSAlan Stern * Conversely, if no status changes are pending but the RHSC 44671b7497cSAlan Stern * status bit was set, then RHSC may be broken so continue polling. 44771b7497cSAlan Stern */ 44871b7497cSAlan Stern if (changed || rhsc_status) 44971b7497cSAlan Stern return 1; 45071b7497cSAlan Stern 45171b7497cSAlan Stern /* It's safe to re-enable RHSC interrupts */ 452b5fb454fSAlan Stern ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable); 453b5fb454fSAlan Stern return 0; 454b5fb454fSAlan Stern } 4551f9fc882SAlan Stern 4568ad7fe16SDavid Brownell #endif /* CONFIG_PM */ 4571da177e4SLinus Torvalds 4581da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds /* build "status change" packet (one or two bytes) from HC registers */ 4611da177e4SLinus Torvalds 46242b59ebaSLaurent Pinchart int ohci_hub_status_data(struct usb_hcd *hcd, char *buf) 4631da177e4SLinus Torvalds { 4641da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 465fdd13b36SDavid Brownell int i, changed = 0, length = 1; 466052ac01aSAlan Stern int any_connected = 0; 46771b7497cSAlan Stern int rhsc_status; 4681da177e4SLinus Torvalds unsigned long flags; 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds spin_lock_irqsave (&ohci->lock, flags); 471541c7d43SAlan Stern if (!HCD_HW_ACCESSIBLE(hcd)) 4726fd75b19SAlan Stern goto done; 4731da177e4SLinus Torvalds 474fdd13b36SDavid Brownell /* undocumented erratum seen on at least rev D */ 475fdd13b36SDavid Brownell if ((ohci->flags & OHCI_QUIRK_AMD756) 476fdd13b36SDavid Brownell && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) { 477fdd13b36SDavid Brownell ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n", 4781da177e4SLinus Torvalds ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP); 4791da177e4SLinus Torvalds /* retry later; "should not happen" */ 4801da177e4SLinus Torvalds goto done; 4811da177e4SLinus Torvalds } 4821da177e4SLinus Torvalds 4831da177e4SLinus Torvalds /* init status */ 4841da177e4SLinus Torvalds if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC)) 4851da177e4SLinus Torvalds buf [0] = changed = 1; 4861da177e4SLinus Torvalds else 4871da177e4SLinus Torvalds buf [0] = 0; 488fdd13b36SDavid Brownell if (ohci->num_ports > 7) { 4891da177e4SLinus Torvalds buf [1] = 0; 4901da177e4SLinus Torvalds length++; 4911da177e4SLinus Torvalds } 4921da177e4SLinus Torvalds 49371b7497cSAlan Stern /* Clear the RHSC status flag before reading the port statuses */ 49471b7497cSAlan Stern ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrstatus); 49571b7497cSAlan Stern rhsc_status = ohci_readl(ohci, &ohci->regs->intrstatus) & 49671b7497cSAlan Stern OHCI_INTR_RHSC; 49771b7497cSAlan Stern 4981da177e4SLinus Torvalds /* look at each port */ 499fdd13b36SDavid Brownell for (i = 0; i < ohci->num_ports; i++) { 5001da177e4SLinus Torvalds u32 status = roothub_portstatus (ohci, i); 5011da177e4SLinus Torvalds 5028d1a243bSAlan Stern /* can't autostop if ports are connected */ 5038d1a243bSAlan Stern any_connected |= (status & RH_PS_CCS); 5048d1a243bSAlan Stern 5051da177e4SLinus Torvalds if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC 5061da177e4SLinus Torvalds | RH_PS_OCIC | RH_PS_PRSC)) { 5071da177e4SLinus Torvalds changed = 1; 5081da177e4SLinus Torvalds if (i < 7) 5091da177e4SLinus Torvalds buf [0] |= 1 << (i + 1); 5101da177e4SLinus Torvalds else 5111da177e4SLinus Torvalds buf [1] |= 1 << (i - 7); 5121da177e4SLinus Torvalds } 5131da177e4SLinus Torvalds } 514d413984aSDavid Brownell 515541c7d43SAlan Stern if (ohci_root_hub_state_changes(ohci, changed, 516541c7d43SAlan Stern any_connected, rhsc_status)) 517541c7d43SAlan Stern set_bit(HCD_FLAG_POLL_RH, &hcd->flags); 518541c7d43SAlan Stern else 519541c7d43SAlan Stern clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 520541c7d43SAlan Stern 521d413984aSDavid Brownell 5221da177e4SLinus Torvalds done: 5231da177e4SLinus Torvalds spin_unlock_irqrestore (&ohci->lock, flags); 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds return changed ? length : 0; 5261da177e4SLinus Torvalds } 52742b59ebaSLaurent Pinchart EXPORT_SYMBOL_GPL(ohci_hub_status_data); 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 5301da177e4SLinus Torvalds 5311da177e4SLinus Torvalds static void 5321da177e4SLinus Torvalds ohci_hub_descriptor ( 5331da177e4SLinus Torvalds struct ohci_hcd *ohci, 5341da177e4SLinus Torvalds struct usb_hub_descriptor *desc 5351da177e4SLinus Torvalds ) { 5361da177e4SLinus Torvalds u32 rh = roothub_a (ohci); 5371da177e4SLinus Torvalds u16 temp; 5381da177e4SLinus Torvalds 5391da177e4SLinus Torvalds desc->bDescriptorType = 0x29; 5401da177e4SLinus Torvalds desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24; 5411da177e4SLinus Torvalds desc->bHubContrCurrent = 0; 5421da177e4SLinus Torvalds 543fdd13b36SDavid Brownell desc->bNbrPorts = ohci->num_ports; 544fdd13b36SDavid Brownell temp = 1 + (ohci->num_ports / 8); 5451da177e4SLinus Torvalds desc->bDescLength = 7 + 2 * temp; 5461da177e4SLinus Torvalds 5471da177e4SLinus Torvalds temp = 0; 5481da177e4SLinus Torvalds if (rh & RH_A_NPS) /* no power switching? */ 5491da177e4SLinus Torvalds temp |= 0x0002; 5501da177e4SLinus Torvalds if (rh & RH_A_PSM) /* per-port power switching? */ 5511da177e4SLinus Torvalds temp |= 0x0001; 5521da177e4SLinus Torvalds if (rh & RH_A_NOCP) /* no overcurrent reporting? */ 5531da177e4SLinus Torvalds temp |= 0x0010; 5541da177e4SLinus Torvalds else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */ 5551da177e4SLinus Torvalds temp |= 0x0008; 5567c71c6e6SAlan Stern desc->wHubCharacteristics = cpu_to_le16(temp); 5571da177e4SLinus Torvalds 558da13051cSSarah Sharp /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 5591da177e4SLinus Torvalds rh = roothub_b (ohci); 560dbe79bbeSJohn Youn memset(desc->u.hs.DeviceRemovable, 0xff, 561dbe79bbeSJohn Youn sizeof(desc->u.hs.DeviceRemovable)); 562dbe79bbeSJohn Youn desc->u.hs.DeviceRemovable[0] = rh & RH_B_DR; 563fdd13b36SDavid Brownell if (ohci->num_ports > 7) { 564dbe79bbeSJohn Youn desc->u.hs.DeviceRemovable[1] = (rh & RH_B_DR) >> 8; 565dbe79bbeSJohn Youn desc->u.hs.DeviceRemovable[2] = 0xff; 5661da177e4SLinus Torvalds } else 567dbe79bbeSJohn Youn desc->u.hs.DeviceRemovable[1] = 0xff; 5681da177e4SLinus Torvalds } 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds #ifdef CONFIG_USB_OTG 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port) 5751da177e4SLinus Torvalds { 5761da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 5771da177e4SLinus Torvalds u32 status; 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds if (!port) 5801da177e4SLinus Torvalds return -EINVAL; 5811da177e4SLinus Torvalds port--; 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds /* start port reset before HNP protocol times out */ 5841da177e4SLinus Torvalds status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]); 5851da177e4SLinus Torvalds if (!(status & RH_PS_CCS)) 5861da177e4SLinus Torvalds return -ENODEV; 5871da177e4SLinus Torvalds 5881da177e4SLinus Torvalds /* khubd will finish the reset later */ 5891da177e4SLinus Torvalds ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]); 5901da177e4SLinus Torvalds return 0; 5911da177e4SLinus Torvalds } 5921da177e4SLinus Torvalds 5931da177e4SLinus Torvalds #else 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds #define ohci_start_port_reset NULL 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds #endif 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 6001da177e4SLinus Torvalds 6011da177e4SLinus Torvalds 6021da177e4SLinus Torvalds /* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling, 6031da177e4SLinus Torvalds * not necessarily continuous ... to guard against resume signaling. 6041da177e4SLinus Torvalds */ 6051da177e4SLinus Torvalds #define PORT_RESET_MSEC 50 6061da177e4SLinus Torvalds 6071da177e4SLinus Torvalds /* this timer value might be vendor-specific ... */ 6081da177e4SLinus Torvalds #define PORT_RESET_HW_MSEC 10 6091da177e4SLinus Torvalds 6101da177e4SLinus Torvalds /* wrap-aware logic morphed from <linux/jiffies.h> */ 6111da177e4SLinus Torvalds #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds /* called from some task, normally khubd */ 61423d10a9eSTakamasa Ohtake static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port) 6151da177e4SLinus Torvalds { 6161da177e4SLinus Torvalds __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; 6171b7b61c5SAlan Stern u32 temp = 0; 6181da177e4SLinus Torvalds u16 now = ohci_readl(ohci, &ohci->regs->fmnumber); 6191da177e4SLinus Torvalds u16 reset_done = now + PORT_RESET_MSEC; 620e01e7fe3SDavid Brownell int limit_1 = DIV_ROUND_UP(PORT_RESET_MSEC, PORT_RESET_HW_MSEC); 6211da177e4SLinus Torvalds 6221da177e4SLinus Torvalds /* build a "continuous enough" reset signal, with up to 6231da177e4SLinus Torvalds * 3msec gap between pulses. scheduler HZ==100 must work; 6241da177e4SLinus Torvalds * this might need to be deadline-scheduled. 6251da177e4SLinus Torvalds */ 6261da177e4SLinus Torvalds do { 627e01e7fe3SDavid Brownell int limit_2; 628e01e7fe3SDavid Brownell 6291da177e4SLinus Torvalds /* spin until any current reset finishes */ 630e01e7fe3SDavid Brownell limit_2 = PORT_RESET_HW_MSEC * 2; 631e01e7fe3SDavid Brownell while (--limit_2 >= 0) { 6321da177e4SLinus Torvalds temp = ohci_readl (ohci, portstat); 63323d10a9eSTakamasa Ohtake /* handle e.g. CardBus eject */ 63423d10a9eSTakamasa Ohtake if (temp == ~(u32)0) 63523d10a9eSTakamasa Ohtake return -ESHUTDOWN; 6361da177e4SLinus Torvalds if (!(temp & RH_PS_PRS)) 6371da177e4SLinus Torvalds break; 6381da177e4SLinus Torvalds udelay (500); 6391da177e4SLinus Torvalds } 6401da177e4SLinus Torvalds 641e01e7fe3SDavid Brownell /* timeout (a hardware error) has been observed when 642e01e7fe3SDavid Brownell * EHCI sets CF while this driver is resetting a port; 643e01e7fe3SDavid Brownell * presumably other disconnect paths might do it too. 644e01e7fe3SDavid Brownell */ 645e01e7fe3SDavid Brownell if (limit_2 < 0) { 646e01e7fe3SDavid Brownell ohci_dbg(ohci, 647e01e7fe3SDavid Brownell "port[%d] reset timeout, stat %08x\n", 648e01e7fe3SDavid Brownell port, temp); 649e01e7fe3SDavid Brownell break; 650e01e7fe3SDavid Brownell } 651e01e7fe3SDavid Brownell 6521da177e4SLinus Torvalds if (!(temp & RH_PS_CCS)) 6531da177e4SLinus Torvalds break; 6541da177e4SLinus Torvalds if (temp & RH_PS_PRSC) 6551da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PRSC, portstat); 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds /* start the next reset, sleep till it's probably done */ 6581da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PRS, portstat); 6591da177e4SLinus Torvalds msleep(PORT_RESET_HW_MSEC); 6601da177e4SLinus Torvalds now = ohci_readl(ohci, &ohci->regs->fmnumber); 661e01e7fe3SDavid Brownell } while (tick_before(now, reset_done) && --limit_1 >= 0); 662e01e7fe3SDavid Brownell 663e01e7fe3SDavid Brownell /* caller synchronizes using PRSC ... and handles PRS 664e01e7fe3SDavid Brownell * still being set when this returns. 665e01e7fe3SDavid Brownell */ 66623d10a9eSTakamasa Ohtake 66723d10a9eSTakamasa Ohtake return 0; 6681da177e4SLinus Torvalds } 6691da177e4SLinus Torvalds 67042b59ebaSLaurent Pinchart int ohci_hub_control( 6711da177e4SLinus Torvalds struct usb_hcd *hcd, 6721da177e4SLinus Torvalds u16 typeReq, 6731da177e4SLinus Torvalds u16 wValue, 6741da177e4SLinus Torvalds u16 wIndex, 6751da177e4SLinus Torvalds char *buf, 6761da177e4SLinus Torvalds u16 wLength 6771da177e4SLinus Torvalds ) { 6781da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 679fcf7d214SAlan Stern int ports = ohci->num_ports; 6801da177e4SLinus Torvalds u32 temp; 6811da177e4SLinus Torvalds int retval = 0; 6821da177e4SLinus Torvalds 683541c7d43SAlan Stern if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) 6848de98402SBenjamin Herrenschmidt return -ESHUTDOWN; 6858de98402SBenjamin Herrenschmidt 6861da177e4SLinus Torvalds switch (typeReq) { 6871da177e4SLinus Torvalds case ClearHubFeature: 6881da177e4SLinus Torvalds switch (wValue) { 6891da177e4SLinus Torvalds case C_HUB_OVER_CURRENT: 6901da177e4SLinus Torvalds ohci_writel (ohci, RH_HS_OCIC, 6911da177e4SLinus Torvalds &ohci->regs->roothub.status); 6921da177e4SLinus Torvalds case C_HUB_LOCAL_POWER: 6931da177e4SLinus Torvalds break; 6941da177e4SLinus Torvalds default: 6951da177e4SLinus Torvalds goto error; 6961da177e4SLinus Torvalds } 6971da177e4SLinus Torvalds break; 6981da177e4SLinus Torvalds case ClearPortFeature: 6991da177e4SLinus Torvalds if (!wIndex || wIndex > ports) 7001da177e4SLinus Torvalds goto error; 7011da177e4SLinus Torvalds wIndex--; 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds switch (wValue) { 7041da177e4SLinus Torvalds case USB_PORT_FEAT_ENABLE: 7051da177e4SLinus Torvalds temp = RH_PS_CCS; 7061da177e4SLinus Torvalds break; 7071da177e4SLinus Torvalds case USB_PORT_FEAT_C_ENABLE: 7081da177e4SLinus Torvalds temp = RH_PS_PESC; 7091da177e4SLinus Torvalds break; 7101da177e4SLinus Torvalds case USB_PORT_FEAT_SUSPEND: 7111da177e4SLinus Torvalds temp = RH_PS_POCI; 7121da177e4SLinus Torvalds break; 7131da177e4SLinus Torvalds case USB_PORT_FEAT_C_SUSPEND: 7141da177e4SLinus Torvalds temp = RH_PS_PSSC; 7151da177e4SLinus Torvalds break; 7161da177e4SLinus Torvalds case USB_PORT_FEAT_POWER: 7171da177e4SLinus Torvalds temp = RH_PS_LSDA; 7181da177e4SLinus Torvalds break; 7191da177e4SLinus Torvalds case USB_PORT_FEAT_C_CONNECTION: 7201da177e4SLinus Torvalds temp = RH_PS_CSC; 7211da177e4SLinus Torvalds break; 7221da177e4SLinus Torvalds case USB_PORT_FEAT_C_OVER_CURRENT: 7231da177e4SLinus Torvalds temp = RH_PS_OCIC; 7241da177e4SLinus Torvalds break; 7251da177e4SLinus Torvalds case USB_PORT_FEAT_C_RESET: 7261da177e4SLinus Torvalds temp = RH_PS_PRSC; 7271da177e4SLinus Torvalds break; 7281da177e4SLinus Torvalds default: 7291da177e4SLinus Torvalds goto error; 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds ohci_writel (ohci, temp, 7321da177e4SLinus Torvalds &ohci->regs->roothub.portstatus [wIndex]); 7331da177e4SLinus Torvalds // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]); 7341da177e4SLinus Torvalds break; 7351da177e4SLinus Torvalds case GetHubDescriptor: 7361da177e4SLinus Torvalds ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf); 7371da177e4SLinus Torvalds break; 7381da177e4SLinus Torvalds case GetHubStatus: 7391da177e4SLinus Torvalds temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE); 740a5abdeafSHarvey Harrison put_unaligned_le32(temp, buf); 7411da177e4SLinus Torvalds break; 7421da177e4SLinus Torvalds case GetPortStatus: 7431da177e4SLinus Torvalds if (!wIndex || wIndex > ports) 7441da177e4SLinus Torvalds goto error; 7451da177e4SLinus Torvalds wIndex--; 7461da177e4SLinus Torvalds temp = roothub_portstatus (ohci, wIndex); 747a5abdeafSHarvey Harrison put_unaligned_le32(temp, buf); 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds if (*(u16*)(buf+2)) /* only if wPortChange is interesting */ 7501da177e4SLinus Torvalds dbg_port(ohci, "GetStatus", wIndex, temp); 7511da177e4SLinus Torvalds break; 7521da177e4SLinus Torvalds case SetHubFeature: 7531da177e4SLinus Torvalds switch (wValue) { 7541da177e4SLinus Torvalds case C_HUB_OVER_CURRENT: 7551da177e4SLinus Torvalds // FIXME: this can be cleared, yes? 7561da177e4SLinus Torvalds case C_HUB_LOCAL_POWER: 7571da177e4SLinus Torvalds break; 7581da177e4SLinus Torvalds default: 7591da177e4SLinus Torvalds goto error; 7601da177e4SLinus Torvalds } 7611da177e4SLinus Torvalds break; 7621da177e4SLinus Torvalds case SetPortFeature: 7631da177e4SLinus Torvalds if (!wIndex || wIndex > ports) 7641da177e4SLinus Torvalds goto error; 7651da177e4SLinus Torvalds wIndex--; 7661da177e4SLinus Torvalds switch (wValue) { 7671da177e4SLinus Torvalds case USB_PORT_FEAT_SUSPEND: 7681da177e4SLinus Torvalds #ifdef CONFIG_USB_OTG 7691da177e4SLinus Torvalds if (hcd->self.otg_port == (wIndex + 1) 7701da177e4SLinus Torvalds && hcd->self.b_hnp_enable) 771e8b24450SDmitry Baryshkov ohci->start_hnp(ohci); 7721da177e4SLinus Torvalds else 7731da177e4SLinus Torvalds #endif 7741da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PSS, 7751da177e4SLinus Torvalds &ohci->regs->roothub.portstatus [wIndex]); 7761da177e4SLinus Torvalds break; 7771da177e4SLinus Torvalds case USB_PORT_FEAT_POWER: 7781da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PPS, 7791da177e4SLinus Torvalds &ohci->regs->roothub.portstatus [wIndex]); 7801da177e4SLinus Torvalds break; 7811da177e4SLinus Torvalds case USB_PORT_FEAT_RESET: 78223d10a9eSTakamasa Ohtake retval = root_port_reset (ohci, wIndex); 7831da177e4SLinus Torvalds break; 7841da177e4SLinus Torvalds default: 7851da177e4SLinus Torvalds goto error; 7861da177e4SLinus Torvalds } 7871da177e4SLinus Torvalds break; 7881da177e4SLinus Torvalds 7891da177e4SLinus Torvalds default: 7901da177e4SLinus Torvalds error: 7911da177e4SLinus Torvalds /* "protocol stall" on error */ 7921da177e4SLinus Torvalds retval = -EPIPE; 7931da177e4SLinus Torvalds } 7941da177e4SLinus Torvalds return retval; 7951da177e4SLinus Torvalds } 79642b59ebaSLaurent Pinchart EXPORT_SYMBOL_GPL(ohci_hub_control); 797