usb: musb: support for suspend and resume
Subsystems (2)
cover usb: musb: support for suspend and resume
I've been working on some patches that allow suspending and resuming the musb-dsps platform. This was tested for host mode only.
With these patches applied, I can successfully bring an AM335x board to suspend with a USB media connected, and access it again after resume. Note that this currently only works with CONFIG_MUSB_PIO_ONLY set. The cppi41 driver needs some more love to make this work. I'll work on that next.
Thanks,
Daniel
Daniel Mack (4):
usb: musb: move port reset to worker
usb: musb: call musb_port_suspend from musb_bus_suspend
usb: musb: conditionally restore and resume the context on resume
usb: musb: dsps: add support for suspend and resume
drivers/usb/musb/musb_core.c | 24 +++++++++++++++++- drivers/usb/musb/musb_core.h | 3 +++ drivers/usb/musb/musb_dsps.c | 54 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/musb/musb_host.c | 2 ++ drivers/usb/musb/musb_host.h | 4 +++ drivers/usb/musb/musb_virthub.c | 15 +++++++----- include/linux/usb/musb.h | 1 + 7 files changed, 96 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.3.1
A message that is not in the archive (sent off-list or not yet received): 1380200942-28175-1-git-send-email-zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 2/4 usb: musb: call musb_port_suspend from musb_bus_suspend
Make musb_port_suspend() externally available, and call it when to host goes into suspend. This allows the core to go into suspend while a device is connected.
--- drivers/usb/musb/musb_host.c | 2 ++ drivers/usb/musb/musb_host.h | 2 ++ drivers/usb/musb/musb_virthub.c | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_host.c +2 -0
@@ -2433,6 +2433,8 @@ static int musb_bus_suspend(struct usb_hcd *hcd)struct musb *musb =hcd_to_musb (hcd);u8 devctl; +musb_port_suspend (musb, true); +if (!is_host_active (musb))return 0 ;
drivers/usb/musb/musb_host.h +2 -0
@@ -93,6 +93,7 @@ extern void musb_root_disconnect(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_port_reset (struct musb *musb); +extern void musb_port_suspend (struct musb *musb,bool do_suspend);#else static inline struct musb *hcd_to_musb (struct usb_hcd *hcd) {
@@ -123,6 +124,7 @@ 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_poke_root_hub (struct musb *musb) {}static inline void musb_port_reset (struct musb *musb) {} +static inline void musb_port_suspend (struct musb *musb,bool do_suspend) {}#endif struct usb_hcd ;
drivers/usb/musb/musb_virthub.c +1 -1
@@ -90,7 +90,7 @@ static void musb_start(struct musb *musb)musb_writeb (regs,MUSB_DEVCTL , devctl); } -static void musb_port_suspend (struct musb *musb,bool do_suspend) +void musb_port_suspend (struct musb *musb,bool do_suspend) {struct usb_otg *otg = musb->xceiv->otg;u8 power;
Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/4 usb: musb: move port reset to worker
In reply to Daniel Mackmusb_port_reset() sleeps, so we can't call it from atomic context. It is, however, called from places inside musb_hub_control() while &musb->lock is held, which leads to a "scheduling while atomic" warning.
Fix this by moving the logic into a worker, and call it where the function was previously called directly.
--- drivers/usb/musb/musb_core.c | 7 +++++++ drivers/usb/musb/musb_core.h | 3 +++ drivers/usb/musb/musb_host.h | 2 ++ drivers/usb/musb/musb_virthub.c | 13 ++++++++----- 4 files changed, 20 insertions(+), 5 deletions(-)
drivers/usb/musb/musb_core.c +7 -0
@@ -1699,6 +1699,12 @@ static void musb_irq_work(struct work_struct *data) } } +static void musb_port_reset_work (struct work_struct *data) +{ + struct musb *musb = container_of(data, struct musb, port_reset_work); +musb_port_reset (musb); +} +/* -------------------------------------------------------------------------- * Init support */
@@ -1857,6 +1863,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)/* Init IRQ workqueue before request_irq */ INIT_WORK (&musb->irq_work, musb_irq_work); +INIT_WORK (&musb->port_reset_work, musb_port_reset_work);/* attach to the IRQ */ if (request_irq (nIrq, musb->isr,0 ,dev_name (dev), musb)) {
drivers/usb/musb/musb_core.h +3 -0
@@ -294,6 +294,9 @@ struct musb {irqreturn_t (*isr)(int ,void *);struct work_struct irq_work; +struct work_struct port_reset_work; +bool port_reset_state; +u16 hwvers;u16 intrrxe;
drivers/usb/musb/musb_host.h +2 -0
@@ -92,6 +92,7 @@ extern void musb_host_rx(struct musb *, u8);extern void musb_root_disconnect (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_port_reset (struct musb *musb);#else static inline struct musb *hcd_to_musb (struct usb_hcd *hcd) {
@@ -121,6 +122,7 @@ 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_poll_rh_status (struct musb *musb) {}static inline void musb_host_poke_root_hub (struct musb *musb) {} +static inline void musb_port_reset (struct musb *musb) {}#endif struct usb_hcd ;
drivers/usb/musb/musb_virthub.c +8 -5
@@ -155,7 +155,7 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend) } } -static void musb_port_reset (struct musb *musb,bool do_reset) +void musb_port_reset (struct musb *musb) {u8 power;void __iomem *mbase = musb->mregs;
@@ -173,7 +173,7 @@ static void musb_port_reset(struct musb *musb, bool do_reset)* the appropriate amount of time has passed */ power =musb_readb (mbase,MUSB_POWER ); -if (do_reset) { +if (musb->port_reset_state) {/* * If RESUME is set, we must make sure it stays minimum 20 ms.
@@ -356,8 +356,10 @@ int musb_hub_control(/* finish RESET signaling? */ if ((musb->port1_status &USB_PORT_STAT_RESET ) - &&time_after_eq (jiffies, musb->rh_timer)) -musb_port_reset (musb, false); + &&time_after_eq (jiffies, musb->rh_timer)) { + musb->port_reset_state = false; +schedule_work (&musb->port_reset_work); + }/* finish RESUME signaling? */ if ((musb->port1_status & MUSB_PORT_STAT_RESUME)
@@ -412,7 +414,8 @@ int musb_hub_control(musb_start (musb);break ;case USB_PORT_FEAT_RESET : -musb_port_reset (musb, true); + musb->port_reset_state = true; +schedule_work (&musb->port_reset_work);break ;case USB_PORT_FEAT_SUSPEND :musb_port_suspend (musb, true);
Signature · 1 line
1.8.3.1
PATCH 3/4 usb: musb: conditionally restore and resume the context on resume
In reply to Daniel MackIt appears not all platforms featuring a musb core need to save the musb core registers at suspend time and restore them on resume.
The dsps platform does, however. So add a bit in struct musb_hdrc_platform_data to let platforms specify their need of such action being taken.
--- drivers/usb/musb/musb_core.c | 17 ++++++++++++++++- include/linux/usb/musb.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_core.c +16 -1
@@ -2152,6 +2152,7 @@ static int musb_suspend(struct device *dev) {struct musb *musb =dev_to_musb (dev);unsigned long flags; +struct musb_hdrc_platform_data *plat =dev_get_platdata (dev);spin_lock_irqsave (&musb->lock, flags);
@@ -2165,16 +2166,30 @@ static int musb_suspend(struct device *dev)*/ } +if (plat->restore_after_suspend) +musb_save_context (musb); +spin_unlock_irqrestore (&musb->lock, flags);return 0 ; }static int musb_resume_noirq (struct device *dev) { -/* for static cmos like DaVinci, register values were preserved +struct musb *musb =dev_to_musb (dev); +struct musb_hdrc_platform_data *plat =dev_get_platdata (dev); + +/* +* For static cmos like DaVinci, register values were preserved * unless for some reason the whole soc powered down or the USB * module got reset through the PSC (vs just being disabled). +* +* The plaform data tells us about the necessity of saving and +* restoring the context across a suspend cycle. */ + +if (plat->restore_after_suspend) +musb_restore_context (musb); +return 0 ; }
include/linux/usb/musb.h +1 -0
@@ -100,6 +100,7 @@ struct musb_hdrc_platform_data {u8 mode; u8 has_mailbox:1; + u8 restore_after_suspend:1;/* for clk_get() */ const char *clock;
Signature · 1 line
1.8.3.1
PATCH 4/4 usb: musb: dsps: add support for suspend and resume
In reply to Daniel MackThe dsps platform needs to save save some registers at suspend time and restore them after resume. This patch adds a struct for these registers, and also lets the musb core know that the core registers need to be saved as well.
--- drivers/usb/musb/musb_dsps.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
drivers/usb/musb/musb_dsps.c +54 -0
@@ -110,6 +110,17 @@ struct dsps_musb_wrapper {u8 poll_seconds; }; +/* +* register shadow for suspend +*/ +struct dsps_context { +u32 control; +u32 epintr; +u32 coreintr; +u32 phy_utmi; +u32 mode; +}; +/** * DSPS glue structure. */
@@ -119,6 +130,8 @@ struct dsps_glue {const struct dsps_musb_wrapper *wrp;/* wrapper register offsets */ struct timer_list timer;/* otg_workaround timer */ unsigned long last_timer;/* last timer data for each instance */ + +struct dsps_context context; };/**
@@ -502,6 +515,7 @@ static int dsps_create_musb_pdev(struct dsps_glue *glue, } pdata.config = config; pdata.platform_ops = &dsps_ops; + pdata.restore_after_suspend =1 ; config->num_eps =get_int_prop (dn,"mentor,num-eps" ); config->ram_bits =get_int_prop (dn,"mentor,ram-bits" );
@@ -623,11 +637,51 @@ static const struct of_device_id musb_dsps_of_match[] = { };MODULE_DEVICE_TABLE (of, musb_dsps_of_match); +#ifdef CONFIG_PM +static int dsps_suspend (struct device *dev) +{ +struct dsps_glue *glue =dev_get_drvdata (dev); +const struct dsps_musb_wrapper *wrp = glue->wrp; +struct musb *musb =platform_get_drvdata (glue->musb); +void __iomem *mbase = musb->ctrl_base; + + glue->context.control =dsps_readl (mbase, wrp->control); + glue->context.epintr =dsps_readl (mbase, wrp->epintr_set); + glue->context.coreintr =dsps_readl (mbase, wrp->coreintr_set); + glue->context.phy_utmi =dsps_readl (mbase, wrp->phy_utmi); + glue->context.mode =dsps_readl (mbase, wrp->mode); + +return 0 ; +} + +static int dsps_resume (struct device *dev) +{ +struct dsps_glue *glue =dev_get_drvdata (dev); +const struct dsps_musb_wrapper *wrp = glue->wrp; +struct musb *musb =platform_get_drvdata (glue->musb); +void __iomem *mbase = musb->ctrl_base; + +dsps_writel (mbase, wrp->control, glue->context.control); +dsps_writel (mbase, wrp->epintr_set, glue->context.epintr); +dsps_writel (mbase, wrp->coreintr_set, glue->context.coreintr); +dsps_writel (mbase, wrp->phy_utmi, glue->context.phy_utmi); +dsps_writel (mbase, wrp->mode, glue->context.mode); + + musb->port_reset_state = false; +schedule_work (&musb->port_reset_work); + +return 0 ; +} +#endif + +static SIMPLE_DEV_PM_OPS(dsps_pm_ops, dsps_suspend, dsps_resume); +static struct platform_driver dsps_usbss_driver = { .probe = dsps_probe, .remove = dsps_remove, .driver = { .name ="musb-dsps" , + .pm = &dsps_pm_ops, .of_match_table =of_match_ptr (musb_dsps_of_match), }, };
Signature · 1 line
1.8.3.1
Quoted 8 lines · Daniel Mack
I've been working on some patches that allow suspending and resuming the musb-dsps platform. This was tested for host mode only.
With these patches applied, I can successfully bring an AM335x board to suspend with a USB media connected, and access it again after resume. Note that this currently only works with
CONFIG_MUSB_PIO_ONLYset. The cppi41 driver needs some more love to make this work. I'll work on that next.
As this series hasn't been applied yet, please consider it outdated. I have some more patches coming and will include them when publishing a new round of patches.
Thanks,
Daniel