diff options
author | Maxime COQUELIN <maxime.coquelin@st.com> | 2014-01-29 11:24:08 -0500 |
---|---|---|
committer | Mike Turquette <mturquette@linaro.org> | 2014-04-30 14:51:27 -0400 |
commit | 0e2de78ecdc842218a2b6c422bb4a8ff4d85d11f (patch) | |
tree | f73422d0e0433a890fe060b400fc528a2784d64b /drivers/clk/clk-divider.c | |
parent | 774b514390b1eb8476bc759262790762bd1ef45a (diff) |
clk: divider: Optimize clk_divider_bestdiv loop
Currently, the for-loop used to try all the different dividers to find the
one that best fit tries all the values from 1 to max_div, incrementing by one.
In case of power-of-two, or table based divider, the loop isn't optimal.
Instead of incrementing by one, this patch provides directly the next divider.
Signed-off-by: Maxime Coquelin <maxime.coquelin@st.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
Diffstat (limited to 'drivers/clk/clk-divider.c')
-rw-r--r-- | drivers/clk/clk-divider.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index c57294563a98..b3c83966be18 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c | |||
@@ -240,6 +240,18 @@ static bool _is_best_div(struct clk_divider *divider, | |||
240 | return now <= rate && now > best; | 240 | return now <= rate && now > best; |
241 | } | 241 | } |
242 | 242 | ||
243 | static int _next_div(struct clk_divider *divider, int div) | ||
244 | { | ||
245 | div++; | ||
246 | |||
247 | if (divider->flags & CLK_DIVIDER_POWER_OF_TWO) | ||
248 | return __roundup_pow_of_two(div); | ||
249 | if (divider->table) | ||
250 | return _round_up_table(divider->table, div); | ||
251 | |||
252 | return div; | ||
253 | } | ||
254 | |||
243 | static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate, | 255 | static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate, |
244 | unsigned long *best_parent_rate) | 256 | unsigned long *best_parent_rate) |
245 | { | 257 | { |
@@ -267,7 +279,7 @@ static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate, | |||
267 | */ | 279 | */ |
268 | maxdiv = min(ULONG_MAX / rate, maxdiv); | 280 | maxdiv = min(ULONG_MAX / rate, maxdiv); |
269 | 281 | ||
270 | for (i = 1; i <= maxdiv; i++) { | 282 | for (i = 1; i <= maxdiv; i = _next_div(divider, i)) { |
271 | if (!_is_valid_div(divider, i)) | 283 | if (!_is_valid_div(divider, i)) |
272 | continue; | 284 | continue; |
273 | if (rate * i == parent_rate_saved) { | 285 | if (rate * i == parent_rate_saved) { |