Skip to contentSkip to conversation

usb: musb: Offmode fix for idle path

PATCH In review Hema HK 4 participants 5 messages Aug 18, 2010 – Sep 3, 2010 1 message not in the archive

Subsystems (7)
lore
Share & tools
lore

Hema HK

author
#0 lore raw

PATCH v2 6/8 usb: musb: Offmode fix for idle path

With OMAP core-off support musb was not functional as context was getting lost after wakeup from core-off. And also musb was blocking the core-off after loading the gadget driver even with no cable connected sometimes.

Added the conext save/restore api in the platform layer which will be called in the idle and wakeup path.

Changed the usb sysconfig settings as per the usbotg functional spec. When the device is not used, configure to force idle and force standby mode. When it is being used, configure in smart standby and smart idle mode. So while attempting to coreoff the usb is configured to force standby and force idle mode, after wakeup configured in smart idle and smart standby.

Cc Felipe Balbi <[email protected]>
Cc Tony Lindgren <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Cousson, Benoit <[email protected]>
Cc Paul Walmsley <[email protected]>
---
 arch/arm/mach-omap2/pm34xx.c          |    5 +++
 arch/arm/mach-omap2/usb-musb.c        |   42 ++++++++++++++++++++++++++++-
 arch/arm/plat-omap/include/plat/usb.h |    2 +
 drivers/usb/musb/musb_core.c          |   10 +++----
 drivers/usb/musb/musb_core.h          |    1 -
 drivers/usb/musb/omap2430.c           |   48 ++++++++++++++++++++++++++++++---
 include/linux/usb/musb.h              |    6 ++++
 7 files changed, 102 insertions(+), 12 deletions(-)
arch/arm/mach-omap2/pm34xx.c +5 -0
index fb4994a..7b34201 100644
@@ -39,6 +39,7 @@
 #include <plat/gpmc.h>
 #include <plat/dma.h>
 #include <plat/dmtimer.h>
+#include <plat/usb.h>
 
 #include <asm/tlbflush.h>
 
@@ -416,6 +417,8 @@ void omap_sram_idle(void)
 		if (core_next_state == PWRDM_POWER_OFF) {
 			omap3_core_save_context();
 			omap3_prcm_save_context();
+			/* Save MUSB context */
+			musb_context_save_restore(1);
 		}
 	}
 
@@ -458,6 +461,8 @@ void omap_sram_idle(void)
 			omap3_prcm_restore_context();
 			omap3_sram_restore_context();
 			omap2_sms_restore_context();
+			/* restore MUSB context */
+			musb_context_save_restore(0);
 		}
 		omap_uart_resume_idle(0);
 		omap_uart_resume_idle(1);
arch/arm/mach-omap2/usb-musb.c +41 -1

68 lines not on this page · raw message

arch/arm/plat-omap/include/plat/usb.h +2 -0
index 2a9427c..ed2b41a 100644
@@ -79,6 +79,8 @@ extern void usb_ehci_init(const struct ehci_hcd_omap_platform_data *pdata);
 
 extern void usb_ohci_init(const struct ohci_hcd_omap_platform_data *pdata);
 
+/* For saving and restoring the musb context during off/wakeup*/
+extern void musb_context_save_restore(int save);
 #endif
 
 
drivers/usb/musb/musb_core.c +4 -6
index 2a50d12..8510e55 100644
@@ -2410,6 +2410,7 @@ static int musb_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	unsigned long	flags;
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
@@ -2428,9 +2429,7 @@ static int musb_suspend(struct device *dev)
 
 	musb_save_context(musb);
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 0);
-	else
+	if (!plat->clk_autogated)
 		clk_disable(musb->clock);
 	spin_unlock_irqrestore(&musb->lock, flags);
 	return 0;
@@ -2440,13 +2439,12 @@ static int musb_resume_noirq(struct device *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 1);
-	else
+	if (!plat->clk_autogated)
 		clk_enable(musb->clock);
 
 	musb_restore_context(musb);
drivers/usb/musb/musb_core.h +0 -1
index 85a92fd..bfdf54d 100644
@@ -472,7 +472,6 @@ struct musb_context_registers {
 
 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \
     defined(CONFIG_ARCH_OMAP4)
-	u32 otg_sysconfig, otg_forcestandby;
 #endif
 	u8 power;
 	u16 intrtxe, intrrxe;
drivers/usb/musb/omap2430.c +44 -4

71 lines not on this page · raw message

include/linux/usb/musb.h +6 -0
index ee2dd1d..da134ab 100644
@@ -126,6 +126,12 @@ struct musb_hdrc_platform_data {
 
 	/* Architecture specific board data	*/
 	void		*board_data;
+
+	/* check usb device active state*/
+	int		(*is_usb_active)(struct device *dev);
+
+	/*  indiates whether clock is autogated */
+	int		clk_autogated;
 };
 
 
Signature · 6 lines
1.7.0.4

--
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): 1282140624-29715-1-git-send-email-hemahk-l0cyMroinI0@public.gmane.org

#2 lore raw
Quoted 4 lines · Hema HK

With OMAP core-off support musb was not functional as context was getting lost after wakeup from core-off. And also musb was blocking the core-off after loading the gadget driver even with no cable connected sometimes.

Quoted 8 lines

Added the conext save/restore api in the platform layer which will be called in the idle and wakeup path.

Changed the usb sysconfig settings as per the usbotg functional spec. When the device is not used, configure to force idle and force standby mode. When it is being used, configure in smart standby and smart idle mode. So while attempting to coreoff the usb is configured to force standby and force idle mode, after wakeup configured in smart idle and smart standby.

You don't describe the new .clk_autogated field added here. That part should be a separate patch as it's not directly related to $SUBJECT patch.

Quoted 61 lines
Cc Felipe Balbi <[email protected]>
Cc Tony Lindgren <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Cousson, Benoit <[email protected]>
Cc Paul Walmsley <[email protected]>
---
 arch/arm/mach-omap2/pm34xx.c          |    5 +++
 arch/arm/mach-omap2/usb-musb.c        |   42 ++++++++++++++++++++++++++++-
 arch/arm/plat-omap/include/plat/usb.h |    2 +
 drivers/usb/musb/musb_core.c          |   10 +++----
 drivers/usb/musb/musb_core.h          |    1 -
 drivers/usb/musb/omap2430.c           |   48 ++++++++++++++++++++++++++++++---
 include/linux/usb/musb.h              |    6 ++++
 7 files changed, 102 insertions(+), 12 deletions(-)
arch/arm/mach-omap2/pm34xx.c +5 -0
index fb4994a..7b34201 100644
@@ -39,6 +39,7 @@
 #include <plat/gpmc.h>
 #include <plat/dma.h>
 #include <plat/dmtimer.h>
+#include <plat/usb.h>
 
 #include <asm/tlbflush.h>
 
@@ -416,6 +417,8 @@ void omap_sram_idle(void)
 		if (core_next_state == PWRDM_POWER_OFF) {
 			omap3_core_save_context();
 			omap3_prcm_save_context();
+			/* Save MUSB context */
+			musb_context_save_restore(1);
 		}
 	}
 
@@ -458,6 +461,8 @@ void omap_sram_idle(void)
 			omap3_prcm_restore_context();
 			omap3_sram_restore_context();
 			omap2_sms_restore_context();
+			/* restore MUSB context */
+			musb_context_save_restore(0);
 		}
 		omap_uart_resume_idle(0);
 		omap_uart_resume_idle(1);
