xf86-video-r128: Branch 'master' - 3 commits

Connor Behan cbehan at kemper.freedesktop.org
Wed Aug 6 12:55:00 PDT 2014


 man/r128.man      |   18 -
 src/Makefile.am   |    2 
 src/r128.h        |   56 +---
 src/r128_accel.c  |   22 -
 src/r128_crtc.c   |   62 ++--
 src/r128_dga.c    |  408 -------------------------------
 src/r128_driver.c |  710 +++++++++++++++++++-----------------------------------
 src/r128_output.c |  164 ++++--------
 src/r128_probe.c  |    1 
 src/r128_probe.h  |   20 -
 src/r128_video.c  |   11 
 11 files changed, 389 insertions(+), 1085 deletions(-)

New commits:
commit d49c3431e92a6120b054959ce6910e8decf61c67
Author: Connor Behan <connor.behan at gmail.com>
Date:   Fri Jul 25 13:39:08 2014 -0700

    Remove custom DGA code
    
    I have yet to see a use for the DGA code included in the driver.
    According to radeon commits, it should be safe to replace it with DiDGA.
    
    Signed-off-by: Connor Behan <connor.behan at gmail.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/src/Makefile.am b/src/Makefile.am
index e4618ea..05fbe6c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,7 +40,7 @@ r128_drv_la_LTLIBRARIES = r128_drv.la
 r128_drv_la_LDFLAGS = -module -avoid-version
 r128_drv_ladir = @moduledir@/drivers
 r128_drv_la_SOURCES = \
-	r128_accel.c r128_cursor.c r128_dga.c r128_driver.c \
+	r128_accel.c r128_cursor.c r128_driver.c \
 	r128_video.c r128_misc.c r128_crtc.c r128_output.c r128_probe.c \
 	$(R128_EXA_SRCS) $(R128_DRI_SRCS)
 
diff --git a/src/r128.h b/src/r128.h
index 3b1e631..19124bf 100644
--- a/src/r128.h
+++ b/src/r128.h
@@ -343,12 +343,6 @@ typedef struct {
     struct r128_2d_state state_2d;
 #endif
 
-    /*
-     * XAAForceTransBlit is used to change the behavior of the XAA
-     * SetupForScreenToScreenCopy function, to make it DGA-friendly.
-     */
-    Bool              XAAForceTransBlit;
-
     int               fifo_slots;   /* Free slots in the FIFO (64 max)       */
     int               pix24bpp;     /* Depth of pixmap for 24bpp framebuffer */
     Bool              dac6bits;     /* Use 6 bit DAC?                        */
@@ -381,12 +375,6 @@ typedef struct {
     int               scanline_direct;
     int               scanline_bpp; /* Only used for ImageWrite */
 
-    DGAModePtr        DGAModes;
-    int               numDGAModes;
-    Bool              DGAactive;
-    int               DGAViewportStatus;
-    DGAFunctionRec    DGAFuncs;
-
     R128FBLayout      CurrentLayout;
 #ifdef R128DRI
     Bool              directRenderingEnabled;
@@ -525,7 +513,6 @@ extern void        R128WaitForVerticalSync(ScrnInfoPtr pScrn);
 extern Bool        R128AccelInit(ScreenPtr pScreen);
 extern void        R128EngineInit(ScrnInfoPtr pScrn);
 extern Bool        R128CursorInit(ScreenPtr pScreen);
-extern Bool        R128DGAInit(ScreenPtr pScreen);
 
 extern int         R128MinBits(int val);
 extern xf86OutputPtr R128FirstOutput(xf86CrtcPtr crtc);
diff --git a/src/r128_accel.c b/src/r128_accel.c
index fa58327..c88e8f9 100644
--- a/src/r128_accel.c
+++ b/src/r128_accel.c
@@ -590,7 +590,7 @@ static void R128SetupForScreenToScreenCopy(ScrnInfoPtr pScrn,
 					? R128_DST_Y_TOP_TO_BOTTOM
 					: 0)));
 
