[Intel-gfx] [PATCH 2/2]i830_display.c:create corresponding functions to find best pll on different platform

Ma Ling ling.ma at intel.com
Thu Mar 5 07:15:37 CET 2009


According to reference spreadsheet, use different algorithms to find best pll.  

---
 src/i830_display.c |  111 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 92 insertions(+), 19 deletions(-)

diff --git a/src/i830_display.c b/src/i830_display.c
index 31f344f..98c6f4f 100644
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@ -67,9 +67,11 @@ typedef struct {
 
 #define INTEL_P2_NUM		      2
 
-typedef struct {
+typedef struct intel_limit {
     intel_range_t   dot, vco, n, m, m1, m2, p, p1;
     intel_p2_t	    p2;
+    Bool (* find_pll)(struct intel_limit *, xf86CrtcPtr,
+	              int, int, intel_clock_t *);
 } intel_limit_t;
 
 #define I8XX_DOT_MIN		  25000
@@ -236,6 +238,11 @@ typedef struct {
 #define IG4X_P2_DUA_LVDS_FAST           7
 #define IG4X_P2_DUA_LVDS_LIMIT          0
 
+static Bool I8xx_and_I9xx_find_pll(intel_limit_t * limit, xf86CrtcPtr crtc,
+	int target, int refclk, intel_clock_t *best_clock);
+static Bool IG4x_find_pll(intel_limit_t * limit, xf86CrtcPtr crtc,
+	int target, int refclk, intel_clock_t *best_clock);
+
 static const intel_limit_t intel_limits[] = {
     { /* INTEL_LIMIT_I8XX_DVO_DAC */
         .dot = { .min = I8XX_DOT_MIN,		.max = I8XX_DOT_MAX },
@@ -248,6 +255,7 @@ static const intel_limit_t intel_limits[] = {
         .p1  = { .min = I8XX_P1_MIN,		.max = I8XX_P1_MAX },
 	.p2  = { .dot_limit = I8XX_P2_SLOW_LIMIT,
 		 .p2_slow = I8XX_P2_SLOW,	.p2_fast = I8XX_P2_FAST },
+	.find_pll = I8xx_and_I9xx_find_pll,
     },
     { /* INTEL_LIMIT_I8XX_LVDS */
         .dot = { .min = I8XX_DOT_MIN,		.max = I8XX_DOT_MAX },
@@ -260,6 +268,7 @@ static const intel_limit_t intel_limits[] = {
         .p1  = { .min = I8XX_P1_LVDS_MIN,	.max = I8XX_P1_LVDS_MAX },
 	.p2  = { .dot_limit = I8XX_P2_SLOW_LIMIT,
 		 .p2_slow = I8XX_P2_LVDS_SLOW,	.p2_fast = I8XX_P2_LVDS_FAST },
+	.find_pll = I8xx_and_I9xx_find_pll,
     },
     { /* INTEL_LIMIT_I9XX_SDVO_DAC */
         .dot = { .min = I9XX_DOT_MIN,		.max = I9XX_DOT_MAX },
@@ -272,6 +281,7 @@ static const intel_limit_t intel_limits[] = {
         .p1  = { .min = I9XX_P1_MIN,		.max = I9XX_P1_MAX },
 	.p2  = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
 		 .p2_slow = I9XX_P2_SDVO_DAC_SLOW,	.p2_fast = I9XX_P2_SDVO_DAC_FAST },
+	.find_pll = I8xx_and_I9xx_find_pll,
     },
     { /* INTEL_LIMIT_I9XX_LVDS */
         .dot = { .min = I9XX_DOT_MIN,		.max = I9XX_DOT_MAX },
@@ -287,6 +297,7 @@ static const intel_limit_t intel_limits[] = {
 	 */
 	.p2  = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
 		 .p2_slow = I9XX_P2_LVDS_SLOW,	.p2_fast = I9XX_P2_LVDS_FAST },
+	.find_pll = I8xx_and_I9xx_find_pll,
     },
     { /* INTEL_LIMIT_IGD_SDVO */
         .dot = { .min = I9XX_DOT_MIN,		.max = I9XX_DOT_MAX},
@@ -299,6 +310,7 @@ static const intel_limit_t intel_limits[] = {
         .p1  = { .min = I9XX_P1_MIN,		.max = I9XX_P1_MAX },
 	.p2  = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
 		 .p2_slow = I9XX_P2_SDVO_DAC_SLOW,	.p2_fast = I9XX_P2_SDVO_DAC_FAST },
+	.find_pll = I8xx_and_I9xx_find_pll,
     },
     { /* INTEL_LIMIT_IGD_LVDS */
         .dot = { .min = I9XX_DOT_MIN,		.max = I9XX_DOT_MAX },
@@ -312,6 +324,7 @@ static const intel_limit_t intel_limits[] = {
 	/* IGD only supports single-channel mode. */
 	.p2  = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
 		 .p2_slow = I9XX_P2_LVDS_SLOW,	.p2_fast = I9XX_P2_LVDS_SLOW },
+	.find_pll = I8xx_and_I9xx_find_pll,
     },
     /* below parameter and function is for EagleLake and Cantig Chipset Family*/
     { /* INTEL_LIMIT_EL_AND_CTG_SDVO */
@@ -341,6 +354,7 @@ static const intel_limit_t intel_limits[] = {
 	    .p2_slow = IG4X_P2_HDMI_DAC_SLOW,
 	    .p2_fast = IG4X_P2_HDMI_DAC_FAST
 	},
+	.find_pll = IG4x_find_pll,
     },
     { /* INTEL_LIMIT_EL_AND_CTG_SIN_LVDS */
 	.dot = { .min = IG4X_DOT_SIN_LVDS_MIN,	.max = IG4X_DOT_SIN_LVDS_MAX },
@@ -355,6 +369,7 @@ static const intel_limit_t intel_limits[] = {
 	    .p2_slow = IG4X_P2_SIN_LVDS_SLOW,
 	    .p2_fast = IG4X_P2_SIN_LVDS_FAST
 	},
+	.find_pll = IG4x_find_pll,
     },
     { /* INTEL_LIMIT_EL_AND_CTG_DUA_LVDS */
 	.dot = { .min = IG4X_DOT_DUA_LVDS_MIN,  .max = IG4X_DOT_DUA_LVDS_MAX },
@@ -369,6 +384,7 @@ static const intel_limit_t intel_limits[] = {
 	    .p2_slow = IG4X_P2_DUA_LVDS_SLOW,
 	    .p2_fast = IG4X_P2_DUA_LVDS_FAST
 	},
+	.find_pll = IG4x_find_pll,
      },
 };
 
@@ -526,18 +542,12 @@ i830PllIsValid(xf86CrtcPtr crtc, intel_clock_t *clock)
     return TRUE;
 }
 
-/**
- * Returns a set of divisors for the desired target clock with the given
- * refclk, or FALSE.  The returned values represent the clock equation:
- * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
- */
-static Bool
-i830FindBestPLL(xf86CrtcPtr crtc, int target, int refclk, intel_clock_t *best_clock)
+static Bool I8xx_and_I9xx_find_pll(intel_limit_t * limit, xf86CrtcPtr crtc,
+	int target, int refclk, intel_clock_t *best_clock)
 {
     ScrnInfoPtr pScrn = crtc->scrn;
     I830Ptr pI830 = I830PTR(pScrn);
-    intel_clock_t   clock;
-    const intel_limit_t   *limit = intel_limit (crtc);
+    intel_clock_t clock;
     int err = target;
 
     if (i830PipeHasType(crtc, I830_OUTPUT_LVDS))
@@ -559,21 +569,20 @@ i830FindBestPLL(xf86CrtcPtr crtc, int target, int refclk, intel_clock_t *best_cl
 
     memset (best_clock, 0, sizeof (*best_clock));
 
-    for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) 
+    for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++)
     {
-	for (clock.m2 = limit->m2.min; clock.m2 <= limit->m2.max; clock.m2++)
+	for (clock.m2 = limit->m2.min;
+		clock.m2 < clock.m1 && clock.m2 <= limit->m2.max; clock.m2++)
 	{
-	    /* m1 is always 0 in IGD */
-	    if (clock.m2 >= clock.m1 && !IS_IGD(pI830))
-		break;
-	    for (clock.n = limit->n.min; clock.n <= limit->n.max; clock.n++) 
+	    for (clock.n = limit->n.min; clock.n <= limit->n.max; clock.n++)
 	    {
-		for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max; clock.p1++) 
+		for (clock.p1 = limit->p1.min;
+			clock.p1 <= limit->p1.max; clock.p1++)
 		{
 		    int this_err;
 
 		    intel_clock (pI830, refclk, &clock);
-		    
+
 		    if (!i830PllIsValid(crtc, &clock))
 			continue;
 
@@ -589,6 +598,63 @@ i830FindBestPLL(xf86CrtcPtr crtc, int target, int refclk, intel_clock_t *best_cl
     return (err != target);
 }
 
+static Bool IG4x_find_pll(intel_limit_t * limit, xf86CrtcPtr crtc,
+	int target, int refclk, intel_clock_t *best_clock)
+{
+    ScrnInfoPtr pScrn = crtc->scrn;
+    I830Ptr pI830 = I830PTR(pScrn);
+    intel_clock_t clock;
+    int  max_n;
+    Bool found = FALSE;
+    int err_most = target * 0.0048;
+
+    if (i830PipeHasType(crtc, I830_OUTPUT_LVDS))
+    {
+	/* For LVDS, if the panel is on, just rely on its current settings for
+	 * dual-channel.  We haven't figured out how to reliably set up
+	 * different single/dual channel state, if we even can.
+	 */
+	if ((INREG(LVDS) & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP)
+	    clock.p2 = limit->p2.p2_fast;
+	else
+	    clock.p2 = limit->p2.p2_slow;
+    } else {
+	if (target < limit->p2.dot_limit)
+	    clock.p2 = limit->p2.p2_slow;
+	else
+	    clock.p2 = limit->p2.p2_fast;
+    }
+
+    max_n = limit->n.max;
+    /* based on hardware requriment prefer smaller n to precision */
+    for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
+	/* based on hardware requirment prefere bigger m1,m2, p1*/
+	for (clock.m1 = limit->m1.max;
+		clock.m1 >= limit->m1.min; clock.m1--) {
+	    for (clock.m2 = limit->m2.max;
+		    clock.m2 >= limit->m2.min; clock.m2--) {
+		for (clock.p1 = limit->p1.max;
+			clock.p1 >= limit->p1.min; clock.p1--) {
+		    int this_err;
+
+		    intel_clock (pI830, refclk, &clock);
+		    if (!i830PllIsValid(crtc, &clock))
+			continue;
+		    this_err = abs(clock.dot - target) ;
+		    if (this_err < err_most && clock.n <= max_n) {
+			memcpy(best_clock, &clock, sizeof(intel_clock_t));
+			err_most = this_err;
+			/*chose smaller n*/
+			max_n = clock.n;
+			found = TRUE;
+		    }
+		}
+	    }
+	}
+    }
+    return found;
+}
+
 void
 i830WaitForVblank(ScrnInfoPtr pScreen)
 {
@@ -1457,6 +1523,7 @@ i830_crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
     uint32_t dpll = 0, fp = 0, dspcntr, pipeconf, lvds_bits = 0;
     Bool ok, is_sdvo = FALSE, is_dvo = FALSE;
     Bool is_crt = FALSE, is_lvds = FALSE, is_tv = FALSE;
+    intel_limit_t   *limit;
 
     /* Set up some convenient bools for what outputs are connected to
      * our pipe, used in DPLL setup.
@@ -1509,7 +1576,13 @@ i830_crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
 	refclk = 48000;
     }
 
-    ok = i830FindBestPLL(crtc, adjusted_mode->Clock, refclk, &clock);
+    /**
+     * Returns a set of divisors for the desired target clock with the given
+     * refclk, or FALSE.  The returned values represent the clock equation:
+     * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
+     */
+    limit = intel_limit (crtc);
+    ok = limit->find_pll(limit, crtc, adjusted_mode->Clock, refclk, &clock);
     if (!ok)
 	FatalError("Couldn't find PLL settings for mode!\n");
 
-- 
1.5.4.4






More information about the Intel-gfx mailing list