Re: [PATCH v4] usb: dwc3: use extcon fwrk to receive connect/disconnect

2013-06-20 Thread Kishon Vijay Abraham I

Hi,

On Monday 17 June 2013 09:39 AM, Chanwoo Choi wrote:

On 06/14/2013 10:10 PM, Kishon Vijay Abraham I wrote:

Modified dwc3-omap to receive connect and disconnect notification using
extcon framework. Also did the necessary cleanups required after
adapting to extcon framework.

Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
Acked-by: Felipe Balbi ba...@ti.com
---
This patch depends on
git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git commit:f7ae906

It should also be applied on top of
usb: dwc3: omap: improve error handling of dwc3_omap_probe patch which is
merged in Felipe's tree.

So I'm not sure on whose tree this patch should go in.

Changes from v3:
* did #include of of_extcon.h after Chanwoo resent the patch separating
extcon-class.c from of_extcon.c
Changes from v2:
* updated the Documentation with dwc3 dt binding information.
* used of_extcon_get_extcon_dev to get extcon device from device tree data.
Changes from v1:
* regulator enable/disable is now done here instead of palmas-usb as some users
of palmas-usb wont need regulator.

  Documentation/devicetree/bindings/usb/omap-usb.txt |5 +
  drivers/usb/dwc3/dwc3-omap.c   |  119 
  include/linux/usb/dwc3-omap.h  |   30 -
  3 files changed, 105 insertions(+), 49 deletions(-)
  delete mode 100644 include/linux/usb/dwc3-omap.h

diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt 
b/Documentation/devicetree/bindings/usb/omap-usb.txt
index d4769f3..f1c15f3 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -53,6 +53,11 @@ OMAP DWC3 GLUE
 It should be set to 1 for HW mode and 2 for SW mode.
   - ranges: the child address space are mapped 1:1 onto the parent address 
space

+Optional Properties:
+ - extcon : phandle for the extcon device omap dwc3 uses to detect
+   connect/disconnect events.
+ - vbus-supply : phandle to the regulator device tree node if needed.
+
  Sub-nodes:
  The dwc3 core should be added as subnode to omap dwc3 glue.
  - dwc3 :
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index f8f76e6..14c1f1b 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -43,13 +43,15 @@
  #include linux/spinlock.h
  #include linux/platform_device.h
  #include linux/platform_data/dwc3-omap.h
-#include linux/usb/dwc3-omap.h
  #include linux/pm_runtime.h
  #include linux/dma-mapping.h
  #include linux/ioport.h
  #include linux/io.h
  #include linux/of.h
  #include linux/of_platform.h
+#include linux/extcon.h
+#include linux/extcon/of_extcon.h
+#include linux/regulator/consumer.h

  #include linux/usb/otg.h

@@ -124,9 +126,21 @@ struct dwc3_omap {
u32 utmi_otg_status;

u32 dma_status:1;
+
+   struct extcon_specific_cable_nb extcon_vbus_dev;
+   struct extcon_specific_cable_nb extcon_id_dev;
+   struct notifier_block   vbus_nb;
+   struct notifier_block   id_nb;
+
+   struct regulator*vbus_reg;
  };

-static struct dwc3_omap*_omap;
+enum omap_dwc3_vbus_id_status {
+   OMAP_DWC3_ID_FLOAT,
+   OMAP_DWC3_ID_GROUND,
+   OMAP_DWC3_VBUS_OFF,
+   OMAP_DWC3_VBUS_VALID,
+};

  static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
  {
@@ -138,18 +152,23 @@ static inline void dwc3_omap_writel(void __iomem *base, 
u32 offset, u32 value)
writel(value, base + offset);
  }

