aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2015-02-21 05:40:25 -0500
committerMichael Turquette <mturquette@linaro.org>2015-03-09 17:20:17 -0400
commit9315514252a95bca37be3ef8a93f835ed91c2855 (patch)
treea417b7e7a6bb53985e43927518ae2e108ee01f95 /drivers/clk
parent26bac95aa88c2b1747808c0b885abe7814c0165d (diff)
clk: divider: fix calculation of initial best divider when rounding to closest
Similar to the reasoning for the previous commit DIV_ROUND_CLOSEST(parent_rate, rate) might not be the best integer divisor to get a good approximation for rate from parent_rate (given the metric for CLK_DIVIDER_ROUND_CLOSEST). For example assume a parent rate of 1000 Hz and a target rate of 700. Using DIV_ROUND_CLOSEST the suggested divisor gets calculated to 1 resulting in a target rate of 1000 with a delta of 300 to the desired rate. With choosing 2 as divisor however the resulting rate is 500 which is nearer to 700. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Acked-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Maxime Coquelin <maxime.coquelin@st.com> Signed-off-by: Michael Turquette <mturquette@linaro.org>
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/clk-divider.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index 78b2e656ff6a..25006a8bb8e6 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -219,17 +219,18 @@ static int _div_round_closest(const struct clk_div_table *table,
219 unsigned long parent_rate, unsigned long rate, 219 unsigned long parent_rate, unsigned long rate,
220 unsigned long flags) 220 unsigned long flags)
221{ 221{
222 int up, down, div; 222 int up, down;
223 unsigned long up_rate, down_rate; 223 unsigned long up_rate, down_rate;
224 224
225 up = down = div = DIV_ROUND_CLOSEST(parent_rate, rate); 225 up = DIV_ROUND_UP(parent_rate, rate);
226 down = parent_rate / rate;
226 227
227 if (flags & CLK_DIVIDER_POWER_OF_TWO) { 228 if (flags & CLK_DIVIDER_POWER_OF_TWO) {
228 up = __roundup_pow_of_two(div); 229 up = __roundup_pow_of_two(up);
229 down = __rounddown_pow_of_two(div); 230 down = __rounddown_pow_of_two(down);
230 } else if (table) { 231 } else if (table) {
231 up = _round_up_table(table, div); 232 up = _round_up_table(table, up);
232 down = _round_down_table(table, div); 233 down = _round_down_table(table, down);
233 } 234 }
234 235
235 up_rate = DIV_ROUND_UP(parent_rate, up); 236 up_rate = DIV_ROUND_UP(parent_rate, up);