arch/arm/mach-omap2/usb-musb.c +1 -0
index c228cc0..9d10440 100644
@@ -35,6 +35,7 @@
 
 static const char name[] = "musb_hdrc";
 #define MAX_OMAP_MUSB_HWMOD_NAME_LEN	16
+struct omap_hwmod *oh_p =NULL;
 
 static struct musb_hdrc_config musb_config = {
 	.multipoint	= 1,

arch/arm/mach-omap2/usb-musb.c static struct musb_hdrc_platform_data musb_plat = { · line 65

Quoted 6 lines
arch/arm/mach-omap2/usb-musb.c +3 -0
@@ -59,6 +60,9 @@ static struct musb_hdrc_platform_data musb_plat = {
 	 * "mode", and should be passed to usb_musb_init().
 	 */
 	.power		= 50,			/* up to 100 mA */
+
+	/* supports clock autogating */
+	.clk_autogated	= 1,

This appears unrelated, and should be a separate patch.

Quoted 35 lines
arch/arm/mach-omap2/usb-musb.c +20 -1
 };
 
 static u64 musb_dmamask = DMA_BIT_MASK(32);
@@ -97,7 +101,7 @@ void __init usb_musb_init(struct omap_musb_board_data *board_data)
 	musb_plat.mode = board_data->mode;
 	musb_plat.extvbus = board_data->extvbus;
 	pdata = &musb_plat;
-
+	oh_p = oh;
 	od = omap_device_build(name, bus_id, oh, pdata,
 			       sizeof(struct musb_hdrc_platform_data),
 						omap_musb_latency,
@@ -116,8 +120,44 @@ void __init usb_musb_init(struct omap_musb_board_data *board_data)
 
 }
 
+void musb_context_save_restore(int save)
+{
+	struct omap_hwmod *oh = oh_p;
+	struct omap_device *od;
+	struct platform_device *pdev;
+	struct device *dev;
+	struct device_driver *drv;
+	struct musb_hdrc_platform_data *pdata;
+	const struct dev_pm_ops *pm;
+
+	if (!oh)
+		return;
+	od = oh->od;
+	pdev = &od->pdev;
+	if (!pdev)
+		return;
+	dev = &pdev->dev;
+	drv = dev->driver;
+

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct omap_musb_board_data *board_data) · line 151

Quoted 10 lines
arch/arm/mach-omap2/usb-musb.c +10 -0
+	if (drv) {
+		pdata = dev->platform_data;
+		pm = drv->pm;
+
+		if (!pdata->is_usb_active(dev)) {
+
+			if (save)
+				pm->suspend(dev);
+			else
+				pm->resume_noirq(dev);

-ECONFUSED

First, this 'save_restore' function neither saves or restores anything.

Second, I'm thoroughly confused about why you are simulating a system suspend/resume here?

Kevin

Quoted 159 lines
arch/arm/mach-omap2/usb-musb.c +7 -0
+		}
+	}
+}
+
 #else
 void __init usb_musb_init(struct omap_musb_board_data *board_data)
 {
 }
+void musb_context_save_restore(int save)
+{
+}
 #endif /* CONFIG_USB_MUSB_SOC */
arch/arm/plat-omap/include/plat/usb.h +2 -0
index 2a9427c..ed2b41a 100644
@@ -79,6 +79,8 @@ extern void usb_ehci_init(const struct ehci_hcd_omap_platform_data *pdata);
 
 extern void usb_ohci_init(const struct ohci_hcd_omap_platform_data *pdata);
 
+/* For saving and restoring the musb context during off/wakeup*/
+extern void musb_context_save_restore(int save);
 #endif
 
 
drivers/usb/musb/musb_core.c +4 -6
index 2a50d12..8510e55 100644
@@ -2410,6 +2410,7 @@ static int musb_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	unsigned long	flags;
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
@@ -2428,9 +2429,7 @@ static int musb_suspend(struct device *dev)
 
 	musb_save_context(musb);
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 0);
-	else
+	if (!plat->clk_autogated)
 		clk_disable(musb->clock);
 	spin_unlock_irqrestore(&musb->lock, flags);
 	return 0;
@@ -2440,13 +2439,12 @@ static int musb_resume_noirq(struct device *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 1);
-	else
+	if (!plat->clk_autogated)
 		clk_enable(musb->clock);
 
 	musb_restore_context(musb);
drivers/usb/musb/musb_core.h +0 -1
index 85a92fd..bfdf54d 100644
@@ -472,7 +472,6 @@ struct musb_context_registers {
 
 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \
     defined(CONFIG_ARCH_OMAP4)
-	u32 otg_sysconfig, otg_forcestandby;
 #endif
 	u8 power;
 	u16 intrtxe, intrrxe;
drivers/usb/musb/omap2430.c +44 -4
index 3bae428..dcba935 100644
@@ -188,6 +188,18 @@ int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
 
 	return 0;
 }
+int is_musb_active(struct device *dev)
+{
+	struct musb *musb;
+
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+	/* usbcore insists dev->driver_data is a "struct hcd *" */
+	musb = hcd_to_musb(dev_get_drvdata(dev));
+#else
+	musb = dev_get_drvdata(dev);
+#endif
+	return musb->is_active;
+}
 
 int __init musb_platform_init(struct musb *musb)
 {
@@ -246,6 +258,7 @@ int __init musb_platform_init(struct musb *musb)
 	if (is_host_enabled(musb))
 		musb->board_set_vbus = omap_set_vbus;
 
+	plat->is_usb_active = is_musb_active;
 	setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
 
 	return 0;
@@ -255,15 +268,42 @@ int __init musb_platform_init(struct musb *musb)
 void musb_platform_save_context(struct musb *musb,
 		struct musb_context_registers *musb_context)
 {
-	musb_context->otg_sysconfig = musb_readl(musb->mregs, OTG_SYSCONFIG);
-	musb_context->otg_forcestandby = musb_readl(musb->mregs, OTG_FORCESTDBY);
+	/*
+	 * As per the omap-usbotg specification, configure it to forced standby
+	 * and  force idle mode when no activity on usb.
+	 */
+	void __iomem *musb_base = musb->mregs;
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 0);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) & ~(NOSTDBY | SMARTSTDBY));
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+					OTG_SYSCONFIG) & ~AUTOIDLE);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) & ~(NOIDLE | SMARTIDLE));
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 1);
 }
 
 void musb_platform_restore_context(struct musb *musb,
 		struct musb_context_registers *musb_context)
 {
-	musb_writel(musb->mregs, OTG_SYSCONFIG, musb_context->otg_sysconfig);
-	musb_writel(musb->mregs, OTG_FORCESTDBY, musb_context->otg_forcestandby);
+	/*
+	 * As per the omap-usbotg specification, configure it smart standby
+	 * and smart idle during operation.
+	 */
+	void __iomem *musb_base = musb->mregs;
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 0);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) | SMARTSTDBY);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) | SMARTIDLE | ENABLEWAKEUP);
 }
 #endif
 
include/linux/usb/musb.h +0 -0
index ee2dd1d..da134ab 100644