-int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
+static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
+   enum omap_dwc3_vbus_id_status status)
  {
-   u32 val;
-   struct dwc3_omap*omap = _omap;
-
-   if (!omap)
-   return -EPROBE_DEFER;
+   int ret;
+   u32 val;

switch (status) {
case OMAP_DWC3_ID_GROUND:
dev_dbg(omap-dev, ID GND\n);

+   if (omap-vbus_reg) {
+   ret = regulator_enable(omap-vbus_reg);
+   if (ret) {
+   dev_dbg(omap-dev, regulator enable failed\n);
+   return;
+   }
+   }
val = dwc3_omap_readl(omap-base, USBOTGSS_UTMI_OTG_STATUS);
val = ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG
| USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
@@ -172,6 +191,9 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
break;

case OMAP_DWC3_ID_FLOAT:
+   if (omap-vbus_reg)
+   regulator_disable(omap-vbus_reg);
+
case OMAP_DWC3_VBUS_OFF:
dev_dbg(omap-dev, VBUS Disconnect\n);

@@ -185,12 +207,9 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
break;

default:
-   dev_dbg(omap-dev, ID float\n);
+   

Re: [PATCH v4] usb: dwc3: use extcon fwrk to receive connect/disconnect

2013-06-16 Thread Chanwoo Choi
On 06/14/2013 10:10 PM, Kishon Vijay Abraham I wrote:
 Modified dwc3-omap to receive connect and disconnect notification using
 extcon framework. Also did the necessary cleanups required after
 adapting to extcon framework.
 
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Acked-by: Felipe Balbi ba...@ti.com
 ---
 This patch depends on
 git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git 
 commit:f7ae906
 
 It should also be applied on top of
 usb: dwc3: omap: improve error handling of dwc3_omap_probe patch which is
 merged in Felipe's tree.
 
 So I'm not sure on whose tree this patch should go in.
 
 Changes from v3:
 * did #include of of_extcon.h after Chanwoo resent the patch separating
 extcon-class.c from of_extcon.c
 Changes from v2:
 * updated the Documentation with dwc3 dt binding information.
 * used of_extcon_get_extcon_dev to get extcon device from device tree data.
 Changes from v1:
 * regulator enable/disable is now done here instead of palmas-usb as some 
 users
 of palmas-usb wont need regulator.
 
  Documentation/devicetree/bindings/usb/omap-usb.txt |5 +
  drivers/usb/dwc3/dwc3-omap.c   |  119 
 
  include/linux/usb/dwc3-omap.h  |   30 -
  3 files changed, 105 insertions(+), 49 deletions(-)
  delete mode 100644 include/linux/usb/dwc3-omap.h
 
 diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt 
 b/Documentation/devicetree/bindings/usb/omap-usb.txt
 index d4769f3..f1c15f3 100644
 --- a/Documentation/devicetree/bindings/usb/omap-usb.txt
 +++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
 @@ -53,6 +53,11 @@ OMAP DWC3 GLUE
 It should be set to 1 for HW mode and 2 for SW mode.
   - ranges: the child address space are mapped 1:1 onto the parent address 
 space
  
 +Optional Properties:
 + - extcon : phandle for the extcon device omap dwc3 uses to detect
 +   connect/disconnect events.
 + - vbus-supply : phandle to the regulator device tree node if needed.
 +
  Sub-nodes:
  The dwc3 core should be added as subnode to omap dwc3 glue.
  - dwc3 :
 diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
 index f8f76e6..14c1f1b 100644
 --- a/drivers/usb/dwc3/dwc3-omap.c
 +++ b/drivers/usb/dwc3/dwc3-omap.c
 @@ -43,13 +43,15 @@
  #include linux/spinlock.h
  #include linux/platform_device.h
  #include linux/platform_data/dwc3-omap.h
 -#include linux/usb/dwc3-omap.h
  #include linux/pm_runtime.h
  #include linux/dma-mapping.h
  #include linux/ioport.h
  #include linux/io.h
  #include linux/of.h
  #include linux/of_platform.h
 +#include linux/extcon.h
 +#include linux/extcon/of_extcon.h
 +#include linux/regulator/consumer.h
  
  #include linux/usb/otg.h
  
 @@ -124,9 +126,21 @@ struct dwc3_omap {
   u32 utmi_otg_status;
  
   u32 dma_status:1;
 +
 + struct extcon_specific_cable_nb extcon_vbus_dev;
 + struct extcon_specific_cable_nb extcon_id_dev;
 + struct notifier_block   vbus_nb;
 + struct notifier_block   id_nb;
 +
 + struct regulator*vbus_reg;
  };
  
 -static struct dwc3_omap  *_omap;
 +enum omap_dwc3_vbus_id_status {
 + OMAP_DWC3_ID_FLOAT,
 + OMAP_DWC3_ID_GROUND,
 + OMAP_DWC3_VBUS_OFF,
 + OMAP_DWC3_VBUS_VALID,
 +};
  
  static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
  {
 @@ -138,18 +152,23 @@ static inline void dwc3_omap_writel(void __iomem *base, 
 u32 offset, u32 value)
   writel(value, base + offset);
  }
  
 -int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
 +static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
 + enum omap_dwc3_vbus_id_status status)
  {
 - u32 val;
 - struct dwc3_omap*omap = _omap;
 -
 - if (!omap)
 - return -EPROBE_DEFER;
 + int ret;
 + u32 val;
  
   switch (status) {
   case OMAP_DWC3_ID_GROUND:
   dev_dbg(omap-dev, ID GND\n);
  
 + if (omap-vbus_reg) {
 + ret = regulator_enable(omap-vbus_reg);
 + if (ret) {
 + dev_dbg(omap-dev, regulator enable failed\n);
 + return;
 + }
 + }
   val = dwc3_omap_readl(omap-base, USBOTGSS_UTMI_OTG_STATUS);
   val = ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG
   | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
 @@ -172,6 +191,9 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status 
 status)
   break;
  
   case OMAP_DWC3_ID_FLOAT:
 + if (omap-vbus_reg)
 + regulator_disable(omap-vbus_reg);
 +
   case OMAP_DWC3_VBUS_OFF:
   dev_dbg(omap-dev, VBUS Disconnect\n);
  
 @@ -185,12 +207,9 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status 
 status)
   break;
  
   default:
 - dev_dbg(omap-dev, ID float\n);
 +