From 207b0e1f1655bd7008b7322cdc3f84fb171c546d Mon Sep 17 00:00:00 2001 From: Hema HK Date: Thu, 17 Feb 2011 12:07:22 +0530 Subject: 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 Signed-off-by: Hema HK Cc: Tony Lindgren Cc: Kevin Hilman Cc: Cousson, Benoit Cc: Paul Walmsley Signed-off-by: Felipe Balbi --- drivers/usb/musb/omap2430.c | 81 +++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 58 deletions(-) (limited to 'drivers/usb/musb/omap2430.c') diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index a3f1233..bb6e6cd 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include "musb_core.h" #include "omap2430.h" @@ -40,7 +42,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 +217,12 @@ static inline void omap2430_low_level_exit(struct musb *musb) 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); @@ -309,21 +302,6 @@ static int omap2430_musb_init(struct musb *musb) omap2430_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) { @@ -386,7 +364,7 @@ static int __init omap2430_probe(struct platform_device *pdev) struct 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; @@ -402,26 +380,12 @@ static int __init omap2430_probe(struct platform_device *pdev) 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; @@ -431,29 +395,32 @@ static int __init omap2430_probe(struct platform_device *pdev) 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); + status = pm_runtime_get_sync(&pdev->dev); + if (status < 0) { + dev_err(&pdev->dev, "pm_runtime_get_sync FAILED"); + goto err3; + } -err4: - clk_disable(clk); + return 0; err3: - clk_put(clk); - + pm_runtime_disable(&pdev->dev); err2: platform_device_put(musb); @@ -470,8 +437,8 @@ static int __exit omap2430_remove(struct platform_device *pdev) platform_device_del(glue->musb); platform_device_put(glue->musb); - clk_disable(glue->clk); - clk_put(glue->clk); + pm_runtime_put(&pdev->dev); + pm_runtime_disable(&pdev->dev); kfree(glue); return 0; @@ -480,13 +447,11 @@ static int __exit omap2430_remove(struct platform_device *pdev) #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); } @@ -498,7 +463,10 @@ static int omap2430_suspend(struct device *dev) omap2430_low_level_exit(musb); otg_set_suspend(musb->xceiv, 1); omap2430_save_context(musb); - clk_disable(glue->clk); + + if (!pm_runtime_suspended(dev) && dev->bus && dev->bus->pm && + dev->bus->pm->runtime_suspend) + dev->bus->pm->runtime_suspend(dev); return 0; } @@ -507,13 +475,10 @@ static int omap2430_resume(struct device *dev) { 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_suspended(dev) && dev->bus && dev->bus->pm && + dev->bus->pm->runtime_resume) + dev->bus->pm->runtime_resume(dev); omap2430_low_level_init(musb); omap2430_restore_context(musb); -- cgit v1.1 From 002eda1348788f623dc42231dcda5f591d753124 Mon Sep 17 00:00:00 2001 From: Hema HK Date: Thu, 17 Feb 2011 12:06:10 +0530 Subject: usb: musb: OMAP4430: Fix usb device detection if connected during boot OMAP4430 is embedded with UTMI PHY. This PHY does not support the OTG features like ID pin detection and VBUS detection. This function is exported to an external companion chip TWL6030. Software must retrieve the OTG HNP and SRP status from the TWL6030 and configure the bits inside the control module that drive the related USBOTGHS UTMI interface signals. It must also read back the UTMI signals needed to configure the TWL6030 OTG module. Can find more details in the TRM[1]. [1]:http://focus.ti.com/pdfs/wtbu/OMAP4430_ES2.0_Public_TRM_vJ.pdf In OMAP4430 musb driver VBUS and ID notifications are received from the transceiver driver. If the cable/device is connected during boot, notifications from transceiver driver will be missed till musb driver is loaded. Patch to configure the transceiver in the platform_enable/disable functions and enable the vbus in the gadget driver based on the last_event of the otg_transceiver. Signed-off-by: Hema HK Cc: Tony Lindgren Cc: Paul Walmsley Signed-off-by: Felipe Balbi --- drivers/usb/musb/omap2430.c | 53 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 'drivers/usb/musb/omap2430.c') diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index bb6e6cd..64cf243 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -328,16 +328,56 @@ static int omap2430_musb_init(struct musb *musb) if (status) DBG(1, "notification register failed\n"); - /* check whether cable is already connected */ - if (musb->xceiv->state ==OTG_STATE_B_IDLE) - musb_otg_notifications(&musb->nb, 1, - musb->xceiv->gadget); - setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); return 0; } +static void omap2430_musb_enable(struct musb *musb) +{ + u8 devctl; + unsigned long timeout = jiffies + msecs_to_jiffies(1000); + struct device *dev = musb->controller; + struct musb_hdrc_platform_data *pdata = dev->platform_data; + struct omap_musb_board_data *data = pdata->board_data; + + switch (musb->xceiv->last_event) { + + case USB_EVENT_ID: + otg_init(musb->xceiv); + if (data->interface_type == MUSB_INTERFACE_UTMI) { + devctl = musb_readb(musb->mregs, MUSB_DEVCTL); + /* start the session */ + devctl |= MUSB_DEVCTL_SESSION; + musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); + while (musb_readb(musb->mregs, MUSB_DEVCTL) & + MUSB_DEVCTL_BDEVICE) { + cpu_relax(); + + if (time_after(jiffies, timeout)) { + dev_err(musb->controller, + "configured as A device timeout"); + break; + } + } + } + break; + + case USB_EVENT_VBUS: + otg_init(musb->xceiv); + break; + + default: + break; + } +} + +static void omap2430_musb_disable(struct musb *musb) +{ + if (musb->xceiv->last_event) + otg_shutdown(musb->xceiv); +} + static int omap2430_musb_exit(struct musb *musb) { @@ -355,6 +395,9 @@ static const struct musb_platform_ops omap2430_ops = { .try_idle = omap2430_musb_try_idle, .set_vbus = omap2430_musb_set_vbus, + + .enable = omap2430_musb_enable, + .disable = omap2430_musb_disable, }; static u64 omap2430_dmamask = DMA_BIT_MASK(32); -- cgit v1.1 From da68ccec210c45eb99e461ad31b499b4e7043c41 Mon Sep 17 00:00:00 2001 From: Hema HK Date: Mon, 28 Feb 2011 14:19:33 +0530 Subject: usb: musb: Remove platform context save/restore API For OMAP3 and OMAP4 for offmode and retention support, musb sysconfig is configured to force idle and standby with ENABLE_FORCE bit of OTG_FORCESTNDBY set. And on wakeup configure to no ilde/standby with resetting the ENABLE_FORCE bit. There is not need to save and restore of this register anymore so removed omap2430_save_context/omap2430_restore_context functions. and also removed otg_forcestandby member of musb_context_registers structure Signed-off-by: Hema HK Signed-off-by: Felipe Balbi --- drivers/usb/musb/omap2430.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'drivers/usb/musb/omap2430.c') diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index 64cf243..b6dcc7e 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -488,15 +488,6 @@ static int __exit omap2430_remove(struct platform_device *pdev) } #ifdef CONFIG_PM -static void omap2430_save_context(struct musb *musb) -{ - musb->context.otg_forcestandby = musb_readl(musb->mregs, OTG_FORCESTDBY); -} - -static void omap2430_restore_context(struct musb *musb) -{ - musb_writel(musb->mregs, OTG_FORCESTDBY, musb->context.otg_forcestandby); -} static int omap2430_suspend(struct device *dev) { @@ -505,7 +496,6 @@ static int omap2430_suspend(struct device *dev) omap2430_low_level_exit(musb); otg_set_suspend(musb->xceiv, 1); - omap2430_save_context(musb); if (!pm_runtime_suspended(dev) && dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend) @@ -524,7 +514,6 @@ static int omap2430_resume(struct device *dev) dev->bus->pm->runtime_resume(dev); omap2430_low_level_init(musb); - omap2430_restore_context(musb); otg_set_suspend(musb->xceiv, 0); return 0; -- cgit v1.1 From 7acc6197b76edd0b932a7cbcc6cfad0a8a87f026 Mon Sep 17 00:00:00 2001 From: Hema HK Date: Mon, 28 Feb 2011 14:19:34 +0530 Subject: usb: musb: Idle path retention and offmode support for OMAP3 This patch supports the retention and offmode support in the idle path for musb driver using runtime pm APIs. This is restricted to support offmode and retention only when device not connected.When device/cable connected with gadget driver loaded,configured to no idle/standby which will not allow the core transition to retention or off. There is no context save/restore done by hardware for musb in OMAP3 and OMAP4,driver has to take care of saving and restoring the context during offmode. Musb has a requirement of configuring sysconfig register to force idle/standby mode and set the ENFORCE bit in module STANDBY register for retention and offmode support. Runtime pm and hwmod frameworks will take care of configuring to force idle/standby when pm_runtime_put_sync is called and back to no idle/standby when pm_runeime_get_sync is called. Compile, boot tested and also tested the retention in the idle path on OMAP3630Zoom3. And tested the global suspend/resume with offmode enabled. Usb basic functionality tested on OMAP4430SDP. There is some problem with idle path offmode in mainline, I could not test with offmode. But I have tested this patch with resetting the controller in the idle path when wakeup from retention just to make sure that the context is lost, and restore path is working fine. Removed .suspend/.resume fnction pointers and functions because there is no need of having these functions as all required work is done at runtime in the driver. There is no need to call the runtime pm api with glue driver device as glue layer device is the parent of musb core device, when runtime apis are called for the child, parent device runtime functionality will be invoked. Design overview: pm_runtime_get_sync: When called with musb core device takes care of enabling the clock, calling runtime callback function of omap2430 glue layer, runtime call back of musb driver and configure the musb sysconfig to no idle/standby pm_runtime_put: Takes care of calling runtime callback function of omap2430 glue layer, runtime call back of musb driver, Configure the musb sysconfig to force idle/standby and disable the clock. During musb driver load: Call pm_runtime_get_sync. End of musb driver load: Call pm_runtime_put During gadget driver load: Call pm_runtime_get_sync, End of gadget driver load: Call pm_runtime_put if there is no device or cable is connected. During unload of the gadget driver:Call pm_runtime_get_sync if cable/device is not connected. End of the gadget driver unload : pm_runtime_put During unload of musb driver : Call pm_runtime_get_sync End of unload: Call pm_runtime_put On connect of usb cable/device -> transceiver notification(VBUS and ID-GND): pm_runtime_get_sync only if the gadget driver loaded. On disconnect of the cable/device -> Disconnect Notification: pm_runtime_put if the gadget driver is loaded. Signed-off-by: Hema HK Signed-off-by: Felipe Balbi --- drivers/usb/musb/omap2430.c | 49 +++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'drivers/usb/musb/omap2430.c') diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index b6dcc7e..4726798 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -244,6 +244,7 @@ static int musb_otg_notifications(struct notifier_block *nb, if (is_otg_enabled(musb)) { #ifdef CONFIG_USB_GADGET_MUSB_HDRC if (musb->gadget_driver) { + pm_runtime_get_sync(musb->controller); otg_init(musb->xceiv); if (data->interface_type == @@ -253,6 +254,7 @@ static int musb_otg_notifications(struct notifier_block *nb, } #endif } else { + pm_runtime_get_sync(musb->controller); otg_init(musb->xceiv); if (data->interface_type == MUSB_INTERFACE_UTMI) @@ -263,12 +265,24 @@ static int musb_otg_notifications(struct notifier_block *nb, case USB_EVENT_VBUS: DBG(4, "VBUS Connect\n"); + if (musb->gadget_driver) + pm_runtime_get_sync(musb->controller); + otg_init(musb->xceiv); break; case USB_EVENT_NONE: DBG(4, "VBUS Disconnect\n"); +#ifdef CONFIG_USB_GADGET_MUSB_HDRC + if (is_otg_enabled(musb)) + if (musb->gadget_driver) +#endif + { + pm_runtime_mark_last_busy(musb->controller); + pm_runtime_put_autosuspend(musb->controller); + } + if (data->interface_type == MUSB_INTERFACE_UTMI) { if (musb->xceiv->set_vbus) otg_set_vbus(musb->xceiv, 0); @@ -300,7 +314,11 @@ static int omap2430_musb_init(struct musb *musb) return -ENODEV; } - omap2430_low_level_init(musb); + status = pm_runtime_get_sync(dev); + if (status < 0) { + dev_err(dev, "pm_runtime_get_sync FAILED"); + goto err1; + } l = musb_readl(musb->mregs, OTG_INTERFSEL); @@ -331,6 +349,10 @@ static int omap2430_musb_init(struct musb *musb) setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); return 0; + +err1: + pm_runtime_disable(dev); + return status; } static void omap2430_musb_enable(struct musb *musb) @@ -407,8 +429,6 @@ static int __init omap2430_probe(struct platform_device *pdev) struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; struct platform_device *musb; struct omap2430_glue *glue; - int status = 0; - int ret = -ENOMEM; glue = kzalloc(sizeof(*glue), GFP_KERNEL); @@ -454,16 +474,9 @@ static int __init omap2430_probe(struct platform_device *pdev) } pm_runtime_enable(&pdev->dev); - status = pm_runtime_get_sync(&pdev->dev); - if (status < 0) { - dev_err(&pdev->dev, "pm_runtime_get_sync FAILED"); - goto err3; - } return 0; -err3: - pm_runtime_disable(&pdev->dev); err2: platform_device_put(musb); @@ -489,7 +502,7 @@ static int __exit omap2430_remove(struct platform_device *pdev) #ifdef CONFIG_PM -static int omap2430_suspend(struct device *dev) +static int omap2430_runtime_suspend(struct device *dev) { struct omap2430_glue *glue = dev_get_drvdata(dev); struct musb *musb = glue_to_musb(glue); @@ -497,22 +510,14 @@ static int omap2430_suspend(struct device *dev) omap2430_low_level_exit(musb); otg_set_suspend(musb->xceiv, 1); - if (!pm_runtime_suspended(dev) && dev->bus && dev->bus->pm && - dev->bus->pm->runtime_suspend) - dev->bus->pm->runtime_suspend(dev); - return 0; } -static int omap2430_resume(struct device *dev) +static int omap2430_runtime_resume(struct device *dev) { struct omap2430_glue *glue = dev_get_drvdata(dev); struct musb *musb = glue_to_musb(glue); - if (!pm_runtime_suspended(dev) && dev->bus && dev->bus->pm && - dev->bus->pm->runtime_resume) - dev->bus->pm->runtime_resume(dev); - omap2430_low_level_init(musb); otg_set_suspend(musb->xceiv, 0); @@ -520,8 +525,8 @@ static int omap2430_resume(struct device *dev) } static struct dev_pm_ops omap2430_pm_ops = { - .suspend = omap2430_suspend, - .resume = omap2430_resume, + .runtime_suspend = omap2430_runtime_suspend, + .runtime_resume = omap2430_runtime_resume, }; #define DEV_PM_OPS (&omap2430_pm_ops) -- cgit v1.1 From 70045c57f31f998a7206baa81167c7bc9f452cef Mon Sep 17 00:00:00 2001 From: Hema HK Date: Mon, 28 Feb 2011 15:05:29 +0530 Subject: usb: musb: OMAP3xxx: Fix device detection in otg & host mode In OMAP3xxx with OTG mode or host only mode, When the device is inserted after the gadget driver loading the enumeration was not through. This is because the mentor controller will start sensing the ID PIN only after setting the session bit. So after ID-GND, need to set the session bit for mentor to get it configured as A device. This is a fix to set the session bit again in ID_GND notification handler. Tested with OMAP3630Zoom3 platform. Signed-off-by: Hema HK Signed-off-by: Felipe Balbi --- drivers/usb/musb/omap2430.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'drivers/usb/musb/omap2430.c') diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index 4726798..f5d4f36 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -246,19 +246,13 @@ static int musb_otg_notifications(struct notifier_block *nb, if (musb->gadget_driver) { pm_runtime_get_sync(musb->controller); otg_init(musb->xceiv); - - if (data->interface_type == - MUSB_INTERFACE_UTMI) - omap2430_musb_set_vbus(musb, 1); - + omap2430_musb_set_vbus(musb, 1); } #endif } else { pm_runtime_get_sync(musb->controller); otg_init(musb->xceiv); - if (data->interface_type == - MUSB_INTERFACE_UTMI) - omap2430_musb_set_vbus(musb, 1); + omap2430_musb_set_vbus(musb, 1); } break; -- cgit v1.1