-    if ((trans_color != -1) || (info->XAAForceTransBlit == TRUE)) {
+    if (trans_color != -1) {
 				/* Set up for transparency */
 	R128WaitForFifo(pScrn, 3);
 	OUTREG(R128_CLR_CMP_CLR_SRC, trans_color);
@@ -1182,7 +1182,7 @@ static void R128CCESetupForScreenToScreenCopy(ScrnInfoPtr pScrn,
 
     ADVANCE_RING();
 
-    if ((trans_color != -1) || (info->XAAForceTransBlit == TRUE)) {
+    if (trans_color != -1) {
 	BEGIN_RING( 6 );
 
 	OUT_RING_REG( R128_CLR_CMP_CLR_SRC, trans_color );
diff --git a/src/r128_dga.c b/src/r128_dga.c
deleted file mode 100644
index bb4a1a6..0000000
--- a/src/r128_dga.c
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * Authors:
- *   Ove KÃ¥ven <ovek at transgaming.com>,
- *    borrowing some code from the Chips and MGA drivers.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <string.h>
-
-				/* Driver data structures */
-#include "r128.h"
-#include "r128_probe.h"
-
-				/* X and server generic header files */
-#include "xf86.h"
-
-				/* DGA support */
-#include "dgaproc.h"
-
-#ifdef R128DRI
-#include "r128_common.h"
-#endif
-
-static Bool R128_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **,
-					int *, int *, int *);
-static Bool R128_SetMode(ScrnInfoPtr, DGAModePtr);
-static int  R128_GetViewport(ScrnInfoPtr);
-static void R128_SetViewport(ScrnInfoPtr, int, int, int);
-#ifdef HAVE_XAA_H
-static void R128_FillRect(ScrnInfoPtr, int, int, int, int, unsigned long);
-static void R128_BlitRect(ScrnInfoPtr, int, int, int, int, int, int);
-static void R128_BlitTransRect(ScrnInfoPtr, int, int, int, int, int, int,
-			       unsigned long);
-#endif
-
-static DGAModePtr R128SetupDGAMode(ScrnInfoPtr pScrn,
-				     DGAModePtr modes,
-				     int *num,
-				     int bitsPerPixel,
-				     int depth,
-				     Bool pixmap,
-				     int secondPitch,
-				     unsigned long red,
-				     unsigned long green,
-				     unsigned long blue,
-				     short visualClass)
-{
-    R128InfoPtr   info     = R128PTR(pScrn);
-    DGAModePtr      newmodes = NULL;
-    DGAModePtr      currentMode;
-    DisplayModePtr  pMode;
-    DisplayModePtr  firstMode;
-    unsigned int    size;
-    int             pitch;
-    int             Bpp      = bitsPerPixel >> 3;
-
-SECOND_PASS:
-
-    pMode = firstMode = pScrn->modes;
-
-    while (1) {
-	pitch = pScrn->displayWidth;
-	size = pitch * Bpp * pMode->VDisplay;
-
-	if ((!secondPitch || (pitch != secondPitch)) &&
-	    (size <= info->FbMapSize)) {
-
-	    if (secondPitch)
-		pitch = secondPitch;
-
-	    if (!(newmodes = realloc(modes, (*num + 1) * sizeof(DGAModeRec))))
-		break;
-
-	    modes       = newmodes;
-	    currentMode = modes + *num;
-
-	    currentMode->mode           = pMode;
-	    currentMode->flags          = DGA_CONCURRENT_ACCESS;
-
-	    if (pixmap)
-		currentMode->flags     |= DGA_PIXMAP_AVAILABLE;
-
-#ifdef HAVE_XAA_H
-	    if (info->accel) {
-	      if (info->accel->SetupForSolidFill &&
-		  info->accel->SubsequentSolidFillRect)
-		 currentMode->flags    |= DGA_FILL_RECT;
-	      if (info->accel->SetupForScreenToScreenCopy &&
-		  info->accel->SubsequentScreenToScreenCopy)
-		 currentMode->flags    |= DGA_BLIT_RECT | DGA_BLIT_RECT_TRANS;
-	      if (currentMode->flags &
-		  (DGA_PIXMAP_AVAILABLE | DGA_FILL_RECT |
-		   DGA_BLIT_RECT | DGA_BLIT_RECT_TRANS))
-		  currentMode->flags   &= ~DGA_CONCURRENT_ACCESS;
-	    }
-#endif
-	    if (pMode->Flags & V_DBLSCAN)
-		currentMode->flags     |= DGA_DOUBLESCAN;
-	    if (pMode->Flags & V_INTERLACE)
-		currentMode->flags     |= DGA_INTERLACED;
-
-	    currentMode->byteOrder      = pScrn->imageByteOrder;
-	    currentMode->depth          = depth;
-	    currentMode->bitsPerPixel   = bitsPerPixel;
-	    currentMode->red_mask       = red;
-	    currentMode->green_mask     = green;
-	    currentMode->blue_mask      = blue;
-	    currentMode->visualClass    = visualClass;
-	    currentMode->viewportWidth  = pMode->HDisplay;
-	    currentMode->viewportHeight = pMode->VDisplay;
-	    currentMode->xViewportStep  = 8;
-	    currentMode->yViewportStep  = 1;
-	    currentMode->viewportFlags  = DGA_FLIP_RETRACE;
-	    currentMode->offset         = 0;
-	    currentMode->address        = (unsigned char*)info->LinearAddr;
-	    currentMode->bytesPerScanline = pitch * Bpp;
-	    currentMode->imageWidth     = pitch;
-	    currentMode->imageHeight    = (info->FbMapSize
-					   / currentMode->bytesPerScanline);
-	    currentMode->pixmapWidth    = currentMode->imageWidth;
-	    currentMode->pixmapHeight   = currentMode->imageHeight;
-	    currentMode->maxViewportX   = (currentMode->imageWidth
-					   - currentMode->viewportWidth);
-	    /* this might need to get clamped to some maximum */
-	    currentMode->maxViewportY   = (currentMode->imageHeight
-					   - currentMode->viewportHeight);
-	    (*num)++;
-	}
-
-	pMode = pMode->next;
-	if (pMode == firstMode)
-	    break;
-    }
-
-    if (secondPitch) {
-	secondPitch = 0;
-	goto SECOND_PASS;
-    }
-
-    return modes;
-}
-
-Bool
-R128DGAInit(ScreenPtr pScreen)
-{
-   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-   R128InfoPtr info = R128PTR(pScrn);
-   DGAModePtr modes = NULL;
-   int num = 0;
-
-   /* 8 */
-   modes = R128SetupDGAMode (pScrn, modes, &num, 8, 8,
-		(pScrn->bitsPerPixel == 8),
-		(pScrn->bitsPerPixel != 8) ? 0 : pScrn->displayWidth,
-		0, 0, 0, PseudoColor);
-
-   /* 15 */
-   modes = R128SetupDGAMode (pScrn, modes, &num, 16, 15,
-		(pScrn->bitsPerPixel == 16),
-		(pScrn->depth != 15) ? 0 : pScrn->displayWidth,
-		0x7c00, 0x03e0, 0x001f, TrueColor);
-
-   modes = R128SetupDGAMode (pScrn, modes, &num, 16, 15,
-		(pScrn->bitsPerPixel == 16),
-		(pScrn->depth != 15) ? 0 : pScrn->displayWidth,
-		0x7c00, 0x03e0, 0x001f, DirectColor);
-
-   /* 16 */
-   modes = R128SetupDGAMode (pScrn, modes, &num, 16, 16,
-		(pScrn->bitsPerPixel == 16),
-		(pScrn->depth != 16) ? 0 : pScrn->displayWidth,
-		0xf800, 0x07e0, 0x001f, TrueColor);
-
-   modes = R128SetupDGAMode (pScrn, modes, &num, 16, 16,
-		(pScrn->bitsPerPixel == 16),
-		(pScrn->depth != 16) ? 0 : pScrn->displayWidth,
-		0xf800, 0x07e0, 0x001f, DirectColor);
-
-   /* 24 */
-   modes = R128SetupDGAMode (pScrn, modes, &num, 24, 24,
-		(pScrn->bitsPerPixel == 24),
-		(pScrn->bitsPerPixel != 24) ? 0 : pScrn->displayWidth,
-		0xff0000, 0x00ff00, 0x0000ff, TrueColor);
-
-   modes = R128SetupDGAMode (pScrn, modes, &num, 24, 24,
-		(pScrn->bitsPerPixel == 24),
-		(pScrn->bitsPerPixel != 24) ? 0 : pScrn->displayWidth,
-		0xff0000, 0x00ff00, 0x0000ff, DirectColor);
-
-   /* 32 */
-   modes = R128SetupDGAMode (pScrn, modes, &num, 32, 24,
-		(pScrn->bitsPerPixel == 32),
-		(pScrn->bitsPerPixel != 32) ? 0 : pScrn->displayWidth,
-		0xff0000, 0x00ff00, 0x0000ff, TrueColor);
-
-   modes = R128SetupDGAMode (pScrn, modes, &num, 32, 24,
-		(pScrn->bitsPerPixel == 32),
-		(pScrn->bitsPerPixel != 32) ? 0 : pScrn->displayWidth,
-		0xff0000, 0x00ff00, 0x0000ff, DirectColor);
-
-   info->numDGAModes = num;
-   info->DGAModes = modes;
-
-   info->DGAFuncs.OpenFramebuffer    = R128_OpenFramebuffer;
-   info->DGAFuncs.CloseFramebuffer   = NULL;
-   info->DGAFuncs.SetMode            = R128_SetMode;
-   info->DGAFuncs.SetViewport        = R128_SetViewport;
-   info->DGAFuncs.GetViewport        = R128_GetViewport;
-
-   info->DGAFuncs.Sync               = NULL;
-   info->DGAFuncs.FillRect           = NULL;
-   info->DGAFuncs.BlitRect           = NULL;
-   info->DGAFuncs.BlitTransRect      = NULL;
-
-#ifdef HAVE_XAA_H
-   if (info->accel) {
-      info->DGAFuncs.Sync            = info->accel->Sync;
-      if (info->accel->SetupForSolidFill &&
-	  info->accel->SubsequentSolidFillRect)
-	info->DGAFuncs.FillRect      = R128_FillRect;
-      if (info->accel->SetupForScreenToScreenCopy &&
-	  info->accel->SubsequentScreenToScreenCopy) {
-	info->DGAFuncs.BlitRect      = R128_BlitRect;
-	info->DGAFuncs.BlitTransRect = R128_BlitTransRect;
-      }
-   }
-#endif
-
-   return DGAInit(pScreen, &(info->DGAFuncs), modes, num);
-}
-
-
-static Bool
-R128_SetMode(
-   ScrnInfoPtr pScrn,
-   DGAModePtr pMode
-){
-   static R128FBLayout SavedLayouts[MAXSCREENS];
-   int indx = pScrn->pScreen->myNum;
-   R128InfoPtr info = R128PTR(pScrn);
-
-   if(!pMode) { /* restore the original mode */
-	/* put the ScreenParameters back */
-	if(info->DGAactive)
-	    memcpy(&info->CurrentLayout, &SavedLayouts[indx], sizeof(R128FBLayout));
-
-	pScrn->currentMode = info->CurrentLayout.mode;
-
-	pScrn->SwitchMode(SWITCH_MODE_ARGS(pScrn, pScrn->currentMode));
-#ifdef R128DRI
-	if (info->directRenderingEnabled) {
-	    R128CCE_STOP(pScrn, info);
-	}
-#endif
-	if (info->accelOn)
-	    R128EngineInit(pScrn);
-#ifdef R128DRI
-	if (info->directRenderingEnabled) {
-	    R128CCE_START(pScrn, info);
-	}
-#endif
-	pScrn->AdjustFrame(ADJUST_FRAME_ARGS(pScrn, 0, 0));
-	info->DGAactive = FALSE;
-   } else {
-	if(!info->DGAactive) {  /* save the old parameters */
-	    memcpy(&SavedLayouts[indx], &info->CurrentLayout, sizeof(R128FBLayout));
-	    info->DGAactive = TRUE;
-	}
-
-	info->CurrentLayout.bitsPerPixel = pMode->bitsPerPixel;
-	info->CurrentLayout.depth = pMode->depth;
-	info->CurrentLayout.displayWidth = pMode->bytesPerScanline /
-					    (pMode->bitsPerPixel >> 3);
-	info->CurrentLayout.pixel_bytes = pMode->bitsPerPixel / 8;
-	info->CurrentLayout.pixel_code  = (pMode->bitsPerPixel != 16
-					  ? pMode->bitsPerPixel
-					  : pMode->depth);
-	/* R128ModeInit() will set the mode field */
-
-	pScrn->SwitchMode(SWITCH_MODE_ARGS(pScrn, pMode->mode));
-
-#ifdef R128DRI
-	if (info->directRenderingEnabled) {
-	    R128CCE_STOP(pScrn, info);
-	}
-#endif
-	if (info->accelOn)
-		R128EngineInit(pScrn);
-#ifdef R128DRI
-	if (info->directRenderingEnabled) {
-	    R128CCE_START(pScrn, info);
-	}
-#endif
-   }
-
-   return TRUE;
-}
-
-
-
-static int
-R128_GetViewport(
-  ScrnInfoPtr pScrn
-){
-    R128InfoPtr info = R128PTR(pScrn);
-
-    return info->DGAViewportStatus;
-}
-
-
-static void
-R128_SetViewport(
-   ScrnInfoPtr pScrn,
-   int x, int y,
-   int flags
-){
-   R128InfoPtr info = R128PTR(pScrn);
-
-   pScrn->AdjustFrame(ADJUST_FRAME_ARGS(pScrn, x, y));
-   info->DGAViewportStatus = 0;  /* FIXME */
-}
-
-#ifdef HAVE_XAA_H
-static void
-R128_FillRect (
-   ScrnInfoPtr pScrn,
-   int x, int y, int w, int h,
-   unsigned long color
-){
-    R128InfoPtr info = R128PTR(pScrn);
-
-    (*info->accel->SetupForSolidFill)(pScrn, color, GXcopy, (uint32_t)(~0));
-    (*info->accel->SubsequentSolidFillRect)(pScrn, x, y, w, h);
-
-    if (pScrn->bitsPerPixel == info->CurrentLayout.bitsPerPixel)
-	SET_SYNC_FLAG(info->accel);
-}
-
-static void
-R128_BlitRect(
-   ScrnInfoPtr pScrn,
-   int srcx, int srcy,
-   int w, int h,
-   int dstx, int dsty
-){
-    R128InfoPtr info = R128PTR(pScrn);
-    int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1;
-    int ydir = (srcy < dsty) ? -1 : 1;
-
-    (*info->accel->SetupForScreenToScreenCopy)(
-	pScrn, xdir, ydir, GXcopy, (uint32_t)(~0), -1);
-    (*info->accel->SubsequentScreenToScreenCopy)(
-	pScrn, srcx, srcy, dstx, dsty, w, h);
-
-    if (pScrn->bitsPerPixel == info->CurrentLayout.bitsPerPixel)
-	SET_SYNC_FLAG(info->accel);
-}
-
-
-static void
-R128_BlitTransRect(
-   ScrnInfoPtr pScrn,
-   int srcx, int srcy,
-   int w, int h,
-   int dstx, int dsty,
-   unsigned long color
-){
-    R128InfoPtr info = R128PTR(pScrn);
-    int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1;
-    int ydir = (srcy < dsty) ? -1 : 1;
-
-    info->XAAForceTransBlit = TRUE;
-
-    (*info->accel->SetupForScreenToScreenCopy)(
-	pScrn, xdir, ydir, GXcopy, (uint32_t)(~0), color);
-
-    info->XAAForceTransBlit = FALSE;
-
-    (*info->accel->SubsequentScreenToScreenCopy)(
-	pScrn, srcx, srcy, dstx, dsty, w, h);
-
-    if (pScrn->bitsPerPixel == info->CurrentLayout.bitsPerPixel)
-	SET_SYNC_FLAG(info->accel);
-}
-#endif
-
-static Bool
-R128_OpenFramebuffer(
-   ScrnInfoPtr pScrn,
-   char **name,
-   unsigned char **mem,
-   int *size,
-   int *offset,
-   int *flags
-){
-    R128InfoPtr info = R128PTR(pScrn);
-
-    *name = NULL;               /* no special device */
-    *mem = (unsigned char*)info->LinearAddr;
-    *size = info->FbMapSize;
-    *offset = 0;
-    *flags = /* DGA_NEED_ROOT */ 0; /* don't need root, just /dev/mem access */
-
-    return TRUE;
-}
diff --git a/src/r128_driver.c b/src/r128_driver.c
index 0a8d802..2cbfc81 100644
--- a/src/r128_driver.c
+++ b/src/r128_driver.c
@@ -2044,7 +2044,9 @@ Bool R128ScreenInit(SCREEN_INIT_ARGS_DECL)
     //pScrn->AdjustFrame(ADJUST_FRAME_ARGS(pScrn, pScrn->frameX0, pScrn->frameY0));
 
 				/* DGA setup */
-    R128DGAInit(pScreen);
+#ifdef XFreeXDGA
+    xf86DiDGAInit(pScreen, info->LinearAddr + pScrn->fbOffset);
+#endif
 
 				/* Backing store setup */
     xf86SetBackingStore(pScreen);
@@ -3629,9 +3631,6 @@ static Bool R128CloseScreen(CLOSE_SCREEN_ARGS_DECL)
     if (info->scratch_save)      free(info->scratch_save);
     info->scratch_save           = NULL;
 
-    if (info->DGAModes)          free(info->DGAModes);
-    info->DGAModes               = NULL;
-
     if (info->adaptor) {
         free(info->adaptor->pPortPrivates[0].ptr);
 	xf86XVFreeVideoAdaptorRec(info->adaptor);
commit 6140081f0e8f41cf85b8e86f7a9474c20be9a2e9
Author: Connor Behan <connor.behan at gmail.com>
Date:   Wed Aug 6 15:51:33 2014 -0700

    Remove custom dualhead code
    
    There are probably no reasons left to use Xinerama over xrandr. This
    removes the screen based dualhead code and the BIOS Display option in
    xorg.conf. Additionally, R128ValidMode() is wrapped so that it can be
    aware of multiple displays.
    
    Even though some Crtc functions refer to them, PanelXRes and PanelYRes
    should be properties of the Output. If this change to the code seems
    awkward, see http://marc.info/?t=107222330700001 for more information.
    
    Signed-off-by: Connor Behan <connor.behan at gmail.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/man/r128.man b/man/r128.man
index d490f93..bd58e0d 100644
--- a/man/r128.man
+++ b/man/r128.man
@@ -88,24 +88,6 @@ are used.  The default is
 This overrides the default pixel value for the YUV video overlay key.
 The default value is
 .B undefined.
-.TP
-.BI "Option \*qDisplay\*q \*q" string \*q
-Select display mode for devices which support flat panels. Supported modes are:
-
-.B \*qFP\*q
-- use flat panel;
-
-.B \*qCRT\*q
-- use cathode ray tube;
-
-.B \*qMirror\*q
-- use both FP and CRT;
-
-.B \*qBIOS\*q
-- use mode as configured in the BIOS.
-
-The default is
-.B FP.
 
 .PP
 The following
diff --git a/src/r128.h b/src/r128.h
index d8748b7..3b1e631 100644
--- a/src/r128.h
+++ b/src/r128.h
@@ -136,6 +136,14 @@
 #define R128_ALIGN(x,bytes) (((x) + ((bytes) - 1)) & ~((bytes) - 1))
 #define R128PTR(pScrn) ((R128InfoPtr)(pScrn)->driverPrivate)
 
+#define R128_BIOS8(v)  ((info->VBIOS[(v)]))
+#define R128_BIOS16(v) ((info->VBIOS[(v)])           | \
+			(info->VBIOS[(v) + 1] << 8))
+#define R128_BIOS32(v) ((info->VBIOS[(v)])           | \
+			(info->VBIOS[(v) + 1] << 8)  | \
+			(info->VBIOS[(v) + 2] << 16) | \
+			(info->VBIOS[(v) + 3] << 24))
+
 typedef struct {        /* All values in XCLKS    */
     int  ML;            /* Memory Read Latency    */
     int  MB;            /* Memory Burst Length    */
@@ -311,16 +319,8 @@ typedef struct {
     uint32_t          MemCntl;
     uint32_t          BusCntl;
     unsigned long     FbMapSize;    /* Size of frame buffer, in bytes        */
-
-    uint8_t           BIOSDisplay;  /* Device the BIOS is set to display to  */
-
     Bool              HasPanelRegs; /* Current chip can connect to a FP      */
 
-				/* Computed values for FPs */
-    int               PanelXRes;
-    int               PanelYRes;
-    int               PanelPwrDly;
-
     R128PLLRec        pll;
     R128RAMPtr        ram;
 
@@ -501,17 +501,10 @@ typedef struct {
 
     Bool              isDFP;
     Bool              isPro2;
+    Bool              SwitchingMode;
     Bool              DDC;
 
     Bool              VGAAccess;
-
-    /****** Added for dualhead support *******************/
-    BOOL              IsSecondary;  /* second Screen */
-    BOOL	      IsPrimary;    /* primary Screen */
-    BOOL              UseCRT;       /* force use CRT port as primary */
-    BOOL              SwitchingMode;
-    R128MonitorType DisplayType;  /* Monitor connected on*/
-
 } R128InfoRec, *R128InfoPtr;
 
 #define R128WaitForFifo(pScrn, entries)                                      \
@@ -535,6 +528,7 @@ extern Bool        R128CursorInit(ScreenPtr pScreen);
 extern Bool        R128DGAInit(ScreenPtr pScreen);
 
 extern int         R128MinBits(int val);
+extern xf86OutputPtr R128FirstOutput(xf86CrtcPtr crtc);
 
 extern void        R128InitVideo(ScreenPtr pScreen);
 
@@ -544,13 +538,13 @@ extern void        R128InitRMXRegisters(R128SavePtr orig, R128SavePtr save, xf86
 extern void        R128InitFPRegisters(R128SavePtr orig, R128SavePtr save, xf86OutputPtr output);
 extern void        R128InitLVDSRegisters(R128SavePtr orig, R128SavePtr save, xf86OutputPtr output);
 extern Bool        R128InitCrtcBase(xf86CrtcPtr crtc, R128SavePtr save, int x, int y);
-extern Bool        R128InitCrtcRegisters(ScrnInfoPtr pScrn, R128SavePtr save, DisplayModePtr mode, R128InfoPtr info);
-extern void        R128InitPLLRegisters(ScrnInfoPtr pScrn, R128SavePtr save, R128PLLPtr pll, double dot_clock);
-extern Bool        R128InitDDARegisters(ScrnInfoPtr pScrn, R128SavePtr save, R128PLLPtr pll, R128InfoPtr info, DisplayModePtr mode);
+extern Bool        R128InitCrtcRegisters(xf86CrtcPtr crtc, R128SavePtr save, DisplayModePtr mode);
+extern void        R128InitPLLRegisters(xf86CrtcPtr crtc, R128SavePtr save, R128PLLPtr pll, double dot_clock);
+extern Bool        R128InitDDARegisters(xf86CrtcPtr crtc, R128SavePtr save, R128PLLPtr pll, DisplayModePtr mode);
 extern Bool        R128InitCrtc2Base(xf86CrtcPtr crtc, R128SavePtr save, int x, int y);
-extern Bool        R128InitCrtc2Registers(ScrnInfoPtr pScrn, R128SavePtr save, DisplayModePtr mode, R128InfoPtr info);
-extern void        R128InitPLL2Registers(ScrnInfoPtr pScrn, R128SavePtr save, R128PLLPtr pll, double dot_clock);
-extern Bool        R128InitDDA2Registers(ScrnInfoPtr pScrn, R128SavePtr save, R128PLLPtr pll, R128InfoPtr info, DisplayModePtr mode);
+extern Bool        R128InitCrtc2Registers(xf86CrtcPtr crtc, R128SavePtr save, DisplayModePtr mode);
+extern void        R128InitPLL2Registers(xf86CrtcPtr crtc, R128SavePtr save, R128PLLPtr pll, double dot_clock);
+extern Bool        R128InitDDA2Registers(xf86CrtcPtr crtc, R128SavePtr save, R128PLLPtr pll, DisplayModePtr mode);
 extern void        R128RestoreCommonRegisters(ScrnInfoPtr pScrn, R128SavePtr restore);
 extern void        R128RestoreDACRegisters(ScrnInfoPtr pScrn, R128SavePtr restore);
 extern void        R128RestoreRMXRegisters(ScrnInfoPtr pScrn, R128SavePtr restore);
@@ -571,11 +565,13 @@ extern void        r128_crtc_load_cursor_image(xf86CrtcPtr crtc, unsigned char *
 
 extern uint32_t    R128AllocateMemory(ScrnInfoPtr pScrn, void **mem_struct, int size, int align, Bool need_accel);
 extern Bool        R128SetupConnectors(ScrnInfoPtr pScrn);
-extern Bool        R128AllocateControllers(ScrnInfoPtr pScrn, int mask);
+extern Bool        R128AllocateControllers(ScrnInfoPtr pScrn);
+extern void        R128GetPanelInfoFromBIOS(xf86OutputPtr output);
 extern void        R128Blank(ScrnInfoPtr pScrn);
 extern void        R128Unblank(ScrnInfoPtr pScrn);
 extern void        R128DPMSSetOn(xf86OutputPtr output);
 extern void        R128DPMSSetOff(xf86OutputPtr output);
+extern ModeStatus     R128DoValidMode(xf86OutputPtr output, DisplayModePtr mode, int flags);
 extern DisplayModePtr R128ProbeOutputModes(xf86OutputPtr output);
 
 #ifdef R128DRI
diff --git a/src/r128_accel.c b/src/r128_accel.c
index 99bfb20..fa58327 100644
--- a/src/r128_accel.c
+++ b/src/r128_accel.c
@@ -1746,7 +1746,7 @@ static void R128CCEAccelInit(ScrnInfoPtr pScrn, XAAInfoRecPtr a)
 					   | HARDWARE_PATTERN_SCREEN_ORIGIN
 					   | BIT_ORDER_IN_BYTE_LSBFIRST);
 
-    if(!info->IsSecondary && xf86IsEntityShared(pScrn->entityList[0]))
+    if (xf86IsEntityShared(info->pEnt->index))
         a->RestoreAccelState           = R128RestoreCCEAccelState;
 
 }
@@ -1851,15 +1851,13 @@ static void R128MMIOAccelInit(ScrnInfoPtr pScrn, XAAInfoRecPtr a)
 					  | LEFT_EDGE_CLIPPING_NEGATIVE_X
 					  | SCANLINE_PAD_DWORD;
 
-    if(xf86IsEntityShared(pScrn->entityList[0]))
-    {
-        R128EntPtr pR128Ent = R128EntPriv(pScrn);
-
-        /*if there are more than one devices sharing this entity, we
-          have to assign this call back, otherwise the XAA will be
-          disabled */
-        if(pR128Ent->HasSecondary || pR128Ent->BypassSecondary)
-           a->RestoreAccelState           = R128RestoreAccelState;
+    if (xf86IsEntityShared(info->pEnt-index)) {
+        /* If there are more than one devices sharing this entity, we
+         * have to assign this call back, otherwise the XAA will be
+         * disabled.
+	 */
+        if (xf86GetNumEntityInstances(info->pEnt->index) > 1)
+            a->RestoreAccelState           = R128RestoreAccelState;
     }
 
 }
diff --git a/src/r128_crtc.c b/src/r128_crtc.c
index 92a6c30..26d4414 100644
--- a/src/r128_crtc.c
+++ b/src/r128_crtc.c
@@ -143,11 +143,11 @@ static void r128_crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayMod
 
     switch (r128_crtc->crtc_id) {
     case 0:
-        R128InitCrtcRegisters(pScrn, &info->ModeReg, adjusted_mode, info);
+        R128InitCrtcRegisters(crtc, &info->ModeReg, adjusted_mode);
 	R128InitCrtcBase(crtc, &info->ModeReg, x, y);
         if (dot_clock) {
-            R128InitPLLRegisters(pScrn, &info->ModeReg, &info->pll, dot_clock);
-            R128InitDDARegisters(pScrn, &info->ModeReg, &info->pll, info, adjusted_mode);
+            R128InitPLLRegisters(crtc, &info->ModeReg, &info->pll, dot_clock);
+            R128InitDDARegisters(crtc, &info->ModeReg, &info->pll, adjusted_mode);
         } else {
             info->ModeReg.ppll_ref_div         = info->SavedReg.ppll_ref_div;
             info->ModeReg.ppll_div_3           = info->SavedReg.ppll_div_3;
@@ -157,11 +157,11 @@ static void r128_crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode, DisplayMod
         }
         break;
     case 1:
-        R128InitCrtc2Registers(pScrn, &info->ModeReg, adjusted_mode, info);
+        R128InitCrtc2Registers(crtc, &info->ModeReg, adjusted_mode);
 	R128InitCrtc2Base(crtc, &info->ModeReg, x, y);
         if (dot_clock) {
-            R128InitPLL2Registers(pScrn, &info->ModeReg, &info->pll, dot_clock);
-            R128InitDDA2Registers(pScrn, &info->ModeReg, &info->pll, info, adjusted_mode);
+            R128InitPLL2Registers(crtc, &info->ModeReg, &info->pll, dot_clock);
+            R128InitDDA2Registers(crtc, &info->ModeReg, &info->pll, adjusted_mode);
         }
         break;
     }
@@ -327,44 +327,40 @@ static const xf86CrtcFuncsRec r128_crtc_funcs = {
     .destroy = NULL,
 };
 
-Bool R128AllocateControllers(ScrnInfoPtr pScrn, int mask)
+Bool R128AllocateControllers(ScrnInfoPtr pScrn)
 {
     R128EntPtr pR128Ent = R128EntPriv(pScrn);
 
-    if (mask & 1) {
-        if (pR128Ent->Controller[0])
-            return TRUE;
+    if (pR128Ent->Controller[0])
+        return TRUE;
 
-        pR128Ent->pCrtc[0] = xf86CrtcCreate(pScrn, &r128_crtc_funcs);
-        if (!pR128Ent->pCrtc[0])
-            return FALSE;
+    pR128Ent->pCrtc[0] = xf86CrtcCreate(pScrn, &r128_crtc_funcs);
+    if (!pR128Ent->pCrtc[0])
+        return FALSE;
 
-        pR128Ent->Controller[0] = xnfcalloc(sizeof(R128CrtcPrivateRec), 1);
-        if (!pR128Ent->Controller[0])
-            return FALSE;
+    pR128Ent->Controller[0] = xnfcalloc(sizeof(R128CrtcPrivateRec), 1);
+    if (!pR128Ent->Controller[0])
+        return FALSE;
 
-        pR128Ent->pCrtc[0]->driver_private = pR128Ent->Controller[0];
-        pR128Ent->Controller[0]->crtc_id = 0;
-    }
-
-    if (mask & 2) {
-        if (!pR128Ent->HasCRTC2)
-            return TRUE;
+    pR128Ent->pCrtc[0]->driver_private = pR128Ent->Controller[0];
+    pR128Ent->Controller[0]->crtc_id = 0;
 
-        pR128Ent->pCrtc[1] = xf86CrtcCreate(pScrn, &r128_crtc_funcs);
-        if (!pR128Ent->pCrtc[1])
-            return FALSE;
+    if (!pR128Ent->HasCRTC2)
+        return TRUE;
 
-        pR128Ent->Controller[1] = xnfcalloc(sizeof(R128CrtcPrivateRec), 1);
-        if (!pR128Ent->Controller[1]) {
-            free(pR128Ent->Controller[0]);
-            return FALSE;
-        }
+    pR128Ent->pCrtc[1] = xf86CrtcCreate(pScrn, &r128_crtc_funcs);
+    if (!pR128Ent->pCrtc[1])
+        return FALSE;
 
-        pR128Ent->pCrtc[1]->driver_private = pR128Ent->Controller[1];
-        pR128Ent->Controller[1]->crtc_id = 1;
+    pR128Ent->Controller[1] = xnfcalloc(sizeof(R128CrtcPrivateRec), 1);
+    if (!pR128Ent->Controller[1]) {
+        free(pR128Ent->Controller[0]);
+        return FALSE;
     }
 
+    pR128Ent->pCrtc[1]->driver_private = pR128Ent->Controller[1];
+    pR128Ent->Controller[1]->crtc_id = 1;
+
     return TRUE;
 }
 
diff --git a/src/r128_driver.c b/src/r128_driver.c
index ce38b4e..0a8d802 100644
--- a/src/r128_driver.c
+++ b/src/r128_driver.c
@@ -171,7 +171,6 @@ static const OptionInfoRec R128Options[] = {
   { OPTION_BUFFER_SIZE,  "BufferSize",       OPTV_INTEGER, {0}, FALSE },
   { OPTION_PAGE_FLIP,    "EnablePageFlip",   OPTV_BOOLEAN, {0}, FALSE },
 #endif
-  { OPTION_DISPLAY,      "Display",          OPTV_STRING,  {0}, FALSE },
   { OPTION_PANEL_WIDTH,  "PanelWidth",       OPTV_INTEGER, {0}, FALSE },
   { OPTION_PANEL_HEIGHT, "PanelHeight",      OPTV_INTEGER, {0}, FALSE },
   { OPTION_PROG_FP_REGS, "ProgramFPRegs",    OPTV_BOOLEAN, {0}, FALSE },
@@ -238,14 +237,6 @@ static Bool R128MapMMIO(ScrnInfoPtr pScrn)
     if (info->FBDev) {
 	info->MMIO = fbdevHWMapMMIO(pScrn);
     } else {
-        /* If the primary screen has already mapped the MMIO region,
-           use its pointer instead of mapping it a second time. */
-        if (info->IsSecondary) {
-            R128EntPtr pR128Ent = R128EntPriv(pScrn);
-            R128InfoPtr info0 = R128PTR(pR128Ent->pPrimaryScrn);
-            info->MMIO=info0->MMIO;
-            if (info->MMIO) return TRUE;
-        }
 #ifndef XSERVER_LIBPCIACCESS
 	info->MMIO = xf86MapPciMem(pScrn->scrnIndex,
 				   VIDMEM_MMIO | VIDMEM_READSIDEEFFECT,
@@ -412,20 +403,26 @@ static int R128Div(int n, int d)
     return (n + (d / 2)) / d;
 }
 
-/* Read the Video BIOS block and the FP registers (if applicable). */
+/* Finds the first output using a given crtc. */
+xf86OutputPtr R128FirstOutput(xf86CrtcPtr crtc)
+{
+    ScrnInfoPtr pScrn = crtc->scrn;
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86OutputPtr output = xf86_config->output[0];
+    int o;
+
+    for (o = 0; o < xf86_config->num_output; o++) {
+        output = xf86_config->output[o];
+        if (output->crtc == crtc) break;
+    }
+
+    return output;
+}
+
+/* Read the Video BIOS block. */
 static Bool R128GetBIOSParameters(ScrnInfoPtr pScrn, xf86Int10InfoPtr pInt10)
 {
     R128InfoPtr info = R128PTR(pScrn);
-    int         i;
-    int         FPHeader = 0;
-
-#define R128_BIOS8(v)  (info->VBIOS[v])
-#define R128_BIOS16(v) (info->VBIOS[v] | \
-			(info->VBIOS[(v) + 1] << 8))
-#define R128_BIOS32(v) (info->VBIOS[v] | \
-			(info->VBIOS[(v) + 1] << 8) | \
-			(info->VBIOS[(v) + 2] << 16) | \
-			(info->VBIOS[(v) + 3] << 24))
 
 #ifdef XSERVER_LIBPCIACCESS
     int size = info->PciInfo->rom_size > R128_VBIOS_SIZE ? info->PciInfo->rom_size : R128_VBIOS_SIZE;
@@ -469,143 +466,103 @@ static Bool R128GetBIOSParameters(ScrnInfoPtr pScrn, xf86Int10InfoPtr pInt10)
 	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
 		   "Video BIOS not found!\n");
     }
-    R128EntPtr pR128Ent = R128EntPriv(pScrn);
-
-        if(pR128Ent->HasCRTC2)
-        {                    
-             if(info->IsSecondary)
-             {  
-		/* there may be a way to detect this, for now, just assume 
-		   second head is CRT */
-                 info->DisplayType = MT_CRT;
-
-                 if(info->DisplayType > MT_NONE)
-                 {
-                     pR128Ent->HasSecondary = TRUE;
-
-                 }
-                 else return FALSE;
-                     
-             }
-             else
-             {
-                 /* really need some sort of detection here */
-		 if (info->HasPanelRegs) {
-		 	info->DisplayType = MT_LCD;
-		 } else if (info->isDFP) {
-			info->DisplayType = MT_DFP;
-                 } else 
-                 {
-                     /*DVI port has no monitor connected, try CRT port.
-                     If something on CRT port, treat it as primary*/
-                     if(xf86IsEntityShared(pScrn->entityList[0]))
-                     {
-                         R128EntPtr pR128Ent = R128EntPriv(pScrn);
-                         pR128Ent->BypassSecondary = TRUE;
-                     }
-
-                     info->DisplayType = MT_CRT;
-#if 0
-                     {
-                         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-                             "No monitor detected!!!\n");
-                         return FALSE;
-                     }
-#endif
-                 }
-             }
-         }
-         else
-         {
-             /*Regular Radeon ASIC, only one CRTC, but it could be
-               used for DFP with a DVI output, like AIW board*/
-             if(info->isDFP) info->DisplayType = MT_DFP;
-             else info->DisplayType = MT_CRT;
-         }
-
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%s Display == Type %d\n",
-              (info->IsSecondary ? "Secondary" : "Primary"), 
-               info->DisplayType);
-
-
-    if (info->VBIOS && info->DisplayType == MT_LCD) {
-	info->FPBIOSstart = 0;
-
-	/* FIXME: There should be direct access to the start of the FP info
-	   tables, but until we find out where that offset is stored, we
-	   must search for the ATI signature string: "M3      ". */
-	for (i = 4; i < R128_VBIOS_SIZE-8; i++) {
-	    if (R128_BIOS8(i)   == 'M' &&
-		R128_BIOS8(i+1) == '3' &&
-		R128_BIOS8(i+2) == ' ' &&
-		R128_BIOS8(i+3) == ' ' &&
-		R128_BIOS8(i+4) == ' ' &&
-		R128_BIOS8(i+5) == ' ' &&
-		R128_BIOS8(i+6) == ' ' &&
-		R128_BIOS8(i+7) == ' ') {
-		FPHeader = i-2;
-		break;
-	    }
-	}
 
-	if (!FPHeader) return TRUE;
+    return TRUE;
+}
 
-	/* Assume that only one panel is attached and supported */
-	for (i = FPHeader+20; i < FPHeader+84; i += 2) {
-	    if (R128_BIOS16(i) != 0) {
-		info->FPBIOSstart = R128_BIOS16(i);
-		break;
-	    }
-	}
-	if (!info->FPBIOSstart) return TRUE;
-
-	if (!info->PanelXRes)
-	    info->PanelXRes = R128_BIOS16(info->FPBIOSstart+25);
-	if (!info->PanelYRes)
-	    info->PanelYRes = R128_BIOS16(info->FPBIOSstart+27);
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Panel size: %dx%d\n",
-		   info->PanelXRes, info->PanelYRes);
-
-	info->PanelPwrDly = R128_BIOS8(info->FPBIOSstart+56);
-
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Panel ID: ");
-	for (i = 1; i <= 24; i++)
-	    ErrorF("%c", R128_BIOS8(info->FPBIOSstart+i));
-	ErrorF("\n");
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Panel Type: ");
-	i = R128_BIOS16(info->FPBIOSstart+29);
-	if (i & 1) ErrorF("Color, ");
-	else       ErrorF("Monochrome, ");
-	if (i & 2) ErrorF("Dual(split), ");
-	else       ErrorF("Single, ");
-	switch ((i >> 2) & 0x3f) {
-	case 0:  ErrorF("STN");        break;
-	case 1:  ErrorF("TFT");        break;
-	case 2:  ErrorF("Active STN"); break;
-	case 3:  ErrorF("EL");         break;
-	case 4:  ErrorF("Plasma");     break;
-	default: ErrorF("UNKNOWN");    break;
-	}
-	ErrorF("\n");
-	if (R128_BIOS8(info->FPBIOSstart+61) & 1) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Panel Interface: LVDS\n");
-	} else {
-	    /* FIXME: Add Non-LVDS flat pael support */
-	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		       "Non-LVDS panel interface detected!  "
-		       "This support is untested and may not "
-		       "function properly\n");
-	}
+/* Read the FP parameters if an LVDS panel is expected. */
+void R128GetPanelInfoFromBIOS(xf86OutputPtr output)
+{
+    ScrnInfoPtr pScrn = output->scrn;
+    R128InfoPtr info  = R128PTR(pScrn);
+    R128OutputPrivatePtr r128_output = output->driver_private;
+    int FPHeader = 0;
+    int i;
+
+    if (!info->VBIOS) return;
+    info->FPBIOSstart = 0;
+
+    /* FIXME: There should be direct access to the start of the FP info
+     * tables, but until we find out where that offset is stored, we
+     * must search for the ATI signature string: "M3      ".
+     */
+    for (i = 4; i < R128_VBIOS_SIZE - 8; i++) {
+        if (R128_BIOS8(i)     == 'M' &&
+            R128_BIOS8(i + 1) == '3' &&
+            R128_BIOS8(i + 2) == ' ' &&
+            R128_BIOS8(i + 3) == ' ' &&
+            R128_BIOS8(i + 4) == ' ' &&
+            R128_BIOS8(i + 5) == ' ' &&
+            R128_BIOS8(i + 6) == ' ' &&
+            R128_BIOS8(i + 7) == ' ') {
+            FPHeader = i - 2;
+            break;
+        }
+    }
+
+    if (!FPHeader) return;
+
+    /* Assume that only one panel is attached and supported */
+    for (i = FPHeader+20; i < FPHeader+84; i += 2) {
+        if (R128_BIOS16(i) != 0) {
+            info->FPBIOSstart = R128_BIOS16(i);
+            break;
+        }
     }
 
-    if (!info->PanelXRes || !info->PanelYRes) {
+    if (!info->FPBIOSstart) return;
+    xf86GetOptValInteger(info->Options, OPTION_PANEL_WIDTH,  &(r128_output->PanelXRes));
+    xf86GetOptValInteger(info->Options, OPTION_PANEL_HEIGHT, &(r128_output->PanelYRes));
+
+    if (!r128_output->PanelXRes)
+        r128_output->PanelXRes = R128_BIOS16(info->FPBIOSstart + 25);
+    if (!r128_output->PanelYRes)
+        r128_output->PanelYRes = R128_BIOS16(info->FPBIOSstart + 27);
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Panel size: %dx%d\n",
+               r128_output->PanelXRes, r128_output->PanelYRes);
+
+    r128_output->PanelPwrDly = R128_BIOS8(info->FPBIOSstart + 56);
+
+    if (!r128_output->PanelXRes || !r128_output->PanelYRes) {
         info->HasPanelRegs = FALSE;
         xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
 		   "Can't determine panel dimensions, and none specified.\n"
 		   "\tDisabling programming of FP registers.\n");
     }
 
