]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
clk: Add of_clk_get_by_clkspec() helper
authorSylwester Nawrocki <s.nawrocki@samsung.com>
Mon, 19 May 2014 17:22:50 +0000 (19:22 +0200)
committerNitin Garg <nitin.garg@freescale.com>
Fri, 16 Jan 2015 03:17:06 +0000 (21:17 -0600)
This patch adds of_clk_get_by_clkspec() helper function, which does only
a struct clk lookup from the clock providers. It is used in the subsequent
patch where parsing of a clock from device tree and the lookup from
providers needed to be split.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
[shawn.guo: cherry-pick commit 7f05e28f9dd3 from upstream]
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
drivers/clk/clk.h
drivers/clk/clkdev.c

index 795cc9f0dac0c0594474b24e7cfd9a2ab8b0565e..c798138f023f6ae6a38c252c0946135a82814eba 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
+struct clk *of_clk_get_by_clkspec(struct of_phandle_args *clkspec);
 struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec);
 void of_clk_lock(void);
 void of_clk_unlock(void);
index 48f67218247cb0cb44cfa92b8ed4903a0f193531..6e772dd9882139ad690df8277edd14061cdfba38 100644 (file)
@@ -27,6 +27,32 @@ static LIST_HEAD(clocks);
 static DEFINE_MUTEX(clocks_mutex);
 
 #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
+
+/**
+ * of_clk_get_by_clkspec() - Lookup a clock form a clock provider
+ * @clkspec: pointer to a clock specifier data structure
+ *
+ * This function looks up a struct clk from the registered list of clock
+ * providers, an input is a clock specifier data structure as returned
+ * from the of_parse_phandle_with_args() function call.
+ */
+struct clk *of_clk_get_by_clkspec(struct of_phandle_args *clkspec)
+{
+       struct clk *clk;
+
+       if (!clkspec)
+               return ERR_PTR(-EINVAL);
+
+       of_clk_lock();
+       clk = __of_clk_get_from_provider(clkspec);
+
+       if (!IS_ERR(clk) && !__clk_get(clk))
+               clk = ERR_PTR(-ENOENT);
+
+       of_clk_unlock();
+       return clk;
+}
+
 struct clk *of_clk_get(struct device_node *np, int index)
 {
        struct of_phandle_args clkspec;
@@ -41,13 +67,7 @@ struct clk *of_clk_get(struct device_node *np, int index)
        if (rc)
                return ERR_PTR(rc);
 
-       of_clk_lock();
-       clk = __of_clk_get_from_provider(&clkspec);
-
-       if (!IS_ERR(clk) && !__clk_get(clk))
-               clk = ERR_PTR(-ENOENT);
-
-       of_clk_unlock();
+       clk = of_clk_get_by_clkspec(&clkspec);
        of_node_put(clkspec.np);
        return clk;
 }