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 39d413984aSDavid Brownell /* hcd->hub_irq_enable() */ 40d413984aSDavid Brownell static void ohci_rhsc_enable (struct usb_hcd *hcd) 41d413984aSDavid Brownell { 42d413984aSDavid Brownell struct ohci_hcd *ohci = hcd_to_ohci (hcd); 43d413984aSDavid Brownell 44052ac01aSAlan Stern spin_lock_irq(&ohci->lock); 45052ac01aSAlan Stern if (!ohci->autostop) 46052ac01aSAlan Stern del_timer(&hcd->rh_timer); /* Prevent next poll */ 47d413984aSDavid Brownell ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable); 48052ac01aSAlan Stern spin_unlock_irq(&ohci->lock); 49d413984aSDavid Brownell } 50d413984aSDavid Brownell 511da177e4SLinus Torvalds #define OHCI_SCHED_ENABLES \ 521da177e4SLinus Torvalds (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) 531da177e4SLinus Torvalds 547d12e780SDavid Howells static void dl_done_list (struct ohci_hcd *); 557d12e780SDavid Howells static void finish_unlinks (struct ohci_hcd *, u16); 561da177e4SLinus Torvalds 57b1878440SAlan Stern #ifdef CONFIG_PM 588d1a243bSAlan Stern static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) 598d1a243bSAlan Stern __releases(ohci->lock) 608d1a243bSAlan Stern __acquires(ohci->lock) 611da177e4SLinus Torvalds { 621da177e4SLinus Torvalds int status = 0; 638de98402SBenjamin Herrenschmidt 641da177e4SLinus Torvalds ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 651da177e4SLinus Torvalds switch (ohci->hc_control & OHCI_CTRL_HCFS) { 661da177e4SLinus Torvalds case OHCI_USB_RESUME: 671da177e4SLinus Torvalds ohci_dbg (ohci, "resume/suspend?\n"); 681da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_CTRL_HCFS; 691da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_RESET; 701da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 711da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 721da177e4SLinus Torvalds /* FALL THROUGH */ 731da177e4SLinus Torvalds case OHCI_USB_RESET: 741da177e4SLinus Torvalds status = -EBUSY; 751da177e4SLinus Torvalds ohci_dbg (ohci, "needs reinit!\n"); 761da177e4SLinus Torvalds goto done; 771da177e4SLinus Torvalds case OHCI_USB_SUSPEND: 788d1a243bSAlan Stern if (!ohci->autostop) { 791da177e4SLinus Torvalds ohci_dbg (ohci, "already suspended\n"); 801da177e4SLinus Torvalds goto done; 811da177e4SLinus Torvalds } 828d1a243bSAlan Stern } 838d1a243bSAlan Stern ohci_dbg (ohci, "%s root hub\n", 848d1a243bSAlan Stern autostop ? "auto-stop" : "suspend"); 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds /* First stop any processing */ 878d1a243bSAlan Stern if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) { 881da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_SCHED_ENABLES; 891da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 901da177e4SLinus Torvalds ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 911da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus); 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds /* sched disables take effect on the next frame, 941da177e4SLinus Torvalds * then the last WDH could take 6+ msec 951da177e4SLinus Torvalds */ 961da177e4SLinus Torvalds ohci_dbg (ohci, "stopping schedules ...\n"); 978d1a243bSAlan Stern ohci->autostop = 0; 988d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 998d1a243bSAlan Stern msleep (8); 1008d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 1011da177e4SLinus Torvalds } 1027d12e780SDavid Howells dl_done_list (ohci); 1037d12e780SDavid Howells finish_unlinks (ohci, ohci_frame_no(ohci)); 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds /* maybe resume can wake root hub */ 1068d1a243bSAlan Stern if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev) || 1078d1a243bSAlan Stern autostop) 1081da177e4SLinus Torvalds ohci->hc_control |= OHCI_CTRL_RWE; 1091f7e1a3bSAlan Stern else { 1101f7e1a3bSAlan Stern ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable); 1111da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_CTRL_RWE; 1121f7e1a3bSAlan Stern } 1131da177e4SLinus Torvalds 114f197b2c5SDavid Brownell /* Suspend hub ... this is the "global (to this bus) suspend" mode, 115f197b2c5SDavid Brownell * which doesn't imply ports will first be individually suspended. 116f197b2c5SDavid Brownell */ 1171da177e4SLinus Torvalds ohci->hc_control &= ~OHCI_CTRL_HCFS; 1181da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_SUSPEND; 1191da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 1201da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds /* no resumes until devices finish suspending */ 1238d1a243bSAlan Stern if (!autostop) { 1241da177e4SLinus Torvalds ohci->next_statechange = jiffies + msecs_to_jiffies (5); 1258d1a243bSAlan Stern ohci->autostop = 0; 1268d1a243bSAlan Stern } 127d413984aSDavid Brownell 1281da177e4SLinus Torvalds done: 1291da177e4SLinus Torvalds return status; 1301da177e4SLinus Torvalds } 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds static inline struct ed *find_head (struct ed *ed) 1331da177e4SLinus Torvalds { 1341da177e4SLinus Torvalds /* for bulk and control lists */ 1351da177e4SLinus Torvalds while (ed->ed_prev) 1361da177e4SLinus Torvalds ed = ed->ed_prev; 1371da177e4SLinus Torvalds return ed; 1381da177e4SLinus Torvalds } 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds /* caller has locked the root hub */ 1418d1a243bSAlan Stern static int ohci_rh_resume (struct ohci_hcd *ohci) 1428d1a243bSAlan Stern __releases(ohci->lock) 1438d1a243bSAlan Stern __acquires(ohci->lock) 1441da177e4SLinus Torvalds { 1458d1a243bSAlan Stern struct usb_hcd *hcd = ohci_to_hcd (ohci); 1461da177e4SLinus Torvalds u32 temp, enables; 1471da177e4SLinus Torvalds int status = -EINPROGRESS; 1488d1a243bSAlan Stern int autostopped = ohci->autostop; 1491da177e4SLinus Torvalds 1508d1a243bSAlan Stern ohci->autostop = 0; 1511da177e4SLinus Torvalds ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvalds if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 154f197b2c5SDavid Brownell /* this can happen after resuming a swsusp snapshot */ 1551da177e4SLinus Torvalds if (hcd->state == HC_STATE_RESUMING) { 1561da177e4SLinus Torvalds ohci_dbg (ohci, "BIOS/SMM active, control %03x\n", 1571da177e4SLinus Torvalds ohci->hc_control); 1581da177e4SLinus Torvalds status = -EBUSY; 1591da177e4SLinus Torvalds /* this happens when pmcore resumes HC then root */ 1601da177e4SLinus Torvalds } else { 1611da177e4SLinus Torvalds ohci_dbg (ohci, "duplicate resume\n"); 1621da177e4SLinus Torvalds status = 0; 1631da177e4SLinus Torvalds } 1641da177e4SLinus Torvalds } else switch (ohci->hc_control & OHCI_CTRL_HCFS) { 1651da177e4SLinus Torvalds case OHCI_USB_SUSPEND: 1661da177e4SLinus Torvalds ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES); 1671da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_RESUME; 1681da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 1691da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 1708d1a243bSAlan Stern ohci_dbg (ohci, "%s root hub\n", 1718d1a243bSAlan Stern autostopped ? "auto-start" : "resume"); 1721da177e4SLinus Torvalds break; 1731da177e4SLinus Torvalds case OHCI_USB_RESUME: 1741da177e4SLinus Torvalds /* HCFS changes sometime after INTR_RD */ 1751b7be3c0SAlan Stern ohci_dbg(ohci, "%swakeup root hub\n", 176583ceadaSAlan Stern autostopped ? "auto-" : ""); 1771da177e4SLinus Torvalds break; 1781da177e4SLinus Torvalds case OHCI_USB_OPER: 179f197b2c5SDavid Brownell /* this can happen after resuming a swsusp snapshot */ 180f197b2c5SDavid Brownell ohci_dbg (ohci, "snapshot resume? reinit\n"); 181f197b2c5SDavid Brownell status = -EBUSY; 1821da177e4SLinus Torvalds break; 1831da177e4SLinus Torvalds default: /* RESET, we lost power */ 184f197b2c5SDavid Brownell ohci_dbg (ohci, "lost power\n"); 1851da177e4SLinus Torvalds status = -EBUSY; 1861da177e4SLinus Torvalds } 1871da177e4SLinus Torvalds if (status == -EBUSY) { 1888d1a243bSAlan Stern if (!autostopped) { 1898d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 1901da177e4SLinus Torvalds (void) ohci_init (ohci); 1918d1a243bSAlan Stern status = ohci_restart (ohci); 192d576bb9fSMichael Hanselmann 193d576bb9fSMichael Hanselmann usb_root_hub_lost_power(hcd->self.root_hub); 194d576bb9fSMichael Hanselmann 1958d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 1961da177e4SLinus Torvalds } 1978d1a243bSAlan Stern return status; 1988d1a243bSAlan Stern } 1991da177e4SLinus Torvalds if (status != -EINPROGRESS) 2001da177e4SLinus Torvalds return status; 2018d1a243bSAlan Stern if (autostopped) 2028d1a243bSAlan Stern goto skip_resume; 2038d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds /* Some controllers (lucent erratum) need extra-long delays */ 206f197b2c5SDavid Brownell msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1); 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds temp = ohci_readl (ohci, &ohci->regs->control); 2091da177e4SLinus Torvalds temp &= OHCI_CTRL_HCFS; 2101da177e4SLinus Torvalds if (temp != OHCI_USB_RESUME) { 2111da177e4SLinus Torvalds ohci_err (ohci, "controller won't resume\n"); 212565402baSAlan Stern spin_lock_irq(&ohci->lock); 2131da177e4SLinus Torvalds return -EBUSY; 2141da177e4SLinus Torvalds } 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds /* disable old schedule state, reinit from scratch */ 2171da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_controlhead); 2181da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent); 2191da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead); 2201da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent); 2211da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent); 2221da177e4SLinus Torvalds ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca); 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds /* Sometimes PCI D3 suspend trashes frame timings ... */ 2251da177e4SLinus Torvalds periodic_reinit (ohci); 2261da177e4SLinus Torvalds 2278d1a243bSAlan Stern /* the following code is executed with ohci->lock held and 2288d1a243bSAlan Stern * irqs disabled if and only if autostopped is true 2298d1a243bSAlan Stern */ 2308d1a243bSAlan Stern 2318d1a243bSAlan Stern skip_resume: 2321da177e4SLinus Torvalds /* interrupts might have been disabled */ 2331da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); 2341da177e4SLinus Torvalds if (ohci->ed_rm_list) 2351da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable); 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds /* Then re-enable operations */ 2381da177e4SLinus Torvalds ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control); 2391da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 2408d1a243bSAlan Stern if (!autostopped) 2411da177e4SLinus Torvalds msleep (3); 2421da177e4SLinus Torvalds 2436a9062f3SDavid Brownell temp = ohci->hc_control; 2446a9062f3SDavid Brownell temp &= OHCI_CTRL_RWC; 2456a9062f3SDavid Brownell temp |= OHCI_CONTROL_INIT | OHCI_USB_OPER; 2461da177e4SLinus Torvalds ohci->hc_control = temp; 2471da177e4SLinus Torvalds ohci_writel (ohci, temp, &ohci->regs->control); 2481da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds /* TRSMRCY */ 2518d1a243bSAlan Stern if (!autostopped) { 2521da177e4SLinus Torvalds msleep (10); 2538d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 2548d1a243bSAlan Stern } 2558d1a243bSAlan Stern /* now ohci->lock is always held and irqs are always disabled */ 2561da177e4SLinus Torvalds 257d413984aSDavid Brownell /* keep it alive for more than ~5x suspend + resume costs */ 258d413984aSDavid Brownell ohci->next_statechange = jiffies + STATECHANGE_DELAY; 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds /* maybe turn schedules back on */ 2611da177e4SLinus Torvalds enables = 0; 2621da177e4SLinus Torvalds temp = 0; 2631da177e4SLinus Torvalds if (!ohci->ed_rm_list) { 2641da177e4SLinus Torvalds if (ohci->ed_controltail) { 2651da177e4SLinus Torvalds ohci_writel (ohci, 2661da177e4SLinus Torvalds find_head (ohci->ed_controltail)->dma, 2671da177e4SLinus Torvalds &ohci->regs->ed_controlhead); 2681da177e4SLinus Torvalds enables |= OHCI_CTRL_CLE; 2691da177e4SLinus Torvalds temp |= OHCI_CLF; 2701da177e4SLinus Torvalds } 2711da177e4SLinus Torvalds if (ohci->ed_bulktail) { 2721da177e4SLinus Torvalds ohci_writel (ohci, find_head (ohci->ed_bulktail)->dma, 2731da177e4SLinus Torvalds &ohci->regs->ed_bulkhead); 2741da177e4SLinus Torvalds enables |= OHCI_CTRL_BLE; 2751da177e4SLinus Torvalds temp |= OHCI_BLF; 2761da177e4SLinus Torvalds } 2771da177e4SLinus Torvalds } 2781da177e4SLinus Torvalds if (hcd->self.bandwidth_isoc_reqs || hcd->self.bandwidth_int_reqs) 2791da177e4SLinus Torvalds enables |= OHCI_CTRL_PLE|OHCI_CTRL_IE; 2801da177e4SLinus Torvalds if (enables) { 2811da177e4SLinus Torvalds ohci_dbg (ohci, "restarting schedules ... %08x\n", enables); 2821da177e4SLinus Torvalds ohci->hc_control |= enables; 2831da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 2841da177e4SLinus Torvalds if (temp) 2851da177e4SLinus Torvalds ohci_writel (ohci, temp, &ohci->regs->cmdstatus); 2861da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 2871da177e4SLinus Torvalds } 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds return 0; 2901da177e4SLinus Torvalds } 2911da177e4SLinus Torvalds 2928d1a243bSAlan Stern static int ohci_bus_suspend (struct usb_hcd *hcd) 2938d1a243bSAlan Stern { 2948d1a243bSAlan Stern struct ohci_hcd *ohci = hcd_to_ohci (hcd); 2958d1a243bSAlan Stern int rc; 2968d1a243bSAlan Stern 2978d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 2988d1a243bSAlan Stern 2998d1a243bSAlan Stern if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 3008d1a243bSAlan Stern rc = -ESHUTDOWN; 3018d1a243bSAlan Stern else 3028d1a243bSAlan Stern rc = ohci_rh_suspend (ohci, 0); 3038d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 3048d1a243bSAlan Stern return rc; 3058d1a243bSAlan Stern } 3068d1a243bSAlan Stern 3078d1a243bSAlan Stern static int ohci_bus_resume (struct usb_hcd *hcd) 3088d1a243bSAlan Stern { 3098d1a243bSAlan Stern struct ohci_hcd *ohci = hcd_to_ohci (hcd); 3108d1a243bSAlan Stern int rc; 3118d1a243bSAlan Stern 3128d1a243bSAlan Stern if (time_before (jiffies, ohci->next_statechange)) 3138d1a243bSAlan Stern msleep(5); 3148d1a243bSAlan Stern 3158d1a243bSAlan Stern spin_lock_irq (&ohci->lock); 3168d1a243bSAlan Stern 3178d1a243bSAlan Stern if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 3188d1a243bSAlan Stern rc = -ESHUTDOWN; 3198d1a243bSAlan Stern else 3208d1a243bSAlan Stern rc = ohci_rh_resume (ohci); 3218d1a243bSAlan Stern spin_unlock_irq (&ohci->lock); 3228d1a243bSAlan Stern 3238d1a243bSAlan Stern /* poll until we know a device is connected or we autostop */ 3248d1a243bSAlan Stern if (rc == 0) 3258d1a243bSAlan Stern usb_hcd_poll_rh_status(hcd); 3268d1a243bSAlan Stern return rc; 3278d1a243bSAlan Stern } 3288d1a243bSAlan Stern 329*43bbb7e0SAlan Stern /* Carry out the final steps of resuming the controller device */ 330*43bbb7e0SAlan Stern static void ohci_finish_controller_resume(struct usb_hcd *hcd) 331*43bbb7e0SAlan Stern { 332*43bbb7e0SAlan Stern struct ohci_hcd *ohci = hcd_to_ohci(hcd); 333*43bbb7e0SAlan Stern int port; 334*43bbb7e0SAlan Stern bool need_reinit = false; 335*43bbb7e0SAlan Stern 336*43bbb7e0SAlan Stern /* See if the controller is already running or has been reset */ 337*43bbb7e0SAlan Stern ohci->hc_control = ohci_readl(ohci, &ohci->regs->control); 338*43bbb7e0SAlan Stern if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 339*43bbb7e0SAlan Stern need_reinit = true; 340*43bbb7e0SAlan Stern } else { 341*43bbb7e0SAlan Stern switch (ohci->hc_control & OHCI_CTRL_HCFS) { 342*43bbb7e0SAlan Stern case OHCI_USB_OPER: 343*43bbb7e0SAlan Stern case OHCI_USB_RESET: 344*43bbb7e0SAlan Stern need_reinit = true; 345*43bbb7e0SAlan Stern } 346*43bbb7e0SAlan Stern } 347*43bbb7e0SAlan Stern 348*43bbb7e0SAlan Stern /* If needed, reinitialize and suspend the root hub */ 349*43bbb7e0SAlan Stern if (need_reinit) { 350*43bbb7e0SAlan Stern spin_lock_irq(&ohci->lock); 351*43bbb7e0SAlan Stern hcd->state = HC_STATE_RESUMING; 352*43bbb7e0SAlan Stern ohci_rh_resume(ohci); 353*43bbb7e0SAlan Stern hcd->state = HC_STATE_QUIESCING; 354*43bbb7e0SAlan Stern ohci_rh_suspend(ohci, 0); 355*43bbb7e0SAlan Stern hcd->state = HC_STATE_SUSPENDED; 356*43bbb7e0SAlan Stern spin_unlock_irq(&ohci->lock); 357*43bbb7e0SAlan Stern } 358*43bbb7e0SAlan Stern 359*43bbb7e0SAlan Stern /* Normally just turn on port power and enable interrupts */ 360*43bbb7e0SAlan Stern else { 361*43bbb7e0SAlan Stern ohci_dbg(ohci, "powerup ports\n"); 362*43bbb7e0SAlan Stern for (port = 0; port < ohci->num_ports; port++) 363*43bbb7e0SAlan Stern ohci_writel(ohci, RH_PS_PPS, 364*43bbb7e0SAlan Stern &ohci->regs->roothub.portstatus[port]); 365*43bbb7e0SAlan Stern 366*43bbb7e0SAlan Stern ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable); 367*43bbb7e0SAlan Stern ohci_readl(ohci, &ohci->regs->intrenable); 368*43bbb7e0SAlan Stern msleep(20); 369*43bbb7e0SAlan Stern } 370*43bbb7e0SAlan Stern } 371*43bbb7e0SAlan Stern 3721f9fc882SAlan Stern /* Carry out polling-, autostop-, and autoresume-related state changes */ 3731f9fc882SAlan Stern static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 3741f9fc882SAlan Stern int any_connected) 3751f9fc882SAlan Stern { 3761f9fc882SAlan Stern int poll_rh = 1; 3771f9fc882SAlan Stern 3781f9fc882SAlan Stern switch (ohci->hc_control & OHCI_CTRL_HCFS) { 3791f9fc882SAlan Stern 3801f9fc882SAlan Stern case OHCI_USB_OPER: 3811f9fc882SAlan Stern /* keep on polling until we know a device is connected 3821f9fc882SAlan Stern * and RHSC is enabled */ 3831f9fc882SAlan Stern if (!ohci->autostop) { 3841f9fc882SAlan Stern if (any_connected || 3851f9fc882SAlan Stern !device_may_wakeup(&ohci_to_hcd(ohci) 3861f9fc882SAlan Stern ->self.root_hub->dev)) { 3871f9fc882SAlan Stern if (ohci_readl(ohci, &ohci->regs->intrenable) & 3881f9fc882SAlan Stern OHCI_INTR_RHSC) 3891f9fc882SAlan Stern poll_rh = 0; 3901f9fc882SAlan Stern } else { 3911f9fc882SAlan Stern ohci->autostop = 1; 3921f9fc882SAlan Stern ohci->next_statechange = jiffies + HZ; 3931f9fc882SAlan Stern } 3941f9fc882SAlan Stern 3951f9fc882SAlan Stern /* if no devices have been attached for one second, autostop */ 3961f9fc882SAlan Stern } else { 3971f9fc882SAlan Stern if (changed || any_connected) { 3981f9fc882SAlan Stern ohci->autostop = 0; 3991f9fc882SAlan Stern ohci->next_statechange = jiffies + 4001f9fc882SAlan Stern STATECHANGE_DELAY; 4011f9fc882SAlan Stern } else if (time_after_eq(jiffies, 4021f9fc882SAlan Stern ohci->next_statechange) 4031f9fc882SAlan Stern && !ohci->ed_rm_list 4041f9fc882SAlan Stern && !(ohci->hc_control & 4051f9fc882SAlan Stern OHCI_SCHED_ENABLES)) { 4061f9fc882SAlan Stern ohci_rh_suspend(ohci, 1); 4071f9fc882SAlan Stern } 4081f9fc882SAlan Stern } 4091f9fc882SAlan Stern break; 4101f9fc882SAlan Stern 4111f9fc882SAlan Stern /* if there is a port change, autostart or ask to be resumed */ 4121f9fc882SAlan Stern case OHCI_USB_SUSPEND: 4131f9fc882SAlan Stern case OHCI_USB_RESUME: 4141f9fc882SAlan Stern if (changed) { 4151f9fc882SAlan Stern if (ohci->autostop) 4161f9fc882SAlan Stern ohci_rh_resume(ohci); 4171f9fc882SAlan Stern else 4181f9fc882SAlan Stern usb_hcd_resume_root_hub(ohci_to_hcd(ohci)); 4191f9fc882SAlan Stern } else { 4201f9fc882SAlan Stern /* everything is idle, no need for polling */ 4211f9fc882SAlan Stern poll_rh = 0; 4221f9fc882SAlan Stern } 4231f9fc882SAlan Stern break; 4241f9fc882SAlan Stern } 4251f9fc882SAlan Stern return poll_rh; 4261f9fc882SAlan Stern } 4271f9fc882SAlan Stern 4281f9fc882SAlan Stern #else /* CONFIG_PM */ 4291f9fc882SAlan Stern 4301f9fc882SAlan Stern static inline int ohci_rh_resume(struct ohci_hcd *ohci) 4311f9fc882SAlan Stern { 4321f9fc882SAlan Stern return 0; 4331f9fc882SAlan Stern } 4341f9fc882SAlan Stern 4351f9fc882SAlan Stern /* Carry out polling-related state changes. 4361f9fc882SAlan Stern * autostop isn't used when CONFIG_PM is turned off. 4371f9fc882SAlan Stern */ 4381f9fc882SAlan Stern static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 4391f9fc882SAlan Stern int any_connected) 4401f9fc882SAlan Stern { 4411f9fc882SAlan Stern int poll_rh = 1; 4421f9fc882SAlan Stern 4431f9fc882SAlan Stern /* keep on polling until RHSC is enabled */ 4441f9fc882SAlan Stern if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC) 4451f9fc882SAlan Stern poll_rh = 0; 4461f9fc882SAlan Stern return poll_rh; 4471f9fc882SAlan Stern } 4481f9fc882SAlan Stern 4498ad7fe16SDavid Brownell #endif /* CONFIG_PM */ 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 4521da177e4SLinus Torvalds 4531da177e4SLinus Torvalds /* build "status change" packet (one or two bytes) from HC registers */ 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds static int 4561da177e4SLinus Torvalds ohci_hub_status_data (struct usb_hcd *hcd, char *buf) 4571da177e4SLinus Torvalds { 4581da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 459fdd13b36SDavid Brownell int i, changed = 0, length = 1; 460052ac01aSAlan Stern int any_connected = 0; 4611da177e4SLinus Torvalds unsigned long flags; 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds spin_lock_irqsave (&ohci->lock, flags); 4646fd75b19SAlan Stern if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 4656fd75b19SAlan Stern goto done; 4661da177e4SLinus Torvalds 467fdd13b36SDavid Brownell /* undocumented erratum seen on at least rev D */ 468fdd13b36SDavid Brownell if ((ohci->flags & OHCI_QUIRK_AMD756) 469fdd13b36SDavid Brownell && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) { 470fdd13b36SDavid Brownell ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n", 4711da177e4SLinus Torvalds ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP); 4721da177e4SLinus Torvalds /* retry later; "should not happen" */ 4731da177e4SLinus Torvalds goto done; 4741da177e4SLinus Torvalds } 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds /* init status */ 4771da177e4SLinus Torvalds if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC)) 4781da177e4SLinus Torvalds buf [0] = changed = 1; 4791da177e4SLinus Torvalds else 4801da177e4SLinus Torvalds buf [0] = 0; 481fdd13b36SDavid Brownell if (ohci->num_ports > 7) { 4821da177e4SLinus Torvalds buf [1] = 0; 4831da177e4SLinus Torvalds length++; 4841da177e4SLinus Torvalds } 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds /* look at each port */ 487fdd13b36SDavid Brownell for (i = 0; i < ohci->num_ports; i++) { 4881da177e4SLinus Torvalds u32 status = roothub_portstatus (ohci, i); 4891da177e4SLinus Torvalds 4908d1a243bSAlan Stern /* can't autostop if ports are connected */ 4918d1a243bSAlan Stern any_connected |= (status & RH_PS_CCS); 4928d1a243bSAlan Stern 4931da177e4SLinus Torvalds if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC 4941da177e4SLinus Torvalds | RH_PS_OCIC | RH_PS_PRSC)) { 4951da177e4SLinus Torvalds changed = 1; 4961da177e4SLinus Torvalds if (i < 7) 4971da177e4SLinus Torvalds buf [0] |= 1 << (i + 1); 4981da177e4SLinus Torvalds else 4991da177e4SLinus Torvalds buf [1] |= 1 << (i - 7); 5001da177e4SLinus Torvalds } 5011da177e4SLinus Torvalds } 502d413984aSDavid Brownell 5031f9fc882SAlan Stern hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed, 5041f9fc882SAlan Stern any_connected); 505d413984aSDavid Brownell 5061da177e4SLinus Torvalds done: 5071da177e4SLinus Torvalds spin_unlock_irqrestore (&ohci->lock, flags); 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds return changed ? length : 0; 5101da177e4SLinus Torvalds } 5111da177e4SLinus Torvalds 5121da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds static void 5151da177e4SLinus Torvalds ohci_hub_descriptor ( 5161da177e4SLinus Torvalds struct ohci_hcd *ohci, 5171da177e4SLinus Torvalds struct usb_hub_descriptor *desc 5181da177e4SLinus Torvalds ) { 5191da177e4SLinus Torvalds u32 rh = roothub_a (ohci); 5201da177e4SLinus Torvalds u16 temp; 5211da177e4SLinus Torvalds 5221da177e4SLinus Torvalds desc->bDescriptorType = 0x29; 5231da177e4SLinus Torvalds desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24; 5241da177e4SLinus Torvalds desc->bHubContrCurrent = 0; 5251da177e4SLinus Torvalds 526fdd13b36SDavid Brownell desc->bNbrPorts = ohci->num_ports; 527fdd13b36SDavid Brownell temp = 1 + (ohci->num_ports / 8); 5281da177e4SLinus Torvalds desc->bDescLength = 7 + 2 * temp; 5291da177e4SLinus Torvalds 5301da177e4SLinus Torvalds temp = 0; 5311da177e4SLinus Torvalds if (rh & RH_A_NPS) /* no power switching? */ 5321da177e4SLinus Torvalds temp |= 0x0002; 5331da177e4SLinus Torvalds if (rh & RH_A_PSM) /* per-port power switching? */ 5341da177e4SLinus Torvalds temp |= 0x0001; 5351da177e4SLinus Torvalds if (rh & RH_A_NOCP) /* no overcurrent reporting? */ 5361da177e4SLinus Torvalds temp |= 0x0010; 5371da177e4SLinus Torvalds else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */ 5381da177e4SLinus Torvalds temp |= 0x0008; 5391da177e4SLinus Torvalds desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 5421da177e4SLinus Torvalds rh = roothub_b (ohci); 543b2134bcdSKAMBAROV, ZAUR memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); 5441da177e4SLinus Torvalds desc->bitmap [0] = rh & RH_B_DR; 545fdd13b36SDavid Brownell if (ohci->num_ports > 7) { 5461da177e4SLinus Torvalds desc->bitmap [1] = (rh & RH_B_DR) >> 8; 547b2134bcdSKAMBAROV, ZAUR desc->bitmap [2] = 0xff; 5481da177e4SLinus Torvalds } else 5491da177e4SLinus Torvalds desc->bitmap [1] = 0xff; 5501da177e4SLinus Torvalds } 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 5531da177e4SLinus Torvalds 5541da177e4SLinus Torvalds #ifdef CONFIG_USB_OTG 5551da177e4SLinus Torvalds 5561da177e4SLinus Torvalds static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port) 5571da177e4SLinus Torvalds { 5581da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 5591da177e4SLinus Torvalds u32 status; 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds if (!port) 5621da177e4SLinus Torvalds return -EINVAL; 5631da177e4SLinus Torvalds port--; 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds /* start port reset before HNP protocol times out */ 5661da177e4SLinus Torvalds status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]); 5671da177e4SLinus Torvalds if (!(status & RH_PS_CCS)) 5681da177e4SLinus Torvalds return -ENODEV; 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds /* khubd will finish the reset later */ 5711da177e4SLinus Torvalds ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]); 5721da177e4SLinus Torvalds return 0; 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds static void start_hnp(struct ohci_hcd *ohci); 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds #else 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds #define ohci_start_port_reset NULL 5801da177e4SLinus Torvalds 5811da177e4SLinus Torvalds #endif 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds 5861da177e4SLinus Torvalds /* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling, 5871da177e4SLinus Torvalds * not necessarily continuous ... to guard against resume signaling. 5881da177e4SLinus Torvalds * The short timeout is safe for non-root hubs, and is backward-compatible 5891da177e4SLinus Torvalds * with earlier Linux hosts. 5901da177e4SLinus Torvalds */ 5911da177e4SLinus Torvalds #ifdef CONFIG_USB_SUSPEND 5921da177e4SLinus Torvalds #define PORT_RESET_MSEC 50 5931da177e4SLinus Torvalds #else 5941da177e4SLinus Torvalds #define PORT_RESET_MSEC 10 5951da177e4SLinus Torvalds #endif 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds /* this timer value might be vendor-specific ... */ 5981da177e4SLinus Torvalds #define PORT_RESET_HW_MSEC 10 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds /* wrap-aware logic morphed from <linux/jiffies.h> */ 6011da177e4SLinus Torvalds #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) 6021da177e4SLinus Torvalds 6031da177e4SLinus Torvalds /* called from some task, normally khubd */ 60423d10a9eSTakamasa Ohtake static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port) 6051da177e4SLinus Torvalds { 6061da177e4SLinus Torvalds __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; 6071da177e4SLinus Torvalds u32 temp; 6081da177e4SLinus Torvalds u16 now = ohci_readl(ohci, &ohci->regs->fmnumber); 6091da177e4SLinus Torvalds u16 reset_done = now + PORT_RESET_MSEC; 610e01e7fe3SDavid Brownell int limit_1 = DIV_ROUND_UP(PORT_RESET_MSEC, PORT_RESET_HW_MSEC); 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds /* build a "continuous enough" reset signal, with up to 6131da177e4SLinus Torvalds * 3msec gap between pulses. scheduler HZ==100 must work; 6141da177e4SLinus Torvalds * this might need to be deadline-scheduled. 6151da177e4SLinus Torvalds */ 6161da177e4SLinus Torvalds do { 617e01e7fe3SDavid Brownell int limit_2; 618e01e7fe3SDavid Brownell 6191da177e4SLinus Torvalds /* spin until any current reset finishes */ 620e01e7fe3SDavid Brownell limit_2 = PORT_RESET_HW_MSEC * 2; 621e01e7fe3SDavid Brownell while (--limit_2 >= 0) { 6221da177e4SLinus Torvalds temp = ohci_readl (ohci, portstat); 62323d10a9eSTakamasa Ohtake /* handle e.g. CardBus eject */ 62423d10a9eSTakamasa Ohtake if (temp == ~(u32)0) 62523d10a9eSTakamasa Ohtake return -ESHUTDOWN; 6261da177e4SLinus Torvalds if (!(temp & RH_PS_PRS)) 6271da177e4SLinus Torvalds break; 6281da177e4SLinus Torvalds udelay (500); 6291da177e4SLinus Torvalds } 6301da177e4SLinus Torvalds 631e01e7fe3SDavid Brownell /* timeout (a hardware error) has been observed when 632e01e7fe3SDavid Brownell * EHCI sets CF while this driver is resetting a port; 633e01e7fe3SDavid Brownell * presumably other disconnect paths might do it too. 634e01e7fe3SDavid Brownell */ 635e01e7fe3SDavid Brownell if (limit_2 < 0) { 636e01e7fe3SDavid Brownell ohci_dbg(ohci, 637e01e7fe3SDavid Brownell "port[%d] reset timeout, stat %08x\n", 638e01e7fe3SDavid Brownell port, temp); 639e01e7fe3SDavid Brownell break; 640e01e7fe3SDavid Brownell } 641e01e7fe3SDavid Brownell 6421da177e4SLinus Torvalds if (!(temp & RH_PS_CCS)) 6431da177e4SLinus Torvalds break; 6441da177e4SLinus Torvalds if (temp & RH_PS_PRSC) 6451da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PRSC, portstat); 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds /* start the next reset, sleep till it's probably done */ 6481da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PRS, portstat); 6491da177e4SLinus Torvalds msleep(PORT_RESET_HW_MSEC); 6501da177e4SLinus Torvalds now = ohci_readl(ohci, &ohci->regs->fmnumber); 651e01e7fe3SDavid Brownell } while (tick_before(now, reset_done) && --limit_1 >= 0); 652e01e7fe3SDavid Brownell 653e01e7fe3SDavid Brownell /* caller synchronizes using PRSC ... and handles PRS 654e01e7fe3SDavid Brownell * still being set when this returns. 655e01e7fe3SDavid Brownell */ 65623d10a9eSTakamasa Ohtake 65723d10a9eSTakamasa Ohtake return 0; 6581da177e4SLinus Torvalds } 6591da177e4SLinus Torvalds 6601da177e4SLinus Torvalds static int ohci_hub_control ( 6611da177e4SLinus Torvalds struct usb_hcd *hcd, 6621da177e4SLinus Torvalds u16 typeReq, 6631da177e4SLinus Torvalds u16 wValue, 6641da177e4SLinus Torvalds u16 wIndex, 6651da177e4SLinus Torvalds char *buf, 6661da177e4SLinus Torvalds u16 wLength 6671da177e4SLinus Torvalds ) { 6681da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 6691da177e4SLinus Torvalds int ports = hcd_to_bus (hcd)->root_hub->maxchild; 6701da177e4SLinus Torvalds u32 temp; 6711da177e4SLinus Torvalds int retval = 0; 6721da177e4SLinus Torvalds 6738de98402SBenjamin Herrenschmidt if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 6748de98402SBenjamin Herrenschmidt return -ESHUTDOWN; 6758de98402SBenjamin Herrenschmidt 6761da177e4SLinus Torvalds switch (typeReq) { 6771da177e4SLinus Torvalds case ClearHubFeature: 6781da177e4SLinus Torvalds switch (wValue) { 6791da177e4SLinus Torvalds case C_HUB_OVER_CURRENT: 6801da177e4SLinus Torvalds ohci_writel (ohci, RH_HS_OCIC, 6811da177e4SLinus Torvalds &ohci->regs->roothub.status); 6821da177e4SLinus Torvalds case C_HUB_LOCAL_POWER: 6831da177e4SLinus Torvalds break; 6841da177e4SLinus Torvalds default: 6851da177e4SLinus Torvalds goto error; 6861da177e4SLinus Torvalds } 6871da177e4SLinus Torvalds break; 6881da177e4SLinus Torvalds case ClearPortFeature: 6891da177e4SLinus Torvalds if (!wIndex || wIndex > ports) 6901da177e4SLinus Torvalds goto error; 6911da177e4SLinus Torvalds wIndex--; 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds switch (wValue) { 6941da177e4SLinus Torvalds case USB_PORT_FEAT_ENABLE: 6951da177e4SLinus Torvalds temp = RH_PS_CCS; 6961da177e4SLinus Torvalds break; 6971da177e4SLinus Torvalds case USB_PORT_FEAT_C_ENABLE: 6981da177e4SLinus Torvalds temp = RH_PS_PESC; 6991da177e4SLinus Torvalds break; 7001da177e4SLinus Torvalds case USB_PORT_FEAT_SUSPEND: 7011da177e4SLinus Torvalds temp = RH_PS_POCI; 7021da177e4SLinus Torvalds break; 7031da177e4SLinus Torvalds case USB_PORT_FEAT_C_SUSPEND: 7041da177e4SLinus Torvalds temp = RH_PS_PSSC; 7051da177e4SLinus Torvalds break; 7061da177e4SLinus Torvalds case USB_PORT_FEAT_POWER: 7071da177e4SLinus Torvalds temp = RH_PS_LSDA; 7081da177e4SLinus Torvalds break; 7091da177e4SLinus Torvalds case USB_PORT_FEAT_C_CONNECTION: 7101da177e4SLinus Torvalds temp = RH_PS_CSC; 7111da177e4SLinus Torvalds break; 7121da177e4SLinus Torvalds case USB_PORT_FEAT_C_OVER_CURRENT: 7131da177e4SLinus Torvalds temp = RH_PS_OCIC; 7141da177e4SLinus Torvalds break; 7151da177e4SLinus Torvalds case USB_PORT_FEAT_C_RESET: 7161da177e4SLinus Torvalds temp = RH_PS_PRSC; 7171da177e4SLinus Torvalds break; 7181da177e4SLinus Torvalds default: 7191da177e4SLinus Torvalds goto error; 7201da177e4SLinus Torvalds } 7211da177e4SLinus Torvalds ohci_writel (ohci, temp, 7221da177e4SLinus Torvalds &ohci->regs->roothub.portstatus [wIndex]); 7231da177e4SLinus Torvalds // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]); 7241da177e4SLinus Torvalds break; 7251da177e4SLinus Torvalds case GetHubDescriptor: 7261da177e4SLinus Torvalds ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf); 7271da177e4SLinus Torvalds break; 7281da177e4SLinus Torvalds case GetHubStatus: 7291da177e4SLinus Torvalds temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE); 73092164c5dSDavid Miller put_unaligned(cpu_to_le32 (temp), (__le32 *) buf); 7311da177e4SLinus Torvalds break; 7321da177e4SLinus Torvalds case GetPortStatus: 7331da177e4SLinus Torvalds if (!wIndex || wIndex > ports) 7341da177e4SLinus Torvalds goto error; 7351da177e4SLinus Torvalds wIndex--; 7361da177e4SLinus Torvalds temp = roothub_portstatus (ohci, wIndex); 73792164c5dSDavid Miller put_unaligned(cpu_to_le32 (temp), (__le32 *) buf); 7381da177e4SLinus Torvalds 7391da177e4SLinus Torvalds #ifndef OHCI_VERBOSE_DEBUG 7401da177e4SLinus Torvalds if (*(u16*)(buf+2)) /* only if wPortChange is interesting */ 7411da177e4SLinus Torvalds #endif 7421da177e4SLinus Torvalds dbg_port (ohci, "GetStatus", wIndex, temp); 7431da177e4SLinus Torvalds break; 7441da177e4SLinus Torvalds case SetHubFeature: 7451da177e4SLinus Torvalds switch (wValue) { 7461da177e4SLinus Torvalds case C_HUB_OVER_CURRENT: 7471da177e4SLinus Torvalds // FIXME: this can be cleared, yes? 7481da177e4SLinus Torvalds case C_HUB_LOCAL_POWER: 7491da177e4SLinus Torvalds break; 7501da177e4SLinus Torvalds default: 7511da177e4SLinus Torvalds goto error; 7521da177e4SLinus Torvalds } 7531da177e4SLinus Torvalds break; 7541da177e4SLinus Torvalds case SetPortFeature: 7551da177e4SLinus Torvalds if (!wIndex || wIndex > ports) 7561da177e4SLinus Torvalds goto error; 7571da177e4SLinus Torvalds wIndex--; 7581da177e4SLinus Torvalds switch (wValue) { 7591da177e4SLinus Torvalds case USB_PORT_FEAT_SUSPEND: 7601da177e4SLinus Torvalds #ifdef CONFIG_USB_OTG 7611da177e4SLinus Torvalds if (hcd->self.otg_port == (wIndex + 1) 7621da177e4SLinus Torvalds && hcd->self.b_hnp_enable) 7631da177e4SLinus Torvalds start_hnp(ohci); 7641da177e4SLinus Torvalds else 7651da177e4SLinus Torvalds #endif 7661da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PSS, 7671da177e4SLinus Torvalds &ohci->regs->roothub.portstatus [wIndex]); 7681da177e4SLinus Torvalds break; 7691da177e4SLinus Torvalds case USB_PORT_FEAT_POWER: 7701da177e4SLinus Torvalds ohci_writel (ohci, RH_PS_PPS, 7711da177e4SLinus Torvalds &ohci->regs->roothub.portstatus [wIndex]); 7721da177e4SLinus Torvalds break; 7731da177e4SLinus Torvalds case USB_PORT_FEAT_RESET: 77423d10a9eSTakamasa Ohtake retval = root_port_reset (ohci, wIndex); 7751da177e4SLinus Torvalds break; 7761da177e4SLinus Torvalds default: 7771da177e4SLinus Torvalds goto error; 7781da177e4SLinus Torvalds } 7791da177e4SLinus Torvalds break; 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds default: 7821da177e4SLinus Torvalds error: 7831da177e4SLinus Torvalds /* "protocol stall" on error */ 7841da177e4SLinus Torvalds retval = -EPIPE; 7851da177e4SLinus Torvalds } 7861da177e4SLinus Torvalds return retval; 7871da177e4SLinus Torvalds } 7881da177e4SLinus Torvalds 789