-    return TRUE;
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Panel ID: ");
+    for (i = 1; i <= 24; i++)
+        ErrorF("%c", R128_BIOS8(info->FPBIOSstart + i));
+
+    ErrorF("\n");
+
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Panel Type: ");
+    i = R128_BIOS16(info->FPBIOSstart + 29);
+    if (i & 1) ErrorF("Color, ");
+    else       ErrorF("Monochrome, ");
+    if (i & 2) ErrorF("Dual(split), ");
+    else       ErrorF("Single, ");
+
+    switch ((i >> 2) & 0x3f) {
+    case 0:  ErrorF("STN");        break;
+    case 1:  ErrorF("TFT");        break;
+    case 2:  ErrorF("Active STN"); break;
+    case 3:  ErrorF("EL");         break;
+    case 4:  ErrorF("Plasma");     break;
+    default: ErrorF("UNKNOWN");    break;
+    }
+
+    ErrorF("\n");
+
+    if (R128_BIOS8(info->FPBIOSstart + 61) & 1) {
+        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Panel Interface: LVDS\n");
+    } else {
+        /* FIXME: Add Non-LVDS flat pael support */
+        xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+                   "Non-LVDS panel interface detected!  "
+                   "This support is untested and may not "
+                   "function properly\n");
+    }
 }
 
 /* Read PLL parameters from BIOS block.  Default to typical values if there
@@ -956,39 +913,6 @@ static Bool R128PreInitConfig(ScrnInfoPtr pScrn)
     info->MemCntl             = INREG(R128_MEM_CNTL);
     info->BusCntl             = INREG(R128_BUS_CNTL);
 
-    /* On non-flat panel systems, the default is to display to the CRT,
-       and on flat panel systems, the default is to display to the flat
-       panel unless the user explicity chooses otherwise using the "Display"
-       config file setting.  BIOS_5_SCRATCH holds the display device on flat
-       panel systems only. */
-    if (info->HasPanelRegs) {
-        char *Display = xf86GetOptValString(info->Options, OPTION_DISPLAY);
-
-	if (info->FBDev)
-	    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-		     "Option \"Display\" ignored "
-		     "(framebuffer device determines display type)\n");
-	else if (!Display)
-	    info->BIOSDisplay = R128_DUALHEAD;
-	else if (!xf86NameCmp(Display, "FP"))
-	    info->BIOSDisplay = R128_BIOS_DISPLAY_FP;
-	else if (!xf86NameCmp(Display, "BIOS"))
-	    info->BIOSDisplay = INREG8(R128_BIOS_5_SCRATCH);
-	else if (!xf86NameCmp(Display, "Mirror"))
-	    info->BIOSDisplay = R128_BIOS_DISPLAY_FP_CRT;
-	else if (!xf86NameCmp(Display, "CRT"))
-	    info->BIOSDisplay = R128_BIOS_DISPLAY_CRT;
-	else {
-	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		"Unsupported type \"%s\" specified for Option \"Display\".\n"
-		"\tSupported types are: "
-		"\"BIOS\", \"Mirror\", \"CRT\" and \"FP\"\n", Display);
-	    return FALSE;
-	}
-    } else {
-	info->BIOSDisplay     = R128_BIOS_DISPLAY_CRT;
-    }
-
 				/* RAM */
     switch (info->MemCntl & 0x3) {
     case 0:                     /* SDR SGRAM 1:1 */
@@ -1027,62 +951,9 @@ static Bool R128PreInitConfig(ScrnInfoPtr pScrn)
     xf86DrvMsg(pScrn->scrnIndex, from,
 	       "VideoRAM: %d kByte (%s)\n", pScrn->videoRam, info->ram->name);
 
-    if (info->IsPrimary) {
-        pScrn->videoRam /= 2;
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, 
-		"Using %dk of videoram for primary head\n",
-		pScrn->videoRam);
-    }
-
-    if (info->IsSecondary) {  
-        pScrn->videoRam /= 2;
-        info->LinearAddr += pScrn->videoRam * 1024;
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, 
-		"Using %dk of videoram for secondary head\n",
-		pScrn->videoRam);
-    }
-
     pScrn->videoRam  &= ~1023;
     info->FbMapSize  = pScrn->videoRam * 1024;
 
