clk: mmp: try to use closer one when do round rate
authorChao Xie <chao.xie@marvell.com>
Thu, 23 Jan 2014 02:47:42 +0000 (10:47 +0800)
committerMike Turquette <mturquette@linaro.org>
Thu, 27 Mar 2014 03:59:27 +0000 (20:59 -0700)
The orignal code will use the bigger rate between
"previous rate" and "current rate" when caculate the
rate.
In fact, hardware cares about the closest one.
So choose the closer rate between "previous rate" and
"current rate".

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

index 5863a37ec84d9a7a20371abd7f9b198c98577b26..23a56f561812decc149624fe72b803a7bbb726ab 100644 (file)
@@ -45,10 +45,14 @@ static long clk_factor_round_rate(struct clk_hw *hw, unsigned long drate,
                if (rate > drate)
                        break;
        }
-       if ((i == 0) || (i == factor->ftbl_cnt))
+       if ((i == 0) || (i == factor->ftbl_cnt)) {
                return rate;
-       else
-               return prev_rate;
+       } else {
+               if ((drate - prev_rate) > (rate - drate))
+                       return rate;
+               else
+                       return prev_rate;
+       }
 }
 
 static unsigned long clk_factor_recalc_rate(struct clk_hw *hw,