clk: sunxi: make use of of_clk_parent_fill helper function
[cascardo/linux.git] / drivers / clk / sunxi / clk-sunxi.c
index 9a82f17..2011f21 100644 (file)
@@ -118,11 +118,8 @@ static long sun6i_ahb1_clk_round(unsigned long rate, u8 *divp, u8 *pre_divp,
        return (parent_rate / calcm) >> calcp;
 }
 
-static long sun6i_ahb1_clk_determine_rate(struct clk_hw *hw, unsigned long rate,
-                                         unsigned long min_rate,
-                                         unsigned long max_rate,
-                                         unsigned long *best_parent_rate,
-                                         struct clk_hw **best_parent_clk)
+static int sun6i_ahb1_clk_determine_rate(struct clk_hw *hw,
+                                        struct clk_rate_request *req)
 {
        struct clk *clk = hw->clk, *parent, *best_parent = NULL;
        int i, num_parents;
@@ -135,25 +132,28 @@ static long sun6i_ahb1_clk_determine_rate(struct clk_hw *hw, unsigned long rate,
                if (!parent)
                        continue;
                if (__clk_get_flags(clk) & CLK_SET_RATE_PARENT)
-                       parent_rate = __clk_round_rate(parent, rate);
+                       parent_rate = __clk_round_rate(parent, req->rate);
                else
                        parent_rate = __clk_get_rate(parent);
 
-               child_rate = sun6i_ahb1_clk_round(rate, NULL, NULL, i,
+               child_rate = sun6i_ahb1_clk_round(req->rate, NULL, NULL, i,
                                                  parent_rate);
 
-               if (child_rate <= rate && child_rate > best_child_rate) {
+               if (child_rate <= req->rate && child_rate > best_child_rate) {
                        best_parent = parent;
                        best = parent_rate;
                        best_child_rate = child_rate;
                }
        }
 
-       if (best_parent)
-               *best_parent_clk = __clk_get_hw(best_parent);
-       *best_parent_rate = best;
+       if (!best_parent)
+               return -EINVAL;
 
-       return best_child_rate;
+       req->best_parent_hw = __clk_get_hw(best_parent);
+       req->best_parent_rate = best;
+       req->rate = best_child_rate;
+
+       return 0;
 }
 
 static int sun6i_ahb1_clk_set_rate(struct clk_hw *hw, unsigned long rate,
@@ -195,17 +195,14 @@ static void __init sun6i_ahb1_clk_setup(struct device_node *node)
        const char *clk_name = node->name;
        const char *parents[SUN6I_AHB1_MAX_PARENTS];
        void __iomem *reg;
-       int i = 0;
+       int i;
 
        reg = of_io_request_and_map(node, 0, of_node_full_name(node));
        if (IS_ERR(reg))
                return;
 
        /* we have a mux, we will have >1 parents */
-       while (i < SUN6I_AHB1_MAX_PARENTS &&
-              (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
-               i++;
-
+       i = of_clk_parent_fill(node, parents, SUN6I_AHB1_MAX_PARENTS);
        of_property_read_string(node, "clock-output-names", &clk_name);
 
        ahb1 = kzalloc(sizeof(struct sun6i_ahb1_clk), GFP_KERNEL);
@@ -786,14 +783,11 @@ static void __init sunxi_mux_clk_setup(struct device_node *node,
        const char *clk_name = node->name;
        const char *parents[SUNXI_MAX_PARENTS];
        void __iomem *reg;
-       int i = 0;
+       int i;
 
        reg = of_iomap(node, 0);
 
-       while (i < SUNXI_MAX_PARENTS &&
-              (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
-               i++;
-
+       i = of_clk_parent_fill(node, parents, SUNXI_MAX_PARENTS);
        of_property_read_string(node, "clock-output-names", &clk_name);
 
        clk = clk_register_mux(NULL, clk_name, parents, i,