-
-				/* Flat panel (part 2) */
-	switch (info->BIOSDisplay) {
-	case R128_DUALHEAD:
-	    xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
-		       "Dual display\n");
-	    break;
-	case R128_BIOS_DISPLAY_FP:
-	    xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
-		       "Using flat panel for display\n");
-	    break;
-	case R128_BIOS_DISPLAY_CRT:
-	    xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
-		       "Using external CRT for display\n");
-	    break;
-	case R128_BIOS_DISPLAY_FP_CRT:
-	    xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
-		       "Using both flat panel and external CRT "
-		       "for display\n");
-	    break;
-	}
-
-    if (info->HasPanelRegs) {
-				/* Panel width/height overrides */
-	info->PanelXRes = 0;
-	info->PanelYRes = 0;
-	if (xf86GetOptValInteger(info->Options,
-				 OPTION_PANEL_WIDTH, &(info->PanelXRes))) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
-		       "Flat panel width: %d\n", info->PanelXRes);
-	}
-	if (xf86GetOptValInteger(info->Options,
-				 OPTION_PANEL_HEIGHT, &(info->PanelYRes))) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
-		       "Flat panel height: %d\n", info->PanelYRes);
-	}
-    }
-
 #ifdef R128DRI
 				/* DMA for Xv */
     info->DMAForXv = xf86ReturnOptValBool(info->Options, OPTION_XV_DMA, FALSE);
@@ -1333,18 +1204,9 @@ static Bool R128PreInitDRI(ScrnInfoPtr pScrn)
 
 static Bool R128PreInitControllers(ScrnInfoPtr pScrn, xf86Int10InfoPtr pInt10)
 {
-    R128InfoPtr info = R128PTR(pScrn);
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-    int i;
-    int mask;
     int found = 0;
-
-    if (info->IsPrimary)
-        mask = 1;
-    else if (info->IsSecondary)
-        mask = 2;
-    else
-        mask = 3;
+    int i;
 
     if (!R128GetBIOSParameters(pScrn, pInt10))
         return FALSE;
@@ -1352,7 +1214,7 @@ static Bool R128PreInitControllers(ScrnInfoPtr pScrn, xf86Int10InfoPtr pInt10)
     if (!R128GetPLLParameters(pScrn))
         return FALSE;
 
-    if (!R128AllocateControllers(pScrn, mask))
+    if (!R128AllocateControllers(pScrn))
         return FALSE;
 
     if (!R128SetupConnectors(pScrn))
@@ -1405,43 +1267,19 @@ Bool R128PreInit(ScrnInfoPtr pScrn, int flags)
 
     if (!R128GetRec(pScrn)) return FALSE;
 
-    info               = R128PTR(pScrn);
-
-    info->IsSecondary  = FALSE;
-    info->IsPrimary = FALSE;
+    info                = R128PTR(pScrn);
     info->SwitchingMode = FALSE;
+    info->MMIO          = NULL;
 
-    info->pEnt         = xf86GetEntityInfo(pScrn->entityList[0]);
+    info->pEnt          = xf86GetEntityInfo(pScrn->entityList[0]);
     if (info->pEnt->location.type != BUS_PCI) goto fail;
 
-    if(xf86IsEntityShared(pScrn->entityList[0]))
-    {
-        if(xf86IsPrimInitDone(pScrn->entityList[0]))
-        {
-            R128EntPtr pR128Ent = R128EntPriv(pScrn);
-            info->IsSecondary = TRUE;
-            if(pR128Ent->BypassSecondary) return FALSE;
-            pR128Ent->pSecondaryScrn = pScrn;
-        }
-        else
-        {
-            R128EntPtr pR128Ent = R128EntPriv(pScrn);
-	    info->IsPrimary = TRUE;
-            xf86SetPrimInitDone(pScrn->entityList[0]);
-            pR128Ent->pPrimaryScrn = pScrn;
-            pR128Ent->BypassSecondary = FALSE;
-            pR128Ent->HasSecondary = FALSE;
-            pR128Ent->RestorePrimary = FALSE;
-            pR128Ent->IsSecondaryRestored = FALSE;
-        }
-    }
-
     if (flags & PROBE_DETECT) {
 	R128ProbeDDC(pScrn, info->pEnt->index);
 	return TRUE;
     }
 
-    info->PciInfo      = xf86GetPciInfoForEntity(info->pEnt->index);
+    info->PciInfo       = xf86GetPciInfoForEntity(info->pEnt->index);
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 	       "PCI bus %d card %d func %d\n",
@@ -1450,16 +1288,16 @@ Bool R128PreInit(ScrnInfoPtr pScrn, int flags)
 	       PCI_DEV_FUNC(info->PciInfo));
 
 #ifndef XSERVER_LIBPCIACCESS
-    info->PciTag       = pciTag(PCI_DEV_BUS(info->PciInfo),
+    info->PciTag        = pciTag(PCI_DEV_BUS(info->PciInfo),
 				PCI_DEV_DEV(info->PciInfo),
 				PCI_DEV_FUNC(info->PciInfo));
 
     if (xf86RegisterResources(info->pEnt->index, 0, ResNone)) goto fail;
     if (xf86SetOperatingState(resVga, info->pEnt->index, ResUnusedOpr)) goto fail;
 
-    pScrn->racMemFlags = RAC_FB | RAC_COLORMAP | RAC_VIEWPORT | RAC_CURSOR;
+    pScrn->racMemFlags  = RAC_FB | RAC_COLORMAP | RAC_VIEWPORT | RAC_CURSOR;
 #endif
-    pScrn->monitor     = pScrn->confScreen->monitor;
+    pScrn->monitor      = pScrn->confScreen->monitor;
 
     /* Allocate an xf86CrtcConfig */
     xf86CrtcConfigInit(pScrn, &R128CRTCResizeFuncs);
@@ -1810,7 +1648,7 @@ Bool R128ScreenInit(SCREEN_INIT_ARGS_DECL)
 
     if (!R128MapMem(pScrn)) return FALSE;
     pScrn->fbOffset    = 0;
-    if(info->IsSecondary) pScrn->fbOffset = pScrn->videoRam * 1024;
+    //if(info->IsSecondary) pScrn->fbOffset = pScrn->videoRam * 1024;
 #ifdef R128DRI
     info->fbX          = 0;
     info->fbY          = 0;
@@ -1857,23 +1695,7 @@ Bool R128ScreenInit(SCREEN_INIT_ARGS_DECL)
 			info->CurrentLayout.pixel_bytes * 3 + 1023) / 1024);
 	    info->directRenderingEnabled = FALSE;
 	} else {
-            if(info->IsSecondary)
-                info->directRenderingEnabled = FALSE;
-            else 
-            {
-                /* Xinerama has sync problem with DRI, disable it for now */
-                if(xf86IsEntityShared(pScrn->entityList[0]))
-                {
-                    info->directRenderingEnabled = FALSE;
- 	            xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-                        "Direct Rendering Disabled -- "
-                        "Dual-head configuration is not working with DRI "
-                        "at present.\nPlease use only one Device/Screen "
-                        "section in your XFConfig file.\n");
-                }
-                else
-                info->directRenderingEnabled = R128DRIScreenInit(pScreen);
-            }
+            info->directRenderingEnabled = R128DRIScreenInit(pScreen);
 	}
     }
 #endif
@@ -2259,8 +2081,7 @@ Bool R128ScreenInit(SCREEN_INIT_ARGS_DECL)
     else
         xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
-    if (!info->IsSecondary)
-	R128InitVideo(pScreen);
+    R128InitVideo(pScreen);
 
 				/* Provide SaveScreen */
     pScreen->SaveScreen  = R128SaveScreen;
@@ -2411,9 +2232,13 @@ void R128RestoreFPRegisters(ScrnInfoPtr pScrn, R128SavePtr restore)
 void R128RestoreLVDSRegisters(ScrnInfoPtr pScrn, R128SavePtr restore)
 {
     R128InfoPtr   info      = R128PTR(pScrn);
+    R128EntPtr    pR128Ent  = R128EntPriv(pScrn);
     unsigned char *R128MMIO = info->MMIO;
     uint32_t      tmp;
 
+    xf86OutputPtr output = R128FirstOutput(pR128Ent->pCrtc[0]);
+    R128OutputPrivatePtr r128_output = output->driver_private;
+
     tmp = INREG(R128_LVDS_GEN_CNTL);
     if ((tmp & (R128_LVDS_ON | R128_LVDS_BLON)) ==
 	(restore->lvds_gen_cntl & (R128_LVDS_ON | R128_LVDS_BLON))) {
@@ -2422,11 +2247,11 @@ void R128RestoreLVDSRegisters(ScrnInfoPtr pScrn, R128SavePtr restore)
 	if (restore->lvds_gen_cntl & (R128_LVDS_ON | R128_LVDS_BLON)) {
 	    OUTREG(R128_LVDS_GEN_CNTL,
 		   restore->lvds_gen_cntl & (uint32_t)~R128_LVDS_BLON);
-	    usleep(R128PTR(pScrn)->PanelPwrDly * 1000);
+	    usleep(r128_output->PanelPwrDly * 1000);
 	    OUTREG(R128_LVDS_GEN_CNTL, restore->lvds_gen_cntl);
 	} else {
 	    OUTREG(R128_LVDS_GEN_CNTL, restore->lvds_gen_cntl | R128_LVDS_BLON);
-	    usleep(R128PTR(pScrn)->PanelPwrDly * 1000);
+	    usleep(r128_output->PanelPwrDly * 1000);
 	    OUTREG(R128_LVDS_GEN_CNTL, restore->lvds_gen_cntl);
 	}
     }
@@ -2664,8 +2489,6 @@ static void R128SaveFPRegisters(ScrnInfoPtr pScrn, R128SavePtr save)
     R128InfoPtr   info      = R128PTR(pScrn);
     unsigned char *R128MMIO = info->MMIO;
 
-    if (info->BIOSDisplay != R128_DUALHEAD)
-        save->crtc2_gen_cntl       = INREG(R128_CRTC2_GEN_CNTL);
     save->fp_crtc_h_total_disp = INREG(R128_FP_CRTC_H_TOTAL_DISP);
     save->fp_crtc_v_total_disp = INREG(R128_FP_CRTC_V_TOTAL_DISP);
     save->fp_gen_cntl          = INREG(R128_FP_GEN_CNTL);
@@ -2769,28 +2592,23 @@ static void R128SavePalette(ScrnInfoPtr pScrn, R128SavePtr save)
 static void R128SaveMode(ScrnInfoPtr pScrn, R128SavePtr save)
 {
     R128InfoPtr   info      = R128PTR(pScrn);
+    R128EntPtr    pR128Ent  = R128EntPriv(pScrn);
 
     R128TRACE(("R128SaveMode(%p)\n", save));
 
-    if(info->IsSecondary)
-    {
+    R128SaveCommonRegisters(pScrn, save);
+    R128SaveCrtcRegisters(pScrn, save);
+    R128SavePLLRegisters(pScrn, save);
+    R128SaveDDARegisters(pScrn, save);
+    if (pR128Ent->HasCRTC2) {
         R128SaveCrtc2Registers(pScrn, save);
         R128SavePLL2Registers(pScrn, save);
         R128SaveDDA2Registers(pScrn, save);
     }
-    else
-    {
-        R128SaveCommonRegisters(pScrn, save);
-        R128SaveCrtcRegisters(pScrn, save);
-        if((info->DisplayType == MT_DFP) || 
-           (info->DisplayType == MT_LCD))
-        {
- 	    R128SaveFPRegisters(pScrn, save);
-        }
-        R128SavePLLRegisters(pScrn, save);
-        R128SaveDDARegisters(pScrn, save);
-        R128SavePalette(pScrn, save);
+    if (info->HasPanelRegs) {
+        R128SaveFPRegisters(pScrn, save);
     }
+    R128SavePalette(pScrn, save);
 
     R128TRACE(("R128SaveMode returns %p\n", save));
 }
@@ -2808,36 +2626,33 @@ static void R128Save(ScrnInfoPtr pScrn)
 	return;
     }
 
-    if (!info->IsSecondary) {
 #ifdef WITH_VGAHW
-        if (info->VGAAccess) {
-            vgaHWPtr hwp = VGAHWPTR(pScrn);
+    if (info->VGAAccess) {
+        vgaHWPtr hwp = VGAHWPTR(pScrn);
 
-            vgaHWUnlock(hwp);
+        vgaHWUnlock(hwp);
 # if defined(__powerpc__)
-            /* temporary hack to prevent crashing on PowerMacs when trying to
-             * read VGA fonts and colormap, will find a better solution
-             * in the future. TODO: Check if there's actually some VGA stuff
-             * setup in the card at all !!
-             */
-            vgaHWSave(pScrn, &hwp->SavedReg, VGA_SR_MODE); /* Save mode only */
+        /* temporary hack to prevent crashing on PowerMacs when trying to
+         * read VGA fonts and colormap, will find a better solution
+         * in the future. TODO: Check if there's actually some VGA stuff
+         * setup in the card at all !!
+         */
+        vgaHWSave(pScrn, &hwp->SavedReg, VGA_SR_MODE); /* Save mode only */
 # else
-            /* Save mode * & fonts & cmap */
-            vgaHWSave(pScrn, &hwp->SavedReg, VGA_SR_MODE | VGA_SR_FONTS);
+        /* Save mode * & fonts & cmap */
+        vgaHWSave(pScrn, &hwp->SavedReg, VGA_SR_MODE | VGA_SR_FONTS);
 # endif
-            vgaHWLock(hwp);
-        }
+        vgaHWLock(hwp);
+    }
 #endif
 
-        save->dp_datatype      = INREG(R128_DP_DATATYPE);
-        save->gen_reset_cntl   = INREG(R128_GEN_RESET_CNTL);
-        save->clock_cntl_index = INREG(R128_CLOCK_CNTL_INDEX);
-        save->amcgpio_en_reg   = INREG(R128_AMCGPIO_EN_REG);
-        save->amcgpio_mask     = INREG(R128_AMCGPIO_MASK);
-    }
+    save->dp_datatype      = INREG(R128_DP_DATATYPE);
+    save->gen_reset_cntl   = INREG(R128_GEN_RESET_CNTL);
+    save->clock_cntl_index = INREG(R128_CLOCK_CNTL_INDEX);
+    save->amcgpio_en_reg   = INREG(R128_AMCGPIO_EN_REG);
+    save->amcgpio_mask     = INREG(R128_AMCGPIO_MASK);
 
     R128SaveMode(pScrn, save);
-
 }
 
 /* Restore the original (text) mode. */
@@ -2856,59 +2671,39 @@ static void R128Restore(ScrnInfoPtr pScrn)
 
     R128Blank(pScrn);
 
-    if (!info->IsSecondary) {
-        OUTREG(R128_AMCGPIO_MASK,     restore->amcgpio_mask);
-        OUTREG(R128_AMCGPIO_EN_REG,   restore->amcgpio_en_reg);
-        OUTREG(R128_CLOCK_CNTL_INDEX, restore->clock_cntl_index);
-        OUTREG(R128_GEN_RESET_CNTL,   restore->gen_reset_cntl);
-        OUTREG(R128_DP_DATATYPE,      restore->dp_datatype);
-
-        R128RestoreCommonRegisters(pScrn, restore);
-        if (pR128Ent->HasCRTC2) {
-            R128RestoreDDA2Registers(pScrn, restore);
-            R128RestoreCrtc2Registers(pScrn, restore);
-            R128RestorePLL2Registers(pScrn, restore);
-        }
-        R128RestoreDDARegisters(pScrn, restore);
-        R128RestoreCrtcRegisters(pScrn, restore);
-        R128RestorePLLRegisters(pScrn, restore);
-        R128RestoreDACRegisters(pScrn, restore);
-        R128RestoreRMXRegisters(pScrn, restore);
-        R128RestoreFPRegisters(pScrn, restore);
-        R128RestoreLVDSRegisters(pScrn, restore);
-    }
+    OUTREG(R128_AMCGPIO_MASK,     restore->amcgpio_mask);
+    OUTREG(R128_AMCGPIO_EN_REG,   restore->amcgpio_en_reg);
+    OUTREG(R128_CLOCK_CNTL_INDEX, restore->clock_cntl_index);
+    OUTREG(R128_GEN_RESET_CNTL,   restore->gen_reset_cntl);
+    OUTREG(R128_DP_DATATYPE,      restore->dp_datatype);
+
+    R128RestoreCommonRegisters(pScrn, restore);
+    if (pR128Ent->HasCRTC2) {
+        R128RestoreDDA2Registers(pScrn, restore);
+        R128RestoreCrtc2Registers(pScrn, restore);
+        R128RestorePLL2Registers(pScrn, restore);
+    }
+    R128RestoreDDARegisters(pScrn, restore);
+    R128RestoreCrtcRegisters(pScrn, restore);
+    R128RestorePLLRegisters(pScrn, restore);
+    R128RestoreDACRegisters(pScrn, restore);
+    R128RestoreRMXRegisters(pScrn, restore);
+    R128RestoreFPRegisters(pScrn, restore);
+    R128RestoreLVDSRegisters(pScrn, restore);
 
 #ifdef WITH_VGAHW
     if (info->VGAAccess) {
         vgaHWPtr hwp = VGAHWPTR(pScrn);
-        if (!info->IsSecondary) {
-            vgaHWUnlock(hwp);
+        vgaHWUnlock(hwp);
 # if defined(__powerpc__)
-            /* Temporary hack to prevent crashing on PowerMacs when trying to
-             * write VGA fonts, will find a better solution in the future
-             */
-            vgaHWRestore(pScrn, &hwp->SavedReg, VGA_SR_MODE );
+        /* Temporary hack to prevent crashing on PowerMacs when trying to
+         * write VGA fonts, will find a better solution in the future
+         */
+        vgaHWRestore(pScrn, &hwp->SavedReg, VGA_SR_MODE );
 # else
-            vgaHWRestore(pScrn, &hwp->SavedReg, VGA_SR_MODE | VGA_SR_FONTS );
+        vgaHWRestore(pScrn, &hwp->SavedReg, VGA_SR_MODE | VGA_SR_FONTS );
 # endif
-            vgaHWLock(hwp);
-        } else {
-            R128EntPtr  pR128Ent = R128EntPriv(pScrn);
-            ScrnInfoPtr   pScrn0 = pR128Ent->pPrimaryScrn;
-            R128InfoPtr info0 = R128PTR(pScrn0);
-            vgaHWPtr      hwp0;
-
-            if (info0->VGAAccess) {
-                hwp0 = VGAHWPTR(pScrn0);
-                vgaHWUnlock(hwp0);
-#if defined(__powerpc__)
-                vgaHWRestore(pScrn0, &hwp0->SavedReg, VGA_SR_MODE);
-#else
-                vgaHWRestore(pScrn0, &hwp0->SavedReg, VGA_SR_MODE | VGA_SR_FONTS );
-#endif
-                vgaHWLock(hwp0);
-            }
-        }
+        vgaHWLock(hwp);
     }
 #endif
 
@@ -3000,9 +2795,13 @@ Bool R128InitCrtc2Base(xf86CrtcPtr crtc, R128SavePtr save, int x, int y)
 }
 
 /* Define CRTC registers for requested video mode. */
-Bool R128InitCrtcRegisters(ScrnInfoPtr pScrn, R128SavePtr save,
-				  DisplayModePtr mode, R128InfoPtr info)
+Bool R128InitCrtcRegisters(xf86CrtcPtr crtc, R128SavePtr save, DisplayModePtr mode)
 {
+    ScrnInfoPtr pScrn = crtc->scrn;
+    R128InfoPtr info  = R128PTR(pScrn);
+    xf86OutputPtr output = R128FirstOutput(crtc);
+    R128OutputPrivatePtr r128_output = output->driver_private;
+
     int    format;
     int    hsync_start;
     int    hsync_wid;
@@ -3026,8 +2825,7 @@ Bool R128InitCrtcRegisters(ScrnInfoPtr pScrn, R128SavePtr save,
 	return FALSE;
     }
 
-    if ((info->DisplayType == MT_DFP) || 
-        (info->DisplayType == MT_LCD))
+    if (r128_output->MonType == MT_LCD || r128_output->MonType == MT_DFP)
 	hsync_fudge = hsync_fudge_fp[format-1];
     else               
         hsync_fudge = hsync_fudge_default[format-1];
@@ -3045,21 +2843,16 @@ Bool R128InitCrtcRegisters(ScrnInfoPtr pScrn, R128SavePtr save,
 			     ? R128_CRTC_CSYNC_EN
 			     : 0));
 
-    if((info->DisplayType == MT_DFP) || 
-       (info->DisplayType == MT_LCD))
-    {
-        save->crtc_gen_cntl &= ~(R128_CRTC_DBL_SCAN_EN | 
-                                  R128_CRTC_INTERLACE_EN);
-    }
+    if (r128_output->MonType == MT_LCD || r128_output->MonType == MT_DFP)
+        save->crtc_gen_cntl &= ~(R128_CRTC_DBL_SCAN_EN | R128_CRTC_INTERLACE_EN);
 
     save->crtc_ext_cntl |= R128_VGA_ATI_LINEAR | R128_XCRT_CNT_EN;
 
