Skip to contentSkip to conversation

usb: musb: dsps: add support for suspend and resume

PATCH New Daniel Mack 2 participants 2 messages Oct 1, 2013 – Oct 8, 2013 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 usb: musb: dsps: add support for suspend and resume

The 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 | 60 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
drivers/usb/musb/musb_dsps.c +60 -0
index 5eba143..f2f4b3a 100644
@@ -112,6 +112,19 @@ 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;
+	u32 tx_mode;
+	u32 rx_mode;
+};
+
 /**
  * DSPS glue structure.
  */
@@ -121,6 +134,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;
 };
 
 /**
@@ -504,6 +519,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");
@@ -627,11 +643,55 @@ 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);
+	glue->context.tx_mode = dsps_readl(mbase, wrp->tx_mode);
+	glue->context.rx_mode = dsps_readl(mbase, wrp->rx_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);
+	dsps_writel(mbase, wrp->tx_mode, glue->context.tx_mode);
+	dsps_writel(mbase, wrp->rx_mode, glue->context.rx_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	= musb_dsps_of_match,
 	},
 };
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

A message that is not in the archive (sent off-list or not yet received): 1380643921-20642-1-git-send-email-zonque-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 1/1 usb: musb: dsps: disable the otg_timer while going to sleep

Testing with "freeze" I run into:

| PM: Syncing filesystems ... done.
| PM: Preparing system for freeze sleep
| Freezing user space processes ... (elapsed 0.002 seconds) done.
| Freezing remaining freezable tasks ... (elapsed 0.002 seconds) done.
| PM: Entering freeze sleep
| usb usb2: usb auto-resume
| hub 2-0:1.0: hub_resume
| hub 2-0:1.0: hub_suspend
| usb usb2: bus suspend, wakeup 0
| usb usb1: usb auto-resume
| hub 1-0:1.0: hub_resume
| hub 1-0:1.0: hub_suspend
| usb usb1: bus suspend, wakeup 0
| PM: suspend of devices complete after 54.622 msecs
| PM: late suspend of devices complete after 4.782 msecs
| PM: noirq suspend of devices complete after 4.990 msecs
| Unhandled fault: external abort on non-linefetch (0x1008) at 0xf0442460
| Internal error: : 1008 [#1] ARM
| PC is at otg_timer+0x28/0x140 [musb_dsps]

This is comming from first dsps_readb() in otg_timer(). The problem is that the device is already suspended (the clocks are off) and the timer tries to access register which fails.
Since there is no need to keep this timer aroud while the device is going to suspend I suggest to remove the timer in suspend and queue it in the resume path.

---
I don't have the "suspend" target in "state" just the "freezer" and with it I get into trouble in the otg_timer(). This triggers a few seconds after the suspend but since this depends on timming, it might trigger just a few secs after the suspend.
What about the this?

 drivers/usb/musb/musb_dsps.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/musb/musb_dsps.c +2 -0
index ced2b76..61b3f3e 100644
@@ -659,6 +659,7 @@ static int dsps_suspend(struct device *dev)
 	glue->context.tx_mode = dsps_readl(mbase, wrp->tx_mode);
 	glue->context.rx_mode = dsps_readl(mbase, wrp->rx_mode);
 
+	del_timer_sync(&glue->timer);
 	return 0;
 }
 
@@ -679,6 +680,7 @@ static int dsps_resume(struct device *dev)
 
 	musb->port_reset_state = false;
 	schedule_work(&musb->port_reset_work);
+	mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ);
 
 	return 0;
 }
Signature · 6 lines
1.8.4.rc3

--
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