replaced hardcoded numbers with valid PLL limit values Signed-off-by: Vijay Purushothaman <vijay.a.purushothaman at intel.com> --- drivers/gpu/drm/i915/intel_display.c | 52 +++++++++++++-------------------- 1 files changed, 21 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 0707b7a..e2d23a3 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -865,69 +865,59 @@ intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc, intel_clock_t *best_clock) { u32 p1, p2, m1, m2, vco, bestn, bestm1, bestm2, bestp1, bestp2; - u32 m, n, fastclk, minvco, maxvco; + u32 m, n, fastclk; u32 updrate, minupdate, fracbits, p; unsigned long bestppm, ppm, absppm; - int dotclk; + int dotclk, flag; dotclk = target * 1000; - bestppm = 1000000; - ppm = 0; - absppm = 0; - + ppm = absppm = 0; fastclk = dotclk / (2*100); - minvco = limit->vco.min; - maxvco = limit->vco.max; updrate = 0; minupdate = 19200; fracbits = 1; - n = p = p1 = p2 = m = m1 = m2 = vco = bestn = 0; bestm1 = bestm2 = bestp1 = bestp2 = 0; - for(n = 1; n <= ((refclk) / minupdate); n++) { + /* based on hardware requirement, prefer smaller n to precision */ + for (n = limit->n.min; n <= ((refclk) / minupdate); n++) { updrate = refclk / n; - for (p1 = 3; p1 > 1; p1--) { - for (p2 = 21; p2 > 0; p2--) { + for (p1 = limit->p1.max; p1 > limit->p1.min; p1--) { + for (p2 = limit->p2.p2_fast+1; p2 > 0; p2--) { if (p2 > 10) p2 = p2 - 1; p = p1 * p2; - - for( m1=2; m1 <= 3; m1++) { + /* based on hardware requirement, prefer bigger m1,m2 values */ + for (m1 = limit->m1.min; m1 <= limit->m1.max; m1++) { m2 = (((2*(fastclk * p * n / m1 )) + refclk) / (2*refclk)); m = m1 * m2; vco = updrate * m; - if(vco >= minvco && vco < maxvco) { - ppm = 1000000 *((vco / p) - - fastclk) / - fastclk; - absppm = (ppm > 0)? ppm: (-ppm); - if (absppm < 100 && - ((p1 * p2) > - (bestp1 * bestp2))) { + if (vco >= limit->vco.min && vco < limit->vco.max) { + ppm = 1000000 * ((vco / p) - fastclk) / fastclk; + absppm = (ppm > 0) ? ppm : (-ppm); + if (absppm < 100 && ((p1 * p2) > (bestp1 * bestp2))) { bestppm = 0; - bestn = n; - bestm1 = m1; - bestm2 = m2; - bestp1 = p1; - bestp2 = p2; + flag = 1; } if (absppm < bestppm - 10) { bestppm = absppm; + flag = 1; + } + if (flag) { bestn = n; bestm1 = m1; bestm2 = m2; bestp1 = p1; bestp2 = p2; + flag = 0; } } } - } /* Next p2 */ - } /* Next p1 */ - }/* Next n */ - + } + } + } best_clock->n = bestn; best_clock->m1 = bestm1; best_clock->m2 = bestm2; -- 1.7.5.4