[PATCH 0/1]: usb: musb: support for OFF mode

2010-01-22 Thread Arnaud Mandy
The following patch must be applied on top of the following patchset.
http://www.spinics.net/lists/linux-omap/msg24154.html
Depending on [PATCH 1/7] usb: musb: Add context save and restore support
Depending on [PATCH 2/7] usb: musb: get rid of omap_readl/writel


--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: musb: support for OFF-mode

2010-01-22 Thread Arnaud Mandy
using a wrapper between the transceiver driver and the controller
driver to signal the controller driver to turn on/off the controller
when VBUS event is detected.

based-on: Heikki Krogerus ext-heikki.kroge...@nokia.com
Signed-off-by: Arnaud Mandy ext-arnaud.2.ma...@nokia.com
---
 drivers/usb/musb/musb_core.c  |   30 +-
 drivers/usb/musb/musb_core.h  |   17 +-
 drivers/usb/musb/omap2430.c   |   66 -
 drivers/usb/otg/otg.c |   16 ++
 drivers/usb/otg/twl4030-usb.c |2 +
 include/linux/usb/otg.h   |   11 +++
 6 files changed, 137 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 2f59892..ab97a02 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -965,6 +965,8 @@ void musb_start(struct musb *musb)
}
musb_platform_enable(musb);
musb_writeb(regs, MUSB_DEVCTL, devctl);
+
+   musb_save_context(musb);
 }
 
 
@@ -1948,6 +1950,25 @@ static void musb_free(struct musb *musb)
 #endif
 }
 
+int musb_power_controller(struct otg_controller *controller, bool vbus)
+{
+   struct musb *musb = dev_to_musb(controller-dev);
+
+   if (!musb-off_mode_support)
+   return 0;
+
+   if (vbus)
+   musb_power_on_controller(musb);
+   else
+   musb_power_off_controller(musb);
+
+   return 0;
+}
+
+struct otg_controller musb_controller = {
+   .power_controller = musb_power_controller,
+};
+
 /*
  * Perform generic per-controller initialization.
  *
@@ -2044,6 +2065,9 @@ bad_config:
goto fail2;
}
 
+   musb_controller.dev = dev;
+   musb-xceiv-controller = musb_controller;
+
 #ifndef CONFIG_MUSB_PIO_ONLY
if (use_dma  dev-dma_mask) {
struct dma_controller   *c;
@@ -2313,7 +2337,8 @@ void musb_save_context(struct musb *musb)
 
musb_writeb(musb_base, MUSB_INDEX, musb_context.index);
 
-   musb_platform_save_context(musb, musb_context);
+   if (!musb-off_mode)
+   musb_platform_save_context(musb, musb_context);
 }
 
 void musb_restore_context(struct musb *musb)
@@ -2322,7 +2347,8 @@ void musb_restore_context(struct musb *musb)
void __iomem *musb_base = musb-mregs;
void __iomem *ep_target_regs;
 
-   musb_platform_restore_context(musb, musb_context);
+   if (!musb-off_mode)
+   musb_platform_restore_context(musb, musb_context);
 
if (is_host_enabled(musb)) {
musb_writew(musb_base, MUSB_FRAME, musb_context.frame);
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 1e3da4e..8105a47 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -448,6 +448,11 @@ struct musb {
struct usb_gadget   g;  /* the gadget */
struct usb_gadget_driver *gadget_driver;/* its driver */
 #endif
+   /* true if off-mode is supported */
+   unsignedoff_mode_support:1;
+
+   /* true if off-mode is requested */
+   unsignedoff_mode:1;
 
