On Mon, Jul 15, 2013 at 10:03:02AM +0300, Roger Quadros wrote:
> Hi,
> 
> On 07/12/2013 12:50 PM, Felipe Balbi wrote:
> > From: Ruchika Kharwar <ruch...@ti.com>
> > 
> > This patch adapts the dwc3 to use the device tree helper
> > "of_usb_get_dr_mode" for the mode of operation of the dwc3 instance
> > being probed.
> > 
> > [ ba...@ti.com : make of_usb_get_dr_mode() conditional on
> >     dev->of_node and let pdata pass dr_mode too ]
> > 
> > Signed-off-by: Ruchika Kharwar <ruch...@ti.com>
> > Signed-off-by: Felipe Balbi <ba...@ti.com>
> > ---
> >  drivers/usb/dwc3/core.c          | 73 
> > +++++++++++++++++++++-------------------
> >  drivers/usb/dwc3/core.h          | 11 +++---
> >  drivers/usb/dwc3/platform_data.h |  2 ++
> >  3 files changed, 44 insertions(+), 42 deletions(-)
> > 
> > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> > index a4dab1c..dcb744c 100644
> > --- a/drivers/usb/dwc3/core.c
> > +++ b/drivers/usb/dwc3/core.c
> > @@ -37,6 +37,7 @@
> >  #include <linux/usb/ch9.h>
> >  #include <linux/usb/gadget.h>
> >  #include <linux/usb/of.h>
> > +#include <linux/usb/otg.h>
> >  
> >  #include "platform_data.h"
> >  #include "core.h"
> > @@ -359,8 +360,6 @@ static int dwc3_probe(struct platform_device *pdev)
> >     void __iomem            *regs;
> >     void                    *mem;
> >  
> > -   u8                      mode;
> > -
> >     mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
> >     if (!mem) {
> >             dev_err(dev, "not enough memory\n");
> > @@ -424,6 +423,7 @@ static int dwc3_probe(struct platform_device *pdev)
> >             }
> >  
> >             dwc->needs_fifo_resize = of_property_read_bool(node, 
> > "tx-fifo-resize");
> > +           dwc->dr_mode = of_usb_get_dr_mode(node);
> >     } else {
> >             dwc->maximum_speed = pdata->maximum_speed;
> >  
> > @@ -440,6 +440,7 @@ static int dwc3_probe(struct platform_device *pdev)
> >             }
> >  
> >             dwc->needs_fifo_resize = pdata->tx_fifo_resize;
> > +           dwc->dr_mode = pdata->dr_mode;
> >     }
> >  
> >     /* default to superspeed if no maximum_speed passed */
> > @@ -518,14 +519,17 @@ static int dwc3_probe(struct platform_device *pdev)
> >     }
> >  
> >     if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
> > -           mode = DWC3_MODE_HOST;
> > +           dwc->dr_mode = USB_DR_MODE_HOST;
> >     else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
> > -           mode = DWC3_MODE_DEVICE;
> > +           dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
> >     else
> > -           mode = DWC3_MODE_DRD;
> > +           dwc->dr_mode = of_usb_get_dr_mode(node);
> 
> Missed to remove this?

thanks for noticing that :)

Here's a better version:

commit ecb1a59d0d236c5485b008b11ca57d809cc70c1d
Author: Ruchika Kharwar <ruch...@ti.com>
Date:   Sat Jul 6 07:52:49 2013 -0500

    usb: dwc3: adapt to use dr_mode device tree helper
    
    This patch adapts the dwc3 to use the device tree helper
    "of_usb_get_dr_mode" for the mode of operation of the dwc3 instance
    being probed.
    
    [ ba...@ti.com : make of_usb_get_dr_mode() conditional on
        dev->of_node and let pdata pass dr_mode too ]
    
    Signed-off-by: Ruchika Kharwar <ruch...@ti.com>
    Signed-off-by: Felipe Balbi <ba...@ti.com>

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index a4dab1c..ae1f7cb 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -37,6 +37,7 @@
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/of.h>
+#include <linux/usb/otg.h>
 
 #include "platform_data.h"
 #include "core.h"
@@ -359,8 +360,6 @@ static int dwc3_probe(struct platform_device *pdev)
        void __iomem            *regs;
        void                    *mem;
 
