Merge branch 'drm-next-3.15-wip' of git://people.freedesktop.org/~deathsimple/linux...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / radeon / radeon_display.c
index 776e03d6ac81a50136b45a25c7a3e207a4cd1bbd..2f7cbb901fb18c04c30c48e7357c23d01edc2529 100644 (file)
@@ -864,7 +864,7 @@ void radeon_compute_pll_avivo(struct radeon_pll *pll,
        unsigned post_div_min, post_div_max, post_div;
        unsigned ref_div_min, ref_div_max, ref_div;
        unsigned post_div_best, diff_best;
-       unsigned nom, den, tmp;
+       unsigned nom, den;
 
        /* determine allowed feedback divider range */
        fb_div_min = pll->min_feedback_div;
@@ -936,23 +936,27 @@ void radeon_compute_pll_avivo(struct radeon_pll *pll,
        }
        post_div = post_div_best;
 
+       /* limit reference * post divider to a maximum */
+       ref_div_max = min(210 / post_div, ref_div_max);
+
        /* get matching reference and feedback divider */
-       ref_div = max(den / post_div, 1u);
-       fb_div = nom;
+       ref_div = max(DIV_ROUND_CLOSEST(den, post_div), 1u);
+       fb_div = DIV_ROUND_CLOSEST(nom * ref_div * post_div, den);
 
        /* we're almost done, but reference and feedback
           divider might be to large now */
 
-       tmp = ref_div;
+       nom = fb_div;
+       den = ref_div;
 
         if (fb_div > fb_div_max) {
-               ref_div = ref_div * fb_div_max / fb_div;
+               ref_div = DIV_ROUND_CLOSEST(den * fb_div_max, nom);
                fb_div = fb_div_max;
        }
 
        if (ref_div > ref_div_max) {
                ref_div = ref_div_max;
-               fb_div = nom * ref_div_max / tmp;
+               fb_div = DIV_ROUND_CLOSEST(nom * ref_div_max, den);
        }
 
        /* reduce the numbers to a simpler ratio once more */