clk: of: helper for filling parent clock array and return num of parents
authorDinh Nguyen <dinguyen@opensource.altera.com>
Fri, 5 Jun 2015 16:26:13 +0000 (11:26 -0500)
committerStephen Boyd <sboyd@codeaurora.org>
Sat, 6 Jun 2015 01:10:33 +0000 (18:10 -0700)
Sprinkled all through the platform clock drivers are code like this to
fill the clock parent array:

for (i = 0; i < num_parents; ++i)
parent_names[i] = of_clk_get_parent_name(np, i);

The of_clk_parent_fill() will do the same as the code above, and while
at it, return the number of parents as well since the logic of the
function is to the walk the clock node to look for the parent.

Signed-off-by: Dinh Nguyen <dinguyen@opensource.altera.com>
[sboyd@codeaurora.org: Fixed kernel-doc]
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
drivers/clk/clk.c
include/linux/clk-provider.h

index a522dbbc01b9983b9b7f10c46d66b8409732f631..ee222e28bd97b35471103723fac29be53d52ed52 100644 (file)
@@ -3016,6 +3016,27 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
 }
 EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
 
+/**
+ * of_clk_parent_fill() - Fill @parents with names of @np's parents and return
+ * number of parents
+ * @np: Device node pointer associated with clock provider
+ * @parents: pointer to char array that hold the parents' names
+ * @size: size of the @parents array
+ *
+ * Return: number of parents for the clock node.
+ */
+int of_clk_parent_fill(struct device_node *np, const char **parents,
+                      unsigned int size)
+{
+       unsigned int i = 0;
+
+       while (i < size && (parents[i] = of_clk_get_parent_name(np, i)) != NULL)
+               i++;
+
+       return i;
+}
+EXPORT_SYMBOL_GPL(of_clk_parent_fill);
+
 struct clock_provider {
        of_clk_init_cb_t clk_init_cb;
        struct device_node *np;
index 5378c2aba4d2eaec6f65e93e4173689b8778d277..2e5df069ca34cf328b61de10104b4401c16a52d1 100644 (file)
@@ -626,6 +626,8 @@ struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
                                  void *data);
 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
 int of_clk_get_parent_count(struct device_node *np);
+int of_clk_parent_fill(struct device_node *np, const char **parents,
+                      unsigned int size);
 const char *of_clk_get_parent_name(struct device_node *np, int index);
 
 void of_clk_init(const struct of_device_id *matches);