diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2015-02-21 05:40:23 -0500 |
---|---|---|
committer | Michael Turquette <mturquette@linaro.org> | 2015-03-09 17:19:27 -0400 |
commit | da321133b53caf7889ed3ca1dabe4cc368db2604 (patch) | |
tree | 8684dc2cedc502ebd6066418833d4a59ad4c6e2a | |
parent | 2f7bf4af5c8177f6a27d9b67efdeb48f5bdbf821 (diff) |
clk: divider: fix calculation of maximal parent rate for a given divider
The rate provided at the output of a clk-divider is calculated as:
DIV_ROUND_UP(parent_rate, div)
since commit b11d282dbea2 (clk: divider: fix rate calculation for
fractional rates). So to yield a rate not bigger than r parent_rate
must be <= r * div.
The effect of choosing a parent rate that is too big as was done before
this patch results in wrongly ruling out good dividers.
Note that this is not a complete fix as __clk_round_rate might return a
value >= its 2nd parameter. Also for dividers with
CLK_DIVIDER_ROUND_CLOSEST set the calculation is not accurate. But this
fixes the test case by Sascha Hauer that uses a chain of three dividers
under a fixed clock.
Fixes: b11d282dbea2 (clk: divider: fix rate calculation for fractional rates)
Suggested-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Michael Turquette <mturquette@linaro.org>
-rw-r--r-- | drivers/clk/clk-divider.c | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index eff8a862eb08..a1a029092c8d 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c | |||
@@ -144,12 +144,6 @@ static unsigned long clk_divider_recalc_rate(struct clk_hw *hw, | |||
144 | divider->flags); | 144 | divider->flags); |
145 | } | 145 | } |
146 | 146 | ||
147 | /* | ||
148 | * The reverse of DIV_ROUND_UP: The maximum number which | ||
149 | * divided by m is r | ||
150 | */ | ||
151 | #define MULT_ROUND_UP(r, m) ((r) * (m) + (m) - 1) | ||
152 | |||
153 | static bool _is_valid_table_div(const struct clk_div_table *table, | 147 | static bool _is_valid_table_div(const struct clk_div_table *table, |
154 | unsigned int div) | 148 | unsigned int div) |
155 | { | 149 | { |
@@ -313,7 +307,7 @@ static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate, | |||
313 | return i; | 307 | return i; |
314 | } | 308 | } |
315 | parent_rate = __clk_round_rate(__clk_get_parent(hw->clk), | 309 | parent_rate = __clk_round_rate(__clk_get_parent(hw->clk), |
316 | MULT_ROUND_UP(rate, i)); | 310 | rate * i); |
317 | now = DIV_ROUND_UP(parent_rate, i); | 311 | now = DIV_ROUND_UP(parent_rate, i); |
318 | if (_is_best_div(rate, now, best, flags)) { | 312 | if (_is_best_div(rate, now, best, flags)) { |
319 | bestdiv = i; | 313 | bestdiv = i; |