clk: mmp: fix the wrong calculation formula
authorChao Xie <chao.xie@marvell.com>
Thu, 23 Jan 2014 02:47:41 +0000 (10:47 +0800)
committerMike Turquette <mturquette@linaro.org>
Thu, 27 Mar 2014 03:59:27 +0000 (20:59 -0700)
The formula is numerator/denominator = Fin / (Fout * factor)
So
Fout = Fin * denominator / (numerator * factor).
Current clk_factor_round_rate and clk_factor_recalc_rate use
wrong formula. This patch will fix them.

Signed-off-by: Chao Xie <chao.xie@marvell.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
drivers/clk/mmp/clk-frac.c

index f6e7691c4efa814d1113606c3a5b8ffc6b3bea84..5863a37ec84d9a7a20371abd7f9b198c98577b26 100644 (file)
@@ -40,12 +40,12 @@ static long clk_factor_round_rate(struct clk_hw *hw, unsigned long drate,
 
        for (i = 0; i < factor->ftbl_cnt; i++) {
                prev_rate = rate;
-               rate = (((*prate / 10000) * factor->ftbl[i].num) /
-                       (factor->ftbl[i].den * factor->masks->factor)) * 10000;
+               rate = (((*prate / 10000) * factor->ftbl[i].den) /
+                       (factor->ftbl[i].num * factor->masks->factor)) * 10000;
                if (rate > drate)
                        break;
        }
-       if (i == 0)
+       if ((i == 0) || (i == factor->ftbl_cnt))
                return rate;
        else
                return prev_rate;
@@ -85,8 +85,8 @@ static int clk_factor_set_rate(struct clk_hw *hw, unsigned long drate,
 
        for (i = 0; i < factor->ftbl_cnt; i++) {
                prev_rate = rate;
-               rate = (((prate / 10000) * factor->ftbl[i].num) /
-                       (factor->ftbl[i].den * factor->masks->factor)) * 10000;
+               rate = (((prate / 10000) * factor->ftbl[i].den) /
+                       (factor->ftbl[i].num * factor->masks->factor)) * 10000;
                if (rate > drate)
                        break;
        }