include/linux/usb/musb.h struct musb_hdrc_platform_data { · line 135

Quoted 10 lines
include/linux/usb/musb.h +6 -0
@@ -126,6 +126,12 @@ struct musb_hdrc_platform_data {
 
 	/* Architecture specific board data	*/
 	void		*board_data;
+
+	/* check usb device active state*/
+	int		(*is_usb_active)(struct device *dev);
+
+	/*  indiates whether clock is autogated */
+	int		clk_autogated;
 };

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

#3 lore raw
Quoted 28 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, August 26, 2010 5:40 AM
To: Kalliguddi, Hema
Cc: [email protected]; [email protected]; Mankad, Maulik Ojas; Felipe Balbi; Tony Lindgren; Cousson, Benoit; Paul Walmsley
Subject: Re: [PATCH 6/8 v2] usb: musb: Offmode fix for idle path

Quoted 1 line · Hema HK

With OMAP core-off support musb was not functional as

context was getting

Quoted 1 line

lost after wakeup from core-off. And also musb was blocking

the core-off

Quoted 1 line

after loading the gadget driver even with no cable connected

sometimes.

Quoted 6 lines

Added the conext save/restore api in the platform layer which will be called in the idle and wakeup path.

Changed the usb sysconfig settings as per the usbotg functional spec. When the device is not used, configure to force idle and

force standby mode.

Quoted 1 line

When it is being used, configure in smart standby and smart

idle mode.

Quoted 9 lines
Quoted 1 line

So while attempting to coreoff the usb is configured to

force standby and

Quoted 1 line

force idle mode, after wakeup configured in smart idle and

smart standby.

You don't describe the new .clk_autogated field added here. That part should be a separate patch as it's not directly related to $SUBJECT patch.

In OMAP for USB there is no need to disable the interface clock. But for the other platforms like davinci which uses mentor USB IP clock is not auto gated so There is a need to disbale the clock when .suspend API defined in the driver is called. So introduced a flag in the platform to enable/disable the clock
In .supend and .resume APIs appropriately in the driver code.

Yes. It may not be directly related to $SUBJECT patch, but I am reusing .suspend and .resume APIs for context save and restore during idle path. Because of that this fix as part of the patch.

Quoted 124 lines
Quoted 11 lines
Cc Felipe Balbi <[email protected]>
Cc Tony Lindgren <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Cousson, Benoit <[email protected]>
Cc Paul Walmsley <[email protected]>
---
 arch/arm/mach-omap2/pm34xx.c          |    5 +++
 arch/arm/mach-omap2/usb-musb.c        |   42 

++++++++++++++++++++++++++++-

Quoted 4 lines
 arch/arm/plat-omap/include/plat/usb.h |    2 +
 drivers/usb/musb/musb_core.c          |   10 +++----
 drivers/usb/musb/musb_core.h          |    1 -
 drivers/usb/musb/omap2430.c           |   48 

++++++++++++++++++++++++++++++---

Review

Quoted 4 lines
 include/linux/usb/musb.h              |    6 ++++
 7 files changed, 102 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-omap2/pm34xx.c

Review

Quoted 30 lines

index fb4994a..7b34201 100644

arch/arm/mach-omap2/pm34xx.c +5 -0
@@ -39,6 +39,7 @@
 #include <plat/gpmc.h>
 #include <plat/dma.h>
 #include <plat/dmtimer.h>
+#include <plat/usb.h>
 
 #include <asm/tlbflush.h>
 
@@ -416,6 +417,8 @@ void omap_sram_idle(void)
 		if (core_next_state == PWRDM_POWER_OFF) {
 			omap3_core_save_context();
 			omap3_prcm_save_context();
+			/* Save MUSB context */
+			musb_context_save_restore(1);
 		}
 	}
 
@@ -458,6 +461,8 @@ void omap_sram_idle(void)
 			omap3_prcm_restore_context();
 			omap3_sram_restore_context();
 			omap2_sms_restore_context();
+			/* restore MUSB context */
+			musb_context_save_restore(0);
 		}
 		omap_uart_resume_idle(0);
 		omap_uart_resume_idle(1);
(quoted diff) +0 -0

b/arch/arm/mach-omap2/usb-musb.c

Quoted 12 lines

index c228cc0..9d10440 100644

arch/arm/mach-omap2/usb-musb.c +1 -0
@@ -35,6 +35,7 @@
 
 static const char name[] = "musb_hdrc";
 #define MAX_OMAP_MUSB_HWMOD_NAME_LEN	16
