usb: dwc2: get optional vbus-supply regulator once
authorFabrice Gasnier <fabrice.gasnier@st.com>
Wed, 5 Sep 2018 11:40:02 +0000 (13:40 +0200)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Tue, 2 Oct 2018 07:37:01 +0000 (10:37 +0300)
Move devm_regulator_get_optional() call to probe routine. This avoids
'vbus-supply' regulator to be requested lots of times, upon each call
to dwc2_vbus_supply_init(), e.g. like with runtime pm.

Fixes: 531ef5ebea96 ("usb: dwc2: add support for host mode external
vbus supply")

Tested-by: Artur Petrosyan <arturp@synopsys.com>
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/dwc2/hcd.c
drivers/usb/dwc2/platform.c

index 5f23b933cafc5700dde27108aab2d049dcdebcc0..24aa5a3acf86a794aa96fe7fc8746d882530246e 100644 (file)
@@ -358,16 +358,10 @@ static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg)
 
 static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg)
 {
-       int ret;
-
-       hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
-       if (IS_ERR(hsotg->vbus_supply)) {
-               ret = PTR_ERR(hsotg->vbus_supply);
-               hsotg->vbus_supply = NULL;
-               return ret == -ENODEV ? 0 : ret;
-       }
+       if (hsotg->vbus_supply)
+               return regulator_enable(hsotg->vbus_supply);
 
-       return regulator_enable(hsotg->vbus_supply);
+       return 0;
 }
 
 static int dwc2_vbus_supply_exit(struct dwc2_hsotg *hsotg)
index 577642895b57d118eb37115cdb005089ee5c6e08..c0b64d48355237bce6b35c25e8e75ce362b300f3 100644 (file)
@@ -432,6 +432,14 @@ static int dwc2_driver_probe(struct platform_device *dev)
        if (retval)
                return retval;
 
+       hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
+       if (IS_ERR(hsotg->vbus_supply)) {
+               retval = PTR_ERR(hsotg->vbus_supply);
+               hsotg->vbus_supply = NULL;
+               if (retval != -ENODEV)
+                       return retval;
+       }
+
        retval = dwc2_lowlevel_hw_enable(hsotg);
        if (retval)
                return retval;