usb: dwc3: adapt dwc3 core to use Generic PHY Framework
authorKishon Vijay Abraham I <kishon@ti.com>
Mon, 3 Mar 2014 11:38:11 +0000 (17:08 +0530)
committerFelipe Balbi <balbi@ti.com>
Wed, 5 Mar 2014 20:40:05 +0000 (14:40 -0600)
Adapted dwc3 core to use the Generic PHY Framework. So for init, exit,
power_on and power_off the following APIs are used phy_init(), phy_exit(),
phy_power_on() and phy_power_off().

However using the old USB phy library wont be removed till the PHYs of all
other SoC's using dwc3 core is adapted to the Generic PHY Framework.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Documentation/devicetree/bindings/usb/dwc3.txt
drivers/usb/dwc3/core.c
drivers/usb/dwc3/core.h

index e807635f9e1c72acec52de0f296804b14e5d458c..471366d6a1291846852e24cb0b03fec0e5fa8b23 100644 (file)
@@ -6,11 +6,13 @@ Required properties:
  - compatible: must be "snps,dwc3"
  - reg : Address and length of the register set for the device
  - interrupts: Interrupts used by the dwc3 controller.
+
+Optional properties:
  - usb-phy : array of phandle for the PHY device.  The first element
    in the array is expected to be a handle to the USB2/HS PHY and
    the second element is expected to be a handle to the USB3/SS PHY
-
-Optional properties:
+ - phys: from the *Generic PHY* bindings
+ - phy-names: from the *Generic PHY* bindings
  - tx-fifo-resize: determines if the FIFO *has* to be reallocated.
 
 This is usually a subnode to DWC3 glue to which it is connected.
index c89570cc0689e563a103eb6c7aaa3779c12b34f4..d001417e8e370cd7f3e7fa2d9b9c2678271987dc 100644 (file)
@@ -61,9 +61,10 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
  * dwc3_core_soft_reset - Issues core soft reset and PHY reset
  * @dwc: pointer to our context structure
  */