-       u8                      mode;
-
        mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
        if (!mem) {
                dev_err(dev, "not enough memory\n");
@@ -424,6 +423,7 @@ static int dwc3_probe(struct platform_device *pdev)
                }
 
                dwc->needs_fifo_resize = of_property_read_bool(node, 
"tx-fifo-resize");
+               dwc->dr_mode = of_usb_get_dr_mode(node);
        } else {
                dwc->maximum_speed = pdata->maximum_speed;
 
@@ -440,6 +440,7 @@ static int dwc3_probe(struct platform_device *pdev)
                }
 
                dwc->needs_fifo_resize = pdata->tx_fifo_resize;
+               dwc->dr_mode = pdata->dr_mode;
        }
 
        /* default to superspeed if no maximum_speed passed */
@@ -518,14 +519,15 @@ static int dwc3_probe(struct platform_device *pdev)
        }
 
        if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
-               mode = DWC3_MODE_HOST;
+               dwc->dr_mode = USB_DR_MODE_HOST;
        else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
-               mode = DWC3_MODE_DEVICE;
-       else
-               mode = DWC3_MODE_DRD;
+               dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
+
+       if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
+               dwc->dr_mode = USB_DR_MODE_OTG;
 
-       switch (mode) {
-       case DWC3_MODE_DEVICE:
+       switch (dwc->dr_mode) {
+       case USB_DR_MODE_PERIPHERAL:
                dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
                ret = dwc3_gadget_init(dwc);
                if (ret) {
@@ -533,7 +535,7 @@ static int dwc3_probe(struct platform_device *pdev)
                        goto err2;
                }
                break;
-       case DWC3_MODE_HOST:
+       case USB_DR_MODE_HOST:
                dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
                ret = dwc3_host_init(dwc);
                if (ret) {
@@ -541,7 +543,7 @@ static int dwc3_probe(struct platform_device *pdev)
                        goto err2;
                }
                break;
-       case DWC3_MODE_DRD:
+       case USB_DR_MODE_OTG:
                dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
                ret = dwc3_host_init(dwc);
                if (ret) {
@@ -556,10 +558,9 @@ static int dwc3_probe(struct platform_device *pdev)
                }
                break;
        default:
-               dev_err(dev, "Unsupported mode of operation %d\n", mode);
+               dev_err(dev, "Unsupported mode of operation %d\n", 
dwc->dr_mode);
                goto err2;
        }
-       dwc->mode = mode;
 
        ret = dwc3_debugfs_init(dwc);
        if (ret) {
@@ -572,14 +573,14 @@ static int dwc3_probe(struct platform_device *pdev)
        return 0;
 
 err3:
-       switch (mode) {
-       case DWC3_MODE_DEVICE:
+       switch (dwc->dr_mode) {
+       case USB_DR_MODE_PERIPHERAL:
                dwc3_gadget_exit(dwc);
                break;
-       case DWC3_MODE_HOST:
+       case USB_DR_MODE_HOST:
                dwc3_host_exit(dwc);
                break;
-       case DWC3_MODE_DRD:
+       case USB_DR_MODE_OTG:
                dwc3_host_exit(dwc);
                dwc3_gadget_exit(dwc);
                break;
@@ -612,14 +613,14 @@ static int dwc3_remove(struct platform_device *pdev)
 
        dwc3_debugfs_exit(dwc);
 
-       switch (dwc->mode) {
-       case DWC3_MODE_DEVICE:
+       switch (dwc->dr_mode) {
+       case USB_DR_MODE_PERIPHERAL:
                dwc3_gadget_exit(dwc);
                break;
-       case DWC3_MODE_HOST:
+       case USB_DR_MODE_HOST:
                dwc3_host_exit(dwc);
                break;
-       case DWC3_MODE_DRD:
+       case USB_DR_MODE_OTG:
                dwc3_host_exit(dwc);
                dwc3_gadget_exit(dwc);
                break;
@@ -643,12 +644,12 @@ static int dwc3_prepare(struct device *dev)
 
        spin_lock_irqsave(&dwc->lock, flags);
 
-       switch (dwc->mode) {
-       case DWC3_MODE_DEVICE:
-       case DWC3_MODE_DRD:
+       switch (dwc->dr_mode) {
+       case USB_DR_MODE_PERIPHERAL:
+       case USB_DR_MODE_OTG:
                dwc3_gadget_prepare(dwc);
                /* FALLTHROUGH */
-       case DWC3_MODE_HOST:
+       case USB_DR_MODE_HOST:
        default:
                dwc3_event_buffers_cleanup(dwc);
                break;
@@ -666,12 +667,12 @@ static void dwc3_complete(struct device *dev)
 
        spin_lock_irqsave(&dwc->lock, flags);
 
-       switch (dwc->mode) {
-       case DWC3_MODE_DEVICE:
-       case DWC3_MODE_DRD:
+       switch (dwc->dr_mode) {
+       case USB_DR_MODE_PERIPHERAL:
+       case USB_DR_MODE_OTG:
                dwc3_gadget_complete(dwc);
                /* FALLTHROUGH */
-       case DWC3_MODE_HOST:
+       case USB_DR_MODE_HOST:
        default:
                dwc3_event_buffers_setup(dwc);
                break;
@@ -687,12 +688,12 @@ static int dwc3_suspend(struct device *dev)
 
        spin_lock_irqsave(&dwc->lock, flags);
 
-       switch (dwc->mode) {
-       case DWC3_MODE_DEVICE:
-       case DWC3_MODE_DRD:
+       switch (dwc->dr_mode) {
+       case USB_DR_MODE_PERIPHERAL:
+       case USB_DR_MODE_OTG:
                dwc3_gadget_suspend(dwc);
                /* FALLTHROUGH */
-       case DWC3_MODE_HOST:
+       case USB_DR_MODE_HOST:
        default:
                /* do nothing */
                break;
@@ -720,12 +721,12 @@ static int dwc3_resume(struct device *dev)
 
        dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
 
-       switch (dwc->mode) {
-       case DWC3_MODE_DEVICE:
-       case DWC3_MODE_DRD:
+       switch (dwc->dr_mode) {
+       case USB_DR_MODE_PERIPHERAL:
+       case USB_DR_MODE_OTG:
                dwc3_gadget_resume(dwc);
                /* FALLTHROUGH */
-       case DWC3_MODE_HOST:
+       case USB_DR_MODE_HOST:
        default:
                /* do nothing */
                break;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index b847728..92df952 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -29,6 +29,7 @@
 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
+#include <linux/usb/otg.h>
 
 /* Global constants */
 #define DWC3_EP0_BOUNCE_SIZE   512
@@ -545,11 +546,6 @@ struct dwc3_hwparams {
 /* HWPARAMS0 */
 #define DWC3_MODE(n)           ((n) & 0x7)
 
-#define DWC3_MODE_DEVICE       0
-#define DWC3_MODE_HOST         1
-#define DWC3_MODE_DRD          2
-#define DWC3_MODE_HUB          3
-
 #define DWC3_MDWIDTH(n)                (((n) & 0xff00) >> 8)
 
 /* HWPARAMS1 */
@@ -611,7 +607,7 @@ struct dwc3_scratchpad_array {
  * @u1u2: only used on revisions <1.83a for workaround
  * @maximum_speed: maximum speed requested (mainly for testing purposes)
  * @revision: revision register contents
- * @mode: mode of operation
+ * @dr_mode: requested mode of operation
  * @usb2_phy: pointer to USB2 PHY
  * @usb3_phy: pointer to USB3 PHY
  * @dcfg: saved contents of DCFG register
@@ -669,6 +665,8 @@ struct dwc3 {
        void __iomem            *regs;
        size_t                  regs_size;
 
+       enum usb_dr_mode        dr_mode;
+
        /* used for suspend/resume */
        u32                     dcfg;
        u32                     gctl;
@@ -677,7 +675,6 @@ struct dwc3 {
        u32                     u1u2;
        u32                     maximum_speed;
        u32                     revision;
-       u32                     mode;
 
 #define DWC3_REVISION_173A     0x5533173a
 #define DWC3_REVISION_175A     0x5533175a
diff --git a/drivers/usb/dwc3/platform_data.h b/drivers/usb/dwc3/platform_data.h
index 16ffe19..7db34f0 100644
--- a/drivers/usb/dwc3/platform_data.h
+++ b/drivers/usb/dwc3/platform_data.h
@@ -18,8 +18,10 @@
  */
 
 #include <linux/usb/ch9.h>
+#include <linux/usb/otg.h>
 
 struct dwc3_platform_data {
        enum usb_device_speed maximum_speed;
+       enum usb_dr_mode dr_mode;
        bool tx_fifo_resize;
 };

-- 
balbi

Attachment: signature.asc
Description: Digital signature

Reply via email to