Commit ebc3dd68 authored by Daniel Glöckner's avatar Daniel Glöckner Committed by Greg Kroah-Hartman

usb: musb: fix remote wakeup racing with suspend

It has been observed that writing 0xF2 to the power register while it
reads as 0xF4 results in the register having the value 0xF0, i.e. clearing
RESUME and setting SUSPENDM in one go does not work. It might also violate
the USB spec to transition directly from resume to suspend, especially
when not taking T_DRSMDN into account. But this is what happens when a
remote wakeup occurs between SetPortFeature USB_PORT_FEAT_SUSPEND on the
root hub and musb_bus_suspend being called.

This commit returns -EBUSY when musb_bus_suspend is called while remote
wakeup is signalled and thus avoids to reset the RESUME bit. Ignoring
this error when musb_port_suspend is called from musb_hub_control is ok.
Signed-off-by: default avatarDaniel Glöckner <dg@emlix.com>
Signed-off-by: default avatarBin Liu <b-liu@ti.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2278446e
...@@ -2524,8 +2524,11 @@ static int musb_bus_suspend(struct usb_hcd *hcd) ...@@ -2524,8 +2524,11 @@ static int musb_bus_suspend(struct usb_hcd *hcd)
{ {
struct musb *musb = hcd_to_musb(hcd); struct musb *musb = hcd_to_musb(hcd);
u8 devctl; u8 devctl;
int ret;
musb_port_suspend(musb, true); ret = musb_port_suspend(musb, true);
if (ret)
return ret;
if (!is_host_active(musb)) if (!is_host_active(musb))
return 0; return 0;
......
...@@ -67,7 +67,7 @@ extern void musb_host_rx(struct musb *, u8); ...@@ -67,7 +67,7 @@ extern void musb_host_rx(struct musb *, u8);
extern void musb_root_disconnect(struct musb *musb); extern void musb_root_disconnect(struct musb *musb);
extern void musb_host_resume_root_hub(struct musb *musb); extern void musb_host_resume_root_hub(struct musb *musb);
extern void musb_host_poke_root_hub(struct musb *musb); extern void musb_host_poke_root_hub(struct musb *musb);
extern void musb_port_suspend(struct musb *musb, bool do_suspend); extern int musb_port_suspend(struct musb *musb, bool do_suspend);
extern void musb_port_reset(struct musb *musb, bool do_reset); extern void musb_port_reset(struct musb *musb, bool do_reset);
extern void musb_host_finish_resume(struct work_struct *work); extern void musb_host_finish_resume(struct work_struct *work);
#else #else
...@@ -99,7 +99,10 @@ static inline void musb_root_disconnect(struct musb *musb) {} ...@@ -99,7 +99,10 @@ static inline void musb_root_disconnect(struct musb *musb) {}
static inline void musb_host_resume_root_hub(struct musb *musb) {} static inline void musb_host_resume_root_hub(struct musb *musb) {}
static inline void musb_host_poll_rh_status(struct musb *musb) {} static inline void musb_host_poll_rh_status(struct musb *musb) {}
static inline void musb_host_poke_root_hub(struct musb *musb) {} static inline void musb_host_poke_root_hub(struct musb *musb) {}
static inline void musb_port_suspend(struct musb *musb, bool do_suspend) {} static inline int musb_port_suspend(struct musb *musb, bool do_suspend)
{
return 0;
}
static inline void musb_port_reset(struct musb *musb, bool do_reset) {} static inline void musb_port_reset(struct musb *musb, bool do_reset) {}
static inline void musb_host_finish_resume(struct work_struct *work) {} static inline void musb_host_finish_resume(struct work_struct *work) {}
#endif #endif
......
...@@ -48,14 +48,14 @@ void musb_host_finish_resume(struct work_struct *work) ...@@ -48,14 +48,14 @@ void musb_host_finish_resume(struct work_struct *work)
spin_unlock_irqrestore(&musb->lock, flags); spin_unlock_irqrestore(&musb->lock, flags);
} }
void musb_port_suspend(struct musb *musb, bool do_suspend) int musb_port_suspend(struct musb *musb, bool do_suspend)
{ {
struct usb_otg *otg = musb->xceiv->otg; struct usb_otg *otg = musb->xceiv->otg;
u8 power; u8 power;
void __iomem *mbase = musb->mregs; void __iomem *mbase = musb->mregs;
if (!is_host_active(musb)) if (!is_host_active(musb))
return; return 0;
/* NOTE: this doesn't necessarily put PHY into low power mode, /* NOTE: this doesn't necessarily put PHY into low power mode,
* turning off its clock; that's a function of PHY integration and * turning off its clock; that's a function of PHY integration and
...@@ -66,7 +66,10 @@ void musb_port_suspend(struct musb *musb, bool do_suspend) ...@@ -66,7 +66,10 @@ void musb_port_suspend(struct musb *musb, bool do_suspend)
if (do_suspend) { if (do_suspend) {
int retries = 10000; int retries = 10000;
power &= ~MUSB_POWER_RESUME; if (power & MUSB_POWER_RESUME)
return -EBUSY;
if (!(power & MUSB_POWER_SUSPENDM)) {
power |= MUSB_POWER_SUSPENDM; power |= MUSB_POWER_SUSPENDM;
musb_writeb(mbase, MUSB_POWER, power); musb_writeb(mbase, MUSB_POWER, power);
...@@ -77,6 +80,7 @@ void musb_port_suspend(struct musb *musb, bool do_suspend) ...@@ -77,6 +80,7 @@ void musb_port_suspend(struct musb *musb, bool do_suspend)
if (retries-- < 1) if (retries-- < 1)
break; break;
} }
}
musb_dbg(musb, "Root port suspended, power %02x", power); musb_dbg(musb, "Root port suspended, power %02x", power);
...@@ -111,6 +115,7 @@ void musb_port_suspend(struct musb *musb, bool do_suspend) ...@@ -111,6 +115,7 @@ void musb_port_suspend(struct musb *musb, bool do_suspend)
schedule_delayed_work(&musb->finish_resume_work, schedule_delayed_work(&musb->finish_resume_work,
msecs_to_jiffies(USB_RESUME_TIMEOUT)); msecs_to_jiffies(USB_RESUME_TIMEOUT));
} }
return 0;
} }
void musb_port_reset(struct musb *musb, bool do_reset) void musb_port_reset(struct musb *musb, bool do_reset)
......
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