+struct omap_hwmod *oh_p =NULL;
 
 static struct musb_hdrc_config musb_config = {
 	.multipoint	= 1,

arch/arm/mach-omap2/usb-musb.c static struct musb_hdrc_platform_data musb_plat = { · line 65

Quoted 6 lines
arch/arm/mach-omap2/usb-musb.c +3 -0
@@ -59,6 +60,9 @@ static struct musb_hdrc_platform_data musb_plat = {
 	 * "mode", and should be passed to usb_musb_init().
 	 */
 	.power		= 50,			/* up to 100 mA */
+
+	/* supports clock autogating */
+	.clk_autogated	= 1,

This appears unrelated, and should be a separate patch.

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct

Quoted 4 lines
arch/arm/mach-omap2/usb-musb.c +0 -0
 };
 
 static u64 musb_dmamask = DMA_BIT_MASK(32);
@@ -97,7 +101,7 @@ void __init usb_musb_init(struct 

omap_musb_board_data *board_data)

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct

Quoted 9 lines
arch/arm/mach-omap2/usb-musb.c +1 -1
 	musb_plat.mode = board_data->mode;
 	musb_plat.extvbus = board_data->extvbus;
 	pdata = &musb_plat;
-
+	oh_p = oh;
 	od = omap_device_build(name, bus_id, oh, pdata,
 			       sizeof(struct musb_hdrc_platform_data),
 						omap_musb_latency,
@@ -116,8 +120,44 @@ void __init usb_musb_init(struct 

omap_musb_board_data *board_data)

Quoted 22 lines
arch/arm/mach-omap2/usb-musb.c +19 -0
 }
 
+void musb_context_save_restore(int save)
+{
+	struct omap_hwmod *oh = oh_p;
+	struct omap_device *od;
+	struct platform_device *pdev;
+	struct device *dev;
+	struct device_driver *drv;
+	struct musb_hdrc_platform_data *pdata;
+	const struct dev_pm_ops *pm;
+
+	if (!oh)
+		return;
+	od = oh->od;
+	pdev = &od->pdev;
+	if (!pdev)
+		return;
+	dev = &pdev->dev;
+	drv = dev->driver;
+

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct omap_musb_board_data *board_data) · line 151

Quoted 10 lines
arch/arm/mach-omap2/usb-musb.c +10 -0
+	if (drv) {
+		pdata = dev->platform_data;
+		pm = drv->pm;
+
+		if (!pdata->is_usb_active(dev)) {
+
+			if (save)
+				pm->suspend(dev);
+			else
+				pm->resume_noirq(dev);

-ECONFUSED

Quoted 2 lines

First, this 'save_restore' function neither saves or restores anything.

There are musb_save/restore APIs defined in the driver code and called in a system suspend/resume APIs. I am just making use of these apis in the idle path aswell.

Quoted 2 lines

Second, I'm thoroughly confused about why you are simulating a system suspend/resume here?

As said, instead of exporting the internal save/restore APIs, I am making use of the pm_ops function pointers To do the same job.

Quoted 191 lines

Kevin

Review

Quoted 13 lines
arch/arm/mach-omap2/usb-musb.c +7 -0
+		}
+	}
+}
+
 #else
 void __init usb_musb_init(struct omap_musb_board_data *board_data)
 {
 }
+void musb_context_save_restore(int save)
+{
+}
 #endif /* CONFIG_USB_MUSB_SOC */
(quoted diff) +0 -0

b/arch/arm/plat-omap/include/plat/usb.h

arch/arm/plat-omap/include/plat/usb.h extern void usb_ehci_init(const struct

Quoted 4 lines

index 2a9427c..ed2b41a 100644

arch/arm/plat-omap/include/plat/usb.h +0 -0
@@ -79,6 +79,8 @@ extern void usb_ehci_init(const struct 

ehci_hcd_omap_platform_data *pdata);

arch/arm/plat-omap/include/plat/usb.h extern void usb_ehci_init(const struct · line 79

Quoted 2 lines
arch/arm/plat-omap/include/plat/usb.h +0 -0
 extern void usb_ohci_init(const struct 

ohci_hcd_omap_platform_data *pdata);

Review

Quoted 7 lines
arch/arm/plat-omap/include/plat/usb.h +2 -0
+/* For saving and restoring the musb context during off/wakeup*/
+extern void musb_context_save_restore(int save);
 #endif
 
 
(quoted diff) +0 -0

b/drivers/usb/musb/musb_core.c

drivers/usb/musb/musb_core.c static int musb_resume_noirq(struct

Quoted 23 lines

index 2a50d12..8510e55 100644

drivers/usb/musb/musb_core.c +2 -3
@@ -2410,6 +2410,7 @@ static int musb_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	unsigned long	flags;
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
@@ -2428,9 +2429,7 @@ static int musb_suspend(struct device *dev)
 
 	musb_save_context(musb);
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 0);
-	else
+	if (!plat->clk_autogated)
 		clk_disable(musb->clock);
 	spin_unlock_irqrestore(&musb->lock, flags);
 	return 0;
@@ -2440,13 +2439,12 @@ static int musb_resume_noirq(struct 

device *dev)

Review

Quoted 16 lines
drivers/usb/musb/musb_core.c +2 -3
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 1);
-	else
+	if (!plat->clk_autogated)
 		clk_enable(musb->clock);
 
 	musb_restore_context(musb);
(quoted diff) +0 -0

b/drivers/usb/musb/musb_core.h

Review

Quoted 12 lines

index 85a92fd..bfdf54d 100644

drivers/usb/musb/musb_core.h +0 -1
@@ -472,7 +472,6 @@ struct musb_context_registers {
 
 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \
     defined(CONFIG_ARCH_OMAP4)
-	u32 otg_sysconfig, otg_forcestandby;
 #endif
 	u8 power;
 	u16 intrtxe, intrrxe;
(quoted diff) +0 -0

b/drivers/usb/musb/omap2430.c

drivers/usb/musb/omap2430.c int musb_platform_set_mode(struct musb

Quoted 4 lines

index 3bae428..dcba935 100644

drivers/usb/musb/omap2430.c +0 -0
@@ -188,6 +188,18 @@ int musb_platform_set_mode(struct musb 

*musb, u8 musb_mode)

Quoted 19 lines
drivers/usb/musb/omap2430.c +12 -0
 	return 0;
 }
+int is_musb_active(struct device *dev)
+{
+	struct musb *musb;
+
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+	/* usbcore insists dev->driver_data is a "struct hcd *" */
+	musb = hcd_to_musb(dev_get_drvdata(dev));
+#else
+	musb = dev_get_drvdata(dev);
+#endif
+	return musb->is_active;
+}
 
 int __init musb_platform_init(struct musb *musb)
 {

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb) · line 262

Quoted 5 lines
drivers/usb/musb/omap2430.c +1 -0
@@ -246,6 +258,7 @@ int __init musb_platform_init(struct musb *musb)
 	if (is_host_enabled(musb))
 		musb->board_set_vbus = omap_set_vbus;
 
+	plat->is_usb_active = is_musb_active;
 	setup_timer(&musb_idle_timer, musb_do_idle, (unsigned 

long) musb);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct

Quoted 3 lines
drivers/usb/musb/omap2430.c +0 -0
 	return 0;
@@ -255,15 +268,42 @@ int __init musb_platform_init(struct 

musb *musb)

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 4 lines
drivers/usb/musb/omap2430.c +0 -1
 void musb_platform_save_context(struct musb *musb,
 		struct musb_context_registers *musb_context)
 {
-	musb_context->otg_sysconfig = musb_readl(musb->mregs, 

OTG_SYSCONFIG);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 259

Quoted 1 line
drivers/usb/musb/omap2430.c +0 -1
-	musb_context->otg_forcestandby = 

musb_readl(musb->mregs, OTG_FORCESTDBY);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 272

Quoted 2 lines
drivers/usb/musb/omap2430.c +2 -0
+	/*
+	 * As per the omap-usbotg specification, configure it 

to forced standby

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 8 lines
drivers/usb/musb/omap2430.c +8 -0
+	 * and  force idle mode when no activity on usb.
+	 */
+	void __iomem *musb_base = musb->mregs;
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 0);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) & ~(NOSTDBY | 

SMARTSTDBY));

Quoted 4 lines
drivers/usb/musb/omap2430.c +4 -0
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+					OTG_SYSCONFIG) & ~AUTOIDLE);
+

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 10 lines
drivers/usb/musb/omap2430.c +4 -1
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) & ~(NOIDLE | SMARTIDLE));
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 1);
 }
 
 void musb_platform_restore_context(struct musb *musb,
 		struct musb_context_registers *musb_context)
 {
-	musb_writel(musb->mregs, OTG_SYSCONFIG, 

musb_context->otg_sysconfig);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 266

Quoted 1 line
drivers/usb/musb/omap2430.c +0 -1
-	musb_writel(musb->mregs, OTG_FORCESTDBY, 

musb_context->otg_forcestandby);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 295

Quoted 2 lines
drivers/usb/musb/omap2430.c +2 -0
+	/*
+	 * As per the omap-usbotg specification, configure it 

smart standby

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 11 lines
drivers/usb/musb/omap2430.c +11 -0
+	 * and smart idle during operation.
+	 */
+	void __iomem *musb_base = musb->mregs;
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 0);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) | SMARTSTDBY);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) | SMARTIDLE | 

ENABLEWAKEUP);

Quoted 18 lines
drivers/usb/musb/omap2430.c +0 -0
 }
 #endif
 
include/linux/usb/musb.h +6 -0
index ee2dd1d..da134ab 100644
@@ -126,6 +126,12 @@ struct musb_hdrc_platform_data {
 
 	/* Architecture specific board data	*/
 	void		*board_data;
+
+	/* check usb device active state*/
+	int		(*is_usb_active)(struct device *dev);
+
+	/*  indiates whether clock is autogated */
+	int		clk_autogated;
 };
#4 lore raw
Quoted 36 lines · Hema
Quoted 26 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, August 26, 2010 5:40 AM
To: Kalliguddi, Hema
Cc: [email protected]; [email protected]; Mankad, Maulik Ojas; Felipe Balbi; Tony Lindgren; Cousson, Benoit; Paul Walmsley
Subject: Re: [PATCH 6/8 v2] usb: musb: Offmode fix for idle path

Quoted 1 line · Hema HK

With OMAP core-off support musb was not functional as

context was getting

Quoted 1 line

lost after wakeup from core-off. And also musb was blocking

the core-off

Quoted 1 line

after loading the gadget driver even with no cable connected

sometimes.

Quoted 6 lines

Added the conext save/restore api in the platform layer which will be called in the idle and wakeup path.

Changed the usb sysconfig settings as per the usbotg functional spec. When the device is not used, configure to force idle and

force standby mode.

Quoted 1 line

When it is being used, configure in smart standby and smart

idle mode.

Quoted 9 lines
Quoted 1 line

So while attempting to coreoff the usb is configured to

force standby and

Quoted 1 line

force idle mode, after wakeup configured in smart idle and