-static void dwc3_core_soft_reset(struct dwc3 *dwc)
+static int dwc3_core_soft_reset(struct dwc3 *dwc)
 {
        u32             reg;
+       int             ret;
 
        /* Before Resetting PHY, put Core in Reset */
        reg = dwc3_readl(dwc->regs, DWC3_GCTL);
@@ -82,6 +83,15 @@ static void dwc3_core_soft_reset(struct dwc3 *dwc)
 
        usb_phy_init(dwc->usb2_phy);
        usb_phy_init(dwc->usb3_phy);
+       ret = phy_init(dwc->usb2_generic_phy);
+       if (ret < 0)
+               return ret;
+
+       ret = phy_init(dwc->usb3_generic_phy);
+       if (ret < 0) {
+               phy_exit(dwc->usb2_generic_phy);
+               return ret;
+       }
        mdelay(100);
 
        /* Clear USB3 PHY reset */
@@ -100,6 +110,8 @@ static void dwc3_core_soft_reset(struct dwc3 *dwc)
        reg = dwc3_readl(dwc->regs, DWC3_GCTL);
        reg &= ~DWC3_GCTL_CORESOFTRESET;
        dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+
+       return 0;
 }
 
 /**
@@ -391,7 +403,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
                cpu_relax();
        } while (true);
 
-       dwc3_core_soft_reset(dwc);
+       ret = dwc3_core_soft_reset(dwc);
+       if (ret)
+               goto err0;
 
        reg = dwc3_readl(dwc->regs, DWC3_GCTL);
        reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
@@ -456,6 +470,8 @@ err2:
 err1:
        usb_phy_shutdown(dwc->usb2_phy);
        usb_phy_shutdown(dwc->usb3_phy);
+       phy_exit(dwc->usb2_generic_phy);
+       phy_exit(dwc->usb3_generic_phy);
 
 err0:
        return ret;
@@ -466,6 +482,8 @@ static void dwc3_core_exit(struct dwc3 *dwc)
        dwc3_free_scratch_buffers(dwc);
        usb_phy_shutdown(dwc->usb2_phy);
        usb_phy_shutdown(dwc->usb3_phy);
+       phy_exit(dwc->usb2_generic_phy);
+       phy_exit(dwc->usb3_generic_phy);
 }
 
 #define DWC3_ALIGN_MASK                (16 - 1)
@@ -556,6 +574,32 @@ static int dwc3_probe(struct platform_device *pdev)
                }
        }
 
+       dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
+       if (IS_ERR(dwc->usb2_generic_phy)) {
+               ret = PTR_ERR(dwc->usb2_generic_phy);
+               if (ret == -ENOSYS || ret == -ENODEV) {
+                       dwc->usb2_generic_phy = NULL;
+               } else if (ret == -EPROBE_DEFER) {
+                       return ret;
+               } else {
+                       dev_err(dev, "no usb2 phy configured\n");
+                       return ret;
+               }
+       }
+
+       dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
+       if (IS_ERR(dwc->usb3_generic_phy)) {
+               ret = PTR_ERR(dwc->usb3_generic_phy);
+               if (ret == -ENOSYS || ret == -ENODEV) {
+                       dwc->usb3_generic_phy = NULL;
+               } else if (ret == -EPROBE_DEFER) {
+                       return ret;
+               } else {
+                       dev_err(dev, "no usb3 phy configured\n");
+                       return ret;
+               }
+       }
+
        dwc->xhci_resources[0].start = res->start;
        dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
                                        DWC3_XHCI_REGS_END;
@@ -612,11 +656,18 @@ static int dwc3_probe(struct platform_device *pdev)
 
        usb_phy_set_suspend(dwc->usb2_phy, 0);
        usb_phy_set_suspend(dwc->usb3_phy, 0);
+       ret = phy_power_on(dwc->usb2_generic_phy);
+       if (ret < 0)
+               goto err1;
+
+       ret = phy_power_on(dwc->usb3_generic_phy);
+       if (ret < 0)
+               goto err_usb2phy_power;
 
        ret = dwc3_event_buffers_setup(dwc);
        if (ret) {
                dev_err(dwc->dev, "failed to setup event buffers\n");
-               goto err1;
+               goto err_usb3phy_power;
        }
 
        switch (dwc->dr_mode) {
@@ -685,6 +736,12 @@ err3:
 err2:
        dwc3_event_buffers_cleanup(dwc);
 
+err_usb3phy_power:
+       phy_power_off(dwc->usb3_generic_phy);
+
+err_usb2phy_power:
+       phy_power_off(dwc->usb2_generic_phy);
+
 err1:
        usb_phy_set_suspend(dwc->usb2_phy, 1);
        usb_phy_set_suspend(dwc->usb3_phy, 1);
@@ -702,6 +759,8 @@ static int dwc3_remove(struct platform_device *pdev)
 
        usb_phy_set_suspend(dwc->usb2_phy, 1);
        usb_phy_set_suspend(dwc->usb3_phy, 1);
+       phy_power_off(dwc->usb2_generic_phy);
+       phy_power_off(dwc->usb3_generic_phy);
 
        pm_runtime_put_sync(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
@@ -799,6 +858,8 @@ static int dwc3_suspend(struct device *dev)
 
        usb_phy_shutdown(dwc->usb3_phy);
        usb_phy_shutdown(dwc->usb2_phy);
+       phy_exit(dwc->usb2_generic_phy);
+       phy_exit(dwc->usb3_generic_phy);
 
        return 0;
 }
@@ -807,9 +868,17 @@ static int dwc3_resume(struct device *dev)
 {
        struct dwc3     *dwc = dev_get_drvdata(dev);
        unsigned long   flags;
+       int             ret;
 
        usb_phy_init(dwc->usb3_phy);
        usb_phy_init(dwc->usb2_phy);
+       ret = phy_init(dwc->usb2_generic_phy);
+       if (ret < 0)
+               return ret;
+
+       ret = phy_init(dwc->usb3_generic_phy);
+       if (ret < 0)
+               goto err_usb2phy_init;
 
        spin_lock_irqsave(&dwc->lock, flags);
 
@@ -833,6 +902,11 @@ static int dwc3_resume(struct device *dev)
        pm_runtime_enable(dev);
 
        return 0;
+
+err_usb2phy_init:
+       phy_exit(dwc->usb2_generic_phy);
+
+       return ret;
 }
 
 static const struct dev_pm_ops dwc3_dev_pm_ops = {
index 535bb6e1f2b8101a621b02c297c6cd34d06e627d..57332e3768e4d8eab0eebc64f12c3c6fde456eff 100644 (file)
@@ -31,6 +31,8 @@
 #include <linux/usb/gadget.h>
 #include <linux/usb/otg.h>
 
+#include <linux/phy/phy.h>
+
 /* Global constants */
 #define DWC3_EP0_BOUNCE_SIZE   512
 #define DWC3_ENDPOINTS_NUM     32
@@ -619,6 +621,8 @@ struct dwc3_scratchpad_array {
  * @dr_mode: requested mode of operation
  * @usb2_phy: pointer to USB2 PHY
  * @usb3_phy: pointer to USB3 PHY
+ * @usb2_generic_phy: pointer to USB2 PHY
+ * @usb3_generic_phy: pointer to USB3 PHY
  * @dcfg: saved contents of DCFG register
  * @gctl: saved contents of GCTL register
  * @isoch_delay: wValue from Set Isochronous Delay request;
@@ -679,6 +683,9 @@ struct dwc3 {
        struct usb_phy          *usb2_phy;
        struct usb_phy          *usb3_phy;
 
+       struct phy              *usb2_generic_phy;
+       struct phy              *usb3_generic_phy;
+
        void __iomem            *regs;
        size_t                  regs_size;
 
This page took 0.030245 seconds and 5 git commands to generate.