/* true if we're using dma */
unsigneduse_dma:1;
@@ -498,8 +503,16 @@ extern void musb_platform_restore_context(struct musb 
*musb,
 #define musb_platform_save_context(m, x)   do {} while (0)
 #define musb_platform_restore_context(m, x)do {} while (0)
 #endif
-
-#endif
+extern void musb_power_on_controller(struct musb *musb);
+extern void musb_power_off_controller(struct musb *musb);
+void musb_save_context(struct musb *musb);
+void musb_restore_context(struct musb *musb);
+#else
+static inline void musb_power_on_controller(struct musb *musb) {};
+static inline void musb_power_off_controller(struct musb *musb) {};
+static inline void musb_save_context(struct musb *musb) {};
+static inline void musb_restore_context(struct musb *musb) {};
+#endif /* CONFIG_PM */
 
 static inline void musb_set_vbus(struct musb *musb, int is_on)
 {
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 21cff53..3cc894b 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -220,6 +220,9 @@ int __init musb_platform_init(struct musb *musb)
 
musb_platform_resume(musb);
 
+#ifdef CONFIG_PM
+   musb-off_mode_support = 1;
+#endif
l = musb_readl(musb-mregs, OTG_SYSCONFIG);
l = ~ENABLEWAKEUP; /* disable wakeup */
l = ~NOSTDBY;  /* remove possible nostdby */
@@ -271,7 +274,68 @@ void musb_platform_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);
 }
-#endif
+
+void musb_power_off_controller(struct musb *musb)
+{
+   u32 l;
+
+   DBG(3, allow OFF-mode\n);
+
+   l = musb_readl(musb-mregs, OTG_FORCESTDBY);
+   l |= ENABLEFORCE

Re: [PATCH 2/3 v3] musb: Add context save and restore support

2009-12-17 Thread Arnaud Mandy

ext Gupta, Ajay Kumar wrote:

snip
  

 #ifdef CONFIG_PM

+static struct musb_context_registers musb_context;
+
+void musb_save_context(struct musb *musb)
+{

  

Could you add one more parameter to this function call, which would
select either if we want to save the musb_platform context or not?
I m working at the moment on turning off the musb when cable unplugged
and turning it on with restoring context after cable re-connect.
In this case I don't need to restore the the musb_platform_context since
I just set them before calling this one.

Same apply for restore.

what do you think?
I could also modify slightly this implementation after it is ready and
submit it.



I think you want to add the parameter in musb_platform_save_context()  and
not in musb_save_context.
If so then where do you restore them? {As you said before calling this}
  


In order to support off-mode, we need the transceiver driver to wake-up 
the controller.

I m working on a hook which would allow that.
I want to take advantage of your implementation for saving/restoring 
musb context, but saving the platform data is not necessary in my case.
Maybe it musb_platform_save/restore_context(), shouldn't be called from 
musb_save/restore_context();



I think if the requirement is generic and suits for all other platforms
Using musb then we can add it.
  


Yes it should.
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3 v3] musb: Add context save and restore support

2009-12-17 Thread Arnaud Mandy

ext Gupta, Ajay Kumar wrote:

-Original Message-
From: Arnaud Mandy [mailto:ext-arnaud.2.ma...@nokia.com]
Sent: Thursday, December 17, 2009 7:41 PM
To: Gupta, Ajay Kumar
Cc: linux-...@vger.kernel.org; linux-omap@vger.kernel.org; Balbi Felipe
(Nokia-D/Helsinki); davi...@pacbell.net; Gadiyar, Anand
Subject: Re: [PATCH 2/3 v3] musb: Add context save and restore support

ext Gupta, Ajay Kumar wrote:


snip

  

 #ifdef CONFIG_PM

+static struct musb_context_registers musb_context;
+
+void musb_save_context(struct musb *musb)
+{


  

Could you add one more parameter to this function call, which would
select either if we want to save the musb_platform context or not?
I m working at the moment on turning off the musb when cable unplugged
and turning it on with restoring context after cable re-connect.
In this case I don't need to restore the the musb_platform_context


since


I just set them before calling this one.

Same apply for restore.

what do you think?
I could also modify slightly this implementation after it is ready and
submit it.



I think you want to add the parameter in musb_platform_save_context()
  

and


not in musb_save_context.
If so then where do you restore them? {As you said before calling this}

  

In order to support off-mode, we need the transceiver driver to wake-up
the controller.
I m working on a hook which would allow that.
I want to take advantage of your implementation for saving/restoring
musb context, but saving the platform data is not necessary in my case.



Then how about having a platform specific flag within
musb_platform_save/restorae_context() implementation which wouldn't
save/restore when you don't need them.

  


I got your point, but how would this flag being passed into 
musb_save_context()?

As a new musb struct member?

  

Maybe it musb_platform_save/restore_context(), shouldn't be called from
musb_save/restore_context();



I think if the requirement is generic and suits for all other platforms
Using musb then we can add it.

  

Yes it should.



--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html