[RFC PATCH 1/2] usb: dwc2: add clock manage for hcd

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

 



This patch move clock init out of gadget into platform,
make both hcd and gadget can use the clock

Signed-off-by: Kever Yang <kever.yang@xxxxxxxxxxxxxx>
---

 drivers/usb/dwc2/gadget.c   | 16 ++--------------
 drivers/usb/dwc2/hcd.c      |  3 +++
 drivers/usb/dwc2/platform.c | 30 ++++++++++++++++++------------
 3 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 6ffbfc2..1943e52 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3408,20 +3408,12 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
 			hsotg->phyif = GUSBCFG_PHYIF8;
 	}
 
-	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);
-	}
-
 	hsotg->gadget.max_speed = USB_SPEED_HIGH;
 	hsotg->gadget.ops = &s3c_hsotg_gadget_ops;
 	hsotg->gadget.name = dev_name(dev);
 
 	/* reset the system */
 
-	clk_prepare_enable(hsotg->clk);
-
 	/* regulators */
 
 	for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++)
@@ -3431,7 +3423,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
 				 hsotg->supplies);
 	if (ret) {
 		dev_err(dev, "failed to request supplies: %d\n", ret);
-		goto err_clk;
+		goto out;
 	}
 
 	ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
@@ -3510,9 +3502,7 @@ err_ep_mem:
 	kfree(eps);
 err_supplies:
 	s3c_hsotg_phy_disable(hsotg);
-err_clk:
-	clk_disable_unprepare(hsotg->clk);
-
+out:
 	return ret;
 }
 EXPORT_SYMBOL_GPL(dwc2_gadget_init);
@@ -3532,8 +3522,6 @@ int s3c_hsotg_remove(struct dwc2_hsotg *hsotg)
 		usb_gadget_unregister_driver(hsotg->driver);
 	}
 
-	clk_disable_unprepare(hsotg->clk);
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(s3c_hsotg_remove);
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index fa49c72..fddd923 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -46,6 +46,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/clk.h>
 #include <linux/usb.h>
 
 #include <linux/usb/hcd.h>
@@ -2266,6 +2267,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
 	spin_lock_irqsave(&hsotg->lock, flags);
 
 	hcd->state = HC_STATE_RUNNING;
+	clk_enable(hsotg->clk);
 
 	if (dwc2_is_device_mode(hsotg)) {
 		spin_unlock_irqrestore(&hsotg->lock, flags);
@@ -2297,6 +2299,7 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd)
 	spin_lock_irqsave(&hsotg->lock, flags);
 	dwc2_hcd_stop(hsotg);
 	spin_unlock_irqrestore(&hsotg->lock, flags);
+	clk_disable(hsotg->clk);
 
 	usleep_range(1000, 3000);
 }
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 77c8417..16cdd1f 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -37,6 +37,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
 #include <linux/of_device.h>
@@ -122,6 +123,7 @@ static int dwc2_driver_remove(struct platform_device *dev)
 
 	dwc2_hcd_remove(hsotg);
 	s3c_hsotg_remove(hsotg);
+	clk_disable_unprepare(hsotg->clk);
 
 	return 0;
 }
@@ -216,24 +218,28 @@ static int dwc2_driver_probe(struct platform_device *dev)
 	hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node);
 
 	spin_lock_init(&hsotg->lock);
-	retval = dwc2_gadget_init(hsotg, irq);
-	if (retval) {
-		/*
-		 * We will not fail the driver initialization for dual-role
-		 * if no clock node is supplied. However, all gadget
-		 * functionality will be disabled if a clock node is not
-		 * provided. Host functionality will continue.
-		 * TO-DO: make clock node a requirement for the HCD.
-		 */
-		if (!IS_ERR(hsotg->clk))
-			return retval;
+	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);
 	}
+
+	clk_prepare_enable(hsotg->clk);
+
+	retval = dwc2_gadget_init(hsotg, irq);
+	if (retval)
+		goto out;
+
 	retval = dwc2_hcd_init(hsotg, irq, params);
 	if (retval)
-		return retval;
+		goto out;
 
 	platform_set_drvdata(dev, hsotg);
 
+out:
+	if (IS_ERR(retval))
+		clk_disable_unprepare(hsotg->clk);
+
 	return retval;
 }
 
-- 
1.9.1

--
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