smart standby.

You don't describe the new .clk_autogated field added here. That part should be a separate patch as it's not directly related to $SUBJECT patch.

Quoted 5 lines

In OMAP for USB there is no need to disable the interface clock. But for the other platforms like davinci which uses mentor USB IP clock is not auto gated so There is a need to disbale the clock when .suspend API defined in the driver is called. So introduced a flag in the platform to enable/disable the clock
In .supend and .resume APIs appropriately in the driver code.

Yes, I understand why it's there, and just suggested that it should be documented and done as a separate patch.

Quoted 128 lines

Yes. It may not be directly related to $SUBJECT patch, but I am reusing .suspend and .resume APIs for context save and restore during idle path. Because of that this fix as part of the patch.

Quoted 124 lines
Quoted 11 lines
Cc Felipe Balbi <[email protected]>
Cc Tony Lindgren <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Cousson, Benoit <[email protected]>
Cc Paul Walmsley <[email protected]>
---
 arch/arm/mach-omap2/pm34xx.c          |    5 +++
 arch/arm/mach-omap2/usb-musb.c        |   42 

++++++++++++++++++++++++++++-

Quoted 4 lines
 arch/arm/plat-omap/include/plat/usb.h |    2 +
 drivers/usb/musb/musb_core.c          |   10 +++----
 drivers/usb/musb/musb_core.h          |    1 -
 drivers/usb/musb/omap2430.c           |   48 

++++++++++++++++++++++++++++++---

Review

Quoted 4 lines
 include/linux/usb/musb.h              |    6 ++++
 7 files changed, 102 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-omap2/pm34xx.c

Review

Quoted 30 lines

index fb4994a..7b34201 100644

arch/arm/mach-omap2/pm34xx.c +5 -0
@@ -39,6 +39,7 @@
 #include <plat/gpmc.h>
 #include <plat/dma.h>
 #include <plat/dmtimer.h>
+#include <plat/usb.h>
 
 #include <asm/tlbflush.h>
 
@@ -416,6 +417,8 @@ void omap_sram_idle(void)
 		if (core_next_state == PWRDM_POWER_OFF) {
 			omap3_core_save_context();
 			omap3_prcm_save_context();
+			/* Save MUSB context */
+			musb_context_save_restore(1);
 		}
 	}
 
@@ -458,6 +461,8 @@ void omap_sram_idle(void)
 			omap3_prcm_restore_context();
 			omap3_sram_restore_context();
 			omap2_sms_restore_context();
+			/* restore MUSB context */
+			musb_context_save_restore(0);
 		}
 		omap_uart_resume_idle(0);
 		omap_uart_resume_idle(1);
(quoted diff) +0 -0

b/arch/arm/mach-omap2/usb-musb.c

Quoted 12 lines

index c228cc0..9d10440 100644

arch/arm/mach-omap2/usb-musb.c +1 -0
@@ -35,6 +35,7 @@
 
 static const char name[] = "musb_hdrc";
 #define MAX_OMAP_MUSB_HWMOD_NAME_LEN	16
+struct omap_hwmod *oh_p =NULL;
 
 static struct musb_hdrc_config musb_config = {
 	.multipoint	= 1,

arch/arm/mach-omap2/usb-musb.c static struct musb_hdrc_platform_data musb_plat = { · line 65

Quoted 6 lines
arch/arm/mach-omap2/usb-musb.c +3 -0
@@ -59,6 +60,9 @@ static struct musb_hdrc_platform_data musb_plat = {
 	 * "mode", and should be passed to usb_musb_init().
 	 */
 	.power		= 50,			/* up to 100 mA */
+
+	/* supports clock autogating */
+	.clk_autogated	= 1,

This appears unrelated, and should be a separate patch.

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct

Quoted 4 lines
arch/arm/mach-omap2/usb-musb.c +0 -0
 };
 
 static u64 musb_dmamask = DMA_BIT_MASK(32);
@@ -97,7 +101,7 @@ void __init usb_musb_init(struct 

omap_musb_board_data *board_data)

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct

Quoted 9 lines
arch/arm/mach-omap2/usb-musb.c +1 -1
 	musb_plat.mode = board_data->mode;
 	musb_plat.extvbus = board_data->extvbus;
 	pdata = &musb_plat;
-
+	oh_p = oh;
 	od = omap_device_build(name, bus_id, oh, pdata,
 			       sizeof(struct musb_hdrc_platform_data),
 						omap_musb_latency,
@@ -116,8 +120,44 @@ void __init usb_musb_init(struct 

omap_musb_board_data *board_data)

Quoted 22 lines
arch/arm/mach-omap2/usb-musb.c +19 -0
 }
 
+void musb_context_save_restore(int save)
+{
+	struct omap_hwmod *oh = oh_p;
+	struct omap_device *od;
+	struct platform_device *pdev;
+	struct device *dev;
+	struct device_driver *drv;
+	struct musb_hdrc_platform_data *pdata;
+	const struct dev_pm_ops *pm;
+
+	if (!oh)
+		return;
+	od = oh->od;
+	pdev = &od->pdev;
+	if (!pdev)
+		return;
+	dev = &pdev->dev;
+	drv = dev->driver;
+

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct omap_musb_board_data *board_data) · line 151

Quoted 10 lines
arch/arm/mach-omap2/usb-musb.c +10 -0
+	if (drv) {
+		pdata = dev->platform_data;
+		pm = drv->pm;
+
+		if (!pdata->is_usb_active(dev)) {
+
+			if (save)
+				pm->suspend(dev);
+			else
+				pm->resume_noirq(dev);

-ECONFUSED

Quoted 5 lines
Quoted 2 lines

First, this 'save_restore' function neither saves or restores anything.

There are musb_save/restore APIs defined in the driver code and called in a system suspend/resume APIs. I am just making use of these apis in the idle path aswell.

Please don't. This is not and intended use of the driver model hooks.

Instead, we need to move the musb idle management out of the interrupts-disabled section of the idle loop and use the runtime PM APIs as intended.

Kevin

Quoted 197 lines
Quoted 2 lines

Second, I'm thoroughly confused about why you are simulating a system suspend/resume here?

As said, instead of exporting the internal save/restore APIs, I am making use of the pm_ops function pointers To do the same job.

Quoted 191 lines

Kevin

Review

Quoted 13 lines
arch/arm/mach-omap2/usb-musb.c +7 -0
+		}
+	}
+}
+
 #else
 void __init usb_musb_init(struct omap_musb_board_data *board_data)
 {
 }
+void musb_context_save_restore(int save)
+{
+}
 #endif /* CONFIG_USB_MUSB_SOC */
(quoted diff) +0 -0

b/arch/arm/plat-omap/include/plat/usb.h

arch/arm/plat-omap/include/plat/usb.h extern void usb_ehci_init(const struct

Quoted 4 lines

index 2a9427c..ed2b41a 100644

arch/arm/plat-omap/include/plat/usb.h +0 -0
@@ -79,6 +79,8 @@ extern void usb_ehci_init(const struct 

ehci_hcd_omap_platform_data *pdata);

arch/arm/plat-omap/include/plat/usb.h extern void usb_ehci_init(const struct · line 79

Quoted 2 lines
arch/arm/plat-omap/include/plat/usb.h +0 -0
 extern void usb_ohci_init(const struct 

ohci_hcd_omap_platform_data *pdata);

Review

Quoted 7 lines
arch/arm/plat-omap/include/plat/usb.h +2 -0
+/* For saving and restoring the musb context during off/wakeup*/
+extern void musb_context_save_restore(int save);
 #endif
 
 
(quoted diff) +0 -0

b/drivers/usb/musb/musb_core.c

drivers/usb/musb/musb_core.c static int musb_resume_noirq(struct

Quoted 23 lines

index 2a50d12..8510e55 100644

drivers/usb/musb/musb_core.c +2 -3
@@ -2410,6 +2410,7 @@ static int musb_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	unsigned long	flags;
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
@@ -2428,9 +2429,7 @@ static int musb_suspend(struct device *dev)
 
 	musb_save_context(musb);
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 0);
-	else
+	if (!plat->clk_autogated)
 		clk_disable(musb->clock);
 	spin_unlock_irqrestore(&musb->lock, flags);
 	return 0;
@@ -2440,13 +2439,12 @@ static int musb_resume_noirq(struct 

device *dev)

Review

Quoted 16 lines
drivers/usb/musb/musb_core.c +2 -3
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 1);
-	else
+	if (!plat->clk_autogated)
 		clk_enable(musb->clock);
 
 	musb_restore_context(musb);
(quoted diff) +0 -0

b/drivers/usb/musb/musb_core.h

Review

Quoted 12 lines

index 85a92fd..bfdf54d 100644

drivers/usb/musb/musb_core.h +0 -1
@@ -472,7 +472,6 @@ struct musb_context_registers {
 
 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \
     defined(CONFIG_ARCH_OMAP4)
-	u32 otg_sysconfig, otg_forcestandby;
 #endif
 	u8 power;
 	u16 intrtxe, intrrxe;
(quoted diff) +0 -0

b/drivers/usb/musb/omap2430.c

drivers/usb/musb/omap2430.c int musb_platform_set_mode(struct musb

Quoted 4 lines

index 3bae428..dcba935 100644

drivers/usb/musb/omap2430.c +0 -0
@@ -188,6 +188,18 @@ int musb_platform_set_mode(struct musb 

*musb, u8 musb_mode)

Quoted 19 lines
drivers/usb/musb/omap2430.c +12 -0
 	return 0;
 }
+int is_musb_active(struct device *dev)
+{
+	struct musb *musb;
+
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+	/* usbcore insists dev->driver_data is a "struct hcd *" */
+	musb = hcd_to_musb(dev_get_drvdata(dev));
+#else
+	musb = dev_get_drvdata(dev);
+#endif
+	return musb->is_active;
+}
 
 int __init musb_platform_init(struct musb *musb)
 {

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb) · line 262

Quoted 5 lines
drivers/usb/musb/omap2430.c +1 -0
@@ -246,6 +258,7 @@ int __init musb_platform_init(struct musb *musb)
 	if (is_host_enabled(musb))
 		musb->board_set_vbus = omap_set_vbus;
 
+	plat->is_usb_active = is_musb_active;
 	setup_timer(&musb_idle_timer, musb_do_idle, (unsigned 

long) musb);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct

Quoted 3 lines
drivers/usb/musb/omap2430.c +0 -0
 	return 0;
@@ -255,15 +268,42 @@ int __init musb_platform_init(struct 

musb *musb)

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 4 lines
drivers/usb/musb/omap2430.c +0 -1
 void musb_platform_save_context(struct musb *musb,
 		struct musb_context_registers *musb_context)
 {
-	musb_context->otg_sysconfig = musb_readl(musb->mregs, 

OTG_SYSCONFIG);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 259

Quoted 1 line
drivers/usb/musb/omap2430.c +0 -1
-	musb_context->otg_forcestandby = 

musb_readl(musb->mregs, OTG_FORCESTDBY);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 272

Quoted 2 lines
drivers/usb/musb/omap2430.c +2 -0
+	/*
+	 * As per the omap-usbotg specification, configure it 

to forced standby

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 8 lines
drivers/usb/musb/omap2430.c +8 -0
+	 * and  force idle mode when no activity on usb.
+	 */
+	void __iomem *musb_base = musb->mregs;
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 0);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) & ~(NOSTDBY | 

SMARTSTDBY));

Quoted 4 lines
drivers/usb/musb/omap2430.c +4 -0
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+					OTG_SYSCONFIG) & ~AUTOIDLE);
+

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 10 lines
drivers/usb/musb/omap2430.c +4 -1
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) & ~(NOIDLE | SMARTIDLE));
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 1);
 }
 
 void musb_platform_restore_context(struct musb *musb,
 		struct musb_context_registers *musb_context)
 {
-	musb_writel(musb->mregs, OTG_SYSCONFIG, 

musb_context->otg_sysconfig);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 266

Quoted 1 line
drivers/usb/musb/omap2430.c +0 -1
-	musb_writel(musb->mregs, OTG_FORCESTDBY, 

musb_context->otg_forcestandby);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 295

Quoted 2 lines
drivers/usb/musb/omap2430.c +2 -0
+	/*
+	 * As per the omap-usbotg specification, configure it 

smart standby

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 11 lines
drivers/usb/musb/omap2430.c +11 -0
+	 * and smart idle during operation.
+	 */
+	void __iomem *musb_base = musb->mregs;
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 0);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) | SMARTSTDBY);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) | SMARTIDLE | 

ENABLEWAKEUP);

Quoted 18 lines
drivers/usb/musb/omap2430.c +0 -0
 }
 #endif
 
include/linux/usb/musb.h +6 -0
index ee2dd1d..da134ab 100644
@@ -126,6 +126,12 @@ struct musb_hdrc_platform_data {
 
 	/* Architecture specific board data	*/
 	void		*board_data;
+
+	/* check usb device active state*/
+	int		(*is_usb_active)(struct device *dev);
+
+	/*  indiates whether clock is autogated */
+	int		clk_autogated;
 };
#5 lore raw

Hi,

Quoted 193 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Tuesday, August 31, 2010 8:49 PM
To: Kalliguddi, Hema
Cc: [email protected]; [email protected]; Mankad, Maulik Ojas; Felipe Balbi; Tony Lindgren; Cousson, Benoit; Paul Walmsley
Subject: Re: [PATCH 6/8 v2] usb: musb: Offmode fix for idle path

Quoted 14 lines · Hema
Quoted 14 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, August 26, 2010 5:40 AM
To: Kalliguddi, Hema
Cc: [email protected]; [email protected]; Mankad, Maulik Ojas; Felipe Balbi; Tony Lindgren; Cousson, Benoit; Paul Walmsley
Subject: Re: [PATCH 6/8 v2] usb: musb: Offmode fix for idle path

Quoted 1 line · Hema HK

With OMAP core-off support musb was not functional as

context was getting

Quoted 1 line

lost after wakeup from core-off. And also musb was blocking

Quoted 8 lines
Quoted 8 lines

the core-off

Quoted 1 line

after loading the gadget driver even with no cable connected

sometimes.

Quoted 5 lines

Added the conext save/restore api in the platform layer which will be called in the idle and wakeup path.

Changed the usb sysconfig settings as per the usbotg

functional spec.

Quoted 10 lines
Quoted 10 lines
Quoted 1 line

When the device is not used, configure to force idle and

force standby mode.

Quoted 1 line

When it is being used, configure in smart standby and smart

idle mode.

Quoted 1 line

So while attempting to coreoff the usb is configured to

force standby and

Quoted 1 line

force idle mode, after wakeup configured in smart idle and

smart standby.

You don't describe the new .clk_autogated field added here.

That part

Quoted 5 lines
Quoted 3 lines

should be a separate patch as it's not directly related to $SUBJECT patch.

