Message ID | 1358477428-2605-2-git-send-email-peter.chen@freescale.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Fri, Jan 18, 2013 at 10:50:28AM +0800, Peter Chen wrote: > During the system suspend/resume procedure, the USB also > needs to go suspend/resume procedure, this patch adds > related APIs. It is tested at i.mx6q sabrelite. Meanwhile, > it fixes the bug that the USB will out of work after > system suspend/resume. > > Signed-off-by: Peter Chen <peter.chen@freescale.com> Haven't reviewed the patches, but I've seen the series fix an imx6q USB issue - the USB will be broken after system suspend/resume operation as below. So for both patches, Tested-by: Shawn Guo <shawn.guo@linaro.org> Shawn $ echo mem > /sys/power/state PM: Syncing filesystems ... done. PM: Preparing system for mem sleep mmc0: card a8a5 removed mmc1: card b368 removed Freezing user space processes ... (elapsed 0.01 seconds) done. Freezing remaining freezable tasks ... (elapsed 0.01 seconds) done. PM: Entering mem sleep fec_stop : Graceful transmit stop did not complete ! PM: suspend of devices complete after 14.490 msecs PM: suspend devices took 0.020 seconds PM: late suspend of devices complete after 1.645 msecs PM: noirq suspend of devices complete after 2.432 msecs Disabling non-boot CPUs ... CPU1: shutdown CPU2: shutdown CPU3: shutdown Enabling non-boot CPUs ... CPU1: Booted secondary processor CPU1 is up CPU2: Booted secondary processor CPU2 is up CPU3: Booted secondary processor CPU3 is up PM: noirq resume of devices complete after 1.217 msecs PM: early resume of devices complete after 1.590 msecs hub 2-1:1.0: hub_port_status failed (err = -71) hub 2-1:1.0: hub_port_status failed (err = -71) hub 2-1:1.0: hub_port_status failed (err = -71) PM: resume of devices complete after 70.677 msecs PM: resume devices took 0.080 seconds PM: Finishing wakeup. Restarting tasks ... done. mmc0: new high speed SDHC card at address a8a5 mmcblk0: mmc0:a8a5 SD04G 3.69 GiB mmcblk0: p1 p2 p3 mmc1: SD Status: Invalid Allocation Unit size. mmc1: card lacks mandatory switch function, performance might suffer. mmc1: new SD card at address b368 mmcblk1: mmc1:b368 MS 121 MiB mmcblk1: p1 root@freescale ~$ ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 hub 2-0:1.0: Cannot enable port 1. Maybe the USB cable is bad? ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 hub 2-0:1.0: Cannot enable port 1. Maybe the USB cable is bad? ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 hub 2-0:1.0: Cannot enable port 1. Maybe the USB cable is bad? ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 ci_hdrc ci_hdrc.1: port 1 reset error -110 hub 2-0:1.0: Cannot enable port 1. Maybe the USB cable is bad? hub 2-1:1.0: hub_port_status failed (err = -19) hub 2-1:1.0: hub_port_status failed (err = -19) hub 2-1:1.0: hub_port_status failed (err = -19) hub 2-1:1.0: activate --> -19 usb 2-1: USB disconnect, device number 2 ...
On Fri, Jan 18, 2013 at 10:50:28AM +0800, Peter Chen wrote: > +#ifdef CONFIG_PM > +static int ci13xxx_imx_suspend(struct device *dev) > +{ > + struct ci13xxx_imx_data *data = > + platform_get_drvdata(to_platform_device(dev)); Is there a reason not to use dev_get_drvdata() here? Hint: #define to_platform_device(x) container_of((x), struct platform_device, dev) static inline void *platform_get_drvdata(const struct platform_device *pdev) { return dev_get_drvdata(&pdev->dev); } So, you're going from a dev => platform device => the same dev again. It's perfectly valid to use dev_get_drvdata() here because we're not going to separate these two (it makes absolutely no sense to.)
> > On Fri, Jan 18, 2013 at 10:50:28AM +0800, Peter Chen wrote: > > +#ifdef CONFIG_PM > > +static int ci13xxx_imx_suspend(struct device *dev) > > +{ > > + struct ci13xxx_imx_data *data = > > + platform_get_drvdata(to_platform_device(dev)); > > Is there a reason not to use dev_get_drvdata() here? Hint: > It is my careless, I will change. Thanks. > #define to_platform_device(x) container_of((x), struct platform_device, > dev) > > static inline void *platform_get_drvdata(const struct platform_device > *pdev) > { > return dev_get_drvdata(&pdev->dev); > } > > So, you're going from a dev => platform device => the same dev again. > > It's perfectly valid to use dev_get_drvdata() here because we're not > going > to separate these two (it makes absolutely no sense to.)
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h index ba9c6ef..d1467bb 100644 --- a/drivers/usb/chipidea/bits.h +++ b/drivers/usb/chipidea/bits.h @@ -47,6 +47,7 @@ #define PORTSC_FPR BIT(6) #define PORTSC_SUSP BIT(7) #define PORTSC_HSP BIT(9) +#define PORTSC_PHCD BIT(23) /* phy suspend mode */ #define PORTSC_PTC (0x0FUL << 16) /* DEVLC */ diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c index 342eab0..e892874 100644 --- a/drivers/usb/chipidea/ci13xxx_imx.c +++ b/drivers/usb/chipidea/ci13xxx_imx.c @@ -25,6 +25,7 @@ #include <linux/mfd/syscon.h> #include "ci.h" +#include "bits.h" #include "ci13xxx_imx.h" #define pdev_to_phy(pdev) \ @@ -321,6 +322,63 @@ static int ci13xxx_imx_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM +static int ci13xxx_imx_suspend(struct device *dev) +{ + struct ci13xxx_imx_data *data = + platform_get_drvdata(to_platform_device(dev)); + struct platform_device *plat_ci; + struct ci13xxx *ci; + + plat_ci = data->ci_pdev; + ci = platform_get_drvdata(plat_ci); + + hw_write(ci, OP_PORTSC, PORTSC_PHCD, PORTSC_PHCD); + + if (data->phy) + usb_phy_set_suspend(data->phy, 1); + + clk_disable_unprepare(data->clk); + + return 0; +} + +static int ci13xxx_imx_resume(struct device *dev) +{ + int ret; + struct ci13xxx_imx_data *data = + platform_get_drvdata(to_platform_device(dev)); + struct platform_device *plat_ci; + struct ci13xxx *ci; + + plat_ci = data->ci_pdev; + ci = platform_get_drvdata(plat_ci); + + ret = clk_prepare_enable(data->clk); + if (ret) { + dev_err(dev, + "Failed to prepare or enable clock, err=%d\n", ret); + return ret; + } + + if (hw_read(ci, OP_PORTSC, PORTSC_PHCD)) { + hw_write(ci, OP_PORTSC, PORTSC_PHCD, 0); + /* Some clks sync between Controller and USB PHY */ + mdelay(1); + } + + if (data->phy) + usb_phy_set_suspend(data->phy, 0); + + return ret; +} + +static const struct dev_pm_ops ci13xxx_imx_pm_ops = { + .suspend = ci13xxx_imx_suspend, + .resume = ci13xxx_imx_resume, +}; +#endif + static const struct of_device_id ci13xxx_imx_dt_ids[] = { { .compatible = "fsl,imx27-usb", }, { /* sentinel */ } @@ -334,6 +392,9 @@ static struct platform_driver ci13xxx_imx_driver = { .name = "imx_usb", .owner = THIS_MODULE, .of_match_table = ci13xxx_imx_dt_ids, +#ifdef CONFIG_PM + .pm = &ci13xxx_imx_pm_ops, +#endif }, };
During the system suspend/resume procedure, the USB also needs to go suspend/resume procedure, this patch adds related APIs. It is tested at i.mx6q sabrelite. Meanwhile, it fixes the bug that the USB will out of work after system suspend/resume. Signed-off-by: Peter Chen <peter.chen@freescale.com> --- drivers/usb/chipidea/bits.h | 1 + drivers/usb/chipidea/ci13xxx_imx.c | 61 ++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 0 deletions(-)