Commit 16032c4f authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

USB: EHCI: fix controller wakeup flag settings during suspend

This patch (as1380) fixes a bug in the wakeup settings for EHCI host
controllers.  When the controller is suspended, if it isn't enabled
for remote wakeup then we have to turn off all the port wakeup flags.
Disabling PCI PME# isn't good enough, because some systems (Intel)
evidently use alternate wakeup signalling paths.

In addition, the patch improves the handling of the Intel Moorestown
hardware by performing various power-up and power-down delays just
once instead of once for each port (i.e., the delays are moved outside
of the port loops).  This requires extra code, but the total delay
time is reduced.

There are also a few additional minor cleanups.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Reported-by: default avatarOndrej Zary <linux@rainbow-software.org>
CC: Alek Du <alek.du@intel.com>
CC: stable <stable@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent eab80de0
...@@ -224,26 +224,17 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev) ...@@ -224,26 +224,17 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
msleep(10); msleep(10);
/* Root hub was already suspended. Disable irq emission and /* Root hub was already suspended. Disable irq emission and
* mark HW unaccessible, bail out if RH has been resumed. Use * mark HW unaccessible. The PM and USB cores make sure that
* the spinlock to properly synchronize with possible pending * the root hub is either suspended or stopped.
* RH suspend or resume activity.
*
* This is still racy as hcd->state is manipulated outside of
* any locks =P But that will be a different fix.
*/ */
spin_lock_irqsave(&ehci->lock, flags); spin_lock_irqsave(&ehci->lock, flags);
if (hcd->state != HC_STATE_SUSPENDED) { ehci_prepare_ports_for_controller_suspend(ehci);
rc = -EINVAL;
goto bail;
}
ehci_writel(ehci, 0, &ehci->regs->intr_enable); ehci_writel(ehci, 0, &ehci->regs->intr_enable);
(void)ehci_readl(ehci, &ehci->regs->intr_enable); (void)ehci_readl(ehci, &ehci->regs->intr_enable);
clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
au1xxx_stop_ehc(); au1xxx_stop_ehc();
bail:
spin_unlock_irqrestore(&ehci->lock, flags); spin_unlock_irqrestore(&ehci->lock, flags);
// could save FLADJ in case of Vaux power loss // could save FLADJ in case of Vaux power loss
...@@ -273,6 +264,7 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev) ...@@ -273,6 +264,7 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) { if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
int mask = INTR_MASK; int mask = INTR_MASK;
ehci_prepare_ports_for_controller_resume(ehci);
if (!hcd->self.root_hub->do_remote_wakeup) if (!hcd->self.root_hub->do_remote_wakeup)
mask &= ~STS_PCD; mask &= ~STS_PCD;
ehci_writel(ehci, mask, &ehci->regs->intr_enable); ehci_writel(ehci, mask, &ehci->regs->intr_enable);
......
...@@ -313,6 +313,7 @@ static int ehci_fsl_drv_suspend(struct device *dev) ...@@ -313,6 +313,7 @@ static int ehci_fsl_drv_suspend(struct device *dev)
struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
void __iomem *non_ehci = hcd->regs; void __iomem *non_ehci = hcd->regs;
ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd));
if (!fsl_deep_sleep()) if (!fsl_deep_sleep())
return 0; return 0;
...@@ -327,6 +328,7 @@ static int ehci_fsl_drv_resume(struct device *dev) ...@@ -327,6 +328,7 @@ static int ehci_fsl_drv_resume(struct device *dev)
struct ehci_hcd *ehci = hcd_to_ehci(hcd); struct ehci_hcd *ehci = hcd_to_ehci(hcd);
void __iomem *non_ehci = hcd->regs; void __iomem *non_ehci = hcd->regs;
ehci_prepare_ports_for_controller_resume(ehci);
if (!fsl_deep_sleep()) if (!fsl_deep_sleep())
return 0; return 0;
......
...@@ -106,12 +106,75 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci) ...@@ -106,12 +106,75 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
ehci->owned_ports = 0; ehci->owned_ports = 0;
} }
static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
bool suspending)
{
int port;
u32 temp;
/* If remote wakeup is enabled for the root hub but disabled
* for the controller, we must adjust all the port wakeup flags
* when the controller is suspended or resumed. In all other
* cases they don't need to be changed.
*/
if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup ||
device_may_wakeup(ehci_to_hcd(ehci)->self.controller))
return;
/* clear phy low-power mode before changing wakeup flags */
if (ehci->has_hostpc) {
port = HCS_N_PORTS(ehci->hcs_params);
while (port--) {
u32 __iomem *hostpc_reg;
hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
+ HOSTPC0 + 4 * port);
temp = ehci_readl(ehci, hostpc_reg);
ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
}
msleep(5);
}
port = HCS_N_PORTS(ehci->hcs_params);
while (port--) {
u32 __iomem *reg = &ehci->regs->port_status[port];
u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
u32 t2 = t1 & ~PORT_WAKE_BITS;
/* If we are suspending the controller, clear the flags.
* If we are resuming the controller, set the wakeup flags.
*/
if (!suspending) {
if (t1 & PORT_CONNECT)
t2 |= PORT_WKOC_E | PORT_WKDISC_E;
else
t2 |= PORT_WKOC_E | PORT_WKCONN_E;
}
ehci_vdbg(ehci, "port %d, %08x -> %08x\n",
port + 1, t1, t2);
ehci_writel(ehci, t2, reg);
}
/* enter phy low-power mode again */
if (ehci->has_hostpc) {
port = HCS_N_PORTS(ehci->hcs_params);
while (port--) {
u32 __iomem *hostpc_reg;
hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
+ HOSTPC0 + 4 * port);
temp = ehci_readl(ehci, hostpc_reg);
ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
}
}
}
static int ehci_bus_suspend (struct usb_hcd *hcd) static int ehci_bus_suspend (struct usb_hcd *hcd)
{ {
struct ehci_hcd *ehci = hcd_to_ehci (hcd); struct ehci_hcd *ehci = hcd_to_ehci (hcd);
int port; int port;
int mask; int mask;
u32 __iomem *hostpc_reg = NULL; int changed;
ehci_dbg(ehci, "suspend root hub\n"); ehci_dbg(ehci, "suspend root hub\n");
...@@ -155,15 +218,13 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) ...@@ -155,15 +218,13 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
*/ */
ehci->bus_suspended = 0; ehci->bus_suspended = 0;
ehci->owned_ports = 0; ehci->owned_ports = 0;
changed = 0;
port = HCS_N_PORTS(ehci->hcs_params); port = HCS_N_PORTS(ehci->hcs_params);
while (port--) { while (port--) {
u32 __iomem *reg = &ehci->regs->port_status [port]; u32 __iomem *reg = &ehci->regs->port_status [port];
u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
u32 t2 = t1; u32 t2 = t1 & ~PORT_WAKE_BITS;
if (ehci->has_hostpc)
hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
+ HOSTPC0 + 4 * (port & 0xff));
/* keep track of which ports we suspend */ /* keep track of which ports we suspend */
if (t1 & PORT_OWNER) if (t1 & PORT_OWNER)
set_bit(port, &ehci->owned_ports); set_bit(port, &ehci->owned_ports);
...@@ -172,40 +233,45 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) ...@@ -172,40 +233,45 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
set_bit(port, &ehci->bus_suspended); set_bit(port, &ehci->bus_suspended);
} }
/* enable remote wakeup on all ports */ /* enable remote wakeup on all ports, if told to do so */
if (hcd->self.root_hub->do_remote_wakeup) { if (hcd->self.root_hub->do_remote_wakeup) {
/* only enable appropriate wake bits, otherwise the /* only enable appropriate wake bits, otherwise the
* hardware can not go phy low power mode. If a race * hardware can not go phy low power mode. If a race
* condition happens here(connection change during bits * condition happens here(connection change during bits
* set), the port change detection will finally fix it. * set), the port change detection will finally fix it.
*/ */
if (t1 & PORT_CONNECT) { if (t1 & PORT_CONNECT)
t2 |= PORT_WKOC_E | PORT_WKDISC_E; t2 |= PORT_WKOC_E | PORT_WKDISC_E;
t2 &= ~PORT_WKCONN_E; else
} else {
t2 |= PORT_WKOC_E | PORT_WKCONN_E; t2 |= PORT_WKOC_E | PORT_WKCONN_E;
t2 &= ~PORT_WKDISC_E; }
}
} else
t2 &= ~PORT_WAKE_BITS;
if (t1 != t2) { if (t1 != t2) {
ehci_vdbg (ehci, "port %d, %08x -> %08x\n", ehci_vdbg (ehci, "port %d, %08x -> %08x\n",
port + 1, t1, t2); port + 1, t1, t2);
ehci_writel(ehci, t2, reg); ehci_writel(ehci, t2, reg);
if (hostpc_reg) { changed = 1;
u32 t3; }
}
spin_unlock_irq(&ehci->lock); if (changed && ehci->has_hostpc) {
msleep(5);/* 5ms for HCD enter low pwr mode */ spin_unlock_irq(&ehci->lock);
spin_lock_irq(&ehci->lock); msleep(5); /* 5 ms for HCD to enter low-power mode */
t3 = ehci_readl(ehci, hostpc_reg); spin_lock_irq(&ehci->lock);
ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
t3 = ehci_readl(ehci, hostpc_reg); port = HCS_N_PORTS(ehci->hcs_params);
ehci_dbg(ehci, "Port%d phy low pwr mode %s\n", while (port--) {
u32 __iomem *hostpc_reg;
u32 t3;
hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
+ HOSTPC0 + 4 * port);
t3 = ehci_readl(ehci, hostpc_reg);
ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
t3 = ehci_readl(ehci, hostpc_reg);
ehci_dbg(ehci, "Port %d phy low-power mode %s\n",
port, (t3 & HOSTPC_PHCD) ? port, (t3 & HOSTPC_PHCD) ?
"succeeded" : "failed"); "succeeded" : "failed");
}
} }
} }
...@@ -291,19 +357,28 @@ static int ehci_bus_resume (struct usb_hcd *hcd) ...@@ -291,19 +357,28 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
msleep(8); msleep(8);
spin_lock_irq(&ehci->lock); spin_lock_irq(&ehci->lock);
/* clear phy low-power mode before resume */
if (ehci->bus_suspended && ehci->has_hostpc) {
i = HCS_N_PORTS(ehci->hcs_params);
while (i--) {
if (test_bit(i, &ehci->bus_suspended)) {
u32 __iomem *hostpc_reg;
hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
+ HOSTPC0 + 4 * i);
temp = ehci_readl(ehci, hostpc_reg);
ehci_writel(ehci, temp & ~HOSTPC_PHCD,
hostpc_reg);
}
}
spin_unlock_irq(&ehci->lock);
msleep(5);
spin_lock_irq(&ehci->lock);
}
/* manually resume the ports we suspended during bus_suspend() */ /* manually resume the ports we suspended during bus_suspend() */
i = HCS_N_PORTS (ehci->hcs_params); i = HCS_N_PORTS (ehci->hcs_params);
while (i--) { while (i--) {
/* clear phy low power mode before resume */
if (ehci->has_hostpc) {
u32 __iomem *hostpc_reg =
(u32 __iomem *)((u8 *)ehci->regs
+ HOSTPC0 + 4 * (i & 0xff));
temp = ehci_readl(ehci, hostpc_reg);
ehci_writel(ehci, temp & ~HOSTPC_PHCD,
hostpc_reg);
mdelay(5);
}
temp = ehci_readl(ehci, &ehci->regs->port_status [i]); temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
if (test_bit(i, &ehci->bus_suspended) && if (test_bit(i, &ehci->bus_suspended) &&
...@@ -685,23 +760,25 @@ static int ehci_hub_control ( ...@@ -685,23 +760,25 @@ static int ehci_hub_control (
goto error; goto error;
if (ehci->no_selective_suspend) if (ehci->no_selective_suspend)
break; break;
if (temp & PORT_SUSPEND) { if (!(temp & PORT_SUSPEND))
if ((temp & PORT_PE) == 0) break;
goto error; if ((temp & PORT_PE) == 0)
/* clear phy low power mode before resume */ goto error;
if (hostpc_reg) {
temp1 = ehci_readl(ehci, hostpc_reg); /* clear phy low-power mode before resume */
ehci_writel(ehci, temp1 & ~HOSTPC_PHCD, if (hostpc_reg) {
temp1 = ehci_readl(ehci, hostpc_reg);
ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
hostpc_reg); hostpc_reg);
mdelay(5); spin_unlock_irqrestore(&ehci->lock, flags);
} msleep(5);/* wait to leave low-power mode */
/* resume signaling for 20 msec */ spin_lock_irqsave(&ehci->lock, flags);
temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
ehci_writel(ehci, temp | PORT_RESUME,
status_reg);
ehci->reset_done [wIndex] = jiffies
+ msecs_to_jiffies (20);
} }
/* resume signaling for 20 msec */
temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
ehci_writel(ehci, temp | PORT_RESUME, status_reg);
ehci->reset_done[wIndex] = jiffies
+ msecs_to_jiffies(20);
break; break;
case USB_PORT_FEAT_C_SUSPEND: case USB_PORT_FEAT_C_SUSPEND:
clear_bit(wIndex, &ehci->port_c_suspend); clear_bit(wIndex, &ehci->port_c_suspend);
......
...@@ -287,23 +287,15 @@ static int ehci_pci_suspend(struct usb_hcd *hcd) ...@@ -287,23 +287,15 @@ static int ehci_pci_suspend(struct usb_hcd *hcd)
msleep(10); msleep(10);
/* Root hub was already suspended. Disable irq emission and /* Root hub was already suspended. Disable irq emission and
* mark HW unaccessible, bail out if RH has been resumed. Use * mark HW unaccessible. The PM and USB cores make sure that
* the spinlock to properly synchronize with possible pending * the root hub is either suspended or stopped.
* RH suspend or resume activity.
*
* This is still racy as hcd->state is manipulated outside of
* any locks =P But that will be a different fix.
*/ */
spin_lock_irqsave (&ehci->lock, flags); spin_lock_irqsave (&ehci->lock, flags);
if (hcd->state != HC_STATE_SUSPENDED) { ehci_prepare_ports_for_controller_suspend(ehci);
rc = -EINVAL;
goto bail;
}
ehci_writel(ehci, 0, &ehci->regs->intr_enable); ehci_writel(ehci, 0, &ehci->regs->intr_enable);
(void)ehci_readl(ehci, &ehci->regs->intr_enable); (void)ehci_readl(ehci, &ehci->regs->intr_enable);
clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
bail:
spin_unlock_irqrestore (&ehci->lock, flags); spin_unlock_irqrestore (&ehci->lock, flags);
// could save FLADJ in case of Vaux power loss // could save FLADJ in case of Vaux power loss
...@@ -333,6 +325,7 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated) ...@@ -333,6 +325,7 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
!hibernated) { !hibernated) {
int mask = INTR_MASK; int mask = INTR_MASK;
ehci_prepare_ports_for_controller_resume(ehci);
if (!hcd->self.root_hub->do_remote_wakeup) if (!hcd->self.root_hub->do_remote_wakeup)
mask &= ~STS_PCD; mask &= ~STS_PCD;
ehci_writel(ehci, mask, &ehci->regs->intr_enable); ehci_writel(ehci, mask, &ehci->regs->intr_enable);
......
...@@ -536,6 +536,16 @@ struct ehci_fstn { ...@@ -536,6 +536,16 @@ struct ehci_fstn {
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/* Prepare the PORTSC wakeup flags during controller suspend/resume */
#define ehci_prepare_ports_for_controller_suspend(ehci) \
ehci_adjust_port_wakeup_flags(ehci, true);
#define ehci_prepare_ports_for_controller_resume(ehci) \
ehci_adjust_port_wakeup_flags(ehci, false);
/*-------------------------------------------------------------------------*/
#ifdef CONFIG_USB_EHCI_ROOT_HUB_TT #ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment