xf86-video-intel: Branch 'modesetting' - 3 commits - src/i830_display.c src/i830_driver.c src/i830_gtf.c src/i830.h src/i830_modes.c src/i830_randr.c src/Makefile.am

Eric Anholt anholt at kemper.freedesktop.org
Sat Jun 24 09:32:05 EEST 2006


 src/Makefile.am    |    1 
 src/i830.h         |   10 
 src/i830_display.c |   38 ++
 src/i830_driver.c  |  214 ----------------
 src/i830_gtf.c     |  356 ++++++++++++++++++++++++++
 src/i830_modes.c   |  706 +++++++++++++++++++++++++++++++++++++++++++----------
 src/i830_randr.c   |    3 
 7 files changed, 987 insertions(+), 341 deletions(-)

New commits:
diff-tree f5e5f8aeddb3e0d6d073471aeff6176fb54576e2 (from 89791914d2a78f19f4f60ca370d387e5b1ccfb46)
Author: Eric Anholt <anholt at FreeBSD.org>
Date:   Fri Jun 23 23:29:55 2006 -0700

    WIP to allow re-probing and validation of modes for new heads at "xrandr" time.
    
    Now, DDC modes always end up being preferred to custom modelines, even if
    smaller.  This should probably be fixed by inserting custom modelines into
    the probed mode list if they're valid according to the probed parameters of the
    monitor.
    
    Too much code is lifted from static functions in xf86Mode.c, and those should be
    made unstatic if possible.  Using xf86ValidateModes is also rather hacky, and
    I want to break the function down, but this is a first step.

diff --git a/src/i830.h b/src/i830.h
index 59f563f..c4a4771 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -595,7 +595,7 @@ extern Bool I830RandRInit(ScreenPtr pScr
 extern Bool I830I2CInit(ScrnInfoPtr pScrn, I2CBusPtr *bus_ptr, int i2c_reg,
 			char *name);
 /* i830_modes.c */
-int I830ValidateXF86ModeList(ScrnInfoPtr pScrn);
+int I830ValidateXF86ModeList(ScrnInfoPtr pScrn, Bool first_time);
 
 /* i830_gtf.c */
 DisplayModePtr i830GetGTF(int h_pixels, int v_lines, float freq,
diff --git a/src/i830_display.c b/src/i830_display.c
index 8843f98..50f4940 100644
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@ -262,6 +262,44 @@ i830PipeSetMode(ScrnInfoPtr pScrn, Displ
     int refclk, pixel_clock, sdvo_pixel_multiply;
     int outputs;
 
+    assert(pMode->VRefresh != 0.0);
+    /* If we've got a list of modes probed for the device, find the best match
+     * in there to the requested mode.
+     */
+    if (pI830->pipeModes[pipe] != NULL) {
+	DisplayModePtr pBest = NULL, pScan;
+
+	assert(pScan->VRefresh != 0.0);
+	for (pScan = pI830->pipeModes[pipe]; pScan != NULL; pScan = pScan->next)
+	{
+	    /* Reject if it's larger than the desired mode. */
+	    if (pScan->HDisplay > pMode->HDisplay ||
+		pScan->VDisplay > pMode->VDisplay)
+	    {
+		continue;
+	    }
+	    if (pBest == NULL) {
+		pBest = pScan;
+	        continue;
+	    }
+	    /* Find if it's closer than the current best option */
+	    if (abs(pScan->VRefresh - pMode->VRefresh) >
+		abs(pBest->VRefresh - pMode->VRefresh))
+	    {
+		continue;
+	    }
+	}
+	if (pBest != NULL) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		       "Choosing pipe's mode %p (%dx%dx%.1f) instead of xf86 "
+		       "mode %p (%dx%dx%.1f)\n", pBest,
+		       pBest->HDisplay, pBest->VDisplay, pBest->VRefresh,
+		       pMode,
+		       pMode->HDisplay, pMode->VDisplay, pMode->VRefresh);
+	    pMode = pBest;
+	}
+    }
+
     ErrorF("Requested pix clock: %d\n", pMode->Clock);
 
     if (pipe == 0)
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 75f9e4b..32beb8a 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2217,23 +2217,19 @@ I830BIOSPreInit(ScrnInfoPtr pScrn, int f
 
      pI830->MaxClock = 300000;
 
-   n = I830ValidateXF86ModeList(pScrn);
+   n = I830ValidateXF86ModeList(pScrn, TRUE);
    if (n <= 0) {
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
       PreInitCleanup(pScrn);
       return FALSE;
    }	
 
-   xf86PruneDriverModes(pScrn);
-
    if (pScrn->modes == NULL) {
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
       PreInitCleanup(pScrn);
       return FALSE;
    }
 
-   xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V);
-
    /*
     * Fix up modes to make hblank start at hsync start.
     * I don't know why the xf86 code mangles this...
diff --git a/src/i830_modes.c b/src/i830_modes.c
index 6f878a5..faa843e 100644
--- a/src/i830_modes.c
+++ b/src/i830_modes.c
@@ -1,6 +1,7 @@
 #define DEBUG_VERB 2
 /*
  * Copyright © 2002 David Dawes
+ * Copyright © 2006 Intel Corporation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -26,6 +27,7 @@
  * the author(s).
  *
  * Authors: David Dawes <dawes at xfree86.org>
+ *	    Eric Anholt <eric.anholt at intel.com>
  *
  * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/vbe/vbeModes.c,v 1.6 2002/11/02 01:38:25 dawes Exp $
  */
@@ -197,6 +199,30 @@ I830xf86SortModes(DisplayModePtr *new, D
     }
 }
 
+/**
+ * Calculates the vertical refresh of a mode.
+ *
+ * Taken directly from xf86Mode.c, and should be put back there --Eric Anholt
+ */
+static double
+I830ModeVRefresh(DisplayModePtr mode)
+{
+    double refresh = 0.0;
+
+    if (mode->VRefresh > 0.0)
+	refresh = mode->VRefresh;
+    else if (mode->HTotal > 0 && mode->VTotal > 0) {
+	refresh = mode->Clock * 1000.0 / mode->HTotal / mode->VTotal;
+	if (mode->Flags & V_INTERLACE)
+	    refresh *= 2.0;
+	if (mode->Flags & V_DBLSCAN)
+	    refresh /= 2.0;
+	if (mode->VScan > 1)
+	    refresh /= (float)(mode->VScan);
+    }
+    return refresh;
+}
+
 DisplayModePtr I830GetDDCModes(ScrnInfoPtr pScrn, xf86MonPtr ddc)
 {
     DisplayModePtr  p;
@@ -552,6 +578,97 @@ I830InjectProbedModes(ScrnInfoPtr pScrn,
     return count;
 }
 
+/*
+ * I830xf86SetModeCrtc
+ *
+ * Initialises the Crtc parameters for a mode.  The initialisation includes
+ * adjustments for interlaced and double scan modes.
+ *
+ * Taken directly from xf86Mode.c:xf86SetModeCrtc -- Eric Anholt
+ *   (and it should be put back there!)
+ */
+static void
+I830xf86SetModeCrtc(DisplayModePtr p, int adjustFlags)
+{
+    if ((p == NULL) || ((p->type & M_T_CRTC_C) == M_T_BUILTIN))
+	return;
+
+    p->CrtcHDisplay             = p->HDisplay;
+    p->CrtcHSyncStart           = p->HSyncStart;
+    p->CrtcHSyncEnd             = p->HSyncEnd;
+    p->CrtcHTotal               = p->HTotal;
+    p->CrtcHSkew                = p->HSkew;
+    p->CrtcVDisplay             = p->VDisplay;
+    p->CrtcVSyncStart           = p->VSyncStart;
+    p->CrtcVSyncEnd             = p->VSyncEnd;
+    p->CrtcVTotal               = p->VTotal;
+    if (p->Flags & V_INTERLACE) {
+	if (adjustFlags & INTERLACE_HALVE_V) {
+	    p->CrtcVDisplay         /= 2;
+	    p->CrtcVSyncStart       /= 2;
+	    p->CrtcVSyncEnd         /= 2;
+	    p->CrtcVTotal           /= 2;
+	}
+	/* Force interlaced modes to have an odd VTotal */
+	/* maybe we should only do this when INTERLACE_HALVE_V is set? */
+	p->CrtcVTotal |= 1;
+    }
+
+    if (p->Flags & V_DBLSCAN) {
+        p->CrtcVDisplay         *= 2;
+        p->CrtcVSyncStart       *= 2;
+        p->CrtcVSyncEnd         *= 2;
+        p->CrtcVTotal           *= 2;
+    }
+    if (p->VScan > 1) {
+        p->CrtcVDisplay         *= p->VScan;
+        p->CrtcVSyncStart       *= p->VScan;
+        p->CrtcVSyncEnd         *= p->VScan;
+        p->CrtcVTotal           *= p->VScan;
+    }
+    p->CrtcHAdjusted = FALSE;
+    p->CrtcVAdjusted = FALSE;
+
+    /*
+     * XXX
+     *
+     * The following is taken from VGA, but applies to other cores as well.
+     */
+    p->CrtcVBlankStart = min(p->CrtcVSyncStart, p->CrtcVDisplay);
+    p->CrtcVBlankEnd = max(p->CrtcVSyncEnd, p->CrtcVTotal);
+    if ((p->CrtcVBlankEnd - p->CrtcVBlankStart) >= 127) {
+        /* 
+         * V Blanking size must be < 127.
+         * Moving blank start forward is safer than moving blank end
+         * back, since monitors clamp just AFTER the sync pulse (or in
+         * the sync pulse), but never before.
+         */
+        p->CrtcVBlankStart = p->CrtcVBlankEnd - 127;
+	/*
+	 * If VBlankStart is now > VSyncStart move VBlankStart
+	 * to VSyncStart using the maximum width that fits into
+	 * VTotal.
+	 */
+	if (p->CrtcVBlankStart > p->CrtcVSyncStart) {
+	    p->CrtcVBlankStart = p->CrtcVSyncStart;
+	    p->CrtcVBlankEnd = min(p->CrtcHBlankStart + 127, p->CrtcVTotal);
+	}
+    }
+    p->CrtcHBlankStart = min(p->CrtcHSyncStart, p->CrtcHDisplay);
+    p->CrtcHBlankEnd = max(p->CrtcHSyncEnd, p->CrtcHTotal);
+
+    if ((p->CrtcHBlankEnd - p->CrtcHBlankStart) >= 63 * 8) {
+        /*
+         * H Blanking size must be < 63*8. Same remark as above.
+         */
+        p->CrtcHBlankStart = p->CrtcHBlankEnd - 63 * 8;
+	if (p->CrtcHBlankStart > p->CrtcHSyncStart) {
+	    p->CrtcHBlankStart = p->CrtcHSyncStart;
+	    p->CrtcHBlankEnd = min(p->CrtcHBlankStart + 63 * 8, p->CrtcHTotal);
+	}
+    }
+}
+
 /**
  * Performs probing of modes available on the output connected to the given
  * pipe.
@@ -567,6 +684,7 @@ I830ReprobePipeModeList(ScrnInfoPtr pScr
     int output_index = -1;
     int i;
     int outputs;
+    DisplayModePtr pMode;
 
     while (pI830->pipeModes[pipe] != NULL)
 	xf86DeleteMode(&pI830->pipeModes[pipe], pI830->pipeModes[pipe]);
@@ -609,26 +727,108 @@ I830ReprobePipeModeList(ScrnInfoPtr pScr
 					       pI830->output[output_index].pDDCBus);
 	pI830->pipeModes[pipe] = I830GetDDCModes(pScrn,
 						 pI830->pipeMon[pipe]);
+
+	for (pMode = pI830->pipeModes[pipe]; pMode != NULL; pMode = pMode->next)
+	{
+	    I830xf86SetModeCrtc(pMode, INTERLACE_HALVE_V);
+	    pMode->VRefresh = I830ModeVRefresh(pMode);
+	}
     } else {
 	ErrorF("don't know how to get modes for this device.\n");
     }
+
+    /* Set the vertical refresh, which is used by the choose-best-mode-per-pipe
+     * code later on.
+     */
+    for (pMode = pI830->pipeModes[pipe]; pMode != NULL; pMode = pMode->next) {
+	pMode->VRefresh = I830ModeVRefresh(pMode);
+    }
 }
 
 /**
+ * This function removes a mode from a list of modes.  It should probably be
+ * moved to xf86Mode.c
+ *
+ * There are different types of mode lists:
+ *
+ *  - singly linked linear lists, ending in NULL
+ *  - doubly linked linear lists, starting and ending in NULL
+ *  - doubly linked circular lists
+ *
+ */
+
+static void
+I830xf86DeleteModeFromList(DisplayModePtr *modeList, DisplayModePtr mode)
+{
+    /* Catch the easy/insane cases */
+    if (modeList == NULL || *modeList == NULL || mode == NULL)
+	return;
+
+    /* If the mode is at the start of the list, move the start of the list */
+    if (*modeList == mode)
+	*modeList = mode->next;
+
+    /* If mode is the only one on the list, set the list to NULL */
+    if ((mode == mode->prev) && (mode == mode->next)) {
+	*modeList = NULL;
+    } else {
+	if ((mode->prev != NULL) && (mode->prev->next == mode))
+	    mode->prev->next = mode->next;
+	if ((mode->next != NULL) && (mode->next->prev == mode))
+	    mode->next->prev = mode->prev;
+    }
+}
+    
+/**
  * Probes for video modes on attached otuputs, and assembles a list to insert
  * into pScrn.
+ *
+ * \param first_time indicates that the memory layout has already been set up,
+ * 	  so displayWidth, virtualX, and virtualY shouldn't be touched.
+ *
+ * A SetMode must follow this call in order for operatingDevices to match the
+ * hardware's state, in case we detect a new output device.  
  */
 int
-I830ValidateXF86ModeList(ScrnInfoPtr pScrn)
+I830ValidateXF86ModeList(ScrnInfoPtr pScrn, Bool first_time)
 {
     I830Ptr pI830 = I830PTR(pScrn);
     ClockRangePtr clockRanges;
     int n, pipe;
+    DisplayModePtr saved_mode;
+    int saved_virtualX = 0, saved_virtualY = 0, saved_displayWidth = 0;
 
     for (pipe = 0; pipe < MAX_DISPLAY_PIPES; pipe++) {
 	I830ReprobePipeModeList(pScrn, pipe);
     }
 
+    /* If we've got a spare pipe, try to detect if a new CRT has been plugged
+     * in.
+     */
+    if ((pI830->operatingDevices & (PIPE_CRT | (PIPE_CRT << 8))) == 0) {
+	if ((pI830->operatingDevices & 0xff) == PIPE_NONE) {
+	    pI830->operatingDevices |= PIPE_CRT;
+	    I830ReprobePipeModeList(pScrn, 0);
+	    if (pI830->pipeModes[0] == NULL) {
+		/* No new output found. */
+		pI830->operatingDevices &= ~PIPE_CRT;
+	    } else {
+		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+			   "Enabled new CRT on pipe A\n");
+	    }
+	} else if (((pI830->operatingDevices >> 8) & 0xff) == PIPE_NONE) {
+	    pI830->operatingDevices |= PIPE_CRT << 8;
+	    I830ReprobePipeModeList(pScrn, 1);
+	    if (pI830->pipeModes[1] == NULL) {
+		/* No new output found. */
+		pI830->operatingDevices &= ~(PIPE_CRT << 8);
+	    } else {
+		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+			   "Enabled new CRT on pipe B\n");
+	    }
+	}
+    }
+
     /* XXX: Clean out modes previously injected by our driver */
 
     if (pI830->pipeModes[0] != NULL) {
@@ -652,23 +852,79 @@ I830ValidateXF86ModeList(ScrnInfoPtr pSc
     clockRanges->interlaceAllowed = TRUE;	/* XXX check this */
     clockRanges->doubleScanAllowed = FALSE;	/* XXX check this */
 
+    /* Remove the current mode from the modelist if we're re-validating, so we
+     * can find a new mode to map ourselves to afterwards.
+     */
+    saved_mode = pI830->currentMode;
+    if (saved_mode != NULL) {
+	I830xf86DeleteModeFromList(&pScrn->modes, saved_mode);
+    }
+
+    if (!first_time) {
+	saved_virtualX = pScrn->virtualX;
+	saved_virtualY = pScrn->virtualY;
+	saved_displayWidth = pScrn->displayWidth;
+    }
+
     /* Take the pScrn->monitor->Modes we've accumulated and validate them into
      * pScrn->modes.
+     * XXX: Should set up a scrp->monitor->DDC covering the union of the
+     *      capabilities of our pipes.
      */
     n = xf86ValidateModes(pScrn,
 			  pScrn->monitor->Modes, /* availModes */
 			  pScrn->display->modes, /* modeNames */
 			  clockRanges, /* clockRanges */
-			  NULL, /* linePitches */
+			  !first_time ? &pScrn->displayWidth : NULL, /* linePitches */
 			  320, /* minPitch */
 			  MAX_DISPLAY_PITCH, /* maxPitch */
 			  64 * pScrn->bitsPerPixel, /* pitchInc */
 			  200, /* minHeight */
 			  MAX_DISPLAY_HEIGHT, /* maxHeight */
-			  pScrn->display->virtualX, /* virtualX */
-			  pScrn->display->virtualY, /* virtualY */
+			  pScrn->virtualX, /* virtualX */
+			  pScrn->virtualY, /* virtualY */
 			  pI830->FbMapSize, /* apertureSize */
 			  LOOKUP_BEST_REFRESH /* strategy */);
 
+    if (!first_time) {
+	/* Restore things that may have been damaged by xf86ValidateModes. */
+	pScrn->virtualX = saved_virtualX;
+	pScrn->virtualY = saved_virtualY;
+	pScrn->displayWidth = saved_displayWidth;
+    }
+
+    /* Need to do xf86CrtcForModes so any user-configured modes are valid for
+     * non-LVDS.
+     */
+    xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V);
+
+    xf86PruneDriverModes(pScrn);
+
+    /* Try to find the closest equivalent of the previous mode pointer to switch
+     * to.
+     */
+    if (saved_mode != NULL) {
+	DisplayModePtr pBestMode = NULL, pMode;
+
+	/* XXX: Is finding a matching x/y res enough?  probably not. */
+	for (pMode = pScrn->modes; ; pMode = pMode->next) {
+	    if (pMode->HDisplay == saved_mode->HDisplay &&
+		pMode->VDisplay == saved_mode->VDisplay)
+	    {
+		ErrorF("found matching mode %p\n", pMode);
+		pBestMode = pMode;
+	    }
+	    if (pMode->next == pScrn->modes)
+		break;
+	}
+
+	if (pBestMode != NULL)
+		xf86SwitchMode(pScrn->pScreen, pBestMode);
+	else
+		FatalError("No suitable modes after re-probe\n");
+
+	xfree(saved_mode->name);
+	xfree(saved_mode);
+    }
     return n;
 }
diff --git a/src/i830_randr.c b/src/i830_randr.c
index 0311f2b..93c0519 100644
--- a/src/i830_randr.c
+++ b/src/i830_randr.c
@@ -79,6 +79,9 @@ I830RandRGetInfo (ScreenPtr pScreen, Rot
 	randrp->virtualY = scrp->virtualY;
     }
 
+    /* Re-probe the outputs for new monitors or modes */
+    I830ValidateXF86ModeList(scrp, FALSE);
+
     for (mode = scrp->modes; ; mode = mode->next)
     {
 	int refresh = I830RandRModeRefresh (mode);
diff-tree 89791914d2a78f19f4f60ca370d387e5b1ccfb46 (from bb4810521633b6c3db2fc7d01ddc71325583d265)
Author: Eric Anholt <anholt at FreeBSD.org>
Date:   Fri Jun 23 18:21:17 2006 -0700

    Split probed modes out per pipe, and union them into the available modes.
    
    This is the first stage of getting runtime monitor attachment.  The old i830
    GTF code is returned to use to provide suitable modelines for xf86ValidateModes
    in the LVDS case, even though the LVDS doesn't care about the modeline and just
    always programs its fixed values.

diff --git a/src/Makefile.am b/src/Makefile.am
index da48149..8970db1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -55,6 +55,7 @@ i810_drv_la_SOURCES = \
 	 i830_display.h \
          i830_driver.c \
          i830.h \
+         i830_gtf.c \
          i830_i2c.c \
          i830_io.c \
          i830_memory.c \
diff --git a/src/i830.h b/src/i830.h
index 26a0063..59f563f 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -399,9 +399,10 @@ typedef struct _I830Rec {
 
    /* [0] is Pipe A, [1] is Pipe B. */
    int availablePipes;
-   int pipeDevices[MAX_DISPLAY_PIPES];
    /* [0] is display plane A, [1] is display plane B. */
    int planeEnabled[MAX_DISPLAY_PIPES];
+   xf86MonPtr pipeMon[MAX_DISPLAY_PIPES];
+   DisplayModePtr pipeModes[MAX_DISPLAY_PIPES];
 
    /* Driver phase/state information */
    Bool preinit;
@@ -593,8 +594,12 @@ extern Rotation I830GetRotation(ScreenPt
 extern Bool I830RandRInit(ScreenPtr pScreen, int rotation);
 extern Bool I830I2CInit(ScrnInfoPtr pScrn, I2CBusPtr *bus_ptr, int i2c_reg,
 			char *name);
-int I830xf86ValidateDDCModes(ScrnInfoPtr pScrn1, char **ppModeName);
-int i830ValidateFPModes(ScrnInfoPtr pScrn, char **ppModeName);
+/* i830_modes.c */
+int I830ValidateXF86ModeList(ScrnInfoPtr pScrn);
+
+/* i830_gtf.c */
+DisplayModePtr i830GetGTF(int h_pixels, int v_lines, float freq,
+			  int interlaced, int margins);
 
 /*
  * 12288 is set as the maximum, chosen because it is enough for
diff --git a/src/i830_driver.c b/src/i830_driver.c
index f3cb186..75f9e4b 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1258,7 +1258,6 @@ I830BIOSPreInit(ScrnInfoPtr pScrn, int f
    int flags24;
    int i, n;
    char *s;
-   ClockRangePtr clockRanges;
    pointer pVBEModule = NULL;
    Bool enable, has_lvds;
    const char *chipname;
@@ -2218,50 +2217,7 @@ I830BIOSPreInit(ScrnInfoPtr pScrn, int f
 
      pI830->MaxClock = 300000;
 
-   /*
-     * Setup the ClockRanges, which describe what clock ranges are available,
-     * and what sort of modes they can be used for.
-     */
-    clockRanges = xnfcalloc(sizeof(ClockRange), 1);
-    clockRanges->next = NULL;
-    /* 25MHz appears to be the smallest that works. */
-    clockRanges->minClock = 25000;
-    clockRanges->maxClock = pI830->MaxClock;
-    clockRanges->clockIndex = -1;		/* programmable */
-    clockRanges->interlaceAllowed = TRUE;	/* XXX check this */
-    clockRanges->doubleScanAllowed = FALSE;	/* XXX check this */
-
-   if ( (pI830->pipe == 1 && pI830->operatingDevices & (PIPE_LFP << 8)) ||
-        (pI830->pipe == 0 && pI830->operatingDevices & PIPE_LFP) ) {
-      /* If we're outputting to an LFP, use the LFP mode validation that will
-       * rely on the scaler so that we can display any mode smaller than or the
-       * same size as the panel.
-       */
-      if (!has_lvds) {
-	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		    "Unable to locate panel information in BIOS VBT tables\n");
-         PreInitCleanup(pScrn);
-	 return FALSE;
-      }
-      n = i830ValidateFPModes(pScrn, pScrn->display->modes);
-   } else {
-      I830xf86ValidateDDCModes(pScrn, pScrn->display->modes);
-      /* XXX minPitch, minHeight are random numbers. */
-      n = xf86ValidateModes(pScrn,
-			    pScrn->monitor->Modes, /* availModes */
-			    pScrn->display->modes, /* modeNames */
-			    clockRanges, /* clockRanges */
-			    NULL, /* linePitches */
-			    320, /* minPitch */
-			    MAX_DISPLAY_PITCH, /* maxPitch */
-			    64 * pScrn->bitsPerPixel, /* pitchInc */
-			    200, /* minHeight */
-			    MAX_DISPLAY_HEIGHT, /* maxHeight */
-			    pScrn->display->virtualX, /* virtualX */
-			    pScrn->display->virtualY, /* virtualY */
-			    pI830->FbMapSize, /* apertureSize */
-			    LOOKUP_BEST_REFRESH /* strategy */);
-   }
+   n = I830ValidateXF86ModeList(pScrn);
    if (n <= 0) {
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
       PreInitCleanup(pScrn);
diff --git a/src/i830_gtf.c b/src/i830_gtf.c
new file mode 100644
index 0000000..2eff46a
--- /dev/null
+++ b/src/i830_gtf.c
@@ -0,0 +1,356 @@
+#define DEBUG_VERB 2
+/*
+ * Copyright © 2002 David Dawes
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the author(s) shall
+ * not be used in advertising or otherwise to promote the sale, use or other
+ * dealings in this Software without prior written authorization from
+ * the author(s).
+ *
+ * Authors: David Dawes <dawes at xfree86.org>
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/vbe/vbeModes.c,v 1.6 2002/11/02 01:38:25 dawes Exp $
+ */
+/*
+ * Modified by Alan Hourihane <alanh at tungstengraphics.com>
+ * to support extended BIOS modes for the Intel chipsets
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+#include "xf86.h"
+#include "vbe.h"
+#include "vbeModes.h"
+#include "i830.h"
+
+#include <math.h>
+
+#define rint(x) floor(x)
+
+#define MARGIN_PERCENT    1.8   /* % of active vertical image                */
+#define CELL_GRAN         8.0   /* assumed character cell granularity        */
+#define MIN_PORCH         1     /* minimum front porch                       */
+#define V_SYNC_RQD        3     /* width of vsync in lines                   */
+#define H_SYNC_PERCENT    8.0   /* width of hsync as % of total line         */
+#define MIN_VSYNC_PLUS_BP 550.0 /* min time of vsync + back porch (microsec) */
+#define M                 600.0 /* blanking formula gradient                 */
+#define C                 40.0  /* blanking formula offset                   */
+#define K                 128.0 /* blanking formula scaling factor           */
+#define J                 20.0  /* blanking formula scaling factor           */
+
+/* C' and M' are part of the Blanking Duty Cycle computation */
+
+#define C_PRIME           (((C - J) * K/256.0) + J)
+#define M_PRIME           (K/256.0 * M)
+
+extern const int i830refreshes[];
+
+DisplayModePtr
+i830GetGTF(int h_pixels, int v_lines, float freq, int interlaced, int margins)
+{
+    float h_pixels_rnd;
+    float v_lines_rnd;
+    float v_field_rate_rqd;
+    float top_margin;
+    float bottom_margin;
+    float interlace;
+    float h_period_est;
+    float vsync_plus_bp;
+    float v_back_porch;
+    float total_v_lines;
+    float v_field_rate_est;
+    float h_period;
+    float v_field_rate;
+    float v_frame_rate;
+    float left_margin;
+    float right_margin;
+    float total_active_pixels;
+    float ideal_duty_cycle;
+    float h_blank;
+    float total_pixels;
+    float pixel_freq;
+    float h_freq;
+
+    float h_sync;
+    float h_front_porch;
+    float v_odd_front_porch_lines;
+    char modename[20];
+    DisplayModePtr m;
+
+    m = xnfcalloc(sizeof(DisplayModeRec), 1);
+    
+    
+    /*  1. In order to give correct results, the number of horizontal
+     *  pixels requested is first processed to ensure that it is divisible
+     *  by the character size, by rounding it to the nearest character
+     *  cell boundary:
+     *
+     *  [H PIXELS RND] = ((ROUND([H PIXELS]/[CELL GRAN RND],0))*[CELLGRAN RND])
+     */
+    
+    h_pixels_rnd = rint((float) h_pixels / CELL_GRAN) * CELL_GRAN;
+    
+    
+    /*  2. If interlace is requested, the number of vertical lines assumed
+     *  by the calculation must be halved, as the computation calculates
+     *  the number of vertical lines per field. In either case, the
+     *  number of lines is rounded to the nearest integer.
+     *   
+     *  [V LINES RND] = IF([INT RQD?]="y", ROUND([V LINES]/2,0),
+     *                                     ROUND([V LINES],0))
+     */
+
+    v_lines_rnd = interlaced ?
+            rint((float) v_lines) / 2.0 :
+            rint((float) v_lines);
+    
+    /*  3. Find the frame rate required:
+     *
+     *  [V FIELD RATE RQD] = IF([INT RQD?]="y", [I/P FREQ RQD]*2,
+     *                                          [I/P FREQ RQD])
+     */
+
+    v_field_rate_rqd = interlaced ? (freq * 2.0) : (freq);
+
+    /*  4. Find number of lines in Top margin:
+     *
+     *  [TOP MARGIN (LINES)] = IF([MARGINS RQD?]="Y",
+     *          ROUND(([MARGIN%]/100*[V LINES RND]),0),
+     *          0)
+     */
+
+    top_margin = margins ? rint(MARGIN_PERCENT / 100.0 * v_lines_rnd) : (0.0);
+
+    /*  5. Find number of lines in Bottom margin:
+     *
+     *  [BOT MARGIN (LINES)] = IF([MARGINS RQD?]="Y",
+     *          ROUND(([MARGIN%]/100*[V LINES RND]),0),
+     *          0)
+     */
+
+    bottom_margin = margins ? rint(MARGIN_PERCENT/100.0 * v_lines_rnd) : (0.0);
+
+    /*  6. If interlace is required, then set variable [INTERLACE]=0.5:
+     *   
+     *  [INTERLACE]=(IF([INT RQD?]="y",0.5,0))
+     */
+
+    interlace = interlaced ? 0.5 : 0.0;
+
+    /*  7. Estimate the Horizontal period
+     *
+     *  [H PERIOD EST] = ((1/[V FIELD RATE RQD]) - [MIN VSYNC+BP]/1000000) /
+     *                    ([V LINES RND] + (2*[TOP MARGIN (LINES)]) +
+     *                     [MIN PORCH RND]+[INTERLACE]) * 1000000
+     */
+
+    h_period_est = (((1.0/v_field_rate_rqd) - (MIN_VSYNC_PLUS_BP/1000000.0))
+                    / (v_lines_rnd + (2*top_margin) + MIN_PORCH + interlace)
+                    * 1000000.0);
+
+    /*  8. Find the number of lines in V sync + back porch:
+     *
+     *  [V SYNC+BP] = ROUND(([MIN VSYNC+BP]/[H PERIOD EST]),0)
+     */
+
+    vsync_plus_bp = rint(MIN_VSYNC_PLUS_BP/h_period_est);
+
+    /*  9. Find the number of lines in V back porch alone:
+     *
+     *  [V BACK PORCH] = [V SYNC+BP] - [V SYNC RND]
+     *
+     *  XXX is "[V SYNC RND]" a typo? should be [V SYNC RQD]?
+     */
+    
+    v_back_porch = vsync_plus_bp - V_SYNC_RQD;
+    
+    /*  10. Find the total number of lines in Vertical field period:
+     *
+     *  [TOTAL V LINES] = [V LINES RND] + [TOP MARGIN (LINES)] +
+     *                    [BOT MARGIN (LINES)] + [V SYNC+BP] + [INTERLACE] +
+     *                    [MIN PORCH RND]
+     */
+
+    total_v_lines = v_lines_rnd + top_margin + bottom_margin + vsync_plus_bp +
+        interlace + MIN_PORCH;
+    
+    /*  11. Estimate the Vertical field frequency:
+     *
+     *  [V FIELD RATE EST] = 1 / [H PERIOD EST] / [TOTAL V LINES] * 1000000
+     */
+
+    v_field_rate_est = 1.0 / h_period_est / total_v_lines * 1000000.0;
+    
+    /*  12. Find the actual horizontal period:
+     *
+     *  [H PERIOD] = [H PERIOD EST] / ([V FIELD RATE RQD] / [V FIELD RATE EST])
+     */
+
+    h_period = h_period_est / (v_field_rate_rqd / v_field_rate_est);
+    
+    /*  13. Find the actual Vertical field frequency:
+     *
+     *  [V FIELD RATE] = 1 / [H PERIOD] / [TOTAL V LINES] * 1000000
+     */
+
+    v_field_rate = 1.0 / h_period / total_v_lines * 1000000.0;
+
+    /*  14. Find the Vertical frame frequency:
+     *
+     *  [V FRAME RATE] = (IF([INT RQD?]="y", [V FIELD RATE]/2, [V FIELD RATE]))
+     */
+
+    v_frame_rate = interlaced ? v_field_rate / 2.0 : v_field_rate;
+
+    /*  15. Find number of pixels in left margin:
+     *
+     *  [LEFT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y",
+     *          (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 /
+     *                   [CELL GRAN RND]),0)) * [CELL GRAN RND],
+     *          0))
+     */
+
+    left_margin = margins ?
+        rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN :
+        0.0;
+    
+    /*  16. Find number of pixels in right margin:
+     *
+     *  [RIGHT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y",
+     *          (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 /
+     *                   [CELL GRAN RND]),0)) * [CELL GRAN RND],
+     *          0))
+     */
+    
+    right_margin = margins ?
+        rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN :
+        0.0;
+    
+    /*  17. Find total number of active pixels in image and left and right
+     *  margins:
+     *
+     *  [TOTAL ACTIVE PIXELS] = [H PIXELS RND] + [LEFT MARGIN (PIXELS)] +
+     *                          [RIGHT MARGIN (PIXELS)]
+     */
+
+    total_active_pixels = h_pixels_rnd + left_margin + right_margin;
+    
+    /*  18. Find the ideal blanking duty cycle from the blanking duty cycle
+     *  equation:
+     *
+     *  [IDEAL DUTY CYCLE] = [C'] - ([M']*[H PERIOD]/1000)
+     */
+
+    ideal_duty_cycle = C_PRIME - (M_PRIME * h_period / 1000.0);
+    
+    /*  19. Find the number of pixels in the blanking time to the nearest
+     *  double character cell:
+     *
+     *  [H BLANK (PIXELS)] = (ROUND(([TOTAL ACTIVE PIXELS] *
+     *                               [IDEAL DUTY CYCLE] /
+     *                               (100-[IDEAL DUTY CYCLE]) /
+     *                               (2*[CELL GRAN RND])), 0))
+     *                       * (2*[CELL GRAN RND])
+     */
+
+    h_blank = rint(total_active_pixels *
+                   ideal_duty_cycle /
+                   (100.0 - ideal_duty_cycle) /
+                   (2.0 * CELL_GRAN)) * (2.0 * CELL_GRAN);
+    
+    /*  20. Find total number of pixels:
+     *
+     *  [TOTAL PIXELS] = [TOTAL ACTIVE PIXELS] + [H BLANK (PIXELS)]
+     */
+
+    total_pixels = total_active_pixels + h_blank;
+    
+    /*  21. Find pixel clock frequency:
+     *
+     *  [PIXEL FREQ] = [TOTAL PIXELS] / [H PERIOD]
+     */
+    
+    pixel_freq = total_pixels / h_period;
+    
+    /*  22. Find horizontal frequency:
+     *
+     *  [H FREQ] = 1000 / [H PERIOD]
+     */
+
+    h_freq = 1000.0 / h_period;
+    
+
+    /* Stage 1 computations are now complete; I should really pass
+       the results to another function and do the Stage 2
+       computations, but I only need a few more values so I'll just
+       append the computations here for now */
+
+    
+
+    /*  17. Find the number of pixels in the horizontal sync period:
+     *
+     *  [H SYNC (PIXELS)] =(ROUND(([H SYNC%] / 100 * [TOTAL PIXELS] /
+     *                             [CELL GRAN RND]),0))*[CELL GRAN RND]
+     */
+
+    h_sync = rint(H_SYNC_PERCENT/100.0 * total_pixels / CELL_GRAN) * CELL_GRAN;
+
+    /*  18. Find the number of pixels in the horizontal front porch period:
+     *
+     *  [H FRONT PORCH (PIXELS)] = ([H BLANK (PIXELS)]/2)-[H SYNC (PIXELS)]
+     */
+
+    h_front_porch = (h_blank / 2.0) - h_sync;
+
+    /*  36. Find the number of lines in the odd front porch period:
+     *
+     *  [V ODD FRONT PORCH(LINES)]=([MIN PORCH RND]+[INTERLACE])
+     */
+    
+    v_odd_front_porch_lines = MIN_PORCH + interlace;
+    
+    /* finally, pack the results in the DisplayMode struct */
+    
+    m->HDisplay  = (int) (h_pixels_rnd);
+    m->HSyncStart = (int) (h_pixels_rnd + h_front_porch);
+    m->HSyncEnd = (int) (h_pixels_rnd + h_front_porch + h_sync);
+    m->HTotal = (int) (total_pixels);
+
+    m->VDisplay  = (int) (v_lines_rnd);
+    m->VSyncStart = (int) (v_lines_rnd + v_odd_front_porch_lines);
+    m->VSyncEnd = (int) (int) (v_lines_rnd + v_odd_front_porch_lines + V_SYNC_RQD);
+    m->VTotal = (int) (total_v_lines);
+
+    m->Clock   = (int)(pixel_freq * 1000);
+    m->SynthClock   = m->Clock;
+    m->HSync = h_freq;
+    m->VRefresh = v_frame_rate /* freq */;
+
+    snprintf(modename, sizeof(modename), "%dx%d", m->HDisplay,m->VDisplay);
+    m->name = xnfstrdup(modename);
+
+    return (m);
+}
diff --git a/src/i830_modes.c b/src/i830_modes.c
index c0c258c..6f878a5 100644
--- a/src/i830_modes.c
+++ b/src/i830_modes.c
@@ -197,7 +197,7 @@ I830xf86SortModes(DisplayModePtr *new, D
     }
 }
 
-DisplayModePtr I830xf86DDCModes(ScrnInfoPtr pScrn)
+DisplayModePtr I830GetDDCModes(ScrnInfoPtr pScrn, xf86MonPtr ddc)
 {
     DisplayModePtr  p;
     DisplayModePtr  last  = NULL;
@@ -206,7 +206,9 @@ DisplayModePtr I830xf86DDCModes(ScrnInfo
     int             count = 0;
     int             j, tmp;
     char            stmp[32];
-    xf86MonPtr      ddc   = pScrn->monitor->DDC;
+
+    if (ddc == NULL)
+	return NULL;
 
     /* Go thru detailed timing table first */
     for (j = 0; j < 4; j++) {
@@ -327,30 +329,17 @@ DisplayModePtr I830xf86DDCModes(ScrnInfo
     }
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-	       "Total of %d mode(s) found.\n", count);
+	       "Total of %d DDC mode(s) found.\n", count);
 
     return first;
 }
 
-static void
-i830SetModeToPanelParameters(ScrnInfoPtr pScrn, DisplayModePtr pMode)
-{
-   I830Ptr pI830 = I830PTR(pScrn);
-
-   pMode->HTotal     = pI830->panel_fixed_hactive;
-   pMode->HSyncStart = pI830->panel_fixed_hactive + pI830->panel_fixed_hsyncoff;
-   pMode->HSyncEnd   = pMode->HSyncStart + pI830->panel_fixed_hsyncwidth;
-   pMode->VTotal     = pI830->panel_fixed_vactive;
-   pMode->VSyncStart = pI830->panel_fixed_vactive + pI830->panel_fixed_vsyncoff;
-   pMode->VSyncEnd   = pMode->VSyncStart + pI830->panel_fixed_vsyncwidth;
-   pMode->Clock      = pI830->panel_fixed_clock;
-}
-
 /**
  * This function returns a default mode for flat panels using the timing
  * information provided by the BIOS.
  */
-static DisplayModePtr i830FPNativeMode(ScrnInfoPtr pScrn)
+static DisplayModePtr
+i830FPNativeMode(ScrnInfoPtr pScrn)
 {
    I830Ptr pI830 = I830PTR(pScrn);
    DisplayModePtr  new;
@@ -366,7 +355,14 @@ static DisplayModePtr i830FPNativeMode(S
    strcpy(new->name, stmp);
    new->HDisplay   = pI830->PanelXRes;
    new->VDisplay   = pI830->PanelYRes;
-   i830SetModeToPanelParameters(pScrn, new);
+   new->HSyncStart = pI830->panel_fixed_hactive + pI830->panel_fixed_hsyncoff;
+   new->HSyncEnd   = new->HSyncStart + pI830->panel_fixed_hsyncwidth;
+   new->HTotal     = new->HSyncEnd + 1;
+   new->VSyncStart = pI830->panel_fixed_vactive + pI830->panel_fixed_vsyncoff;
+   new->VSyncEnd   = new->VSyncStart + pI830->panel_fixed_vsyncwidth;
+   new->VTotal     = new->VSyncEnd + 1;
+   new->Clock      = pI830->panel_fixed_clock;
+
    new->type       = M_T_USERDEF;
 
    pScrn->virtualX = MAX(pScrn->virtualX, pI830->PanelXRes);
@@ -380,10 +376,21 @@ static DisplayModePtr i830FPNativeMode(S
    return new;
 }
 
-/* FP mode validation routine for using panel fitting.
+/**
+ * FP automatic modelist creation routine for using panel fitting.
+ *
+ * Constructs modes for any resolution less than the panel size specified by the
+ * user, with the user flag set, plus standard VESA mode sizes without the user
+ * flag set (for randr).
+ *
+ * Modes will be faked to use GTF parameters, even though at the time of being
+ * programmed into the LVDS they'll end up being forced to the panel's fixed
+ * mode.
+ *
+ * \return doubly-linked list of modes.
  */
-int
-i830ValidateFPModes(ScrnInfoPtr pScrn, char **ppModeName)
+DisplayModePtr
+i830GetLVDSModes(ScrnInfoPtr pScrn, char **ppModeName)
 {
    I830Ptr pI830 = I830PTR(pScrn);
    DisplayModePtr  last       = NULL;
@@ -419,14 +426,8 @@ i830ValidateFPModes(ScrnInfoPtr pScrn, c
 	 continue;
       }
 
-      new             = xnfcalloc(1, sizeof(DisplayModeRec));
-      new->name       = xnfalloc(strlen(ppModeName[i]) + 1);
-      strcpy(new->name, ppModeName[i]);
-      new->HDisplay   = width;
-      new->VDisplay   = height;
-      new->type      |= M_T_USERDEF;
-
-      i830SetModeToPanelParameters(pScrn, new);
+      new = i830GetGTF(width, height, 60.0, FALSE, FALSE);
+      new->type |= M_T_USERDEF;
 
       new->next       = NULL;
       new->prev       = last;
@@ -437,21 +438,19 @@ i830ValidateFPModes(ScrnInfoPtr pScrn, c
       if (!first)
 	 first = new;
 
-      pScrn->display->virtualX = pScrn->virtualX = MAX(pScrn->virtualX, width);
-      pScrn->display->virtualY = pScrn->virtualY = MAX(pScrn->virtualY, height);
       count++;
       xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		 "Valid mode using panel fitting: %s\n", new->name);
    }
 
-   /* If all else fails, add the native mode */
+   /* If the user hasn't specified modes, add the native mode */
    if (!count) {
       first = last = i830FPNativeMode(pScrn);
       if (first)
 	 count = 1;
    }
 
-   /* add in all default vesa modes smaller than panel size, used for randr*/
+   /* add in all default vesa modes smaller than panel size, used for randr */
    for (p = pScrn->monitor->Modes; p && p->next; p = p->next->next) {
       if ((p->HDisplay <= pI830->PanelXRes) && (p->VDisplay <= pI830->PanelYRes)) {
 	 tmp = first;
@@ -460,13 +459,11 @@ i830ValidateFPModes(ScrnInfoPtr pScrn, c
 	       tmp = tmp->next;
 	 }
 	 if (!tmp) {
-	    new             = xnfcalloc(1, sizeof(DisplayModeRec));
-	    new->name       = xnfalloc(strlen(p->name) + 1);
-	    strcpy(new->name, p->name);
-	    new->HDisplay   = p->HDisplay;
-	    new->VDisplay   = p->VDisplay;
-	    i830SetModeToPanelParameters(pScrn, new);
-	    new->type      |= M_T_DEFAULT;
+	    new = i830GetGTF(p->HDisplay, p->VDisplay, 60.0, FALSE, FALSE);
+	    if (ppModeName[i] == NULL)
+		new->type |= M_T_USERDEF;
+	    else
+		new->type |= M_T_DEFAULT;
 
 	    new->next       = NULL;
 	    new->prev       = last;
@@ -476,166 +473,202 @@ i830ValidateFPModes(ScrnInfoPtr pScrn, c
 	    last = new;
 	    if (!first)
 	       first = new;
+
+	    count++;
 	 }
       }
    }
 
-   /* Close the doubly-linked mode list, if we found any usable modes */
-   if (last) {
-      last->next   = first;
-      first->prev  = last;
-      pScrn->modes = first;
-   }
-
    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 	      "Total number of valid FP mode(s) found: %d\n", count);
 
-   /* Adjust the display pitch to fit the modes we've come up with. */
-   pScrn->displayWidth = MAX(pScrn->displayWidth, pScrn->virtualX);
-   pScrn->displayWidth = (pScrn->displayWidth + 63) & ~63;
-
-   return count;
+   return first;
 }
 
-/* XFree86's xf86ValidateModes routine doesn't work well with DDC modes,
- * so here is our own validation routine.
+/**
+ * Allocates and returns a copy of pMode, including pointers within pMode.
  */
-int I830xf86ValidateDDCModes(ScrnInfoPtr pScrn1, char **ppModeName)
+static DisplayModePtr
+I830DuplicateMode(DisplayModePtr pMode)
 {
-    DisplayModePtr  p;
-    DisplayModePtr  last       = NULL;
-    DisplayModePtr  first      = NULL;
-    DisplayModePtr  ddcModes   = NULL;
-    int             count      = 0;
-    int             i, width, height;
-    ScrnInfoPtr pScrn = pScrn1;
-
-    pScrn->virtualX = pScrn1->display->virtualX;
-    pScrn->virtualY = pScrn1->display->virtualY;
-
-    if (pScrn->monitor->DDC) {
-	int  maxVirtX = pScrn->virtualX;
-	int  maxVirtY = pScrn->virtualY;
+    DisplayModePtr pNew;
 
-	/* Collect all of the DDC modes */
-	first = last = ddcModes = I830xf86DDCModes(pScrn);
+    pNew = xnfalloc(sizeof(DisplayModeRec));
+    *pNew = *pMode;
+    pNew->next = NULL;
+    pNew->prev = NULL;
+    pNew->name = xnfstrdup(pMode->name);
 
-	for (p = ddcModes; p; p = p->next) {
+    return pNew;
+}
 
-	    maxVirtX = MAX(maxVirtX, p->HDisplay);
-	    maxVirtY = MAX(maxVirtY, p->VDisplay);
-	    count++;
+/**
+ * Injects a list of probed modes into another mode list.
+ *
+ * Take the doubly-linked list of modes we've probed for the device, and injects
+ * it into the doubly-linked modeList.  We don't need to filter, because the
+ * eventual call to xf86ValidateModes will do this for us.  I think.
+ */
+int
+I830InjectProbedModes(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+		      char **ppModeName, DisplayModePtr addModes)
+{
+    DisplayModePtr  last = modeList;
+    DisplayModePtr  first = modeList;
+    DisplayModePtr  addMode;
+    int count = 0;
+
+    for (addMode = addModes; addMode != NULL; addMode = addMode->next) {
+	DisplayModePtr pNew;
+
+	/* XXX: Do we need to check if modeList already contains the same mode?
+	 */
+
+	pNew = I830DuplicateMode(addMode);
+	/* If the user didn't specify any modes, mark all modes as M_T_USERDEF
+	 * so that we can cycle through them, etc.  XXX: really need to?
+	 */
+	if (ppModeName[0] == NULL) {
+	    pNew->type |= M_T_USERDEF;
+	}
 
-	    last = p;
+	/* Insert pNew into modeList */
+	if (last) {
+	    last->next = pNew;
+	    pNew->prev = last;
+	} else {
+	    first = pNew;
+	    pNew->prev = NULL;
 	}
+	pNew->next = NULL;
+	last = pNew;
 
-	/* Match up modes that are specified in the XF86Config file */
-	if (ppModeName[0]) {
-	    DisplayModePtr  next;
-
-	    /* Reset the max virtual dimensions */
-	    maxVirtX = pScrn->virtualX;
-	    maxVirtY = pScrn->virtualY;
-
-	    /* Reset list */
-	    first = last = NULL;
-
-	    for (i = 0; ppModeName[i]; i++) {
-		/* FIXME: Use HDisplay and VDisplay instead of mode string */
-		if (sscanf(ppModeName[i], "%dx%d", &width, &height) == 2) {
-		    for (p = ddcModes; p; p = next) {
-			next = p->next;
-
-			if (p->HDisplay == width && p->VDisplay == height) {
-			    /* We found a DDC mode that matches the one
-                               requested in the XF86Config file */
-			    p->type |= M_T_USERDEF;
-
-			    /* Update  the max virtual setttings */
-			    maxVirtX = MAX(maxVirtX, width);
-			    maxVirtY = MAX(maxVirtY, height);
-
-			    /* Unhook from DDC modes */
-			    if (p->prev) p->prev->next = p->next;
-			    if (p->next) p->next->prev = p->prev;
-			    if (p == ddcModes) ddcModes = p->next;
-
-			    /* Add to used modes */
-			    if (last) {
-				last->next = p;
-				p->prev = last;
-			    } else {
-				first = p;
-				p->prev = NULL;
-			    }
-			    p->next = NULL;
-			    last = p;
+	count++;
+    }
 
-			    break;
-			}
-		    }
-		}
-	    }
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+	       "Injected %d modes detected from the monitor\n", count);
 
-	    /*
-	     * Add remaining DDC modes if they're smaller than the user
-	     * specified modes
-	     */
-	    for (p = ddcModes; p; p = next) {
-		next = p->next;
-		if (p->HDisplay <= maxVirtX && p->VDisplay <= maxVirtY) {
-		    /* Unhook from DDC modes */
-		    if (p->prev) p->prev->next = p->next;
-		    if (p->next) p->next->prev = p->prev;
-		    if (p == ddcModes) ddcModes = p->next;
-
-		    /* Add to used modes */
-		    if (last) {
-			last->next = p;
-			p->prev = last;
-		    } else {
-			first = p;
-			p->prev = NULL;
-		    }
-		    p->next = NULL;
-		    last = p;
-		}
-	    }
+    return count;
+}
 
-	    /* Delete unused modes */
-	    while (ddcModes)
-		xf86DeleteMode(&ddcModes, ddcModes);
-	} else {
-	    /*
-	     * No modes were configured, so we make the DDC modes
-	     * available for the user to cycle through.
-	     */
-	    for (p = ddcModes; p; p = p->next)
-		p->type |= M_T_USERDEF;
+/**
+ * Performs probing of modes available on the output connected to the given
+ * pipe.
+ *
+ * We do not support multiple outputs per pipe (since the cases for that are
+ * sufficiently rare we can't imagine the complexity being worth it), so
+ * the pipe is a sufficient specifier.
+ */
+static void
+I830ReprobePipeModeList(ScrnInfoPtr pScrn, int pipe)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    int output_index = -1;
+    int i;
+    int outputs;
+
+    while (pI830->pipeModes[pipe] != NULL)
+	xf86DeleteMode(&pI830->pipeModes[pipe], pI830->pipeModes[pipe]);
+
+    if (pipe == 0)
+	outputs = pI830->operatingDevices & 0xff;
+    else
+	outputs = (pI830->operatingDevices >> 8) & 0xff;
+
+    for (i = 0; i < MAX_OUTPUTS; i++) {
+	switch (pI830->output[i].type) {
+	case I830_OUTPUT_ANALOG:
+	    if (outputs & PIPE_CRT) {
+		output_index = i;
+	    }
+	    break;
+	case I830_OUTPUT_LVDS:
+	    if (outputs & PIPE_LFP) {
+		output_index = i;
+	    }
+	    break;
+	case I830_OUTPUT_SDVO:
+	    if (outputs & PIPE_DFP) {
+		output_index = i;
+	    }
+	    break;
 	}
+    }
+    /* XXX: If there's no output associated with the pipe, bail for now. */
+    if (output_index == -1)
+	return;
+
+    if (outputs & PIPE_LFP) {
+	pI830->pipeMon[pipe] = NULL; /* XXX */
+	pI830->pipeModes[pipe] = i830GetLVDSModes(pScrn,
+						  pScrn->display->modes);
+    } else if (pI830->output[output_index].pDDCBus != NULL) {
+	/* XXX: Free the mon */
+	pI830->pipeMon[pipe] = xf86DoEDID_DDC2(pScrn->scrnIndex,
+					       pI830->output[output_index].pDDCBus);
+	pI830->pipeModes[pipe] = I830GetDDCModes(pScrn,
+						 pI830->pipeMon[pipe]);
+    } else {
+	ErrorF("don't know how to get modes for this device.\n");
+    }
+}
 
-	pScrn->virtualX = pScrn->display->virtualX = maxVirtX;
-	pScrn->virtualY = pScrn->display->virtualY = maxVirtY;
+/**
+ * Probes for video modes on attached otuputs, and assembles a list to insert
+ * into pScrn.
+ */
+int
+I830ValidateXF86ModeList(ScrnInfoPtr pScrn)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    ClockRangePtr clockRanges;
+    int n, pipe;
+
+    for (pipe = 0; pipe < MAX_DISPLAY_PIPES; pipe++) {
+	I830ReprobePipeModeList(pScrn, pipe);
     }
 
-    /* Close the doubly-linked mode list, if we found any usable modes */
-    if (last) {
-      DisplayModePtr  temp      = NULL;
-        /* we should add these to pScrn monitor modes */
-      last->next   = pScrn->monitor->Modes;
-      temp = pScrn->monitor->Modes->prev;
-      pScrn->monitor->Modes->prev = first;
-      pScrn->monitor->Modes->prev = last;
-
-      first->prev = temp;
-      if (temp)
-	temp->next = first;
+    /* XXX: Clean out modes previously injected by our driver */
 
-      pScrn->monitor->Modes = first;
+    if (pI830->pipeModes[0] != NULL) {
+	I830InjectProbedModes(pScrn, pScrn->monitor->Modes,
+			      pScrn->display->modes, pI830->pipeModes[0]);
+    }
+    if (pI830->pipeModes[1] != NULL) {
+	I830InjectProbedModes(pScrn, pScrn->monitor->Modes,
+			      pScrn->display->modes, pI830->pipeModes[1]);
     }
 
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-	       "Total number of valid DDC mode(s) found: %d\n", count);
+   /*
+     * Set up the ClockRanges, which describe what clock ranges are available,
+     * and what sort of modes they can be used for.
+     */
+    clockRanges = xnfcalloc(sizeof(ClockRange), 1);
+    clockRanges->next = NULL;
+    clockRanges->minClock = 25000;
+    clockRanges->maxClock = pI830->MaxClock;
+    clockRanges->clockIndex = -1;		/* programmable */
+    clockRanges->interlaceAllowed = TRUE;	/* XXX check this */
+    clockRanges->doubleScanAllowed = FALSE;	/* XXX check this */
+
+    /* Take the pScrn->monitor->Modes we've accumulated and validate them into
+     * pScrn->modes.
+     */
+    n = xf86ValidateModes(pScrn,
+			  pScrn->monitor->Modes, /* availModes */
+			  pScrn->display->modes, /* modeNames */
+			  clockRanges, /* clockRanges */
+			  NULL, /* linePitches */
+			  320, /* minPitch */
+			  MAX_DISPLAY_PITCH, /* maxPitch */
+			  64 * pScrn->bitsPerPixel, /* pitchInc */
+			  200, /* minHeight */
+			  MAX_DISPLAY_HEIGHT, /* maxHeight */
+			  pScrn->display->virtualX, /* virtualX */
+			  pScrn->display->virtualY, /* virtualY */
+			  pI830->FbMapSize, /* apertureSize */
+			  LOOKUP_BEST_REFRESH /* strategy */);
 
-    return count;
+    return n;
 }
diff-tree bb4810521633b6c3db2fc7d01ddc71325583d265 (from 66d9a1be302ad34573de98de21cbdf6419592092)
Author: Eric Anholt <anholt at FreeBSD.org>
Date:   Thu Jun 22 09:38:27 2006 -0700

    Move FP mode validation next to other mode validation code.

diff --git a/src/i830.h b/src/i830.h
index d5bb9c6..26a0063 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -594,6 +594,7 @@ extern Bool I830RandRInit(ScreenPtr pScr
 extern Bool I830I2CInit(ScrnInfoPtr pScrn, I2CBusPtr *bus_ptr, int i2c_reg,
 			char *name);
 int I830xf86ValidateDDCModes(ScrnInfoPtr pScrn1, char **ppModeName);
+int i830ValidateFPModes(ScrnInfoPtr pScrn, char **ppModeName);
 
 /*
  * 12288 is set as the maximum, chosen because it is enough for
diff --git a/src/i830_driver.c b/src/i830_driver.c
index c51587b..f3cb186 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1245,170 +1245,6 @@ I830IsPrimary(ScrnInfoPtr pScrn)
    return TRUE;
 }
 
-static void
-i830SetModeToPanelParameters(ScrnInfoPtr pScrn, DisplayModePtr pMode)
-{
-   I830Ptr pI830 = I830PTR(pScrn);
-
-   pMode->HTotal     = pI830->panel_fixed_hactive;
-   pMode->HSyncStart = pI830->panel_fixed_hactive + pI830->panel_fixed_hsyncoff;
-   pMode->HSyncEnd   = pMode->HSyncStart + pI830->panel_fixed_hsyncwidth;
-   pMode->VTotal     = pI830->panel_fixed_vactive;
-   pMode->VSyncStart = pI830->panel_fixed_vactive + pI830->panel_fixed_vsyncoff;
-   pMode->VSyncEnd   = pMode->VSyncStart + pI830->panel_fixed_vsyncwidth;
-   pMode->Clock      = pI830->panel_fixed_clock;
-}
-
-/**
- * This function returns a default mode for flat panels using the timing
- * information provided by the BIOS.
- */
-static DisplayModePtr i830FPNativeMode(ScrnInfoPtr pScrn)
-{
-   I830Ptr pI830 = I830PTR(pScrn);
-   DisplayModePtr  new;
-   char            stmp[32];
-
-   if (pI830->PanelXRes == 0 || pI830->PanelYRes == 0)
-      return NULL;
-
-   /* Add native panel size */
-   new             = xnfcalloc(1, sizeof (DisplayModeRec));
-   sprintf(stmp, "%dx%d", pI830->PanelXRes, pI830->PanelYRes);
-   new->name       = xnfalloc(strlen(stmp) + 1);
-   strcpy(new->name, stmp);
-   new->HDisplay   = pI830->PanelXRes;
-   new->VDisplay   = pI830->PanelYRes;
-   i830SetModeToPanelParameters(pScrn, new);
-   new->type       = M_T_USERDEF;
-
-   pScrn->virtualX = MAX(pScrn->virtualX, pI830->PanelXRes);
-   pScrn->virtualY = MAX(pScrn->virtualY, pI830->PanelYRes);
-   pScrn->display->virtualX = pScrn->virtualX;
-   pScrn->display->virtualY = pScrn->virtualY;
-
-   xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-	      "No valid mode specified, force to native mode\n");
-
-   return new;
-}
-
-/* FP mode validation routine for using panel fitting.
- */
-static int i830ValidateFPModes(ScrnInfoPtr pScrn, char **ppModeName)
-{
-   I830Ptr pI830 = I830PTR(pScrn);
-   DisplayModePtr  last       = NULL;
-   DisplayModePtr  new        = NULL;
-   DisplayModePtr  first      = NULL;
-   DisplayModePtr  p, tmp;
-   int             count      = 0;
-   int             i, width, height;
-
-   pScrn->virtualX = pScrn->display->virtualX;
-   pScrn->virtualY = pScrn->display->virtualY;
-
-   /* We have a flat panel connected to the primary display, and we
-    * don't have any DDC info.
-    */
-   for (i = 0; ppModeName[i] != NULL; i++) {
-
-      if (sscanf(ppModeName[i], "%dx%d", &width, &height) != 2)
-	 continue;
-
-      /* Note: We allow all non-standard modes as long as they do not
-       * exceed the native resolution of the panel.  Since these modes
-       * need the internal RMX unit in the video chips (and there is
-       * only one per card), this will only apply to the primary head.
-       */
-      if (width < 320 || width > pI830->PanelXRes ||
-	 height < 200 || height > pI830->PanelYRes) {
-	 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Mode %s is out of range.\n",
-		    ppModeName[i]);
-	 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		    "Valid modes must be between 320x200-%dx%d\n",
-		    pI830->PanelXRes, pI830->PanelYRes);
-	 continue;
-      }
-
-      new             = xnfcalloc(1, sizeof(DisplayModeRec));
-      new->name       = xnfalloc(strlen(ppModeName[i]) + 1);
-      strcpy(new->name, ppModeName[i]);
-      new->HDisplay   = width;
-      new->VDisplay   = height;
-      new->type      |= M_T_USERDEF;
-
-      i830SetModeToPanelParameters(pScrn, new);
-
-      new->next       = NULL;
-      new->prev       = last;
-
-      if (last)
-	 last->next = new;
-      last = new;
-      if (!first)
-	 first = new;
-
-      pScrn->display->virtualX = pScrn->virtualX = MAX(pScrn->virtualX, width);
-      pScrn->display->virtualY = pScrn->virtualY = MAX(pScrn->virtualY, height);
-      count++;
-      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-		 "Valid mode using panel fitting: %s\n", new->name);
-   }
-
-   /* If all else fails, add the native mode */
-   if (!count) {
-      first = last = i830FPNativeMode(pScrn);
-      if (first)
-	 count = 1;
-   }
-
-   /* add in all default vesa modes smaller than panel size, used for randr*/
-   for (p = pScrn->monitor->Modes; p && p->next; p = p->next->next) {
-      if ((p->HDisplay <= pI830->PanelXRes) && (p->VDisplay <= pI830->PanelYRes)) {
-	 tmp = first;
-	 while (tmp) {
-	    if ((p->HDisplay == tmp->HDisplay) && (p->VDisplay == tmp->VDisplay)) break;
-	       tmp = tmp->next;
-	 }
-	 if (!tmp) {
-	    new             = xnfcalloc(1, sizeof(DisplayModeRec));
-	    new->name       = xnfalloc(strlen(p->name) + 1);
-	    strcpy(new->name, p->name);
-	    new->HDisplay   = p->HDisplay;
-	    new->VDisplay   = p->VDisplay;
-	    i830SetModeToPanelParameters(pScrn, new);
-	    new->type      |= M_T_DEFAULT;
-
-	    new->next       = NULL;
-	    new->prev       = last;
-
-	    if (last)
-	       last->next = new;
-	    last = new;
-	    if (!first)
-	       first = new;
-	 }
-      }
-   }
-
-   /* Close the doubly-linked mode list, if we found any usable modes */
-   if (last) {
-      last->next   = first;
-      first->prev  = last;
-      pScrn->modes = first;
-   }
-
-   xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-	      "Total number of valid FP mode(s) found: %d\n", count);
-
-   /* Adjust the display pitch to fit the modes we've come up with. */
-   pScrn->displayWidth = MAX(pScrn->displayWidth, pScrn->virtualX);
-   pScrn->displayWidth = (pScrn->displayWidth + 63) & ~63;
-
-   return count;
-}
-
 static Bool
 I830BIOSPreInit(ScrnInfoPtr pScrn, int flags)
 {
diff --git a/src/i830_modes.c b/src/i830_modes.c
index ce86d8c..c0c258c 100644
--- a/src/i830_modes.c
+++ b/src/i830_modes.c
@@ -332,6 +332,171 @@ DisplayModePtr I830xf86DDCModes(ScrnInfo
     return first;
 }
 
+static void
+i830SetModeToPanelParameters(ScrnInfoPtr pScrn, DisplayModePtr pMode)
+{
+   I830Ptr pI830 = I830PTR(pScrn);
+
+   pMode->HTotal     = pI830->panel_fixed_hactive;
+   pMode->HSyncStart = pI830->panel_fixed_hactive + pI830->panel_fixed_hsyncoff;
+   pMode->HSyncEnd   = pMode->HSyncStart + pI830->panel_fixed_hsyncwidth;
+   pMode->VTotal     = pI830->panel_fixed_vactive;
+   pMode->VSyncStart = pI830->panel_fixed_vactive + pI830->panel_fixed_vsyncoff;
+   pMode->VSyncEnd   = pMode->VSyncStart + pI830->panel_fixed_vsyncwidth;
+   pMode->Clock      = pI830->panel_fixed_clock;
+}
+
+/**
+ * This function returns a default mode for flat panels using the timing
+ * information provided by the BIOS.
+ */
+static DisplayModePtr i830FPNativeMode(ScrnInfoPtr pScrn)
+{
+   I830Ptr pI830 = I830PTR(pScrn);
+   DisplayModePtr  new;
+   char            stmp[32];
+
+   if (pI830->PanelXRes == 0 || pI830->PanelYRes == 0)
+      return NULL;
+
+   /* Add native panel size */
+   new             = xnfcalloc(1, sizeof (DisplayModeRec));
+   sprintf(stmp, "%dx%d", pI830->PanelXRes, pI830->PanelYRes);
+   new->name       = xnfalloc(strlen(stmp) + 1);
+   strcpy(new->name, stmp);
+   new->HDisplay   = pI830->PanelXRes;
+   new->VDisplay   = pI830->PanelYRes;
+   i830SetModeToPanelParameters(pScrn, new);
+   new->type       = M_T_USERDEF;
+
+   pScrn->virtualX = MAX(pScrn->virtualX, pI830->PanelXRes);
+   pScrn->virtualY = MAX(pScrn->virtualY, pI830->PanelYRes);
+   pScrn->display->virtualX = pScrn->virtualX;
+   pScrn->display->virtualY = pScrn->virtualY;
+
+   xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+	      "No valid mode specified, force to native mode\n");
+
+   return new;
+}
+
+/* FP mode validation routine for using panel fitting.
+ */
+int
+i830ValidateFPModes(ScrnInfoPtr pScrn, char **ppModeName)
+{
+   I830Ptr pI830 = I830PTR(pScrn);
+   DisplayModePtr  last       = NULL;
+   DisplayModePtr  new        = NULL;
+   DisplayModePtr  first      = NULL;
+   DisplayModePtr  p, tmp;
+   int             count      = 0;
+   int             i, width, height;
+
+   pScrn->virtualX = pScrn->display->virtualX;
+   pScrn->virtualY = pScrn->display->virtualY;
+
+   /* We have a flat panel connected to the primary display, and we
+    * don't have any DDC info.
+    */
+   for (i = 0; ppModeName[i] != NULL; i++) {
+
+      if (sscanf(ppModeName[i], "%dx%d", &width, &height) != 2)
+	 continue;
+
+      /* Note: We allow all non-standard modes as long as they do not
+       * exceed the native resolution of the panel.  Since these modes
+       * need the internal RMX unit in the video chips (and there is
+       * only one per card), this will only apply to the primary head.
+       */
+      if (width < 320 || width > pI830->PanelXRes ||
+	 height < 200 || height > pI830->PanelYRes) {
+	 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Mode %s is out of range.\n",
+ 		    ppModeName[i]);
+	 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		    "Valid modes must be between 320x200-%dx%d\n",
+		    pI830->PanelXRes, pI830->PanelYRes);
+	 continue;
+      }
+
+      new             = xnfcalloc(1, sizeof(DisplayModeRec));
+      new->name       = xnfalloc(strlen(ppModeName[i]) + 1);
+      strcpy(new->name, ppModeName[i]);
+      new->HDisplay   = width;
+      new->VDisplay   = height;
+      new->type      |= M_T_USERDEF;
+
+      i830SetModeToPanelParameters(pScrn, new);
+
+      new->next       = NULL;
+      new->prev       = last;
+
+      if (last)
+	 last->next = new;
+      last = new;
+      if (!first)
+	 first = new;
+
+      pScrn->display->virtualX = pScrn->virtualX = MAX(pScrn->virtualX, width);
+      pScrn->display->virtualY = pScrn->virtualY = MAX(pScrn->virtualY, height);
+      count++;
+      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		 "Valid mode using panel fitting: %s\n", new->name);
+   }
+
+   /* If all else fails, add the native mode */
+   if (!count) {
+      first = last = i830FPNativeMode(pScrn);
+      if (first)
+	 count = 1;
+   }
+
+   /* add in all default vesa modes smaller than panel size, used for randr*/
+   for (p = pScrn->monitor->Modes; p && p->next; p = p->next->next) {
+      if ((p->HDisplay <= pI830->PanelXRes) && (p->VDisplay <= pI830->PanelYRes)) {
+	 tmp = first;
+	 while (tmp) {
+	    if ((p->HDisplay == tmp->HDisplay) && (p->VDisplay == tmp->VDisplay)) break;
+	       tmp = tmp->next;
+	 }
+	 if (!tmp) {
+	    new             = xnfcalloc(1, sizeof(DisplayModeRec));
+	    new->name       = xnfalloc(strlen(p->name) + 1);
+	    strcpy(new->name, p->name);
+	    new->HDisplay   = p->HDisplay;
+	    new->VDisplay   = p->VDisplay;
+	    i830SetModeToPanelParameters(pScrn, new);
+	    new->type      |= M_T_DEFAULT;
+
+	    new->next       = NULL;
+	    new->prev       = last;
+
+	    if (last)
+	       last->next = new;
+	    last = new;
+	    if (!first)
+	       first = new;
+	 }
+      }
+   }
+
+   /* Close the doubly-linked mode list, if we found any usable modes */
+   if (last) {
+      last->next   = first;
+      first->prev  = last;
+      pScrn->modes = first;
+   }
+
+   xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+	      "Total number of valid FP mode(s) found: %d\n", count);
+
+   /* Adjust the display pitch to fit the modes we've come up with. */
+   pScrn->displayWidth = MAX(pScrn->displayWidth, pScrn->virtualX);
+   pScrn->displayWidth = (pScrn->displayWidth + 63) & ~63;
+
+   return count;
+}
+
 /* XFree86's xf86ValidateModes routine doesn't work well with DDC modes,
  * so here is our own validation routine.
  */



More information about the xorg-commit mailing list