usb: musb: Using runtime pm APIs for musb.
PATCH v4 5/5 usb: musb: Using runtime pm APIs for musb.
Calling runtime pm APIs pm_runtime_put_sync() and pm_runtime_get_sync() for enabling/disabling the clocks, sysconfig settings.
enable clock, configure no-idle/standby when active and configure force idle/standby and disable clock when idled. This is taken care by the runtime framework when driver calls the pm_runtime_get_sync and pm_runtime_put_sync APIs. Need to configure MUSB into force standby and force idle mode when usb not used
---
drivers/usb/musb/musb_core.h | 2 - drivers/usb/musb/omap2430.c | 77 ++++++++++--------------------------------- 2 files changed, 20 insertions(+), 59 deletions(-)
drivers/usb/musb/omap2430.c +19 -58
@@ -33,6 +33,7 @@#include <linux/io.h> #include <linux/platform_device.h> #include <linux/dma-mapping.h> +#include <linux/pm_runtime.h> #include "musb_core.h" #include "omap2430.h"
@@ -40,7 +41,6 @@struct omap2430_glue {struct device *dev;struct platform_device *musb; -struct clk *clk; };#define glue_to_musb (g) platform_get_drvdata(g->musb)
@@ -216,20 +216,12 @@ static inline void omap2430_low_level_ex l =musb_readl (musb->mregs,OTG_FORCESTDBY ); l |=ENABLEFORCE ;/* enable MSTANDBY */ musb_writel (musb->mregs,OTG_FORCESTDBY , l); - - l =musb_readl (musb->mregs,OTG_SYSCONFIG ); - l |=ENABLEWAKEUP ;/* enable wakeup */ -musb_writel (musb->mregs,OTG_SYSCONFIG , l); }static inline void omap2430_low_level_init (struct musb *musb) {u32 l; - l =musb_readl (musb->mregs,OTG_SYSCONFIG ); - l &= ~ENABLEWAKEUP ;/* disable wakeup */ -musb_writel (musb->mregs,OTG_SYSCONFIG , l); - l =musb_readl (musb->mregs,OTG_FORCESTDBY ); l &= ~ENABLEFORCE ;/* disable MSTANDBY */ musb_writel (musb->mregs,OTG_FORCESTDBY , l);
@@ -307,21 +299,6 @@ static int omap2430_musb_init(struct musomap2430_low_level_init (musb); - l =musb_readl (musb->mregs,OTG_SYSCONFIG ); - l &= ~ENABLEWAKEUP ;/* disable wakeup */ - l &= ~NOSTDBY ;/* remove possible nostdby */ - l |=SMARTSTDBY ;/* enable smart standby */ - l &= ~AUTOIDLE ;/* disable auto idle */ - l &= ~NOIDLE ;/* remove possible noidle */ - l |=SMARTIDLE ;/* enable smart idle */ -/* -* MUSB AUTOIDLE don't work in 3430. -* Workaround by Richard Woodruff/TI -*/ -if (!cpu_is_omap3430 ()) - l |=AUTOIDLE ;/* enable auto idle */ -musb_writel (musb->mregs,OTG_SYSCONFIG , l); - l =musb_readl (musb->mregs,OTG_INTERFSEL );if (data->interface_type ==MUSB_INTERFACE_UTMI ) {
@@ -384,7 +361,7 @@ static int __init omap2430_probe(structstruct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;struct platform_device *musb;struct omap2430_glue *glue; -struct clk *clk; +int status =0 ;int ret = -ENOMEM ;
@@ -400,26 +377,12 @@ static int __init omap2430_probe(struct goto err1; } - clk =clk_get (&pdev->dev,"ick" ); -if (IS_ERR (clk)) { -dev_err (&pdev->dev,"failed to get clock\n" ); - ret =PTR_ERR (clk); - goto err2; - } - - ret =clk_enable (clk); -if (ret) { -dev_err (&pdev->dev,"failed to enable clock\n" ); - goto err3; - } - musb->dev.parent = &pdev->dev; musb->dev.dma_mask = &omap2430_dmamask; musb->dev.coherent_dma_mask = omap2430_dmamask; glue->dev = &pdev->dev; glue->musb = musb; - glue->clk = clk; pdata->platform_ops = &omap2430_ops;
@@ -429,28 +392,29 @@ static int __init omap2430_probe(struct pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); - goto err4; + goto err2; } ret =platform_device_add_data (musb, pdata,sizeof (*pdata));if (ret) {dev_err (&pdev->dev,"failed to add platform_data\n" ); - goto err4; + goto err2; } ret =platform_device_add (musb);if (ret) {dev_err (&pdev->dev,"failed to register musb device\n" ); - goto err4; + goto err2; } -return 0 ; +pm_runtime_enable (&pdev->dev); +if (pm_runtime_get_sync (dev)) { +dev_err (dev,"pm_runtime_get_sync FAILED" ); + goto err2; + } -err4: -clk_disable (clk); +return 0 ; -err3: -clk_put (clk); err2:platform_device_put (musb);
@@ -468,8 +432,7 @@ static int __exit omap2430_remove(structplatform_device_del (glue->musb);platform_device_put (glue->musb); -clk_disable (glue->clk); -clk_put (glue->clk); +pm_runtime_put_sync (&pdev->dev);kfree (glue);return 0 ;
@@ -478,13 +441,11 @@ static int __exit omap2430_remove(struct#ifdef CONFIG_PM static void omap2430_save_context (struct musb *musb) { - musb->context.otg_sysconfig =musb_readl (musb->mregs,OTG_SYSCONFIG ); musb->context.otg_forcestandby =musb_readl (musb->mregs,OTG_FORCESTDBY ); }static void omap2430_restore_context (struct musb *musb) { -musb_writel (musb->mregs,OTG_SYSCONFIG , musb->context.otg_sysconfig);musb_writel (musb->mregs,OTG_FORCESTDBY , musb->context.otg_forcestandby); }
@@ -496,8 +457,11 @@ static int omap2430_suspend(struct devicomap2430_low_level_exit (musb);otg_set_suspend (musb->xceiv,1 );omap2430_save_context (musb); -clk_disable (glue->clk); +if (pm_runtime_put_sync (dev)) +dev_err (dev,"pm_runtime_put_sync FAILED" ); +return -EINVLD ; + }return 0 ; }
@@ -505,14 +469,11 @@ static int omap2430_resume(struct device {struct omap2430_glue *glue =dev_get_drvdata (dev);struct musb *musb =glue_to_musb (glue); -int ret; - ret =clk_enable (glue->clk); -if (ret) { -dev_err (dev,"faled to enable clock\n" ); -return ret; + if (pm_runtime_get_sync(&pdev->dev) { +dev_err (dev,"pm_runtime_get_sync FAILED" ); +return -EINVLD ; } -omap2430_low_level_init (musb);omap2430_restore_context (musb);otg_set_suspend (musb->xceiv,0 );
drivers/usb/musb/musb_core.h +1 -1
@@ -360,7 +360,7 @@ struct musb_context_registers {#if defined(CONFIG_ARCH_OMAP2430 ) || defined(CONFIG_ARCH_OMAP3 ) || \ defined(CONFIG_ARCH_OMAP4 ) -u32 otg_sysconfig, otg_forcestandby; +u32 otg_forcestandby;#endif u8 power;u16 intrtxe, intrrxe;
Hi,
Quoted 18 lines · Hema HK
drivers/usb/musb/omap2430.c +2
-2@@ -429,28 +392,29 @@ static int __init omap2430_probe(struct pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); - goto err4; + goto err2; } ret =platform_device_add_data (musb, pdata,sizeof (*pdata));if (ret) {dev_err (&pdev->dev,"failed to add platform_data\n" ); - goto err4; + goto err2; } ret =platform_device_add (musb);if (ret) {dev_err (&pdev->dev,"failed to register musb device\n" );
drivers/usb/musb/omap2430.c static int __init omap2430_probe(struct · line 414
Quoted 10 lines
drivers/usb/musb/omap2430.c +6
-2- goto err4; + goto err2; } -return 0 ; +pm_runtime_enable (&pdev->dev); +if (pm_runtime_get_sync (dev)) { +dev_err (dev,"pm_runtime_get_sync FAILED" ); + goto err2; + }
don't you have to pm_runtime_disable() if get_sync fails ?
drivers/usb/musb/omap2430.c static int __exit omap2430_remove(struct · line 435
Quoted 7 lines
drivers/usb/musb/omap2430.c +1
-2@@ -468,8 +432,7 @@ static int __exit omap2430_remove(structplatform_device_del (glue->musb);platform_device_put (glue->musb); -clk_disable (glue->clk); -clk_put (glue->clk); +pm_runtime_put_sync (&pdev->dev);
same here, don't you need to pm_runtime_disable() ??
Signature · 1 line
balbi
A message that is not in the archive (sent off-list or not yet received): 20101210125958.GK6027-UiBtZHVXSwEVvW8u9ZQWYwjfymiNCTlR@public.gmane.org
Quoted 26 lines · Felipe Balbi
Hi,
Quoted 23 lines · Hema HK
drivers/usb/musb/omap2430.c +3
-3@@ -429,28 +392,29 @@ static int __init omap2430_probe(struct pdev->num_resources); if (ret) { dev_err(&pdev->dev, "failed to add resources\n"); - goto err4; + goto err2; } ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); if (ret) { dev_err(&pdev->dev, "failed to add platform_data\n"); - goto err4; + goto err2; } ret = platform_device_add(musb); if (ret) { dev_err(&pdev->dev, "failed to register musb device\n"); - goto err4; + goto err2; }
Quoted 8 lines
drivers/usb/musb/omap2430.c static int __init omap2430_probe(struct · line 414
Quoted 6 lines
drivers/usb/musb/omap2430.c +5
-1- return 0; + pm_runtime_enable(&pdev->dev); + if (pm_runtime_get_sync(dev)) { + dev_err(dev, "pm_runtime_get_sync FAILED"); + goto err2; + }don't you have to
pm_runtime_disable()ifget_syncfails ?
Yes. That is require. Otherwise next time driver load will through warning. Thanks for pointing this out.
Quoted 10 lines
drivers/usb/musb/omap2430.c static int __exit omap2430_remove(struct · line 435
Quoted 8 lines
drivers/usb/musb/omap2430.c +1
-2@@ -468,8 +432,7 @@ static int __exit omap2430_remove(struct platform_device_del(glue->musb); platform_device_put(glue->musb); - clk_disable(glue->clk); - clk_put(glue->clk); + pm_runtime_put_sync(&pdev->dev);same here, don't you need to
pm_runtime_disable()??
Yes.
Regards,
Hema
Quoted 4 lines
--
balbi
--
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