From: Dinh Nguyen <dingu...@opensource.altera.com>

Since the dwc2 hcd driver is currently not looking for a clock node during
init, we should not completely fail if there isn't a clock provided.
Add a check for a valid clock before calling clock functions.

Signed-off-by: Dinh Nguyen <dingu...@opensource.altera.com>
---
 drivers/usb/dwc2/gadget.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index d8b86a3..a3a3d31 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2854,7 +2854,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
        hsotg->gadget.dev.of_node = hsotg->dev->of_node;
        hsotg->gadget.speed = USB_SPEED_UNKNOWN;
 
-       clk_enable(hsotg->clk);
+       if (!IS_ERR(hsotg->clk))
+               clk_enable(hsotg->clk);
 
        ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
                                    hsotg->supplies);
@@ -2905,7 +2906,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
        regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
                                hsotg->supplies);
 
-       clk_disable(hsotg->clk);
+       if (!IS_ERR(hsotg->clk))
+               clk_disable(hsotg->clk);
 
        return 0;
 }
@@ -2938,10 +2940,12 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, 
int is_on)
        spin_lock_irqsave(&hsotg->lock, flags);
        if (is_on) {
                s3c_hsotg_phy_enable(hsotg);
-               clk_enable(hsotg->clk);
+               if (!IS_ERR(hsotg->clk))
+                       clk_enable(hsotg->clk);
                s3c_hsotg_core_init(hsotg);
        } else {
-               clk_disable(hsotg->clk);
+               if (!IS_ERR(hsotg->clk))
+                       clk_disable(hsotg->clk);
                s3c_hsotg_phy_disable(hsotg);
        }
 
@@ -3412,16 +3416,15 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
        }
 
        hsotg->clk = devm_clk_get(dev, "otg");
-       if (IS_ERR(hsotg->clk)) {
-               dev_err(dev, "cannot get otg clock\n");
-               return PTR_ERR(hsotg->clk);
-       }
+       if (IS_ERR(hsotg->clk))
+               dev_warn(dev, "cannot get otg clock\n");
 
        hsotg->gadget.max_speed = USB_SPEED_HIGH;
        hsotg->gadget.ops = &s3c_hsotg_gadget_ops;
        hsotg->gadget.name = dev_name(dev);
 
-       clk_prepare_enable(hsotg->clk);
+       if (!IS_ERR(hsotg->clk))
+               clk_prepare_enable(hsotg->clk);
 
        /* regulators */
 
@@ -3454,7 +3457,8 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
                        dev_name(dev), hsotg);
        if (ret < 0) {
                s3c_hsotg_phy_disable(hsotg);
-               clk_disable_unprepare(hsotg->clk);
+               if (!IS_ERR(hsotg->clk))
+                       clk_disable_unprepare(hsotg->clk);
                regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
                                       hsotg->supplies);
                dev_err(dev, "cannot claim IRQ\n");
@@ -3524,7 +3528,8 @@ err_ep_mem:
 err_supplies:
        s3c_hsotg_phy_disable(hsotg);
 err_clk:
-       clk_disable_unprepare(hsotg->clk);
+       if (!IS_ERR(hsotg->clk))
+               clk_disable_unprepare(hsotg->clk);
 
        return ret;
 }
@@ -3544,7 +3549,8 @@ int s3c_hsotg_remove(struct dwc2_hsotg *hsotg)
                usb_gadget_unregister_driver(hsotg->driver);
        }
 
-       clk_disable_unprepare(hsotg->clk);
+       if (!IS_ERR(hsotg->clk))
+               clk_disable_unprepare(hsotg->clk);
 
        return 0;
 }
@@ -3571,7 +3577,8 @@ static int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg)
 
                ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
                                             hsotg->supplies);
-               clk_disable(hsotg->clk);
+               if (!IS_ERR(hsotg->clk))
+                       clk_disable(hsotg->clk);
        }
 
        return ret;
@@ -3586,7 +3593,8 @@ static int s3c_hsotg_resume(struct dwc2_hsotg *hsotg)
                dev_info(hsotg->dev, "resuming usb gadget %s\n",
                         hsotg->driver->driver.name);
 
-               clk_enable(hsotg->clk);
+               if (!IS_ERR(hsotg->clk))
+                       clk_enable(hsotg->clk);
                ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
                                           hsotg->supplies);
        }
-- 
2.0.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to