drm/sun4i: dotclock: Round to closest clock rate
[cascardo/linux.git] / drivers / gpu / drm / sun4i / sun4i_dotclock.c
index 3eb9978..d401156 100644 (file)
@@ -90,7 +90,8 @@ static long sun4i_dclk_round_rate(struct clk_hw *hw, unsigned long rate,
                        goto out;
                }
 
-               if ((rounded < ideal) && (rounded > best_parent)) {
+               if (abs(rate - rounded / i) <
+                   abs(rate - best_parent / best_div)) {
                        best_parent = rounded;
                        best_div = i;
                }