-    if(info->isDFP && !info->isPro2)
-    {
-        if(info->PanelXRes < mode->CrtcHDisplay)
-            mode->HDisplay = mode->CrtcHDisplay = info->PanelXRes;
-        if(info->PanelYRes < mode->CrtcVDisplay)
-            mode->VDisplay = mode->CrtcVDisplay = info->PanelYRes;
+    if (info->isDFP && !info->isPro2) {
+        if (r128_output->PanelXRes < mode->CrtcHDisplay)
+            mode->HDisplay = mode->CrtcHDisplay = r128_output->PanelXRes;
+        if (r128_output->PanelYRes < mode->CrtcVDisplay)
+            mode->VDisplay = mode->CrtcVDisplay = r128_output->PanelYRes;
     }
 
     save->crtc_h_total_disp = ((((mode->CrtcHTotal / 8) - 1) & 0xffff)
@@ -3118,9 +2911,11 @@ Bool R128InitCrtcRegisters(ScrnInfoPtr pScrn, R128SavePtr save,
 }
 
 /* Define CRTC2 registers for requested video mode. */
-Bool R128InitCrtc2Registers(ScrnInfoPtr pScrn, R128SavePtr save,
-				  DisplayModePtr mode, R128InfoPtr info)
+Bool R128InitCrtc2Registers(xf86CrtcPtr crtc, R128SavePtr save, DisplayModePtr mode)
 {
+    ScrnInfoPtr pScrn = crtc->scrn;
+    R128InfoPtr info  = R128PTR(pScrn);
+
     int    format;
     int    hsync_start;
     int    hsync_wid;
@@ -3314,9 +3109,10 @@ void R128InitLVDSRegisters(R128SavePtr orig, R128SavePtr save, xf86OutputPtr out
 }
 
 /* Define PLL registers for requested video mode. */
-void R128InitPLLRegisters(ScrnInfoPtr pScrn, R128SavePtr save,
+void R128InitPLLRegisters(xf86CrtcPtr crtc, R128SavePtr save,
 				R128PLLPtr pll, double dot_clock)
 {
+    ScrnInfoPtr pScrn  = crtc->scrn;
     unsigned long freq = dot_clock * 100;
     struct {
 	int divider;
@@ -3366,9 +3162,10 @@ void R128InitPLLRegisters(ScrnInfoPtr pScrn, R128SavePtr save,
 }
 
 /* Define PLL2 registers for requested video mode. */
-void R128InitPLL2Registers(ScrnInfoPtr pScrn, R128SavePtr save,
+void R128InitPLL2Registers(xf86CrtcPtr crtc, R128SavePtr save,
 				   R128PLLPtr pll, double dot_clock)
 {
+    ScrnInfoPtr pScrn  = crtc->scrn;
     unsigned long freq = dot_clock * 100;
     struct {
 	int divider;
@@ -3418,10 +3215,14 @@ void R128InitPLL2Registers(ScrnInfoPtr pScrn, R128SavePtr save,
 }
 
 /* Define DDA registers for requested video mode. */
-Bool R128InitDDARegisters(ScrnInfoPtr pScrn, R128SavePtr save,
-				 R128PLLPtr pll, R128InfoPtr info,
-                                 DisplayModePtr mode)
+Bool R128InitDDARegisters(xf86CrtcPtr crtc, R128SavePtr save,
+				 R128PLLPtr pll, DisplayModePtr mode)
 {
+    ScrnInfoPtr pScrn = crtc->scrn;
+    R128InfoPtr info  = R128PTR(pScrn);
+    xf86OutputPtr output = R128FirstOutput(crtc);
+    R128OutputPrivatePtr r128_output = output->driver_private;
+
     int         DisplayFifoWidth = 128;
     int         DisplayFifoDepth = 32;
     int         XclkFreq;
@@ -3437,10 +3238,10 @@ Bool R128InitDDARegisters(ScrnInfoPtr pScrn, R128SavePtr save,
     VclkFreq = R128Div(pll->reference_freq * save->feedback_div,
 		       pll->reference_div * save->post_div);
 
-    if(info->isDFP && !info->isPro2){
-        if(info->PanelXRes != mode->CrtcHDisplay)
-            VclkFreq = (VclkFreq * mode->CrtcHDisplay)/info->PanelXRes;
-	}
+    if (info->isDFP && !info->isPro2) {
+        if (r128_output->PanelXRes != mode->CrtcHDisplay)
+            VclkFreq = (VclkFreq * mode->CrtcHDisplay) / r128_output->PanelXRes;
+    }
 
     XclksPerTransfer = R128Div(XclkFreq * DisplayFifoWidth,
 			       VclkFreq * (info->CurrentLayout.pixel_bytes * 8));
@@ -3487,10 +3288,14 @@ Bool R128InitDDARegisters(ScrnInfoPtr pScrn, R128SavePtr save,
 }
 
 /* Define DDA2 registers for requested video mode. */
-Bool R128InitDDA2Registers(ScrnInfoPtr pScrn, R128SavePtr save,
-				 R128PLLPtr pll, R128InfoPtr info,
-                                 DisplayModePtr mode)
+Bool R128InitDDA2Registers(xf86CrtcPtr crtc, R128SavePtr save,
+				 R128PLLPtr pll, DisplayModePtr mode)
 {
+    ScrnInfoPtr pScrn = crtc->scrn;
+    R128InfoPtr info  = R128PTR(pScrn);
+    xf86OutputPtr output = R128FirstOutput(crtc);
+    R128OutputPrivatePtr r128_output = output->driver_private;
+
     int         DisplayFifoWidth = 128;
     int         DisplayFifoDepth = 32;
     int         XclkFreq;
@@ -3506,10 +3311,10 @@ Bool R128InitDDA2Registers(ScrnInfoPtr pScrn, R128SavePtr save,
     VclkFreq = R128Div(pll->reference_freq * save->feedback_div_2,
 		       pll->reference_div * save->post_div_2);
 
-    if(info->isDFP && !info->isPro2){
-        if(info->PanelXRes != mode->CrtcHDisplay)
-            VclkFreq = (VclkFreq * mode->CrtcHDisplay)/info->PanelXRes;
-	}
+    if (info->isDFP && !info->isPro2) {
+        if (r128_output->PanelXRes != mode->CrtcHDisplay)
+            VclkFreq = (VclkFreq * mode->CrtcHDisplay) / r128_output->PanelXRes;
+    }
 
     XclksPerTransfer = R128Div(XclkFreq * DisplayFifoWidth,
 			       VclkFreq * (info->CurrentLayout.pixel_bytes * 8));
@@ -3602,42 +3407,40 @@ Bool R128SwitchMode(SWITCH_MODE_ARGS_DECL)
     return ret;
 }
 
-/* Used to disallow modes that are not supported by the hardware. */
-ModeStatus R128ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode,
-                                   Bool verbose, int flags)
+ModeStatus R128DoValidMode(xf86OutputPtr output, DisplayModePtr mode, int flags)
 {
-    SCRN_INFO_PTR(arg);
-    R128InfoPtr   info  = R128PTR(pScrn);
+    ScrnInfoPtr pScrn = output->scrn;
+    R128InfoPtr info  = R128PTR(pScrn);
+    R128OutputPrivatePtr r128_output = output->driver_private;
 
-    if (info->BIOSDisplay == R128_BIOS_DISPLAY_CRT)
-	return MODE_OK;
+    if (r128_output->MonType == MT_CRT)
+        return MODE_OK;
 
-    if(info->isDFP) {
-        if(info->PanelXRes < mode->CrtcHDisplay ||
-           info->PanelYRes < mode->CrtcVDisplay)
+    if (info->isDFP) {
+        if (r128_output->PanelXRes < mode->CrtcHDisplay ||
+            r128_output->PanelYRes < mode->CrtcVDisplay)
             return MODE_NOMODE;
         else
             return MODE_OK;
     }
 
-    if (info->DisplayType == MT_LCD) {
+    if (r128_output->MonType == MT_LCD) {
 	if (mode->Flags & V_INTERLACE) return MODE_NO_INTERLACE;
 	if (mode->Flags & V_DBLSCAN)   return MODE_NO_DBLESCAN;
     }
 
-    if (info->DisplayType == MT_LCD &&
-	info->VBIOS) {
+    if (r128_output->MonType == MT_LCD && info->VBIOS) {
 	int i;
-	for (i = info->FPBIOSstart+64; R128_BIOS16(i) != 0; i += 2) {
+	for (i = info->FPBIOSstart + 64; R128_BIOS16(i) != 0; i += 2) {
 	    int j = R128_BIOS16(i);
 
 	    if (mode->CrtcHDisplay == R128_BIOS16(j) &&
-		mode->CrtcVDisplay == R128_BIOS16(j+2)) {
+		mode->CrtcVDisplay == R128_BIOS16(j + 2)) {
 		if ((flags & MODECHECK_FINAL) == MODECHECK_FINAL) {
 		    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 			       "Modifying mode according to VBIOS: %ix%i [pclk %.1f MHz] for FP to: ",
-			       mode->CrtcHDisplay,mode->CrtcVDisplay,
-			       (float)mode->Clock/1000);
+			       mode->CrtcHDisplay, mode->CrtcVDisplay,
+			       (float)mode->Clock / 1000);
 
 		    /* Assume we are using expanded mode */
 		    if (R128_BIOS16(j+5)) j  = R128_BIOS16(j+5);
@@ -3646,25 +3449,25 @@ ModeStatus R128ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode,
 		    mode->Clock = (uint32_t)R128_BIOS16(j) * 10;
 
 		    mode->HDisplay   = mode->CrtcHDisplay   =
-			((R128_BIOS16(j+10) & 0x01ff)+1)*8;
+			((R128_BIOS16(j + 10) & 0x01ff) + 1) * 8;
 		    mode->HSyncStart = mode->CrtcHSyncStart =
-			((R128_BIOS16(j+12) & 0x01ff)+1)*8;
+			((R128_BIOS16(j + 12) & 0x01ff) + 1) * 8;
 		    mode->HSyncEnd   = mode->CrtcHSyncEnd   =
-			mode->CrtcHSyncStart + (R128_BIOS8(j+14) & 0x1f);
+			mode->CrtcHSyncStart + (R128_BIOS8(j + 14) & 0x1f);
 		    mode->HTotal     = mode->CrtcHTotal     =
-			((R128_BIOS16(j+8)  & 0x01ff)+1)*8;
+			((R128_BIOS16(j + 8)  & 0x01ff) + 1) * 8;
 
 		    mode->VDisplay   = mode->CrtcVDisplay   =
-			(R128_BIOS16(j+17) & 0x07ff)+1;
+			(R128_BIOS16(j + 17) & 0x07ff) + 1;
 		    mode->VSyncStart = mode->CrtcVSyncStart =
-			(R128_BIOS16(j+19) & 0x07ff)+1;
+			(R128_BIOS16(j + 19) & 0x07ff) + 1;
 		    mode->VSyncEnd   = mode->CrtcVSyncEnd   =
-			mode->CrtcVSyncStart + ((R128_BIOS16(j+19) >> 11) & 0x1f);
+			mode->CrtcVSyncStart + ((R128_BIOS16(j + 19) >> 11) & 0x1f);
 		    mode->VTotal     = mode->CrtcVTotal     =
-			(R128_BIOS16(j+15) & 0x07ff)+1;
+			(R128_BIOS16(j + 15) & 0x07ff) + 1;
 		    xf86ErrorF("%ix%i [pclk %.1f MHz]\n",
 			       mode->CrtcHDisplay,mode->CrtcVDisplay,
-			       (float)mode->Clock/1000);
+			       (float)mode->Clock/ 1000);
 		}
 		return MODE_OK;
 	    }
@@ -3680,6 +3483,17 @@ ModeStatus R128ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode,
     return MODE_OK;
 }
 
+/* Used to disallow modes that are not supported by the hardware. */
+ModeStatus R128ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode,
+                                   Bool verbose, int flags)
+{
+    SCRN_INFO_PTR(arg);
+    R128EntPtr  pR128Ent = R128EntPriv(pScrn);
+    xf86OutputPtr output = R128FirstOutput(pR128Ent->pCrtc[0]);
+
+    return R128DoValidMode(output, mode, flags);
+}
+
 /* Adjust viewport into virtual desktop such that (0,0) in viewport space
    is (x,y) in virtual space. */
 void R128AdjustFrame(ADJUST_FRAME_ARGS_DECL)
@@ -3706,14 +3520,7 @@ void R128AdjustFrame(ADJUST_FRAME_ARGS_DECL)
     if (info->CurrentLayout.pixel_code == 24)
 	Base += 8 * (Base % 3); /* Must be multiple of 8 and 3 */
 
-    if(info->IsSecondary)    
-    {
-        Base += pScrn->fbOffset; 
-        OUTREG(R128_CRTC2_OFFSET, Base);
-    }
-    else
     OUTREG(R128_CRTC_OFFSET, Base);
-
 }
 
 /* Called when VT switching back to the X server.  Reinitialize the video
diff --git a/src/r128_output.c b/src/r128_output.c
index 757ef9b..8ef6d45 100644
--- a/src/r128_output.c
+++ b/src/r128_output.c
@@ -181,7 +181,7 @@ void R128DPMSSetOn(xf86OutputPtr output)
     switch(MonType) {
     case MT_LCD:
         OUTREGP(R128_LVDS_GEN_CNTL, R128_LVDS_BLON, ~R128_LVDS_BLON);
-        usleep(info->PanelPwrDly * 1000);
+        usleep(r128_output->PanelPwrDly * 1000);
         OUTREGP(R128_LVDS_GEN_CNTL, R128_LVDS_ON, ~R128_LVDS_ON);
         save->lvds_gen_cntl |=     (R128_LVDS_ON | R128_LVDS_BLON);
         break;
@@ -307,7 +307,7 @@ DisplayModePtr R128ProbeOutputModes(xf86OutputPtr output)
     for (mode = modes; mode != NULL; mode = mode->next) {
 	xf86SetModeCrtc(mode, INTERLACE_HALVE_V);
 	if (mode->status == MODE_OK)
-            mode->status = R128ValidMode(XF86_SCRN_ARG(pScrn), mode, TRUE, MODECHECK_FINAL);
+            mode->status = R128DoValidMode(output, mode, MODECHECK_FINAL);
     }
 
     xf86ValidateModesUserConfig(pScrn, modes);
@@ -457,10 +457,10 @@ Bool R128SetupConnectors(ScrnInfoPtr pScrn)
             }
             r128_output->ddc_i2c = i2c;
             R128I2CInit(output, &r128_output->pI2CBus, output->name);
-        } else if (otypes[i] == OUTPUT_LVDS) {
-            r128_output->PanelXRes = info->PanelXRes;
-            r128_output->PanelYRes = info->PanelYRes;
         }
+
+        if (otypes[i] != OUTPUT_VGA)
+            R128GetPanelInfoFromBIOS(output);
     }
 
     return TRUE;
diff --git a/src/r128_probe.c b/src/r128_probe.c
index 348d15b..9771d52 100644
--- a/src/r128_probe.c
+++ b/src/r128_probe.c
@@ -288,7 +288,6 @@ r128_get_scrninfo(int entity_num)
                 R128EntPtr pR128Ent;
                 pPriv->ptr = xnfcalloc(sizeof(R128EntRec), 1);
                 pR128Ent = pPriv->ptr;
-                pR128Ent->BypassSecondary = FALSE;
                 pR128Ent->HasSecondary = FALSE;
                 pR128Ent->IsSecondaryRestored = FALSE;
             }
diff --git a/src/r128_probe.h b/src/r128_probe.h
index fef210d..0b54d21 100644
--- a/src/r128_probe.h
+++ b/src/r128_probe.h
@@ -142,6 +142,7 @@ typedef struct _R128OutputPrivateRec {
     R128I2CBusRec ddc_i2c;
     int PanelXRes;
     int PanelYRes;
+    int PanelPwrDly;
 } R128OutputPrivateRec, *R128OutputPrivatePtr;
 
 #define R128_MAX_CRTC 2
@@ -151,7 +152,6 @@ typedef struct
 {
     Bool HasSecondary;
     Bool HasCRTC2;
-    Bool BypassSecondary;
     /*These two registers are used to make sure the CRTC2 is
       retored before CRTC_EXT, otherwise it could lead to blank screen.*/
     Bool IsSecondaryRestored;
@@ -160,7 +160,7 @@ typedef struct
     xf86CrtcPtr pCrtc[R128_MAX_CRTC];
     R128CrtcPrivatePtr Controller[R128_MAX_CRTC];
 
-    ScrnInfoPtr pSecondaryScrn;    
+    ScrnInfoPtr pSecondaryScrn;
     ScrnInfoPtr pPrimaryScrn;
 } R128EntRec, *R128EntPtr;
 
diff --git a/src/r128_video.c b/src/r128_video.c
index b0059b5..dc1f25b 100644
--- a/src/r128_video.c
+++ b/src/r128_video.c
@@ -661,8 +661,12 @@ R128DisplayVideo422(
     short drw_w, short drw_h
 ){
     R128InfoPtr info = R128PTR(pScrn);
+    R128EntPtr pR128Ent = R128EntPriv(pScrn);
+    xf86OutputPtr output = R128FirstOutput(pR128Ent->pCrtc[0]);
+    R128OutputPrivatePtr r128_output = output->driver_private;
     unsigned char *R128MMIO = info->MMIO;
     R128PortPrivPtr pPriv = info->adaptor->pPortPrivates[0].ptr;
+
     int v_inc, h_inc, step_by, tmp, v_inc_shift;
     int p1_h_accum_init, p23_h_accum_init;
     int p1_v_accum_init;
@@ -678,7 +682,7 @@ R128DisplayVideo422(
 
     rmx_active = INREG(R128_FP_VERT_STRETCH) & R128_VERT_STRETCH_ENABLE;
     if (rmx_active) {
-        v_inc = ((src_h * pScrn->currentMode->CrtcVDisplay / info->PanelYRes) << v_inc_shift) / drw_h;
+        v_inc = ((src_h * pScrn->currentMode->CrtcVDisplay / r128_output->PanelYRes) << v_inc_shift) / drw_h;
     } else {
         v_inc = (src_h << v_inc_shift) / drw_h;
     }
@@ -747,6 +751,9 @@ R128DisplayVideo420(
     short drw_w, short drw_h
 ){
     R128InfoPtr info = R128PTR(pScrn);
+    R128EntPtr pR128Ent = R128EntPriv(pScrn);
+    xf86OutputPtr output = R128FirstOutput(pR128Ent->pCrtc[0]);
+    R128OutputPrivatePtr r128_output = output->driver_private;
     unsigned char *R128MMIO = info->MMIO;
     R128PortPrivPtr pPriv = info->adaptor->pPortPrivates[0].ptr;
     int v_inc, h_inc, step_by, tmp, leftUV, v_inc_shift;
@@ -762,7 +769,7 @@ R128DisplayVideo420(
 
     rmx_active = INREG(R128_FP_VERT_STRETCH) & R128_VERT_STRETCH_ENABLE;
     if (rmx_active) {
-        v_inc = ((src_h * pScrn->currentMode->CrtcVDisplay / info->PanelYRes) << v_inc_shift) / drw_h;
+        v_inc = ((src_h * pScrn->currentMode->CrtcVDisplay / r128_output->PanelYRes) << v_inc_shift) / drw_h;
     } else {
         v_inc = (src_h << v_inc_shift) / drw_h;
     }
commit 2072d9aa1a144e699f020a7f9e6a870e410bc9d7
Author: Connor Behan <connor.behan at gmail.com>
Date:   Wed Aug 6 15:41:02 2014 -0700

    Improve handling of monitor and output types
    
    Checking for OUTPUT_DVI is not the same as checking for MT_DFP. There
    might be r128 cards with a DVI-I connector. These have the capability of
    driving an MT_CRT so we now check the monitor type before programming
    DAC or TMDS registers.
    
    This patch also removes R128ConnectorType and R128BIOSConnector because
    they were not doing much. These data structures are more useful for the
    radeon driver where there is a much wider range of cards.
    
    Signed-off-by: Connor Behan <connor.behan at gmail.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/src/r128.h b/src/r128.h
index 6df1b51..d8748b7 100644
--- a/src/r128.h
+++ b/src/r128.h
@@ -504,7 +504,6 @@ typedef struct {
     Bool              DDC;
 
     Bool              VGAAccess;
-    R128BIOSConnector BiosConnector[R128_MAX_BIOS_CONNECTOR];
 
     /****** Added for dualhead support *******************/
     BOOL              IsSecondary;  /* second Screen */
diff --git a/src/r128_driver.c b/src/r128_driver.c
index c541bfa..ce38b4e 100644
--- a/src/r128_driver.c
+++ b/src/r128_driver.c
@@ -3225,7 +3225,7 @@ void R128InitRMXRegisters(R128SavePtr orig, R128SavePtr save,
     save->fp_h_sync_strt_wid   = save->crtc_h_sync_strt_wid;
     save->fp_v_sync_strt_wid   = save->crtc_v_sync_strt_wid;
 
-    if (r128_output->type != OUTPUT_DVI && r128_output->type != OUTPUT_LVDS)
+    if (r128_output->MonType != MT_DFP && r128_output->MonType != MT_LCD)
         return;
 
     if (r128_output->PanelXRes == 0 || r128_output->PanelYRes == 0) {
diff --git a/src/r128_output.c b/src/r128_output.c
index 7bb2e2a..757ef9b 100644
--- a/src/r128_output.c
+++ b/src/r128_output.c
@@ -90,21 +90,21 @@ static void r128_mode_set(xf86OutputPtr output, DisplayModePtr mode, DisplayMode
     if (r128_crtc->crtc_id == 0)
         R128InitRMXRegisters(&info->SavedReg, &info->ModeReg, output, adjusted_mode);
 
-    if (r128_output->type == OUTPUT_DVI)
+    if (r128_output->MonType == MT_DFP)
         R128InitFPRegisters(&info->SavedReg, &info->ModeReg, output);
-    else if (r128_output->type == OUTPUT_LVDS)
+    else if (r128_output->MonType == MT_LCD)
         R128InitLVDSRegisters(&info->SavedReg, &info->ModeReg, output);
-    else if (r128_output->type == OUTPUT_VGA)
+    else if (r128_output->MonType == MT_CRT)
         R128InitDACRegisters(&info->SavedReg, &info->ModeReg, output);
 
     if (r128_crtc->crtc_id == 0)
         R128RestoreRMXRegisters(pScrn, &info->ModeReg);
 
-    if (r128_output->type == OUTPUT_DVI)
+    if (r128_output->MonType == MT_DFP)
         R128RestoreFPRegisters(pScrn, &info->ModeReg);
-    else if (r128_output->type == OUTPUT_LVDS)
+    else if (r128_output->MonType == MT_LCD)
         R128RestoreLVDSRegisters(pScrn, &info->ModeReg);
-    else if (r128_output->type == OUTPUT_VGA)
+    else if (r128_output->MonType == MT_CRT)
         R128RestoreDACRegisters(pScrn, &info->ModeReg);
 }
 
@@ -375,133 +375,91 @@ static Bool R128I2CInit(xf86OutputPtr output, I2CBusPtr *bus_ptr, char *name)
     return TRUE;
 }
 
-void R128SetOutputType(ScrnInfoPtr pScrn, R128OutputPrivatePtr r128_output)
-{
-    R128OutputType output = OUTPUT_NONE;
-
-    switch (r128_output->ConnectorType) {
-    case CONNECTOR_VGA:
-        output = OUTPUT_VGA;
-        break;
-    case CONNECTOR_LVDS:
-        output = OUTPUT_LVDS;
-        break;
-    case CONNECTOR_DVI_D:
-    case CONNECTOR_DVI_I:
-    case CONNECTOR_DVI_A:
-        output = OUTPUT_DVI;
-        break;
-    default:
-        output = OUTPUT_NONE;
-    }
-
-    r128_output->type = output;
-}
-
-void R128SetupGenericConnectors(ScrnInfoPtr pScrn)
+void R128SetupGenericConnectors(ScrnInfoPtr pScrn, R128OutputType *otypes)
 {
     R128InfoPtr info    = R128PTR(pScrn);
     R128EntPtr pR128Ent = R128EntPriv(pScrn);
 
     if (!pR128Ent->HasCRTC2 && !info->isDFP) {
-        info->BiosConnector[0].ConnectorType = CONNECTOR_VGA;
-        info->BiosConnector[0].valid = TRUE;
+        otypes[0] = OUTPUT_VGA;
         return;
     } else if (!pR128Ent->HasCRTC2) {
-        info->BiosConnector[0].ConnectorType = CONNECTOR_DVI_D;
-	info->BiosConnector[0].valid = TRUE;
+        otypes[0] = OUTPUT_DVI;
 	return;
     }
 
-    info->BiosConnector[0].ConnectorType = CONNECTOR_LVDS;
-    info->BiosConnector[0].valid = TRUE;
-
-    info->BiosConnector[1].ConnectorType = CONNECTOR_VGA;
-    info->BiosConnector[1].valid = TRUE;
+    otypes[0] = OUTPUT_LVDS;
+    otypes[1] = OUTPUT_VGA;
 }
 
 Bool R128SetupConnectors(ScrnInfoPtr pScrn)
 {
     R128InfoPtr info    = R128PTR(pScrn);
     R128EntPtr pR128Ent = R128EntPriv(pScrn);
-    xf86OutputPtr output;
+
+    R128OutputType otypes[R128_MAX_BIOS_CONNECTOR];
+    xf86OutputPtr  output;
     int num_vga = 0;
     int num_dvi = 0;
     int i;
 
-    for (i = 0; i < R128_MAX_BIOS_CONNECTOR; i++) {
-        info->BiosConnector[i].valid = FALSE;
-        info->BiosConnector[i].ConnectorType = CONNECTOR_NONE;
-    }
-
     /* XXX: Can we make R128GetConnectorInfoFromBIOS()? */
-    R128SetupGenericConnectors(pScrn);
+    R128SetupGenericConnectors(pScrn, otypes);
 
     for (i = 0; i < R128_MAX_BIOS_CONNECTOR; i++) {
-        if (info->BiosConnector[i].valid) {
-            if ((info->BiosConnector[i].ConnectorType == CONNECTOR_DVI_D) ||
-                (info->BiosConnector[i].ConnectorType == CONNECTOR_DVI_I) ||
-                (info->BiosConnector[i].ConnectorType == CONNECTOR_DVI_A)) {
-                num_dvi++;
-            } else if (info->BiosConnector[i].ConnectorType == CONNECTOR_VGA) {
-                num_vga++;
-            }
-        }
+        if (otypes[i] == OUTPUT_VGA)
+            num_vga++;
+        else if (otypes[i] == OUTPUT_DVI)
+            num_dvi++;
     }
 
     for (i = 0; i < R128_MAX_BIOS_CONNECTOR; i++) {
-        if (info->BiosConnector[i].valid) {
-	    R128I2CBusRec i2c;
-            R128OutputPrivatePtr r128_output;
-            R128ConnectorType conntype = info->BiosConnector[i].ConnectorType;
+        if (otypes[i] == OUTPUT_NONE) continue;
 
-            if (conntype == CONNECTOR_NONE)
-                continue;
+	R128I2CBusRec i2c;
+        R128OutputPrivatePtr r128_output;
 
-            r128_output = xnfcalloc(sizeof(R128OutputPrivateRec), 1);
-            if (!r128_output) return FALSE;
+        r128_output = xnfcalloc(sizeof(R128OutputPrivateRec), 1);
+        if (!r128_output) return FALSE;
 
-            r128_output->MonType = MT_UNKNOWN;
-            r128_output->ConnectorType = conntype;
-            r128_output->num = i;
+        r128_output->MonType = MT_UNKNOWN;
+        r128_output->type = otypes[i];
+        r128_output->num = i;
 
-            if (conntype == CONNECTOR_LVDS) {
-                output = R128OutputCreate(pScrn, "LVDS", 0);
-            } else if (conntype == CONNECTOR_VGA) {
-                output = R128OutputCreate(pScrn, "VGA-%d", --num_vga);
-            } else {
-                output = R128OutputCreate(pScrn, "DVI-%d", --num_dvi);
-            }
+        if (otypes[i] == OUTPUT_LVDS) {
+            output = R128OutputCreate(pScrn, "LVDS", 0);
+        } else if (otypes[i] == OUTPUT_VGA) {
+            output = R128OutputCreate(pScrn, "VGA-%d", --num_vga);
+        } else {
+            output = R128OutputCreate(pScrn, "DVI-%d", --num_dvi);
+        }
 
-            if (!output) return FALSE;
-            output->interlaceAllowed = TRUE;
-            output->doubleScanAllowed = TRUE;
-            output->driver_private = r128_output;
-	    output->possible_clones = 0;
-	    if (conntype == CONNECTOR_LVDS || !pR128Ent->HasCRTC2)
-	        output->possible_crtcs = 1;
-	    else
-	        output->possible_crtcs = 2;
-
-            if (conntype != CONNECTOR_LVDS && info->DDC) {
-		i2c.ddc_reg      = R128_GPIO_MONID;
-		i2c.put_clk_mask = R128_GPIO_MONID_EN_3;
-		i2c.get_clk_mask = R128_GPIO_MONID_Y_3;
-		if (conntype == CONNECTOR_VGA) {
-		    i2c.put_data_mask = R128_GPIO_MONID_EN_1;
-		    i2c.get_data_mask = R128_GPIO_MONID_Y_1;
-		} else {
-		    i2c.put_data_mask = R128_GPIO_MONID_EN_0;
-		    i2c.get_data_mask = R128_GPIO_MONID_Y_0;
-		}
-		r128_output->ddc_i2c = i2c;
-		R128I2CInit(output, &r128_output->pI2CBus, output->name);
-	    } else if (conntype == CONNECTOR_LVDS) {
-                r128_output->PanelXRes = info->PanelXRes;
-                r128_output->PanelYRes = info->PanelYRes;
+        if (!output) return FALSE;
+        output->interlaceAllowed = TRUE;
+        output->doubleScanAllowed = TRUE;
+        output->driver_private = r128_output;
+	output->possible_clones = 0;
+	if (otypes[i] == OUTPUT_LVDS || !pR128Ent->HasCRTC2)
+	    output->possible_crtcs = 1;
+	else
+	    output->possible_crtcs = 2;
+
+        if (otypes[i] != OUTPUT_LVDS && info->DDC) {
+            i2c.ddc_reg      = R128_GPIO_MONID;
+            i2c.put_clk_mask = R128_GPIO_MONID_EN_3;
+            i2c.get_clk_mask = R128_GPIO_MONID_Y_3;
+            if (otypes[i] == OUTPUT_VGA) {
+                i2c.put_data_mask = R128_GPIO_MONID_EN_1;
+                i2c.get_data_mask = R128_GPIO_MONID_Y_1;
+            } else {
+                i2c.put_data_mask = R128_GPIO_MONID_EN_0;
+                i2c.get_data_mask = R128_GPIO_MONID_Y_0;
             }
-
-            R128SetOutputType(pScrn, r128_output);
+            r128_output->ddc_i2c = i2c;
+            R128I2CInit(output, &r128_output->pI2CBus, output->name);
+        } else if (otypes[i] == OUTPUT_LVDS) {
+            r128_output->PanelXRes = info->PanelXRes;
+            r128_output->PanelYRes = info->PanelYRes;
         }
     }
 
diff --git a/src/r128_probe.h b/src/r128_probe.h
index 433463b..fef210d 100644
--- a/src/r128_probe.h
+++ b/src/r128_probe.h
@@ -112,16 +112,6 @@ typedef enum
 
 typedef enum
 {
-    CONNECTOR_NONE,
-    CONNECTOR_VGA,
-    CONNECTOR_DVI_I,
-    CONNECTOR_DVI_D,
-    CONNECTOR_DVI_A,
-    CONNECTOR_LVDS
-} R128ConnectorType;
-
-typedef enum
-{
     OUTPUT_NONE,
     OUTPUT_VGA,
     OUTPUT_DVI,
@@ -144,15 +134,9 @@ typedef struct _R128CrtcPrivateRec {
     uint8_t lut_r[256], lut_g[256], lut_b[256];
 } R128CrtcPrivateRec, *R128CrtcPrivatePtr;
 
-typedef struct {
-    R128ConnectorType ConnectorType;
-    Bool valid;
-} R128BIOSConnector;
-
 typedef struct _R128OutputPrivateRec {
     int num;
     R128OutputType type;
-    R128ConnectorType ConnectorType;
     R128MonitorType MonType;
     I2CBusPtr pI2CBus;
     R128I2CBusRec ddc_i2c;


More information about the xorg-commit mailing list