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 427d12e780SDavid Howells static void dl_done_list (struct ohci_hcd *); 437d12e780SDavid Howells static void finish_unlinks (struct ohci_hcd *, u16); 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 } 907d12e780SDavid Howells dl_done_list (ohci); 917d12e780SDavid Howells finish_unlinks (ohci, ohci_frame_no(ohci)); 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds /* maybe resume can wake root hub */ 9458a97ffeSAlan Stern if (ohci_to_hcd(ohci)->self.root_hub->do_remote_wakeup || autostop) { 951da177e4SLinus Torvalds ohci->hc_control |= OHCI_CTRL_RWE; 9658a97ffeSAlan Stern } else { 975f47493cSAlan Stern ohci_writel(ohci, OHCI_INTR_RHSC | OHCI_INTR_RD, 985f47493cSAlan Stern &ohci->regs->intrdisable); 991da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_CTRL_RWE; 1001f7e1a3bSAlan Stern } 1011da177e4SLinus Torvalds 102f197b2c5SDavid Brownell /* Suspend hub ... this is the "global (to this bus) suspend" mode, 103f197b2c5SDavid Brownell * which doesn't imply ports will first be individually suspended. 104f197b2c5SDavid Brownell */ 1051da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_CTRL_HCFS; 1061da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_SUSPEND; 1071da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 1081da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds /* no resumes until devices finish suspending */ 1118d1a243bSAlan Stern if (!autostop) { 1121da177e4SLinus Torvalds ohci->next_statechange = jiffies + msecs_to_jiffies (5); 1138d1a243bSAlan Stern ohci->autostop = 0; 1148d1a243bSAlan Stern } 115d413984aSDavid Brownell 1161da177e4SLinus Torvalds done: 1171da177e4SLinus Torvalds return status; 1181da177e4SLinus Torvalds } 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds static inline struct ed *find_head (struct ed *ed) 1211da177e4SLinus Torvalds { 1221da177e4SLinus Torvalds /* for bulk and control lists */ 1231da177e4SLinus Torvalds while (ed->ed_prev) 1241da177e4SLinus Torvalds ed = ed->ed_prev; 1251da177e4SLinus Torvalds return ed; 1261da177e4SLinus Torvalds } 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds /* caller has locked the root hub */ 1298d1a243bSAlan Stern static int ohci_rh_resume (struct ohci_hcd *ohci) 1308d1a243bSAlan Stern __releases(ohci->lock) 1318d1a243bSAlan Stern __acquires(ohci->lock) 1321da177e4SLinus Torvalds { 1338d1a243bSAlan Stern struct usb_hcd *hcd = ohci_to_hcd (ohci); 1341da177e4SLinus Torvalds u32 temp, enables; 1351da177e4SLinus Torvalds int status = -EINPROGRESS; 1368d1a243bSAlan Stern int autostopped = ohci->autostop; 1371da177e4SLinus Torvalds 1388d1a243bSAlan Stern ohci->autostop = 0; 1391da177e4SLinus Torvalds ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 142f197b2c5SDavid Brownell /* this can happen after resuming a swsusp snapshot */ 1431da177e4SLinus Torvalds if (hcd->state == HC_STATE_RESUMING) { 1441da177e4SLinus Torvalds ohci_dbg (ohci, "BIOS/SMM active, control %03x\n", 1451da177e4SLinus Torvalds ohci->hc_control); 1461da177e4SLinus Torvalds status = -EBUSY; 1471da177e4SLinus Torvalds /* this happens when pmcore resumes HC then root */ 1481da177e4SLinus Torvalds } else { 1491da177e4SLinus Torvalds ohci_dbg (ohci, "duplicate resume\n"); 1501da177e4SLinus Torvalds status = 0; 1511da177e4SLinus Torvalds } 1521da177e4SLinus Torvalds } else switch (ohci->hc_control & OHCI_CTRL_HCFS) { 1531da177e4SLinus Torvalds case OHCI_USB_SUSPEND: 1541da177e4SLinus Torvalds ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES); 1551da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_RESUME; 1561da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 1571da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 1588d1a243bSAlan Stern ohci_dbg (ohci, "%s root hub\n", 1598d1a243bSAlan Stern autostopped ? "auto-start" : "resume"); 1601da177e4SLinus Torvalds break; 1611da177e4SLinus Torvalds case OHCI_USB_RESUME: 1621da177e4SLinus Torvalds /* HCFS changes sometime after INTR_RD */ 1631b7be3c0SAlan Stern ohci_dbg(ohci, "%swakeup root hub\n", 164583ceadaSAlan Stern autostopped ? "auto-" : ""); 1651da177e4SLinus Torvalds break; 1661da177e4SLinus Torvalds case OHCI_USB_OPER: 167f197b2c5SDavid Brownell /* this can happen after resuming a swsusp snapshot */ 168f197b2c5SDavid Brownell ohci_dbg (ohci, "snapshot resume? reinit\n"); 169f197b2c5SDavid Brownell status = -EBUSY; 1701da177e4SLinus Torvalds break; 1711da177e4SLinus Torvalds default: /* RESET, we lost power */ 172f197b2c5SDavid Brownell ohci_dbg (ohci, "lost power\n"); 1731da177e4SLinus Torvalds status = -EBUSY; 1741da177e4SLinus Torvalds } 1751da177e4SLinus Torvalds if (status == -EBUSY) { 1768d1a243bSAlan Stern if (!autostopped) { 1778d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 1781da177e4SLinus Torvalds (void) ohci_init (ohci); 1798d1a243bSAlan Stern status = ohci_restart (ohci); 180d576bb9fSMichael Hanselmann 181d576bb9fSMichael Hanselmann usb_root_hub_lost_power(hcd->self.root_hub); 182d576bb9fSMichael Hanselmann 1838d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 1841da177e4SLinus Torvalds } 1858d1a243bSAlan Stern return status; 1868d1a243bSAlan Stern } 1871da177e4SLinus Torvalds if (status != -EINPROGRESS) 1881da177e4SLinus Torvalds return status; 1898d1a243bSAlan Stern if (autostopped) 1908d1a243bSAlan Stern goto skip_resume; 1918d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds /* Some controllers (lucent erratum) need extra-long delays */ 194f197b2c5SDavid Brownell msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1); 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds temp = ohci_readl (ohci, &ohci->regs->control); 1971da177e4SLinus Torvalds temp &= OHCI_CTRL_HCFS; 1981da177e4SLinus Torvalds if (temp != OHCI_USB_RESUME) { 1991da177e4SLinus Torvalds ohci_err (ohci, "controller won't resume\n"); 200565402baSAlan Stern spin_lock_irq(&ohci->lock); 2011da177e4SLinus Torvalds return -EBUSY; 2021da177e4SLinus Torvalds } 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds /* disable old schedule state, reinit from scratch */ 2051da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_controlhead); 2061da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent); 2071da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead); 2081da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent); 2091da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent); 2101da177e4SLinus Torvalds ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca); 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds /* Sometimes PCI D3 suspend trashes frame timings ... */ 2131da177e4SLinus Torvalds periodic_reinit (ohci); 2141da177e4SLinus Torvalds 2158d1a243bSAlan Stern /* the following code is executed with ohci->lock held and 2168d1a243bSAlan Stern * irqs disabled if and only if autostopped is true 2178d1a243bSAlan Stern */ 2188d1a243bSAlan Stern 2198d1a243bSAlan Stern skip_resume: 2201da177e4SLinus Torvalds /* interrupts might have been disabled */ 2211da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); 2221da177e4SLinus Torvalds if (ohci->ed_rm_list) 2231da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable); 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds /* Then re-enable operations */ 2261da177e4SLinus Torvalds ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control); 2271da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 2288d1a243bSAlan Stern if (!autostopped) 2291da177e4SLinus Torvalds msleep (3); 2301da177e4SLinus Torvalds 2316a9062f3SDavid Brownell temp = ohci->hc_control; 2326a9062f3SDavid Brownell temp &= OHCI_CTRL_RWC; 2336a9062f3SDavid Brownell temp |= OHCI_CONTROL_INIT | OHCI_USB_OPER; 2341da177e4SLinus Torvalds ohci->hc_control = temp; 2351da177e4SLinus Torvalds ohci_writel (ohci, temp, &ohci->regs->control); 2361da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds /* TRSMRCY */ 2398d1a243bSAlan Stern if (!autostopped) { 2401da177e4SLinus Torvalds msleep (10); 2418d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 2428d1a243bSAlan Stern } 2438d1a243bSAlan Stern /* now ohci->lock is always held and irqs are always disabled */ 2441da177e4SLinus Torvalds 245d413984aSDavid Brownell /* keep it alive for more than ~5x suspend + resume costs */ 246d413984aSDavid Brownell ohci->next_statechange = jiffies + STATECHANGE_DELAY; 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds /* maybe turn schedules back on */ 2491da177e4SLinus Torvalds enables = 0; 2501da177e4SLinus Torvalds temp = 0; 2511da177e4SLinus Torvalds if (!ohci->ed_rm_list) { 2521da177e4SLinus Torvalds if (ohci->ed_controltail) { 2531da177e4SLinus Torvalds ohci_writel (ohci, 2541da177e4SLinus Torvalds find_head (ohci->ed_controltail)->dma, 2551da177e4SLinus Torvalds &ohci->regs->ed_controlhead); 2561da177e4SLinus Torvalds enables |= OHCI_CTRL_CLE; 2571da177e4SLinus Torvalds temp |= OHCI_CLF; 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds if (ohci->ed_bulktail) { 2601da177e4SLinus Torvalds ohci_writel (ohci, find_head (ohci->ed_bulktail)->dma, 2611da177e4SLinus Torvalds &ohci->regs->ed_bulkhead); 2621da177e4SLinus Torvalds enables |= OHCI_CTRL_BLE; 2631da177e4SLinus Torvalds temp |= OHCI_BLF; 2641da177e4SLinus Torvalds } 2651da177e4SLinus Torvalds } 2661da177e4SLinus Torvalds if (hcd->self.bandwidth_isoc_reqs || hcd->self.bandwidth_int_reqs) 2671da177e4SLinus Torvalds enables |= OHCI_CTRL_PLE|OHCI_CTRL_IE; 2681da177e4SLinus Torvalds if (enables) { 2691da177e4SLinus Torvalds ohci_dbg (ohci, "restarting schedules ... %08x\n", enables); 2701da177e4SLinus Torvalds ohci->hc_control |= enables; 2711da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 2721da177e4SLinus Torvalds if (temp) 2731da177e4SLinus Torvalds ohci_writel (ohci, temp, &ohci->regs->cmdstatus); 2741da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 2751da177e4SLinus Torvalds } 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds return 0; 2781da177e4SLinus Torvalds } 2791da177e4SLinus Torvalds 2808d1a243bSAlan Stern static int ohci_bus_suspend (struct usb_hcd *hcd) 2818d1a243bSAlan Stern { 2828d1a243bSAlan Stern struct ohci_hcd *ohci = hcd_to_ohci (hcd); 2838d1a243bSAlan Stern int rc; 2848d1a243bSAlan Stern 2858d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 2868d1a243bSAlan Stern 2878d1a243bSAlan Stern if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 2888d1a243bSAlan Stern rc = -ESHUTDOWN; 2898d1a243bSAlan Stern else 2908d1a243bSAlan Stern rc = ohci_rh_suspend (ohci, 0); 2918d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 2928d1a243bSAlan Stern return rc; 2938d1a243bSAlan Stern } 2948d1a243bSAlan Stern 2958d1a243bSAlan Stern static int ohci_bus_resume (struct usb_hcd *hcd) 2968d1a243bSAlan Stern { 2978d1a243bSAlan Stern struct ohci_hcd *ohci = hcd_to_ohci (hcd); 2988d1a243bSAlan Stern int rc; 2998d1a243bSAlan Stern 3008d1a243bSAlan Stern if (time_before (jiffies, ohci->next_statechange)) 3018d1a243bSAlan Stern msleep(5); 3028d1a243bSAlan Stern 3038d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 3048d1a243bSAlan Stern 3058d1a243bSAlan Stern if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 3068d1a243bSAlan Stern rc = -ESHUTDOWN; 3078d1a243bSAlan Stern else 3088d1a243bSAlan Stern rc = ohci_rh_resume (ohci); 3098d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 3108d1a243bSAlan Stern 3118d1a243bSAlan Stern /* poll until we know a device is connected or we autostop */ 3128d1a243bSAlan Stern if (rc == 0) 3138d1a243bSAlan Stern usb_hcd_poll_rh_status(hcd); 3148d1a243bSAlan Stern return rc; 3158d1a243bSAlan Stern } 3168d1a243bSAlan Stern 31743bbb7e0SAlan Stern /* Carry out the final steps of resuming the controller device */ 31843bbb7e0SAlan Stern static void ohci_finish_controller_resume(struct usb_hcd *hcd) 31943bbb7e0SAlan Stern { 32043bbb7e0SAlan Stern struct ohci_hcd *ohci = hcd_to_ohci(hcd); 32143bbb7e0SAlan Stern int port; 32243bbb7e0SAlan Stern bool need_reinit = false; 32343bbb7e0SAlan Stern 32443bbb7e0SAlan Stern /* See if the controller is already running or has been reset */ 32543bbb7e0SAlan Stern ohci->hc_control = ohci_readl(ohci, &ohci->regs->control); 32643bbb7e0SAlan Stern if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 32743bbb7e0SAlan Stern need_reinit = true; 32843bbb7e0SAlan Stern } else { 32943bbb7e0SAlan Stern switch (ohci->hc_control & OHCI_CTRL_HCFS) { 33043bbb7e0SAlan Stern case OHCI_USB_OPER: 33143bbb7e0SAlan Stern case OHCI_USB_RESET: 33243bbb7e0SAlan Stern need_reinit = true; 33343bbb7e0SAlan Stern } 33443bbb7e0SAlan Stern } 33543bbb7e0SAlan Stern 33643bbb7e0SAlan Stern /* If needed, reinitialize and suspend the root hub */ 33743bbb7e0SAlan Stern if (need_reinit) { 33843bbb7e0SAlan Stern spin_lock_irq(&ohci->lock); 33943bbb7e0SAlan Stern hcd->state = HC_STATE_RESUMING; 34043bbb7e0SAlan Stern ohci_rh_resume(ohci); 34143bbb7e0SAlan Stern hcd->state = HC_STATE_QUIESCING; 34243bbb7e0SAlan Stern ohci_rh_suspend(ohci, 0); 34343bbb7e0SAlan Stern hcd->state = HC_STATE_SUSPENDED; 34443bbb7e0SAlan Stern spin_unlock_irq(&ohci->lock); 34543bbb7e0SAlan Stern } 34643bbb7e0SAlan Stern 34743bbb7e0SAlan Stern /* Normally just turn on port power and enable interrupts */ 34843bbb7e0SAlan Stern else { 34943bbb7e0SAlan Stern ohci_dbg(ohci, "powerup ports\n"); 35043bbb7e0SAlan Stern for (port = 0; port < ohci->num_ports; port++) 35143bbb7e0SAlan Stern ohci_writel(ohci, RH_PS_PPS, 35243bbb7e0SAlan Stern &ohci->regs->roothub.portstatus[port]); 35343bbb7e0SAlan Stern 35443bbb7e0SAlan Stern ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable); 35543bbb7e0SAlan Stern ohci_readl(ohci, &ohci->regs->intrenable); 35643bbb7e0SAlan Stern msleep(20); 35743bbb7e0SAlan Stern } 35843bbb7e0SAlan Stern } 35943bbb7e0SAlan Stern 3601f9fc882SAlan Stern /* Carry out polling-, autostop-, and autoresume-related state changes */ 3611f9fc882SAlan Stern static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 3621f9fc882SAlan Stern int any_connected) 3631f9fc882SAlan Stern { 3641f9fc882SAlan Stern int poll_rh = 1; 365*4a511bc3SAlan Stern int rhsc_status, rhsc_enable; 3661f9fc882SAlan Stern 367*4a511bc3SAlan Stern /* Some broken controllers never turn off RHCS in the interrupt 368*4a511bc3SAlan Stern * status register. For their sake we won't re-enable RHSC 369*4a511bc3SAlan Stern * interrupts if the interrupt bit is already active. 370b5fb454fSAlan Stern */ 371*4a511bc3SAlan Stern rhsc_status = ohci_readl(ohci, &ohci->regs->intrstatus) & 372*4a511bc3SAlan Stern OHCI_INTR_RHSC; 373*4a511bc3SAlan Stern rhsc_enable = ohci_readl(ohci, &ohci->regs->intrenable) & 374*4a511bc3SAlan Stern OHCI_INTR_RHSC; 375*4a511bc3SAlan Stern 376*4a511bc3SAlan Stern switch (ohci->hc_control & OHCI_CTRL_HCFS) { 377*4a511bc3SAlan Stern case OHCI_USB_OPER: 378*4a511bc3SAlan Stern /* If no status changes are pending, enable RHSC interrupts. */ 379*4a511bc3SAlan Stern if (!rhsc_enable && !rhsc_status && !changed) { 380*4a511bc3SAlan Stern rhsc_enable = OHCI_INTR_RHSC; 381*4a511bc3SAlan Stern ohci_writel(ohci, rhsc_enable, &ohci->regs->intrenable); 382b5fb454fSAlan Stern } 383b5fb454fSAlan Stern 384b5fb454fSAlan Stern /* Keep on polling until we know a device is connected 385b5fb454fSAlan Stern * and RHSC is enabled, or until we autostop. 386b5fb454fSAlan Stern */ 3871f9fc882SAlan Stern if (!ohci->autostop) { 3881f9fc882SAlan Stern if (any_connected || 3891f9fc882SAlan Stern !device_may_wakeup(&ohci_to_hcd(ohci) 3901f9fc882SAlan Stern ->self.root_hub->dev)) { 391*4a511bc3SAlan Stern if (rhsc_enable) 3921f9fc882SAlan Stern poll_rh = 0; 3931f9fc882SAlan Stern } else { 3941f9fc882SAlan Stern ohci->autostop = 1; 3951f9fc882SAlan Stern ohci->next_statechange = jiffies + HZ; 3961f9fc882SAlan Stern } 3971f9fc882SAlan Stern 3981f9fc882SAlan Stern /* if no devices have been attached for one second, autostop */ 3991f9fc882SAlan Stern } else { 4001f9fc882SAlan Stern if (changed || any_connected) { 4011f9fc882SAlan Stern ohci->autostop = 0; 4021f9fc882SAlan Stern ohci->next_statechange = jiffies + 4031f9fc882SAlan Stern STATECHANGE_DELAY; 404*4a511bc3SAlan Stern } else if (time_after_eq(jiffies, 4051f9fc882SAlan Stern ohci->next_statechange) 4061f9fc882SAlan Stern && !ohci->ed_rm_list 4071f9fc882SAlan Stern && !(ohci->hc_control & 4081f9fc882SAlan Stern OHCI_SCHED_ENABLES)) { 4091f9fc882SAlan Stern ohci_rh_suspend(ohci, 1); 410*4a511bc3SAlan Stern if (rhsc_enable) 411b5fb454fSAlan Stern poll_rh = 0; 4121f9fc882SAlan Stern } 4131f9fc882SAlan Stern } 4141f9fc882SAlan Stern break; 4151f9fc882SAlan Stern 4161f9fc882SAlan Stern case OHCI_USB_SUSPEND: 4171f9fc882SAlan Stern case OHCI_USB_RESUME: 418*4a511bc3SAlan Stern /* if there is a port change, autostart or ask to be resumed */ 4191f9fc882SAlan Stern if (changed) { 4201f9fc882SAlan Stern if (ohci->autostop) 4211f9fc882SAlan Stern ohci_rh_resume(ohci); 4221f9fc882SAlan Stern else 4231f9fc882SAlan Stern usb_hcd_resume_root_hub(ohci_to_hcd(ohci)); 4241f9fc882SAlan Stern } else { 425*4a511bc3SAlan Stern if (!rhsc_enable && !rhsc_status && (ohci->autostop || 426b5fb454fSAlan Stern ohci_to_hcd(ohci)->self.root_hub-> 427*4a511bc3SAlan Stern do_remote_wakeup)) { 428*4a511bc3SAlan Stern rhsc_enable = OHCI_INTR_RHSC; 429*4a511bc3SAlan Stern ohci_writel(ohci, rhsc_enable, 430b5fb454fSAlan Stern &ohci->regs->intrenable); 431*4a511bc3SAlan Stern } 432*4a511bc3SAlan Stern if (rhsc_enable) 4331f9fc882SAlan Stern poll_rh = 0; 4341f9fc882SAlan Stern } 4351f9fc882SAlan Stern break; 4361f9fc882SAlan Stern } 4371f9fc882SAlan Stern return poll_rh; 4381f9fc882SAlan Stern } 4391f9fc882SAlan Stern 4401f9fc882SAlan Stern #else /* CONFIG_PM */ 4411f9fc882SAlan Stern 4421f9fc882SAlan Stern static inline int ohci_rh_resume(struct ohci_hcd *ohci) 4431f9fc882SAlan Stern { 4441f9fc882SAlan Stern return 0; 4451f9fc882SAlan Stern } 4461f9fc882SAlan Stern 4471f9fc882SAlan Stern /* Carry out polling-related state changes. 4481f9fc882SAlan Stern * autostop isn't used when CONFIG_PM is turned off. 4491f9fc882SAlan Stern */ 4501f9fc882SAlan Stern static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 4511f9fc882SAlan Stern int any_connected) 4521f9fc882SAlan Stern { 453*4a511bc3SAlan Stern int rhsc_status; 454*4a511bc3SAlan Stern 455b5fb454fSAlan Stern /* If RHSC is enabled, don't poll */ 45609ca8adbSLinus Torvalds if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC) 457b5fb454fSAlan Stern return 0; 458b5fb454fSAlan Stern 459*4a511bc3SAlan Stern /* If no status changes are pending, enable RHSC interrupts */ 460*4a511bc3SAlan Stern rhsc_status = ohci_readl(ohci, &ohci->regs->intrstatus) & 461*4a511bc3SAlan Stern OHCI_INTR_RHSC; 462*4a511bc3SAlan Stern if (!changed && !rhsc_status) { 463b5fb454fSAlan Stern ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable); 464b5fb454fSAlan Stern return 0; 465b5fb454fSAlan Stern } 466b5fb454fSAlan Stern return 1; 4671f9fc882SAlan Stern } 4681f9fc882SAlan Stern 4698ad7fe16SDavid Brownell #endif /* CONFIG_PM */ 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds /* build "status change" packet (one or two bytes) from HC registers */ 4741da177e4SLinus Torvalds 4751da177e4SLinus Torvalds static int 4761da177e4SLinus Torvalds ohci_hub_status_data (struct usb_hcd *hcd, char *buf) 4771da177e4SLinus Torvalds { 4781da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 479fdd13b36SDavid Brownell int i, changed = 0, length = 1; 480052ac01aSAlan Stern int any_connected = 0; 4811da177e4SLinus Torvalds unsigned long flags; 4821da177e4SLinus Torvalds 4831da177e4SLinus Torvalds spin_lock_irqsave (&ohci->lock, flags); 4846fd75b19SAlan Stern if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 4856fd75b19SAlan Stern goto done; 4861da177e4SLinus Torvalds 487fdd13b36SDavid Brownell /* undocumented erratum seen on at least rev D */ 488fdd13b36SDavid Brownell if ((ohci->flags & OHCI_QUIRK_AMD756) 489fdd13b36SDavid Brownell && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) { 490fdd13b36SDavid Brownell ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n", 4911da177e4SLinus Torvalds ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP); 4921da177e4SLinus Torvalds /* retry later; "should not happen" */ 4931da177e4SLinus Torvalds goto done; 4941da177e4SLinus Torvalds } 4951da177e4SLinus Torvalds 4961da177e4SLinus Torvalds /* init status */ 4971da177e4SLinus Torvalds if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC)) 4981da177e4SLinus Torvalds buf [0] = changed = 1; 4991da177e4SLinus Torvalds else 5001da177e4SLinus Torvalds buf [0] = 0; 501fdd13b36SDavid Brownell if (ohci->num_ports > 7) { 5021da177e4SLinus Torvalds buf [1] = 0; 5031da177e4SLinus Torvalds length++; 5041da177e4SLinus Torvalds } 5051da177e4SLinus Torvalds 5061da177e4SLinus Torvalds /* look at each port */ 507fdd13b36SDavid Brownell for (i = 0; i < ohci->num_ports; i++) { 5081da177e4SLinus Torvalds u32 status = roothub_portstatus (ohci, i); 5091da177e4SLinus Torvalds 5108d1a243bSAlan Stern /* can't autostop if ports are connected */ 5118d1a243bSAlan Stern any_connected |= (status & RH_PS_CCS); 5128d1a243bSAlan Stern 5131da177e4SLinus Torvalds if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC 5141da177e4SLinus Torvalds | RH_PS_OCIC | RH_PS_PRSC)) { 5151da177e4SLinus Torvalds changed = 1; 5161da177e4SLinus Torvalds if (i < 7) 5171da177e4SLinus Torvalds buf [0] |= 1 << (i + 1); 5181da177e4SLinus Torvalds else 5191da177e4SLinus Torvalds buf [1] |= 1 << (i - 7); 5201da177e4SLinus Torvalds } 5211da177e4SLinus Torvalds } 522d413984aSDavid Brownell 5231f9fc882SAlan Stern hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed, 5241f9fc882SAlan Stern any_connected); 525d413984aSDavid Brownell 5261da177e4SLinus Torvalds done: 5271da177e4SLinus Torvalds spin_unlock_irqrestore (&ohci->lock, flags); 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds return changed ? length : 0; 5301da177e4SLinus Torvalds } 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 5331da177e4SLinus Torvalds 5341da177e4SLinus Torvalds static void 5351da177e4SLinus Torvalds ohci_hub_descriptor ( 5361da177e4SLinus Torvalds struct ohci_hcd *ohci, 5371da177e4SLinus Torvalds struct usb_hub_descriptor *desc 5381da177e4SLinus Torvalds ) { 5391da177e4SLinus Torvalds u32 rh = roothub_a (ohci); 5401da177e4SLinus Torvalds u16 temp; 5411da177e4SLinus Torvalds 5421da177e4SLinus Torvalds desc->bDescriptorType = 0x29; 5431da177e4SLinus Torvalds desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24; 5441da177e4SLinus Torvalds desc->bHubContrCurrent = 0; 5451da177e4SLinus Torvalds 546fdd13b36SDavid Brownell desc->bNbrPorts = ohci->num_ports; 547fdd13b36SDavid Brownell temp = 1 + (ohci->num_ports / 8); 5481da177e4SLinus Torvalds desc->bDescLength = 7 + 2 * temp; 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvalds temp = 0; 5511da177e4SLinus Torvalds if (rh & RH_A_NPS) /* no power switching? */ 5521da177e4SLinus Torvalds temp |= 0x0002; 5531da177e4SLinus Torvalds if (rh & RH_A_PSM) /* per-port power switching? */ 5541da177e4SLinus Torvalds temp |= 0x0001; 5551da177e4SLinus Torvalds if (rh & RH_A_NOCP) /* no overcurrent reporting? */ 5561da177e4SLinus Torvalds temp |= 0x0010; 5571da177e4SLinus Torvalds else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */ 5581da177e4SLinus Torvalds temp |= 0x0008; 5591da177e4SLinus Torvalds desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 5621da177e4SLinus Torvalds rh = roothub_b (ohci); 563b2134bcdSKAMBAROV, ZAUR memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); 5641da177e4SLinus Torvalds desc->bitmap [0] = rh & RH_B_DR; 565fdd13b36SDavid Brownell if (ohci->num_ports > 7) { 5661da177e4SLinus Torvalds desc->bitmap [1] = (rh & RH_B_DR) >> 8; 567b2134bcdSKAMBAROV, ZAUR desc->bitmap [2] = 0xff; 5681da177e4SLinus Torvalds } else 5691da177e4SLinus Torvalds desc->bitmap [1] = 0xff; 5701da177e4SLinus Torvalds } 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds #ifdef CONFIG_USB_OTG 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvalds static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port) 5771da177e4SLinus Torvalds { 5781da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 5791da177e4SLinus Torvalds u32 status; 5801da177e4SLinus Torvalds 5811da177e4SLinus Torvalds if (!port) 5821da177e4SLinus Torvalds return -EINVAL; 5831da177e4SLinus Torvalds port--; 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds /* start port reset before HNP protocol times out */ 5861da177e4SLinus Torvalds status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]); 5871da177e4SLinus Torvalds if (!(status & RH_PS_CCS)) 5881da177e4SLinus Torvalds return -ENODEV; 5891da177e4SLinus Torvalds 5901da177e4SLinus Torvalds /* khubd will finish the reset later */ 5911da177e4SLinus Torvalds ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]); 5921da177e4SLinus Torvalds return 0; 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds #else 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds #define ohci_start_port_reset NULL 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds #endif 6001da177e4SLinus Torvalds 6011da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 6021da177e4SLinus Torvalds 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds /* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling, 6051da177e4SLinus Torvalds * not necessarily continuous ... to guard against resume signaling. 6061da177e4SLinus Torvalds * The short timeout is safe for non-root hubs, and is backward-compatible 6071da177e4SLinus Torvalds * with earlier Linux hosts. 6081da177e4SLinus Torvalds */ 6091da177e4SLinus Torvalds #ifdef CONFIG_USB_SUSPEND 6101da177e4SLinus Torvalds #define PORT_RESET_MSEC 50 6111da177e4SLinus Torvalds #else 6121da177e4SLinus Torvalds #define PORT_RESET_MSEC 10 6131da177e4SLinus Torvalds #endif 6141da177e4SLinus Torvalds 6151da177e4SLinus Torvalds /* this timer value might be vendor-specific ... */ 6161da177e4SLinus Torvalds #define PORT_RESET_HW_MSEC 10 6171da177e4SLinus Torvalds 6181da177e4SLinus Torvalds /* wrap-aware logic morphed from <linux/jiffies.h> */ 6191da177e4SLinus Torvalds #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds /* called from some task, normally khubd */ 62223d10a9eSTakamasa Ohtake static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port) 6231da177e4SLinus Torvalds { 6241da177e4SLinus Torvalds __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; 6251b7b61c5SAlan Stern u32 temp = 0; 6261da177e4SLinus Torvalds u16 now = ohci_readl(ohci, &ohci->regs->fmnumber); 6271da177e4SLinus Torvalds u16 reset_done = now + PORT_RESET_MSEC; 628e01e7fe3SDavid Brownell int limit_1 = DIV_ROUND_UP(PORT_RESET_MSEC, PORT_RESET_HW_MSEC); 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds /* build a "continuous enough" reset signal, with up to 6311da177e4SLinus Torvalds * 3msec gap between pulses. scheduler HZ==100 must work; 6321da177e4SLinus Torvalds * this might need to be deadline-scheduled. 6331da177e4SLinus Torvalds */ 6341da177e4SLinus Torvalds do { 635e01e7fe3SDavid Brownell int limit_2; 636e01e7fe3SDavid Brownell 6371da177e4SLinus Torvalds /* spin until any current reset finishes */ 638e01e7fe3SDavid Brownell limit_2 = PORT_RESET_HW_MSEC * 2; 639e01e7fe3SDavid Brownell while (--limit_2 >= 0) { 6401da177e4SLinus Torvalds temp = ohci_readl (ohci, portstat); 64123d10a9eSTakamasa Ohtake /* handle e.g. CardBus eject */ 64223d10a9eSTakamasa Ohtake if (temp == ~(u32)0) 64323d10a9eSTakamasa Ohtake return -ESHUTDOWN; 6441da177e4SLinus Torvalds if (!(temp & RH_PS_PRS)) 6451da177e4SLinus Torvalds break; 6461da177e4SLinus Torvalds udelay (500); 6471da177e4SLinus Torvalds } 6481da177e4SLinus Torvalds 649e01e7fe3SDavid Brownell /* timeout (a hardware error) has been observed when 650e01e7fe3SDavid Brownell * EHCI sets CF while this driver is resetting a port; 651e01e7fe3SDavid Brownell * presumably other disconnect paths might do it too. 652e01e7fe3SDavid Brownell */ 653e01e7fe3SDavid Brownell if (limit_2 < 0) { 654e01e7fe3SDavid Brownell ohci_dbg(ohci, 655e01e7fe3SDavid Brownell "port[%d] reset timeout, stat %08x\n", 656e01e7fe3SDavid Brownell port, temp); 657e01e7fe3SDavid Brownell break; 658e01e7fe3SDavid Brownell } 659e01e7fe3SDavid Brownell 6601da177e4SLinus Torvalds if (!(temp & RH_PS_CCS)) 6611da177e4SLinus Torvalds break; 6621da177e4SLinus Torvalds if (temp & RH_PS_PRSC) 6631da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PRSC, portstat); 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds /* start the next reset, sleep till it's probably done */ 6661da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PRS, portstat); 6671da177e4SLinus Torvalds msleep(PORT_RESET_HW_MSEC); 6681da177e4SLinus Torvalds now = ohci_readl(ohci, &ohci->regs->fmnumber); 669e01e7fe3SDavid Brownell } while (tick_before(now, reset_done) && --limit_1 >= 0); 670e01e7fe3SDavid Brownell 671e01e7fe3SDavid Brownell /* caller synchronizes using PRSC ... and handles PRS 672e01e7fe3SDavid Brownell * still being set when this returns. 673e01e7fe3SDavid Brownell */ 67423d10a9eSTakamasa Ohtake 67523d10a9eSTakamasa Ohtake return 0; 6761da177e4SLinus Torvalds } 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds static int ohci_hub_control ( 6791da177e4SLinus Torvalds struct usb_hcd *hcd, 6801da177e4SLinus Torvalds u16 typeReq, 6811da177e4SLinus Torvalds u16 wValue, 6821da177e4SLinus Torvalds u16 wIndex, 6831da177e4SLinus Torvalds char *buf, 6841da177e4SLinus Torvalds u16 wLength 6851da177e4SLinus Torvalds ) { 6861da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 6871da177e4SLinus Torvalds int ports = hcd_to_bus (hcd)->root_hub->maxchild; 6881da177e4SLinus Torvalds u32 temp; 6891da177e4SLinus Torvalds int retval = 0; 6901da177e4SLinus Torvalds 6918de98402SBenjamin Herrenschmidt if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 6928de98402SBenjamin Herrenschmidt return -ESHUTDOWN; 6938de98402SBenjamin Herrenschmidt 6941da177e4SLinus Torvalds switch (typeReq) { 6951da177e4SLinus Torvalds case ClearHubFeature: 6961da177e4SLinus Torvalds switch (wValue) { 6971da177e4SLinus Torvalds case C_HUB_OVER_CURRENT: 6981da177e4SLinus Torvalds ohci_writel (ohci, RH_HS_OCIC, 6991da177e4SLinus Torvalds &ohci->regs->roothub.status); 7001da177e4SLinus Torvalds case C_HUB_LOCAL_POWER: 7011da177e4SLinus Torvalds break; 7021da177e4SLinus Torvalds default: 7031da177e4SLinus Torvalds goto error; 7041da177e4SLinus Torvalds } 7051da177e4SLinus Torvalds break; 7061da177e4SLinus Torvalds case ClearPortFeature: 7071da177e4SLinus Torvalds if (!wIndex || wIndex > ports) 7081da177e4SLinus Torvalds goto error; 7091da177e4SLinus Torvalds wIndex--; 7101da177e4SLinus Torvalds 7111da177e4SLinus Torvalds switch (wValue) { 7121da177e4SLinus Torvalds case USB_PORT_FEAT_ENABLE: 7131da177e4SLinus Torvalds temp = RH_PS_CCS; 7141da177e4SLinus Torvalds break; 7151da177e4SLinus Torvalds case USB_PORT_FEAT_C_ENABLE: 7161da177e4SLinus Torvalds temp = RH_PS_PESC; 7171da177e4SLinus Torvalds break; 7181da177e4SLinus Torvalds case USB_PORT_FEAT_SUSPEND: 7191da177e4SLinus Torvalds temp = RH_PS_POCI; 7201da177e4SLinus Torvalds break; 7211da177e4SLinus Torvalds case USB_PORT_FEAT_C_SUSPEND: 7221da177e4SLinus Torvalds temp = RH_PS_PSSC; 7231da177e4SLinus Torvalds break; 7241da177e4SLinus Torvalds case USB_PORT_FEAT_POWER: 7251da177e4SLinus Torvalds temp = RH_PS_LSDA; 7261da177e4SLinus Torvalds break; 7271da177e4SLinus Torvalds case USB_PORT_FEAT_C_CONNECTION: 7281da177e4SLinus Torvalds temp = RH_PS_CSC; 7291da177e4SLinus Torvalds break; 7301da177e4SLinus Torvalds case USB_PORT_FEAT_C_OVER_CURRENT: 7311da177e4SLinus Torvalds temp = RH_PS_OCIC; 7321da177e4SLinus Torvalds break; 7331da177e4SLinus Torvalds case USB_PORT_FEAT_C_RESET: 7341da177e4SLinus Torvalds temp = RH_PS_PRSC; 7351da177e4SLinus Torvalds break; 7361da177e4SLinus Torvalds default: 7371da177e4SLinus Torvalds goto error; 7381da177e4SLinus Torvalds } 7391da177e4SLinus Torvalds ohci_writel (ohci, temp, 7401da177e4SLinus Torvalds &ohci->regs->roothub.portstatus [wIndex]); 7411da177e4SLinus Torvalds // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]); 7421da177e4SLinus Torvalds break; 7431da177e4SLinus Torvalds case GetHubDescriptor: 7441da177e4SLinus Torvalds ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf); 7451da177e4SLinus Torvalds break; 7461da177e4SLinus Torvalds case GetHubStatus: 7471da177e4SLinus Torvalds temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE); 748a5abdeafSHarvey Harrison put_unaligned_le32(temp, buf); 7491da177e4SLinus Torvalds break; 7501da177e4SLinus Torvalds case GetPortStatus: 7511da177e4SLinus Torvalds if (!wIndex || wIndex > ports) 7521da177e4SLinus Torvalds goto error; 7531da177e4SLinus Torvalds wIndex--; 7541da177e4SLinus Torvalds temp = roothub_portstatus (ohci, wIndex); 755a5abdeafSHarvey Harrison put_unaligned_le32(temp, buf); 7561da177e4SLinus Torvalds 7571da177e4SLinus Torvalds #ifndef OHCI_VERBOSE_DEBUG 7581da177e4SLinus Torvalds if (*(u16*)(buf+2)) /* only if wPortChange is interesting */ 7591da177e4SLinus Torvalds #endif 7601da177e4SLinus Torvalds dbg_port (ohci, "GetStatus", wIndex, temp); 7611da177e4SLinus Torvalds break; 7621da177e4SLinus Torvalds case SetHubFeature: 7631da177e4SLinus Torvalds switch (wValue) { 7641da177e4SLinus Torvalds case C_HUB_OVER_CURRENT: 7651da177e4SLinus Torvalds // FIXME: this can be cleared, yes? 7661da177e4SLinus Torvalds case C_HUB_LOCAL_POWER: 7671da177e4SLinus Torvalds break; 7681da177e4SLinus Torvalds default: 7691da177e4SLinus Torvalds goto error; 7701da177e4SLinus Torvalds } 7711da177e4SLinus Torvalds break; 7721da177e4SLinus Torvalds case SetPortFeature: 7731da177e4SLinus Torvalds if (!wIndex || wIndex > ports) 7741da177e4SLinus Torvalds goto error; 7751da177e4SLinus Torvalds wIndex--; 7761da177e4SLinus Torvalds switch (wValue) { 7771da177e4SLinus Torvalds case USB_PORT_FEAT_SUSPEND: 7781da177e4SLinus Torvalds #ifdef CONFIG_USB_OTG 7791da177e4SLinus Torvalds if (hcd->self.otg_port == (wIndex + 1) 7801da177e4SLinus Torvalds && hcd->self.b_hnp_enable) 781e8b24450SDmitry Baryshkov ohci->start_hnp(ohci); 7821da177e4SLinus Torvalds else 7831da177e4SLinus Torvalds #endif 7841da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PSS, 7851da177e4SLinus Torvalds &ohci->regs->roothub.portstatus [wIndex]); 7861da177e4SLinus Torvalds break; 7871da177e4SLinus Torvalds case USB_PORT_FEAT_POWER: 7881da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PPS, 7891da177e4SLinus Torvalds &ohci->regs->roothub.portstatus [wIndex]); 7901da177e4SLinus Torvalds break; 7911da177e4SLinus Torvalds case USB_PORT_FEAT_RESET: 79223d10a9eSTakamasa Ohtake retval = root_port_reset (ohci, wIndex); 7931da177e4SLinus Torvalds break; 7941da177e4SLinus Torvalds default: 7951da177e4SLinus Torvalds goto error; 7961da177e4SLinus Torvalds } 7971da177e4SLinus Torvalds break; 7981da177e4SLinus Torvalds 7991da177e4SLinus Torvalds default: 8001da177e4SLinus Torvalds error: 8011da177e4SLinus Torvalds /* "protocol stall" on error */ 8021da177e4SLinus Torvalds retval = -EPIPE; 8031da177e4SLinus Torvalds } 8041da177e4SLinus Torvalds return retval; 8051da177e4SLinus Torvalds } 8061da177e4SLinus Torvalds 807