clk: divider: fix rate calculation for fractional rates
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Thu, 13 Feb 2014 10:03:59 +0000 (12:03 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 8 Dec 2014 19:26:01 +0000 (19:26 +0000)
commite6da086ba98a0d5d6b1840f9221a257b2c03e104
tree63bdefdbd4f8aaabfafd2e32152fffb9b6ca6d5d
parent8bb495e3f02401ee6f76d1b1d77f3ac9f079e376
clk: divider: fix rate calculation for fractional rates

clk-divider.c does not calculate the rates consistently at the moment.

As an example, on OMAP3 we have a clock divider with a source clock of
864000000 Hz. With dividers 6, 7 and 8 the theoretical rates are:

6: 144000000
7: 123428571.428571...
8: 108000000

Calling clk_round_rate() with the rate in the first column will give the
rate in the second column:

144000000 -> 144000000
143999999 -> 123428571
123428572 -> 123428571
123428571 -> 108000000

Note how clk_round_rate() returns 123428571 for rates from 123428572 to
143999999, which is mathematically correct, but when clk_round_rate() is
called with 123428571, the returned value is surprisingly 108000000.

This means that the following code works a bit oddly:

rate = clk_round_rate(clk, 123428572);
clk_set_rate(clk, rate);

As clk_set_rate() also does clock rate rounding, the result is that the
clock is set to the rate of 108000000, not 123428571 returned by the
clk_round_rate.

This patch changes the clk-divider.c to use DIV_ROUND_UP when
calculating the rate. This gives the following behavior which fixes the
inconsistency:

144000000 -> 144000000
143999999 -> 123428572
123428572 -> 123428572
123428571 -> 108000000

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
(cherry picked from commit b11d282dbea27db1788893115dfca8a7856bf205)
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/clk/clk-divider.c