aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk/clk.c
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2014-03-26 19:06:36 -0400
committerMike Turquette <mturquette@linaro.org>2014-04-30 14:51:48 -0400
commit8f2c2db132cf5f4ffb4b9702ddb7e6bc5a343814 (patch)
tree3cbf9723124a52478c2cb424abf1705a5d0240e0 /drivers/clk/clk.c
parent86a612349fa58467cd63b30748114ec377d61807 (diff)
clk: Consolidate recalc rate logic
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>
Diffstat (limited to 'drivers/clk/clk.c')
-rw-r--r--drivers/clk/clk.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 453cf3d210d2..3c02be74fd7c 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1115,6 +1115,13 @@ long clk_get_accuracy(struct clk *clk)
1115} 1115}
1116EXPORT_SYMBOL_GPL(clk_get_accuracy); 1116EXPORT_SYMBOL_GPL(clk_get_accuracy);
1117 1117
1118static unsigned long clk_recalc(struct clk *clk, unsigned long parent_rate)
1119{
1120 if (clk->ops->recalc_rate)
1121 return clk->ops->recalc_rate(clk->hw, parent_rate);
1122 return parent_rate;
1123}
1124
1118/** 1125/**
1119 * __clk_recalc_rates 1126 * __clk_recalc_rates
1120 * @clk: first clk in the subtree 1127 * @clk: first clk in the subtree
@@ -1140,10 +1147,7 @@ static void __clk_recalc_rates(struct clk *clk, unsigned long msg)
1140 if (clk->parent) 1147 if (clk->parent)
1141 parent_rate = clk->parent->rate; 1148 parent_rate = clk->parent->rate;
1142 1149
1143 if (clk->ops->recalc_rate) 1150 clk->rate = clk_recalc(clk, parent_rate);
1144 clk->rate = clk->ops->recalc_rate(clk->hw, parent_rate);
1145 else
1146 clk->rate = parent_rate;
1147 1151
1148 /* 1152 /*
1149 * ignore NOTIFY_STOP and NOTIFY_BAD return values for POST_RATE_CHANGE 1153 * 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)
1334 unsigned long new_rate; 1338 unsigned long new_rate;
1335 int ret = NOTIFY_DONE; 1339 int ret = NOTIFY_DONE;
1336 1340
1337 if (clk->ops->recalc_rate) 1341 new_rate = clk_recalc(clk, parent_rate);
1338 new_rate = clk->ops->recalc_rate(clk->hw, parent_rate);
1339 else
1340 new_rate = parent_rate;
1341 1342
1342 /* abort rate change if a driver returns NOTIFY_BAD or NOTIFY_STOP */ 1343 /* abort rate change if a driver returns NOTIFY_BAD or NOTIFY_STOP */
1343 if (clk->notifier_count) 1344 if (clk->notifier_count)
@@ -1373,10 +1374,7 @@ static void clk_calc_subtree(struct clk *clk, unsigned long new_rate,
1373 new_parent->new_child = clk; 1374 new_parent->new_child = clk;
1374 1375
1375 hlist_for_each_entry(child, &clk->children, child_node) { 1376 hlist_for_each_entry(child, &clk->children, child_node) {
1376 if (child->ops->recalc_rate) 1377 child->new_rate = clk_recalc(child, new_rate);
1377 child->new_rate = child->ops->recalc_rate(child->hw, new_rate);
1378 else
1379 child->new_rate = new_rate;
1380 clk_calc_subtree(child, child->new_rate, NULL, 0); 1378 clk_calc_subtree(child, child->new_rate, NULL, 0);
1381 } 1379 }
1382} 1380}
@@ -1524,10 +1522,7 @@ static void clk_change_rate(struct clk *clk)
1524 if (!skip_set_rate && clk->ops->set_rate) 1522 if (!skip_set_rate && clk->ops->set_rate)
1525 clk->ops->set_rate(clk->hw, clk->new_rate, best_parent_rate); 1523 clk->ops->set_rate(clk->hw, clk->new_rate, best_parent_rate);
1526 1524
1527 if (clk->ops->recalc_rate) 1525 clk->rate = clk_recalc(clk, best_parent_rate);
1528 clk->rate = clk->ops->recalc_rate(clk->hw, best_parent_rate);
1529 else
1530 clk->rate = best_parent_rate;
1531 1526
1532 if (clk->notifier_count && old_rate != clk->rate) 1527 if (clk->notifier_count && old_rate != clk->rate)
1533 __clk_notify(clk, POST_RATE_CHANGE, old_rate, clk->rate); 1528 __clk_notify(clk, POST_RATE_CHANGE, old_rate, clk->rate);