In OMAP for USB there is no need to disable the interface

clock. But for the other

Quoted 1 line

platforms like davinci which uses mentor USB IP clock is not

auto gated so

Quoted 1 line

There is a need to disbale the clock when .suspend API

defined in the driver is called.

Quoted 2 lines

So introduced a flag in the platform to enable/disable the clock In .supend and .resume APIs appropriately in the driver code.

Yes, I understand why it's there, and just suggested that it should be documented and done as a separate patch.

Quoted 1 line

Yes. It may not be directly related to $SUBJECT patch, but I

am reusing

Quoted 1 line

.suspend and .resume APIs for context save and restore

during idle path.

Quoted 60 lines

Because of that this fix as part of the patch.

Quoted 58 lines
Quoted 11 lines
Cc Felipe Balbi <[email protected]>
Cc Tony Lindgren <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Cousson, Benoit <[email protected]>
Cc Paul Walmsley <[email protected]>
---
 arch/arm/mach-omap2/pm34xx.c          |    5 +++
 arch/arm/mach-omap2/usb-musb.c        |   42 

++++++++++++++++++++++++++++-

Quoted 4 lines
 arch/arm/plat-omap/include/plat/usb.h |    2 +
 drivers/usb/musb/musb_core.c          |   10 +++----
 drivers/usb/musb/musb_core.h          |    1 -
 drivers/usb/musb/omap2430.c           |   48 

++++++++++++++++++++++++++++++---

Review

Quoted 4 lines
 include/linux/usb/musb.h              |    6 ++++
 7 files changed, 102 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-omap2/pm34xx.c

Review

Quoted 30 lines

index fb4994a..7b34201 100644

arch/arm/mach-omap2/pm34xx.c +5 -0
@@ -39,6 +39,7 @@
 #include <plat/gpmc.h>
 #include <plat/dma.h>
 #include <plat/dmtimer.h>
+#include <plat/usb.h>
 
 #include <asm/tlbflush.h>
 
@@ -416,6 +417,8 @@ void omap_sram_idle(void)
 		if (core_next_state == PWRDM_POWER_OFF) {
 			omap3_core_save_context();
 			omap3_prcm_save_context();
+			/* Save MUSB context */
+			musb_context_save_restore(1);
 		}
 	}
 
@@ -458,6 +461,8 @@ void omap_sram_idle(void)
 			omap3_prcm_restore_context();
 			omap3_sram_restore_context();
 			omap2_sms_restore_context();
+			/* restore MUSB context */
+			musb_context_save_restore(0);
 		}
 		omap_uart_resume_idle(0);
 		omap_uart_resume_idle(1);
(quoted diff) +0 -0

b/arch/arm/mach-omap2/usb-musb.c

Quoted 5 lines

index c228cc0..9d10440 100644

arch/arm/mach-omap2/usb-musb.c +0 -0
@@ -35,6 +35,7 @@
 
Quoted 7 lines
Quoted 7 lines

arch/arm/mach-omap2/usb-musb.c static struct musb_hdrc_platform_data

Quoted 7 lines
arch/arm/mach-omap2/usb-musb.c +1 -0
 static const char name[] = "musb_hdrc";
 #define MAX_OMAP_MUSB_HWMOD_NAME_LEN	16
