Merge tag 'exynos-dt-2' of git://git.kernel.org/pub/scm/linux/kernel/git/kgene/linux...
[sfrench/cifs-2.6.git] / arch / arm / mach-imx / clk.c
index 37e884ed1cd4098d43788e34e7f21d7d1ff88404..55bc80a00666412b8d7c53daaba26dced5e2eb95 100644 (file)
@@ -1,4 +1,39 @@
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/slab.h>
 #include <linux/spinlock.h>
 #include "clk.h"
 
 DEFINE_SPINLOCK(imx_ccm_lock);
+
+static struct clk * __init imx_obtain_fixed_clock_from_dt(const char *name)
+{
+       struct of_phandle_args phandle;
+       struct clk *clk = ERR_PTR(-ENODEV);
+       char *path;
+
+       path = kasprintf(GFP_KERNEL, "/clocks/%s", name);
+       if (!path)
+               return ERR_PTR(-ENOMEM);
+
+       phandle.np = of_find_node_by_path(path);
+       kfree(path);
+
+       if (phandle.np) {
+               clk = of_clk_get_from_provider(&phandle);
+               of_node_put(phandle.np);
+       }
+       return clk;
+}
+
+struct clk * __init imx_obtain_fixed_clock(
+                       const char *name, unsigned long rate)
+{
+       struct clk *clk;
+
+       clk = imx_obtain_fixed_clock_from_dt(name);
+       if (IS_ERR(clk))
+               clk = imx_clk_fixed(name, rate);
+       return clk;
+}