]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
clk: Consolidate recalc rate logic
authorStephen Boyd <sboyd@codeaurora.org>
Wed, 26 Mar 2014 23:06:36 +0000 (16:06 -0700)
committerMike Turquette <mturquette@linaro.org>
Wed, 30 Apr 2014 18:51:48 +0000 (11:51 -0700)
The same if-else statement exists four times to recalculate the
rate of a clock. Consolidate this logic into a single function to
save some lines.

Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
drivers/clk/clk.c

index 453cf3d210d2556b41c93d89e89bde7a4968f7b8..3c02be74fd7c250fcd859edb2fe2a46cfd0de887 100644 (file)
@@ -1115,6 +1115,13 @@ long clk_get_accuracy(struct clk *clk)
 }
 EXPORT_SYMBOL_GPL(clk_get_accuracy);
 
+static unsigned long clk_recalc(struct clk *clk, unsigned long parent_rate)
+{
+       if (clk->ops->recalc_rate)
+               return clk->ops->recalc_rate(clk->hw, parent_rate);
+       return parent_rate;
+}
+
 /**
  * __clk_recalc_rates
  * @clk: first clk in the subtree
@@ -1140,10 +1147,7 @@ static void __clk_recalc_rates(struct clk *clk, unsigned long msg)
        if (clk->parent)
                parent_rate = clk->parent->rate;
 
-       if (clk->ops->recalc_rate)
-               clk->rate = clk->ops->recalc_rate(clk->hw, parent_rate);
-       else
-               clk->rate = parent_rate;
+       clk->rate = clk_recalc(clk, parent_rate);
 
        /*
         * ignore NOTIFY_STOP and NOTIFY_BAD return values for POST_RATE_CHANGE
@@ -1334,10 +1338,7 @@ static int __clk_speculate_rates(struct clk *clk, unsigned long parent_rate)
        unsigned long new_rate;
        int ret = NOTIFY_DONE;
 
-       if (clk->ops->recalc_rate)
-               new_rate = clk->ops->recalc_rate(clk->hw, parent_rate);
-       else
-               new_rate = parent_rate;
+       new_rate = clk_recalc(clk, parent_rate);
 
        /* abort rate change if a driver returns NOTIFY_BAD or NOTIFY_STOP */
        if (clk->notifier_count)
@@ -1373,10 +1374,7 @@ static void clk_calc_subtree(struct clk *clk, unsigned long new_rate,
                new_parent->new_child = clk;
 
        hlist_for_each_entry(child, &clk->children, child_node) {
-               if (child->ops->recalc_rate)
-                       child->new_rate = child->ops->recalc_rate(child->hw, new_rate);
-               else
-                       child->new_rate = new_rate;
+               child->new_rate = clk_recalc(child, new_rate);
                clk_calc_subtree(child, child->new_rate, NULL, 0);
        }
 }
@@ -1524,10 +1522,7 @@ static void clk_change_rate(struct clk *clk)
        if (!skip_set_rate && clk->ops->set_rate)
                clk->ops->set_rate(clk->hw, clk->new_rate, best_parent_rate);
 
-       if (clk->ops->recalc_rate)
-               clk->rate = clk->ops->recalc_rate(clk->hw, best_parent_rate);
-       else
-               clk->rate = best_parent_rate;
+       clk->rate = clk_recalc(clk, best_parent_rate);
 
        if (clk->notifier_count && old_rate != clk->rate)
                __clk_notify(clk, POST_RATE_CHANGE, old_rate, clk->rate);