+struct omap_hwmod *oh_p =NULL;
 
 static struct musb_hdrc_config musb_config = {
 	.multipoint	= 1,
@@ -59,6 +60,9 @@ static struct musb_hdrc_platform_data 

musb_plat = {

Quoted 59 lines
Quoted 59 lines

arch/arm/mach-omap2/usb-musb.c static struct musb_hdrc_platform_data musb_plat = { · line 65

Quoted 6 lines
arch/arm/mach-omap2/usb-musb.c +3 -0
 	 * "mode", and should be passed to usb_musb_init().
 	 */
 	.power		= 50,			/* up to 100 mA */
+
+	/* supports clock autogating */
+	.clk_autogated	= 1,

This appears unrelated, and should be a separate patch.

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct

Quoted 4 lines
arch/arm/mach-omap2/usb-musb.c +0 -0
 };
 
 static u64 musb_dmamask = DMA_BIT_MASK(32);
@@ -97,7 +101,7 @@ void __init usb_musb_init(struct 

omap_musb_board_data *board_data)

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct

Quoted 9 lines
arch/arm/mach-omap2/usb-musb.c +1 -1
 	musb_plat.mode = board_data->mode;
 	musb_plat.extvbus = board_data->extvbus;
 	pdata = &musb_plat;
-
+	oh_p = oh;
 	od = omap_device_build(name, bus_id, oh, pdata,
 			       sizeof(struct musb_hdrc_platform_data),
 						omap_musb_latency,
@@ -116,8 +120,44 @@ void __init usb_musb_init(struct 

omap_musb_board_data *board_data)

Quoted 22 lines
arch/arm/mach-omap2/usb-musb.c +19 -0
 }
 
+void musb_context_save_restore(int save)
+{
+	struct omap_hwmod *oh = oh_p;
+	struct omap_device *od;
+	struct platform_device *pdev;
+	struct device *dev;
+	struct device_driver *drv;
+	struct musb_hdrc_platform_data *pdata;
+	const struct dev_pm_ops *pm;
+
+	if (!oh)
+		return;
+	od = oh->od;
+	pdev = &od->pdev;
+	if (!pdev)
+		return;
+	dev = &pdev->dev;
+	drv = dev->driver;
+

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct omap_musb_board_data *board_data) · line 151

Quoted 10 lines
arch/arm/mach-omap2/usb-musb.c +10 -0
+	if (drv) {
+		pdata = dev->platform_data;
+		pm = drv->pm;
+
+		if (!pdata->is_usb_active(dev)) {
+
+			if (save)
+				pm->suspend(dev);
+			else
+				pm->resume_noirq(dev);

-ECONFUSED

Quoted 1 line
Quoted 1 line

First, this 'save_restore' function neither saves or

Quoted 9 lines

restores anything.

Quoted 3 lines
Quoted 1 line

There are musb_save/restore APIs defined in the driver code

and called in a system suspend/resume APIs.

Quoted 1 line

I am just making use of these apis in the idle path aswell.

Please don't. This is not and intended use of the driver model hooks.

I am using this hooks because the save/restore API is not a exported API
And it needs a musb structure parameter which will not be available in the platform layer. Once I move o runtime PM api usage and use the runtime suspend/resume APIs need not use these hooks. But for this patch we will have live with these hooks.

Quoted 4 lines

Instead, we need to move the musb idle management out of the interrupts-disabled section of the idle loop and use the runtime PM APIs
as intended.

As part of the runtime PM patch I will take care of this.

Quoted 204 lines

Kevin

Quoted 4 lines
Quoted 2 lines

Second, I'm thoroughly confused about why you are simulating a system suspend/resume here?

As said, instead of exporting the internal save/restore

APIs, I am making use of the pm_ops function pointers

Quoted 76 lines

To do the same job.

Quoted 74 lines

Kevin

Review

Quoted 13 lines
arch/arm/mach-omap2/usb-musb.c +7 -0
+		}
+	}
+}
+
 #else
 void __init usb_musb_init(struct omap_musb_board_data *board_data)
 {
 }
+void musb_context_save_restore(int save)
+{
+}
 #endif /* CONFIG_USB_MUSB_SOC */
(quoted diff) +0 -0

b/arch/arm/plat-omap/include/plat/usb.h

arch/arm/plat-omap/include/plat/usb.h extern void usb_ehci_init(const struct

Quoted 4 lines

index 2a9427c..ed2b41a 100644

arch/arm/plat-omap/include/plat/usb.h +0 -0
@@ -79,6 +79,8 @@ extern void usb_ehci_init(const struct 

ehci_hcd_omap_platform_data *pdata);

arch/arm/plat-omap/include/plat/usb.h extern void usb_ehci_init(const struct · line 79

Quoted 2 lines
arch/arm/plat-omap/include/plat/usb.h +0 -0
 extern void usb_ohci_init(const struct 

ohci_hcd_omap_platform_data *pdata);

Review

Quoted 7 lines
arch/arm/plat-omap/include/plat/usb.h +2 -0
+/* For saving and restoring the musb context during off/wakeup*/
+extern void musb_context_save_restore(int save);
 #endif
 
 
(quoted diff) +0 -0

b/drivers/usb/musb/musb_core.c

drivers/usb/musb/musb_core.c static int musb_resume_noirq(struct

Quoted 23 lines

index 2a50d12..8510e55 100644

drivers/usb/musb/musb_core.c +2 -3
@@ -2410,6 +2410,7 @@ static int musb_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	unsigned long	flags;
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
@@ -2428,9 +2429,7 @@ static int musb_suspend(struct device *dev)
 
 	musb_save_context(musb);
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 0);
-	else
+	if (!plat->clk_autogated)
 		clk_disable(musb->clock);
 	spin_unlock_irqrestore(&musb->lock, flags);
 	return 0;
@@ -2440,13 +2439,12 @@ static int musb_resume_noirq(struct 

device *dev)

Review

Quoted 16 lines
drivers/usb/musb/musb_core.c +2 -3
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct musb	*musb = dev_to_musb(&pdev->dev);
+	struct musb_hdrc_platform_data *plat = dev->platform_data;
 
 	if (!musb->clock)
 		return 0;
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 1);
-	else
+	if (!plat->clk_autogated)
 		clk_enable(musb->clock);
 
 	musb_restore_context(musb);
(quoted diff) +0 -0

b/drivers/usb/musb/musb_core.h

Quoted 6 lines
Quoted 6 lines

drivers/usb/musb/musb_core.h struct musb_context_registers { · line 473

Quoted 6 lines

index 85a92fd..bfdf54d 100644

drivers/usb/musb/musb_core.h +0 -0
@@ -472,7 +472,6 @@ struct musb_context_registers {
 
 #if defined(CONFIG_ARCH_OMAP2430) || 

defined(CONFIG_ARCH_OMAP3) || \

Quoted 28 lines
Quoted 28 lines

Review

Quoted 6 lines
drivers/usb/musb/musb_core.h +0 -1
     defined(CONFIG_ARCH_OMAP4)
-	u32 otg_sysconfig, otg_forcestandby;
 #endif
 	u8 power;
 	u16 intrtxe, intrrxe;
(quoted diff) +0 -0

b/drivers/usb/musb/omap2430.c

drivers/usb/musb/omap2430.c int musb_platform_set_mode(struct musb

Quoted 4 lines

index 3bae428..dcba935 100644

drivers/usb/musb/omap2430.c +0 -0
@@ -188,6 +188,18 @@ int musb_platform_set_mode(struct musb 

*musb, u8 musb_mode)

Quoted 16 lines
drivers/usb/musb/omap2430.c +12 -0
 	return 0;
 }
+int is_musb_active(struct device *dev)
+{
+	struct musb *musb;
+
+#ifdef CONFIG_USB_MUSB_HDRC_HCD
+	/* usbcore insists dev->driver_data is a "struct hcd *" */
+	musb = hcd_to_musb(dev_get_drvdata(dev));
+#else
+	musb = dev_get_drvdata(dev);
+#endif
+	return musb->is_active;
+}
 
Quoted 3 lines
Quoted 3 lines

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct

Quoted 3 lines
drivers/usb/musb/omap2430.c +0 -0
 int __init musb_platform_init(struct musb *musb)
 {
@@ -246,6 +258,7 @@ int __init musb_platform_init(struct 

musb *musb)

Quoted 80 lines
Quoted 80 lines

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 5 lines
drivers/usb/musb/omap2430.c +1 -0
 	if (is_host_enabled(musb))
 		musb->board_set_vbus = omap_set_vbus;
 
+	plat->is_usb_active = is_musb_active;
 	setup_timer(&musb_idle_timer, musb_do_idle, (unsigned 

long) musb);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct

Quoted 3 lines
drivers/usb/musb/omap2430.c +0 -0
 	return 0;
@@ -255,15 +268,42 @@ int __init musb_platform_init(struct 

musb *musb)

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 4 lines
drivers/usb/musb/omap2430.c +0 -1
 void musb_platform_save_context(struct musb *musb,
 		struct musb_context_registers *musb_context)
 {
-	musb_context->otg_sysconfig = musb_readl(musb->mregs, 

OTG_SYSCONFIG);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 259

Quoted 1 line
drivers/usb/musb/omap2430.c +0 -1
-	musb_context->otg_forcestandby = 

musb_readl(musb->mregs, OTG_FORCESTDBY);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 272

Quoted 2 lines
drivers/usb/musb/omap2430.c +2 -0
+	/*
+	 * As per the omap-usbotg specification, configure it 

to forced standby

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 8 lines
drivers/usb/musb/omap2430.c +8 -0
+	 * and  force idle mode when no activity on usb.
+	 */
+	void __iomem *musb_base = musb->mregs;
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 0);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) & ~(NOSTDBY | 

SMARTSTDBY));

Quoted 4 lines
drivers/usb/musb/omap2430.c +4 -0
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+					OTG_SYSCONFIG) & ~AUTOIDLE);
+

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 10 lines
drivers/usb/musb/omap2430.c +4 -1
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) & ~(NOIDLE | SMARTIDLE));
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 1);
 }
 
 void musb_platform_restore_context(struct musb *musb,
 		struct musb_context_registers *musb_context)
 {
-	musb_writel(musb->mregs, OTG_SYSCONFIG, 

musb_context->otg_sysconfig);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 266

Quoted 1 line
drivers/usb/musb/omap2430.c +0 -1
-	musb_writel(musb->mregs, OTG_FORCESTDBY, 

musb_context->otg_forcestandby);

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct · line 295

Quoted 2 lines
drivers/usb/musb/omap2430.c +2 -0
+	/*
+	 * As per the omap-usbotg specification, configure it 

smart standby

drivers/usb/musb/omap2430.c int __init musb_platform_init(struct musb *musb)

Quoted 11 lines
drivers/usb/musb/omap2430.c +11 -0
+	 * and smart idle during operation.
+	 */
+	void __iomem *musb_base = musb->mregs;
+
+	musb_writel(musb_base, OTG_FORCESTDBY, 0);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) | SMARTSTDBY);
+
+	musb_writel(musb_base, OTG_SYSCONFIG, musb_readl(musb_base,
+				OTG_SYSCONFIG) | SMARTIDLE | 

ENABLEWAKEUP);

Quoted 18 lines
drivers/usb/musb/omap2430.c +0 -0
 }
 #endif
 
include/linux/usb/musb.h +6 -0
index ee2dd1d..da134ab 100644
@@ -126,6 +126,12 @@ struct musb_hdrc_platform_data {
 
 	/* Architecture specific board data	*/
 	void		*board_data;
+
+	/* check usb device active state*/
+	int		(*is_usb_active)(struct device *dev);
+
+	/*  indiates whether clock is autogated */
+	int		clk_autogated;
 };