/* First stop any processing */ if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) {
ohci->hc_control &= ~OHCI_SCHED_ENABLES;
ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus);
/* sched disables take effect on the next frame, * then the last WDH could take 6+ msec
*/
ohci_dbg (ohci, "stopping schedules ...\n");
ohci->autostop = 0;
spin_unlock_irq (&ohci->lock);
msleep (8);
spin_lock_irq (&ohci->lock);
}
update_done_list(ohci);
ohci_work(ohci);
/* All ED unlinks should be finished, no need for SOF interrupts */
ohci_writel(ohci, OHCI_INTR_SF, &ohci->regs->intrdisable);
/* * Some controllers don't handle "global" suspend properly if * there are unsuspended ports. For these controllers, put all * the enabled ports into suspend before suspending the root hub.
*/ if (ohci->flags & OHCI_QUIRK_GLOBAL_SUSPEND) {
__hc32 __iomem *portstat = ohci->regs->roothub.portstatus; int i; unsigned temp;
for (i = 0; i < ohci->num_ports; (++i, ++portstat)) {
temp = ohci_readl(ohci, portstat); if ((temp & (RH_PS_PES | RH_PS_PSS)) ==
RH_PS_PES)
ohci_writel(ohci, RH_PS_PSS, portstat);
}
}
/* maybe resume can wake root hub */ if (ohci_to_hcd(ohci)->self.root_hub->do_remote_wakeup || autostop) {
ohci->hc_control |= OHCI_CTRL_RWE;
} else {
ohci_writel(ohci, OHCI_INTR_RHSC | OHCI_INTR_RD,
&ohci->regs->intrdisable);
ohci->hc_control &= ~OHCI_CTRL_RWE;
}
/* Suspend hub ... this is the "global (to this bus) suspend" mode, * which doesn't imply ports will first be individually suspended.
*/
ohci->hc_control &= ~OHCI_CTRL_HCFS;
ohci->hc_control |= OHCI_USB_SUSPEND;
ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
(void) ohci_readl (ohci, &ohci->regs->control);
/* no resumes until devices finish suspending */ if (!autostop) {
ohci->next_statechange = jiffies + msecs_to_jiffies (5);
ohci->autostop = 0;
ohci->rh_state = OHCI_RH_SUSPENDED;
}
done: return status;
}
staticinlinestruct ed *find_head (struct ed *ed)
{ /* for bulk and control lists */ while (ed->ed_prev)
ed = ed->ed_prev; return ed;
}
/* caller has locked the root hub */ staticint ohci_rh_resume (struct ohci_hcd *ohci)
__releases(ohci->lock)
__acquires(ohci->lock)
{ struct usb_hcd *hcd = ohci_to_hcd (ohci);
u32 temp, enables; int status = -EINPROGRESS; int autostopped = ohci->autostop;
/* * The following code is executed with ohci->lock held and * irqs disabled if and only if autostopped is true. This * will cause sparse to warn about a "context imbalance".
*/
skip_resume: /* interrupts might have been disabled */
ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); if (ohci->ed_rm_list)
ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
/* Then re-enable operations */
ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control);
(void) ohci_readl (ohci, &ohci->regs->control); if (!autostopped)
msleep (3);
/* poll until we know a device is connected or we autostop */ if (rc == 0)
usb_hcd_poll_rh_status(hcd); return rc;
}
/* Carry out polling-, autostop-, and autoresume-related state changes */ staticint ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, int any_connected, int rhsc_status)
{ int poll_rh = 1; int rhsc_enable;
/* Some broken controllers never turn off RHSC in the interrupt * status register. For their sake we won't re-enable RHSC * interrupts if the interrupt bit is already active.
*/
rhsc_enable = ohci_readl(ohci, &ohci->regs->intrenable) &
OHCI_INTR_RHSC;
switch (ohci->hc_control & OHCI_CTRL_HCFS) { case OHCI_USB_OPER: /* If no status changes are pending, enable RHSC interrupts. */ if (!rhsc_enable && !rhsc_status && !changed) {
rhsc_enable = OHCI_INTR_RHSC;
ohci_writel(ohci, rhsc_enable, &ohci->regs->intrenable);
}
/* Keep on polling until we know a device is connected * and RHSC is enabled, or until we autostop.
*/ if (!ohci->autostop) { if (any_connected ||
!device_may_wakeup(&ohci_to_hcd(ohci)
->self.root_hub->dev)) { if (rhsc_enable)
poll_rh = 0;
} else {
ohci->autostop = 1;
ohci->next_statechange = jiffies + HZ;
}
/* if no devices have been attached for one second, autostop */
} else { if (changed || any_connected) {
ohci->autostop = 0;
ohci->next_statechange = jiffies +
STATECHANGE_DELAY;
} elseif (time_after_eq(jiffies,
ohci->next_statechange)
&& !ohci->ed_rm_list
&& !(ohci->hc_control &
OHCI_SCHED_ENABLES)) {
ohci_rh_suspend(ohci, 1); if (rhsc_enable)
poll_rh = 0;
}
} break;
case OHCI_USB_SUSPEND: case OHCI_USB_RESUME: /* if there is a port change, autostart or ask to be resumed */ if (changed) { if (ohci->autostop)
ohci_rh_resume(ohci); else
usb_hcd_resume_root_hub(ohci_to_hcd(ohci));
/* If remote wakeup is disabled, stop polling */
} elseif (!ohci->autostop &&
!ohci_to_hcd(ohci)->self.root_hub->
do_remote_wakeup) {
poll_rh = 0;
} else { /* If no status changes are pending, * enable RHSC interrupts
*/ if (!rhsc_enable && !rhsc_status) {
rhsc_enable = OHCI_INTR_RHSC;
ohci_writel(ohci, rhsc_enable,
&ohci->regs->intrenable);
} /* Keep polling until RHSC is enabled */ if (rhsc_enable)
poll_rh = 0;
} break;
} return poll_rh;
}
/* Carry out polling-related state changes. * autostop isn't used when CONFIG_PM is turned off.
*/ staticint ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, int any_connected, int rhsc_status)
{ /* If RHSC is enabled, don't poll */ if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC) return 0;
/* If status changes are pending, continue polling. * Conversely, if no status changes are pending but the RHSC * status bit was set, then RHSC may be broken so continue polling.
*/ if (changed || rhsc_status) return 1;
/* Clear the RHSC status flag before reading the port statuses */
ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrstatus);
rhsc_status = ohci_readl(ohci, &ohci->regs->intrstatus) &
OHCI_INTR_RHSC;
/* look at each port */ for (i = 0; i < ohci->num_ports; i++) {
u32 status = roothub_portstatus (ohci, i);
/* can't autostop if ports are connected */
any_connected |= (status & RH_PS_CCS);
if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
| RH_PS_OCIC | RH_PS_PRSC)) {
changed = 1; if (i < 7)
buf [0] |= 1 << (i + 1); else
buf [1] |= 1 << (i - 7);
}
}
if (ohci_root_hub_state_changes(ohci, changed,
any_connected, rhsc_status))
set_bit(HCD_FLAG_POLL_RH, &hcd->flags); else
clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
/* start port reset before HNP protocol times out */
status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]); if (!(status & RH_PS_CCS)) return -ENODEV;
/* hub_wq will finish the reset later */
ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]); return 0;
}
/* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling, * not necessarily continuous ... to guard against resume signaling.
*/ #define PORT_RESET_MSEC 50
/* this timer value might be vendor-specific ... */ #define PORT_RESET_HW_MSEC 10
/* called from some task, normally hub_wq */ staticinlineint root_port_reset (struct ohci_hcd *ohci, unsigned port)
{
__hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
u32 temp = 0;
u16 now = ohci_readl(ohci, &ohci->regs->fmnumber);
u16 reset_done = now + PORT_RESET_MSEC; int limit_1 = DIV_ROUND_UP(PORT_RESET_MSEC, PORT_RESET_HW_MSEC);
/* build a "continuous enough" reset signal, with up to * 3msec gap between pulses. scheduler HZ==100 must work; * this might need to be deadline-scheduled.
*/ do { int limit_2;
/* spin until any current reset finishes */
limit_2 = PORT_RESET_HW_MSEC * 2; while (--limit_2 >= 0) {
temp = ohci_readl (ohci, portstat); /* handle e.g. CardBus eject */ if (temp == ~(u32)0) return -ESHUTDOWN; if (!(temp & RH_PS_PRS)) break;
udelay (500);
}
/* timeout (a hardware error) has been observed when * EHCI sets CF while this driver is resetting a port; * presumably other disconnect paths might do it too.
*/ if (limit_2 < 0) {
ohci_dbg(ohci, "port[%d] reset timeout, stat %08x\n",
port, temp); break;
}
if (!(temp & RH_PS_CCS)) break; if (temp & RH_PS_PRSC)
ohci_writel (ohci, RH_PS_PRSC, portstat);
/* start the next reset, sleep till it's probably done */
ohci_writel (ohci, RH_PS_PRS, portstat);
msleep(PORT_RESET_HW_MSEC);
now = ohci_readl(ohci, &ohci->regs->fmnumber);
} while (tick_before(now, reset_done) && --limit_1 >= 0);
/* caller synchronizes using PRSC ... and handles PRS * still being set when this returns.
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.