Lines Matching +full:auto +full:- +full:sleep +full:- +full:disabled
1 // SPDX-License-Identifier: GPL-1.0+
6 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
11 /*-------------------------------------------------------------------------*/
38 /*-------------------------------------------------------------------------*/
48 __releases(ohci->lock) in ohci_rh_suspend()
49 __acquires(ohci->lock) in ohci_rh_suspend()
53 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); in ohci_rh_suspend()
54 switch (ohci->hc_control & OHCI_CTRL_HCFS) { in ohci_rh_suspend()
57 ohci->hc_control &= ~OHCI_CTRL_HCFS; in ohci_rh_suspend()
58 ohci->hc_control |= OHCI_USB_RESET; in ohci_rh_suspend()
59 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); in ohci_rh_suspend()
60 (void) ohci_readl (ohci, &ohci->regs->control); in ohci_rh_suspend()
63 status = -EBUSY; in ohci_rh_suspend()
67 if (!ohci->autostop) { in ohci_rh_suspend()
73 autostop ? "auto-stop" : "suspend"); in ohci_rh_suspend()
76 if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) { in ohci_rh_suspend()
77 ohci->hc_control &= ~OHCI_SCHED_ENABLES; in ohci_rh_suspend()
78 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); in ohci_rh_suspend()
79 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); in ohci_rh_suspend()
80 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus); in ohci_rh_suspend()
86 ohci->autostop = 0; in ohci_rh_suspend()
87 spin_unlock_irq (&ohci->lock); in ohci_rh_suspend()
89 spin_lock_irq (&ohci->lock); in ohci_rh_suspend()
95 ohci_writel(ohci, OHCI_INTR_SF, &ohci->regs->intrdisable); in ohci_rh_suspend()
102 if (ohci->flags & OHCI_QUIRK_GLOBAL_SUSPEND) { in ohci_rh_suspend()
103 __hc32 __iomem *portstat = ohci->regs->roothub.portstatus; in ohci_rh_suspend()
107 for (i = 0; i < ohci->num_ports; (++i, ++portstat)) { in ohci_rh_suspend()
116 if (ohci_to_hcd(ohci)->self.root_hub->do_remote_wakeup || autostop) { in ohci_rh_suspend()
117 ohci->hc_control |= OHCI_CTRL_RWE; in ohci_rh_suspend()
120 &ohci->regs->intrdisable); in ohci_rh_suspend()
121 ohci->hc_control &= ~OHCI_CTRL_RWE; in ohci_rh_suspend()
127 ohci->hc_control &= ~OHCI_CTRL_HCFS; in ohci_rh_suspend()
128 ohci->hc_control |= OHCI_USB_SUSPEND; in ohci_rh_suspend()
129 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); in ohci_rh_suspend()
130 (void) ohci_readl (ohci, &ohci->regs->control); in ohci_rh_suspend()
134 ohci->next_statechange = jiffies + msecs_to_jiffies (5); in ohci_rh_suspend()
135 ohci->autostop = 0; in ohci_rh_suspend()
136 ohci->rh_state = OHCI_RH_SUSPENDED; in ohci_rh_suspend()
146 while (ed->ed_prev) in find_head()
147 ed = ed->ed_prev; in find_head()
153 __releases(ohci->lock) in ohci_rh_resume()
154 __acquires(ohci->lock) in ohci_rh_resume()
158 int status = -EINPROGRESS; in ohci_rh_resume()
159 int autostopped = ohci->autostop; in ohci_rh_resume()
161 ohci->autostop = 0; in ohci_rh_resume()
162 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); in ohci_rh_resume()
164 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { in ohci_rh_resume()
166 if (ohci->rh_state != OHCI_RH_RUNNING) { in ohci_rh_resume()
168 ohci->hc_control); in ohci_rh_resume()
169 status = -EBUSY; in ohci_rh_resume()
175 } else switch (ohci->hc_control & OHCI_CTRL_HCFS) { in ohci_rh_resume()
177 ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES); in ohci_rh_resume()
178 ohci->hc_control |= OHCI_USB_RESUME; in ohci_rh_resume()
179 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); in ohci_rh_resume()
180 (void) ohci_readl (ohci, &ohci->regs->control); in ohci_rh_resume()
182 autostopped ? "auto-start" : "resume"); in ohci_rh_resume()
187 autostopped ? "auto-" : ""); in ohci_rh_resume()
192 status = -EBUSY; in ohci_rh_resume()
196 status = -EBUSY; in ohci_rh_resume()
198 if (status == -EBUSY) { in ohci_rh_resume()
200 spin_unlock_irq (&ohci->lock); in ohci_rh_resume()
203 usb_root_hub_lost_power(hcd->self.root_hub); in ohci_rh_resume()
205 spin_lock_irq (&ohci->lock); in ohci_rh_resume()
209 if (status != -EINPROGRESS) in ohci_rh_resume()
213 spin_unlock_irq (&ohci->lock); in ohci_rh_resume()
215 /* Some controllers (lucent erratum) need extra-long delays */ in ohci_rh_resume()
218 temp = ohci_readl (ohci, &ohci->regs->control); in ohci_rh_resume()
222 spin_lock_irq(&ohci->lock); in ohci_rh_resume()
223 return -EBUSY; in ohci_rh_resume()
227 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead); in ohci_rh_resume()
228 ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent); in ohci_rh_resume()
229 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead); in ohci_rh_resume()
230 ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent); in ohci_rh_resume()
231 ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent); in ohci_rh_resume()
232 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca); in ohci_rh_resume()
238 * The following code is executed with ohci->lock held and in ohci_rh_resume()
239 * irqs disabled if and only if autostopped is true. This in ohci_rh_resume()
243 /* interrupts might have been disabled */ in ohci_rh_resume()
244 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); in ohci_rh_resume()
245 if (ohci->ed_rm_list) in ohci_rh_resume()
246 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable); in ohci_rh_resume()
248 /* Then re-enable operations */ in ohci_rh_resume()
249 ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control); in ohci_rh_resume()
250 (void) ohci_readl (ohci, &ohci->regs->control); in ohci_rh_resume()
254 temp = ohci->hc_control; in ohci_rh_resume()
257 ohci->hc_control = temp; in ohci_rh_resume()
258 ohci_writel (ohci, temp, &ohci->regs->control); in ohci_rh_resume()
259 (void) ohci_readl (ohci, &ohci->regs->control); in ohci_rh_resume()
264 spin_lock_irq (&ohci->lock); in ohci_rh_resume()
266 /* now ohci->lock is always held and irqs are always disabled */ in ohci_rh_resume()
269 ohci->next_statechange = jiffies + STATECHANGE_DELAY; in ohci_rh_resume()
274 if (!ohci->ed_rm_list) { in ohci_rh_resume()
275 if (ohci->ed_controltail) { in ohci_rh_resume()
277 find_head (ohci->ed_controltail)->dma, in ohci_rh_resume()
278 &ohci->regs->ed_controlhead); in ohci_rh_resume()
282 if (ohci->ed_bulktail) { in ohci_rh_resume()
283 ohci_writel (ohci, find_head (ohci->ed_bulktail)->dma, in ohci_rh_resume()
284 &ohci->regs->ed_bulkhead); in ohci_rh_resume()
289 if (hcd->self.bandwidth_isoc_reqs || hcd->self.bandwidth_int_reqs) in ohci_rh_resume()
293 ohci->hc_control |= enables; in ohci_rh_resume()
294 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); in ohci_rh_resume()
296 ohci_writel (ohci, temp, &ohci->regs->cmdstatus); in ohci_rh_resume()
297 (void) ohci_readl (ohci, &ohci->regs->control); in ohci_rh_resume()
300 ohci->rh_state = OHCI_RH_RUNNING; in ohci_rh_resume()
309 spin_lock_irq (&ohci->lock); in ohci_bus_suspend()
312 rc = -ESHUTDOWN; in ohci_bus_suspend()
315 spin_unlock_irq (&ohci->lock); in ohci_bus_suspend()
318 del_timer_sync(&ohci->io_watchdog); in ohci_bus_suspend()
319 ohci->prev_frame_no = IO_WATCHDOG_OFF; in ohci_bus_suspend()
329 if (time_before (jiffies, ohci->next_statechange)) in ohci_bus_resume()
332 spin_lock_irq (&ohci->lock); in ohci_bus_resume()
335 rc = -ESHUTDOWN; in ohci_bus_resume()
338 spin_unlock_irq (&ohci->lock); in ohci_bus_resume()
346 /* Carry out polling-, autostop-, and autoresume-related state changes */
354 * status register. For their sake we won't re-enable RHSC in ohci_root_hub_state_changes()
357 rhsc_enable = ohci_readl(ohci, &ohci->regs->intrenable) & in ohci_root_hub_state_changes()
360 switch (ohci->hc_control & OHCI_CTRL_HCFS) { in ohci_root_hub_state_changes()
365 ohci_writel(ohci, rhsc_enable, &ohci->regs->intrenable); in ohci_root_hub_state_changes()
371 if (!ohci->autostop) { in ohci_root_hub_state_changes()
374 ->self.root_hub->dev)) { in ohci_root_hub_state_changes()
378 ohci->autostop = 1; in ohci_root_hub_state_changes()
379 ohci->next_statechange = jiffies + HZ; in ohci_root_hub_state_changes()
385 ohci->autostop = 0; in ohci_root_hub_state_changes()
386 ohci->next_statechange = jiffies + in ohci_root_hub_state_changes()
389 ohci->next_statechange) in ohci_root_hub_state_changes()
390 && !ohci->ed_rm_list in ohci_root_hub_state_changes()
391 && !(ohci->hc_control & in ohci_root_hub_state_changes()
404 if (ohci->autostop) in ohci_root_hub_state_changes()
409 /* If remote wakeup is disabled, stop polling */ in ohci_root_hub_state_changes()
410 } else if (!ohci->autostop && in ohci_root_hub_state_changes()
411 !ohci_to_hcd(ohci)->self.root_hub-> in ohci_root_hub_state_changes()
422 &ohci->regs->intrenable); in ohci_root_hub_state_changes()
440 /* Carry out polling-related state changes.
447 if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC) in ohci_root_hub_state_changes()
457 /* It's safe to re-enable RHSC interrupts */ in ohci_root_hub_state_changes()
458 ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable); in ohci_root_hub_state_changes()
464 /*-------------------------------------------------------------------------*/
476 spin_lock_irqsave (&ohci->lock, flags); in ohci_hub_status_data()
481 if ((ohci->flags & OHCI_QUIRK_AMD756) in ohci_hub_status_data()
484 ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP); in ohci_hub_status_data()
494 if (ohci->num_ports > 7) { in ohci_hub_status_data()
500 ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrstatus); in ohci_hub_status_data()
501 rhsc_status = ohci_readl(ohci, &ohci->regs->intrstatus) & in ohci_hub_status_data()
505 for (i = 0; i < ohci->num_ports; i++) { in ohci_hub_status_data()
517 buf [1] |= 1 << (i - 7); in ohci_hub_status_data()
523 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in ohci_hub_status_data()
525 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in ohci_hub_status_data()
529 spin_unlock_irqrestore (&ohci->lock, flags); in ohci_hub_status_data()
535 /*-------------------------------------------------------------------------*/
545 desc->bDescriptorType = USB_DT_HUB; in ohci_hub_descriptor()
546 desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24; in ohci_hub_descriptor()
547 desc->bHubContrCurrent = 0; in ohci_hub_descriptor()
549 desc->bNbrPorts = ohci->num_ports; in ohci_hub_descriptor()
550 temp = 1 + (ohci->num_ports / 8); in ohci_hub_descriptor()
551 desc->bDescLength = 7 + 2 * temp; in ohci_hub_descriptor()
556 if (rh & RH_A_PSM) /* per-port power switching? */ in ohci_hub_descriptor()
560 else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */ in ohci_hub_descriptor()
562 desc->wHubCharacteristics = cpu_to_le16(temp); in ohci_hub_descriptor()
566 memset(desc->u.hs.DeviceRemovable, 0xff, in ohci_hub_descriptor()
567 sizeof(desc->u.hs.DeviceRemovable)); in ohci_hub_descriptor()
568 desc->u.hs.DeviceRemovable[0] = rh & RH_B_DR; in ohci_hub_descriptor()
569 if (ohci->num_ports > 7) { in ohci_hub_descriptor()
570 desc->u.hs.DeviceRemovable[1] = (rh & RH_B_DR) >> 8; in ohci_hub_descriptor()
571 desc->u.hs.DeviceRemovable[2] = 0xff; in ohci_hub_descriptor()
573 desc->u.hs.DeviceRemovable[1] = 0xff; in ohci_hub_descriptor()
576 /*-------------------------------------------------------------------------*/
586 return -EINVAL; in ohci_start_port_reset()
587 port--; in ohci_start_port_reset()
590 status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]); in ohci_start_port_reset()
592 return -ENODEV; in ohci_start_port_reset()
595 ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]); in ohci_start_port_reset()
605 /*-------------------------------------------------------------------------*/
613 /* this timer value might be vendor-specific ... */
616 /* wrap-aware logic morphed from <linux/jiffies.h> */
617 #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
622 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; in root_port_reset()
624 u16 now = ohci_readl(ohci, &ohci->regs->fmnumber); in root_port_reset()
630 * this might need to be deadline-scheduled. in root_port_reset()
637 while (--limit_2 >= 0) { in root_port_reset()
641 return -ESHUTDOWN; in root_port_reset()
663 /* start the next reset, sleep till it's probably done */ in root_port_reset()
666 now = ohci_readl(ohci, &ohci->regs->fmnumber); in root_port_reset()
667 } while (tick_before(now, reset_done) && --limit_1 >= 0); in root_port_reset()
685 int ports = ohci->num_ports; in ohci_hub_control()
690 return -ESHUTDOWN; in ohci_hub_control()
697 &ohci->regs->roothub.status); in ohci_hub_control()
708 wIndex--; in ohci_hub_control()
739 &ohci->regs->roothub.portstatus [wIndex]); in ohci_hub_control()
740 // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]); in ohci_hub_control()
752 wIndex--; in ohci_hub_control()
772 wIndex--; in ohci_hub_control()
776 if (hcd->self.otg_port == (wIndex + 1) in ohci_hub_control()
777 && hcd->self.b_hnp_enable) in ohci_hub_control()
778 ohci->start_hnp(ohci); in ohci_hub_control()
782 &ohci->regs->roothub.portstatus [wIndex]); in ohci_hub_control()
786 &ohci->regs->roothub.portstatus [wIndex]); in ohci_hub_control()
799 retval = -EPIPE; in ohci_hub_control()