]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/usb/host/xhci-plat.c
usb: host: xhci-plat: add clock support
[karo-tx-linux.git] / drivers / usb / host / xhci-plat.c
index 151901ce1ba933598b09cd8d01a077a7b66c1cc9..8108e58c9e02589a971e2e47b417aca2823fc817 100644 (file)
  * version 2 as published by the Free Software Foundation.
  */
 
-#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
 #include <linux/module.h>
-#include <linux/slab.h>
 #include <linux/of.h>
-#include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
 
 #include "xhci.h"
 
@@ -91,6 +92,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
        struct xhci_hcd         *xhci;
        struct resource         *res;
        struct usb_hcd          *hcd;
+       struct clk              *clk;
        int                     ret;
        int                     irq;
 
@@ -137,14 +139,27 @@ static int xhci_plat_probe(struct platform_device *pdev)
                goto release_mem_region;
        }
 
+       /*
+        * Not all platforms have a clk so it is not an error if the
+        * clock does not exists.
+        */
+       clk = devm_clk_get(&pdev->dev, NULL);
+       if (!IS_ERR(clk)) {
+               ret = clk_prepare_enable(clk);
+               if (ret)
+                       goto unmap_registers;
+       }
+
        ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
        if (ret)
-               goto unmap_registers;
+               goto disable_clk;
+
        device_wakeup_enable(hcd->self.controller);
 
        /* USB 2.0 roothub is stored in the platform_device now. */
        hcd = platform_get_drvdata(pdev);
        xhci = hcd_to_xhci(hcd);
+       xhci->clk = clk;
        xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
                        dev_name(&pdev->dev), hcd);
        if (!xhci->shared_hcd) {
@@ -173,6 +188,10 @@ put_usb3_hcd:
 dealloc_usb2_hcd:
        usb_remove_hcd(hcd);
 
+disable_clk:
+       if (!IS_ERR(clk))
+               clk_disable_unprepare(clk);
+
 unmap_registers:
        iounmap(hcd->regs);
 
@@ -189,11 +208,14 @@ static int xhci_plat_remove(struct platform_device *dev)
 {
        struct usb_hcd  *hcd = platform_get_drvdata(dev);
        struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+       struct clk *clk = xhci->clk;
 
        usb_remove_hcd(xhci->shared_hcd);
        usb_put_hcd(xhci->shared_hcd);
 
        usb_remove_hcd(hcd);
+       if (!IS_ERR(clk))
+               clk_disable_unprepare(clk);
        iounmap(hcd->regs);
        release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
        usb_put_hcd(hcd);