Skip to contentSkip to conversation

usb: gadget: Add clock support

PATCH Superseded Shubhrajyoti Datta 3 participants 5 messages Sep 22, 2021 – Sep 27, 2021

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover usb: gadget: Add clock support

Add clock support to udc xilinx.

v2:
Add the clock binding
v3:
Add a warn print

Shubhrajyoti Datta (2):
dt-binding: usb: xilinx: Add clocking node
usb: gadget: udc-xilinx: Add clock support

 .../devicetree/bindings/usb/xlnx,usb2.yaml    |  8 ++++++
 drivers/usb/gadget/udc/udc-xilinx.c           | 25 +++++++++++++++++++
 2 files changed, 33 insertions(+)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/2 dt-binding: usb: xilinx: Add clocking node

Add a clocking node for xilinx udc.

---
 Documentation/devicetree/bindings/usb/xlnx,usb2.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/usb/xlnx,usb2.yaml +8 -0
index b8acc415eaf1..39213806ac79 100644
@@ -24,6 +24,14 @@ properties:
       If present, hardware has dma capability.
     type: boolean
 
+  clocks:
+    minItems: 1
+
+  clock-name:
+    const: "s_axi_aclk"
+    description: |
+      Input clock name.
+
 required:
   - compatible
   - reg
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v3 1/2] dt-binding: usb: xilinx: Add clocking node

Quoted 12 lines · Shubhrajyoti Datta

Add a clocking node for xilinx udc.

---
 Documentation/devicetree/bindings/usb/xlnx,usb2.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/usb/xlnx,usb2.yaml +0 -0
index b8acc415eaf1..39213806ac79 100644

Documentation/devicetree/bindings/usb/xlnx,usb2.yaml properties: · line 30

Quoted 7 lines
Documentation/devicetree/bindings/usb/xlnx,usb2.yaml +4 -0
@@ -24,6 +24,14 @@ properties:
       If present, hardware has dma capability.
     type: boolean
 
+  clocks:
+    minItems: 1
+
+  clock-name:

I think you meant 'clock-names'.

Documentation/devicetree/bindings/usb/xlnx,usb2.yaml properties: · line 31

Quoted 1 line
Documentation/devicetree/bindings/usb/xlnx,usb2.yaml +1 -0
+    const: "s_axi_aclk"

Don't need quotes.

Documentation/devicetree/bindings/usb/xlnx,usb2.yaml properties: · line 33

Quoted 2 lines
Documentation/devicetree/bindings/usb/xlnx,usb2.yaml +2 -0
+    description: |
+      Input clock name.

That's every 'clock-names'. You can drop description.

Quoted 8 lines
Documentation/devicetree/bindings/usb/xlnx,usb2.yaml +1 -0
+
 required:
   - compatible
   - reg
Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 2/2 usb: gadget: udc-xilinx: Add clock support

In reply to Shubhrajyoti Datta

Currently the driver depends on the bootloader to enable the clocks. Add support for clocking. The patch enables the clock at probe and disables them at remove.

---
v3:
Add dev_warn

 drivers/usb/gadget/udc/udc-xilinx.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/usb/gadget/udc/udc-xilinx.c +25 -0
index fb4ffedd6f0d..f5ca670776a3 100644
@@ -11,6 +11,7 @@
  * USB peripheral controller (at91_udc.c).
  */
 
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
@@ -171,6 +172,7 @@ struct xusb_ep {
  * @addr: the usb device base address
  * @lock: instance of spinlock
  * @dma_enabled: flag indicating whether the dma is included in the system
+ * @clk: pointer to struct clk
  * @read_fn: function pointer to read device registers
  * @write_fn: function pointer to write to device registers
  */
@@ -188,6 +190,7 @@ struct xusb_udc {
 	void __iomem *addr;
 	spinlock_t lock;
 	bool dma_enabled;
+	struct clk *clk;
 
 	unsigned int (*read_fn)(void __iomem *);
 	void (*write_fn)(void __iomem *, u32, u32);
@@ -2092,6 +2095,27 @@ static int xudc_probe(struct platform_device *pdev)
 	udc->gadget.ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO].ep_usb;
 	udc->gadget.name = driver_name;
 
+	udc->clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
+	if (IS_ERR(udc->clk)) {
+		if (PTR_ERR(udc->clk) != -ENOENT) {
+			ret = PTR_ERR(udc->clk);
+			goto fail;
+		}
+
+		/*
+		 * Clock framework support is optional, continue on,
+		 * anyways if we don't find a matching clock
+		 */
+		dev_warn(&pdev->dev, "s_axi_aclk clock property is not found\n");
+		udc->clk = NULL;
+	}
+
+	ret = clk_prepare_enable(udc->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Unable to enable clock.\n");
+		return ret;
+	}
+
 	spin_lock_init(&udc->lock);
 
 	/* Check for IP endianness */
@@ -2147,6 +2171,7 @@ static int xudc_remove(struct platform_device *pdev)
 	struct xusb_udc *udc = platform_get_drvdata(pdev);
 
 	usb_del_gadget_udc(&udc->gadget);
+	clk_disable_unprepare(udc->clk);
 
 	return 0;
 }
Signature · 1 line
2.25.1