usb: dwc2: platform: add generic PHY framework support
[linux-block.git] / drivers / usb / dwc2 / platform.c
index 6a795aa2ff05efc207f99bbb0f1cc5d001bb38ba..ae095f009b4f792b508ee2e713f3268359a27b42 100644 (file)
@@ -155,6 +155,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
        struct dwc2_core_params defparams;
        struct dwc2_hsotg *hsotg;
        struct resource *res;
+       struct phy *phy;
+       struct usb_phy *uphy;
        int retval;
        int irq;
 
@@ -212,6 +214,24 @@ static int dwc2_driver_probe(struct platform_device *dev)
 
        hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node);
 
+       /*
+        * Attempt to find a generic PHY, then look for an old style
+        * USB PHY
+        */
+       phy = devm_phy_get(&dev->dev, "usb2-phy");
+       if (IS_ERR(phy)) {
+               hsotg->phy = NULL;
+               uphy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
+               if (IS_ERR(uphy))
+                       hsotg->uphy = NULL;
+               else
+                       hsotg->uphy = uphy;
+       } else {
+               hsotg->phy = phy;
+               phy_power_on(hsotg->phy);
+               phy_init(hsotg->phy);
+       }
+
        spin_lock_init(&hsotg->lock);
        mutex_init(&hsotg->init_mutex);
        retval = dwc2_gadget_init(hsotg, irq);
@@ -231,8 +251,15 @@ static int __maybe_unused dwc2_suspend(struct device *dev)
        struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
        int ret = 0;
 
-       if (dwc2_is_device_mode(dwc2))
+       if (dwc2_is_device_mode(dwc2)) {
                ret = s3c_hsotg_suspend(dwc2);
+       } else {
+               if (dwc2->lx_state == DWC2_L0)
+                       return 0;
+               phy_exit(dwc2->phy);
+               phy_power_off(dwc2->phy);
+
+       }
        return ret;
 }
 
@@ -241,8 +268,13 @@ static int __maybe_unused dwc2_resume(struct device *dev)
        struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
        int ret = 0;
 
-       if (dwc2_is_device_mode(dwc2))
+       if (dwc2_is_device_mode(dwc2)) {
                ret = s3c_hsotg_resume(dwc2);
+       } else {
+               phy_power_on(dwc2->phy);
+               phy_init(dwc2->phy);
+
+       }
        return ret;
 }