[PATCHv2 09/13] usb: dwc2: gadget: Do not fail probe if there isn't a clock node

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Dinh Nguyen <dinguyen@xxxxxxxxxx>

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 <dinguyen@xxxxxxxxxx>
---
 drivers/usb/dwc2/gadget.c |   37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 737e979..dbcdee0 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->s3c_hsotg->clk);
+	if (!IS_ERR(hsotg->s3c_hsotg->clk))
+		clk_enable(hsotg->s3c_hsotg->clk);
 
 	ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
 				    hsotg->s3c_hsotg->supplies);
@@ -2905,7 +2906,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
 	regulator_bulk_disable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
 				hsotg->s3c_hsotg->supplies);
 
-	clk_disable(hsotg->s3c_hsotg->clk);
+	if (!IS_ERR(hsotg->s3c_hsotg->clk))
+		clk_disable(hsotg->s3c_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->s3c_hsotg->clk);
+		if (!IS_ERR(hsotg->s3c_hsotg->clk))
+			clk_enable(hsotg->s3c_hsotg->clk);
 		s3c_hsotg_core_init(hsotg);
 	} else {
-		clk_disable(hsotg->s3c_hsotg->clk);
+		if (!IS_ERR(hsotg->s3c_hsotg->clk))
+			clk_disable(hsotg->s3c_hsotg->clk);
 		s3c_hsotg_phy_disable(hsotg);
 	}
 
@@ -3418,16 +3422,15 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
 	}
 
 	hsotg->s3c_hsotg->clk = devm_clk_get(dev, "otg");
-	if (IS_ERR(hsotg->s3c_hsotg->clk)) {
-		dev_err(dev, "cannot get otg clock\n");
-		return PTR_ERR(hsotg->s3c_hsotg->clk);
-	}
+	if (IS_ERR(hsotg->s3c_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->s3c_hsotg->clk);
+	if (!IS_ERR(hsotg->s3c_hsotg->clk))
+		clk_prepare_enable(hsotg->s3c_hsotg->clk);
 
 	/* regulators */
 
@@ -3460,7 +3463,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->s3c_hsotg->clk);
+		if (!IS_ERR(hsotg->s3c_hsotg->clk))
+			clk_disable_unprepare(hsotg->s3c_hsotg->clk);
 		regulator_bulk_disable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
 				       hsotg->s3c_hsotg->supplies);
 		dev_err(dev, "cannot claim IRQ\n");
@@ -3530,7 +3534,8 @@ err_ep_mem:
 err_supplies:
 	s3c_hsotg_phy_disable(hsotg);
 err_clk:
-	clk_disable_unprepare(hsotg->s3c_hsotg->clk);
+	if (!IS_ERR(hsotg->s3c_hsotg->clk))
+		clk_disable_unprepare(hsotg->s3c_hsotg->clk);
 
 	return ret;
 }
@@ -3550,7 +3555,8 @@ int s3c_hsotg_remove(struct dwc2_hsotg *hsotg)
 		usb_gadget_unregister_driver(hsotg->driver);
 	}
 
-	clk_disable_unprepare(hsotg->s3c_hsotg->clk);
+	if (!IS_ERR(hsotg->s3c_hsotg->clk))
+		clk_disable_unprepare(hsotg->s3c_hsotg->clk);
 
 	return 0;
 }
@@ -3577,7 +3583,9 @@ static int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg)
 
 		ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
 					     hsotg->s3c_hsotg->supplies);
-		clk_disable(hsotg->s3c_hsotg->clk);
+
+		if (!IS_ERR(hsotg->s3c_hsotg->clk))
+			clk_disable(hsotg->s3c_hsotg->clk);
 	}
 
 	return ret;
@@ -3592,7 +3600,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->s3c_hsotg->clk);
+		if (!IS_ERR(hsotg->s3c_hsotg->clk))
+			clk_enable(hsotg->s3c_hsotg->clk);
 		ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->s3c_hsotg->supplies),
 				      hsotg->s3c_hsotg->supplies);
 	}
-- 
1.7.9.5

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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux