vserver 1.9.5.x5
[linux-2.6.git] / drivers / video / sis / init301.c
index 82a73bf..2bc5b80 100644 (file)
@@ -1,9 +1,10 @@
 /* $XFree86$ */
+/* $XdotOrg$ */
 /*
  * Mode initializing code (CRT2 section)
  * for SiS 300/305/540/630/730 and
- *     SiS 315/550/650/M650/651/661FX/M661xX/740/741/M741/330/660/M660/760/M760
- * (Universal module for Linux kernel framebuffer and XFree86 4.x)
+ *     SiS 315/550/650/M650/651/661FX/M661xX/740/741(GX)/M741/330/660/M660/760/M760
+ * (Universal module for Linux kernel framebuffer and XFree86/X.org 4.x)
  *
  * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
  *
  * * 2) Redistributions in binary form must reproduce the above copyright
  * *    notice, this list of conditions and the following disclaimer in the
  * *    documentation and/or other materials provided with the distribution.
- * * 3) All advertising materials mentioning features or use of this software
- * *    must display the following acknowledgement: "This product includes
- * *    software developed by Thomas Winischhofer, Vienna, Austria."
- * * 4) The name of the author may not be used to endorse or promote products
+ * * 3) The name of the author may not be used to endorse or promote products
  * *    derived from this software without specific prior written permission.
  * *
- * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
  * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 
 #include "init301.h"
 
-#if 0
-#define TWNEWPANEL
-#endif
-
 #ifdef SIS300
 #include "oem300.h"
 #endif
@@ -91,6 +85,8 @@
 #define SiS_I2CDELAY      1000
 #define SiS_I2CDELAYSHORT  150
 
+static USHORT SiS_GetBIOSLCDResInfo(SiS_Private *SiS_Pr);
+
 /*********************************************/
 /*         HELPER: Lock/Unlock CRT2          */
 /*********************************************/
 void
 SiS_UnLockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
-  if(HwInfo->jChipType >= SIS_315H)
-     SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
-  else
-     SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
+   if(HwInfo->jChipType >= SIS_315H)
+      SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
+   else
+      SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
 }
 
 void
 SiS_LockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
-  if(HwInfo->jChipType >= SIS_315H)
-     SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
-  else
-     SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
-}
-
-/*********************************************/
-/*            HELPER: Enable CRT2            */
-/*********************************************/
-
-void
-SiS_EnableCRT2(SiS_Private *SiS_Pr)
-{
-  SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
+   if(HwInfo->jChipType >= SIS_315H)
+      SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
+   else
+      SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
 }
 
 /*********************************************/
@@ -130,7 +116,10 @@ SiS_EnableCRT2(SiS_Private *SiS_Pr)
 static void
 SiS_SetRegSR11ANDOR(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DataAND, USHORT DataOR)
 {
-   if(HwInfo->jChipType >= SIS_661) DataAND &= 0x0f;
+   if(HwInfo->jChipType >= SIS_661) {
+      DataAND &= 0x0f;
+      DataOR  &= 0x0f;
+   }
    SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR);
 }
 
@@ -138,117 +127,61 @@ SiS_SetRegSR11ANDOR(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DataAND, US
 /*    HELPER: Get Pointer to LCD structure   */
 /*********************************************/
 
-/* For 661 series only */
 #ifdef SIS315H
-#if 0   /* Need to wait until hardware using this really exists */
 static UCHAR *
-GetLCDPtr661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, int tabletype,
-             USHORT ModeNo, USHORT ModeIdIndex, USHORT RRTI)
+GetLCDStructPtr661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
-  UCHAR *ROMAddr =  HwInfo->pjVirtualRomBase;
-  UCHAR *tableptr = NULL;
-  UCHAR tablelengths[] = { 8, 7, 6, 6, 8, 6, 0, 0, 0 };
-  USHORT modeflag, CRT2Index, tablelength, lcdid, myid, tableptri;
-
-  if(ModeNo <= 0x13) {
-     modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-     CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
-  } else {
-     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-     CRT2Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT2CRTC;
-     /* This is total bullshit: */
-     if(SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO == SIS_RI_720x576) CRT2Index = 10;
-  }
-
-  if(tabletype <= 1) {
-#if 0  /* Not yet implemented */
-     if(ModeNo <= 0x13) {
-        CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex]. + 5;
-     } else {
-        CRT2Index = SiS_Pr->SiS_RefIndex[RRTI]. + 5;
-     }
-     if(tabletype & 1) CRT2Index >>= 4;
-#endif
-  }
-
-  CRT2Index &= 0x0f;
-
-  tablelength = tablelengths[tabletype];
-  if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
-     if((tabletype == 5) || (tabletype == 7)) tablelength = 8;
-     if((tabletype == 3) || (tabletype == 8)) tablelength = 8;
-  }
-
-  if(!tablelength) return NULL;
+   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
+   UCHAR  *myptr = NULL;
+   USHORT romindex = 0, reg = 0, idx = 0;
 
-  tableptri = ROMAddr[0x222] | (ROMAddr[0x223] << 8);
-  tableptri += (tabletype << 1);
-  if(!tableptri) return NULL;
-  tableptr = &ROMAddr[tableptri];
+   /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
+    * due to the variaty of panels the BIOS doesn't know about.
+    * Exception: If the BIOS has better knowledge (such as in case
+    * of machines with a 301C and a panel that does not support DDC)
+    * use the BIOS data as well.
+    */
 
-  do {
-     lcdid = tableptr[0];
-     if(lcdid == 0xff) break;
-     myid = SiS_Pr->SiS_LCDResInfo;
-     if((lcdid & 0x80) && (lcdid != 0x80)) {
-        lcdid &= 0x7f;
-       myid = SiS_Pr->SiS_LCDTypeInfo;
-     }
-     if(SiS_Pr->SiS_LCDInfo & LCDPass11) myid &= ~0x1f;
+   if((SiS_Pr->SiS_ROMNew) &&
+      ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) || (!SiS_Pr->PanelSelfDetected))) {
 
-     if(myid == lcdid) {
-       lcdid = tableptr[1] | (tableptr[2] << 8);
-       myid = SiS_Pr->SiS_LCDInfo661;
-       if(modeflag & HalfDCLK) myid |= 0x200;
-       if(ModeNo <= 0x13)      myid |= 0x400;
-       lcdid &= myid;
-       myid = tableptr[3] | (tableptr[4] << 8);
-       if(lcdid == myid) break;
-     }
-     tableptr += 7;
-  } while (1);
+      if(HwInfo->jChipType < SIS_661) reg = 0x3c;
+      else                            reg = 0x7d;
 
-  if(lcdid == myid) {
-     lcdid = tableptr[5] | (tableptr[6] << 8);
-     lcdid += (tablelength * CRT2Index);
-     return((UCHAR *)&ROMAddr[lcdid]);
-  }
+      idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26;
 
-  return NULL;
+      if(idx < (8*26)) {
+         myptr = (UCHAR *)&SiS_LCDStruct661[idx];
+      }
+      romindex = SISGETROMW(0x100);
+      if(romindex) {
+         romindex += idx;
+         myptr = &ROMAddr[romindex];
+      }
+   }
+   return myptr;
 }
-#endif
 
-static UCHAR *
-GetLCDStructPtr661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
+static USHORT
+GetLCDStructPtr661_2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
    UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
-   USHORT lcdres = SiS_Pr->SiS_LCDResInfo;
-   USHORT lcdtype = SiS_Pr->SiS_LCDTypeInfo;
-   USHORT romindex=0;
-   UCHAR  *myptr = NULL;
-   UCHAR  lcdid;
+   USHORT romptr = 0;
 
-   if((ROMAddr) && SiS_Pr->SiS_UseROM) {
-      romindex = ROMAddr[0x256] | (ROMAddr[0x257] << 8);
-   }
-   if(romindex) {
-      myptr = &ROMAddr[romindex];
-   } else {
-      myptr = (UCHAR *)SiS_LCDStruct661;
-   }
+   /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
+    * due to the variaty of panels the BIOS doesn't know about.
+    * Exception: If the BIOS has better knowledge (such as in case
+    * of machines with a 301C and a panel that does not support DDC)
+    * use the BIOS data as well.
+    */
 
-   while(myptr[0] != 0xff) {
-      lcdid = myptr[0];
-      if((lcdid & 0x80) && (lcdid != 0x80)) {
-         lcdres = lcdtype;
-        lcdid &= 0x7f;
-      }
-      if(lcdid == lcdres) break;
-      myptr += 26;
+   if((SiS_Pr->SiS_ROMNew) &&
+      ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) || (!SiS_Pr->PanelSelfDetected))) {
+      romptr = SISGETROMW(0x102);
+      romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
    }
-   if(myptr[0] == 0xff) return NULL;
 
-   return myptr;
+   return(romptr);
 }
 #endif
 
@@ -258,74 +191,74 @@ GetLCDStructPtr661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 
 static BOOLEAN
 SiS_AdjustCRT2Rate(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
-                   USHORT RefreshRateTableIndex, USHORT *i,
-                  PSIS_HW_INFO HwInfo)
+                   USHORT RRTI, USHORT *i, PSIS_HW_INFO HwInfo)
 {
-  USHORT tempax,tempbx,infoflag;
+  USHORT checkmask=0,modeid,infoflag;
 
-  tempbx = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
-
-  tempax = 0;
+  modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID;
 
   if(SiS_Pr->SiS_VBType & VB_SISVB) {
 
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
 
-       tempax |= SupportRAMDAC2;
+       checkmask |= SupportRAMDAC2;
        if(HwInfo->jChipType >= SIS_315H) {
-          tempax |= SupportRAMDAC2_135;
+          checkmask |= SupportRAMDAC2_135;
           if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-             tempax |= SupportRAMDAC2_162;
+             checkmask |= SupportRAMDAC2_162;
              if(SiS_Pr->SiS_VBType & VB_SIS301C) {
-                tempax |= SupportRAMDAC2_202;
+                checkmask |= SupportRAMDAC2_202;
              }
           }
        }
 
      } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
 
-       tempax |= SupportLCD;
+       checkmask |= SupportLCD;
        if(HwInfo->jChipType >= SIS_315H) {
-          if(SiS_Pr->SiS_VBType & VB_SIS301B302B) {
-             if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-                if(tempbx == 0x2e) {  /* 640x480 */
-                   tempax |= Support64048060Hz;
-                }
+          if(SiS_Pr->SiS_VBType & VB_SISVB) {
+             if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+                if(modeid == 0x2e) checkmask |= Support64048060Hz;
              }
           }
        }
 
      } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
 
-       tempax |= SupportHiVision;
+       checkmask |= SupportHiVision;
 
      } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
 
-        tempax |= SupportTV;
+        checkmask |= SupportTV;
        if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-          tempax |= SupportTV1024;
+          checkmask |= SupportTV1024;
+          if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
+             if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
+                checkmask |= SupportYPbPr750p;
+             }
+          }
        }
 
      }
 
-  } else {     /* for LVDS  */
+  } else {     /* LVDS */
 
      if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
        if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-           tempax |= SupportCHTV;
+           checkmask |= SupportCHTV;
        }
      }
 
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-       tempax |= SupportLCD;
+       checkmask |= SupportLCD;
      }
 
   }
 
   /* Look backwards in table for matching CRT2 mode */
-  for(; SiS_Pr->SiS_RefIndex[RefreshRateTableIndex+(*i)].ModeID == tempbx; (*i)--) {
-     infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].Ext_InfoFlag;
-     if(infoflag & tempax) return(1);
+  for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
+     infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
+     if(infoflag & checkmask) return TRUE;
      if((*i) == 0) break;
   }
 
@@ -333,17 +266,15 @@ SiS_AdjustCRT2Rate(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
    * for a matching CRT2 mode if no mode was found yet.
    */
   for((*i) = 0; ; (*i)++) {
-     if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].ModeID != tempbx) {
-       return(0);
-     }
-     infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].Ext_InfoFlag;
-     if(infoflag & tempax) return(1);
+     if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
+     infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
+     if(infoflag & checkmask) return TRUE;
   }
-  return(1);
+  return FALSE;
 }
 
 /*********************************************/
-/*              Get rate pointer             */
+/*              Get rate index               */
 /*********************************************/
 
 USHORT
@@ -355,26 +286,25 @@ SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                               0x01, 0x01, 0x01, 0x01,
                               0x01, 0x01, 0x01, 0x01,
                               0x00, 0x00, 0x00, 0x00 };
-  USHORT RefreshRateTableIndex,i,backup_i;
+  USHORT RRTI,i,backup_i;
   USHORT modeflag,index,temp,backupindex;
 
   /* Do NOT check for UseCustomMode here, will skrew up FIFO */
   if(ModeNo == 0xfe) return 0;
 
-  if(ModeNo <= 0x13)
+  if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-  else
+  } else {
      modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
+  }
 
   if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-       if(modeflag & HalfDCLK) return(0);
+       if(modeflag & HalfDCLK) return 0;
      }
   }
 
-  if(ModeNo < 0x14) return(0xFFFF);
-
-  /* CR33 holds refresh rate index for CRT1 [3:0] and CRT2 [7:4]. */
+  if(ModeNo < 0x14) return 0xFFFF;
 
   index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
   backupindex = index;
@@ -389,7 +319,7 @@ SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
        }
        if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
           if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
-              temp = LCDRefreshIndex[SiS_Pr->SiS_LCDResInfo];
+              temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
               if(index > temp) index = temp;
           }
        }
@@ -401,23 +331,23 @@ SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      }
   }
 
-  RefreshRateTableIndex = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
-  ModeNo = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].ModeID;
+  RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
+  ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID;
 
   if(HwInfo->jChipType >= SIS_315H) {
      if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
         if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
             (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
-           if(backupindex <= 1) RefreshRateTableIndex++;
+           if(backupindex <= 1) RRTI++;
         }
      }
   }
 
   i = 0;
   do {
-     if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + i].ModeID != ModeNo) break;
-     temp = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
-     temp &= ModeInfoFlag;
+     if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break;
+     temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag;
+     temp &= ModeTypeMask;
      if(temp < SiS_Pr->SiS_ModeType) break;
      i++;
      index--;
@@ -425,7 +355,7 @@ SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
   if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
      if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
-       temp = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + i - 1].Ext_InfoFlag;
+       temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag;
        if(temp & InterlaceMode) i++;
      }
   }
@@ -434,12 +364,12 @@ SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
   if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
      backup_i = i;
-     if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, &i, HwInfo))) {
+     if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i, HwInfo))) {
        i = backup_i;
      }
   }
 
-  return(RefreshRateTableIndex + i);
+  return(RRTI + i);
 }
 
 /*********************************************/
@@ -462,37 +392,39 @@ SiS_SaveCRT2Info(SiS_Private *SiS_Pr, USHORT ModeNo)
 /*    HELPER: GET SOME DATA FROM BIOS ROM    */
 /*********************************************/
 
+#ifdef SIS300
 static BOOLEAN
 SiS_CR36BIOSWord23b(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
+  UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
   USHORT temp,temp1;
-  UCHAR *ROMAddr;
 
-  if((ROMAddr = (UCHAR *)HwInfo->pjVirtualRomBase) && SiS_Pr->SiS_UseROM) {
+  if(SiS_Pr->SiS_UseROM) {
      if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
-        temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xff) >> 4);
-        temp1 = (ROMAddr[0x23c] << 8) | ROMAddr[0x23b];
-        if(temp1 & temp) return(1);
+        temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
+        temp1 = SISGETROMW(0x23b);
+        if(temp1 & temp) return TRUE;
      }
   }
-  return(0);
+  return FALSE;
 }
 
 static BOOLEAN
 SiS_CR36BIOSWord23d(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
+  UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
   USHORT temp,temp1;
-  UCHAR *ROMAddr;
 
-  if((ROMAddr = (UCHAR *)HwInfo->pjVirtualRomBase) && SiS_Pr->SiS_UseROM) {
+  if(SiS_Pr->SiS_UseROM) {
      if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
-        temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xff) >> 4);
-        temp1 = (ROMAddr[0x23e] << 8) | ROMAddr[0x23d];
-        if(temp1 & temp) return(1);
+        temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
+        temp1 = SISGETROMW(0x23d);
+        if(temp1 & temp) return TRUE;
      }
   }
-  return(0);
+  return FALSE;
 }
+#endif
 
 /*********************************************/
 /*          HELPER: DELAY FUNCTIONS          */
@@ -508,6 +440,7 @@ SiS_DDC2Delay(SiS_Private *SiS_Pr, USHORT delaytime)
   }
 }
 
+#if defined(SIS300) || defined(SIS315H)
 static void
 SiS_GenericDelay(SiS_Private *SiS_Pr, USHORT delay)
 {
@@ -522,6 +455,7 @@ SiS_GenericDelay(SiS_Private *SiS_Pr, USHORT delay)
      delay--;
   }
 }
+#endif
 
 #ifdef SIS315H
 static void
@@ -533,6 +467,7 @@ SiS_LongDelay(SiS_Private *SiS_Pr, USHORT delay)
 }
 #endif
 
+#if defined(SIS300) || defined(SIS315H)
 static void
 SiS_ShortDelay(SiS_Private *SiS_Pr, USHORT delay)
 {
@@ -540,12 +475,15 @@ SiS_ShortDelay(SiS_Private *SiS_Pr, USHORT delay)
      SiS_GenericDelay(SiS_Pr,0x42);
   }
 }
+#endif
 
 static void
 SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
 {
+#if defined(SIS300) || defined(SIS315H)
   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
   USHORT PanelID, DelayIndex, Delay=0;
+#endif
 
   if(HwInfo->jChipType < SIS_315H) {
 
@@ -553,6 +491,7 @@ SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
 
       PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
       if(SiS_Pr->SiS_VBType & VB_SISVB) {
+         if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7;
          if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
       }
       DelayIndex = PanelID >> 4;
@@ -560,23 +499,19 @@ SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
          Delay = 3;
       } else {
          if(DelayTime >= 2) DelayTime -= 2;
-
          if(!(DelayTime & 0x01)) {
                    Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
          } else {
                    Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
          }
-        if((ROMAddr) && (SiS_Pr->SiS_UseROM)) {
+        if(SiS_Pr->SiS_UseROM) {
             if(ROMAddr[0x220] & 0x40) {
-               if(!(DelayTime & 0x01)) {
-                 Delay = (USHORT)ROMAddr[0x225];
-               } else {
-                 Delay = (USHORT)ROMAddr[0x226];
-               }
+               if(!(DelayTime & 0x01)) Delay = (USHORT)ROMAddr[0x225];
+               else                   Delay = (USHORT)ROMAddr[0x226];
             }
          }
       }
-      SiS_ShortDelay(SiS_Pr,Delay);
+      SiS_ShortDelay(SiS_Pr, Delay);
 
 #endif  /* SIS300 */
 
@@ -584,11 +519,20 @@ SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
 
 #ifdef SIS315H
 
-      if(HwInfo->jChipType >= SIS_330) return;
+      if((HwInfo->jChipType >= SIS_661)    ||
+         (HwInfo->jChipType <= SIS_315PRO) ||
+        (HwInfo->jChipType == SIS_330)    ||
+        (SiS_Pr->SiS_ROMNew)) {
+
+         if(!(DelayTime & 0x01)) {
+           SiS_DDC2Delay(SiS_Pr, 0x1000);
+         } else {
+           SiS_DDC2Delay(SiS_Pr, 0x4000);
+         }
 
-      if((SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
+      } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* ||
          (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-        (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {                      /* 315 series, LVDS; Special */
+        (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) {                  /* 315 series, LVDS; Special */
 
          if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
             PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
@@ -609,7 +553,7 @@ SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
                } else {
                          Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
                }
-              if((ROMAddr) && (SiS_Pr->SiS_UseROM)) {
+              if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
                   if(ROMAddr[0x13c] & 0x40) {
                      if(!(DelayTime & 0x01)) {
                        Delay = (USHORT)ROMAddr[0x17e];
@@ -619,7 +563,7 @@ SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
                   }
                }
             }
-           SiS_ShortDelay(SiS_Pr,Delay);
+           SiS_ShortDelay(SiS_Pr, Delay);
         }
 
       } else if(SiS_Pr->SiS_VBType & VB_SISVB) {                       /* 315 series, all bridges */
@@ -662,7 +606,6 @@ SiS_WaitRetrace1(SiS_Private *SiS_Pr)
   USHORT watchdog;
 
   if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
-
   if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
 
   watchdog = 65535;
@@ -671,6 +614,7 @@ SiS_WaitRetrace1(SiS_Private *SiS_Pr)
   while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
 }
 
+#if defined(SIS300) || defined(SIS315H)
 static void
 SiS_WaitRetrace2(SiS_Private *SiS_Pr, USHORT reg)
 {
@@ -681,6 +625,7 @@ SiS_WaitRetrace2(SiS_Private *SiS_Pr, USHORT reg)
   watchdog = 65535;
   while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
 }
+#endif
 
 static void
 SiS_WaitVBRetrace(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
@@ -718,10 +663,10 @@ SiS_VBWait(SiS_Private *SiS_Pr)
        tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
        if(temp & 0x01) {
           if((tempal & 0x08))  continue;
-          if(!(tempal & 0x08)) break;
+          else break;
        } else {
           if(!(tempal & 0x08)) continue;
-          if((tempal & 0x08))  break;
+          else break;
        }
     }
     temp ^= 0x01;
@@ -742,15 +687,14 @@ SiS_VBLongWait(SiS_Private *SiS_Pr)
 /*               HELPER: MISC                */
 /*********************************************/
 
+#ifdef SIS300
 static BOOLEAN
 SiS_Is301B(SiS_Private *SiS_Pr)
 {
-  USHORT flag;
-
-  flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01);
-  if(flag >= 0xb0) return TRUE;
+  if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return TRUE;
   return FALSE;
 }
+#endif
 
 static BOOLEAN
 SiS_CRT2IsLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
@@ -796,6 +740,16 @@ SiS_IsVAMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
   return FALSE;
 }
 
+#ifdef SIS315H
+static BOOLEAN
+SiS_IsVAorLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
+{
+  if(SiS_IsVAMode(SiS_Pr,HwInfo))   return TRUE;
+  if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) return TRUE;
+  return FALSE;
+}
+#endif
+
 static BOOLEAN
 SiS_IsDualLink(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
@@ -815,7 +769,7 @@ static BOOLEAN
 SiS_TVEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
   if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return TRUE;
-  if(SiS_Pr->SiS_VBType & (VB_301C | VB_SIS301LV302LV)) {
+  if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS301LV302LV)) {
      if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return TRUE;
   }
   return FALSE;
@@ -835,11 +789,8 @@ SiS_LCDAEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 static BOOLEAN
 SiS_WeHaveBacklightCtrl(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
-  USHORT flag;
-
   if((HwInfo->jChipType >= SIS_315H) && (HwInfo->jChipType < SIS_661)) {
-     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
-     if(flag & 0x10) return TRUE;
+     if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return TRUE;
   }
   return FALSE;
 }
@@ -935,12 +886,12 @@ SiS_BridgeIsOn(SiS_Private *SiS_Pr)
   USHORT flag;
 
   if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
-     return FALSE;
+     return TRUE;
   } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
      flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
-     if((flag == 1) || (flag == 2)) return FALSE;
+     if((flag == 1) || (flag == 2)) return TRUE;
   }
-  return TRUE;
+  return FALSE;
 }
 
 static BOOLEAN
@@ -948,21 +899,21 @@ SiS_BridgeIsEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
   USHORT flag;
 
-  if(!(SiS_BridgeIsOn(SiS_Pr))) {
+  if(SiS_BridgeIsOn(SiS_Pr)) {
      flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
      if(HwInfo->jChipType < SIS_315H) {
        flag &= 0xa0;
-       if((flag == 0x80) || (flag == 0x20)) return FALSE;
+       if((flag == 0x80) || (flag == 0x20)) return TRUE;
      } else {
        flag &= 0x50;
-       if((flag == 0x40) || (flag == 0x10)) return FALSE;
+       if((flag == 0x40) || (flag == 0x10)) return TRUE;
      }
   }
-  return TRUE;
+  return FALSE;
 }
 
 static BOOLEAN
-SiS_BridgeInSlave(SiS_Private *SiS_Pr)
+SiS_BridgeInSlavemode(SiS_Private *SiS_Pr)
 {
   USHORT flag1;
 
@@ -984,8 +935,8 @@ SiS_SetChrontelGPIO(SiS_Private *SiS_Pr, USHORT myvbinfo)
 
    if(!(SiS_Pr->SiS_ChSW)) return;
 
-#ifndef LINUX_XF86
-   SiS_SetRegLong(0xcf8,0x80000874);              /* get ACPI base */
+#ifdef LINUX_KERNEL
+   SiS_SetRegLong(0xcf8,0x80000874);                  /* get ACPI base */
    acpibase = SiS_GetRegLong(0xcfc);
 #else
    acpibase = pciReadLong(0x00000800, 0x74);
@@ -1003,30 +954,27 @@ SiS_SetChrontelGPIO(SiS_Private *SiS_Pr, USHORT myvbinfo)
 }
 
 void
-SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo,
-              USHORT ModeIdIndex,PSIS_HW_INFO HwInfo,
-             int checkcrt2mode)
+SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
+              PSIS_HW_INFO HwInfo, int checkcrt2mode)
 {
   USHORT tempax,tempbx,temp;
   USHORT modeflag, resinfo=0;
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
+  } else if(SiS_Pr->UseCustomMode) {
+     modeflag = SiS_Pr->CModeFlag;
   } else {
-     if(SiS_Pr->UseCustomMode) {
-        modeflag = SiS_Pr->CModeFlag;
-     } else {
-       modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-       resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
-     }
+     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
+     resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
   }
 
   SiS_Pr->SiS_SetFlag = 0;
 
-  SiS_Pr->SiS_ModeType = modeflag & ModeInfoFlag;
+  SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask;
 
   tempbx = 0;
-  if(SiS_BridgeIsOn(SiS_Pr) == 0) {
+  if(SiS_BridgeIsOn(SiS_Pr)) {
        temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
 #if 0
        if(HwInfo->jChipType < SIS_661) {
@@ -1048,13 +996,13 @@ SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo,
 
 #ifdef SIS315H
        if(HwInfo->jChipType >= SIS_315H) {
-          if(SiS_Pr->SiS_VBType & (VB_SIS301C|VB_SIS302B|VB_SIS301LV|VB_SIS302LV|VB_SIS302ELV)) {
+          if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
              if(ModeNo == 0x03) {
                 /* Mode 0x03 is never in driver mode */
                 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf);
              }
              if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) {
-                /* Reset LCDA setting */
+                /* Reset LCDA setting if not driver mode */
                 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
              }
              if(IS_SIS650) {
@@ -1071,16 +1019,21 @@ SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo,
                 tempbx |= SetCRT2ToLCDA;
              }
           }
+
+          if(SiS_Pr->SiS_VBType & (VB_SIS301LV|VB_SIS302LV|VB_SIS302ELV)) {
+             tempbx &= ~(SetCRT2ToRAMDAC);
+          }
+
           if(HwInfo->jChipType >= SIS_661) {
              tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision);
              temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
-             if(SiS_Pr->SiS_VBType & (VB_SIS301C|VB_SIS301LV|VB_SIS302LV|VB_SIS302ELV)) {
+             if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
                 if(temp & 0x04) {
                    temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
                    if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
                    else             tempbx |= SetCRT2ToYPbPr525750;
                 }
-             } else if(SiS_Pr->SiS_VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B)) {
+             } else if(SiS_Pr->SiS_VBType & VB_SISHIVISION) {
                 if(temp & 0x04) {
                    temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
                    if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
@@ -1148,24 +1101,12 @@ SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo,
                                SetPALTV           |
                                SwitchCRT2         |
                                SetSimuScanMode );
-          if(tempbx & SetCRT2ToLCDA) {
-              tempbx &= (clearmask | SetCRT2ToLCDA);
-          }
-          if(tempbx & SetCRT2ToRAMDAC) {
-              tempbx &= (clearmask | SetCRT2ToRAMDAC);
-          }
-          if(tempbx & SetCRT2ToLCD) {
-              tempbx &= (clearmask | SetCRT2ToLCD);
-          }
-          if(tempbx & SetCRT2ToSCART) {
-              tempbx &= (clearmask | SetCRT2ToSCART);
-          }
-          if(tempbx & SetCRT2ToHiVision) {
-              tempbx &= (clearmask | SetCRT2ToHiVision);
-          }
-          if(tempbx & SetCRT2ToYPbPr525750) {
-             tempbx &= (clearmask | SetCRT2ToYPbPr525750);
-          }
+          if(tempbx & SetCRT2ToLCDA)        tempbx &= (clearmask | SetCRT2ToLCDA);
+          if(tempbx & SetCRT2ToRAMDAC)      tempbx &= (clearmask | SetCRT2ToRAMDAC);
+          if(tempbx & SetCRT2ToLCD)         tempbx &= (clearmask | SetCRT2ToLCD);
+          if(tempbx & SetCRT2ToSCART)       tempbx &= (clearmask | SetCRT2ToSCART);
+          if(tempbx & SetCRT2ToHiVision)    tempbx &= (clearmask | SetCRT2ToHiVision);
+          if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750);
        } else {
           if(HwInfo->jChipType >= SIS_315H) {
              if(tempbx & SetCRT2ToLCDA) {
@@ -1193,14 +1134,12 @@ SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo,
           }
        }
 
-       if(!(tempbx & DriverMode)){
-          tempbx |= SetSimuScanMode;
-       }
+       if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode;
 
        /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */
        if(SiS_Pr->SiS_ModeType <= ModeVGA) {
           if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
-              ((tempbx & SetCRT2ToLCD) && (SiS_Pr->SiS_VBType & VB_NoLCD)) ) {
+              ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) {
               modeflag &= (~CRT2Mode);
           }
        }
@@ -1218,9 +1157,9 @@ SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo,
                 }
               }
           } else {
-              if(!(SiS_BridgeIsEnabled(SiS_Pr,HwInfo))) {
+              if(SiS_BridgeIsEnabled(SiS_Pr,HwInfo)) {
                 if(!(tempbx & DriverMode)) {
-                   if(SiS_BridgeInSlave(SiS_Pr)) {
+                   if(SiS_BridgeInSlavemode(SiS_Pr)) {
                       tempbx |= SetSimuScanMode;
                    }
                  }
@@ -1346,7 +1285,7 @@ SiS_SetTVMode(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_IN
           if(HwInfo->jChipType >= SIS_330) romindex = 0x11b;
         }
         if(temp) {
-           if(romindex && ROMAddr && SiS_Pr->SiS_UseROM) {
+           if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
              OutputSelect = ROMAddr[romindex];
              if(!(OutputSelect & EnablePALMN)) {
                  SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F);
@@ -1443,6 +1382,22 @@ SiS_SetTVMode(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_IN
        } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
           SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL);
        }
+       if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) {
+          if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) {
+             SiS_Pr->SiS_TVMode |= TVAspect169;
+          } else {
+             temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
+             if(temp1 & 0x02) {
+                if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) {
+                   SiS_Pr->SiS_TVMode |= TVAspect169;
+                } else {
+                   SiS_Pr->SiS_TVMode |= TVAspect43LB;
+                }
+             } else {
+                SiS_Pr->SiS_TVMode |= TVAspect43;
+             }
+          }
+       }
      }
   }
 
@@ -1493,72 +1448,170 @@ SiS_SetTVMode(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_IN
 #ifdef TWDEBUG
   xf86DrvMsg(0, X_INFO, "(init301: TVMode %x, VBInfo %x)\n", SiS_Pr->SiS_TVMode, SiS_Pr->SiS_VBInfo);
 #endif
-
 }
 
 /*********************************************/
 /*               GET LCD INFO                */
 /*********************************************/
 
+static USHORT
+SiS_GetBIOSLCDResInfo(SiS_Private *SiS_Pr)
+{
+   USHORT temp = SiS_Pr->SiS_LCDResInfo;
+   /* Translate my LCDResInfo to BIOS value */
+   if(temp == Panel_1280x768_2)  temp = Panel_1280x768;
+   if(temp == Panel_1280x800_2)  temp = Panel_1280x800;
+   return temp;
+}
+
+static void
+SiS_GetLCDInfoBIOS(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
+{
+#ifdef SIS315H
+   UCHAR  *ROMAddr;
+   USHORT temp;
+
+#ifdef TWDEBUG
+   xf86DrvMsg(0, X_INFO, "Paneldata driver: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
+       SiS_Pr->PanelHT, SiS_Pr->PanelVT,
+       SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
+       SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
+       SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
+       SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
+       SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
+#endif
+
+   if((ROMAddr = GetLCDStructPtr661(SiS_Pr, HwInfo))) {
+      if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
+         SiS_Pr->SiS_NeedRomModeData = TRUE;
+        SiS_Pr->PanelHT  = temp;
+      }
+      if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
+         SiS_Pr->SiS_NeedRomModeData = TRUE;
+         SiS_Pr->PanelVT  = temp;
+      }
+      SiS_Pr->PanelHRS = SISGETROMW(10);
+      SiS_Pr->PanelHRE = SISGETROMW(12);
+      SiS_Pr->PanelVRS = SISGETROMW(14);
+      SiS_Pr->PanelVRE = SISGETROMW(16);
+      SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
+      SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK =
+        SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (USHORT)((UCHAR)ROMAddr[18]);
+      SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B =
+        SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19];
+      SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
+        SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
+
+#ifdef TWDEBUG
+      xf86DrvMsg(0, X_INFO, "Paneldata BIOS:  [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
+       SiS_Pr->PanelHT, SiS_Pr->PanelVT,
+       SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
+       SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
+       SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
+       SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
+       SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
+#endif
+
+   }
+#endif
+}
+
+static void
+SiS_CheckScaling(SiS_Private *SiS_Pr, USHORT resinfo, const UCHAR *nonscalingmodes)
+{
+    int i = 0;
+    while(nonscalingmodes[i] != 0xff) {
+        if(nonscalingmodes[i++] == resinfo) {
+          if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ||
+             (SiS_Pr->UsePanelScaler == -1)) {
+             SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+          }
+          break;
+       }
+    }
+}
+
 void
 SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                  PSIS_HW_INFO HwInfo)
 {
 #ifdef SIS300
-  UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
+  UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
+  const unsigned char SiS300SeriesLCDRes[] =
+          { 0,  1,  2,  3,  7,  4,  5,  8,
+           0,  0, 10,  0,  0,  0,  0, 15 };
 #endif
 #ifdef SIS315H
-  UCHAR  *myptr = NULL;
+  UCHAR   *myptr = NULL;
 #endif
-  USHORT temp,modeflag,resinfo=0;
-  const unsigned char SiS300SeriesLCDRes[] =
-         { 0,  1,  2,  3,  7,  4,  5,  8,
-          0,  0, 10,  0,  0,  0,  0, 15 };
+  USHORT  temp,modeflag,resinfo=0,modexres=0,modeyres=0;
+  BOOLEAN panelcanscale = FALSE;
 
-  SiS_Pr->SiS_LCDResInfo = 0;
+  SiS_Pr->SiS_LCDResInfo  = 0;
   SiS_Pr->SiS_LCDTypeInfo = 0;
-  SiS_Pr->SiS_LCDInfo = 0;
+  SiS_Pr->SiS_LCDInfo     = 0;
+  SiS_Pr->PanelHRS        = 999; /* HSync start */
+  SiS_Pr->PanelHRE        = 999; /* HSync end */
+  SiS_Pr->PanelVRS        = 999; /* VSync start */
+  SiS_Pr->PanelVRE        = 999; /* VSync end */
+  SiS_Pr->SiS_NeedRomModeData = FALSE;
 
-  if(SiS_Pr->UseCustomMode) {
+  if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
+
+  if(ModeNo <= 0x13) {
+     modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
+  } else if(SiS_Pr->UseCustomMode) {
      modeflag = SiS_Pr->CModeFlag;
   } else {
-     if(ModeNo <= 0x13) {
-       modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-     } else {
-       modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-       resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
-     }
+     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
+     resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
+     modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal;
+     modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal;
   }
 
-  if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
-
   temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
 
-  if((HwInfo->jChipType < SIS_315H) || (HwInfo->jChipType >= SIS_661)) {
+  /* For broken BIOSes: Assume 1024x768 */
+  if(temp == 0) temp = 0x02;
+
+  if((HwInfo->jChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
+     SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2;
+  } else if((HwInfo->jChipType < SIS_315H) || (HwInfo->jChipType >= SIS_661)) {
      SiS_Pr->SiS_LCDTypeInfo = temp >> 4;
   } else {
      SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
   }
   temp &= 0x0f;
+#ifdef SIS300
   if(HwInfo->jChipType < SIS_315H) {
-      /* Translate 300 series LCDRes to 315 series for unified usage */
-      temp = SiS300SeriesLCDRes[temp];
+     /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
+     if(SiS_Pr->SiS_VBType & VB_SIS301) {
+        if(temp < 0x0f) temp &= 0x07;
+     }
+     /* Translate 300 series LCDRes to 315 series for unified usage */
+     temp = SiS300SeriesLCDRes[temp];
   }
-  SiS_Pr->SiS_LCDResInfo = temp;
+#endif
 
-  if(SiS_Pr->SiS_VBType & VB_SISVB) {
-     if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
-       SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301;
-  } else {
-     if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS)
-       SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS;
+  /* Translate to our internal types */
+  if(HwInfo->jChipType == SIS_550) {
+     if(temp == Panel310_640x480_2) temp = Panel_640x480_2;
+     if(temp == Panel310_640x480_3) temp = Panel_640x480_3;
   }
 
-  if((!SiS_Pr->CP_HaveCustomData) || (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_PanelCustom)) {
-     if(SiS_Pr->SiS_LCDResInfo > SiS_Pr->SiS_PanelMax)
-       SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_Panel1024x768;
+  if(SiS_Pr->SiS_VBType & VB_SISLVDS) {        /* SiS LVDS */
+     if(temp == Panel310_1280x768) {
+        temp = Panel_1280x768_2;
+     }
+     if(SiS_Pr->SiS_ROMNew) {
+        if(temp == Panel661_1280x800) {
+          temp = Panel_1280x800_2;
+       }
+     }
   }
 
+  SiS_Pr->SiS_LCDResInfo = temp;
+
   if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
      if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
         SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
@@ -1567,113 +1620,439 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      }
   }
 
-  switch(SiS_Pr->SiS_LCDResInfo) {
-     case Panel_800x600:   SiS_Pr->PanelXRes =  800; SiS_Pr->PanelYRes =  600; break;
-     case Panel_1024x768:  SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes =  768; break;
-     case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024; break;
-     case Panel_640x480_3:
-     case Panel_640x480_2:
-     case Panel_640x480:   SiS_Pr->PanelXRes =  640; SiS_Pr->PanelYRes =  480; break;
-     case Panel_1024x600:  SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes =  600; break;
-     case Panel_1152x864:  SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes =  864; break;
-     case Panel_1280x960:  SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes =  960; break;
-     case Panel_1152x768:  SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes =  768; break;
-     case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050; break;
-     case Panel_1280x768:  SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes =  768; break;
-     case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200; break;
-     case Panel_320x480:   SiS_Pr->PanelXRes =  320; SiS_Pr->PanelYRes =  480; break;
-     case Panel_Custom:    SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
-                          SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
-                          break;
-     case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024; break;
-     case Panel_848x480:   SiS_Pr->PanelXRes =  848; SiS_Pr->PanelYRes =  480; break;
-     default:             SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes =  768; break;
+  if(SiS_Pr->SiS_VBType & VB_SISVB) {
+     if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
+       SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301;
+  } else {
+     if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS)
+       SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS;
   }
 
   temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
-  if(HwInfo->jChipType < SIS_661) {
-     temp &= ~0xe;
-  } else {
+  SiS_Pr->SiS_LCDInfo = temp & ~0x000e;
+  /* Need temp below! */
+
+  /* These can't scale no matter what */
+  switch(SiS_Pr->SiS_LCDResInfo) {
+  case Panel_1280x960:
+      SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
+  }
+
+  panelcanscale = (SiS_Pr->SiS_LCDInfo & DontExpandLCD) ? TRUE : FALSE;
+
+  if(!SiS_Pr->UsePanelScaler)          SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
+  else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+
+  /* Dual link, Pass 1:1 BIOS default, etc. */
 #ifdef SIS315H
-     if(!(temp & 0x10)) {
-        if(temp & 0x08) temp |= LCDPass11;
+  if(HwInfo->jChipType >= SIS_661) {
+     if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+        if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
      }
-     temp &= ~0xe;
      if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
-        myptr = GetLCDStructPtr661(SiS_Pr, HwInfo);
-        if(myptr) {
-           if(myptr[2] & 0x01) temp |= LCDDualLink;
+        if(SiS_Pr->SiS_ROMNew) {
+          if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
+       } else if((myptr = GetLCDStructPtr661(SiS_Pr, HwInfo))) {
+           if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
+       }
+     }
+  } else if(HwInfo->jChipType >= SIS_315H) {
+     if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+        if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11;
+     }
+     if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) {
+        SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit);
+       temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
+        if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit;
+       if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
+          if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
+       }
+     } else if(!(SiS_Pr->SiS_ROMNew)) {
+        if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
+           if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
+             (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) {
+             SiS_Pr->SiS_LCDInfo |= LCDDualLink;
+          }
+           if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
+             (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
+              (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
+             (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) {
+             SiS_Pr->SiS_LCDInfo |= LCDDualLink;
+          }
         }
      }
-#endif
   }
-  SiS_Pr->SiS_LCDInfo = temp;
+#endif
 
-  if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
-     if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
-        SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20;   /* neg h/v sync, RGB24 */
+  /* Pass 1:1 */
+  if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
+     /* Always center screen on LVDS (if scaling is disabled) */
+     SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
+  } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
+     if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
+        /* Always center screen on SiS LVDS (if scaling is disabled) */
+        SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
+     } else {
+        /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */
+        if(panelcanscale)             SiS_Pr->SiS_LCDInfo |= LCDPass11;
+        if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
      }
   }
 
-  if(!(SiS_Pr->UsePanelScaler))        SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
-  else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+  SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
+  SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
 
-  if(SiS_Pr->SiS_VBType & VB_SISVB) {
-     if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom) {
-          /* For non-standard LCD resolution, we let the panel scale */
-           SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-          if(ModeNo == 0x7c || ModeNo == 0x7d || ModeNo == 0x7e) {
-             /* We do not scale to 1280x960 (B/C bridges only) */
-              SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
-          }
-          if(((HwInfo->jChipType >= SIS_315H) && (ModeNo == 0x23 || ModeNo == 0x24 || ModeNo == 0x25)) ||
-             ((HwInfo->jChipType < SIS_315H)  && (ModeNo == 0x55 || ModeNo == 0x5a || ModeNo == 0x5b))) {
-             /* We do not scale to 1280x768 (B/C bridges only) */
-              SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
-          }
-          if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
-             /* No non-scaling data available for LV bridges */
-             SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
-          }
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) {
-           /* No idea about the timing and zoom factors */
-           SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
-          if(ModeNo == 0x3a || ModeNo == 0x4d || ModeNo == 0x65) {
-             /* We do not scale to 1280x1024 (all bridges) */
-             SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
-          }
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) {
-          if(SiS_Pr->SiS_VBType & VB_SIS301B302B) {
-             /* No idea about the timing and zoom factors (C bridge only) */
-             SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
-          }
+  switch(SiS_Pr->SiS_LCDResInfo) {
+     case Panel_320x480:    SiS_Pr->PanelXRes =  320; SiS_Pr->PanelYRes =  480;
+                           SiS_Pr->PanelHT   =  400; SiS_Pr->PanelVT   =  525;
+                           SiS_Pr->PanelVCLKIdx300 = VCLK28;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK28;
+                           break;
+     case Panel_640x480_2:
+     case Panel_640x480_3:  SiS_Pr->PanelXRes =  640; SiS_Pr->PanelYRes =  480;
+                           SiS_Pr->PanelVRS  =   24; SiS_Pr->PanelVRE  =    3;
+                           SiS_Pr->PanelVCLKIdx300 = VCLK28;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK28;
+                           break;
+     case Panel_640x480:    SiS_Pr->PanelXRes =  640; SiS_Pr->PanelYRes =  480;
+                                                     SiS_Pr->PanelVRE  =    3;
+                           SiS_Pr->PanelVCLKIdx300 = VCLK28;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK28;
+                           break;
+     case Panel_800x600:    SiS_Pr->PanelXRes =  800; SiS_Pr->PanelYRes =  600;
+                           SiS_Pr->PanelHT   = 1056; SiS_Pr->PanelVT   =  628;
+                           SiS_Pr->PanelHRS  =   40; SiS_Pr->PanelHRE  =  128;
+                           SiS_Pr->PanelVRS  =    1; SiS_Pr->PanelVRE  =    4;
+                           SiS_Pr->PanelVCLKIdx300 = VCLK40;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK40;
+                           break;
+     case Panel_1024x600:   SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes =  600;
+                           SiS_Pr->PanelHT   = 1344; SiS_Pr->PanelVT   =  800;
+                           SiS_Pr->PanelHRS  =   24; SiS_Pr->PanelHRE  =  136;
+                           SiS_Pr->PanelVRS  =    2 /* 88 */ ; SiS_Pr->PanelVRE  =    6;
+                           SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
+                           break;
+     case Panel_1024x768:   SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes =  768;
+                           SiS_Pr->PanelHT   = 1344; SiS_Pr->PanelVT   =  806;
+                           SiS_Pr->PanelHRS  =   24; SiS_Pr->PanelHRE  =  136;
+                           SiS_Pr->PanelVRS  =    3; SiS_Pr->PanelVRE  =    6;
+                           if(HwInfo->jChipType < SIS_315H) {
+                              SiS_Pr->PanelHRS = 23;
+                                                     SiS_Pr->PanelVRE  =    5;
+                           }
+                           SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
+                           SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
+                           break;
+     case Panel_1152x768:   SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes =  768;
+                           SiS_Pr->PanelHT   = 1344; SiS_Pr->PanelVT   =  806;
+                           SiS_Pr->PanelHRS  =   24;
+                           SiS_Pr->PanelVRS  =    3; SiS_Pr->PanelVRE  =    6;
+                           if(HwInfo->jChipType < SIS_315H) {
+                              SiS_Pr->PanelHRS = 23;
+                                                     SiS_Pr->PanelVRE  =    5;
+                           }
+                           SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
+                           break;
+     case Panel_1152x864:   SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes =  864;
+                           break;
+     case Panel_1280x720:   SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes =  720;
+                           SiS_Pr->PanelHT   = 1650; SiS_Pr->PanelVT   =  750;
+                           SiS_Pr->PanelHRS  =  110; SiS_Pr->PanelHRE  =   40;
+                           SiS_Pr->PanelVRS  =    5; SiS_Pr->PanelVRE  =    5;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720;
+                           /* Data above for TMDS (projector); get from BIOS for LVDS */
+                           SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
+                           break;
+     case Panel_1280x768:   SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes =  768;
+                           if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
+                              SiS_Pr->PanelHT   = 1408; SiS_Pr->PanelVT   =  806;
+                              SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */
+                              SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */
+                           } else {
+                              SiS_Pr->PanelHT   = 1688; SiS_Pr->PanelVT   =  802;
+                              SiS_Pr->PanelHRS  =   48; SiS_Pr->PanelHRS  =  112;
+                              SiS_Pr->PanelVRS  =    3; SiS_Pr->PanelVRE  =    6;
+                              SiS_Pr->PanelVCLKIdx300 = VCLK81_300;
+                              SiS_Pr->PanelVCLKIdx315 = VCLK81_315;
+                           }
+                           break;
+     case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes =  768;
+                           SiS_Pr->PanelHT   = 1660; SiS_Pr->PanelVT   =  806;
+                           SiS_Pr->PanelHRS  =   48; SiS_Pr->PanelHRE  =  112;
+                           SiS_Pr->PanelVRS  =    3; SiS_Pr->PanelVRE  =    6;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2;
+                           SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
+                           break;
+     case Panel_1280x800:   SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes =  800;
+                           SiS_Pr->PanelHT   = 1408; SiS_Pr->PanelVT   =  816;
+                           SiS_Pr->PanelHRS   =  21; SiS_Pr->PanelHRE  =   24;
+                           SiS_Pr->PanelVRS   =   4; SiS_Pr->PanelVRE  =    3;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315;
+                           SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
+                           break;
+     case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes =  800;
+                           SiS_Pr->PanelHT   = 1552; SiS_Pr->PanelVT   =  812;
+                           SiS_Pr->PanelHRS   =  48; SiS_Pr->PanelHRE  =  112;
+                           SiS_Pr->PanelVRS   =   4; SiS_Pr->PanelVRE  =    3;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2;
+                           SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
+                           break;
+     case Panel_1280x960:   SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes =  960;
+                           SiS_Pr->PanelHT   = 1800; SiS_Pr->PanelVT   = 1000;
+                           SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315;
+                           if(resinfo == SIS_RI_1280x1024) {
+                              SiS_Pr->PanelVCLKIdx300 = VCLK100_300;
+                              SiS_Pr->PanelVCLKIdx315 = VCLK100_315;
+                           }
+                           break;
+     case Panel_1280x1024:  SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024;
+                           SiS_Pr->PanelHT   = 1688; SiS_Pr->PanelVT   = 1066;
+                           SiS_Pr->PanelHRS  =   48; SiS_Pr->PanelHRE  =  112;
+                           SiS_Pr->PanelVRS  =    1; SiS_Pr->PanelVRE  =    3;
+                           SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
+                           SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
+                           break;
+     case Panel_1400x1050:  SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050;
+                           SiS_Pr->PanelHT   = 1688; SiS_Pr->PanelVT   = 1066;
+                           SiS_Pr->PanelHRS  =   48; SiS_Pr->PanelHRE  =  112; /* HRE OK for LVDS, not for LCDA */
+                           SiS_Pr->PanelVRS  =    1; SiS_Pr->PanelVRE  =    3;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
+                           SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
+                           break;
+     case Panel_1600x1200:  SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200;
+                           SiS_Pr->PanelHT   = 2160; SiS_Pr->PanelVT   = 1250;
+                           SiS_Pr->PanelHRS  =   64; SiS_Pr->PanelHRE  =  192;
+                           SiS_Pr->PanelVRS  =    1; SiS_Pr->PanelVRE  =    3;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK162_315;
+                           SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
+                           break;
+     case Panel_1680x1050:  SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050;
+                           SiS_Pr->PanelHT   = 1900; SiS_Pr->PanelVT   = 1066;
+                           SiS_Pr->PanelHRS  =   26; SiS_Pr->PanelHRE  =   76;
+                           SiS_Pr->PanelVRS  =    3; SiS_Pr->PanelVRE  =    6;
+                           SiS_Pr->PanelVCLKIdx315 = VCLK121_315;
+                           SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
+                           break;
+     case Panel_Barco1366:  SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024;
+                           SiS_Pr->PanelHT   = 1688; SiS_Pr->PanelVT   = 1066;
+                           break;
+     case Panel_848x480:    SiS_Pr->PanelXRes =  848; SiS_Pr->PanelYRes =  480;
+                           SiS_Pr->PanelHT   = 1088; SiS_Pr->PanelVT   =  525;
+                           break;
+     case Panel_Custom:     SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
+                           SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
+                           SiS_Pr->PanelHT   = SiS_Pr->CHTotal;
+                           SiS_Pr->PanelVT   = SiS_Pr->CVTotal;
+                           if(SiS_Pr->CP_PreferredIndex != -1) {
+                              SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex];
+                              SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex];
+                              SiS_Pr->PanelHT   = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex];
+                              SiS_Pr->PanelVT   = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex];
+                              SiS_Pr->PanelHRS  = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex];
+                              SiS_Pr->PanelHRE  = SiS_Pr->CP_HSyncEnd[SiS_Pr->CP_PreferredIndex];
+                              SiS_Pr->PanelVRS  = SiS_Pr->CP_VSyncStart[SiS_Pr->CP_PreferredIndex];
+                              SiS_Pr->PanelVRE  = SiS_Pr->CP_VSyncEnd[SiS_Pr->CP_PreferredIndex];
+                              SiS_Pr->PanelHRS -= SiS_Pr->PanelXRes;
+                              SiS_Pr->PanelHRE -= SiS_Pr->PanelHRS;
+                              SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes;
+                              SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS;
+                              if(SiS_Pr->CP_PrefClock) {
+                                 int idx;
+                                 SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
+                                 SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300;
+                                 if(HwInfo->jChipType < SIS_315H) idx = VCLK_CUSTOM_300;
+                                 else                             idx = VCLK_CUSTOM_315;
+                                 SiS_Pr->SiS_VCLKData[idx].CLOCK =
+                                    SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock;
+                                 SiS_Pr->SiS_VCLKData[idx].SR2B =
+                                    SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B;
+                                 SiS_Pr->SiS_VCLKData[idx].SR2C =
+                                    SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C;
+                              }
+                           }
+                           break;
+     default:              SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes =  768;
+                           SiS_Pr->PanelHT   = 1344; SiS_Pr->PanelVT   =  806;
+                           break;
+  }
+
+  /* Special cases */
+  if( (SiS_Pr->SiS_IF_DEF_FSTN)              ||
+      (SiS_Pr->SiS_IF_DEF_DSTN)              ||
+      (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
+      (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
+      (SiS_Pr->SiS_CustomT == CUT_PANEL848) ) {
+     SiS_Pr->PanelHRS = 999;
+     SiS_Pr->PanelHRE = 999;
+  }
+
+  if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
+      (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
+      (SiS_Pr->SiS_CustomT == CUT_PANEL848) ) {
+     SiS_Pr->PanelVRS = 999;
+     SiS_Pr->PanelVRE = 999;
+  }
+
+  /* DontExpand overrule */
+  if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
+
+     if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (modeflag & NoSupportLCDScale)) {
+       /* No scaling for this mode on any panel (LCD=CRT2)*/
+       SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+     }
+
+     switch(SiS_Pr->SiS_LCDResInfo) {
+
+     case Panel_Custom:
+     case Panel_1152x864:
+     case Panel_1280x768:      /* TMDS only */
+        SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+       break;
+
+     case Panel_800x600: {
+        static const UCHAR nonscalingmodes[] = {
+          SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+       break;
+     }
+     case Panel_1024x768: {
+        static const UCHAR nonscalingmodes[] = {
+          SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+          SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+          0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+       break;
+     }
+     case Panel_1280x720: {
+        static const UCHAR nonscalingmodes[] = {
+          SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+          SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+          0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+       if(SiS_Pr->PanelHT == 1650) {
+          SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
        }
-       if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-          if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
-              if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-                SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
-             }
-          }
+       break;
+     }
+     case Panel_1280x768_2: {  /* LVDS only */
+        static const UCHAR nonscalingmodes[] = {
+          SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+          SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+          SIS_RI_1152x768,0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+       switch(resinfo) {
+       case SIS_RI_1280x720:  if(SiS_Pr->UsePanelScaler == -1) {
+                                 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+                              }
+                              break;
        }
+        break;
      }
-  }
-
-  if(HwInfo->jChipType >= SIS_315H) {
-#ifdef SIS315H
-     if(HwInfo->jChipType < SIS_661) {
-        if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) {
-           SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
-          SiS_Pr->SiS_LCDInfo |= LCDPass11;
+     case Panel_1280x800: {    /* SiS TMDS special (Averatec 6200 series) */
+        static const UCHAR nonscalingmodes[] = {
+          SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+          SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+          SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+        break;
+     }
+     case Panel_1280x800_2:  {         /* SiS LVDS */
+        static const UCHAR nonscalingmodes[] = {
+          SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+          SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+          SIS_RI_1152x768,0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+       switch(resinfo) {
+       case SIS_RI_1280x720:
+       case SIS_RI_1280x768:  if(SiS_Pr->UsePanelScaler == -1) {
+                                 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+                              }
+                              break;
+       }
+        break;
+     }
+     case Panel_1280x960: {
+        static const UCHAR nonscalingmodes[] = {
+          SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+          SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+          SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
+          0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+        break;
+     }
+     case Panel_1280x1024: {
+        static const UCHAR nonscalingmodes[] = {
+          SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+          SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+          SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
+          SIS_RI_1280x960,0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+       break;
+     }
+     case Panel_1400x1050: {
+        static const UCHAR nonscalingmodes[] = {
+            SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+            SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+            SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x960,
+            0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+        switch(resinfo) {
+       case SIS_RI_1280x720:  if(SiS_Pr->UsePanelScaler == -1) {
+                                 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+                              }
+                              break;
+       case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+                              break;
        }
+       break;
      }
-#endif
-  } else {
+     case Panel_1600x1200: {
+        static const UCHAR nonscalingmodes[] = {
+            SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+            SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+            SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
+            SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+        break;
+     }
+     case Panel_1680x1050: {
+        static const UCHAR nonscalingmodes[] = {
+            SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
+            SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
+            SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,
+            0xff
+       };
+       SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
+       break;
+     }
+     }
+  }
+
+  if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
+     if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
+        SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20;   /* neg h/v sync, RGB24(D0 = 0) */
+     }
+  }
+
 #ifdef SIS300
+  if(HwInfo->jChipType < SIS_315H) {
      if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
-        if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+        if(SiS_Pr->SiS_UseROM) {
           if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
               if(!(ROMAddr[0x235] & 0x02)) {
                 SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
@@ -1685,76 +2064,87 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
            SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
        }
      }
+  }
 #endif
+
+  /* Special cases */
+
+  if(modexres == SiS_Pr->PanelXRes && modeyres == SiS_Pr->PanelYRes) {
+     SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
   }
 
-  /* Trumpion: Assume non-expanding */
-  if(SiS_Pr->SiS_IF_DEF_TRUMPION != 0) {
-     SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
+  if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
+     SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
   }
 
-  if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-     SiS_Pr->SiS_LCDInfo &= (~LCDPass11);
+  switch(SiS_Pr->SiS_LCDResInfo) {
+  case Panel_640x480:
+     SiS_Pr->SiS_LCDInfo |= LCDPass11;
+     break;
+  case Panel_1280x800:
+     /* Don't pass 1:1 by default (TMDS special) */
+     if(SiS_Pr->CenterScreen == -1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
+     break;
+  case Panel_1280x960:
+     SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
+     break;
+  case Panel_Custom:
+     if((!SiS_Pr->CP_PrefClock) ||
+        (modexres > SiS_Pr->PanelXRes) || (modeyres > SiS_Pr->PanelYRes)) {
+        SiS_Pr->SiS_LCDInfo |= LCDPass11;
+     }
+     break;
   }
 
-#ifdef SIS315H
-  if((HwInfo->jChipType >= SIS_315H) && (HwInfo->jChipType < SIS_661)) {
-     if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
-       /* Enable 302LV/302ELV dual link mode.
-        * For 661, this is done above.
-        */
-        if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
-          (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)) {
-          /* (Sets this in SenseLCD; new paneltypes) */
-          SiS_Pr->SiS_LCDInfo |= LCDDualLink;
-       }
-        if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) ||
-          (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) ||
-           (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)) {
-          SiS_Pr->SiS_LCDInfo |= LCDDualLink;
-       }
-     }
+  if(SiS_Pr->UseCustomMode) {
+     SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
+  }
+
+  /* (In)validate LCDPass11 flag */
+  if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
+     SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
   }
-#endif
 
+  /* LVDS DDA */
   if(!((HwInfo->jChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) {
 
-     if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) {
-          if(ModeNo > 0x13) {
-             if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
-                 if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
-                    SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+     if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
+       if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
+          if(ModeNo == 0x12) {
+             if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
+                SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+             }
+          } else if(ModeNo > 0x13) {
+             if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
+                if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
+                   if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
+                       SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+                   }
                 }
-              }
-           }
-        }
-       if(ModeNo == 0x12) {
-          if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
-             SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+             }
           }
        }
      }
 
      if(modeflag & HalfDCLK) {
-        if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
-           if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
-             if(!(((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (HwInfo->jChipType < SIS_315H)) &&
-                                             (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480))) {
-                 if(ModeNo > 0x13) {
-                    if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-                       if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
-                    } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) {
-                       if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
-                    }
-                 }
-             } else SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
-           } else SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
-        } else SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+        if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) {
+          SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+        } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+          SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+       } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) {
+          SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+       } else if(ModeNo > 0x13) {
+           if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
+              if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+           } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) {
+              if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
+           }
+       }
      }
 
   }
 
+  /* VESA timing */
   if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
      if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) {
        SiS_Pr->SiS_SetFlag |= LCDVESATiming;
@@ -1763,14 +2153,6 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      SiS_Pr->SiS_SetFlag |= LCDVESATiming;
   }
 
-  SiS_Pr->SiS_LCDInfo661 = 0;
-  if(SiS_Pr->SiS_SetFlag & LCDVESATiming) SiS_Pr->SiS_LCDInfo661 |= 0x0001;
-  if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) SiS_Pr->SiS_LCDInfo661 |= 0x0002;
-  if(SiS_Pr->SiS_LCDInfo & LCDPass11)     SiS_Pr->SiS_LCDInfo661 |= 0x0008;
-  if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) SiS_Pr->SiS_LCDInfo661 |= 0x0010;
-  SiS_Pr->SiS_LCDInfo661 |= (SiS_Pr->SiS_LCDInfo & 0xe0);
-  if(SiS_Pr->SiS_LCDInfo & LCDDualLink)   SiS_Pr->SiS_LCDInfo661 |= 0x0100;
-
 #ifdef LINUX_KERNEL
 #ifdef TWDEBUG
   printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
@@ -1792,54 +2174,21 @@ USHORT
 SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
 {
-  USHORT tempbx;
-  const USHORT LCDXlat0VCLK[4]    = {VCLK40,       VCLK40,       VCLK40,       VCLK40};
-  const USHORT LVDSXlat1VCLK[4]   = {VCLK40,       VCLK40,       VCLK40,       VCLK40};
-  const USHORT LVDSXlat4VCLK[4]   = {VCLK28,       VCLK28,       VCLK28,       VCLK28};
-#ifdef SIS300
-  const USHORT LCDXlat1VCLK300[4] = {VCLK65_300,   VCLK65_300,   VCLK65_300,   VCLK65_300};
-  const USHORT LCDXlat2VCLK300[4] = {VCLK108_2_300,VCLK108_2_300,VCLK108_2_300,VCLK108_2_300};
-  const USHORT LVDSXlat2VCLK300[4]= {VCLK65_300,   VCLK65_300,   VCLK65_300,   VCLK65_300};
-  const USHORT LVDSXlat3VCLK300[4]= {VCLK65_300,   VCLK65_300,   VCLK65_300,   VCLK65_300};
-#endif
-#ifdef SIS315H
-  const USHORT LCDXlat1VCLK310[4] = {VCLK65_315,   VCLK65_315,   VCLK65_315,   VCLK65_315};
-  const USHORT LCDXlat2VCLK310[4] = {VCLK108_2_315,VCLK108_2_315,VCLK108_2_315,VCLK108_2_315};
-  const USHORT LVDSXlat2VCLK310[4]= {VCLK65_315,   VCLK65_315,   VCLK65_315,   VCLK65_315};
-  const USHORT LVDSXlat3VCLK310[4]= {VCLK108_2_315,VCLK108_2_315,VCLK108_2_315,VCLK108_2_315};
-#endif
-  USHORT CRT2Index,VCLKIndex=0;
-  USHORT modeflag,resinfo;
-  const UCHAR  *CHTVVCLKPtr = NULL;
-  const USHORT *LCDXlatVCLK1 = NULL;
-  const USHORT *LCDXlatVCLK2 = NULL;
-  const USHORT *LVDSXlatVCLK2 = NULL;
-  const USHORT *LVDSXlatVCLK3 = NULL;
-
-  if(HwInfo->jChipType >= SIS_315H) {
-#ifdef SIS315H
-     LCDXlatVCLK1 = LCDXlat1VCLK310;
-     LCDXlatVCLK2 = LCDXlat2VCLK310;
-     LVDSXlatVCLK2 = LVDSXlat2VCLK310;
-     LVDSXlatVCLK3 = LVDSXlat3VCLK310;
-#endif
-  } else {
-#ifdef SIS300
-     LCDXlatVCLK1 = LCDXlat1VCLK300;
-     LCDXlatVCLK2 = LCDXlat2VCLK300;
-     LVDSXlatVCLK2 = LVDSXlat2VCLK300;
-     LVDSXlatVCLK3 = LVDSXlat3VCLK300;
-#endif
-  }
+  USHORT CRT2Index,VCLKIndex=0,VCLKIndexGEN=0;
+  USHORT modeflag,resinfo,tempbx;
+  const UCHAR *CHTVVCLKPtr = NULL;
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
      resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
      CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+     VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03;
   } else {
      modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
      resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
      CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
+     VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
+     if(HwInfo->jChipType < SIS_315H) VCLKIndexGEN &= 0x3f;
   }
 
   if(SiS_Pr->SiS_VBType & VB_SISVB) {    /* 30x/B/LV */
@@ -1847,50 +2196,31 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
 
         CRT2Index >>= 6;
-        if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {      /*  LCD */
+        if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {              /*  LCD */
 
            if(HwInfo->jChipType < SIS_315H) {
-             if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) {
-                VCLKIndex = LCDXlat0VCLK[CRT2Index];
-             } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-                VCLKIndex = LCDXlatVCLK1[CRT2Index];
-             } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) {
-                VCLKIndex = LCDXlatVCLK1[CRT2Index];
-             } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) {
-                VCLKIndex = LCDXlatVCLK1[CRT2Index];
-             } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) {
-                VCLKIndex = VCLK81_300;        /* guessed */
-             } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) {
-                VCLKIndex = VCLK108_3_300;
-                if(resinfo == SIS_RI_1280x1024) VCLKIndex = VCLK100_300;
-             } else {
-                VCLKIndex = LCDXlatVCLK2[CRT2Index];
+             VCLKIndex = SiS_Pr->PanelVCLKIdx300;
+             if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+                VCLKIndex = VCLKIndexGEN;
              }
           } else {
-             if( (SiS_Pr->SiS_VBType & VB_SIS301LV302LV) ||
-                 (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
-                if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-                   VCLKIndex = VCLK108_2_315;
-                } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) {
-                   VCLKIndex = VCLK81_315;     /* guessed */
-                } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
-                   VCLKIndex = VCLK108_2_315;
-                } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) {
-                   VCLKIndex = VCLK162_315;
-                } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) {
-                   VCLKIndex = VCLK108_3_315;
-                   if(resinfo == SIS_RI_1280x1024) VCLKIndex = VCLK100_315;
-                } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-                   VCLKIndex = LCDXlatVCLK1[CRT2Index];
-                } else {
-                   VCLKIndex = LCDXlatVCLK2[CRT2Index];
-                }
-             } else {
-                 VCLKIndex = (UCHAR)SiS_GetRegByte((USHORT)(SiS_Pr->SiS_P3ca+0x02));  /*  Port 3cch */
-                VCLKIndex = ((VCLKIndex >> 2) & 0x03);
-                if(ModeNo > 0x13) {
-                   VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
-                }
+             VCLKIndex = SiS_Pr->PanelVCLKIdx315;
+             if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+                switch(resinfo) {
+                /* Only those whose IndexGEN doesn't match VBVCLK array */
+                case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
+                case SIS_RI_720x480:  VCLKIndex = VCLK_720x480;  break;
+                case SIS_RI_720x576:  VCLKIndex = VCLK_720x576;  break;
+                case SIS_RI_768x576:  VCLKIndex = VCLK_768x576;  break;
+                case SIS_RI_848x480:  VCLKIndex = VCLK_848x480;  break;
+                case SIS_RI_856x480:  VCLKIndex = VCLK_856x480;  break;
+                case SIS_RI_800x480:  VCLKIndex = VCLK_800x480;  break;
+                case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break;
+                case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break;
+                case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break;
+                default:              VCLKIndex = VCLKIndexGEN;
+                }
+
                 if(ModeNo <= 0x13) {
                    if(HwInfo->jChipType <= SIS_315PRO) {
                       if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42;
@@ -1906,34 +2236,28 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
              }
           }
 
-        } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {                 /*  TV */
+        } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {                  /*  TV */
 
           if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
-              if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2;
-             else                                  VCLKIndex = HiTVVCLK;
+              if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO)            VCLKIndex = HiTVVCLKDIV2;
+             else                                              VCLKIndex = HiTVVCLK;
               if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
-                if(modeflag & Charx8Dot)           VCLKIndex = HiTVSimuVCLK;
-                else                               VCLKIndex = HiTVTextVCLK;
+                if(modeflag & Charx8Dot)                       VCLKIndex = HiTVSimuVCLK;
+                else                                           VCLKIndex = HiTVTextVCLK;
               }
-           } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK - TVCLKBASE_315;
-          else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p)   VCLKIndex = TVVCLKDIV2;
-          else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO)     VCLKIndex = TVVCLKDIV2;
-           else                                          VCLKIndex = TVVCLK;
+           } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p)      VCLKIndex = YPbPr750pVCLK;
+          else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p)         VCLKIndex = TVVCLKDIV2;
+          else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO)           VCLKIndex = TVVCLKDIV2;
+           else                                                VCLKIndex = TVVCLK;
 
-          if(HwInfo->jChipType < SIS_315H) {
-              VCLKIndex += TVCLKBASE_300;
-          } else {
-             VCLKIndex += TVCLKBASE_315;
-          }
+          if(HwInfo->jChipType < SIS_315H) VCLKIndex += TVCLKBASE_300;
+          else                             VCLKIndex += TVCLKBASE_315;
 
-        } else {                                               /* VGA2 */
+        } else {                                                       /* VGA2 */
 
-           VCLKIndex = (UCHAR)SiS_GetRegByte((USHORT)(SiS_Pr->SiS_P3ca+0x02));
-           VCLKIndex = ((VCLKIndex >> 2) & 0x03);
-           if(ModeNo > 0x13) {
-              VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
-             if(HwInfo->jChipType < SIS_315H) {
-                VCLKIndex &= 0x3f;
+          VCLKIndex = VCLKIndexGEN;
+          if(HwInfo->jChipType < SIS_315H) {
+              if(ModeNo > 0x13) {
                 if( (HwInfo->jChipType == SIS_630) &&
                     (HwInfo->jChipRevision >= 0x30)) {
                    if(VCLKIndex == 0x14) VCLKIndex = 0x34;
@@ -1946,15 +2270,12 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
      } else {   /* If not programming CRT2 */
 
-        VCLKIndex = (UCHAR)SiS_GetRegByte((USHORT)(SiS_Pr->SiS_P3ca+0x02));
-        VCLKIndex = ((VCLKIndex >> 2) & 0x03);
-        if(ModeNo > 0x13) {
-           VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
-          if(HwInfo->jChipType < SIS_315H) {
-              VCLKIndex &= 0x3f;
+        VCLKIndex = VCLKIndexGEN;
+       if(HwInfo->jChipType < SIS_315H) {
+           if(ModeNo > 0x13) {
              if( (HwInfo->jChipType != SIS_630) &&
                  (HwInfo->jChipType != SIS_300) ) {
-                if(VCLKIndex == 0x1b) VCLKIndex = 0x35;
+                if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
              }
           }
         }
@@ -1964,7 +2285,7 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
      VCLKIndex = CRT2Index;
 
-     if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {  /* programming CRT2 */
+     if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
 
         if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) {
 
@@ -2000,32 +2321,16 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
         } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
 
-          VCLKIndex >>= 6;
-          if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) ||
-             (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel320x480))
-             VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480   ||
-                  SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2 ||
-                  SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3)
-             VCLKIndex = LVDSXlat4VCLK[VCLKIndex];
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)
-             VCLKIndex = LVDSXlatVCLK2[VCLKIndex];
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600)
-              VCLKIndex = LVDSXlatVCLK2[VCLKIndex];
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768)
-              VCLKIndex = LVDSXlatVCLK2[VCLKIndex];
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768)
-             VCLKIndex = VCLK68_315;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)
-             VCLKIndex = VCLK162_315;
-          else
-             VCLKIndex = LVDSXlatVCLK3[VCLKIndex];
-
-          if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
-             /* Special Timing: Barco iQ Pro R series */
-             VCLKIndex = 0x44;
+          if(HwInfo->jChipType < SIS_315H) {
+             VCLKIndex = SiS_Pr->PanelVCLKIdx300;
+          } else {
+             VCLKIndex = SiS_Pr->PanelVCLKIdx315;
           }
 
+          /* Special Timing: Barco iQ Pro R series */
+          if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
+
+          /* Special Timing: 848x480 parallel lvds */
           if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
              if(HwInfo->jChipType < SIS_315H) {
                 VCLKIndex = VCLK34_300;
@@ -2038,31 +2343,25 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
         } else {
 
-          VCLKIndex = (UCHAR)SiS_GetRegByte((USHORT)(SiS_Pr->SiS_P3ca+0x02));
-           VCLKIndex = ((VCLKIndex >> 2) & 0x03);
-           if(ModeNo > 0x13) {
-              VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
-             if(HwInfo->jChipType < SIS_315H) {
-                VCLKIndex &= 0x3F;
+          VCLKIndex = VCLKIndexGEN;
+          if(HwInfo->jChipType < SIS_315H) {
+              if(ModeNo > 0x13) {
+                if( (HwInfo->jChipType == SIS_630) &&
+                     (HwInfo->jChipRevision >= 0x30) ) {
+                   if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
+                }
               }
-             if( (HwInfo->jChipType == SIS_630) &&
-                  (HwInfo->jChipRevision >= 0x30) ) {
-                if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
-             }
           }
         }
 
      } else {  /* if not programming CRT2 */
 
-        VCLKIndex = (UCHAR)SiS_GetRegByte((USHORT)(SiS_Pr->SiS_P3ca+0x02));
-        VCLKIndex = ((VCLKIndex >> 2) & 0x03);
-        if(ModeNo > 0x13) {
-           VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
-           if(HwInfo->jChipType < SIS_315H) {
-             VCLKIndex &= 0x3F;
+        VCLKIndex = VCLKIndexGEN;
+       if(HwInfo->jChipType < SIS_315H) {
+           if(ModeNo > 0x13) {
              if( (HwInfo->jChipType != SIS_630) &&
                  (HwInfo->jChipType != SIS_300) ) {
-                if(VCLKIndex == 0x1b) VCLKIndex = 0x35;
+                if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
              }
 #if 0
              if(HwInfo->jChipType == SIS_730) {
@@ -2094,27 +2393,22 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 {
   USHORT i,j,modeflag;
   USHORT tempcl,tempah=0;
-#ifdef SIS300
-  USHORT temp;
+#if defined(SIS300) || defined(SIS315H)
+  USHORT tempbl;
 #endif
 #ifdef SIS315H
-  USHORT tempbl, tempah2, tempbl2;
+  UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
+  USHORT tempah2, tempbl2;
 #endif
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
+  } else if(SiS_Pr->UseCustomMode) {
+     modeflag = SiS_Pr->CModeFlag;
   } else {
-     if(SiS_Pr->UseCustomMode) {
-        modeflag = SiS_Pr->CModeFlag;
-     } else {
-       modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-     }
+     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
   }
 
-  /* BIOS does not do this (neither 301 nor LVDS) */
-  /* (But it's harmless; see SetCRT2Offset) */
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0x00);   /* fix write part1 index 0  BTDRAM bit Bug */
-
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
 
      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40);
@@ -2123,6 +2417,9 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
   } else {
 
      for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0);
+     if(HwInfo->jChipType >= SIS_315H) {
+        SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F);
+     }
 
      tempcl = SiS_Pr->SiS_ModeType;
 
@@ -2132,14 +2429,14 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
         /* For 301BDH: (with LCD via LVDS) */
         if(SiS_Pr->SiS_VBType & VB_NoLCD) {
-          temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
-          temp &= 0xef;
-          temp |= 0x02;
+          tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
+          tempbl &= 0xef;
+          tempbl |= 0x02;
           if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
-             temp |= 0x10;
-             temp &= 0xfd;
+             tempbl |= 0x10;
+             tempbl &= 0xfd;
           }
-          SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
+          SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl);
         }
 
         if(ModeNo > 0x13) {
@@ -2225,13 +2522,9 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
           tempah |= 0x10;
         }
 
-        if((HwInfo->jChipType < SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301)) {
-          if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) ||
-             (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960)) {
-             tempah |= 0x80;
-          }
-        } else {
-          tempah |= 0x80;
+       tempah |= 0x80;
+        if(SiS_Pr->SiS_VBType & VB_SIS301) {
+          if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80;
         }
 
         if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
@@ -2244,7 +2537,10 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
         SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah);
 
-        tempah = 0;
+       tempah = 0x80;
+       if(SiS_Pr->SiS_VBType & VB_SIS301) {
+          if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0;
+       }
 
        if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempah |= 0x40;
 
@@ -2254,19 +2550,13 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                   }
         }
 
-       if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) ||
-          (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960)  ||
-          ((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom) &&
-           (SiS_Pr->CP_MaxX >= 1280) && (SiS_Pr->CP_MaxY >= 960))) {
-          tempah |= 0x80;
-        }
-
         SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah);
 
      } else {  /* LVDS */
 
         if(HwInfo->jChipType >= SIS_315H) {
 
+#ifdef SIS315H
           /* LVDS can only be slave in 8bpp modes */
           tempah = 0x80;
           if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) {
@@ -2288,9 +2578,11 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
           }
 
           SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah);
+#endif
 
         } else {
 
+#ifdef SIS300
           tempah = 0;
           if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
               tempah |= 0x02;
@@ -2300,6 +2592,7 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
           if(SiS_Pr->SiS_VBInfo & DisableCRT2Display)  tempah = 0;
 
           SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
+#endif
 
         }
 
@@ -2312,7 +2605,6 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      if(HwInfo->jChipType >= SIS_315H) {
 
 #ifdef SIS315H
-
         unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01);
 
        /* The following is nearly unpreditable and varies from machine
@@ -2344,10 +2636,11 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
         * in a 650 box (Jake). What is the criteria?
         */
 
-       if((IS_SIS740) || (HwInfo->jChipType >= SIS_661)) {
+       if((IS_SIS740) || (HwInfo->jChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
           tempah = 0x30;
           tempbl = 0xc0;
-          if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
+          if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
+             ((SiS_Pr->SiS_ROMNew) && (!(ROMAddr[0x5b] & 0x04)))) {
              tempah = 0x00;
              tempbl = 0x00;
           }
@@ -2378,38 +2671,41 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
        if(IS_SIS740) {
           tempah = 0x80;
-          if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
-             tempah = 0x00;
-          }
+          if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x00;
           SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah);
        } else {
           tempah = 0x00;
            tempbl = 0x7f;
            if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
               tempbl = 0xff;
-             if(!(SiS_IsDualEdge(SiS_Pr, HwInfo))) {
-                tempah = 0x80;
-             }
+             if(!(SiS_IsDualEdge(SiS_Pr, HwInfo))) tempah = 0x80;
            }
            SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
        }
 
-       /* 661: Sets p4 27 and 34 here, done in SetGroup4 here */
-
 #endif /* SIS315H */
 
      } else if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
 
+#ifdef SIS300
         SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
 
         if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
-           (   (SiS_Pr->SiS_VBType & VB_NoLCD) &&
-              (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ) ) {
+           ((SiS_Pr->SiS_VBType & VB_NoLCD) &&
+           (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
           SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F);
        } else {
           SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80);
        }
+#endif
+
+     }
 
+     if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
+        SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80);
+        if(SiS_Pr->SiS_VBType & VB_SIS301C) {
+          SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0);
+        }
      }
 
   } else {  /* LVDS */
@@ -2423,9 +2719,7 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
           tempbl = 0xfb;
            if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
               tempah = 0x00;
-             if(SiS_IsDualEdge(SiS_Pr, HwInfo)) {
-                tempbl = 0xff;
-             }
+             if(SiS_IsDualEdge(SiS_Pr, HwInfo)) tempbl = 0xff;
            }
           SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
 
@@ -2456,14 +2750,8 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 USHORT
 SiS_GetResInfo(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex)
 {
-  USHORT resindex;
-
-  if(ModeNo <= 0x13)
-     resindex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
-  else
-     resindex = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
-
-  return(resindex);
+  if(ModeNo <= 0x13) return((USHORT)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo);
+  else               return((USHORT)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO);
 }
 
 static void
@@ -2473,8 +2761,12 @@ SiS_GetCRT2ResInfo(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
   USHORT xres,yres,modeflag=0,resindex;
 
   if(SiS_Pr->UseCustomMode) {
-     SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = SiS_Pr->CHDisplay;
-     SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = SiS_Pr->CVDisplay;
+     xres = SiS_Pr->CHDisplay;
+     if(SiS_Pr->CModeFlag & HalfDCLK) xres *= 2;
+     SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
+     yres = SiS_Pr->CVDisplay;
+     if(SiS_Pr->CModeFlag & DoubleScanMode) yres *= 2;
+     SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
      return;
   }
 
@@ -2489,7 +2781,7 @@ SiS_GetCRT2ResInfo(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
      modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
   }
 
-  if((!SiS_Pr->SiS_IF_DEF_DSTN) && (!SiS_Pr->SiS_IF_DEF_FSTN)) {
+  if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) {
 
      if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) {
         if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
@@ -2500,72 +2792,66 @@ SiS_GetCRT2ResInfo(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
         }
      }
 
-     if(ModeNo > 0x13) {
-       if(modeflag & HalfDCLK)       xres *= 2;
-       if(modeflag & DoubleScanMode) yres *= 2;
-     }
+     if(modeflag & HalfDCLK)       xres *= 2;
+     if(modeflag & DoubleScanMode) yres *= 2;
 
   }
 
-  if(SiS_Pr->SiS_VBType & VB_SISVB) {
-        if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
+  if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
+
+#if 0
+        if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCDA | SetCRT2ToLCD | SetCRT2ToHiVision)) {
            if(xres == 720) xres = 640;
-       } else {
-          if(SiS_Pr->SiS_VBType & VB_NoLCD) {           /* 301BDH */
-               if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
-                   if(xres == 720) xres = 640;
-               }
-               if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
-                  yres = 400;
-                  if(HwInfo->jChipType >= SIS_315H) {
-                     if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
-                  } else {
-                     if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
-                  }
-               }
-          } else {
-             if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
-                if(xres == 720) xres = 640;
-             }
-             if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-                if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) {
-                   if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
-                      if(yres == 1024) yres = 1056;
-                   }
-                } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-                   if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
-                      /* BIOS bug - does this regardless of scaling */
-                      if(yres == 400) yres = 405;
-                   }
-                   if(yres == 350) yres = 360;
-                   if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
-                      if(yres == 360) yres = 375;
-                   }
-                } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-                   if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
-                      if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
-                         if(yres == 350) yres = 357;
-                         if(yres == 400) yres = 420;
-                         if(yres == 480) yres = 525;
-                      }
-                   }
-                }
+       }
+#endif
+
+       if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+          switch(SiS_Pr->SiS_LCDResInfo) {
+          case Panel_1024x768:
+             if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
+                 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
+                   if(yres == 350) yres = 357;
+                   if(yres == 400) yres = 420;
+                   if(yres == 480) yres = 525;
+                }
+             }
+             break;
+          case Panel_1280x1024:
+             if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
+                /* BIOS bug - does this regardless of scaling */
+                if(yres == 400) yres = 405;
              }
+             if(yres == 350) yres = 360;
+             if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
+                 if(yres == 360) yres = 375;
+             }
+             break;
+          case Panel_1600x1200:
+             if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
+                if(yres == 1024) yres = 1056;
+             }
+             break;
           }
        }
+
   } else {
-       if(xres == 720) xres = 640;
-       if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
-          yres = 400;
-          if(HwInfo->jChipType >= SIS_315H) {
-             if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
-          } else {
-             if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
-          }
-          if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
-             yres = 480;
-          }
+
+     if(SiS_Pr->SiS_VBType & VB_SISVB) {
+        if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
+           if(xres == 720) xres = 640;
        }
+     } else if(xres == 720) xres = 640;
+
+     if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
+       yres = 400;
+        if(HwInfo->jChipType >= SIS_315H) {
+           if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
+        } else {
+           if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
+        }
+        if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN)  yres = 480;
+     }
+
   }
   SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
   SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
@@ -2580,103 +2866,84 @@ SiS_GetLVDSCRT1Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                   USHORT RefreshRateTableIndex, USHORT *ResIndex,
                   USHORT *DisplayType)
  {
-  USHORT tempbx,modeflag=0;
-  USHORT Flag,CRT2CRTC;
+  USHORT modeflag=0;
 
   if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
      if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
         if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return FALSE;
      }
   } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
-     if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return FALSE;
+     if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))    return FALSE;
   } else
      return FALSE;
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-     CRT2CRTC = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+     (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
   } else {
      modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-     CRT2CRTC = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
+     (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
   }
 
-  Flag = 1;
-  tempbx = 0;
-  if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
-     if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
-        Flag = 0;
-        tempbx = 18;
-        if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
-        if(SiS_Pr->SiS_TVMode & TVSetPAL) {
-          tempbx += 2;
-          if(SiS_Pr->SiS_ModeType > ModeVGA) {
-             if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
-          }
-          if(SiS_Pr->SiS_TVMode & TVSetPALM) {
-             tempbx = 18;  /* PALM uses NTSC data */
-             if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
-          } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
-             tempbx = 20;  /* PALN uses PAL data  */
-             if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
-          }
-        }
-     }
-  }
-  if(Flag) {
-     tempbx = SiS_Pr->SiS_LCDResInfo;
-     tempbx -= SiS_Pr->SiS_PanelMinLVDS;
-     if(SiS_Pr->SiS_LCDResInfo <= SiS_Pr->SiS_Panel1280x1024) {
-        if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 6;
-        if(modeflag & HalfDCLK) tempbx += 3;
-     } else {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
-           tempbx = 14;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 2;
-          if(modeflag & HalfDCLK) tempbx++;
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) {
-           tempbx = 23;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 2;
-          if(modeflag & HalfDCLK) tempbx++;
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) {
-           tempbx = 27;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 2;
-          if(modeflag & HalfDCLK) tempbx++;
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) {
-           tempbx = 36;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 2;
-          if(modeflag & HalfDCLK) tempbx++;
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) {
-           tempbx = 40;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 2;
-          if(modeflag & HalfDCLK) tempbx++;
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) {
-           tempbx = 54;
-          if(modeflag & HalfDCLK) tempbx++;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2) {
-           tempbx = 52;
-          if(modeflag & HalfDCLK) tempbx++;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) {
-           tempbx = 50;
-          if(modeflag & HalfDCLK) tempbx++;
-        }
+  (*ResIndex) &= 0x3F;
 
+  if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
+     (*DisplayType) = 18;
+     if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
+     if(SiS_Pr->SiS_TVMode & TVSetPAL) {
+       (*DisplayType) += 2;
+       if(SiS_Pr->SiS_ModeType > ModeVGA) {
+          if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 99;
+       }
+       if(SiS_Pr->SiS_TVMode & TVSetPALM) {
+          (*DisplayType) = 18;  /* PALM uses NTSC data */
+          if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
+       } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
+          (*DisplayType) = 20;  /* PALN uses PAL data  */
+          if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
+       }
+     }
+  } else {
+     switch(SiS_Pr->SiS_LCDResInfo) {
+     case Panel_640x480:   (*DisplayType) = 50; break;
+     case Panel_640x480_2: (*DisplayType) = 52; break;
+     case Panel_640x480_3: (*DisplayType) = 54; break;
+     case Panel_800x600:   (*DisplayType) =  0; break;
+     case Panel_1024x600:  (*DisplayType) = 23; break;
+     case Panel_1024x768:  (*DisplayType) =  4; break;
+     case Panel_1152x768:  (*DisplayType) = 27; break;
+     case Panel_1280x768:  (*DisplayType) = 40; break;
+     case Panel_1280x1024: (*DisplayType) =  8; break;
+     case Panel_1400x1050: (*DisplayType) = 14; break;
+     case Panel_1600x1200: (*DisplayType) = 36; break;
+     default: return FALSE;
+     }
+
+     if(modeflag & HalfDCLK) (*DisplayType)++;
+
+     switch(SiS_Pr->SiS_LCDResInfo) {
+     case Panel_640x480:
+     case Panel_640x480_2:
+     case Panel_640x480_3:
+        break;
+     default:
+        if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
      }
+
      if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
-        tempbx = 12;
-       if(modeflag & HalfDCLK) tempbx++;
+        (*DisplayType) = 12;
+       if(modeflag & HalfDCLK) (*DisplayType)++;
      }
   }
 
 #if 0
   if(SiS_Pr->SiS_IF_DEF_FSTN) {
      if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel320x480){
-        tempbx = 22;
+        (*DisplayType) = 22;
      }
   }
 #endif
 
-  *ResIndex = CRT2CRTC & 0x3F;
-  *DisplayType = tempbx;
   return TRUE;
 }
 
@@ -2685,8 +2952,7 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
               USHORT RefreshRateTableIndex,USHORT *CRT2Index,USHORT *ResIndex,
               PSIS_HW_INFO HwInfo)
 {
-  USHORT tempbx=0,tempal=0;
-  USHORT Flag,resinfo=0;
+  USHORT tempbx=0,tempal=0,resinfo=0;
 
   if(ModeNo <= 0x13) {
      tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
@@ -2699,55 +2965,34 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
 
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {                            /* LCD */
 
-       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) {
-          tempbx = 15;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
-          tempbx = 20;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)         tempbx = 21;
-          else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx = 22;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) {
-          tempbx = 23;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)         tempbx = 24;
-          else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx = 25;
-#if 0
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) {
-          tempbx = 26;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)         tempbx = 27;
-          else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx = 28;
-#endif
-       } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-          if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
-             if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)       tempbx = 13;
-             else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) tempbx = 14;
-             else {
-                tempbx = 29;
-                if(ModeNo >= 0x13) {
-                   /* see below */
-                   if(resinfo == SIS_RI_1280x960) tempal = 10;
-                }
-              }
-          } else {
-             tempbx = 29;
-             if(ModeNo >= 0x13) {
-                /* 1280x768 and 1280x960 have same CRT2CRTC,
-                 * so we change it here if 1280x960 is chosen
-                 */
-                if(resinfo == SIS_RI_1280x960) tempal = 10;
-             }
-          }
-       } else {
-          tempbx = SiS_Pr->SiS_LCDResInfo - SiS_Pr->SiS_Panel1024x768;
-          if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
-              tempbx += 10;
-                  }
+        tempbx = SiS_Pr->SiS_LCDResInfo;
+       if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32;
+
+       if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) {
+          if     (resinfo == SIS_RI_1280x800)  tempal =  9;
+          else if(resinfo == SIS_RI_1400x1050) tempal = 11;
+       } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) ||
+                 (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2)) {
+          if     (resinfo == SIS_RI_1280x768)  tempal =  9;
+       }
+
+       if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+          /* Pass 1:1 only (center-screen handled outside) */
+          /* This is never called for the panel's native resolution */
+          /* since Pass1:1 will not be set in this case */
+          tempbx = 100;
+          if(ModeNo >= 0x13) {
+             tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
+          }
        }
 
 #ifdef SIS315H
        if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
-          if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-             tempbx = 50;
-             if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)         tempbx = 51;
-             else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx = 52;
+          if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
+             if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
+                tempbx = 200;
+                if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
+             }
           }
        }
 #endif
@@ -2783,12 +3028,20 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
              (resinfo == SIS_RI_720x576) ||
              (resinfo == SIS_RI_768x576)) {
              tempal = 6;
+             if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) {
+                if(resinfo == SIS_RI_720x480) tempal = 9;
+             }
           }
           if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
               if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
-                if(resinfo == SIS_RI_1024x768) {
+                if(resinfo == SIS_RI_1024x768) tempal = 8;
+             }
+             if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
+                if((resinfo == SIS_RI_720x576) ||
+                   (resinfo == SIS_RI_768x576)) {
                    tempal = 8;
                 }
+                if(resinfo == SIS_RI_1280x720) tempal = 9;
              }
           }
        }
@@ -2799,115 +3052,75 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
 
   } else {   /* LVDS, 301B-DH (if running on LCD) */
 
-     Flag = 1;
      tempbx = 0;
-     if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
-        if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
-           Flag = 0;
-           tempbx = 10;
-          if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
-           if(SiS_Pr->SiS_TVMode & TVSetPAL) {
-             tempbx += 2;
-             if(SiS_Pr->SiS_ModeType > ModeVGA) {
-                if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
-             }
-             if(SiS_Pr->SiS_TVMode & TVSetPALM) {
-                tempbx = 90;
-                if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
-             } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
-                tempbx = 92;
-                if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
-             }
-           }
-        }
-     }
+     if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
 
-     if(Flag) {
-
-       if(SiS_Pr->SiS_LCDResInfo <= SiS_Pr->SiS_Panel1280x1024) {
-          tempbx = SiS_Pr->SiS_LCDResInfo - SiS_Pr->SiS_PanelMinLVDS;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx += 3;
-
-          if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
-             tempbx = 82;
-             if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx++;
-          }
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) {
-          tempbx = 18;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx++;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) {
-          tempbx = 6;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2) {
-          tempbx = 30;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) {
-          tempbx = 30;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) {
-          tempbx = 15;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx += 2;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) {
-          tempbx = 16;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx += 2;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
-          tempbx = 8;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx++;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) {
-          tempbx = 21;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx++;
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelBarco1366) {
-          tempbx = 80;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx++;
-       }
-
-       if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
-          tempbx = 7;
+        tempbx = 10;
+       if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
+        if(SiS_Pr->SiS_TVMode & TVSetPAL) {
+          tempbx += 2;
+          if(SiS_Pr->SiS_ModeType > ModeVGA) {
+             if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
+          }
+          if(SiS_Pr->SiS_TVMode & TVSetPALM) {
+             tempbx = 90;
+             if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
+          } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
+             tempbx = 92;
+             if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
+          }
         }
 
-       if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
-          tempbx = 84;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx++;
-       }
+     } else {
 
-     }
+        switch(SiS_Pr->SiS_LCDResInfo) {
+       case Panel_640x480:   tempbx = 6;  break;
+       case Panel_640x480_2:
+       case Panel_640x480_3: tempbx = 30; break;
+       case Panel_800x600:   tempbx = 0;  break;
+       case Panel_1024x600:  tempbx = 15; break;
+       case Panel_1024x768:  tempbx = 2;  break;
+       case Panel_1152x768:  tempbx = 17; break;
+       case Panel_1280x768:  tempbx = 18; break;
+       case Panel_1280x1024: tempbx = 4;  break;
+       case Panel_1400x1050: tempbx = 8;  break;
+       case Panel_1600x1200: tempbx = 21; break;
+       case Panel_Barco1366: tempbx = 80; break;
+       }
 
-     if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
-        if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) tempal = 7;
-       if(HwInfo->jChipType < SIS_315H) {
-          if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) tempal++;
+       switch(SiS_Pr->SiS_LCDResInfo) {
+       case Panel_640x480:
+       case Panel_640x480_2:
+       case Panel_640x480_3:
+          break;
+       default:
+          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
        }
-     }
 
-     *CRT2Index = tempbx;
-     *ResIndex = tempal & 0x1F;
-  }
-}
+       if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 7;
 
-#ifdef SIS315H
-static void
-SiS_GetCRT2PtrA(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
-               USHORT RefreshRateTableIndex,USHORT *CRT2Index,
-               USHORT *ResIndex)
-{
-  USHORT tempbx,tempal;
-
-  tempbx = SiS_Pr->SiS_LCDResInfo;
-
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)      tempbx = 4;
-  else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempbx = 3;
-  else tempbx -= SiS_Pr->SiS_Panel1024x768;
-
-  if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx += 5;
+       if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
+          tempbx = 82;
+          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
+       } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
+          tempbx = 84;
+          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
+       }
 
-  if(ModeNo <= 0x13)
-     tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
-  else
-     tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
+       if((SiS_Pr->SiS_CustomT != CUT_BARCO1366) &&
+           (SiS_Pr->SiS_CustomT != CUT_PANEL848)) {
+           if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) &&
+             (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
+              tempal = 0;
+          }
+        }
 
-  /* No customs required yet (Clevo, Compaq, etc) */
+     }
 
-  *CRT2Index = tempbx;
-  *ResIndex = tempal & 0x1F;
+     (*CRT2Index) = tempbx;
+     (*ResIndex) = tempal & 0x1F;
+  }
 }
-#endif
 
 static void
 SiS_GetRAMDAC2DATA(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
@@ -2969,8 +3182,7 @@ SiS_GetRAMDAC2DATA(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
 
 static void
 SiS_GetCRT2DataLVDS(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
-                    USHORT RefreshRateTableIndex,
-                   PSIS_HW_INFO HwInfo)
+                    USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
 {
    USHORT CRT2Index, ResIndex;
    const SiS_LVDSDataStruct *LVDSData = NULL;
@@ -2988,23 +3200,41 @@ SiS_GetCRT2DataLVDS(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
       SiS_Pr->SiS_RY4COE = 0;
    }
 
-   if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
+   if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
 
 #ifdef SIS315H
-      SiS_GetCRT2PtrA(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
-                      &CRT2Index,&ResIndex);
-
-      switch (CRT2Index) {
-       case  0:  LVDSData = SiS_Pr->SiS_LCDA1024x768Data_1;    break;
-       case  1:  LVDSData = SiS_Pr->SiS_LCDA1280x1024Data_1;   break;
-       case  3:  LVDSData = SiS_Pr->SiS_LCDA1400x1050Data_1;   break;
-       case  4:  LVDSData = SiS_Pr->SiS_LCDA1600x1200Data_1;   break;
-       case  5:  LVDSData = SiS_Pr->SiS_LCDA1024x768Data_2;    break;
-       case  6:  LVDSData = SiS_Pr->SiS_LCDA1280x1024Data_2;   break;
-       case  8:  LVDSData = SiS_Pr->SiS_LCDA1400x1050Data_2;   break;
-       case  9:  LVDSData = SiS_Pr->SiS_LCDA1600x1200Data_2;   break;
-       default:  LVDSData = SiS_Pr->SiS_LCDA1024x768Data_1;    break;
+      if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+         if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
+           if(SiS_Pr->UseCustomMode) {
+              SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->CHTotal;
+              SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
+           } else {
+              if(ModeNo < 0x13) {
+                 ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+              } else {
+                 ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
+              }
+              SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
+               SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
+               SiS_Pr->SiS_HT    = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
+               SiS_Pr->SiS_VT    = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
+           }
+        } else {
+           SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
+            SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
+        }
+      } else {
+        /* This handles custom modes and custom panels */
+        SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
+         SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
+         SiS_Pr->SiS_HT  = SiS_Pr->PanelHT;
+         SiS_Pr->SiS_VT  = SiS_Pr->PanelVT;
+        SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
+        SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
       }
+
+      SiS_CalcLCDACRT1Timing(SiS_Pr,ModeNo,ModeIdIndex);
+
 #endif
 
    } else {
@@ -3015,7 +3245,7 @@ SiS_GetCRT2DataLVDS(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
       }
 
       SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
-                     &CRT2Index, &ResIndex, HwInfo);
+                               &CRT2Index, &ResIndex, HwInfo);
 
       /* 301BDH needs LVDS Data */
       if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
@@ -3023,72 +3253,59 @@ SiS_GetCRT2DataLVDS(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
       }
 
       switch (CRT2Index) {
-       case  0:  LVDSData = SiS_Pr->SiS_LVDS800x600Data_1;    break;
-       case  1:  LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1;   break;
-       case  2:  LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_1;  break;
-       case  3:  LVDSData = SiS_Pr->SiS_LVDS800x600Data_2;    break;
-       case  4:  LVDSData = SiS_Pr->SiS_LVDS1024x768Data_2;   break;
-       case  5:  LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_2;  break;
-       case  6:  LVDSData = SiS_Pr->SiS_LVDS640x480Data_1;    break;
-        case  7:  LVDSData = SiS_Pr->SiS_LVDSXXXxXXXData_1;    break;
-       case  8:  LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_1;  break;
-       case  9:  LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_2;  break;
-       case 10:  LVDSData = SiS_Pr->SiS_CHTVUNTSCData;        break;
-       case 11:  LVDSData = SiS_Pr->SiS_CHTVONTSCData;        break;
-       case 12:  LVDSData = SiS_Pr->SiS_CHTVUPALData;         break;
-       case 13:  LVDSData = SiS_Pr->SiS_CHTVOPALData;         break;
-       case 14:  LVDSData = SiS_Pr->SiS_LVDS320x480Data_1;    break;
-       case 15:  LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1;   break;
-       case 16:  LVDSData = SiS_Pr->SiS_LVDS1152x768Data_1;   break;
-       case 17:  LVDSData = SiS_Pr->SiS_LVDS1024x600Data_2;   break;
-       case 18:  LVDSData = SiS_Pr->SiS_LVDS1152x768Data_2;   break;
-       case 19:  LVDSData = SiS_Pr->SiS_LVDS1280x768Data_1;   break;
-       case 20:  LVDSData = SiS_Pr->SiS_LVDS1280x768Data_2;   break;
-       case 21:  LVDSData = SiS_Pr->SiS_LVDS1600x1200Data_1;  break;
-       case 22:  LVDSData = SiS_Pr->SiS_LVDS1600x1200Data_2;  break;
-       case 30:  LVDSData = SiS_Pr->SiS_LVDS640x480Data_2;    break;
-       case 80:  LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1;  break;
-       case 81:  LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2;  break;
-       case 82:  LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1;  break;
-       case 83:  LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_2;  break;
-       case 84:  LVDSData = SiS_Pr->SiS_LVDS848x480Data_1;    break;
-       case 85:  LVDSData = SiS_Pr->SiS_LVDS848x480Data_2;    break;
-       case 90:  LVDSData = SiS_Pr->SiS_CHTVUPALMData;        break;
-       case 91:  LVDSData = SiS_Pr->SiS_CHTVOPALMData;        break;
-       case 92:  LVDSData = SiS_Pr->SiS_CHTVUPALNData;        break;
-       case 93:  LVDSData = SiS_Pr->SiS_CHTVOPALNData;        break;
-       case 99:  LVDSData = SiS_Pr->SiS_CHTVSOPALData;        break;  /* Super Overscan */
-       default:  LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1;   break;
-      }
-   }
-
-   SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
-   SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
-   SiS_Pr->SiS_HT    = (LVDSData+ResIndex)->LCDHT;
-   SiS_Pr->SiS_VT    = (LVDSData+ResIndex)->LCDVT;
-
-   if(SiS_Pr->SiS_VBType & VB_SISVB) {
-
-      if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
-         SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
-         SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
+        case  0: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1;    break;
+        case  1: LVDSData = SiS_Pr->SiS_LVDS800x600Data_2;    break;
+        case  2: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1;   break;
+        case  3: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_2;   break;
+        case  4: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_1;  break;
+        case  5: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_2;  break;
+        case  6: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1;    break;
+         case  7: LVDSData = SiS_Pr->SiS_LVDSXXXxXXXData_1;    break;
+        case  8: LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_1;  break;
+        case  9: LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_2;  break;
+        case 10: LVDSData = SiS_Pr->SiS_CHTVUNTSCData;        break;
+        case 11: LVDSData = SiS_Pr->SiS_CHTVONTSCData;        break;
+        case 12: LVDSData = SiS_Pr->SiS_CHTVUPALData;         break;
+        case 13: LVDSData = SiS_Pr->SiS_CHTVOPALData;         break;
+        case 14: LVDSData = SiS_Pr->SiS_LVDS320x480Data_1;    break;
+        case 15: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1;   break;
+        case 16: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_2;   break;
+        case 17: LVDSData = SiS_Pr->SiS_LVDS1152x768Data_1;   break;
+        case 18: LVDSData = SiS_Pr->SiS_LVDS1152x768Data_2;   break;
+        case 19: LVDSData = SiS_Pr->SiS_LVDS1280x768Data_1;   break;
+        case 20: LVDSData = SiS_Pr->SiS_LVDS1280x768Data_2;   break;
+        case 21: LVDSData = SiS_Pr->SiS_LVDS1600x1200Data_1;  break;
+        case 22: LVDSData = SiS_Pr->SiS_LVDS1600x1200Data_2;  break;
+        case 30: LVDSData = SiS_Pr->SiS_LVDS640x480Data_2;    break;
+        case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1;  break;
+        case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2;  break;
+        case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1;  break;
+        case 83: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_2;  break;
+        case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1;    break;
+        case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2;    break;
+        case 90: LVDSData = SiS_Pr->SiS_CHTVUPALMData;        break;
+        case 91: LVDSData = SiS_Pr->SiS_CHTVOPALMData;        break;
+        case 92: LVDSData = SiS_Pr->SiS_CHTVUPALNData;        break;
+        case 93: LVDSData = SiS_Pr->SiS_CHTVOPALNData;        break;
+        case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData;        break;  /* Super Overscan */
+        default: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1;   break;
       }
 
-   } else {
+      SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
+      SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
+      SiS_Pr->SiS_HT    = (LVDSData+ResIndex)->LCDHT;
+      SiS_Pr->SiS_VT    = (LVDSData+ResIndex)->LCDVT;
 
-      if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
+      if(!(SiS_Pr->SiS_VBType & VB_SISVB)) {
          if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
-            if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-               if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
-                 SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
-                  SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
-
-                 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
-                    if(ResIndex < 0x08) {
-                       SiS_Pr->SiS_HDE = 1280;
-                        SiS_Pr->SiS_VDE = 1024;
-                    }
-                 }
+            if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
+              SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
+               SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
+              if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
+                 if(ResIndex < 0x08) {
+                    SiS_Pr->SiS_HDE = 1280;
+                     SiS_Pr->SiS_VDE = 1024;
+                  }
                }
             }
          }
@@ -3101,23 +3318,38 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
                    USHORT RefreshRateTableIndex,
                   PSIS_HW_INFO HwInfo)
 {
-  USHORT tempax,tempbx,modeflag;
-  USHORT resinfo;
-  USHORT CRT2Index,ResIndex;
+  UCHAR  *ROMAddr = NULL;
+  USHORT tempax,tempbx,modeflag,romptr=0;
+  USHORT resinfo,CRT2Index,ResIndex;
   const SiS_LCDDataStruct *LCDPtr = NULL;
   const SiS_TVDataStruct  *TVPtr  = NULL;
+#ifdef SIS315H
+  SHORT  resinfo661;
+#endif
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
      resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
+  } else if(SiS_Pr->UseCustomMode) {
+     modeflag = SiS_Pr->CModeFlag;
+     resinfo = 0;
   } else {
-     if(SiS_Pr->UseCustomMode) {
-        modeflag = SiS_Pr->CModeFlag;
-       resinfo = 0;
-     } else {
-       modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-       resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
+     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
+     resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
+#ifdef SIS315H
+     resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
+     if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)   &&
+         (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
+         (resinfo661 >= 0)                     &&
+        (SiS_Pr->SiS_NeedRomModeData) ) {
+        if((ROMAddr = GetLCDStructPtr661(SiS_Pr, HwInfo))) {
+          if((romptr = (SISGETROMW(21)))) {
+              romptr += (resinfo661 * 10);
+             ROMAddr = HwInfo->pjVirtualRomBase;
+          }
+       }
      }
+#endif
   }
   
   SiS_Pr->SiS_NewFlickerMode = 0;
@@ -3145,6 +3377,7 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
      } else {
 
         SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
+
      }
 
   } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
@@ -3153,20 +3386,20 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
                     &CRT2Index,&ResIndex,HwInfo);
 
      switch(CRT2Index) {
-       case  2:  TVPtr = SiS_Pr->SiS_ExtHiTVData;   break;
-       case  3:  TVPtr = SiS_Pr->SiS_ExtPALData;    break;
-       case  4:  TVPtr = SiS_Pr->SiS_ExtNTSCData;   break;
-       case  5:  TVPtr = SiS_Pr->SiS_Ext525iData;   break;
-       case  6:  TVPtr = SiS_Pr->SiS_Ext525pData;   break;
-       case  7:  TVPtr = SiS_Pr->SiS_Ext750pData;   break;
-       case  8:  TVPtr = SiS_Pr->SiS_StPALData;     break;
-       case  9:  TVPtr = SiS_Pr->SiS_StNTSCData;    break;
-       case 10:  TVPtr = SiS_Pr->SiS_St525iData;    break;
-       case 11:  TVPtr = SiS_Pr->SiS_St525pData;    break;
-       case 12:  TVPtr = SiS_Pr->SiS_St750pData;    break;
-       case 13:  TVPtr = SiS_Pr->SiS_St1HiTVData;   break;
-       case 14:  TVPtr = SiS_Pr->SiS_St2HiTVData;   break;
-       default:  TVPtr = SiS_Pr->SiS_StPALData;     break;
+        case  2: TVPtr = SiS_Pr->SiS_ExtHiTVData;   break;
+        case  3: TVPtr = SiS_Pr->SiS_ExtPALData;    break;
+        case  4: TVPtr = SiS_Pr->SiS_ExtNTSCData;   break;
+        case  5: TVPtr = SiS_Pr->SiS_Ext525iData;   break;
+        case  6: TVPtr = SiS_Pr->SiS_Ext525pData;   break;
+        case  7: TVPtr = SiS_Pr->SiS_Ext750pData;   break;
+        case  8: TVPtr = SiS_Pr->SiS_StPALData;     break;
+        case  9: TVPtr = SiS_Pr->SiS_StNTSCData;    break;
+        case 10: TVPtr = SiS_Pr->SiS_St525iData;    break;
+        case 11: TVPtr = SiS_Pr->SiS_St525pData;    break;
+        case 12: TVPtr = SiS_Pr->SiS_St750pData;    break;
+        case 13: TVPtr = SiS_Pr->SiS_St1HiTVData;   break;
+        case 14: TVPtr = SiS_Pr->SiS_St2HiTVData;   break;
+        default: TVPtr = SiS_Pr->SiS_StPALData;     break;
      }
 
      SiS_Pr->SiS_RVBHCMAX  = (TVPtr+ResIndex)->RVBHCMAX;
@@ -3247,71 +3480,108 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
 
   } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
 
+     SiS_Pr->SiS_RVBHCMAX  = 1;
+     SiS_Pr->SiS_RVBHCFACT = 1;
+
      if(SiS_Pr->UseCustomMode) {
 
-        SiS_Pr->SiS_RVBHCMAX  = 1;
-        SiS_Pr->SiS_RVBHCFACT = 1;
-        SiS_Pr->SiS_VGAHT     = SiS_Pr->CHTotal;
-        SiS_Pr->SiS_VGAVT     = SiS_Pr->CVTotal;
-        SiS_Pr->SiS_HT        = SiS_Pr->CHTotal;
-        SiS_Pr->SiS_VT        = SiS_Pr->CVTotal;
-       SiS_Pr->SiS_HDE       = SiS_Pr->SiS_VGAHDE;
-        SiS_Pr->SiS_VDE       = SiS_Pr->SiS_VGAVDE;
+        SiS_Pr->SiS_VGAHT = SiS_Pr->CHTotal;
+        SiS_Pr->SiS_VGAVT = SiS_Pr->CVTotal;
+        SiS_Pr->SiS_HT    = SiS_Pr->CHTotal;
+        SiS_Pr->SiS_VT    = SiS_Pr->CVTotal;
+       SiS_Pr->SiS_HDE   = SiS_Pr->SiS_VGAHDE;
+        SiS_Pr->SiS_VDE   = SiS_Pr->SiS_VGAVDE;
 
      } else {
 
-        SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
-                      &CRT2Index,&ResIndex,HwInfo);
-
-        switch(CRT2Index) {
-         case  0: LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data;        break; /* VESA Timing */
-         case  1: LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data;       break; /* VESA Timing */
-         case  5: LCDPtr = SiS_Pr->SiS_StLCD1024x768Data;         break; /* Obviously unused */
-         case  6: LCDPtr = SiS_Pr->SiS_StLCD1280x1024Data;        break; /* Obviously unused */
-         case 10: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data;        break; /* Non-VESA Timing */
-         case 11: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data;       break; /* Non-VESA Timing */
-         case 13: LCDPtr = SiS_Pr->SiS_NoScaleData1024x768;       break; /* Non-expanding */
-         case 14: LCDPtr = SiS_Pr->SiS_NoScaleData1280x1024;      break; /* Non-expanding */
-         case 15: LCDPtr = SiS_Pr->SiS_LCD1280x960Data;           break; /* 1280x960 */
-         case 20: LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data;       break; /* VESA Timing */
-         case 21: LCDPtr = SiS_Pr->SiS_NoScaleData1400x1050;      break; /* Non-expanding (let panel scale) */
-         case 22: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data;        break; /* Non-VESA Timing (let panel scale) */
-         case 23: LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data;       break; /* VESA Timing */
-         case 24: LCDPtr = SiS_Pr->SiS_NoScaleData1600x1200;      break; /* Non-expanding */
-         case 25: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data;        break; /* Non-VESA Timing */
-         case 26: LCDPtr = SiS_Pr->SiS_ExtLCD1280x768Data;        break; /* VESA Timing */
-         case 27: LCDPtr = SiS_Pr->SiS_NoScaleData1280x768;       break; /* Non-expanding */
-         case 28: LCDPtr = SiS_Pr->SiS_StLCD1280x768Data;         break; /* Non-VESA Timing */
-         case 29: LCDPtr = SiS_Pr->SiS_NoScaleData;              break; /* Generic no-scale data */
+        BOOLEAN gotit = FALSE;
+
+        if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
+
+           SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
+           SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
+           SiS_Pr->SiS_HT    = SiS_Pr->PanelHT;
+           SiS_Pr->SiS_VT    = SiS_Pr->PanelVT;
+          gotit = TRUE;
+
+       } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
+
 #ifdef SIS315H
-        case 50: LCDPtr = (SiS_LCDDataStruct *)SiS310_ExtCompaq1280x1024Data;  break;
-        case 51: LCDPtr = SiS_Pr->SiS_NoScaleData1280x1024;                    break;
-        case 52: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data;                     break;
+          SiS_Pr->SiS_RVBHCMAX  = ROMAddr[romptr];
+           SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
+           SiS_Pr->SiS_VGAHT     = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
+           SiS_Pr->SiS_VGAVT     = ROMAddr[romptr+4] | ((ROMAddr[romptr+3] & 0xf0) << 4);
+           SiS_Pr->SiS_HT        = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8);
+           SiS_Pr->SiS_VT        = ROMAddr[romptr+7] | ((ROMAddr[romptr+6] & 0xf0) << 4);
+          if(SiS_Pr->SiS_VGAHT) gotit = TRUE;
+          else {
+             SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
+             SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
+             SiS_Pr->SiS_VGAHT   = SiS_Pr->PanelHT;
+              SiS_Pr->SiS_VGAVT   = SiS_Pr->PanelVT;
+              SiS_Pr->SiS_HT      = SiS_Pr->PanelHT;
+              SiS_Pr->SiS_VT      = SiS_Pr->PanelVT;
+             gotit = TRUE;
+          }
 #endif
-         default: LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data;       break;
-        }
 
-        SiS_Pr->SiS_RVBHCMAX  = (LCDPtr+ResIndex)->RVBHCMAX;
-        SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
-        SiS_Pr->SiS_VGAHT     = (LCDPtr+ResIndex)->VGAHT;
-        SiS_Pr->SiS_VGAVT     = (LCDPtr+ResIndex)->VGAVT;
-        SiS_Pr->SiS_HT        = (LCDPtr+ResIndex)->LCDHT;
-        SiS_Pr->SiS_VT        = (LCDPtr+ResIndex)->LCDVT;
+       }
+
+       if(!gotit) {
+
+           SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
+                          &CRT2Index,&ResIndex,HwInfo);
+
+           switch(CRT2Index) {
+             case Panel_1024x768      : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data;   break;
+             case Panel_1024x768  + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data;   break;
+             case Panel_1280x720      :
+             case Panel_1280x720  + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data;      break;
+             case Panel_1280x768_2    : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break;
+              case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data;  break;
+             case Panel_1280x800      :
+             case Panel_1280x800  + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data;      break;
+             case Panel_1280x800_2    :
+             case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data;    break;
+             case Panel_1280x960      :
+             case Panel_1280x960  + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data;      break;
+              case Panel_1280x1024     : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data;  break;
+              case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data;  break;
+              case Panel_1400x1050     : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data;  break;
+              case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data;   break;
+              case Panel_1600x1200     : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data;  break;
+              case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data;   break;
+             case Panel_1680x1050     :
+             case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data;     break;
+             case 100                 : LCDPtr = SiS_Pr->SiS_NoScaleData;          break;
+#ifdef SIS315H
+             case 200                 : LCDPtr = SiS310_ExtCompaq1280x1024Data;    break;
+             case 201                 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data;  break;
+#endif
+              default                  : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data;   break;
+           }
 
 #ifdef TWDEBUG
-        xf86DrvMsg(0, X_INFO,
-           "GetCRT2Data: Index %d ResIndex %d\n", CRT2Index, ResIndex);
+           xf86DrvMsg(0, X_INFO, "GetCRT2Data: Index %d ResIndex %d\n", CRT2Index, ResIndex);
 #endif
 
-       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-           tempax = 1024;
+           SiS_Pr->SiS_RVBHCMAX  = (LCDPtr+ResIndex)->RVBHCMAX;
+           SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
+           SiS_Pr->SiS_VGAHT     = (LCDPtr+ResIndex)->VGAHT;
+           SiS_Pr->SiS_VGAVT     = (LCDPtr+ResIndex)->VGAVT;
+           SiS_Pr->SiS_HT        = (LCDPtr+ResIndex)->LCDHT;
+           SiS_Pr->SiS_VT        = (LCDPtr+ResIndex)->LCDVT;
+
+        }
+
+       tempax = SiS_Pr->PanelXRes;
+        tempbx = SiS_Pr->PanelYRes;
+
+       if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
            if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
               if(HwInfo->jChipType < SIS_315H) {
                  if     (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
                  else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
-                 else                               tempbx = 768;
-              } else {
-                 tempbx = 768;
               }
            } else {
               if     (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527;
@@ -3320,43 +3590,27 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
               else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775;
               else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
               else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
-              else                               tempbx = 768;
            }
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-           tempax = 1280;
-           if     (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
-           else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
-           else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
-           else                               tempbx = 1024;
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) {
-           tempax = 1280;
+       } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) {
            if     (SiS_Pr->SiS_VGAVDE == 350)  tempbx = 700;
            else if(SiS_Pr->SiS_VGAVDE == 400)  tempbx = 800;
            else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960;
-           else                                tempbx = 960;
-       } else if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) &&
-                 (HwInfo->jChipType >= SIS_661)) {
-          tempax = 1400;
-          tempbx = 1050;
-          if(SiS_Pr->SiS_VGAVDE == 1024) {
-             tempax = 1280;
-             tempbx = 1024;
-          }
-        } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) {
-           tempax = 1600;
-          tempbx = 1200;
-          if((HwInfo->jChipType < SIS_661) || (!(SiS_Pr->SiS_SetFlag & LCDVESATiming))) {
+       } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
+           if     (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
+           else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
+           else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
+        } else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) {
+          if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
               if     (SiS_Pr->SiS_VGAVDE == 350)  tempbx = 875;
               else if(SiS_Pr->SiS_VGAVDE == 400)  tempbx = 1000;
            }
-        } else {
-          tempax = SiS_Pr->PanelXRes;
-           tempbx = SiS_Pr->PanelYRes;
-       }
+        }
+
         if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
            tempax = SiS_Pr->SiS_VGAHDE;
            tempbx = SiS_Pr->SiS_VGAVDE;
         }
+
         SiS_Pr->SiS_HDE = tempax;
         SiS_Pr->SiS_VDE = tempbx;
      }
@@ -3370,31 +3624,15 @@ SiS_GetCRT2Data(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
   if(SiS_Pr->SiS_VBType & VB_SISVB) {
 
-     if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-
-        if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
-
-           SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
-
-        } else {
-
-          if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
-
-             /* Need LVDS Data for LCD on 301B-DH */
-             SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
-
-          } else {
-
-             SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
-
-           }
-
-        }
-
+     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
+        SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
      } else {
-
-       SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
-
+       if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
+          /* Need LVDS Data for LCD on 301B-DH */
+          SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
+       } else {
+          SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
+        }
      }
 
   } else {
@@ -3405,7 +3643,7 @@ SiS_GetCRT2Data(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 }
 
 /*********************************************/
-/*            GET LVDS DES DATA              */
+/*         GET LVDS DES (SKEW) DATA          */
 /*********************************************/
 
 static void
@@ -3413,106 +3651,55 @@ SiS_GetLVDSDesPtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                   USHORT RefreshRateTableIndex, USHORT *PanelIndex,
                  USHORT *ResIndex, PSIS_HW_INFO HwInfo)
 {
-  USHORT tempbx,tempal,modeflag;
+  USHORT modeflag;
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-     tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+     (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
   } else {
      modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-     tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
+     (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
   }
 
-  tempbx = 0;
+  (*ResIndex) &= 0x1F;
+  (*PanelIndex) = 0;
+
   if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-        tempbx = 50;
-        if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) tempbx += 2;
-        if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
+        (*PanelIndex) = 50;
+        if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) (*PanelIndex) += 2;
+        if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*PanelIndex) += 1;
         /* Nothing special needed for SOverscan    */
-        /*     PALM uses NTSC data, PALN uses PAL data */
+        /* PALM uses NTSC data, PALN uses PAL data */
      }
   }
 
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-     tempbx = SiS_Pr->SiS_LCDTypeInfo;
+     *PanelIndex = SiS_Pr->SiS_LCDTypeInfo;
      if(HwInfo->jChipType >= SIS_661) {
         /* As long as we don's use the BIOS tables, we
         * need to convert the TypeInfo as for 315 series
         */
-        tempbx = SiS_Pr->SiS_LCDResInfo - 1;
+        (*PanelIndex) = SiS_Pr->SiS_LCDResInfo - 1;
      }
-     if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 16;
-     if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
-        tempbx = 32;
-        if(modeflag & HalfDCLK) tempbx++;
+     if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+        (*PanelIndex) += 16;
+        if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
+           (*PanelIndex) = 32;
+           if(modeflag & HalfDCLK) (*PanelIndex)++;
+       }
      }
   }
 
   if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
-     if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480)  {
-        tempal = 0x07;
+     if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) {
+        (*ResIndex) = 7;
         if(HwInfo->jChipType < SIS_315H) {
-           if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) tempal++;
+           if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) (*ResIndex)++;
         }
      }
   }
-
-  *PanelIndex = tempbx;
-  *ResIndex = tempal & 0x1F;
-}
-
-#ifdef SIS315H
-static void
-SiS_GetLVDSDesPtrA(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
-                   USHORT RefreshRateTableIndex, USHORT *PanelIndex, USHORT *ResIndex,
-                  PSIS_HW_INFO HwInfo)
-{
-  USHORT tempbx=0,tempal;
-
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050)      tempbx = 2;
-  else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempbx = 3;
-  else tempbx = SiS_Pr->SiS_LCDResInfo - 2;
-
-  if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)  tempbx += 4;
-
-  if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-        if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
-          tempbx = 80;
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
-       }
-     }
-  }
-  if((SiS_Pr->SiS_CustomT == CUT_UNIWILL1024) ||
-     (SiS_Pr->SiS_CustomT == CUT_UNIWILL10242)) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-       tempbx = 82;
-       if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
-     }
-  }
-  if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-       tempbx = 84;
-       if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
-     }
-  }
-  if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-       tempbx = 86;
-       if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
-     }
-  }
-
-  if(ModeNo <= 0x13)
-     tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
-  else
-     tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
-
-  *PanelIndex = tempbx;
-  *ResIndex = tempal & 0x1F;
 }
-#endif
 
 static void
 SiS_GetLVDSDesData(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
@@ -3522,39 +3709,45 @@ SiS_GetLVDSDesData(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
   USHORT PanelIndex,ResIndex;
   const  SiS_LVDSDesStruct *PanelDesPtr = NULL;
 
-  if((SiS_Pr->UseCustomMode) ||
-     (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom) ||
-     (SiS_Pr->SiS_CustomT == CUT_PANEL848)) {
-     SiS_Pr->SiS_LCDHDES = 0;
-     SiS_Pr->SiS_LCDVDES = 0;
+  SiS_Pr->SiS_LCDHDES = 0;
+  SiS_Pr->SiS_LCDVDES = 0;
+
+  if( (SiS_Pr->UseCustomMode)                   ||
+      (SiS_Pr->SiS_LCDResInfo == Panel_Custom)   ||
+      (SiS_Pr->SiS_CustomT == CUT_PANEL848)      ||
+      ((SiS_Pr->SiS_VBType & VB_SISVB) &&
+       (SiS_Pr->SiS_LCDInfo & DontExpandLCD) &&
+       (SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
      return;
   }
 
   if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
 
 #ifdef SIS315H
-     SiS_GetLVDSDesPtrA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
-                        &PanelIndex, &ResIndex, HwInfo);
-
-     switch (PanelIndex)
-     {
-       case  0: PanelDesPtr = SiS_Pr->LVDS1024x768Des_1;   break;  /* --- expanding --- */
-       case  1: PanelDesPtr = SiS_Pr->LVDS1280x1024Des_1;  break;
-       case  2: PanelDesPtr = SiS_Pr->LVDS1400x1050Des_1;  break;
-       case  3: PanelDesPtr = SiS_Pr->LVDS1600x1200Des_1;  break;
-       case  4: PanelDesPtr = SiS_Pr->LVDS1024x768Des_2;   break;  /* --- non expanding --- */
-       case  5: PanelDesPtr = SiS_Pr->LVDS1280x1024Des_2;  break;
-       case  6: PanelDesPtr = SiS_Pr->LVDS1400x1050Des_2;  break;
-       case  7: PanelDesPtr = SiS_Pr->LVDS1600x1200Des_2;  break;
-       case 80: PanelDesPtr = (SiS_LVDSDesStruct *)Clevo1024x768Des_1;   break;  /*  custom  */
-       case 81: PanelDesPtr = (SiS_LVDSDesStruct *)Clevo1024x768Des_2;   break;
-       case 82: PanelDesPtr = (SiS_LVDSDesStruct *)Uniwill1024x768Des_1; break;
-       case 83: PanelDesPtr = (SiS_LVDSDesStruct *)Uniwill1024x768Des_2; break;
-       case 84: PanelDesPtr = (SiS_LVDSDesStruct *)Compaq1280x1024Des_1; break;
-       case 85: PanelDesPtr = (SiS_LVDSDesStruct *)Compaq1280x1024Des_2; break;
-       case 86: PanelDesPtr = (SiS_LVDSDesStruct *)Asus1024x768Des_1;    break;  /*  custom  */
-       case 87: PanelDesPtr = (SiS_LVDSDesStruct *)Asus1024x768Des_2;    break;
-       default: PanelDesPtr = SiS_Pr->LVDS1024x768Des_1;   break;
+     if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+        /* non-pass 1:1 only, see above */
+        if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
+           SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
+       }
+       if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
+          SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
+       }
+     }
+     if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
+        switch(SiS_Pr->SiS_CustomT) {
+        case CUT_UNIWILL1024:
+        case CUT_UNIWILL10242:
+        case CUT_CLEVO1400:
+          if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
+             SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
+          }
+          break;
+       }
+       if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
+          if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
+             SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
+          }
+       }
      }
 #endif
 
@@ -3563,87 +3756,68 @@ SiS_GetLVDSDesData(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
      SiS_GetLVDSDesPtr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
                        &PanelIndex, &ResIndex, HwInfo);
 
-     switch (PanelIndex)
-     {
-       case  0: PanelDesPtr = SiS_Pr->SiS_PanelType00_1;   break;   /* ---  */
-       case  1: PanelDesPtr = SiS_Pr->SiS_PanelType01_1;   break;
-       case  2: PanelDesPtr = SiS_Pr->SiS_PanelType02_1;   break;
-       case  3: PanelDesPtr = SiS_Pr->SiS_PanelType03_1;   break;
-       case  4: PanelDesPtr = SiS_Pr->SiS_PanelType04_1;   break;
-       case  5: PanelDesPtr = SiS_Pr->SiS_PanelType05_1;   break;
-       case  6: PanelDesPtr = SiS_Pr->SiS_PanelType06_1;   break;
-       case  7: PanelDesPtr = SiS_Pr->SiS_PanelType07_1;   break;
-       case  8: PanelDesPtr = SiS_Pr->SiS_PanelType08_1;   break;
-       case  9: PanelDesPtr = SiS_Pr->SiS_PanelType09_1;   break;
-       case 10: PanelDesPtr = SiS_Pr->SiS_PanelType0a_1;   break;
-       case 11: PanelDesPtr = SiS_Pr->SiS_PanelType0b_1;   break;
-       case 12: PanelDesPtr = SiS_Pr->SiS_PanelType0c_1;   break;
-       case 13: PanelDesPtr = SiS_Pr->SiS_PanelType0d_1;   break;
-       case 14: PanelDesPtr = SiS_Pr->SiS_PanelType0e_1;   break;
-       case 15: PanelDesPtr = SiS_Pr->SiS_PanelType0f_1;   break;
-       case 16: PanelDesPtr = SiS_Pr->SiS_PanelType00_2;   break;    /* --- */
-       case 17: PanelDesPtr = SiS_Pr->SiS_PanelType01_2;   break;
-       case 18: PanelDesPtr = SiS_Pr->SiS_PanelType02_2;   break;
-       case 19: PanelDesPtr = SiS_Pr->SiS_PanelType03_2;   break;
-       case 20: PanelDesPtr = SiS_Pr->SiS_PanelType04_2;   break;
-       case 21: PanelDesPtr = SiS_Pr->SiS_PanelType05_2;   break;
-       case 22: PanelDesPtr = SiS_Pr->SiS_PanelType06_2;   break;
-       case 23: PanelDesPtr = SiS_Pr->SiS_PanelType07_2;   break;
-       case 24: PanelDesPtr = SiS_Pr->SiS_PanelType08_2;   break;
-       case 25: PanelDesPtr = SiS_Pr->SiS_PanelType09_2;   break;
-       case 26: PanelDesPtr = SiS_Pr->SiS_PanelType0a_2;   break;
-       case 27: PanelDesPtr = SiS_Pr->SiS_PanelType0b_2;   break;
-       case 28: PanelDesPtr = SiS_Pr->SiS_PanelType0c_2;   break;
-       case 29: PanelDesPtr = SiS_Pr->SiS_PanelType0d_2;   break;
-       case 30: PanelDesPtr = SiS_Pr->SiS_PanelType0e_2;   break;
-       case 31: PanelDesPtr = SiS_Pr->SiS_PanelType0f_2;   break;
-       case 32: PanelDesPtr = SiS_Pr->SiS_PanelTypeNS_1;   break;    /* pass 1:1 */
-       case 33: PanelDesPtr = SiS_Pr->SiS_PanelTypeNS_2;   break;
-       case 50: PanelDesPtr = SiS_Pr->SiS_CHTVUNTSCDesData;   break; /* TV */
-       case 51: PanelDesPtr = SiS_Pr->SiS_CHTVONTSCDesData;   break;
-       case 52: PanelDesPtr = SiS_Pr->SiS_CHTVUPALDesData;    break;
-       case 53: PanelDesPtr = SiS_Pr->SiS_CHTVOPALDesData;    break;
-       default:
-                if(HwInfo->jChipType < SIS_315H)
-                   PanelDesPtr = SiS_Pr->SiS_PanelType0e_1;
-                else
-                   PanelDesPtr = SiS_Pr->SiS_PanelType01_1;
-                break;
-     }
-  }
-  SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
-  SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
-
-  if(SiS_Pr->SiS_LCDInfo & DontExpandLCD){
-     if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
-        if(ModeNo <= 0x13) {
-           modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-          if(!(modeflag & HalfDCLK)) {
-             SiS_Pr->SiS_LCDHDES = 632;
-          }
-        }
-     } else {
-        if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
-           if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024) {
-              if(SiS_Pr->SiS_LCDResInfo >= SiS_Pr->SiS_Panel1024x768) {
-                 if(ModeNo <= 0x13) {
-                   modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-                   if(HwInfo->jChipType < SIS_315H) {
-                      if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
-                   } else {
-                      if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)
-                         SiS_Pr->SiS_LCDHDES = 480;
-                       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050)
-                         SiS_Pr->SiS_LCDHDES = 804;
-                      if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)
-                         SiS_Pr->SiS_LCDHDES = 704;
-                       if(!(modeflag & HalfDCLK)) {
-                          SiS_Pr->SiS_LCDHDES = 320;
-                         if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050)
-                            SiS_Pr->SiS_LCDHDES = 632;
-                         else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)
-                            SiS_Pr->SiS_LCDHDES = 542;
-                       }
+     switch(PanelIndex) {
+       case  0: PanelDesPtr = SiS_Pr->SiS_PanelType00_1;    break;   /* ---  */
+       case  1: PanelDesPtr = SiS_Pr->SiS_PanelType01_1;    break;
+       case  2: PanelDesPtr = SiS_Pr->SiS_PanelType02_1;    break;
+       case  3: PanelDesPtr = SiS_Pr->SiS_PanelType03_1;    break;
+       case  4: PanelDesPtr = SiS_Pr->SiS_PanelType04_1;    break;
+       case  5: PanelDesPtr = SiS_Pr->SiS_PanelType05_1;    break;
+       case  6: PanelDesPtr = SiS_Pr->SiS_PanelType06_1;    break;
+       case  7: PanelDesPtr = SiS_Pr->SiS_PanelType07_1;    break;
+       case  8: PanelDesPtr = SiS_Pr->SiS_PanelType08_1;    break;
+       case  9: PanelDesPtr = SiS_Pr->SiS_PanelType09_1;    break;
+       case 10: PanelDesPtr = SiS_Pr->SiS_PanelType0a_1;    break;
+       case 11: PanelDesPtr = SiS_Pr->SiS_PanelType0b_1;    break;
+       case 12: PanelDesPtr = SiS_Pr->SiS_PanelType0c_1;    break;
+       case 13: PanelDesPtr = SiS_Pr->SiS_PanelType0d_1;    break;
+       case 14: PanelDesPtr = SiS_Pr->SiS_PanelType0e_1;    break;
+       case 15: PanelDesPtr = SiS_Pr->SiS_PanelType0f_1;    break;
+       case 16: PanelDesPtr = SiS_Pr->SiS_PanelType00_2;    break;    /* --- */
+       case 17: PanelDesPtr = SiS_Pr->SiS_PanelType01_2;    break;
+       case 18: PanelDesPtr = SiS_Pr->SiS_PanelType02_2;    break;
+       case 19: PanelDesPtr = SiS_Pr->SiS_PanelType03_2;    break;
+       case 20: PanelDesPtr = SiS_Pr->SiS_PanelType04_2;    break;
+       case 21: PanelDesPtr = SiS_Pr->SiS_PanelType05_2;    break;
+       case 22: PanelDesPtr = SiS_Pr->SiS_PanelType06_2;    break;
+       case 23: PanelDesPtr = SiS_Pr->SiS_PanelType07_2;    break;
+       case 24: PanelDesPtr = SiS_Pr->SiS_PanelType08_2;    break;
+       case 25: PanelDesPtr = SiS_Pr->SiS_PanelType09_2;    break;
+       case 26: PanelDesPtr = SiS_Pr->SiS_PanelType0a_2;    break;
+       case 27: PanelDesPtr = SiS_Pr->SiS_PanelType0b_2;    break;
+       case 28: PanelDesPtr = SiS_Pr->SiS_PanelType0c_2;    break;
+       case 29: PanelDesPtr = SiS_Pr->SiS_PanelType0d_2;    break;
+       case 30: PanelDesPtr = SiS_Pr->SiS_PanelType0e_2;    break;
+       case 31: PanelDesPtr = SiS_Pr->SiS_PanelType0f_2;    break;
+       case 32: PanelDesPtr = SiS_Pr->SiS_PanelTypeNS_1;    break;    /* pass 1:1 */
+       case 33: PanelDesPtr = SiS_Pr->SiS_PanelTypeNS_2;    break;
+       case 50: PanelDesPtr = SiS_Pr->SiS_CHTVUNTSCDesData; break;    /* TV */
+       case 51: PanelDesPtr = SiS_Pr->SiS_CHTVONTSCDesData; break;
+       case 52: PanelDesPtr = SiS_Pr->SiS_CHTVUPALDesData;  break;
+       case 53: PanelDesPtr = SiS_Pr->SiS_CHTVOPALDesData;  break;
+       default: return;
+     }
+
+     SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
+     SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
+
+     if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
+        modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
+        if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
+          if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632;
+        } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
+           if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
+              if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) {
+                if(HwInfo->jChipType < SIS_315H) {
+                   if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
+                } else {
+                   if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768)  SiS_Pr->SiS_LCDHDES = 480;
+                    if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
+                   if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
+                    if(!(modeflag & HalfDCLK)) {
+                       SiS_Pr->SiS_LCDHDES = 320;
+                      if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632;
+                      if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542;
                     }
                  }
               }
@@ -3653,18 +3827,6 @@ SiS_GetLVDSDesData(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
   }
 }
 
-/*********************************************/
-/*          SET CRT2 AUTO-THRESHOLD          */
-/*********************************************/
-
-#ifdef SIS315H
-static void
-SiS_CRT2AutoThreshold(SiS_Private *SiS_Pr)
-{
-  SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
-}
-#endif
-
 /*********************************************/
 /*           DISABLE VIDEO BRIDGE            */
 /*********************************************/
@@ -3683,55 +3845,40 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 
   if(SiS_Pr->SiS_VBType & VB_SISVB) {
 
-      if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {   /* ===== For 30xB/LV ===== */
+     if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {   /* ===== For 30xB/LV ===== */
 
         if(HwInfo->jChipType < SIS_315H) {
 
 #ifdef SIS300     /* 300 series */
 
-           if(HwInfo->jChipType == SIS_300) {  /* For 300+301LV (A907) */
-
-             if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
-                if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
-                   SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
-                   SiS_PanelDelay(SiS_Pr, HwInfo, 3);
-                }
+          if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
+             if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+                SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
+             } else {
+                SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08);
              }
+             SiS_PanelDelay(SiS_Pr, HwInfo, 3);
+          }
+          if(SiS_Is301B(SiS_Pr)) {
              SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
              SiS_ShortDelay(SiS_Pr,1);
-             SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
-             SiS_DisplayOff(SiS_Pr);
-             SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
-             SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
-             if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
-                if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) ||
-                    (!(SiS_CR36BIOSWord23d(SiS_Pr, HwInfo))) ) {
-                   SiS_PanelDelay(SiS_Pr, HwInfo, 2);
-                    SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
-                }
-             }
-
-          } else {
-
-             if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
-                SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08);
-                SiS_PanelDelay(SiS_Pr, HwInfo, 3);
-             }
-             if(SiS_Is301B(SiS_Pr)) {
-                SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
-                SiS_ShortDelay(SiS_Pr,1);
-             }
-             SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
-             SiS_DisplayOff(SiS_Pr);
-             SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
-             SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
-             SiS_UnLockCRT2(SiS_Pr,HwInfo);
+           }
+          SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
+          SiS_DisplayOff(SiS_Pr);
+          SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
+          SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
+          SiS_UnLockCRT2(SiS_Pr,HwInfo);
+          if(!(SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
              SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
              SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
-             if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) ||
-                 (!(SiS_CR36BIOSWord23d(SiS_Pr, HwInfo))) ) {
-                SiS_PanelDelay(SiS_Pr, HwInfo, 2);
-                 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04);
+          }
+          if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) ||
+              (!(SiS_CR36BIOSWord23d(SiS_Pr, HwInfo))) ) {
+             SiS_PanelDelay(SiS_Pr, HwInfo, 2);
+             if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+                 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
+             } else {
+                SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04);
              }
           }
 
@@ -3741,149 +3888,101 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 
 #ifdef SIS315H    /* 315 series */
 
-           if(IS_SIS550650740660) {            /* 550, 650, 740, 660 */
+          BOOLEAN custom1 = ((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
+                             (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) ? TRUE : FALSE;
+
+          modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
 
-             modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
+           if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
 
-              if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {                      /* LV */
 #ifdef SET_EMI
-                if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
-                   if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
-                      SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
-                   }
+             if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
+                if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
+                   SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
                 }
+             }
 #endif
-                if( (modenum <= 0x13) ||
-                    (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ||
-                    (SiS_IsVAMode(SiS_Pr,HwInfo)) ) {
-                   SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
-                   if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-                      (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {
-                      SiS_PanelDelay(SiS_Pr, HwInfo, 3);
-                   }
-                }
+             if( (modenum <= 0x13)                  ||
+                 (SiS_IsVAMode(SiS_Pr,HwInfo))      ||
+                 (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ) {
+                SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
+                if(custom1) SiS_PanelDelay(SiS_Pr, HwInfo, 3);
+             }
 
-                if((SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) &&
-                   (SiS_Pr->SiS_CustomT != CUT_CLEVO1400)) {
-                   SiS_DDC2Delay(SiS_Pr,0xff00);
-                   SiS_DDC2Delay(SiS_Pr,0xe000);
+             if(!custom1) {
+                SiS_DDC2Delay(SiS_Pr,0xff00);
+                SiS_DDC2Delay(SiS_Pr,0xe000);
+                SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
+                 pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
+                if(IS_SIS740) {
+                   SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
+                }
+                SiS_PanelDelay(SiS_Pr, HwInfo, 3);
+             }
 
-                   SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
+           }
 
-                    pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
+          if(!(SiS_IsNotM650orLater(SiS_Pr, HwInfo))) {
+             if(HwInfo->jChipType < SIS_340) {
+                tempah = 0xef;
+                if(SiS_IsVAMode(SiS_Pr,HwInfo)) tempah = 0xf7;
+                SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
+             }
+          }
 
-                   if(IS_SIS740) {
-                      SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
-                   }
+          if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+             SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10);
+          }
 
-                   SiS_PanelDelay(SiS_Pr, HwInfo, 3);
+          tempah = 0x3f;
+          if(SiS_IsDualEdge(SiS_Pr,HwInfo)) {
+             tempah = 0x7f;
+             if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) tempah = 0xbf;
+          }
+          SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
 
-                   if(!(SiS_IsNotM650orLater(SiS_Pr, HwInfo))) {
-                      tempah = 0xef;
-                      if(SiS_IsVAMode(SiS_Pr,HwInfo)) {
-                         tempah = 0xf7;
-                       }
-                      SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
-                   }
-                }
+           if((SiS_IsVAMode(SiS_Pr,HwInfo)) ||
+             ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && (modenum <= 0x13))) {
 
-              } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {                       /* B-DH */
+             SiS_DisplayOff(SiS_Pr);
+             if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+                SiS_PanelDelay(SiS_Pr, HwInfo, 2);
+             }
+             SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
+             SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
 
-                if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) {
-                   SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,0xef);
-                }
+          }
 
-             }
+          if((!(SiS_IsVAMode(SiS_Pr,HwInfo))) ||
+             ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && (modenum <= 0x13))) {
 
-             if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-                (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {
-                SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,0xef);
+             if(!(SiS_IsDualEdge(SiS_Pr,HwInfo))) {
+                SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
+                SiS_DisplayOff(SiS_Pr);
              }
+             SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
 
-              if((SiS_Pr->SiS_VBType & VB_SIS301B302B) ||
-                (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-                (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {
-                tempah = 0x3f;
-                if(SiS_IsDualEdge(SiS_Pr,HwInfo)) {
-                   tempah = 0x7f;
-                   if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
-                      tempah = 0xbf;
-                    }
-                }
-                SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
+             if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+                SiS_PanelDelay(SiS_Pr, HwInfo, 2);
              }
 
-              if((SiS_IsVAMode(SiS_Pr,HwInfo)) ||
-                ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && (modenum <= 0x13))) {
-
-                if((SiS_Pr->SiS_VBType & VB_SIS301B302B) ||
-                   (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-                   (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {
-                   SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
-                   SiS_DisplayOff(SiS_Pr);
-                   SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
-                } else {
-                   SiS_DisplayOff(SiS_Pr);
-                   SiS_PanelDelay(SiS_Pr, HwInfo, 2);
-                   SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
-                   SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
-                   if((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && (modenum <= 0x13)) {
-                      SiS_DisplayOff(SiS_Pr);
-                      SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
-                      SiS_PanelDelay(SiS_Pr, HwInfo, 2);
-                      SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
-                      temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
-                       SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
-                      SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
-                      SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
-                   }
-                }
-
-             } else {
-
-                if((SiS_Pr->SiS_VBType & VB_SIS301B302B) ||
-                   (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-                   (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {
-                   if(!(SiS_IsDualEdge(SiS_Pr,HwInfo))) {
-                      SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
-                      SiS_DisplayOff(SiS_Pr);
-                   }
-                   SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
-                } else {
-                    SiS_DisplayOff(SiS_Pr);
-                   SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
-                   SiS_PanelDelay(SiS_Pr, HwInfo, 2);
-                }
+             SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
+             temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
+              SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
+             SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
+             SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
 
-                SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
-                temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
-                 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
-                SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
-                SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
+          }
 
-             }
+          if(SiS_IsNotM650orLater(SiS_Pr,HwInfo)) {
+             SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
+          }
 
-             if((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) &&
-                (SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) &&
-                (SiS_Pr->SiS_CustomT != CUT_CLEVO1400)) {
+          if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
 
-                SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,~0x10);
-
-                tempah = 0x3f;
-                if(SiS_IsDualEdge(SiS_Pr,HwInfo)) {
-                   tempah = 0x7f;
-                   if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
-                      tempah = 0xbf;
-                    }
-                }
-                SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
-
-                if(SiS_IsNotM650orLater(SiS_Pr,HwInfo)) {
-                   SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
-                }
+             if(!custom1) {
 
                 if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
-                   SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
                    if(!(SiS_CRT2IsLCD(SiS_Pr,HwInfo))) {
                       if(!(SiS_IsDualEdge(SiS_Pr,HwInfo))) {
                          SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
@@ -3894,95 +3993,39 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
                 SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
 
                 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
-                   if( (SiS_IsVAMode(SiS_Pr, HwInfo)) ||
-                       (SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ) {
+                   if(SiS_IsVAorLCD(SiS_Pr, HwInfo)) {
                       SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 20);
                    }
                 }
 
-             } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
-
-                /* NIL */
-
-             } else if((SiS_Pr->SiS_VBType & VB_SIS301B302B) ||
-                       (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-                       (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {
+             } else {
 
-                if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) {
-                   tempah = 0xef;
-                   if(SiS_IsDualEdge(SiS_Pr,HwInfo)) {
-                      if(modenum > 0x13) {
-                         tempah = 0xf7;
-                      }
-                    }
-                   SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
-                }
-                if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-                   (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {
-                   if((SiS_IsVAMode(SiS_Pr,HwInfo)) ||
-                      (!(SiS_IsDualEdge(SiS_Pr,HwInfo)))) {
-                      if((!(SiS_WeHaveBacklightCtrl(SiS_Pr, HwInfo))) ||
-                         (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo)))) {
-                         SiS_PanelDelay(SiS_Pr, HwInfo, 2);
-                         SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
-                         SiS_PanelDelay(SiS_Pr, HwInfo, 4);
-                      }
+                if((SiS_IsVAMode(SiS_Pr,HwInfo)) ||
+                   (!(SiS_IsDualEdge(SiS_Pr,HwInfo)))) {
+                   if((!(SiS_WeHaveBacklightCtrl(SiS_Pr, HwInfo))) ||
+                      (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo)))) {
+                      SiS_PanelDelay(SiS_Pr, HwInfo, 2);
+                      SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
+                      SiS_PanelDelay(SiS_Pr, HwInfo, 4);
                    }
                 }
 
              }
-
-         } else {                      /* 315, 330 - all bridge types */
-
-            if(SiS_Is301B(SiS_Pr)) {
-               tempah = 0x3f;
-               if(SiS_IsDualEdge(SiS_Pr,HwInfo)) {
-                  tempah = 0x7f;
-                  if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
-                     tempah = 0xbf;
-                   }
-               }
-               SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
-               if(SiS_IsVAMode(SiS_Pr,HwInfo)) {
-                  SiS_DisplayOff(SiS_Pr);
-                  SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
-               }
-            }
-            if( (!(SiS_Is301B(SiS_Pr))) ||
-                (!(SiS_IsVAMode(SiS_Pr,HwInfo))) ) {
-
-               if( (!(SiS_Is301B(SiS_Pr))) ||
-                   (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ) {
-
-                  SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
-                  SiS_DisplayOff(SiS_Pr);
-
-               }
-
-                SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
-
-                SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
-
-               temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
-                SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
-               SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
-               SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
-
-            }
-
-         }    /* 315/330 */
+           }
 
 #endif /* SIS315H */
 
        }
 
-      } else {     /* ============ For 301 ================ */
+     } else {     /* ============ For 301 ================ */
 
         if(HwInfo->jChipType < SIS_315H) {
+#ifdef SIS300
            if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
              SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08);
              SiS_PanelDelay(SiS_Pr, HwInfo, 3);
           }
+#endif
        }
 
         SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);           /* disable VB */
@@ -4000,12 +4043,14 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
            SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
            SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
        } else {
+#ifdef SIS300
             SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);            /* disable CRT2 */
            if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) ||
                (!(SiS_CR36BIOSWord23d(SiS_Pr,HwInfo))) ) {
                SiS_PanelDelay(SiS_Pr, HwInfo, 2);
                SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04);
            }
+#endif
        }
 
       }
@@ -4064,6 +4109,12 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 
 #ifdef SIS315H /* 315 series */
 
+        if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) {
+          if(HwInfo->jChipType < SIS_340) {
+              SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18);
+          }
+        }
+
        if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
 
           if(HwInfo->jChipType == SIS_740) {
@@ -4194,7 +4245,6 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
   BOOLEAN delaylong = FALSE;
 #endif
 
-
   if(SiS_Pr->SiS_VBType & VB_SISVB) {
 
     if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {   /* ====== For 301B et al  ====== */
@@ -4203,28 +4253,55 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 
 #ifdef SIS300     /* 300 series */
 
-         if(HwInfo->jChipType == SIS_300) {
-
-           if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
-              if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
-                 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
-                 if(!(SiS_CR36BIOSWord23d(SiS_Pr, HwInfo))) {
-                    SiS_PanelDelay(SiS_Pr, HwInfo, 0);
-                 }
+        if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
+           if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+              SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
+           } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
+              SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00);
+           }
+           if(SiS_Pr->SiS_VBType & (VB_SIS301LV302LV | VB_NoLCD)) {
+              if(!(SiS_CR36BIOSWord23d(SiS_Pr, HwInfo))) {
+                 SiS_PanelDelay(SiS_Pr, HwInfo, 0);
               }
            }
+        }
+
+        if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
+           (SiS_CRT2IsLCD(SiS_Pr, HwInfo))) {
+
+           SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);                   /* Enable CRT2 */
+            SiS_DisplayOn(SiS_Pr);
+           SiS_UnLockCRT2(SiS_Pr,HwInfo);
+           SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
+           if(SiS_BridgeInSlavemode(SiS_Pr)) {
+              SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
+           } else {
+              SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
+            }
+           if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
+              if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
+                 if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
+                    SiS_PanelDelay(SiS_Pr, HwInfo, 1);
+                  }
+                 SiS_WaitVBRetrace(SiS_Pr,HwInfo);
+                  SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00);
+               }
+           }
+
+        } else {
+
            temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;             /* lock mode */
-            if(SiS_BridgeInSlave(SiS_Pr)) {
+            if(SiS_BridgeInSlavemode(SiS_Pr)) {
                tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
-               if(!(tempah & SetCRT2ToRAMDAC))  temp |= 0x20;
+               if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
             }
             SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
            SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
            SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20);        /* enable VB processor */
            SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
            SiS_DisplayOn(SiS_Pr);
-           if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
-              if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+           if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+              if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
                  if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
                     if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
                        SiS_PanelDelay(SiS_Pr, HwInfo, 1);
@@ -4234,440 +4311,283 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
               }
            }
 
-        } else {
+        }
 
-           if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
-              (SiS_CRT2IsLCD(SiS_Pr, HwInfo))) {
-              /* This is only for LCD output on 301B-DH via LVDS */
-              SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00);
-              if(!(SiS_CR36BIOSWord23d(SiS_Pr,HwInfo))) {
-                 SiS_PanelDelay(SiS_Pr, HwInfo, 0);
-              }
-              SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);   /* Enable CRT2 */
-               SiS_DisplayOn(SiS_Pr);
-              SiS_UnLockCRT2(SiS_Pr,HwInfo);
-              SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
-              if(SiS_BridgeInSlave(SiS_Pr)) {
-                 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
-              } else {
-                 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
-               }
-              if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
-                  if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
-                      if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
-                          SiS_PanelDelay(SiS_Pr, HwInfo, 1);
-                       }
-                      SiS_WaitVBRetrace(SiS_Pr,HwInfo);
-                       SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00);
-                   }
-              }
-            } else {
-              temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;             /* lock mode */
-               if(SiS_BridgeInSlave(SiS_Pr)) {
-                  tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
-                  if(!(tempah & SetCRT2ToRAMDAC))  temp |= 0x20;
-               }
-               SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
-              SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
-              SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20);        /* enable VB processor */
-              SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
-              SiS_DisplayOn(SiS_Pr);
-           }
 
-         }
 #endif /* SIS300 */
 
       } else {
 
 #ifdef SIS315H    /* 315 series */
 
-        if(IS_SIS550650740660) {               /* 550, 650, 740, 660 */
-
-           UCHAR r30=0, r31=0, r32=0, r33=0, cr36=0;
-
-           if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+#ifdef SET_EMI
+        UCHAR   r30=0, r31=0, r32=0, r33=0, cr36=0;
+        /* USHORT  emidelay=0; */
+#endif
 
-              if((SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) &&
-                 (SiS_Pr->SiS_CustomT != CUT_CLEVO1400)) {
-                 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
+        if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+           SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
 #ifdef SET_EMI
-                 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
-                    SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
-                 }
+           if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
+              SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
+           }
 #endif
-              }
+        }
 
-               if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) {
-                 tempah = 0x10;
-                 if(SiS_LCDAEnabled(SiS_Pr, HwInfo)) {
-                    if(SiS_TVEnabled(SiS_Pr, HwInfo)) tempah = 0x18;
-                    else                              tempah = 0x08;
-                 }
-                 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
+         if(!(SiS_IsNotM650orLater(SiS_Pr, HwInfo))) {
+           if(HwInfo->jChipType < SIS_340) {
+              tempah = 0x10;
+              if(SiS_LCDAEnabled(SiS_Pr, HwInfo)) {
+                 if(SiS_TVEnabled(SiS_Pr, HwInfo)) tempah = 0x18;
+                 else                              tempah = 0x08;
               }
+              SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
+           }
+        }
 
-              if((SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) &&
-                 (SiS_Pr->SiS_CustomT != CUT_CLEVO1400)) {
-                 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
-                 SiS_DisplayOff(SiS_Pr);
-                 pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
-                 if(IS_SIS740) {
-                    SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
-                 }
-              }
+        if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
 
-              if( (SiS_IsVAMode(SiS_Pr,HwInfo)) ||
-                  (SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ) {
-                  if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
-                    if((SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) &&
-                       (SiS_Pr->SiS_CustomT != CUT_CLEVO1400)) {
-                       SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 2);
-                       SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
-                       if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
-                          SiS_GenericDelay(SiS_Pr, 0x4500);
-                       }
-                       SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 2);
-                    } else {
-                       SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
-                       SiS_PanelDelay(SiS_Pr, HwInfo, 0);
-                    }
-                 }
-              }
+           SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
+           SiS_DisplayOff(SiS_Pr);
+           pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
+           if(IS_SIS740) {
+              SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
+           }
 
-               if((SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) &&
-                 (SiS_Pr->SiS_CustomT != CUT_CLEVO1400)) {
-                 if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
-                     SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10);
-                    delaylong = TRUE;
+           if(SiS_IsVAorLCD(SiS_Pr, HwInfo)) {
+               if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
+                 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 2);
+                 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
+                 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 2);
+                 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
+                    SiS_GenericDelay(SiS_Pr, 0x4500);
                  }
               }
+           }
 
-           } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
+           if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
+               SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10);
+              delaylong = TRUE;
+           }
 
-              if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) {
-                 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x10);
-              }
+        }
 
-           } else if(SiS_Pr->SiS_VBType & VB_SIS301B302B) {
+        if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
 
-              if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) {
-                 tempah = 0x10;
-                 if(SiS_LCDAEnabled(SiS_Pr, HwInfo)) {
-                    if(SiS_TVEnabled(SiS_Pr, HwInfo)) tempah = 0x18;
-                    else                              tempah = 0x08;
-                 }
-                 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
+            temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
+           if(SiS_BridgeInSlavemode(SiS_Pr)) {
+               tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
+               if(!(tempah & SetCRT2ToRAMDAC)) {
+                 if(!(SiS_LCDAEnabled(SiS_Pr, HwInfo))) temp |= 0x20;
               }
+            }
+            SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
 
-           }
-
-           if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
-               temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
-              if(SiS_BridgeInSlave(SiS_Pr)) {
-                  tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
-                  if(!(tempah & SetCRT2ToRAMDAC)) {
-                    if(!(SiS_LCDAEnabled(SiS_Pr, HwInfo))) temp |= 0x20;
-                 }
-               }
-               SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
+           SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);                   /* enable CRT2 */
 
-              SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);                   /* enable CRT2 */
+           SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
+           SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
 
-              if((SiS_Pr->SiS_VBType & VB_SIS301B302B) ||
-                 (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-                 (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {
-                 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
-                 temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2e);
-                 if(!(temp & 0x80)) {
-                    SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
-                 }
-              } else {
-                 SiS_PanelDelay(SiS_Pr, HwInfo, 2);
-              }
-           } else {
-              SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20);
+           if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+              SiS_PanelDelay(SiS_Pr, HwInfo, 2);
            }
 
-           SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
+        } else {
 
-           if((SiS_Pr->SiS_VBType & VB_SIS301B302B) ||
-              (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-              (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {
-              temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2e);
-              if(!(temp & 0x80)) {
-                 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
-              }
-           }
+           SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20);
 
-           tempah = 0xc0;
-           if(SiS_IsDualEdge(SiS_Pr, HwInfo)) {
-              tempah = 0x80;
-              if(!(SiS_IsVAMode(SiS_Pr, HwInfo))) {
-                 tempah = 0x40;
-               }
-           }
-            SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
+        }
 
-           if((SiS_Pr->SiS_VBType & VB_SIS301B302B) ||
-              (((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
-                (SiS_Pr->SiS_CustomT == CUT_CLEVO1400))     &&
-               (!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))))) {
-               SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
-           }
+        SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
+        SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
 
-           if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+        tempah = 0xc0;
+        if(SiS_IsDualEdge(SiS_Pr, HwInfo)) {
+           tempah = 0x80;
+           if(!(SiS_IsVAMode(SiS_Pr, HwInfo))) tempah = 0x40;
+        }
+         SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
 
-              if((SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) &&
-                 (SiS_Pr->SiS_CustomT != CUT_CLEVO1400)) {
-                 SiS_PanelDelay(SiS_Pr, HwInfo, 2);
-              }
-#ifdef COMPAQ_HACK
-              if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
-                 SiS_PanelDelay(SiS_Pr, HwInfo, 2);
-              }
-#endif
+        if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+
+           SiS_PanelDelay(SiS_Pr, HwInfo, 2);
 
-              SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
+           SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
+           SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
 
-              if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
+           if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
 #ifdef SET_EMI
-                 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
-                    SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
-                 }
+              if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
+                 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
+                 SiS_GenericDelay(SiS_Pr, 0x500);
+              }
 #endif
-                 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
+              SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
+
+              if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
 #ifdef SET_EMI
-                 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
-
-                    cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
-
-                    /*                                              (P4_30|0x40)  */
-                    /* Compal 1400x1050: 0x05, 0x60, 0x00                YES  (1.10.7w;  CR36=69)      */
-                    /* Compal 1400x1050: 0x0d, 0x70, 0x40                YES  (1.10.7x;  CR36=69)      */
-                    /* Acer   1280x1024: 0x12, 0xd0, 0x6b                NO   (1.10.9k;  CR36=73)      */
-                    /* Compaq 1280x1024: 0x0d, 0x70, 0x6b                YES  (1.12.04b; CR36=03)      */
-                    /* Clevo   1024x768: 0x05, 0x60, 0x33                NO   (1.10.8e;  CR36=12, DL!) */
-                    /* Clevo   1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES  (1.10.8y;  CR36=?2)      */
-                    /* Clevo   1024x768: 0x05, 0x60, 0x33 (if type != 3) YES  (1.10.8y;  CR36=?2)      */
-                    /* Asus    1024x768: ?                                ?   (1.10.8o;  CR36=?2)      */
-                    /* Asus    1024x768: 0x08, 0x10, 0x3c (problematic)  YES  (1.10.8q;  CR36=22)      */
-
-                    if(SiS_Pr->HaveEMI) {
-                       r30 = SiS_Pr->EMI_30;
-                       r31 = SiS_Pr->EMI_31;
-                       r32 = SiS_Pr->EMI_32;
-                       r33 = SiS_Pr->EMI_33;
-                    } else {
-                       r30 = 0;
+                 cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
+
+                 if(SiS_Pr->SiS_ROMNew) {
+                    UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
+                    USHORT romptr = GetLCDStructPtr661_2(SiS_Pr, HwInfo);
+                    if(romptr) {
+                       SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
+                       SiS_Pr->EMI_30 = 0;
+                       SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0];
+                       SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1];
+                       SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2];
+                       if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40;
+                       /* emidelay = SISGETROMW((romptr + 0x22)); */
+                       SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = TRUE;
                     }
+                 }
 
-                    /* EMI_30 is read at driver start; however, the BIOS sets this
-                     * (if it is used) only if the LCD is in use. In case we caught
-                     * the machine while on TV output, this bit is not set and we
-                     * don't know if it should be set - hence our detection is wrong.
-                     * Work-around this here:
-                     */
-
-                    if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) {
-                       if((cr36 & 0x0f) == 0x02) {                     /* 1024x768 */
-                          r30 |= 0x40;
-                          if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
-                             r30 &= ~0x40;
-                          }
-                       } else if((cr36 & 0x0f) == 0x03) {              /* 1280x1024 */
-                          r30 |= 0x40;
-                          if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
-                             r30 &= ~0x40;
-                          }
-                       } else if((cr36 & 0x0f) == 0x09) {              /* 1400x1050 */
-                          r30 |= 0x40;
-                       } else if((cr36 & 0x0f) == 0x0b) {              /* 1600x1200 - unknown */
-                          r30 |= 0x40;
-                       }
-                     }
+                 /*                                              (P4_30|0x40)  */
+                 /* Compal 1400x1050: 0x05, 0x60, 0x00                YES  (1.10.7w;  CR36=69)      */
+                 /* Compal 1400x1050: 0x0d, 0x70, 0x40                YES  (1.10.7x;  CR36=69)      */
+                 /* Acer   1280x1024: 0x12, 0xd0, 0x6b                NO   (1.10.9k;  CR36=73)      */
+                 /* Compaq 1280x1024: 0x0d, 0x70, 0x6b                YES  (1.12.04b; CR36=03)      */
+                 /* Clevo   1024x768: 0x05, 0x60, 0x33                NO   (1.10.8e;  CR36=12, DL!) */
+                 /* Clevo   1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES  (1.10.8y;  CR36=?2)      */
+                 /* Clevo   1024x768: 0x05, 0x60, 0x33 (if type != 3) YES  (1.10.8y;  CR36=?2)      */
+                 /* Asus    1024x768: ?                                ?   (1.10.8o;  CR36=?2)      */
+                 /* Asus    1024x768: 0x08, 0x10, 0x3c (problematic)  YES  (1.10.8q;  CR36=22)      */
+
+                 if(SiS_Pr->HaveEMI) {
+                    r30 = SiS_Pr->EMI_30; r31 = SiS_Pr->EMI_31;
+                    r32 = SiS_Pr->EMI_32; r33 = SiS_Pr->EMI_33;
+                 } else {
+                    r30 = 0;
+                 }
 
-                    if(!SiS_Pr->HaveEMI) {
-                       if((cr36 & 0x0f) == 0x02) {
+                 /* EMI_30 is read at driver start; however, the BIOS sets this
+                  * (if it is used) only if the LCD is in use. In case we caught
+                  * the machine while on TV output, this bit is not set and we
+                  * don't know if it should be set - hence our detection is wrong.
+                  * Work-around this here:
+                  */
+
+                 if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) {
+                    switch((cr36 & 0x0f)) {
+                    case 2:
+                       r30 |= 0x40;
+                       if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) r30 &= ~0x40;
+                       if(!SiS_Pr->HaveEMI) {
+                          r31 = 0x05; r32 = 0x60; r33 = 0x33;
                           if((cr36 & 0xf0) == 0x30) {
                              r31 = 0x0d; r32 = 0x70; r33 = 0x40;
-                          } else {
-                             r31 = 0x05; r32 = 0x60; r33 = 0x33;
                           }
-                       } else if((cr36 & 0x0f) == 0x03) {
+                       }
+                       break;
+                    case 3:  /* 1280x1024 */
+                       if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) r30 |= 0x40;
+                       if(!SiS_Pr->HaveEMI) {
+                          r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
                           if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
                              r31 = 0x0d; r32 = 0x70; r33 = 0x6b;
-                          } else {
-                             r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
                           }
-                       } else if((cr36 & 0x0f) == 0x09) {
+                       }
+                       break;
+                    case 9:  /* 1400x1050 */
+                       r30 |= 0x40;
+                       if(!SiS_Pr->HaveEMI) {
+                          r31 = 0x05; r32 = 0x60; r33 = 0x00;
                           if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
                              r31 = 0x0d; r32 = 0x70; r33 = 0x40;  /* BIOS values */
-                          } else {
-                             r31 = 0x05; r32 = 0x60; r33 = 0x00;
                           }
-                       } else {
+                       }
+                       break;
+                    case 11: /* 1600x1200 - unknown */
+                       r30 |= 0x40;
+                       if(!SiS_Pr->HaveEMI) {
                           r31 = 0x05; r32 = 0x60; r33 = 0x00;
                        }
                     }
+                  }
 
-                    /* BIOS values don't work so well sometimes */
-                    if(!SiS_Pr->OverruleEMI) {
+                 /* BIOS values don't work so well sometimes */
+                 if(!SiS_Pr->OverruleEMI) {
 #ifdef COMPAL_HACK
-                       if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
-                          if((cr36 & 0x0f) == 0x09) {
-                             r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
-                          }
-                       }
+                    if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
+                       if((cr36 & 0x0f) == 0x09) {
+                          r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
+                       }
+                    }
 #endif
 #ifdef COMPAQ_HACK
-                       if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
-                          if((cr36 & 0x0f) == 0x03) {
-                             r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;     /* rev 1 */
-                          }
+                    if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
+                       if((cr36 & 0x0f) == 0x03) {
+                          r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
                        }
+                    }
 #endif
 #ifdef ASUS_HACK
-                       if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
-                          if((cr36 & 0x0f) == 0x02) {
-                             /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33;  */   /* rev 2 */
-                             /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33;  */   /* rev 3 */
-                             /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40;  */   /* rev 4 */
-                             /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40;  */   /* rev 5 */
-                          }
+                    if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
+                       if((cr36 & 0x0f) == 0x02) {
+                          /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33;  */   /* rev 2 */
+                          /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33;  */   /* rev 3 */
+                          /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40;  */   /* rev 4 */
+                          /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40;  */   /* rev 5 */
                        }
-#endif
-                    }
-                    if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
-                       SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20);
-                    }
-                    SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
-                    SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
-                    SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33);
-                    if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
-                       SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
-                    } else {
-                       SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x00);
                     }
-                    if( (SiS_IsVAMode(SiS_Pr,HwInfo)) ||
-                        (SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ) {
-                       if(r30 & 0x40) {
-                          SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 5);
-                          if(delaylong) {
-                             SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 5);
-                             delaylong = FALSE;
-                          }
-                          SiS_WaitVBRetrace(SiS_Pr,HwInfo);
-                          if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
-                             SiS_GenericDelay(SiS_Pr, 0x500);
-                          }
-                          SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40);
-                       }
-                    }
-                 }
 #endif
-              }
-
-              if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
-
-                 if( (SiS_IsVAMode(SiS_Pr,HwInfo)) ||
-                     (SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ) {
-                    SiS_DisplayOn(SiS_Pr);
-                    SiS_PanelDelay(SiS_Pr, HwInfo, 1);
-                    SiS_WaitVBRetrace(SiS_Pr, HwInfo);
-                    SiS_PanelDelay(SiS_Pr, HwInfo, 3);
-                    if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
-                       SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
-                    }
-                 }
+                 }
 
-              } else if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
-
-                 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
-                    if( (SiS_IsVAMode(SiS_Pr, HwInfo)) ||
-                        (SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ) {
-                       SiS_DisplayOn(SiS_Pr);
-                       SiS_PanelDelay(SiS_Pr, HwInfo, 1);
-                       SiS_WaitVBRetrace(SiS_Pr,HwInfo);
-                       SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
-                    }
+                 if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
+                    SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
+                    SiS_GenericDelay(SiS_Pr, 0x500);
                  }
+                 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
+                 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
+                 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33);
+#endif /* SET_EMI */
 
-              } else {
+                 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
 
-                 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
-                 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
-                    if( (SiS_IsVAMode(SiS_Pr,HwInfo)) ||
-                        ((SiS_CRT2IsLCD(SiS_Pr, HwInfo))) ) {
-                       SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10);
-                       if(delaylong) {
-                          SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10);
-                       }
-                        SiS_WaitVBRetrace(SiS_Pr,HwInfo);
-                       if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
+#ifdef SET_EMI
+                 if( (SiS_LCDAEnabled(SiS_Pr, HwInfo)) ||
+                     (SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ) {
+                    if(r30 & 0x40) {
+                       SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 5);
+                       if(delaylong) {
+                          SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 5);
+                          delaylong = FALSE;
+                       }
+                       SiS_WaitVBRetrace(SiS_Pr,HwInfo);
+                       if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
                           SiS_GenericDelay(SiS_Pr, 0x500);
                        }
-                       SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
+                       SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40);   /* Enable */
                     }
-                 }
-
-                 SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
-                 SiS_DisplayOn(SiS_Pr);
-                 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff);
-
-                 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
-                    SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
-                 }
-
+                 }
+#endif
               }
-
            }
 
-        } else {                       /* 315, 330 */
-
-           if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
-              temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
-              if(SiS_BridgeInSlave(SiS_Pr)) {
-                  tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
-                  if(!(tempah & SetCRT2ToRAMDAC))  temp |= 0x20;
-               }
-               SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
-
-              SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);                   /* enable CRT2 */
-
-              temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
-               if(!(temp & 0x80))
-                  SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
-            }
-
-           SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
-
-           if(SiS_Is301B(SiS_Pr)) {
-
-              temp=SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
-               if(!(temp & 0x80))
-                  SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
-
-              tempah = 0xc0;
-              if(SiS_IsDualEdge(SiS_Pr,HwInfo)) {
-                 tempah = 0x80;
-                 if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
-                    tempah = 0x40;
-                  }
+           if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
+              if(SiS_IsVAorLCD(SiS_Pr, HwInfo)) {
+                 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10);
+                 if(delaylong) {
+                    SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10);
+                 }
+                  SiS_WaitVBRetrace(SiS_Pr,HwInfo);
+                 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
+                    SiS_GenericDelay(SiS_Pr, 0x500);
+                 }
+                 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
               }
-               SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
-
-              SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
-
-           } else {
+           }
 
-              SiS_VBLongWait(SiS_Pr);
-               SiS_DisplayOn(SiS_Pr);
-              SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7F);
-               SiS_VBLongWait(SiS_Pr);
+           SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
+           SiS_DisplayOn(SiS_Pr);
+           SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff);
 
-           }
+        }
 
-        }   /* 315, 330 */
+        if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
+           SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
+        }
 
 #endif /* SIS315H */
 
@@ -4683,9 +4603,9 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
        }
 
        temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;          /* lock mode */
-       if(SiS_BridgeInSlave(SiS_Pr)) {
+       if(SiS_BridgeInSlavemode(SiS_Pr)) {
           tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
-          if(!(tempah & SetCRT2ToRAMDAC))  temp |= 0x20;
+          if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
        }
        SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
 
@@ -4734,11 +4654,11 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
          }
        }
 
-       SiS_EnableCRT2(SiS_Pr);
+       SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
        SiS_DisplayOn(SiS_Pr);
        SiS_UnLockCRT2(SiS_Pr,HwInfo);
        SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
-       if(SiS_BridgeInSlave(SiS_Pr)) {
+       if(SiS_BridgeInSlavemode(SiS_Pr)) {
          SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
        } else {
          SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
@@ -4770,6 +4690,12 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 
 #ifdef SIS315H    /* 315 series */
 
+       if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) {
+          if(HwInfo->jChipType < SIS_340) {
+             SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18);
+         }
+       }
+
        if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
          if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
             SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00);
@@ -4777,7 +4703,7 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
           }
        }
 
-       SiS_EnableCRT2(SiS_Pr);
+       SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
        SiS_UnLockCRT2(SiS_Pr,HwInfo);
 
        SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
@@ -4868,33 +4794,31 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 /*         SET PART 1 REGISTER GROUP         */
 /*********************************************/
 
-/********** Set CRT2 OFFSET / PITCH **********/
+/* Set CRT2 OFFSET / PITCH */
 static void
-SiS_SetCRT2Offset(SiS_Private *SiS_Pr,USHORT ModeNo,
-                  USHORT ModeIdIndex ,USHORT RefreshRateTableIndex,
-                 PSIS_HW_INFO HwInfo)
+SiS_SetCRT2Offset(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
+                 USHORT RRTI, PSIS_HW_INFO HwInfo)
 {
   USHORT offset;
   UCHAR temp;
 
   if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return;
 
-  offset = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
-                         HwInfo);
+  offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI,HwInfo);
 
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2 ||
-     SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) offset >>= 1;
+  if((SiS_Pr->SiS_LCDResInfo == Panel_640x480_2) ||
+     (SiS_Pr->SiS_LCDResInfo == Panel_640x480_3)) {
+     offset >>= 1;
+  }
 
-  temp = (UCHAR)(offset & 0xFF);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,temp);
-  temp = (UCHAR)(offset >> 8);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF));
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8));
   temp = (UCHAR)(((offset >> 3) & 0xFF) + 1);
   if(offset % 8) temp++;
   SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
 }
 
-/************* Set CRT2 Sync *************/
+/* Set CRT2 sync and PanelLink mode */
 static void
 SiS_SetCRT2Sync(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT RefreshRateTableIndex,
                 PSIS_HW_INFO HwInfo)
@@ -4916,23 +4840,27 @@ SiS_SetCRT2Sync(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT RefreshRateTableIndex
      } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) {
         tempah = SiS_Pr->SiS_LCDInfo;
      } else tempah = infoflag >> 8;
-
      tempah &= 0xC0;
-
      tempah |= 0x20;
      if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
-
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
         if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
            (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
-          tempah |= 0xc0;
+          tempah |= 0xf0;
+        }
+       if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
+            (SiS_Pr->SiS_IF_DEF_DSTN) ||
+            (SiS_Pr->SiS_IF_DEF_TRUMPION) ||
+            (SiS_Pr->SiS_CustomT == CUT_PANEL848) ) {
+           tempah |= 0x30;
         }
      }
-
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
         if(HwInfo->jChipType >= SIS_315H) {
            tempah >>= 3;
+          tempah &= 0x18;
            SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah);
+          /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */
         } else {
            SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0);
         }
@@ -4949,19 +4877,21 @@ SiS_SetCRT2Sync(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT RefreshRateTableIndex
         if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {                  /* 630 - 301B(-DH) */
 
           tempah = infoflag >> 8;
+          tempbl = 0;
            if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
              if(SiS_Pr->SiS_LCDInfo & LCDSync) {
                 tempah = SiS_Pr->SiS_LCDInfo;
+                tempbl = (tempah >> 6) & 0x03;
               }
            }
            tempah &= 0xC0;
-
            tempah |= 0x20;
            if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
-
-          tempah &= 0x3f;
-          tempah |= tempbl;
+          tempah |= 0xc0;
            SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
+          if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
+             SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
+          }
 
         } else {                                                       /* 630 - 301 */
 
@@ -4979,43 +4909,74 @@ SiS_SetCRT2Sync(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT RefreshRateTableIndex
 
 #ifdef SIS315H  /* ------- 315 series ------ */
 
-        if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {                    /* 315 - 30xLV */
+        if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {                    /* 315 - LVDS */
 
-          if(((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
-              (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024)) ||
-             ((SiS_Pr->SiS_CustomT == CUT_CLEVO1400)  &&
-              (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050))) {
+          tempbl = 0;
+          if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
+             (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
              tempah = infoflag >> 8;
+             if(SiS_Pr->SiS_LCDInfo & LCDSync) {
+               tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
+             }
+          } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400)  &&
+                    (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) {
+                     tempah = infoflag >> 8;
+             tempbl = 0x03;
           } else {
               tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
+             tempbl = (tempah >> 6) & 0x03;
+             tempbl |= 0x08;
+             if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04;
           }
           tempah &= 0xC0;
-
            tempah |= 0x20;
            if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
+          if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)   tempah |= 0xc0;
            SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
+          if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
+             if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+                SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
+             }
+          }
 
-        } else {                                                       /* 315 - 301, 301B */
+        } else {                                                       /* 315 - TMDS */
 
-           tempah = infoflag >> 8;
+           tempah = tempbl = infoflag >> 8;
           if(!SiS_Pr->UseCustomMode) {
-             if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-                if(SiS_Pr->SiS_LCDInfo & LCDSync) {
-                   tempah = SiS_Pr->SiS_LCDInfo;
+             tempbl = 0;
+             if((SiS_Pr->SiS_VBType & VB_SIS301C) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
+                if(ModeNo <= 0x13) {
+                   tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
+                }
+             }
+             if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+                if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+                   if(SiS_Pr->SiS_LCDInfo & LCDSync) {
+                      tempah = SiS_Pr->SiS_LCDInfo;
+                      tempbl = (tempah >> 6) & 0x03;
+                   }
                 }
              }
           }
           tempah &= 0xC0;
-
            tempah |= 0x20;
            if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
-
-          if(SiS_Pr->SiS_VBType & VB_NoLCD) {                  /* TEST, imitate BIOS bug */
-             if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-                tempah |= 0xc0;
+          if(SiS_Pr->SiS_VBType & VB_NoLCD) {
+             /* Imitate BIOS bug */
+             if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)  tempah |= 0xc0;
+          }
+          if((SiS_Pr->SiS_VBType & VB_SIS301C) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
+             tempah >>= 3;
+             tempah &= 0x18;
+             SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah);
+          } else {
+              SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
+             if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
+                if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+                   SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
+                }
              }
           }
-           SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
 
         }
 #endif  /* SIS315H */
@@ -5023,7 +4984,7 @@ SiS_SetCRT2Sync(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT RefreshRateTableIndex
    }
 }
 
-/******** Set CRT2 FIFO on 300/630/730 *******/
+/* Set CRT2 FIFO on 300/630/730 */
 #ifdef SIS300
 static void
 SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
@@ -5078,7 +5039,7 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
 
   if(!SiS_Pr->CRT1UsesCustomMode) {
 
-     CRT1ModeNo = SiS_Pr->SiS_CRT1Mode;                                        /* get CRT1 ModeNo */
+     CRT1ModeNo = SiS_Pr->SiS_CRT1Mode;                                 /* get CRT1 ModeNo */
      SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex);
      SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
      SiS_Pr->SiS_SelectCRT2Rate = 0;
@@ -5087,7 +5048,7 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
      if(CRT1ModeNo >= 0x13) {
         index = SiS_Pr->SiS_RefIndex[refreshratetableindex].Ext_CRTVCLK;
         index &= 0x3F;
-        VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;                              /* Get VCLK */
+        VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;                      /* Get VCLK */
 
        colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex);     /* Get colordepth */
         colorth >>= 1;
@@ -5097,9 +5058,9 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
   } else {
 
      CRT1ModeNo = 0xfe;
-     VCLK = SiS_Pr->CSRClock_CRT1;                                             /* Get VCLK */
-     data2 = (SiS_Pr->CModeFlag_CRT1 & ModeInfoFlag) - 2;
-     switch(data2) {                                                           /* Get color depth */
+     VCLK = SiS_Pr->CSRClock_CRT1;                                     /* Get VCLK */
+     data2 = (SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2;
+     switch(data2) {                                                   /* Get color depth */
         case 0 : colorth = 1; break;
         case 1 : colorth = 1; break;
         case 2 : colorth = 2; break;
@@ -5161,7 +5122,7 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
 
     } else if(HwInfo->jChipType == SIS_730) {
 
-#ifndef LINUX_XF86
+#ifdef LINUX_KERNEL
        SiS_SetRegLong(0xcf8,0x80000050);
        eax = SiS_GetRegLong(0xcfc);
 #else
@@ -5171,7 +5132,7 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
        tempal &= 0x06;
        tempal <<= 5;
 
-#ifndef LINUX_XF86
+#ifdef LINUX_KERNEL
        SiS_SetRegLong(0xcf8,0x800000A0);
        eax = SiS_GetRegLong(0xcfc);
 #else
@@ -5201,7 +5162,7 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
        temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
        if(temp & 0x0080) index += 12;
 
-#ifndef LINUX_XF86
+#ifdef LINUX_KERNEL
        SiS_SetRegLong(0xcf8,0x800000A0);
        eax = SiS_GetRegLong(0xcfc);
 #else
@@ -5214,7 +5175,7 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
        temp = (USHORT)(eax >> 24);
        if(!(temp&0x01)) index += 24;
 
-#ifndef LINUX_XF86
+#ifdef LINUX_KERNEL
        SiS_SetRegLong(0xcf8,0x80000050);
        eax = SiS_GetRegLong(0xcfc);
 #else
@@ -5246,10 +5207,10 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
 
        index = SiS_GetVCLK2Ptr(SiS_Pr,CRT2ModeNo,modeidindex,
                                refreshratetableindex,HwInfo);
-       VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;                               /* Get VCLK  */
+       VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;                /* Get VCLK  */
 
        if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
-          if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+          if(SiS_Pr->SiS_UseROM) {
             if(ROMAddr[0x220] & 0x01) {
                 VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
             }
@@ -5259,11 +5220,11 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
     } else {
 
        CRT2ModeNo = 0xfe;
-       VCLK = SiS_Pr->CSRClock;                                                        /* Get VCLK */
+       VCLK = SiS_Pr->CSRClock;                                        /* Get VCLK */
 
     }
 
-    colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex);        /* Get colordepth */
+    colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex); /* Get colordepth */
     colorth >>= 1;
     if(!colorth) colorth++;
 
@@ -5282,8 +5243,8 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
     if(HwInfo->jChipType == SIS_300) {
        if(data <= 0x0f) temp = (temp & (~0x1F)) | 0x13;
        else             temp = (temp & (~0x1F)) | 0x16;
-       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-                       temp = (temp & (~0x1F)) | 0x13;
+       if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
+                 temp = (temp & (~0x1F)) | 0x13;
        }
     } else {
        if( ( (HwInfo->jChipType == SIS_630) ||
@@ -5313,316 +5274,71 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
 }
 #endif
 
-/**** Set CRT2 FIFO on 315/330 series ****/
+/* Set CRT2 FIFO on 315/330 series */
 #ifdef SIS315H
 static void
-SiS_SetCRT2FIFO_310(SiS_Private *SiS_Pr)
+SiS_SetCRT2FIFO_310(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
   SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B);
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3F,0x04);
+  if( (HwInfo->jChipType == SIS_760)      &&
+      (SiS_Pr->SiS_SysFlags & SF_760LFB)  &&
+      (SiS_Pr->SiS_ModeType == Mode32Bpp) &&
+      (SiS_Pr->SiS_VGAHDE >= 1280)       &&
+      (SiS_Pr->SiS_VGAVDE >= 1024) ) {
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x03);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3b);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x01);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,0x6e);
+  } else {
+     SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3f,0x04);
+  }
+
 }
 #endif
 
-/*************** Set LCD-A ***************/
-#ifdef SIS315H
-static void
-SiS_SetGroup1_LCDA(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
-                   PSIS_HW_INFO HwInfo, USHORT RefreshRateTableIndex)
+static USHORT
+SiS_GetVGAHT2(SiS_Private *SiS_Pr)
 {
-  USHORT modeflag,resinfo;
-  USHORT push2,tempax,tempbx,tempcx,temp;
-  ULONG tempeax=0,tempebx,tempecx,tempvcfact;
+  ULONG tempax,tempbx;
 
-  /* This is not supported with LCDA */
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom) return;
-  if(SiS_Pr->UseCustomMode) return;
+  tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX;
+  tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
+  tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
+  return((USHORT)tempax);
+}
 
-  if(IS_SIS330) {
-     SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);                    /* Xabre 1.01.03 */
-  } else if(IS_SIS740) {
-     if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {                                        /* 740/LVDS */
-        SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);         /* 740/LVDS */
-       SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03);
-     } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
-        SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);                 /* 740/301LV, 301BDH */
-     }
-  } else {
-     if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {                                        /* 650/LVDS */
-        SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);         /* 650/LVDS */
-       SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);                  /* 650/LVDS 1.10.07 */
-     } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
-        SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);                        /* 650/30xLv 1.10.6s */
-     }
-  }
+/* Set Part 1 / SiS bridge slave mode */
+static void
+SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
+                  PSIS_HW_INFO HwInfo,USHORT RefreshRateTableIndex)
+{
+  USHORT  push1,push2;
+  USHORT  tempax,tempbx,tempcx,temp;
+  USHORT  resinfo,modeflag,xres=0;
+  unsigned char p1_7, p1_8;
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
      resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
+  } else if(SiS_Pr->UseCustomMode) {
+     modeflag = SiS_Pr->CModeFlag;
+     resinfo = 0;
+     xres = SiS_Pr->CHDisplay;
   } else {
      modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
      resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
+     xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes;
   }
 
-  tempax = SiS_Pr->SiS_LCDHDES;
+  /* The following is only done if bridge is in slave mode: */
 
-  temp = (tempax & 0x0007);                                    /* BPLHDESKEW[2:0]   */
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp);                         /* Part1_1Ah  */
-  temp = (tempax >> 3) & 0x00FF;                                       /* BPLHDESKEW[10:3]  */
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp);                         /* Part1_16h  */
-
-  tempbx = SiS_Pr->SiS_HDE;
-  if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-     tempbx = SiS_Pr->PanelXRes;
-  }
-
-  tempax += tempbx;                                            /* HDE + HSKEW = lcdhdee  */
-  if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
-
-  temp = tempax;
-  if(SiS_Pr->SiS_VBType & VB_SISVB) {
-     if(temp & 0x07) temp += 8;
-  }
-  temp >>= 3;                                                  /* BPLHDEE  */
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp);                         /* Part1_17h  */
-
-  tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2;                             /* (HT-HDE) / 4  */
-
-  /* 650/30xLV 1.10.6s, 740/LVDS */
-  if( ((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) ||
-      ((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ) {
-     if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600)        tempcx = 0x28;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)  tempcx = 0x18;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempcx = 0x30;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempcx = 0x40;
-       else                                                          tempcx = 0x30;
-     }
-  }
-
-  tempcx += tempax;                                            /* lcdhrs  */
-  if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
-
-  temp = (tempcx >> 3) & 0x00FF;                               /* BPLHRS */
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp);                                 /* Part1_14h  */
-
-  temp += 10;
-  if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-        if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-          temp += 6;
-          if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel800x600) {
-             temp++;
-             if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1024x768) {
-                temp += 7;
-                if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1600x1200) {
-                   temp -= 10;
-                }
-             }
-          }
-       }
-     }
-  }
-  temp &= 0x1F;
-  temp |= ((tempcx & 0x07) << 5);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp);                         /* Part1_15h  */
-
-  if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
-     tempax = SiS_Pr->PanelYRes;
-  } else {
-     tempax = SiS_Pr->SiS_VGAVDE;
-  }
-
-  tempbx = SiS_Pr->SiS_LCDVDES + tempax;
-  if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
-  push2 = tempbx;
-
-  tempcx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 2;
-
-  if( ((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) ||
-      ((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ) {
-     if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600)         tempcx = 1;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)   tempcx = 3;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768)   tempcx = 3;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024)  tempcx = 1;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050)  tempcx = 1;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)  tempcx = 1;
-       else                                                           tempcx = 0x0057;
-     }
-  }
-
-  tempbx += tempcx;
-  if(SiS_Pr->SiS_VBType & VB_SISVB) {
-     tempbx++;                                                 /* BPLVRS  */
-  }
-  if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
-  temp = tempbx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);                             /* Part1_18h  */
-
-  tempcx >>= 3;
-  if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-        if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-          if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600)         tempcx = 3;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)   tempcx = 5;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768)   tempcx = 5;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024)  tempcx = 5;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050)  tempcx = 2;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)  tempcx = 2;
-       }
-     }
-  }
-  tempcx += tempbx;
-  tempcx++;                                                    /* BPLVRE  */
-  temp = tempcx & 0x000F;
-  if(SiS_Pr->SiS_VBType & VB_SISVB) {
-     temp |= 0xC0;
-     SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp);            /* Part1_19h  */
-  } else {
-     SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp);
-  }
-
-  temp = ((tempbx >> 8) & 0x07) << 3;
-  if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
-  if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA)   temp |= 0x40;
-  if(SiS_Pr->SiS_VBType & VB_SISVB) {
-     /* Don't check Part1Port,0x00 -> is not being set if LCDA! */
-     /* We check SR06 instead here: */
-     if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
-        if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80;
-     }
-  } else {
-     if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
-        if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80;
-     }
-  }
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,0x07,temp);            /* Part1_1Ah */
-
-  tempbx = push2;                                                      /* BPLVDEE */
-
-  tempcx = SiS_Pr->SiS_LCDVDES;                                        /* NPLVDES */
-  if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) {
-        if(resinfo == SIS_RI_800x600) tempcx++;
-     }
-  }
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) {
-     tempbx = tempcx = SiS_Pr->SiS_VGAVDE;
-     tempbx--;
-  }
-
-  temp = ((tempbx >> 8) & 0x07) << 3;
-  temp = temp | ((tempcx >> 8) & 0x07);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);                          /* Part1_1Dh */
-  temp = tempbx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,temp);                          /* Part1_1Ch  */
-  temp = tempcx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,temp);                          /* Part1_1Bh  */
-
-  tempeax = SiS_Pr->SiS_VGAVDE << 18;
-  tempebx = SiS_Pr->SiS_VDE;
-  temp = (USHORT)(tempeax % tempebx);
-  tempeax = tempeax / tempebx;
-  if(temp) tempeax++;
-  tempvcfact = tempeax;
-
-  temp = (USHORT)(tempeax & 0x00FF);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
-
-  temp = (USHORT)((tempeax & 0x00FF00) >> 8);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
-
-  temp = (USHORT)((tempeax & 0x00030000) >> 16);
-  if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
-
-  if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) {
-     temp = (USHORT)(tempeax & 0x00FF);
-     SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
-     temp = (USHORT)((tempeax & 0x00FF00) >> 8);
-     SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
-     temp = (USHORT)(((tempeax & 0x00030000) >> 16) << 6);
-     SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
-     temp = 0;
-     if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
-     SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp);
-  }
-
-  tempeax = SiS_Pr->SiS_VGAHDE << 16;
-  tempebx = SiS_Pr->SiS_HDE;
-  temp = tempeax % tempebx;
-  tempeax /= tempebx;
-  if(temp) tempeax++;
-  if(tempebx == SiS_Pr->SiS_VGAHDE) tempeax = 0xFFFF;
-  tempecx = tempeax;
-  tempeax = ((SiS_Pr->SiS_VGAHDE << 16) / tempecx) - 1;
-  tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
-  temp = (USHORT)(tempecx & 0x00FF);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);                          /* Part1_1Fh  */
-
-  tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
-  tempbx = (USHORT)(tempeax & 0x0FFFF);
-
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempbx--;
-
-  if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA)  tempbx = 1;
-
-  temp = ((tempbx >> 8) & 0x07) << 3;
-  temp = temp | ((tempecx >> 8) & 0x07);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);                         /* Part1_20h */
-
-  temp = tempbx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,temp);                         /* Part1_21h */
-
-  tempecx >>= 16;                                              /* BPLHCFACT  */
-  if(modeflag & HalfDCLK) tempecx >>= 1;
-  temp = (USHORT)((tempecx & 0x0000FF00) >> 8);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);                         /* Part1_22h */
-
-  temp = (USHORT)(tempecx & 0x000000FF);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
-
-  if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBInfo & VB_SIS301LV302LV)) {
-     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
-  }
-}
-#endif  /* SIS 315 */
-
-static USHORT
-SiS_GetVGAHT2(SiS_Private *SiS_Pr)
-{
-  ULONG tempax,tempbx;
-
-  tempbx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX) & 0xFFFF;
-  tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
-  tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
-  return((USHORT) tempax);
-}
-
-/******* Set Part 1 / SiS bridge *********/
-static void
-SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
-                  PSIS_HW_INFO HwInfo,USHORT RefreshRateTableIndex)
-{
-  USHORT  push1,push2;
-  USHORT  tempax,tempbx,tempcx,temp;
-  USHORT  resinfo,modeflag;
-  unsigned char p1_7, p1_8;
-
-  if(ModeNo <= 0x13) {
-     modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-     resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
-  } else {
-     if(SiS_Pr->UseCustomMode) {
-        modeflag = SiS_Pr->CModeFlag;
-       resinfo = 0;
-     } else {
-       modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-       resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
-     }
-  }
-
-  /* The following is only done if bridge is in slave mode: */
+  if((HwInfo->jChipType >= SIS_661) && (ModeNo > 0x13)) {
+     if(xres >= 1600) {
+        SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04);
+     }
+  }
 
   SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0xff);                  /* set MAX HT */
 
@@ -5684,21 +5400,20 @@ SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
      } else {
         if(!(modeflag & HalfDCLK)) {
            temp -= 4;
-           if((SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x960) &&
-             (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1600x1200)) {
+           if((SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
+             (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200)) {
               if(SiS_Pr->SiS_VGAHDE >= 800) {
                  temp -= 7;
                 if(HwInfo->jChipType < SIS_315H) {
-                   /* 650/301LV(x) does not do this, 630/301B, 300/301LV do */
                     if(SiS_Pr->SiS_ModeType == ModeEGA) {
                        if(SiS_Pr->SiS_VGAVDE == 1024) {
                           temp += 15;
-                          if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024)
+                          if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024)
                             temp += 7;
                        }
                     }
                 }
-                if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1400x1050) {
+                if(SiS_Pr->SiS_LCDResInfo != Panel_1400x1050) {
                     if(SiS_Pr->SiS_VGAHDE >= 1280) {
                        if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) temp += 28;
                    }
@@ -5762,6 +5477,10 @@ SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
              p1_7 = 0xab;
           }
        }
+     } else {
+        if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
+          if(modeflag & HalfDCLK) p1_7 = 0x30;
+       }
      }
   }
 
@@ -5784,7 +5503,7 @@ SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
   else if(tempbx == 525) tempbx = 480;
   push2 = tempbx;
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
        if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
            if     (tempbx == 350) tempbx += 5;
            else if(tempbx == 480) tempbx += 5;
@@ -5830,7 +5549,7 @@ SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
        tempbx += (tempax << 1);
      }
   } else if(HwInfo->jChipType >= SIS_315H) {
-     if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1400x1050) {
+     if(SiS_Pr->SiS_LCDResInfo != Panel_1400x1050) {
        tempbx += (tempax << 1);
      }
   }
@@ -5907,521 +5626,464 @@ SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
      }
   }
   SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp);                 /* 0x1A SR0E */
+
+  temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp);
 }
 
-/*********** Set Part 1 / LVDS ***********/
+/* Setup panel link
+ * This is used for LVDS, LCDA and Chrontel TV output
+ * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA
+ */
 static void
 SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
-                  PSIS_HW_INFO HwInfo, USHORT RefreshRateTableIndex)
+                   PSIS_HW_INFO HwInfo, USHORT RefreshRateTableIndex)
 {
-  USHORT modeflag, resinfo;
-  USHORT push1, push2, tempax, tempbx, tempcx, temp;
+  USHORT modeflag,resinfo;
+  USHORT push2,tempax,tempbx,tempcx,temp;
+  ULONG tempeax=0,tempebx,tempecx,tempvcfact=0;
+  BOOLEAN islvds = FALSE, issis  = FALSE, chkdclkfirst = FALSE;
+#ifdef SIS300
+  USHORT crt2crtc;
+#endif
 #ifdef SIS315H
   USHORT pushcx;
 #endif
-  ULONG  tempeax=0, tempebx, tempecx, tempvcfact=0;
-
-  /* This is not supported on LVDS */
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom) return;
-  if(SiS_Pr->UseCustomMode) return;
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
      resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
+#ifdef SIS300
+     crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+#endif
+  } else if(SiS_Pr->UseCustomMode) {
+     modeflag = SiS_Pr->CModeFlag;
+     resinfo = 0;
+#ifdef SIS300
+     crt2crtc = 0;
+#endif
   } else {
      modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
      resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
+#ifdef SIS300
+     crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+#endif
   }
 
-  /* Set up Panel Link */
-
-  /* 1. Horizontal setup */
-
-  tempax = SiS_Pr->SiS_LCDHDES;
-
-  if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
-     if( (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) &&
-         (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
-          tempax -= 8;
-     }
+  /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */
+  if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
+     islvds = TRUE;
   }
 
-  tempcx = SiS_Pr->SiS_HT;                               /* Horiz. Total */
-
-  tempbx = SiS_Pr->SiS_HDE;                               /* Horiz. Display End */
+  /* is really sis if sis bridge, but not 301B-DH */
+  if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
+     issis = TRUE;
+  }
 
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2 ||
-     SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) {
-     tempbx >>= 1;
+  if((HwInfo->jChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
+     if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
+        chkdclkfirst = TRUE;
+     }
   }
 
-  if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
-     if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-        if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
-          tempbx = SiS_Pr->PanelXRes;
-       } else if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-          tempbx = SiS_Pr->PanelXRes;
-          if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
-             tempbx = 800;
-             if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel800x600) {
-                tempbx = 1024;
+#ifdef SIS315H
+  if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
+     if(IS_SIS330) {
+        SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
+     } else if(IS_SIS740) {
+        if(islvds) {
+           SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
+          SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03);
+        } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
+           SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
+        }
+     } else {
+        if(islvds) {
+           SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
+          SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);
+        } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
+           SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);
+          if(SiS_Pr->SiS_VBType & VB_SIS301C) {
+             if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) ||
+                (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
+                SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20);
              }
           }
         }
      }
   }
-  tempcx = (tempcx - tempbx) >> 2;              /* HT-HDE / 4 */
-
-  push1 = tempax;
-
-  tempax += tempbx;
-
-  if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
+#endif
 
-  push2 = tempax;
+  /* Horizontal */
 
-  if((!SiS_Pr->SiS_IF_DEF_FSTN) &&
-     (!SiS_Pr->SiS_IF_DEF_DSTN) &&
-     (SiS_Pr->SiS_CustomT != CUT_BARCO1366) &&
-     (SiS_Pr->SiS_CustomT != CUT_BARCO1024) &&
-     (SiS_Pr->SiS_CustomT != CUT_PANEL848)) {
-     if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
-        if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-           if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-             if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600)        tempcx = 0x0028;
-             else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600)  tempcx = 0x0018;
-             else if( (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) ||
-                   (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) ) {
-                  if(HwInfo->jChipType < SIS_315H) {
-                     if(SiS_Pr->SiS_VBType & VB_SISVB) {
-                        tempcx = 0x0017;  /* A901; sometimes 0x0018; */
-                     } else {
-                        tempcx = 0x0017;
-#ifdef TWNEWPANEL
-                        tempcx = 0x0018;
-#endif
-                     }
-                  } else {
-                     tempcx = 0x0018;
-                  }
-             }
-             else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768)  tempcx = 0x0028;
-             else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) tempcx = 0x0030;
-             else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempcx = 0x0030;
-             else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempcx = 0x0040;
+  tempax = SiS_Pr->SiS_LCDHDES;
+  if(islvds) {
+     if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+        if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
+           if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) &&
+              (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
+             tempax -= 8;
           }
-        }
+       }
      }
   }
 
-  tempcx += tempax;                              /* lcdhrs  */
-  if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
-
-  tempax = tempcx >> 3;                          /* BPLHRS */
-  temp = tempax & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp);          /* Part1_14h; Panel Link Horizontal Retrace Start  */
+  temp = (tempax & 0x0007);
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp);                 /* BPLHDESKEW[2:0]   */
+  temp = (tempax >> 3) & 0x00FF;
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp);                 /* BPLHDESKEW[10:3]  */
 
-  if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
-     temp = (tempax & 0x00FF) + 2;
-  } else {
-     temp = (tempax & 0x00FF) + 10;
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-        if((!SiS_Pr->SiS_IF_DEF_DSTN) &&
-          (!SiS_Pr->SiS_IF_DEF_FSTN) &&
-          (SiS_Pr->SiS_CustomT != CUT_BARCO1366) &&
-          (SiS_Pr->SiS_CustomT != CUT_BARCO1024) &&
-          (SiS_Pr->SiS_CustomT != CUT_PANEL848)) {
-           if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-             temp += 6;
-              if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel800x600) {
-                temp++;
-                if(HwInfo->jChipType >= SIS_315H) {
-                   if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1024x768) {
-                      temp += 7;
-                      if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1600x1200) {
-                         temp -= 0x14;
-                         if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x768) {
-                            temp -= 10;
-                         }
-                      }
-                   }
-                }
-             }
-           }
-        }
+  tempbx = SiS_Pr->SiS_HDE;
+  if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+     if((SiS_Pr->SiS_LCDResInfo == Panel_640x480_2) ||
+        (SiS_Pr->SiS_LCDResInfo == Panel_640x480_3)) {
+        tempbx >>= 1;
+     }
+     if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+        tempbx = SiS_Pr->PanelXRes;
      }
   }
 
-  temp &= 0x1F;
-  temp |= ((tempcx & 0x0007) << 5);
-#if 0
-  if(SiS_Pr->SiS_IF_DEF_FSTN) temp = 0x20;       /* WRONG? BIOS loads cl, not ah */
-#endif
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp);          /* Part1_15h; Panel Link Horizontal Retrace End/Skew */
-
-  tempbx = push2;
-  tempcx = push1;                                /* lcdhdes  */
+  tempax += tempbx;
+  if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
 
-  temp = (tempcx & 0x0007);                      /* BPLHDESKEW  */
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp);          /* Part1_1Ah; Panel Link Vertical Retrace Start (2:0) */
+  temp = tempax;
+  if(temp & 0x07) temp += 8;
+  temp >>= 3;
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp);                 /* BPLHDEE  */
 
-  tempcx >>= 3;                                  /* BPLHDES */
-  temp = (tempcx & 0x00FF);
-#if 0 /* Not 550 FSTN */
-  if(HwInfo->jChipType >= SIS_315H) {
-     if(ModeNo == 0x5b) temp--; */
-  }
-#endif
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp);          /* Part1_16h; Panel Link Horizontal Display Enable Start  */
+  tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2;
 
-  if((HwInfo->jChipType < SIS_315H) ||
-     (SiS_Pr->SiS_IF_DEF_FSTN) ||
-     (SiS_Pr->SiS_IF_DEF_DSTN)) {
-     if(tempbx & 0x07) tempbx += 8;
-  }
-  tempbx >>= 3;                                  /* BPLHDEE  */
-  temp = tempbx & 0x00FF;
-#if 0 /* Not 550 FSTN */
-  if(HwInfo->jChipType >= SIS_315H) {
-     if(ModeNo == 0x5b) temp--;
+  if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+     if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+        if(SiS_Pr->PanelHRS != 999) tempcx = SiS_Pr->PanelHRS;
+     }
   }
-#endif
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp);          /* Part1_17h; Panel Link Horizontal Display Enable End  */
 
-  /* 2. Vertical setup */
+  tempcx += tempax;
+  if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
 
-  if(HwInfo->jChipType < SIS_315H) {
-     tempcx = SiS_Pr->SiS_VGAVT;
-     tempbx = SiS_Pr->SiS_VGAVDE;
-     if((SiS_Pr->SiS_CustomT != CUT_BARCO1366) && (SiS_Pr->SiS_CustomT != CUT_BARCO1024)) {
-        if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-           if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-             tempbx = SiS_Pr->PanelYRes;
+  temp = (tempcx >> 3) & 0x00FF;
+  if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+     if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
+        if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
+           switch(ModeNo) {
+           case 0x04:
+           case 0x05:
+           case 0x0d: temp = 0x56; break;
+           case 0x10: temp = 0x60; break;
+           case 0x13: temp = 0x5f; break;
+           case 0x40:
+           case 0x41:
+           case 0x4f:
+           case 0x43:
+           case 0x44:
+           case 0x62:
+           case 0x56:
+           case 0x53:
+           case 0x5d:
+           case 0x5e: temp = 0x54; break;
            }
-       }
+        }
      }
-     tempcx -= tempbx;
+  }
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp);                 /* BPLHRS */
 
+  if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+     temp += 2;
+     if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+        temp += 8;
+        if(SiS_Pr->PanelHRE != 999) {
+           temp = tempcx + SiS_Pr->PanelHRE;
+          if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT;
+          temp >>= 3;
+        }
+     }
   } else {
-
-     tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;           /* VGAVT-VGAVDE  */
-
+     temp += 10;
   }
 
-  tempbx = SiS_Pr->SiS_LCDVDES;                                        /* VGAVDES  */
-  push1 = tempbx;
+  temp &= 0x1F;
+  temp |= ((tempcx & 0x07) << 5);
+#if 0
+  if(SiS_Pr->SiS_IF_DEF_FSTN) temp = 0x20;                     /* WRONG? BIOS loads cl, not ah */
+#endif
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp);                 /* BPLHRE */
+
+  /* Vertical */
 
   tempax = SiS_Pr->SiS_VGAVDE;
-
-  if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-     if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
-        if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-           tempax = 600;
-          if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel800x600) {
-             tempax = 768;
-          }
-       }
-     } else if( (SiS_Pr->SiS_IF_DEF_TRUMPION == 0)   &&
-                (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) &&
-                ((SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) ||
-                (SiS_Pr->SiS_IF_DEF_FSTN) ||
-                (SiS_Pr->SiS_IF_DEF_DSTN)) ) {
+  if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+     if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
        tempax = SiS_Pr->PanelYRes;
      }
   }
 
-  tempbx += tempax;
+  tempbx = SiS_Pr->SiS_LCDVDES + tempax;
   if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
 
   push2 = tempbx;
 
-  tempcx >>= 1;
-
-  if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
-     (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) &&
-     (SiS_Pr->SiS_CustomT != CUT_BARCO1366) &&
-     (SiS_Pr->SiS_CustomT != CUT_BARCO1024) &&
-     (SiS_Pr->SiS_CustomT != CUT_PANEL848)) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2 ||
-        SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) {
-       tempcx = 0x0017;
-     } else if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
-        if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
-          if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600)         tempcx = 0x0003;
-          else if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) ||
-                  (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768)) tempcx = 0x0003;
-           else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024)  tempcx = 0x0001;
-           else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050)  tempcx = 0x0001;
-          else                                                           tempcx = 0x0057;
-        } else  {
-          if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600)         tempcx = 0x0001;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600)   tempcx = 0x0001;
-          else if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) ||
-                  (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768)) {
-                  if(HwInfo->jChipType < SIS_315H) {
-                     if(SiS_Pr->SiS_VBType & VB_SISVB) {
-                        tempcx = 0x0002;   /* A901; sometimes 0x0003; */
-                     } else {
-                        tempcx = 0x0002;
-#ifdef TWNEWPANEL
-                        tempcx = 0x0003;
-#endif
-                     }
-                  } else tempcx = 0x0003;
-           }
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768)  tempcx = 0x0003;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) tempcx = 0x0001;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempcx = 0x0001;
-          else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempcx = 0x0001;
-          else                                                          tempcx = 0x0057;
+  tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;
+  if(HwInfo->jChipType < SIS_315H) {
+     if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+        if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+          tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes;
        }
      }
   }
+  if(islvds) tempcx >>= 1;
+  else       tempcx >>= 2;
 
-  tempbx += tempcx;                            /* BPLVRS  */
-
-  if((HwInfo->jChipType < SIS_315H) ||
-     (SiS_Pr->SiS_IF_DEF_FSTN) ||
-     (SiS_Pr->SiS_IF_DEF_DSTN)) {
-     tempbx++;
+  if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
+      (!(SiS_Pr->SiS_LCDInfo & LCDPass11))                 &&
+      (SiS_Pr->PanelVRS != 999) ) {
+     tempcx = SiS_Pr->PanelVRS;
+     tempbx += tempcx;
+     if(issis) tempbx++;
+  } else {
+     tempbx += tempcx;
+     if(HwInfo->jChipType < SIS_315H) tempbx++;
+     else if(issis)                   tempbx++;
   }
 
-  if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
+  if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;       /* BPLVRS  */
 
   temp = tempbx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);          /* Part1_18h; Panel Link Vertical Retrace Start  */
+  if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
+        if(ModeNo == 0x10) temp = 0xa9;
+     }
+  }
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);
 
   tempcx >>= 3;
+  tempcx++;
 
-  if((!(SiS_Pr->SiS_LCDInfo & LCDPass11)) &&
-     (SiS_Pr->SiS_CustomT != CUT_BARCO1366) &&
-     (SiS_Pr->SiS_CustomT != CUT_BARCO1024) &&
-     (SiS_Pr->SiS_CustomT != CUT_PANEL848)) {
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-        if( (HwInfo->jChipType < SIS_315H) &&
-            (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) )     tempcx = 0x0001;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2)  tempcx = 0x0002;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3)  tempcx = 0x0002;
-        else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600)    tempcx = 0x0003;
-        else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600)   tempcx = 0x0005;
-        else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768)   tempcx = 0x0005;
-       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768)   tempcx = 0x0011;
-        else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024)  tempcx = 0x0005;
-        else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050)  tempcx = 0x0002;
-        else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)  tempcx = 0x0011;
-        else if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480)  {
-               if(HwInfo->jChipType < SIS_315H) {
-                  if(SiS_Pr->SiS_VBType & VB_SISVB) {
-                     tempcx = 0x0004;   /* A901; Other BIOS sets 0x0005; */
-                  } else {
-                     tempcx = 0x0004;
-#ifdef TWNEWPANEL
-                     tempcx = 0x0005;
-#endif
-                  }
-               } else {
-                  tempcx = 0x0005;
-               }
-        }
+  if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+     if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+        if(SiS_Pr->PanelVRE != 999) tempcx = SiS_Pr->PanelVRE;
      }
   }
 
-  tempcx = tempcx + tempbx + 1;                  /* BPLVRE  */
+  tempcx += tempbx;
   temp = tempcx & 0x000F;
-  if(SiS_Pr->SiS_IF_DEF_FSTN ||
-     SiS_Pr->SiS_IF_DEF_DSTN ||
-     (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
-     (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
-     (SiS_Pr->SiS_CustomT == CUT_PANEL848)) {
-     temp |= 0x30;
-  }
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xf0,temp); /* Part1_19h; Panel Link Vertical Retrace End (3:0); Misc.  */
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp);       /* BPLVRE  */
 
-  temp = ((tempbx & 0x0700) >> 8) << 3;          /* BPLDESKEW =0 */
+  temp = ((tempbx >> 8) & 0x07) << 3;
   if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
      if(SiS_Pr->SiS_HDE != 640) {
-        if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE)   temp |= 0x40;
+        if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE)  temp |= 0x40;
+     }
+  } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
+  if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA)          temp |= 0x40;
+  tempbx = 0x87;
+  if((HwInfo->jChipType >= SIS_315H) ||
+     (HwInfo->jChipRevision >= 0x30)) {
+     tempbx = 0x07;
+     if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
+       if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03)    temp |= 0x80;
+     }
+     /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit mutliplexed) via VGA2 */
+     if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
+       if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
+          if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10)      temp |= 0x80;
+       } else {
+          if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80;
+       }
      }
-  } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE)  temp |= 0x40;
-  if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA)           temp |= 0x40;
-  if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
-     if(HwInfo->jChipType >= SIS_315H) {
-        if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
-           temp |= 0x80;
+  }
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp);
+
+  tempbx = push2;                                                      /* BPLVDEE */
+
+  tempcx = SiS_Pr->SiS_LCDVDES;                                        /* BPLVDES */
+
+  if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+     switch(SiS_Pr->SiS_LCDResInfo) {
+     case Panel_640x480:
+        tempbx = SiS_Pr->SiS_VGAVDE - 1;
+        tempcx = SiS_Pr->SiS_VGAVDE;
+       break;
+     case Panel_800x600:
+        if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
+           if(resinfo == SIS_RI_800x600) tempcx++;
         }
-     } else {
-       if( (HwInfo->jChipType == SIS_630) ||
-           (HwInfo->jChipType == SIS_730) ) {
-          if(HwInfo->jChipRevision >= 0x30) {
-             temp |= 0x80;
+       break;
+     case Panel_1024x600:
+        if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
+           if(resinfo == SIS_RI_1024x600) tempcx++;
+           if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+             if(resinfo == SIS_RI_800x600) tempcx++;
           }
-       }
+        }
+       break;
+     case Panel_1024x768:
+        if(HwInfo->jChipType < SIS_315H) {
+           if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
+              if(resinfo == SIS_RI_1024x768) tempcx++;
+          }
+        }
+       break;
      }
   }
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,0x87,temp);  /* Part1_1Ah; Panel Link Control Signal (7:3); Vertical Retrace Start (2:0) */
 
-  if (HwInfo->jChipType < SIS_315H) {
+  temp = ((tempbx >> 8) & 0x07) << 3;
+  temp = temp | ((tempcx >> 8) & 0x07);
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);
+  /* if(SiS_Pr->SiS_IF_DEF_FSTN) tempbx++;  */
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx);
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx);
 
-#ifdef SIS300      /* 300 series */
+  /* Vertical scaling */
 
-        tempeax = SiS_Pr->SiS_VGAVDE << 6;
-        temp = (USHORT)(tempeax % (ULONG)SiS_Pr->SiS_VDE);
-        tempeax = tempeax / (ULONG)SiS_Pr->SiS_VDE;
-        if(temp != 0) tempeax++;
-        tempebx = tempeax;                         /* BPLVCFACT  */
+  if(HwInfo->jChipType < SIS_315H) {
 
-       if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
-          tempebx = 0x003F;
-       }
+#ifdef SIS300      /* 300 series */
+     tempeax = SiS_Pr->SiS_VGAVDE << 6;
+     temp = (tempeax % (ULONG)SiS_Pr->SiS_VDE);
+     tempeax = tempeax / (ULONG)SiS_Pr->SiS_VDE;
+     if(temp) tempeax++;
 
-       temp = (USHORT)(tempebx & 0x00FF);
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp);      /* Part1_1Eh; Panel Link Vertical Scaling Factor */
+     if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F;
 
+     temp = (USHORT)(tempeax & 0x00FF);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp);              /* BPLVCFACT */
+     tempvcfact = temp;
 #endif /* SIS300 */
 
   } else {
 
 #ifdef SIS315H  /* 315 series */
+     tempeax = SiS_Pr->SiS_VGAVDE << 18;
+     tempebx = SiS_Pr->SiS_VDE;
+     temp = (tempeax % tempebx);
+     tempeax = tempeax / tempebx;
+     if(temp) tempeax++;
+     tempvcfact = tempeax;
 
-        if(HwInfo->jChipType == SIS_740) {
-           SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x03);
-        } else {
-          SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,0x23);
-       }
-
-       tempeax = SiS_Pr->SiS_VGAVDE << 18;
-       temp = (USHORT)(tempeax % (ULONG)SiS_Pr->SiS_VDE);
-       tempeax = tempeax / SiS_Pr->SiS_VDE;
-       if(temp != 0) tempeax++;
-       tempebx = tempeax;                         /* BPLVCFACT  */
-        tempvcfact = tempeax;
-       temp = (USHORT)(tempebx & 0x00FF);
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);      /* Part1_37h; Panel Link Vertical Scaling Factor */
-       temp = (USHORT)((tempebx & 0x00FF00) >> 8);
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);      /* Part1_36h; Panel Link Vertical Scaling Factor */
-       temp = (USHORT)((tempebx & 0x00030000) >> 16);
-       temp &= 0x03;
-       if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);      /* Part1_35h; Panel Link Vertical Scaling Factor */
-
-#endif /* SIS315H */
-
-  }
-
-  tempbx = push2;                                  /* BPLVDEE  */
-  tempcx = push1;
-
-  push1 = temp;
-
-  if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
-       if(!SiS_Pr->SiS_IF_DEF_FSTN && !SiS_Pr->SiS_IF_DEF_DSTN) {
-               if(HwInfo->jChipType < SIS_315H) {
-                       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) {
-                               if(resinfo == SIS_RI_1024x600) tempcx++;
-                               if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-                                       if(resinfo == SIS_RI_800x600) tempcx++;
-                               }
-                       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) {
-                               if(resinfo == SIS_RI_800x600)  tempcx++;
-                               if(resinfo == SIS_RI_1024x768) tempcx++; /* Doesnt make sense anyway... */
-                       } else  if(resinfo == SIS_RI_1024x768) tempcx++;
-               } else {
-                       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) {
-                               if(resinfo == SIS_RI_800x600)  tempcx++;
-                       }
-               }
-       }
-  }
+     temp = (USHORT)(tempeax & 0x00FF);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
+     temp = (USHORT)((tempeax & 0x00FF00) >> 8);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
+     temp = (USHORT)((tempeax & 0x00030000) >> 16);
+     if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
 
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) {
-     if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
-        tempcx = SiS_Pr->SiS_VGAVDE;
-        tempbx = SiS_Pr->SiS_VGAVDE - 1;
+     if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) {
+        temp = (USHORT)(tempeax & 0x00FF);
+        SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
+        temp = (USHORT)((tempeax & 0x00FF00) >> 8);
+        SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
+        temp = (USHORT)(((tempeax & 0x00030000) >> 16) << 6);
+        SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
+        temp = 0;
+        if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
+        SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp);
      }
-  }
-
-  temp = ((tempbx & 0x0700) >> 8) << 3;
-  temp |= ((tempcx & 0x0700) >> 8);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);         /* Part1_1Dh; Vertical Display Overflow; Control Signal */
-
-  temp = tempbx & 0x00FF;
-  /* if(SiS_Pr->SiS_IF_DEF_FSTN) temp++;  */
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,temp);         /* Part1_1Ch; Panel Link Vertical Display Enable End  */
+#endif
 
-  temp = tempcx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,temp);         /* Part1_1Bh; Panel Link Vertical Display Enable Start  */
+  }
 
-  /* 3. Additional horizontal setup (scaling, etc) */
+  /* Horizontal scaling */
 
-  tempecx = SiS_Pr->SiS_VGAHDE;
-  if(HwInfo->jChipType >= SIS_315H) {
-     if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
-        if(modeflag & HalfDCLK) tempecx >>= 1;
-     }
+  tempeax = SiS_Pr->SiS_VGAHDE;                /* 1f = ( (VGAHDE * 65536) / ( (VGAHDE * 65536) / HDE ) ) - 1*/
+  if(chkdclkfirst) {
+     if(modeflag & HalfDCLK) tempeax >>= 1;
   }
-  tempebx = SiS_Pr->SiS_HDE;
-  if(tempecx == tempebx) tempeax = 0xFFFF;
-  else {
-     tempeax = tempecx;
-     tempeax <<= 16;
-     temp = (USHORT)(tempeax % tempebx);
-     tempeax = tempeax / tempebx;
+  tempebx = tempeax << 16;
+  if(SiS_Pr->SiS_HDE == tempeax) {
+     tempecx = 0xFFFF;
+  } else {
+     tempecx = tempebx / SiS_Pr->SiS_HDE;
      if(HwInfo->jChipType >= SIS_315H) {
-        if(temp) tempeax++;
+        if(tempebx % SiS_Pr->SiS_HDE) tempecx++;
      }
   }
-  tempecx = tempeax;
 
   if(HwInfo->jChipType >= SIS_315H) {
-     tempeax = SiS_Pr->SiS_VGAHDE;
-     if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
-        if(modeflag & HalfDCLK) tempeax >>= 1;
-     }
-     tempeax <<= 16;
-     tempeax = (tempeax / tempecx) - 1;
+     tempeax = (tempebx / tempecx) - 1;
   } else {
      tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1;
   }
-  tempecx <<= 16;
-  tempecx |= (tempeax & 0xFFFF);
+  tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
   temp = (USHORT)(tempecx & 0x00FF);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);          /* Part1_1Fh; Panel Link DDA Operational Number in each horiz. line */
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);
 
-  tempbx = SiS_Pr->SiS_VDE;
   if(HwInfo->jChipType >= SIS_315H) {
      tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
-     tempbx = (USHORT)(tempeax & 0x0FFFF);
+     tempbx = (USHORT)(tempeax & 0xFFFF);
   } else {
      tempeax = SiS_Pr->SiS_VGAVDE << 6;
-     tempbx = push1 & 0x3f;
+     tempbx = tempvcfact & 0x3f;
      if(tempbx == 0) tempbx = 64;
      tempeax /= tempbx;
-     tempbx = (USHORT)(tempeax & 0x0FFFF);
+     tempbx = (USHORT)(tempeax & 0xFFFF);
   }
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempbx--;
+  if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--;
   if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
      if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) tempbx = 1;
-     else if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480)  tempbx = 1;
+     else if(SiS_Pr->SiS_LCDResInfo != Panel_640x480)             tempbx = 1;
   }
 
-  temp = ((tempbx & 0xFF00) >> 8) << 3;
-  temp |= (USHORT)((tempecx & 0x0700) >> 8);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);         /* Part1_20h; Overflow register */
-
-  temp = tempbx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,temp);         /* Part1_21h; Panel Link Vertical Accumulator Register */
+  temp = ((tempbx >> 8) & 0x07) << 3;
+  temp = temp | ((tempecx >> 8) & 0x07);
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx);
 
-  tempecx >>= 16;                               /* BPLHCFACT  */
-  if((HwInfo->jChipType < SIS_315H) || (SiS_Pr->SiS_IF_DEF_FSTN) || (SiS_Pr->SiS_IF_DEF_DSTN)) {
+  tempecx >>= 16;                                              /* BPLHCFACT  */
+  if(!chkdclkfirst) {
      if(modeflag & HalfDCLK) tempecx >>= 1;
   }
   temp = (USHORT)((tempecx & 0xFF00) >> 8);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);         /* Part1_22h; Panel Link Horizontal Scaling Factor High */
-
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);
   temp = (USHORT)(tempecx & 0x00FF);
-  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);         /* Part1_22h; Panel Link Horizontal Scaling Factor Low */
+  SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
 
-  /* 630/301B and 630/LVDS do something for 640x480 panels here */
+#ifdef SIS315H
+  if(HwInfo->jChipType >= SIS_315H) {
+     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
+        if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SIS301LV302LV)) {
+           SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
+       }
+     } else {
+        if(islvds) {
+           if(HwInfo->jChipType == SIS_740) {
+              SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
+           } else {
+             SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23);
+           }
+        }
+     }
+  }
+#endif
+
+#ifdef SIS300
+  if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
+     int i;
+     UCHAR TrumpMode13[4]   = { 0x01, 0x10, 0x2c, 0x00 };
+     UCHAR TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 };
+     UCHAR TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 };
+
+     SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf);
+     for(i=0; i<5; i++) {
+        SiS_SetTrumpionBlock(SiS_Pr, &SiS300_TrumpionData[crt2crtc][0]);
+     }
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
+        if(ModeNo == 0x13) {
+          for(i=0; i<4; i++) {
+             SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]);
+          }
+       } else if(ModeNo == 0x10) {
+          for(i=0; i<4; i++) {
+             SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_1[0]);
+             SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_2[0]);
+          }
+       }
+     }
+     SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
+  }
+#endif
 
 #ifdef SIS315H
   if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
@@ -6431,10 +6093,10 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      SiS_SetReg(SiS_Pr->SiS_Part1Port,0x28,0x87);
      SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A);
      SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B);
-     SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x007,0x03);
+     SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03);
      tempax = SiS_Pr->SiS_HDE;                                 /* Blps = lcdhdee(lcdhdes+HDE) + 64 */
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2 ||
-        SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) tempax >>= 1;
+     if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
+        SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1;
      tempax += 64;
      temp = tempax & 0x00FF;
      SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,temp);
@@ -6448,8 +6110,8 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x007,0x00);
 
      tempax = SiS_Pr->SiS_VDE;
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2 ||
-        SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) tempax >>= 1;
+     if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
+        SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1;
      tempax >>= 1;
      temp = tempax & 0x00FF;
      SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,temp);
@@ -6457,8 +6119,8 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp);
 
      tempeax = SiS_Pr->SiS_HDE;
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2 ||
-        SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) tempeax >>= 1;
+     if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
+        SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempeax >>= 1;
      tempeax <<= 2;                                            /* BDxFIFOSTOP = (HDE*4)/128 */
      tempebx = 128;
      temp = (USHORT)(tempeax % tempebx);
@@ -6472,8 +6134,8 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x040,0x00);
 
      tempax = SiS_Pr->SiS_HDE;
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2 ||
-        SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) tempax >>= 1;
+     if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
+        SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1;
      tempax >>= 4;                                             /* BDxWadroff = HDE*4/8/8 */
      pushcx = tempax;
      temp = tempax & 0x00FF;
@@ -6482,8 +6144,8 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x0F8,temp);
 
      tempax = SiS_Pr->SiS_VDE;                                 /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_2 ||
-        SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480_3) tempax >>= 1;
+     if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
+        SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1;
      tempeax = (tempax * pushcx);
      tempebx = 0x00100000 + tempeax;
      temp = (USHORT)tempebx & 0x000000FF;
@@ -6525,496 +6187,380 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      }
   }
 #endif  /* SIS315H */
-
 }
 
-/************** Set Part 1 ***************/
+/* Set Part 1 */
 static void
 SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
               PSIS_HW_INFO HwInfo, USHORT RefreshRateTableIndex)
 {
-  UCHAR  *ROMAddr  = HwInfo->pjVirtualRomBase;
-  USHORT  temp=0, tempax=0, tempbx=0, tempcx=0;
-  USHORT  pushbx=0, CRT1Index=0;
+#if defined(SIS300) || defined(SIS315H)
+  UCHAR   *ROMAddr = HwInfo->pjVirtualRomBase;
+#endif
+  USHORT  temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
+  USHORT  pushbx=0, CRT1Index=0, modeflag, resinfo=0;
 #ifdef SIS315H
   USHORT  tempbl=0;
 #endif
-  USHORT  modeflag, resinfo=0;
+
+  if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
+     SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
+     return;
+  }
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
+  } else if(SiS_Pr->UseCustomMode) {
+     modeflag = SiS_Pr->CModeFlag;
   } else {
-     if(SiS_Pr->UseCustomMode) {
-       modeflag = SiS_Pr->CModeFlag;
-     } else {
-       CRT1Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
-       resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
-       modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-     }
+     CRT1Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
+     resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
+     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
   }
 
-  if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
+  SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
 
-#ifdef SIS315H
-     SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex, HwInfo);
-     SiS_SetGroup1_LCDA(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
-#endif
-
-  } else {
-
-     if( (HwInfo->jChipType >= SIS_315H) &&
+  if( ! ((HwInfo->jChipType >= SIS_315H) &&
          (SiS_Pr->SiS_IF_DEF_LVDS == 1) &&
-        (SiS_Pr->SiS_VBInfo & SetInSlaveMode) ) {
-
-        SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex, HwInfo);
-
-     } else {
-
-        SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex,
-                         RefreshRateTableIndex, HwInfo);
+         (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
 
-        if (HwInfo->jChipType < SIS_315H ) {
+     if(HwInfo->jChipType < SIS_315H ) {
 #ifdef SIS300
-             SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo, HwInfo);
+       SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo, HwInfo);
 #endif
-        } else {
+     } else {
 #ifdef SIS315H
-              SiS_SetCRT2FIFO_310(SiS_Pr);
+        SiS_SetCRT2FIFO_310(SiS_Pr, HwInfo);
 #endif
-       }
-
-        SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex, HwInfo);
+     }
 
-       /* 1. Horizontal setup */
+     /* 1. Horizontal setup */
 
-        if(HwInfo->jChipType < SIS_315H ) {
+     if(HwInfo->jChipType < SIS_315H ) {
 
 #ifdef SIS300   /* ------------- 300 series --------------*/
 
-               temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF;                         /* BTVGA2HT 0x08,0x09 */
-               SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp);                   /* CRT2 Horizontal Total */
-
-               temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
-               SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp);          /* CRT2 Horizontal Total Overflow [7:4] */
-
-               temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF;                       /* BTVGA2HDEE 0x0A,0x0C */
-               SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp);                   /* CRT2 Horizontal Display Enable End */
+       temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF;                   /* BTVGA2HT 0x08,0x09 */
+       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp);              /* CRT2 Horizontal Total */
 
-               pushbx = SiS_Pr->SiS_VGAHDE + 12;                               /* bx  BTVGA@HRS 0x0B,0x0C */
-               tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
-               tempbx = pushbx + tempcx;
-               tempcx <<= 1;
-               tempcx += tempbx;
+       temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
+       SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp);    /* CRT2 Horizontal Total Overflow [7:4] */
 
-               if(SiS_Pr->SiS_VBType & VB_SISVB) {
+       temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF;                 /* BTVGA2HDEE 0x0A,0x0C */
+       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp);              /* CRT2 Horizontal Display Enable End */
 
-                  if(SiS_Pr->UseCustomMode) {
-                     tempbx = SiS_Pr->CHSyncStart + 12;
-                     tempcx = SiS_Pr->CHSyncEnd + 12;
-                  }
+       pushbx = SiS_Pr->SiS_VGAHDE + 12;                         /* bx  BTVGA2HRS 0x0B,0x0C */
+       tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
+       tempbx = pushbx + tempcx;
+       tempcx <<= 1;
+       tempcx += tempbx;
 
-                  if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
-                     unsigned char cr4, cr14, cr5, cr15;
-                     if(SiS_Pr->UseCustomMode) {
-                        cr4  = SiS_Pr->CCRT1CRTC[4];
-                        cr14 = SiS_Pr->CCRT1CRTC[14];
-                        cr5  = SiS_Pr->CCRT1CRTC[5];
-                        cr15 = SiS_Pr->CCRT1CRTC[15];
-                     } else {
-                        cr4  = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
-                        cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
-                        cr5  = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
-                        cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
-                     }
-                     tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 1) << 3;
-                     tempcx = (((cr5 & 0x1F) | ((cr15 & 0x04) << (6-2))) - 1) << 3;
-                  }
-
-                  if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (resinfo == SIS_RI_1024x768)){
-                     if(!(SiS_Pr->SiS_TVMode & TVSetPAL)){
-                        tempbx = 1040;
-                        tempcx = 1042;
-                     }
-                  }
-               }
+       bridgeadd = 12;
 
-               temp = tempbx & 0x00FF;
-               SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,temp);                   /* CRT2 Horizontal Retrace Start */
 #endif /* SIS300 */
 
-       } else {
+     } else {
 
 #ifdef SIS315H  /* ------------------- 315/330 series --------------- */
 
-               tempcx = SiS_Pr->SiS_VGAHT;                                    /* BTVGA2HT 0x08,0x09 */
-               if(modeflag & HalfDCLK) {
-                   if(SiS_Pr->SiS_VBType & VB_SISVB) {
-                      tempcx >>= 1;
-                   } else {
-                      tempax = SiS_Pr->SiS_VGAHDE >> 1;
-                      tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax;
-                      if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-                         tempcx = SiS_Pr->SiS_HT - tempax;
-                      }
-                   }
-               }
-               tempcx--;
+       tempcx = SiS_Pr->SiS_VGAHT;                               /* BTVGA2HT 0x08,0x09 */
+       if(modeflag & HalfDCLK) {
+          if(SiS_Pr->SiS_VBType & VB_SISVB) {
+             tempcx >>= 1;
+          } else {
+             tempax = SiS_Pr->SiS_VGAHDE >> 1;
+             tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax;
+             if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+                tempcx = SiS_Pr->SiS_HT - tempax;
+             }
+          }
+       }
+       tempcx--;
+       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,tempcx);            /* CRT2 Horizontal Total */
+       temp = (tempcx >> 4) & 0xF0;
+       SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp);    /* CRT2 Horizontal Total Overflow [7:4] */
+
+       tempcx = SiS_Pr->SiS_VGAHT;                               /* BTVGA2HDEE 0x0A,0x0C */
+       tempbx = SiS_Pr->SiS_VGAHDE;
+       tempcx -= tempbx;
+       tempcx >>= 2;
+       if(modeflag & HalfDCLK) {
+          tempbx >>= 1;
+          tempcx >>= 1;
+       }
+       tempbx += 16;
 
-               temp = tempcx & 0xff;
-               SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp);                  /* CRT2 Horizontal Total */
+       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,tempbx);            /* CRT2 Horizontal Display Enable End */
 
-               temp = ((tempcx & 0xff00) >> 8) << 4;
-               SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp);         /* CRT2 Horizontal Total Overflow [7:4] */
+       pushbx = tempbx;
+       tempcx >>= 1;
+       tempbx += tempcx;
+       tempcx += tempbx;
 
-               tempcx = SiS_Pr->SiS_VGAHT;                                    /* BTVGA2HDEE 0x0A,0x0C */
-               tempbx = SiS_Pr->SiS_VGAHDE;
-               tempcx -= tempbx;
-               tempcx >>= 2;
-               if(modeflag & HalfDCLK) {
-                  tempbx >>= 1;
-                  tempcx >>= 1;
-               }
-               tempbx += 16;
-
-               temp = tempbx & 0xff;
-               SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp);                  /* CRT2 Horizontal Display Enable End */
-
-               pushbx = tempbx;
-               tempcx >>= 1;
-               tempbx += tempcx;
-               tempcx += tempbx;
-
-               if(SiS_Pr->SiS_VBType & VB_SISVB) {
-
-                  if(HwInfo->jChipType >= SIS_661) {
-                     if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) ||
-                        (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024)) {
-                        if(resinfo == SIS_RI_1280x1024) {
-                           tempcx = 0x30;
-                        } else if(resinfo == SIS_RI_1600x1200) {
-                           tempcx = 0xff;
-                        }
-                     }
-                  }
+       bridgeadd = 16;
 
-                  if(SiS_Pr->UseCustomMode) {
-                     tempbx = SiS_Pr->CHSyncStart + 16;
-                     tempcx = SiS_Pr->CHSyncEnd + 16;
-                     tempax = SiS_Pr->SiS_VGAHT;
-                     if(modeflag & HalfDCLK) tempax >>= 1;
-                     tempax--;
-                     if(tempcx > tempax)  tempcx = tempax;
-                  }
+       if(SiS_Pr->SiS_VBType & VB_SISVB) {
+          if(HwInfo->jChipType >= SIS_661) {
+             if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
+                (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
+                if(resinfo == SIS_RI_1280x1024) {
+                   tempcx = (tempcx & 0xff00) | 0x30;
+                } else if(resinfo == SIS_RI_1600x1200) {
+                   tempcx = (tempcx & 0xff00) | 0xff;
+                }
+             }
+          }
+        }
 
-                  if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
-                     unsigned char cr4, cr14, cr5, cr15;
-                     if(SiS_Pr->UseCustomMode) {
-                        cr4  = SiS_Pr->CCRT1CRTC[4];
-                        cr14 = SiS_Pr->CCRT1CRTC[14];
-                        cr5  = SiS_Pr->CCRT1CRTC[5];
-                        cr15 = SiS_Pr->CCRT1CRTC[15];
-                     } else {
-                        cr4  = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
-                        cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
-                        cr5  = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
-                        cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
-                     }
-                      tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3;                /* (VGAHRS-3)*8 */
-                      tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3;   /* (VGAHRE-3)*8 */
-                     tempcx &= 0x00FF;
-                     tempcx |= (tempbx & 0xFF00);
-                      tempbx += 16;
-                      tempcx += 16;
-                     tempax = SiS_Pr->SiS_VGAHT;
-                     if(modeflag & HalfDCLK) tempax >>= 1;
-                     tempax--;
-                     if(tempcx > tempax)  tempcx = tempax;
-                  }
-
-                  if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
-                     tempbx = 1040;
-                     tempcx = 1042;
-                  }
-
-                }
-
-               temp = tempbx & 0xff;
-               SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,temp);                 /* CRT2 Horizontal Retrace Start */
 #endif  /* SIS315H */
 
-       }  /* 315/330 series */
+     }  /* 315/330 series */
 
-       /* The following is done for all bridge/chip types/series */
+     if(SiS_Pr->SiS_VBType & VB_SISVB) {
 
-       tempax = tempbx & 0xFF00;
-       tempbx = pushbx;
-       tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
-       tempax |= (tempbx & 0xFF00);
-       temp = (tempax & 0xFF00) >> 8;
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp);                        /* Overflow */
+        if(SiS_Pr->UseCustomMode) {
+          tempbx = SiS_Pr->CHSyncStart + bridgeadd;
+          tempcx = SiS_Pr->CHSyncEnd + bridgeadd;
+          tempax = SiS_Pr->SiS_VGAHT;
+          if(modeflag & HalfDCLK) tempax >>= 1;
+          tempax--;
+          if(tempcx > tempax) tempcx = tempax;
+       }
 
-       temp = tempcx & 0x00FF;
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,temp);                        /* CRT2 Horizontal Retrace End */
+       if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
+          unsigned char cr4, cr14, cr5, cr15;
+          if(SiS_Pr->UseCustomMode) {
+             cr4  = SiS_Pr->CCRT1CRTC[4];
+             cr14 = SiS_Pr->CCRT1CRTC[14];
+             cr5  = SiS_Pr->CCRT1CRTC[5];
+             cr15 = SiS_Pr->CCRT1CRTC[15];
+          } else {
+             cr4  = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
+             cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
+             cr5  = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
+             cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
+          }
+           tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3;               /* (VGAHRS-3)*8 */
+           tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3;   /* (VGAHRE-3)*8 */
+          tempcx &= 0x00FF;
+          tempcx |= (tempbx & 0xFF00);
+           tempbx += bridgeadd;
+           tempcx += bridgeadd;
+          tempax = SiS_Pr->SiS_VGAHT;
+          if(modeflag & HalfDCLK) tempax >>= 1;
+          tempax--;
+          if(tempcx > tempax) tempcx = tempax;
+        }
 
-       /* 2. Vertical setup */
+        if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
+          tempbx = 1040;
+          tempcx = 1044;   /* HWCursor bug! */
+        }
 
-       tempcx = SiS_Pr->SiS_VGAVT - 1;
-       temp = tempcx & 0x00FF;
+     }
 
-       if(HwInfo->jChipType < SIS_661) {
-           if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
-             if(HwInfo->jChipType < SIS_315H) {
-                if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
-                   if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
-                      temp--;
-                   }
-                 }
-             } else {
-                temp--;
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,tempbx);                      /* CRT2 Horizontal Retrace Start */
+
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,tempcx);               /* CRT2 Horizontal Retrace End */
+
+     temp = ((tempbx >> 8) & 0x0F) | ((pushbx >> 4) & 0xF0);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp);                /* Overflow */
+
+     /* 2. Vertical setup */
+
+     tempcx = SiS_Pr->SiS_VGAVT - 1;
+     temp = tempcx & 0x00FF;
+
+     if(HwInfo->jChipType < SIS_661) {
+        if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
+          if(HwInfo->jChipType < SIS_315H) {
+             if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
+                if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
+                   temp--;
+                }
               }
-           } else if(HwInfo->jChipType >= SIS_315H) {
-             temp--;
-          }
-       }
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp);                        /* CRT2 Vertical Total */
-
-       tempbx = SiS_Pr->SiS_VGAVDE - 1;
-       temp = tempbx & 0x00FF;
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,temp);                        /* CRT2 Vertical Display Enable End */
-
-       temp = ((tempbx & 0xFF00) << 3) >> 8;
-       temp |= ((tempcx & 0xFF00) >> 8);
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp);                        /* Overflow (and HWCursor Test Mode) */
-
-       if((HwInfo->jChipType >= SIS_315H) && (HwInfo->jChipType < SIS_661)) {
-           tempbx++;
-          tempax = tempbx;
-          tempcx++;
-          tempcx -= tempax;
-          tempcx >>= 2;
-          tempbx += tempcx;
-          if(tempcx < 4) tempcx = 4;
-          tempcx >>= 2;
-          tempcx += tempbx;
-          tempcx++;
-       } else {
-          tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1;                 /*  BTVGA2VRS     0x10,0x11   */
-          tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1;  /*  BTVGA2VRE     0x11        */
+          } else {
+             temp--;
+           }
+        } else if(HwInfo->jChipType >= SIS_315H) {
+          temp--;
        }
+     }
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp);                 /* CRT2 Vertical Total */
+
+     tempbx = SiS_Pr->SiS_VGAVDE - 1;
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,tempbx);               /* CRT2 Vertical Display Enable End */
+
+     temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp);                 /* Overflow */
+
+     if((HwInfo->jChipType >= SIS_315H) && (HwInfo->jChipType < SIS_661)) {
+        tempbx++;
+       tempax = tempbx;
+       tempcx++;
+       tempcx -= tempax;
+       tempcx >>= 2;
+       tempbx += tempcx;
+       if(tempcx < 4) tempcx = 4;
+       tempcx >>= 2;
+       tempcx += tempbx;
+       tempcx++;
+     } else {
+       tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1;                 /*  BTVGA2VRS     0x10,0x11   */
+       tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1;  /*  BTVGA2VRE     0x11        */
+     }
 
-       if(SiS_Pr->SiS_VBType & VB_SISVB) {
-
+     if(SiS_Pr->SiS_VBType & VB_SISVB) {
+       if(SiS_Pr->UseCustomMode) {
+          tempbx = SiS_Pr->CVSyncStart;
+          tempcx = SiS_Pr->CVSyncEnd;
+       }
+        if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
+          unsigned char cr8, cr7, cr13;
           if(SiS_Pr->UseCustomMode) {
-             tempbx = SiS_Pr->CVSyncStart;
-             tempcx = (tempcx & 0xFF00) | (SiS_Pr->CVSyncEnd & 0x00FF);
+             cr8    = SiS_Pr->CCRT1CRTC[8];
+             cr7    = SiS_Pr->CCRT1CRTC[7];
+             cr13   = SiS_Pr->CCRT1CRTC[13];
+             tempcx = SiS_Pr->CCRT1CRTC[9];
+          } else {
+             cr8    = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8];
+             cr7    = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
+             cr13   = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
+             tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
           }
+          tempbx = cr8;
+          if(cr7  & 0x04) tempbx |= 0x0100;
+          if(cr7  & 0x80) tempbx |= 0x0200;
+          if(cr13 & 0x08) tempbx |= 0x0400;
+               }
+     }
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx);               /* CRT2 Vertical Retrace Start */
 
-          if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
-             unsigned char cr8, cr7, cr13, cr9;
-             if(SiS_Pr->UseCustomMode) {
-                cr8  = SiS_Pr->CCRT1CRTC[8];
-                cr7  = SiS_Pr->CCRT1CRTC[7];
-                cr13 = SiS_Pr->CCRT1CRTC[13];
-                cr9  = SiS_Pr->CCRT1CRTC[9];
-             } else {
-                cr8  = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8];
-                cr7  = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
-                cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
-                cr9  = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
-             }
-             tempbx = cr8;
-             if(cr7 & 0x04)  tempbx |= 0x0100;
-             if(cr7 & 0x80)  tempbx |= 0x0200;
-             if(cr13 & 0x08) tempbx |= 0x0400;
-             tempcx = (tempcx & 0xFF00) | (cr9 & 0x00FF);
-          }
-       }
-       temp = tempbx & 0x00FF;
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,temp);           /* CRT2 Vertical Retrace Start */
-
-       temp = ((tempbx & 0xFF00) >> 8) << 4;
-       temp |= (tempcx & 0x000F);
-       SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp);           /* CRT2 Vert. Retrace End; Overflow; "Enable CRTC Check" */
+     temp = ((tempbx >> 4) & 0x70) | (tempcx & 0x0F);
+     SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp);                 /* CRT2 Vert. Retrace End; Overflow */
 
-       /* 3. Panel compensation delay */
+     /* 3. Panel delay compensation */
 
-       if(HwInfo->jChipType < SIS_315H) {
+     if(HwInfo->jChipType < SIS_315H) {
 
 #ifdef SIS300  /* ---------- 300 series -------------- */
 
-          if(SiS_Pr->SiS_VBType & VB_SISVB) {
-               temp = 0x20;
+       if(SiS_Pr->SiS_VBType & VB_SISVB) {
+          temp = 0x20;
+          if(HwInfo->jChipType == SIS_300) {
+             temp = 0x10;
+             if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768)  temp = 0x2c;
+             if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
+          }
+          if(SiS_Pr->SiS_VBType & VB_SIS301) {
+             if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
+          }
+          if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960)     temp = 0x24;
+          if(SiS_Pr->SiS_LCDResInfo == Panel_Custom)       temp = 0x2c;
+          if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)             temp = 0x08;
+          if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
+             if(SiS_Pr->SiS_VBInfo & SetInSlaveMode)       temp = 0x2c;
+             else                                          temp = 0x20;
+          }
+          if(SiS_Pr->SiS_UseROM) {
+             if(ROMAddr[0x220] & 0x80) {
+                if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
+                   temp = ROMAddr[0x221];
+                else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
+                   temp = ROMAddr[0x222];
+                else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)
+                   temp = ROMAddr[0x223];
+                else
+                   temp = ROMAddr[0x224];
+                temp &= 0x3c;
+             }
+          }
+          if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+             if(SiS_Pr->PDC != -1)  temp = SiS_Pr->PDC & 0x3c;
+          }
 
-               if(HwInfo->jChipType == SIS_300) {
-                  temp = 0x10;
-                  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)  temp = 0x2c;
-                  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) temp = 0x20;
-               }
-               if(SiS_Pr->SiS_VBType & VB_SIS301) {
-                  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) temp = 0x20;
-               }
-               if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960)     temp = 0x24;
-               if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom)       temp = 0x2c;
-               if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)            temp = 0x08;
-               if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
-                  if(SiS_Pr->SiS_VBInfo & SetInSlaveMode)      temp = 0x2c;
-                  else                                         temp = 0x20;
-               }
-               if((ROMAddr) && (SiS_Pr->SiS_UseROM)) {
-                   if(ROMAddr[0x220] & 0x80) {
-                       if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
-                               temp = ROMAddr[0x221];
-                       else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
-                               temp = ROMAddr[0x222];
-                       else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024)
-                               temp = ROMAddr[0x223];
-                       else
-                               temp = ROMAddr[0x224];
-                       temp &= 0x3c;
-                   }
-               }
-               if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-                  if(SiS_Pr->PDC) {
-                       temp = SiS_Pr->PDC & 0x3c;
-                  }
-               }
-          } else {
-               temp = 0x20;
-               if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
-                  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) temp = 0x04;
-               }
-               if((ROMAddr) && SiS_Pr->SiS_UseROM) {
-                   if(ROMAddr[0x220] & 0x80) {
-                       temp = ROMAddr[0x220] & 0x3c;
-                   }
-               }
-               if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-                  if(SiS_Pr->PDC) {
-                     temp = SiS_Pr->PDC & 0x3c;
-                  }
-               }
+       } else {
+          temp = 0x20;
+          if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
+             if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) temp = 0x04;
           }
+          if(SiS_Pr->SiS_UseROM) {
+             if(ROMAddr[0x220] & 0x80) {
+                temp = ROMAddr[0x220] & 0x3c;
+             }
+          }
+          if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+             if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC & 0x3c;
+          }
+        }
 
-          SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x03C,temp);         /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
+       SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);   /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
 
 #endif  /* SIS300 */
 
-       } else {
+     } else {
 
 #ifdef SIS315H   /* --------------- 315/330 series ---------------*/
 
-          if(HwInfo->jChipType < SIS_661) {
-
-             if(SiS_Pr->SiS_VBType & VB_SISVB) {
+        if(HwInfo->jChipType < SIS_661) {
 
-                 temp = 0x10;
-                 if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)  temp = 0x2c;
-                if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) temp = 0x20;
-                if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960)  temp = 0x24;
-                if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom)    temp = 0x2c;
-                if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-                   temp = 0x08;
-                   if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
-                      if(SiS_Pr->SiS_VBInfo & SetInSlaveMode)  temp = 0x2c;
-                      else                                     temp = 0x20;
-                   }
-                }
-                if((SiS_Pr->SiS_VBType & VB_SIS301B302B) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
-                   tempbl = 0x00;
-                   if((ROMAddr) && (SiS_Pr->SiS_UseROM)) {
-                      if(HwInfo->jChipType < SIS_330) {
-                         if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
-                      } else {
-                         if(ROMAddr[0x1bc] & 0x80) tempbl = 0xf0;
-                      }
-                   }
-                } else {  /* LV (550/301LV checks ROM byte, other LV BIOSes do not) */
-                   tempbl = 0xF0;
-                }
-                if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) {
-                   if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
-                      if(SiS_Pr->PDC) {
-                         temp = SiS_Pr->PDC;
-                         tempbl = 0;
-                      }
-                   }
-                }
+          if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
 
-             } else {  /* LVDS */
+             if(HwInfo->jChipType == SIS_740) temp = 0x03;
+             else                             temp = 0x00;
 
-                if(HwInfo->jChipType == SIS_740) {
-                   temp = 0x03;
-                } else {
-                   temp = 0x00;
-                }
-                if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
-                tempbl = 0xF0;
-                if(HwInfo->jChipType == SIS_650) {
-                   if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
-                      if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
-                   }
+             if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
+             tempbl = 0xF0;
+             if(HwInfo->jChipType == SIS_650) {
+                if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
+                   if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
                 }
+             }
 
-                if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
-                   temp = 0x08;
-                   tempbl = 0;
-                   if((ROMAddr) && (SiS_Pr->SiS_UseROM)) {
-                      if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
-                   }
+             if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
+                temp = 0x08;
+                tempbl = 0;
+                if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
+                   if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
                 }
              }
 
              SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp);      /* Panel Link Delay Compensation */
+          }
 
-          } /* < 661 */
+       } /* < 661 */
 
-          tempax = 0;
-          if (modeflag & DoubleScanMode) tempax |= 0x80;
-          if (modeflag & HalfDCLK)       tempax |= 0x40;
-          SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
+       tempax = 0;
+       if(modeflag & DoubleScanMode) tempax |= 0x80;
+       if(modeflag & HalfDCLK)       tempax |= 0x40;
+       SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
 
 #endif  /* SIS315H */
 
-       }
-
-     }  /* Slavemode */
+     }
 
-     if(SiS_Pr->SiS_VBType & VB_SISVB) {
+  }  /* Slavemode */
 
+  if(SiS_Pr->SiS_VBType & VB_SISVB) {
+     if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
         /* For 301BDH with LCD, we set up the Panel Link */
-        if( (SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ) {
-
-           SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex,
-                              HwInfo, RefreshRateTableIndex);
-
-        } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
-
-           SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex,
-                             HwInfo, RefreshRateTableIndex);
-        }
-
+       SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
+     } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
+       SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
+     }
+  } else {
+     if(HwInfo->jChipType < SIS_315H) {
+       SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
      } else {
-
-        if(HwInfo->jChipType < SIS_315H) {
-
-          SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex,
-                               HwInfo, RefreshRateTableIndex);
+       if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
+           if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
+             SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex, HwInfo,RefreshRateTableIndex);
+           }
        } else {
-
-          if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
-              if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
-                 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,
-                                     HwInfo,RefreshRateTableIndex);
-              }
-          } else {
-             SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,
-                                HwInfo,RefreshRateTableIndex);
-          }
-
+          SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex, HwInfo,RefreshRateTableIndex);
        }
-
      }
-  } /* LCDA */
+  }
 }
 
 /*********************************************/
@@ -7025,9 +6571,8 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 static UCHAR *
 SiS_GetGroup2CLVXPtr(SiS_Private *SiS_Pr, int tabletype, PSIS_HW_INFO HwInfo)
 {
-   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
    const UCHAR  *tableptr = NULL;
-   USHORT a, b, p = 0;
+   USHORT       a, b, p = 0;
 
    a = SiS_Pr->SiS_VGAHDE;
    b = SiS_Pr->SiS_HDE;
@@ -7036,66 +6581,33 @@ SiS_GetGroup2CLVXPtr(SiS_Private *SiS_Pr, int tabletype, PSIS_HW_INFO HwInfo)
       b = SiS_Pr->SiS_VDE;
    }
 
-   if((HwInfo->jChipType >= SIS_661) && (ROMAddr = (UCHAR *)HwInfo->pjVirtualRomBase) && SiS_Pr->SiS_UseROM) {
-
-      if(a < b) {
-         p = ROMAddr[0x278] | (ROMAddr[0x279] << 8);
-      } else if(a == b) {
-         p = ROMAddr[0x27a] | (ROMAddr[0x27b] << 8);
-      } else {
-         if(SiS_Pr->SiS_TVMode & TVSetPAL) {
-           p = ROMAddr[0x27e] | (ROMAddr[0x27f] << 8);
-        } else {
-           p = ROMAddr[0x27c] | (ROMAddr[0x27d] << 8);
-        }
-        if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
-           if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)      p = ROMAddr[0x280] | (ROMAddr[0x281] << 8);
-           else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) p = ROMAddr[0x282] | (ROMAddr[0x283] << 8);
-           else                                         p = ROMAddr[0x284] | (ROMAddr[0x285] << 8);
-        } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
-           p = ROMAddr[0x286] | (ROMAddr[0x287] << 8);
-        }
-        do {
-           if((ROMAddr[p] | ROMAddr[p+1] << 8) == a) break;
-           p += 0x42;
-        } while((ROMAddr[p] | ROMAddr[p+1] << 8) != 0xffff);
-        if((ROMAddr[p] | ROMAddr[p+1] << 8) == 0xffff) p -= 0x42;
-      }
-      p += 2;
-      return(&ROMAddr[p]);
-
+   if(a < b) {
+      tableptr = SiS_Part2CLVX_1;
+   } else if(a == b) {
+      tableptr = SiS_Part2CLVX_2;
    } else {
-
-      if(a < b) {
-         tableptr = SiS_Part2CLVX_1;
-      } else if(a == b) {
-         tableptr = SiS_Part2CLVX_2;
+      if(SiS_Pr->SiS_TVMode & TVSetPAL) {
+        tableptr = SiS_Part2CLVX_4;
       } else {
-         if(SiS_Pr->SiS_TVMode & TVSetPAL) {
-           tableptr = SiS_Part2CLVX_4;
-        } else {
-           tableptr = SiS_Part2CLVX_3;
-        }
-        if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
-           if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)      tableptr = SiS_Part2CLVX_3;
-           else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tableptr = SiS_Part2CLVX_3;
-           else                                         tableptr = SiS_Part2CLVX_5;
-
-        } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
-           tableptr = SiS_Part2CLVX_6;
-        }
-        do {
-           if((tableptr[p] | tableptr[p+1] << 8) == a) break;
-           p += 0x42;
-        } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff);
-        if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
+        tableptr = SiS_Part2CLVX_3;
+      }
+      if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
+        if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)        tableptr = SiS_Part2CLVX_3;
+        else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p)   tableptr = SiS_Part2CLVX_3;
+        else                                           tableptr = SiS_Part2CLVX_5;
+      } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
+        tableptr = SiS_Part2CLVX_6;
       }
-      p += 2;
-      return((UCHAR *)&tableptr[p]);
+      do {
+        if((tableptr[p] | tableptr[p+1] << 8) == a) break;
+        p += 0x42;
+      } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff);
+      if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
    }
+   p += 2;
+   return((UCHAR *)&tableptr[p]);
 }
 
-
 static void
 SiS_SetGroup2_C_ELV(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                    USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
@@ -7121,49 +6633,97 @@ SiS_SetGroup2_C_ELV(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
    SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp);
 }
 
-static void
+static BOOLEAN
 SiS_GetCRT2Part2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
                    USHORT RefreshRateTableIndex,USHORT *CRT2Index,
                    USHORT *ResIndex,PSIS_HW_INFO HwInfo)
 {
-  USHORT tempbx,tempal;
+
+  if(HwInfo->jChipType < SIS_315H) return FALSE;
 
   if(ModeNo <= 0x13)
-       tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+     (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
   else
-       tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
+     (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
 
-  tempbx = SiS_Pr->SiS_LCDResInfo;
+  (*ResIndex) &= 0x3f;
+  (*CRT2Index) = 0;
 
-  if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)      tempbx += 16;
-  else if(SiS_Pr->SiS_SetFlag & LCDVESATiming) tempbx += 32;
-
-  if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-        tempbx = 100;
-        if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)      tempbx = 101;
-       else if(SiS_Pr->SiS_SetFlag & LCDVESATiming) tempbx = 102;
-     }
-  } else if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-        if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
-           tempbx = 103;
-           if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)      tempbx = 104;
-          else if(SiS_Pr->SiS_SetFlag & LCDVESATiming) tempbx = 105;
-       }
-     }
-  } else if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-        if(SiS_Pr->SiS_SetFlag & LCDVESATiming) tempbx = 106;
+  if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
+     if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
+        (*CRT2Index) = 200;
      }
   }
 
-  *CRT2Index = tempbx;
-  *ResIndex = tempal & 0x3F;
+  if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
+        if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206;
+     }
+  }
+  return(((*CRT2Index) != 0));
 }
 #endif
 
 #ifdef SIS300
+static void
+SiS_Group2LCDSpecial(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo, USHORT crt2crtc)
+{
+   USHORT tempcx;
+   const UCHAR atable[] = {
+       0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
+       0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
+   };
+
+   if(!SiS_Pr->UseCustomMode) {
+      if( ( ( (HwInfo->jChipType == SIS_630) ||
+              (HwInfo->jChipType == SIS_730) ) &&
+            (HwInfo->jChipRevision > 2) )  &&
+          (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) &&
+          (!(SiS_Pr->SiS_SetFlag & LCDVESATiming))  &&
+          (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
+         if(ModeNo == 0x13) {
+            SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
+            SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
+            SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
+         } else {
+            if((crt2crtc & 0x3F) == 4) {
+               SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
+               SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
+               SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
+               SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
+               SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
+            }
+         }
+      }
+
+      if(HwInfo->jChipType < SIS_315H) {
+         if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
+            crt2crtc &= 0x1f;
+            tempcx = 0;
+            if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
+               if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
+                  tempcx += 7;
+               }
+            }
+            tempcx += crt2crtc;
+            if(crt2crtc >= 4) {
+               SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
+            }
+
+            if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
+               if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
+                  if(crt2crtc == 4) {
+                     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
+                  }
+               }
+            }
+            SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
+            SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
+         }
+      }
+   }
+}
+
 /* For ECS A907. Highly preliminary. */
 static void
 SiS_Set300Part2Regs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
@@ -7232,15 +6792,81 @@ SiS_SetTVSpecial(SiS_Private *SiS_Pr, USHORT ModeNo)
        if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750)) {
           if(SiS_Pr->SiS_TVMode & TVSetPALM) {
              SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14);
+             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b);
           } else {
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x15);
+             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14);  /* 15 */
+             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1a);  /* 1b */
           }
-          SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b);
        }
      }
   } else {
-     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x21);
-     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x5a);
+     if((ModeNo == 0x38) || (ModeNo == 0x4a) || (ModeNo == 0x64) ||
+        (ModeNo == 0x52) || (ModeNo == 0x58) || (ModeNo == 0x5c)) {
+        SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b);  /* 21 */
+        SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54);  /* 5a */
+     } else {
+        SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1a);  /* 21 */
+        SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x53);  /* 5a */
+     }
+  }
+}
+
+static void
+SiS_SetGroup2_Tail(SiS_Private *SiS_Pr, USHORT ModeNo)
+{
+  USHORT temp;
+
+  if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
+     if(SiS_Pr->SiS_VGAVDE == 525) {
+       temp = 0xc3;
+       if(SiS_Pr->SiS_ModeType <= ModeVGA) {
+          temp++;
+          if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp += 2;
+       }
+       SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
+       SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
+     } else if(SiS_Pr->SiS_VGAVDE == 420) {
+       temp = 0x4d;
+       if(SiS_Pr->SiS_ModeType <= ModeVGA) {
+          temp++;
+          if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp++;
+       }
+       SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
+     }
+  }
+
+  if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
+       if(SiS_Pr->SiS_VBType & VB_SIS301B302B) {
+          SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03);
+          /* Not always for LV, see SetGrp2 */
+       }
+       temp = 1;
+       if(ModeNo <= 0x13) temp = 3;
+       SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp);
+     }
+#if 0
+     /* 651+301C, for 1280x768 - do I really need that? */
+     if((SiS_Pr->SiS_PanelXRes == 1280) && (SiS_Pr->SiS_PanelYRes == 768)) {
+        if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
+          if(((SiS_Pr->SiS_HDE == 640) && (SiS_Pr->SiS_VDE == 480)) ||
+             ((SiS_Pr->SiS_HDE == 320) && (SiS_Pr->SiS_VDE == 240))) {
+             SiS_SetReg(SiS_Part2Port,0x01,0x2b);
+             SiS_SetReg(SiS_Part2Port,0x02,0x13);
+             SiS_SetReg(SiS_Part2Port,0x04,0xe5);
+             SiS_SetReg(SiS_Part2Port,0x05,0x08);
+             SiS_SetReg(SiS_Part2Port,0x06,0xe2);
+             SiS_SetReg(SiS_Part2Port,0x1c,0x21);
+             SiS_SetReg(SiS_Part2Port,0x1d,0x45);
+             SiS_SetReg(SiS_Part2Port,0x1f,0x0b);
+             SiS_SetReg(SiS_Part2Port,0x20,0x00);
+             SiS_SetReg(SiS_Part2Port,0x21,0xa9);
+             SiS_SetReg(SiS_Part2Port,0x23,0x0b);
+             SiS_SetReg(SiS_Part2Port,0x25,0x04);
+          }
+       }
+     }
+#endif
   }
 }
 
@@ -7248,37 +6874,27 @@ static void
 SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT RefreshRateTableIndex,
              PSIS_HW_INFO HwInfo)
 {
-  USHORT      i, j, tempax, tempbx, tempcx, temp;
-  USHORT      push1, push2, modeflag, crt2crtc;
-  ULONG       longtemp, tempeax;
+  USHORT      i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
+  USHORT      push2, modeflag, crt2crtc, bridgeoffset;
+  ULONG       longtemp;
   const       UCHAR *PhasePoint;
   const       UCHAR *TimingPoint;
 #ifdef SIS315H
   USHORT      resindex, CRT2Index;
   const       SiS_Part2PortTblStruct *CRT2Part2Ptr = NULL;
-#endif
-#ifdef SIS300
-  const UCHAR atable[] = {
-       0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
-       0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
-  };
-#endif
 
-#ifdef SIS315H   
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
 #endif
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
      crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+  } else if(SiS_Pr->UseCustomMode) {
+     modeflag = SiS_Pr->CModeFlag;
+     crt2crtc = 0;
   } else {
-     if(SiS_Pr->UseCustomMode) {
-        modeflag = SiS_Pr->CModeFlag;
-       crt2crtc = 0;
-     } else {
-        modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-       crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
-     }
+     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
+     crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
   }
 
   temp = 0;
@@ -7395,7 +7011,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
 
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)   tempax = 950;
   else if(SiS_Pr->SiS_TVMode & TVSetPAL)       tempax = 520;
-  else                                                 tempax = 440;
+  else                                                 tempax = 440; /* NTSC, YPbPr 525, 750 */
 
   if( ( (!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) && (SiS_Pr->SiS_VDE <= tempax) ) ||
       ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) &&
@@ -7411,10 +7027,10 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
      temp = tempax + (USHORT)TimingPoint[1];
      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
 
-     if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
+     if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
         if(SiS_Pr->SiS_TVMode & TVSetPAL) {
-           SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x19);
-           SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x52);
+           SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b);  /* 19 */
+           SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54);  /* 52 */
         } else {
            SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17);
            SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d);
@@ -7427,199 +7043,157 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
   if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempcx >>= 1;
   tempcx--;
   if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) tempcx--;
-  temp = tempcx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,temp);
-  temp = (tempcx & 0xFF00) >> 8;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,temp);
-
-  tempcx++;
-  if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) tempcx++;
-  tempcx >>= 1;
-
-  push1 = tempcx;
+  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx);
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f));
 
+  tempcx = SiS_Pr->SiS_HT >> 1;
+  if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempcx >>= 1;
   tempcx += 7;
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
-  temp = (tempcx & 0x00FF) << 4;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,temp);
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0));
 
-  tempbx = TimingPoint[j] | ((TimingPoint[j+1]) << 8);
+  tempbx = TimingPoint[j] | (TimingPoint[j+1] << 8);
   tempbx += tempcx;
-
-  temp = tempbx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,temp);
-  temp = ((tempbx & 0xFF00) >> 8) << 4;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,tempbx);
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,((tempbx >> 4) & 0xf0));
 
   tempbx += 8;
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
      tempbx -= 4;
      tempcx = tempbx;
   }
-  temp = (tempbx & 0x00FF) << 4;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,temp);
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,((tempbx << 4) & 0xf0));
 
   j += 2;
-  tempcx += ((TimingPoint[j] | ((TimingPoint[j+1]) << 8)));
-  temp = tempcx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,temp);
-  temp = ((tempcx & 0xFF00) >> 8) << 4;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,temp);
+  tempcx += (TimingPoint[j] | (TimingPoint[j+1] << 8));
+  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,tempcx);
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,((tempcx >> 4) & 0xf0));
 
   tempcx += 8;
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
-  temp = (tempcx & 0x00FF) << 4;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,temp);
-
-  tempcx = push1;
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0));
 
+  tempcx = SiS_Pr->SiS_HT >> 1;
+  if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempcx >>= 1;
   j += 2;
   tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
-  temp = (tempcx & 0x00FF) << 4;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,temp);
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0));
 
   tempcx -= 11;
   if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
      tempcx = SiS_GetVGAHT2(SiS_Pr) - 1;
   }
-  temp = tempcx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,tempcx);
 
   tempbx = SiS_Pr->SiS_VDE;
-  if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746;
-  if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746;
-  if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853;
-  if(HwInfo->jChipType < SIS_315H) {
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempbx >>= 1;
-  } else {
-     if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
-         (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
-       tempbx >>= 1;
-       if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
-          if(ModeNo <= 0x13) {
-             if(crt2crtc == 1) tempbx++;
-          }
+  if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+     if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746;
+     if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746;
+     if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853;
+  } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
+             (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
+     tempbx >>= 1;
+     if(HwInfo->jChipType >= SIS_315H) {
+        if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
+          if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++;
        } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
-          if(crt2crtc == 4) {
-              if(SiS_Pr->SiS_ModeType <= 3) tempbx++;
+          if(SiS_Pr->SiS_ModeType <= ModeVGA) {
+             if(crt2crtc == 4) tempbx++;
           }
        }
      }
-  }
-  tempbx -= 2;
-  temp = tempbx & 0x00FF;
-  if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
      if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
-        if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) temp++;
-     }
-  }
-
-  if(HwInfo->jChipType < SIS_661) {
-     /* From 1.10.7w - doesn't make sense */
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-        if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
-           if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
-             if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {   /* SetFlag?? */
-                if(ModeNo == 0x03) temp++;
-             }
-          }
+        if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
+          if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) tempbx++;
+       }
+       if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
+          if(ModeNo == 0x03) tempbx++; /* From 1.10.7w - doesn't make sense */
         }
      }
   }
-  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,temp);
+  tempbx -= 2;
+  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,tempbx);
 
   temp = (tempcx >> 8) & 0x0F;
-  temp |= (((tempbx >> 8) << 6) & 0xC0);
-  if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750 | SetCRT2ToSCART))) {
+  temp |= ((tempbx >> 2) & 0xC0);
+  if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
      temp |= 0x10;
-     if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) temp |= 0x20;
+     if(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO) temp |= 0x20;
   }
   SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp);
 
-  if((HwInfo->jChipType > SIS_315H) && (HwInfo->jChipType < SIS_661)) {
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-        if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV | VB_SIS302ELV)) {
-           if( (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) ||
-               (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) ) {
-              SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x10,0x60);
-          }
-        }
+  if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV | VB_SIS302ELV)) {
+     SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5));
+  }
+
+#if 0
+  /* TEST qqqq */
+  if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
+     for(i=0x01, j=0; i<=0x2D; i++, j++) {
+        SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
+     }
+     for(i=0x39; i<=0x45; i++, j++) {
+        SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
      }
   }
+#endif
 
   if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
      tempbx = SiS_Pr->SiS_VDE;
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-        if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) {
-           tempbx >>= 1;
-       }
+     if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
+         (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) {
+        tempbx >>= 1;
      }
      tempbx -= 3;
-     if(HwInfo->jChipType >= SIS_661) {
-        if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV | VB_SIS302ELV)) {  /* Why not 301B/LV? */
-           temp = 0;
-          if(tempcx & 0x0400) temp |= 0x20;
-          if(tempbx & 0x0400) temp |= 0x40;
-          SiS_SetReg(SiS_Pr->SiS_Part4Port,0x10,temp);
-       }
-     }
-     tempbx &= 0x03ff;
-     temp = ((tempbx & 0xFF00) >> 8) << 5;
-     temp |= 0x18;
+     temp = ((tempbx >> 3) & 0x60) | 0x18;
      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp);
-     temp = tempbx & 0x00FF;
-     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,temp);
+     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx);
 
+     if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV | VB_SIS302ELV)) {
+       SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4));
+     }
   }
 
   tempbx = 0;
   if(!(modeflag & HalfDCLK)) {
      if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) {
         tempax = 0;
-        tempbx |= 0x2000;
+        tempbx |= 0x20;
      }
   }
 
-  tempcx = 0x0101;
+  tempch = tempcl = 0x01;
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
      if(SiS_Pr->SiS_VGAHDE >= 1024) {
         if((!(modeflag & HalfDCLK)) || (HwInfo->jChipType < SIS_315H)) {
-           tempcx = 0x1920;
+           tempch = 0x19;
+          tempcl = 0x20;
            if(SiS_Pr->SiS_VGAHDE >= 1280) {
-              tempcx = 0x1420;
-              tempbx &= ~0x2000;
+              tempch = 0x14;
+              tempbx &= ~0x20;
            }
         }
      }
   }
 
-  if(!(tempbx & 0x2000)) {
-     if(modeflag & HalfDCLK) {
-        tempcx = (tempcx & 0xFF00) | ((tempcx << 1) & 0x00FF);
-     }
-     longtemp = (SiS_Pr->SiS_VGAHDE * ((tempcx & 0xFF00) >> 8)) / (tempcx & 0x00FF);
-     longtemp <<= 13;
-     if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-       longtemp <<= 3;
-     }
-     tempeax = longtemp / SiS_Pr->SiS_HDE;
-     if(longtemp % SiS_Pr->SiS_HDE) tempeax++;
-     tempax = (USHORT)tempeax;
-     tempbx |= (tempax & 0x1F00);
-     tempcx = (tempax & 0xFF00) >> (8 + 5);
+  if(!(tempbx & 0x20)) {
+     if(modeflag & HalfDCLK) tempcl <<= 1;
+     longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13;
+     if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) longtemp <<= 3;
+     tempax = longtemp / SiS_Pr->SiS_HDE;
+     if(longtemp % SiS_Pr->SiS_HDE) tempax++;
+     tempbx |= ((tempax >> 8) & 0x1F);
+     tempcx = tempax >> 13;
   }
 
   SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax);
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,(tempbx >> 8));
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx);
 
   if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
 
-     temp = tempcx & 0x0007;
-     if(tempbx & 0x2000) temp = 0;
-     if((HwInfo->jChipType < SIS_661) || (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
-        temp |= 0x18;
-     }
-     SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xE0,temp);
+     tempcx &= 0x07;
+     if(tempbx & 0x20) tempcx = 0;
+     SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xF8,tempcx);
 
      if(SiS_Pr->SiS_TVMode & TVSetPAL) {
         tempbx = 0x0382;
@@ -7628,11 +7202,9 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
         tempbx = 0x0369;
         tempcx = 0x0061;
      }
-     temp = (tempbx & 0x00FF) ;
-     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,temp);
-     temp = (tempcx & 0x00FF) ;
-     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,temp);
-     temp = (tempcx & 0x0300) >> (8 - 2);
+     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,tempbx);
+     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,tempcx);
+     temp = (tempcx & 0x0300) >> 6;
      temp |= ((tempbx >> 8) & 0x03);
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
         temp |= 0x10;
@@ -7642,7 +7214,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4D,temp);
 
      temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
-     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(USHORT)(temp - 3));
+     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(temp - 3));
 
      SiS_SetTVSpecial(SiS_Pr, ModeNo);
 
@@ -7657,7 +7229,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
   if(SiS_Pr->SiS_TVMode & TVSetPALM) {
      if(!(SiS_Pr->SiS_TVMode & TVSetNTSC1024)) {
         temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
-        SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp - 1);
+        SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,(temp - 1));
      }
      SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF);
   }
@@ -7675,13 +7247,11 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
   tempbx = SiS_Pr->SiS_HDE;
   if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
   tempbx--;                                    /* RHACTE = HDE - 1 */
-  temp = tempbx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,temp);
-  temp = (tempbx & 0xFF00) >> 4;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx);
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0));
 
   temp = 0x01;
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
+  if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
      if(SiS_Pr->SiS_ModeType == ModeEGA) {
         if(SiS_Pr->SiS_VGAHDE >= 1024) {
            temp = 0x02;
@@ -7696,49 +7266,19 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
   SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,temp);
 
   tempbx = SiS_Pr->SiS_VDE - 1;
-  temp = tempbx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,temp);
-  temp = ((tempbx & 0xFF00) >> 8) & 0x07;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,tempbx);
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,((tempbx >> 8) & 0x07));
 
   tempcx = SiS_Pr->SiS_VT - 1;
-  temp = tempcx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,temp);
-
-  temp = ((tempcx & 0xFF00) >> 8) << 5;
-
-  /* Enable dithering; only do this for 32bpp mode */
+  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,tempcx);
+  temp = (tempcx >> 3) & 0xE0;
   if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
+     /* Enable dithering; only do this for 32bpp mode */
      if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
         temp |= 0x10;
      }
   }
-
-  /* Must do special for Compaq1280; Acer1280 OK, Clevo1400 OK, COMPAL1400 OK */
-  /* Compaq1280 panel loses sync if using CR37 sync info. */
-  if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
-     if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
-       if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
-          (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024)) {
-          if(SiS_Pr->SiS_LCDInfo & LCDSync) {
-             temp |= ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
-          }
-       } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) &&
-                 (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050)) {
-          temp |= 0x03;
-       } else {
-           temp |= (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) >> 6);
-          temp |= 0x08;
-          if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) temp |= 0x04;
-       }
-     } else {
-        if(SiS_Pr->SiS_LCDInfo & LCDSync) {
-          temp |= ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
-       }
-     }
-  }
-
-  SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1A,temp);
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1A,0x0f,temp);
 
   SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0);
   SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0);
@@ -7746,154 +7286,13 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
   SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
   SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);
 
-#if 0  /* Use the 315/330 series code for now */
-  if((HwInfo->jChipType >= SIS_661)          &&
-     (SiS_Pr->SiS_VBType & VB_SIS301LV302LV) &&
-     (ROMAddr && SiS_Pr->SiS_UseROM)) {
-
-      /* This is done for the LVDS bridges only, since
-       * the TMDS panels already work correctly with
-       * the old code. Besides, we only do that if
-       * we can get the data from the ROM, I am tired
-       * of carrying a lot of tables around.
-       */
-
-#ifdef SIS315H                                                         /* ------------ 661/741/760 series --------- */
-      UCHAR *myptr = NULL, myptr1 = NULL;
-
-      myptr = (UCHAR *)GetLCDPtr661(SiS_Pr, HwInfo, 6, ModeNo, ModeIdIndex, RefreshRateTableIndex);
-      myptr1 = (UCHAR *)GetLCDStructPtr661(SiS_Pr, HwInfo);
-
-      tempbx = (myptr[3] | (myptr[4] << 8)) & 0x0fff;
-      tempcx = SiS_Pr->PanelYRes;
-      if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
-         tempcx = SiS_Pr->SiS_VDE;
-      }
-
-      tempcx += tempbx;
-      if(tempcx >= SiS_Pr->SiS_VT) tempcx -= SiS_Pr->SiS_VT;
-
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempbx);
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempcx);
-
-      tempcx &= 0x07ff;
-      tempbx &= 0x07ff;
-      temp = (tempcx >> 8) << 3;
-      temp |= (tempbx >> 8);
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
-
-      tempbx = (myptr[4] | (myptr[5] << 8)) >> 4;
-      tempcx = myptr1[6];
-      if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempcx = myptr[7];
-
-      tempcx += tempbx;
-      if(tempcx >= SiS_Pr->SiS_VT) tempcx -= SiS_Pr->SiS_VT;
-
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx);
-      temp = tempcx & 0x000f;
-      temp |= ((tempbx & 0x0f00) >> 4);
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
-
-      tempax = SiS_Pr->SiS_HT;
-      tempbx = (myptr[0] | (myptr[1] << 8)) & 0x0fff;
-      tempcx = SiS_Pr->PanelXRes;
-      if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempcx = SiS_Pr->SiS_HDE;
-
-      if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
-         tempax >>= 1;
-        tempbx >>= 1;
-        tempcx >>= 1;
-      }
-      if(SiS_Pr->SiS_VBType & VB_SIS302LV)                 tempbx++;
-      if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) tempbx++;
-
-      tempcx += tempbx;
-      if(tempcx >= tempax) tempcx -= tempax;
-
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,tempbx);
-      temp = ((tempbx & 0xff00) >> 8) << 4;
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x20,temp);
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempcx);
-      temp = tempcx >> 8;
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x25,temp);
-
-      tempax = SiS_Pr->SiS_HT;
-      tempbx = (myptr[1] | (myptr[2] << 8)) >> 4;
-      tempcx = myptr1[5];
-      if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
-         tempcx = myptr[6];
-      }
-      if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
-         tempax >>= 1;
-        tempbx >>= 1;
-        tempcx >>= 1;
-      }
-      if(SiS_Pr->SiS_VBType & VB_SIS302LV) tempbx++;
-
-      tempcx += tempbx;
-      if(tempcx >= tempax) tempcx -= tempax;
-
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1c,tempbx);
-      temp = (tempbx & 0x0f00) >> 4;
-      SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1d,0x0f,temp);
-      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempcx);
-
-      if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
-         if(SiS_Pr->SiS_VGAVDE == 525) {
-           temp = 0xc3;
-           if(SiS_Pr->SiS_ModeType <= ModeVGA) {
-              temp++;
-              if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp += 2;
-           }
-           SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
-           SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
-        } else if(SiS_Pr->SiS_VGAVDE == 420) {
-           temp = 0x4d;
-           if(SiS_Pr->SiS_ModeType <= ModeVGA) {
-              temp++;
-              if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp++;
-           }
-           SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
-        }
-      }
-
-#endif
-
-  } else
-#endif
-         if((HwInfo->jChipType >= SIS_315H)                    &&
-            (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)            &&
-            ((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768)  ||
-             (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) ||
-             (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) ||
-             (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)) ) {
-
-#ifdef SIS315H                                                         /* ------------- 315/330 series ------------ */
-
-      SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
-                          &CRT2Index, &resindex, HwInfo);
-
+#ifdef SIS315H
+  if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
+                                               &CRT2Index, &resindex, HwInfo)) {
       switch(CRT2Index) {
-        case Panel_1024x768      : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;  break;  /* "Normal" */
-        case Panel_1280x1024     : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1280x1024_1; break;
-       case Panel_1400x1050     : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1400x1050_1; break;
-       case Panel_1600x1200     : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1600x1200_1; break;
-        case Panel_1024x768  + 16: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2;  break;  /* Non-Expanding */
-        case Panel_1280x1024 + 16: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1280x1024_2; break;
-       case Panel_1400x1050 + 16: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1400x1050_2; break;
-       case Panel_1600x1200 + 16: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1600x1200_2; break;
-        case Panel_1024x768  + 32: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_3;  break;  /* VESA Timing */
-        case Panel_1280x1024 + 32: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1280x1024_3; break;
-       case Panel_1400x1050 + 32: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1400x1050_3; break;
-       case Panel_1600x1200 + 32: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1600x1200_3; break;
-       case 100:                  CRT2Part2Ptr = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_Compaq1280x1024_1; break;  /* Custom */
-       case 101:                  CRT2Part2Ptr = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_Compaq1280x1024_2; break;
-       case 102:                  CRT2Part2Ptr = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_Compaq1280x1024_3; break;
-       case 103:                  CRT2Part2Ptr = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_Clevo1024x768_1; break;    /* Custom */
-       case 104:                  CRT2Part2Ptr = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_Clevo1024x768_2; break;
-       case 105:                  CRT2Part2Ptr = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_Clevo1024x768_3; break;
-       case 106:                  CRT2Part2Ptr = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_Asus1024x768_3; break;
-       default:                   CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_3;  break;
+        case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;   break;
+       case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3;    break;
+       default:  CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_3;   break;
       }
 
       SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
@@ -7910,58 +7309,34 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
       SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
       SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
 
-      if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
-        if(SiS_Pr->SiS_VGAVDE == 525) {
-         temp = 0xc3;
-         if(SiS_Pr->SiS_ModeType <= ModeVGA) {
-            temp++;
-            if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp += 2;
-         }
-         SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
-         SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
-       } else if(SiS_Pr->SiS_VGAVDE == 420) {
-         temp = 0x4d;
-         if(SiS_Pr->SiS_ModeType <= ModeVGA) {
-            temp++;
-            if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp++;
-         }
-         SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
-       }
-     }
-
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
-          /* See Sync above, 0x1a */
-          temp = 1;
-          if(ModeNo <= 0x13) temp = 3;
-          SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp);
-       }
-     }
-#endif
+      SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
 
-  } else {   /* ------ 300 series and other bridges, other LCD resolutions ------ */
 
-      /* Using this on the 301B with an auto-expanding 1024 panel (CR37=1) makes
-       * the panel scale at modes < 1024 (no black bars); if the panel is non-expanding,
-       * the bridge scales all modes to 1024.
-       * !!! Malfunction at 640x480 and 640x400 when panel is auto-expanding - black screen !!!
-       */
+  } else {
+#endif
 
-    tempcx = SiS_Pr->SiS_VT;
-    tempbx = SiS_Pr->PanelYRes;
+    /* Checked for 1024x768, 1280x1024, 1400x1050, 1600x1200 */
+    /*             Clevo dual-link 1024x768 */
+    /*                    Compaq 1280x1024 has HT 1696 sometimes (calculation OK, if given HT is correct)  */
+    /*            Acer: OK, but uses different setting for VESA timing at 640/800/1024 and 640x400 */
 
     if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-       tempbx = SiS_Pr->SiS_VDE - 1;
-       tempcx--;
-    }
-
-    tempax = 1;
-    if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
-       if(tempbx != SiS_Pr->SiS_VDE) {
-          tempax = tempbx;
-          if(tempax < SiS_Pr->SiS_VDE) {
-             tempax = 0;
-             tempcx = 0;
+       if((SiS_Pr->SiS_LCDInfo & LCDPass11) || (SiS_Pr->PanelYRes == SiS_Pr->SiS_VDE)) {
+          tempbx = SiS_Pr->SiS_VDE - 1;
+          tempcx = SiS_Pr->SiS_VT - 1;
+       } else {
+          tempbx = SiS_Pr->SiS_VDE + ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
+         tempcx = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
+       }
+    } else {
+       tempbx = SiS_Pr->PanelYRes;
+       tempcx = SiS_Pr->SiS_VT;
+       tempax = 1;
+       if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
+          tempax = SiS_Pr->PanelYRes;
+         /* if(SiS_Pr->SiS_VGAVDE == 525) tempax += 0x3c;   */  /* 651+301C */
+          if(SiS_Pr->PanelYRes < SiS_Pr->SiS_VDE) {
+             tempax = tempcx = 0;
           } else {
              tempax -= SiS_Pr->SiS_VDE;
           }
@@ -7971,29 +7346,55 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
        tempbx -= tempax; /* lcdvdee */
     }
 
-    /* Non-expanding: lcdvdees = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
+    /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
 
 #ifdef TWDEBUG
     xf86DrvMsg(0, X_INFO, "lcdvdes 0x%x lcdvdee 0x%x\n", tempcx, tempbx);
 #endif
 
-    temp = tempcx & 0x00FF;                            /* RVEQ1EQ=lcdvdes */
-    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,temp);
-    temp = tempbx & 0x00FF;                            /* RVEQ2EQ=lcdvdee */
-    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,temp);
+    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx);     /* lcdvdes  */
+    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx);     /* lcdvdee  */
 
-    temp = ((tempbx & 0xFF00) >> 8) << 3;
-    temp |= ((tempcx & 0xFF00) >> 8);
+    temp = (tempbx >> 5) & 0x38;
+    temp |= ((tempcx >> 8) & 0x07);
     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
 
-    tempbx = SiS_Pr->SiS_VT;    /* push2; */
-    tempax = SiS_Pr->SiS_VDE;   /* push1; */
-    tempcx = (tempbx - tempax) >> 4;
-    tempbx += tempax;
-    tempbx >>= 1;
-    if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx -= 10;
+    tempax = SiS_Pr->SiS_VDE;
+    if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
+       tempax = SiS_Pr->PanelYRes;
+    }
+    tempcx = (SiS_Pr->SiS_VT - tempax) >> 4;
+    if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
+       if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
+         tempcx = (SiS_Pr->SiS_VT - tempax) / 10;
+       }
+    }
+
+    tempbx = ((SiS_Pr->SiS_VT + SiS_Pr->SiS_VDE) >> 1) - 1;
+    if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+       if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
+          if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { /* ? */
+             tempax = SiS_Pr->SiS_VT - SiS_Pr->PanelYRes;
+            if(tempax % 4) { tempax >>= 2; tempax++; }
+            else           { tempax >>= 2;           }
+             tempbx -= (tempax - 1);
+         } else {
+            tempbx -= 10;
+            if(tempbx <= SiS_Pr->SiS_VDE) tempbx = SiS_Pr->SiS_VDE + 1;
+         }
+       }
+    }
+    if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
+       tempbx++;
+       if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (crt2crtc == 6)) {
+          if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
+            tempbx = 770;
+            tempcx = 3;
+         }
+       }
+    }
 
-    /* non-expanding: lcdvrs = tempbx = ((VT + VDE) / 2) - 10 */
+    /* non-expanding: lcdvrs = ((VT + VDE) / 2) - 10 */
 
     if(SiS_Pr->UseCustomMode) {
        tempbx = SiS_Pr->CVSyncStart;
@@ -8003,12 +7404,11 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
     xf86DrvMsg(0, X_INFO, "lcdvrs 0x%x\n", tempbx);
 #endif
 
-    temp = tempbx & 0x00FF;                            /* RTVACTEE = lcdvrs */
-    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,temp);
+    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx);         /* lcdvrs */
 
-    temp = ((tempbx & 0xFF00) >> 8) << 4;
+    temp = (tempbx >> 4) & 0xF0;
     tempbx += (tempcx + 1);
-    temp |= (tempbx & 0x000F);
+    temp |= (tempbx & 0x0F);
 
     if(SiS_Pr->UseCustomMode) {
        temp &= 0xf0;
@@ -8021,149 +7421,103 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
 
     SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
 
-    /* Code from 630/301B (I+II) BIOS */
-
 #ifdef SIS300
-    if(!SiS_Pr->UseCustomMode) {
-       if( ( ( (HwInfo->jChipType == SIS_630) ||
-               (HwInfo->jChipType == SIS_730) ) &&
-             (HwInfo->jChipRevision > 2) )  &&
-           (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) &&
-           (!(SiS_Pr->SiS_SetFlag & LCDVESATiming))  &&
-           (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
-          if(ModeNo == 0x13) {
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
-          } else {
-             if((crt2crtc & 0x3F) == 4) {
-                SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
-                SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
-                SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
-                SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
-                SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
-             }
-          }
-       }
+    SiS_Group2LCDSpecial(SiS_Pr, HwInfo, ModeNo, crt2crtc);
+#endif
 
-       if(HwInfo->jChipType < SIS_315H) {
-          if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
-             crt2crtc &= 0x1f;
-             tempcx = 0;
-             if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
-                if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
-                   tempcx += 7;
-                }
-             }
-             tempcx += crt2crtc;
-             if(crt2crtc >= 4) {
-                SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
-             }
+    bridgeoffset = 7;
+    if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)          bridgeoffset += 2;
+    if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) bridgeoffset++;
+    if(SiS_IsDualLink(SiS_Pr, HwInfo))                  bridgeoffset++;
 
-             if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
-                if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
-                   if(crt2crtc == 4) {
-                      SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
-                   }
-                }
-             }
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
-          }
+    temp = 0;
+    if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
+       if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
+          temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
+         if(SiS_IsDualLink(SiS_Pr, HwInfo)) temp >>= 1;
        }
     }
-#endif
-
-    tempcx = (SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE) >> 2;     /* (HT - HDE) >> 2 */
-    tempbx = SiS_Pr->SiS_HDE + 7;                        /* lcdhdee         */
-    if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-       tempbx += 2;
+    temp += bridgeoffset;
+    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp);            /* lcdhdes */
+    SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0F,((temp >> 4) & 0xf0));
+
+    tempcx = SiS_Pr->SiS_HT;
+    tempax = tempbx = SiS_Pr->SiS_HDE;
+    if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
+       if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
+          tempax = SiS_Pr->PanelXRes;
+          tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
+       }
+    }
+    if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
+       tempcx >>= 1;
+       tempbx >>= 1;
+       tempax >>= 1;
     }
-    push1 = tempbx;
 
 #ifdef TWDEBUG
     xf86DrvMsg(0, X_INFO, "lcdhdee 0x%x\n", tempbx);
 #endif
 
-    temp = tempbx & 0x00FF;                                      /* RHEQPLE = lcdhdee */
-    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,temp);
-    temp = (tempbx & 0xFF00) >> 8;
-    SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,temp);
+    tempbx += bridgeoffset;
 
-    temp = 7;
-    if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-       temp += 2;
-    }
-    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp);         /* RHBLKE = lcdhdes[7:0] */
-    SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x20,0x0F);      /* lcdhdes [11:8] */
+    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx);         /* lcdhdee */
+    SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,((tempbx >> 8) & 0x0f));
+
+    tempcx = (tempcx - tempax) >> 2;
 
     tempbx += tempcx;
     push2 = tempbx;
 
-    if(SiS_Pr->UseCustomMode) {
-       tempbx = SiS_Pr->CHSyncStart + 7;
-       if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-          tempbx += 2;
+    if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
+       if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
+          if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
+             if(SiS_Pr->SiS_HDE == 1280) tempbx = (tempbx & 0xff00) | 0x47;
+         }
        }
     }
 
+    if(SiS_Pr->UseCustomMode) {
+       tempbx = SiS_Pr->CHSyncStart;
+       if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
+       tempbx += bridgeoffset;
+    }
+
 #ifdef TWDEBUG
     xf86DrvMsg(0, X_INFO, "lcdhrs 0x%x\n", tempbx);
 #endif
 
-    temp = tempbx & 0x00FF;                                      /* RHBURSTS = lcdhrs */
-    if(!SiS_Pr->UseCustomMode) {
-       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-          if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
-             if(SiS_Pr->SiS_HDE == 1280) temp = 0x47;
-          }
-       }
-    }
-    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,temp);
-    temp = (tempbx & 0x0F00) >> 4;
-    SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,temp);
+    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx);         /* lcdhrs */
+    SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
 
     tempbx = push2;
+
     tempcx <<= 1;
+    if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
+       if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) tempcx >>= 2;
+    }
     tempbx += tempcx;
 
     if(SiS_Pr->UseCustomMode) {
-       tempbx = SiS_Pr->CHSyncEnd + 7;
-       if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-          tempbx += 2;
-       }
+       tempbx = SiS_Pr->CHSyncEnd;
+       if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
+       tempbx += bridgeoffset;
     }
 
 #ifdef TWDEBUG
     xf86DrvMsg(0, X_INFO, "lcdhre 0x%x\n", tempbx);
 #endif
 
-    temp = tempbx & 0x00FF;                                      /* RHSYEXP2S = lcdhre */
-    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,temp);
-
-    if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
-       if(SiS_Pr->SiS_VGAVDE == 525) {
-          if(SiS_Pr->SiS_ModeType <= ModeVGA)
-            temp=0xC6;
-          else
-                    temp=0xC3;
-          SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
-          SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xB3);
-       } else if(SiS_Pr->SiS_VGAVDE == 420) {
-          if(SiS_Pr->SiS_ModeType <= ModeVGA)
-            temp=0x4F;
-          else
-                    temp=0x4D;
-          SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
-       }
-    }
+    SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx);         /* lcdhre */
+
+    SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
 
 #ifdef SIS300
-    SiS_Set300Part2Regs(SiS_Pr, HwInfo, ModeIdIndex,
-                        RefreshRateTableIndex, ModeNo);
+    SiS_Set300Part2Regs(SiS_Pr, HwInfo, ModeIdIndex, RefreshRateTableIndex, ModeNo);
+#endif
+#ifdef SIS315H
+  } /* CRT2-LCD from table */
 #endif
-
-  } /* HwInfo */
 }
 
 /*********************************************/
@@ -8174,26 +7528,14 @@ static void
 SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
               PSIS_HW_INFO HwInfo)
 {
-  USHORT modeflag, i;
-  const UCHAR  *tempdi;
+  USHORT       i;
+  const UCHAR          *tempdi;
 
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
 
-  if(ModeNo<=0x13) {
-     modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-  } else {
-     if(SiS_Pr->UseCustomMode) {
-        modeflag = SiS_Pr->CModeFlag;
-     } else {
-       modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-     }
-  }
-
 #ifndef SIS_CP
   SiS_SetReg(SiS_Pr->SiS_Part3Port,0x00,0x00);
-#endif
-
-#ifdef SIS_CP
+#else
   SIS_CP_INIT301_CP
 #endif
 
@@ -8216,11 +7558,6 @@ SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      tempdi = SiS_Pr->SiS_HiTVGroup3Data;
      if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
         tempdi = SiS_Pr->SiS_HiTVGroup3Simu;
-#if 0
-        if(!(modeflag & Charx8Dot)) {
-           tempdi = SiS_Pr->SiS_HiTVGroup3Text;
-        }
-#endif
      }
   } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
      if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
@@ -8229,7 +7566,7 @@ SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      }
   }
   if(tempdi) {
-     for(i=0; i<=0x3E; i++){
+     for(i=0; i<=0x3E; i++) {
         SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]);
      }
      if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) {
@@ -8239,11 +7576,9 @@ SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      }
   }
 
-  if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) {
 #ifdef SIS_CP
-     SIS_CP_INIT301_CP2
+  SIS_CP_INIT301_CP2
 #endif
-  }
 }
 
 /*********************************************/
@@ -8252,43 +7587,81 @@ SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
 #ifdef SIS315H
 static void
-SiS_SetGroup4_C_ELV(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
+SiS_ShiftXPos(SiS_Private *SiS_Pr, int shift)
 {
-   USHORT temp, temp1;
+   USHORT temp, temp1, temp2;
 
-   if(!(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV))) return;
+   temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f);
+   temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20);
+   temp = (USHORT)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
+   SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp);
+   SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0));
+   temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f;
+   temp = (USHORT)((int)(temp) + shift);
+   SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f));
+   temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
+   temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42);
+   temp = (USHORT)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
+   SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp);
+   SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0));
+}
+
+static void
+SiS_SetGroup4_C_ELV(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
+                    USHORT ModeNo, USHORT ModeIdIndex)
+{
+   USHORT temp, temp1, resinfo = 0;
+
+   if(!(SiS_Pr->SiS_VBType & VB_SIS301C)) return;
+   if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return;
+
+   if(ModeNo > 0x13) {
+      resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
+   }
 
    SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3a,0x08);
    temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x3a);
    if(!(temp & 0x01)) {
       SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf);
       SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc);
-      if(HwInfo->jChipType < SIS_661) {
+      if((HwInfo->jChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) {
          SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8);
       }
       SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb);
-      temp = 0;
-      if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr750p)) {
-         temp |= 0x0002;
-         if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525p)) {
-           temp ^= 0x0402;
-           if(!(SiS_Pr->SiS_TVMode & TVSetHiVision)) {
-              temp ^= 0x0002;
-           }
-        }
-      }
-      if(HwInfo->jChipType >= SIS_661) {
-         temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
-         if(temp1 & 0x01) temp |= 0x10;
-         if(temp1 & 0x02) temp |= 0x01;
-        SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xec,(temp & 0xff));
+      if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p)      temp = 0x0000;
+      else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002;
+      else if(SiS_Pr->SiS_TVMode & TVSetHiVision)  temp = 0x0400;
+      else                                        temp = 0x0402;
+      if((HwInfo->jChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
+         temp1 = 0;
+        if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4;
+        SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1);
+        if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01;
+        SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff));
       } else {
          temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03;
         if(temp1 == 0x01) temp |= 0x01;
         if(temp1 == 0x03) temp |= 0x04;  /* ? why not 0x10? */
-        SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xea,(temp & 0xff));
+        SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff));
       }
       SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
+      if(ModeNo > 0x13) {
+         SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd);
+      }
+
+      if(HwInfo->jChipType >= SIS_661) {               /* ? */
+         if(SiS_Pr->SiS_TVMode & TVAspect43) {
+            if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
+              if(resinfo == SIS_RI_1024x768) {
+                 SiS_ShiftXPos(SiS_Pr, 97);
+              } else {
+                 SiS_ShiftXPos(SiS_Pr, 111);
+              }
+           } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
+              SiS_ShiftXPos(SiS_Pr, 136);
+           }
+         }
+      }
    }
 }
 #endif
@@ -8330,25 +7703,22 @@ SiS_SetCRT2VCLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
   SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,temp);
 }
 
-/* Set 301 VGA2 registers */
 static void
 SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
              USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
 {
-  USHORT tempax,tempcx,tempbx,modeflag,temp,temp2,resinfo;
+  USHORT tempax,tempcx,tempbx,modeflag,temp,resinfo;
   ULONG tempebx,tempeax,templong;
 
   if(ModeNo <= 0x13) {
      modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
      resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
+  } else if(SiS_Pr->UseCustomMode) {
+     modeflag = SiS_Pr->CModeFlag;
+     resinfo = 0;
   } else {
-     if(SiS_Pr->UseCustomMode) {
-        modeflag = SiS_Pr->CModeFlag;
-       resinfo = 0;
-     } else {
-       modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-       resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
-     }
+     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
+     resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
   }
 
   if(HwInfo->jChipType >= SIS_315H) {
@@ -8370,187 +7740,154 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
         if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
           if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
              SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
+          } else {
+             SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
           }
-#ifdef SET_EMI
+
           if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
              SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
+#ifdef SET_EMI
              SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
+#endif
              SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
           }
-#endif
        }
        return;
      }
   }
 
-  temp = SiS_Pr->SiS_RVBHCFACT;
-  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,SiS_Pr->SiS_RVBHCFACT);
 
   tempbx = SiS_Pr->SiS_RVBHCMAX;
-  temp = tempbx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,tempbx);
 
-  temp2 = (((tempbx & 0xFF00) >> 8) << 7) & 0x00ff;
+  temp = (tempbx >> 1) & 0x80;
 
   tempcx = SiS_Pr->SiS_VGAHT - 1;
-  temp = tempcx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,tempcx);
 
-  temp = (((tempcx & 0xFF00) >> 8) << 3) & 0x00ff;
-  temp2 |= temp;
+  temp |= ((tempcx >> 5) & 0x78);
 
   tempcx = SiS_Pr->SiS_VGAVT - 1;
-  if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV))  tempcx -= 5;
+  if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5;
+  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,tempcx);
 
-  temp = tempcx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,temp);
-
-  temp = temp2 | ((tempcx & 0xFF00) >> 8);
+  temp |= ((tempcx >> 8) & 0x07);
   SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp);
 
   tempbx = SiS_Pr->SiS_VGAHDE;
-  if(modeflag & HalfDCLK)  tempbx >>= 1;
-  if(HwInfo->jChipType >= SIS_661) {
-     if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
-  }
+  if(modeflag & HalfDCLK)            tempbx >>= 1;
+  if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
 
-  temp = 0xA0;
-  if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
+  if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
      temp = 0;
-     if(tempbx > 800) {
-        temp = 0xA0;
-        if(tempbx != 1024) {
-           temp = 0xC0;
-           if(tempbx != 1280) temp = 0;
-       }
-     }
-  } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-     if(tempbx <= 800) {
-        temp = 0x80;
-     }
+     if(tempbx > 800)        temp = 0x60;
+  } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
+     temp = 0;
+     if(tempbx == 1024)      temp = 0xA0;
+     else if(tempbx > 1024)  temp = 0xC0;
+  } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
+     temp = 0;
+     if(tempbx >= 1280)      temp = 0x40;
+     else if(tempbx >= 1024) temp = 0x20;
   } else {
      temp = 0x80;
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-        temp = 0;
-        if(tempbx > 800) temp = 0x60;
-     }
-  }
-
-  if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
-     temp = 0;
-     if(SiS_Pr->SiS_VGAHDE == 1024) temp = 0x20;
-  }
-
-  if(HwInfo->jChipType < SIS_661) {
-     if(SiS_IsDualLink(SiS_Pr, HwInfo)) temp = 0;
+     if(tempbx >= 1024)      temp = 0xA0;
   }
 
   if(SiS_Pr->SiS_VBType & VB_SIS301) {
-     if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024)
-        temp |= 0x0A;
+     if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) temp |= 0x0A;
   }
 
   SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp);
 
+  tempeax = SiS_Pr->SiS_VGAVDE;
   tempebx = SiS_Pr->SiS_VDE;
-
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
      if(!(temp & 0xE0)) tempebx >>=1;
   }
 
   tempcx = SiS_Pr->SiS_RVBHRS;
-  temp = tempcx & 0x00FF;
-  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,temp);
+  SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,tempcx);
+  tempcx >>= 8;
+  tempcx |= 0x40;
 
-  tempeax = SiS_Pr->SiS_VGAVDE;
-  tempcx |= 0x4000;
   if(tempeax <= tempebx) {
-     tempcx ^= 0x4000;
+     tempcx ^= 0x40;
   } else {
      tempeax -= tempebx;
   }
 
-  templong = (tempeax * 256 * 1024) % tempebx;
-  tempeax = (tempeax * 256 * 1024) / tempebx;
-  tempebx = tempeax;
-  if(templong != 0) tempebx++;
+  tempeax *= (256 * 1024);
+  templong = tempeax % tempebx;
+  tempeax /= tempebx;
+  if(templong) tempeax++;
 
-  temp = (USHORT)(tempebx & 0x000000FF);
+  temp = (USHORT)(tempeax & 0x000000FF);
   SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp);
-  temp = (USHORT)((tempebx & 0x0000FF00) >> 8);
+  temp = (USHORT)((tempeax & 0x0000FF00) >> 8);
   SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp);
-
-  tempbx = (USHORT)(tempebx >> 16);
-  temp = tempbx & 0x00FF;
-  temp <<= 4;
-  temp |= ((tempcx & 0xFF00) >> 8);
+  temp = (USHORT)((tempeax >> 12) & 0x70); /* sic! */
+  temp |= (tempcx & 0x4F);
   SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp);
 
   if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
 
      SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28);
 
+     /* Calc Linebuffer max address and set/clear decimode */
      tempbx = 0;
+     if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08;
      tempax = SiS_Pr->SiS_VGAHDE;
-     if(modeflag & HalfDCLK)           tempax >>= 1;
+     if(modeflag & HalfDCLK)            tempax >>= 1;
      if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempax >>= 1;
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-       if(tempax > 800) tempax -= 800;
-     } else {
-        if(tempax > 800) {
-          tempbx = 8;
-           if(tempax == 1024)
-             tempax *= 25;
-           else
-             tempax *= 20;
-
+     if(tempax > 800) {
+        if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+          tempax -= 800;
+       } else {  /* 651+301C: Only if TVNoHiviNoYPbPr */
+          tempbx = 0x08;
+           if(tempax == 1024) tempax *= 25;
+           else                      tempax *= 20;
           temp = tempax % 32;
           tempax /= 32;
-          tempax--;
-          if (temp!=0) tempax++;
-        }
+          if(temp) tempax++;
+          tempax++;
+          if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) ||
+             (SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
+             if(resinfo == SIS_RI_1024x768) {
+                /* Otherwise white line at right edge */
+                tempax = (tempax & 0xff00) | 0x20;
+             }
+          }
+       }
      }
      tempax--;
-     temp = ((tempax & 0xFF00) >> 8) & 0x03;
-     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {                    /* From 1.10.7w */
-       if(ModeNo > 0x13) {                                     /* From 1.10.7w */
-          if(resinfo == SIS_RI_1024x768) tempax = 0x1f;        /* From 1.10.7w */
-       }                                                       /* From 1.10.7w */
-     }                                                         /* From 1.10.7w */
-     SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax & 0x00FF);
-     temp <<= 4;
-     temp |= tempbx;
+     temp = ((tempax >> 4) & 0x30) | tempbx;
+     SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax);
      SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp);
 
-     if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
-       if(IS_SIS550650740660) {
-          temp = 0x0026;  /* 1.10.7w; 1.10.8r; needs corresponding code in Dis/EnableBridge! */
-       } else {
-          temp = 0x0036;
-       }
-     } else {
-       temp = 0x0036;
+     temp = 0x0036; tempbx = 0xD0;
+     if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
+       temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */
      }
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
         if(!(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetHiVision | TVSetYPbPr750p | TVSetYPbPr525p))) {
           temp |= 0x01;
           if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
              if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
-                temp &= 0xFE;
+                temp &= ~0x01;
              }
           }
        }
      }
-     SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0,temp);
+     SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp);
 
-     tempbx = SiS_Pr->SiS_HT;
+     tempbx = SiS_Pr->SiS_HT >> 1;
      if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
-     tempbx >>= 1;
      tempbx -= 2;
-     temp = ((tempbx & 0x0700) >> 8) << 3;
+     SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx);
+     temp = (tempbx >> 5) & 0x38;
      SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp);
-     temp = tempbx & 0x00FF;
-     SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,temp);
 
      if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
        if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
@@ -8560,15 +7897,17 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
        if(HwInfo->jChipType >= SIS_315H) {
           if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
              SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
+          } else {
+             SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
           }
        }
-#ifdef SET_EMI
        if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
           SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
+#ifdef SET_EMI
           SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
+#endif
           SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
        }
-#endif
      }
 
   }  /* 301B */
@@ -8580,7 +7919,6 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 /*         SET PART 5 REGISTER GROUP         */
 /*********************************************/
 
-/* Set 301 Palette address port registers */
 static void
 SiS_SetGroup5(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
               PSIS_HW_INFO HwInfo)
@@ -8590,7 +7928,7 @@ SiS_SetGroup5(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
   if(SiS_Pr->SiS_ModeType == ModeVGA) {
      if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) {
-        SiS_EnableCRT2(SiS_Pr);
+        SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
         SiS_LoadDAC(SiS_Pr, HwInfo, ModeNo, ModeIdIndex);
      }
   }
@@ -8608,11 +7946,8 @@ SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
   USHORT ResIndex,DisplayType;
   const SiS_LVDSCRT1DataStruct *LVDSCRT1Ptr=NULL;
 
-  if(ModeNo <= 0x13) {
-     modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-  } else {
-     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-  }
+  if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
+  else               modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
 
   if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
      (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
@@ -8620,7 +7955,9 @@ SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      return;
 
   if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
-                          &ResIndex, &DisplayType))) return;
+                          &ResIndex, &DisplayType))) {
+     return;
+  }
 
   if(HwInfo->jChipType < SIS_315H) {
      if(SiS_Pr->SiS_SetFlag & SetDOSMode) return;
@@ -8628,16 +7965,16 @@ SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
   switch(DisplayType) {
     case 0 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1;           break;
-    case 1 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1;          break;
-    case 2 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1;         break;
-    case 3 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1_H;         break;
-    case 4 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1_H;        break;
-    case 5 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1_H;       break;
-    case 6 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2;           break;
-    case 7 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2;          break;
-    case 8 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2;         break;
-    case 9 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2_H;         break;
-    case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2_H;        break;
+    case 1 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1_H;         break;
+    case 2 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2;           break;
+    case 3 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2_H;         break;
+    case 4 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1;          break;
+    case 5 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1_H;        break;
+    case 6 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2;          break;
+    case 7 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2_H;        break;
+    case 8 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1;         break;
+    case 9 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1_H;       break;
+    case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2;         break;
     case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2_H;       break;
     case 12: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1;           break;
     case 13: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H;         break;
@@ -8676,7 +8013,7 @@ SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
     default: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1;          break;
   }
 
-  SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);                        /*unlock cr0-7  */
+  SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
 
   tempah = (LVDSCRT1Ptr + ResIndex)->CR[0];
   SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,tempah);
@@ -8711,12 +8048,6 @@ SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
   tempah <<= 5;
   if(modeflag & DoubleScanMode)  tempah |= 0x080;
   SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
-
-  /* 650/LVDS BIOS - doesn't make sense */
-  if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-     if(modeflag & HalfDCLK)
-        SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
-  }
 }
 
 /*********************************************/
@@ -8731,7 +8062,7 @@ SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
   USHORT clkbase, vclkindex=0;
   UCHAR  sr2b, sr2c;
 
-  if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) || (SiS_Pr->SiS_IF_DEF_TRUMPION == 1)) {
+  if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) || (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
        SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
         if((SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK & 0x3f) == 2) {
           RefreshRateTableIndex--;
@@ -8748,7 +8079,7 @@ SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
   sr2c = SiS_Pr->SiS_VCLKData[vclkindex].SR2C;
 
   if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
-     if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+     if(SiS_Pr->SiS_UseROM) {
        if(ROMAddr[0x220] & 0x01) {
            sr2b = ROMAddr[0x227];
           sr2c = ROMAddr[0x228];
@@ -8763,7 +8094,6 @@ SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      }
   }
 
-  SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
   SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20);
   SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
   SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
@@ -8783,14 +8113,17 @@ static void
 SiS_SetCHTVReg(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                USHORT RefreshRateTableIndex)
 {
-  USHORT temp, tempbx, tempcl;
+#if defined(SIS300) || defined(SIS315H)
+  USHORT temp, tempbx;
+#endif
+  USHORT tempcl;
   USHORT TVType, resindex;
   const SiS_CHTVRegDataStruct *CHTVRegData = NULL;
 
   if(ModeNo <= 0x13)
-       tempcl = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+     tempcl = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
   else
-       tempcl = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
+     tempcl = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
 
   TVType = 0;
   if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
@@ -8808,16 +8141,16 @@ SiS_SetCHTVReg(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
        }
   }
   switch(TVType) {
-       case  0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
-       case  1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
-       case  2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL;  break;
-       case  3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL;  break;
-       case  4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
-       case  5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
-       case  6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
-       case  7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
-       case  8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
-       default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL;  break;
+     case  0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
+     case  1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
+     case  2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL;  break;
+     case  3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL;  break;
+     case  4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
+     case  5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
+     case  6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
+     case  7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
+     case  8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
+     default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL;  break;
   }
   resindex = tempcl & 0x3F;
 
@@ -9089,21 +8422,21 @@ SiS_ChrontelPowerSequencing(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
   /* Set up Power up/down timing */
 
   if(HwInfo->jChipType == SIS_740) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
         if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740;
         else                                     tableptr = table1024_740;
-     } else if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) ||
-               (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) ||
-              (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)) {
+     } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
+               (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
+              (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
        if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740;
         else                                     tableptr = table1400_740;
      } else return;
   } else {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
         tableptr = table1024_650;
-     } else if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) ||
-               (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) ||
-              (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200)) {
+     } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
+               (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
+              (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
         tableptr = table1400_650;
      } else return;
   }
@@ -9139,45 +8472,35 @@ SiS_SetCH701xForLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
   int i;
 
   if(HwInfo->jChipType == SIS_740) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-        tableptr = table1024_740;
-     } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-        tableptr = table1280_740;
-     } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
-        tableptr = table1400_740;
-     } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) {
-        tableptr = table1600_740;
-     } else return;
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768)       tableptr = table1024_740;
+     else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740;
+     else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740;
+     else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_740;
+     else return;
   } else {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-        tableptr = table1024_650;
-     } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
-        tableptr = table1280_650;
-     } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
-        tableptr = table1400_650;
-     } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) {
-        tableptr = table1600_650;
-     } else return;
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768)       tableptr = table1024_650;
+     else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_650;
+     else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_650;
+     else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_650;
+     else return;
   }
 
   tempbh = SiS_GetCH701x(SiS_Pr,0x74);
   if((tempbh == 0xf6) || (tempbh == 0xc7)) {
      tempbh = SiS_GetCH701x(SiS_Pr,0x73);
      if(tempbh == 0xc8) {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) return;
+        if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) return;
      } else if(tempbh == 0xdb) {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) return;
-       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) return;
+        if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) return;
+       if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) return;
      } else if(tempbh == 0xde) {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) return;
+        if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) return;
      }
   }
 
-  if(HwInfo->jChipType == SIS_740) {
-     tempbh = 0x0d;
-  } else {
-     tempbh = 0x0c;
-  }
+  if(HwInfo->jChipType == SIS_740) tempbh = 0x0d;
+  else                            tempbh = 0x0c;
+
   for(i = 0; i < tempbh; i++) {
      SiS_SetCH701x(SiS_Pr,(tableptr[i] << 8) | regtable[i]);
   }
@@ -9217,7 +8540,7 @@ SiS_ChrontelResetVSync(SiS_Private *SiS_Pr)
   SiS_SetCH701x(SiS_Pr,(temp1 << 8) | 0x49);
 }
 
-void
+static void
 SiS_Chrontel701xOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
   USHORT temp;
@@ -9262,7 +8585,7 @@ SiS_Chrontel701xOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
   }
 }
 
-void
+static void
 SiS_Chrontel701xOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
   USHORT temp;
@@ -9335,7 +8658,7 @@ SiS_ChrontelResetDB(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
      }
 }
 
-void
+static void
 SiS_ChrontelInitTVVSync(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
      USHORT temp;
@@ -9461,7 +8784,7 @@ SiS_ChrontelDoSomething2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
     SiS_SetCH701x(SiS_Pr,0x0077);  /* MV? */
 }
 
-void
+static void
 SiS_ChrontelDoSomething1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
      USHORT temp;
@@ -9564,13 +8887,12 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
 
    SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
 
-   /* Set up Panel Link for LVDS, 301BDH and 30xLV(for LCDA) */
+   /* Set up Panel Link for LVDS and LCDA */
+   SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
    if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
        ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ||
        ((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) ) {
       SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
-   } else {
-      SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
    }
 
 #ifdef LINUX_XF86
@@ -9598,13 +8920,15 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
           SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex, HwInfo);
           SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
 #ifdef SIS315H
-          SiS_SetGroup4_C_ELV(SiS_Pr, HwInfo);
+          SiS_SetGroup4_C_ELV(SiS_Pr, HwInfo, ModeNo, ModeIdIndex);
 #endif
           SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex, HwInfo);
 
+          SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex, HwInfo);
+
           /* For 301BDH (Panel link initialization): */
           if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
-             if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
+             if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) {
                 if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) {
                    if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
                       SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,
@@ -9619,15 +8943,13 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
 
    } else {
 
-        if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) {
-          if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
-             SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,
-                             RefreshRateTableIndex,HwInfo);
-          }
+        SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex, HwInfo);
+
+        if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+          SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,HwInfo);
        }
 
-        SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,
-                       RefreshRateTableIndex,HwInfo);
+        SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,HwInfo);
 
        if(SiS_Pr->SiS_SetFlag & LowModeTests) {
           if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
@@ -9639,8 +8961,7 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
                 }
              }
              if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
-                        SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,
-                              RefreshRateTableIndex);
+                        SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
              }
           }
        }
@@ -9651,7 +8972,7 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
    if(HwInfo->jChipType < SIS_315H) {
       if(SiS_Pr->SiS_SetFlag & LowModeTests) {
         if(SiS_Pr->SiS_UseOEM) {
-           if((SiS_Pr->SiS_UseROM) && ROMAddr && (SiS_Pr->SiS_UseOEM == -1)) {
+           if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) {
               if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
                  SiS_OEM300Setting(SiS_Pr,HwInfo,ModeNo,ModeIdIndex,
                                    RefreshRateTableIndex);
@@ -9666,16 +8987,9 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
               (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
               SetOEMLCDData2(SiS_Pr, HwInfo, ModeNo, ModeIdIndex,RefreshRateTableIndex);
            }
-            if(HwInfo->jChipType == SIS_730) {
-               SiS_DisplayOn(SiS_Pr);
-           }
+           SiS_DisplayOn(SiS_Pr);
          }
       }
-      if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
-          if(HwInfo->jChipType != SIS_730) {
-             SiS_DisplayOn(SiS_Pr);
-         }
-      }
    }
 #endif
 
@@ -9684,13 +8998,11 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
       if(SiS_Pr->SiS_SetFlag & LowModeTests) {
         if(HwInfo->jChipType < SIS_661) {
            SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex, HwInfo);
-            if(SiS_Pr->SiS_UseOEM) {
-               SiS_OEM310Setting(SiS_Pr, HwInfo, ModeNo, ModeIdIndex);
-            }
+            SiS_OEM310Setting(SiS_Pr, HwInfo, ModeNo, ModeIdIndex, RefreshRateTableIndex);
         } else {
            SiS_OEM661Setting(SiS_Pr, HwInfo, ModeNo, ModeIdIndex, RefreshRateTableIndex);
         }
-         SiS_CRT2AutoThreshold(SiS_Pr);
+         SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
       }
    }
 #endif
@@ -9761,6 +9073,63 @@ SiS_SetupDDCN(SiS_Private *SiS_Pr)
   }
 }
 
+#ifdef SIS300
+static UCHAR *
+SiS_SetTrumpBlockLoop(SiS_Private *SiS_Pr, UCHAR *dataptr)
+{
+  int i, j, num;
+  USHORT tempah,temp;
+  UCHAR *mydataptr;
+
+  for(i=0; i<20; i++) {                                /* Do 20 attempts to write */
+     mydataptr = dataptr;
+     num = *mydataptr++;
+     if(!num) return mydataptr;
+     if(i) {
+        SiS_SetStop(SiS_Pr);
+       SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT*2);
+     }
+     if(SiS_SetStart(SiS_Pr)) continue;                /* Set start condition */
+     tempah = SiS_Pr->SiS_DDC_DeviceAddr;
+     temp = SiS_WriteDDC2Data(SiS_Pr,tempah);  /* Write DAB (S0=0=write) */
+     if(temp) continue;                                /*    (ERROR: no ack) */
+     tempah = *mydataptr++;
+     temp = SiS_WriteDDC2Data(SiS_Pr,tempah);  /* Write register number */
+     if(temp) continue;                                /*    (ERROR: no ack) */
+     for(j=0; j<num; j++) {
+        tempah = *mydataptr++;
+        temp = SiS_WriteDDC2Data(SiS_Pr,tempah);/* Write DAB (S0=0=write) */
+       if(temp) break;
+     }
+     if(temp) continue;
+     if(SiS_SetStop(SiS_Pr)) continue;
+     return mydataptr;
+  }
+  return NULL;
+}
+
+static BOOLEAN
+SiS_SetTrumpionBlock(SiS_Private *SiS_Pr, UCHAR *dataptr)
+{
+  SiS_Pr->SiS_DDC_DeviceAddr = 0xF0;           /* DAB (Device Address Byte) */
+  SiS_Pr->SiS_DDC_Index = 0x11;                        /* Bit 0 = SC;  Bit 1 = SD */
+  SiS_Pr->SiS_DDC_Data  = 0x02;                /* Bitmask in IndexReg for Data */
+  SiS_Pr->SiS_DDC_Clk   = 0x01;                /* Bitmask in IndexReg for Clk */
+  SiS_SetupDDCN(SiS_Pr);
+
+  SiS_SetSwitchDDC2(SiS_Pr);
+
+  while(*dataptr) {
+     dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
+     if(!dataptr) return FALSE;
+  }
+#ifdef TWDEBUG
+  xf86DrvMsg(0, X_INFO, "Trumpion block success\n");
+#endif
+  return TRUE;
+}
+#endif
+
 /* The Chrontel 700x is connected to the 630/730 via
  * the 630/730's DDC/I2C port.
  *
@@ -9796,6 +9165,22 @@ SiS_SetChReg(SiS_Private *SiS_Pr, USHORT tempbx, USHORT myor)
   return FALSE;
 }
 
+#if 0
+#ifdef SIS300
+/* Write Trumpion register */
+static void
+SiS_SetTrumpReg(SiS_Private *SiS_Pr, USHORT tempbx)
+{
+  SiS_Pr->SiS_DDC_DeviceAddr = 0xF0;           /* DAB (Device Address Byte) */
+  SiS_Pr->SiS_DDC_Index = 0x11;                        /* Bit 0 = SC;  Bit 1 = SD */
+  SiS_Pr->SiS_DDC_Data  = 0x02;                /* Bitmask in IndexReg for Data */
+  SiS_Pr->SiS_DDC_Clk   = 0x01;                /* Bitmask in IndexReg for Clk */
+  SiS_SetupDDCN(SiS_Pr);
+  SiS_SetChReg(SiS_Pr, tempbx, 0);
+}
+#endif
+#endif
+
 /* Write to Chrontel 700x */
 /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
 void
@@ -9831,17 +9216,16 @@ SiS_SetCH701x(SiS_Private *SiS_Pr, USHORT tempbx)
   SiS_Pr->SiS_DDC_Clk   = 0x04;                 /* Bitmask in IndexReg for Clk */
   SiS_SetupDDCN(SiS_Pr);
   SiS_Pr->SiS_DDC_DeviceAddr = 0xEA;           /* DAB (Device Address Byte) */
-
   SiS_SetChReg(SiS_Pr, tempbx, 0);
 }
 
 void
 SiS_SetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx)
 {
-   if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
-      SiS_SetCH700x(SiS_Pr,tempbx);
-   else
-      SiS_SetCH701x(SiS_Pr,tempbx);
+  if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
+     SiS_SetCH700x(SiS_Pr,tempbx);
+  else
+     SiS_SetCH701x(SiS_Pr,tempbx);
 }
 
 static USHORT
@@ -9873,6 +9257,23 @@ SiS_GetChReg(SiS_Private *SiS_Pr, USHORT myor)
   return 0xFFFF;
 }
 
+#if 0
+#ifdef SIS300
+/* Read from Trumpion */
+static USHORT
+SiS_GetTrumpReg(SiS_Private *SiS_Pr, USHORT tempbx)
+{
+  SiS_Pr->SiS_DDC_DeviceAddr = 0xF0;   /* DAB */
+  SiS_Pr->SiS_DDC_Index = 0x11;                /* Bit 0 = SC;  Bit 1 = SD */
+  SiS_Pr->SiS_DDC_Data  = 0x02;         /* Bitmask in IndexReg for Data */
+  SiS_Pr->SiS_DDC_Clk   = 0x01;         /* Bitmask in IndexReg for Clk */
+  SiS_SetupDDCN(SiS_Pr);
+  SiS_Pr->SiS_DDC_ReadAddr = tempbx;
+  return(SiS_GetChReg(SiS_Pr,0));
+}
+#endif
+#endif
+
 /* Read from Chrontel 700x */
 /* Parameter is [Register no (S7-S0)] */
 USHORT
@@ -9925,14 +9326,14 @@ SiS_GetCH701x(SiS_Private *SiS_Pr, USHORT tempbx)
 USHORT
 SiS_GetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx)
 {
-   if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
-      return(SiS_GetCH700x(SiS_Pr, tempbx));
-   else
-      return(SiS_GetCH701x(SiS_Pr, tempbx));
+  if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
+     return(SiS_GetCH700x(SiS_Pr, tempbx));
+  else
+     return(SiS_GetCH701x(SiS_Pr, tempbx));
 }
 
 /* Our own DDC functions */
-USHORT
+static USHORT
 SiS_InitDDCRegs(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
                 USHORT adaptnum, USHORT DDCdatatype, BOOLEAN checkcr32)
 {
@@ -10046,7 +9447,7 @@ SiS_InitDDCRegs(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
     return 0;
 }
 
-USHORT
+static USHORT
 SiS_WriteDABDDC(SiS_Private *SiS_Pr)
 {
    if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
@@ -10059,7 +9460,7 @@ SiS_WriteDABDDC(SiS_Private *SiS_Pr)
    return(0);
 }
 
-USHORT
+static USHORT
 SiS_PrepareReadDDC(SiS_Private *SiS_Pr)
 {
    if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
@@ -10069,7 +9470,7 @@ SiS_PrepareReadDDC(SiS_Private *SiS_Pr)
    return(0);
 }
 
-USHORT
+static USHORT
 SiS_PrepareDDC(SiS_Private *SiS_Pr)
 {
    if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr);
@@ -10077,7 +9478,7 @@ SiS_PrepareDDC(SiS_Private *SiS_Pr)
    return(0);
 }
 
-void
+static void
 SiS_SendACK(SiS_Private *SiS_Pr, USHORT yesno)
 {
    SiS_SetSCLKLow(SiS_Pr);
@@ -10095,7 +9496,7 @@ SiS_SendACK(SiS_Private *SiS_Pr, USHORT yesno)
    SiS_SetSCLKHigh(SiS_Pr);
 }
 
-USHORT
+static USHORT
 SiS_DoProbeDDC(SiS_Private *SiS_Pr)
 {
     unsigned char mask, value;
@@ -10145,7 +9546,7 @@ SiS_DoProbeDDC(SiS_Private *SiS_Pr)
     return(ret);
 }
 
-USHORT
+static USHORT
 SiS_ProbeDDC(SiS_Private *SiS_Pr)
 {
    USHORT flag;
@@ -10161,7 +9562,7 @@ SiS_ProbeDDC(SiS_Private *SiS_Pr)
    return(flag);
 }
 
-USHORT
+static USHORT
 SiS_ReadDDC(SiS_Private *SiS_Pr, USHORT DDCdatatype, unsigned char *buffer)
 {
    USHORT flag, length, i;
@@ -10204,8 +9605,9 @@ SiS_ReadDDC(SiS_Private *SiS_Pr, USHORT DDCdatatype, unsigned char *buffer)
    regards chipset and video bridge type.
 
    Arguments:
-       adaptnum: 0=CRT1, 1=LCD, 2=VGA2
-                 CRT2 DDC is only supported on SiS301, 301B, 302B.
+       adaptnum: 0=CRT1(analog), 1=CRT2/LCD(digital), 2=CRT2/VGA2(analog)
+                 CRT2 DDC is only supported on SiS301, 301B, 301C, 302B.
+                LCDA is CRT1, but DDC is read from CRT2 port.
        DDCdatatype: 0=Probe, 1=EDID, 2=EDID+VDIF, 3=EDID V2 (P&D), 4=EDID V2 (FPDI-2)
        buffer: ptr to 256 data bytes which will be filled with read data.
 
@@ -10247,6 +9649,19 @@ SiS_HandleDDC(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
       result = SiS_ProbeDDC(SiS_Pr);
    } else {
       result = SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer);
+      if((!result) && (DDCdatatype == 1)) {
+         if((buffer[0] == 0x00) && (buffer[1] == 0xff) &&
+           (buffer[2] == 0xff) && (buffer[3] == 0xff) &&
+           (buffer[4] == 0xff) && (buffer[5] == 0xff) &&
+           (buffer[6] == 0xff) && (buffer[7] == 0x00) &&
+           (buffer[0x12] == 1)) {
+           if(adaptnum == 1) {
+              if(!(buffer[0x14] & 0x80)) result = 0xFFFE;
+           } else {
+              if(buffer[0x14] & 0x80)    result = 0xFFFE;
+           }
+        }
+      }
    }
    SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,sr1f);
    if(VGAEngine == SIS_300_VGA) {
@@ -10306,15 +9721,22 @@ USHORT
 SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
 {
    USHORT DDCdatatype, paneltype, flag, xres=0, yres=0;
-   USHORT index, myindex, lumsize, numcodes;
+   USHORT index, myindex, lumsize, numcodes, panelvendor, panelproduct;
+   int maxx=0, maxy=0, prefx=0, prefy=0;
    unsigned char cr37=0, seekcode;
    BOOLEAN checkexpand = FALSE;
+   BOOLEAN havesync = FALSE;
+   BOOLEAN indb = FALSE;
    int retry, i;
    unsigned char buffer[256];
 
    for(i=0; i<7; i++) SiS_Pr->CP_DataValid[i] = FALSE;
    SiS_Pr->CP_HaveCustomData = FALSE;
    SiS_Pr->CP_MaxX = SiS_Pr->CP_MaxY = SiS_Pr->CP_MaxClock = 0;
+   SiS_Pr->CP_PreferredX = SiS_Pr->CP_PreferredY = 0;
+   SiS_Pr->CP_PreferredIndex = -1;
+   SiS_Pr->CP_PrefClock = 0;
+   SiS_Pr->PanelSelfDetected = FALSE;
 
    if(!(pSiS->VBFlags & (VB_301|VB_301B|VB_301C|VB_302B))) return 0;
    if(pSiS->VBFlags & VB_30xBDH) return 0;
@@ -10370,25 +9792,24 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
       /* Catch a few clear cases: */
       if(!(checkedid1(buffer))) {
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: EDID corrupt\n");
+               "LCD sense: EDID corrupt\n");
         return 0;
       }
 
       if(!(buffer[0x14] & 0x80)) {
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: Attached display expects analog input (0x%02x)\n",
+               "LCD sense: Attached display expects analog input (0x%02x)\n",
                buffer[0x14]);
         return 0;
       }
 
       if((buffer[0x18] & 0x18) != 0x08) {
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: Attached display is not of RGB but of %s type (0x%02x)\n",
+               "LCD sense: Warning: Attached display is not of RGB but of %s type (0x%02x)\n",
                ((buffer[0x18] & 0x18) == 0x00) ? "monochrome/greyscale" :
                  ( ((buffer[0x18] & 0x18) == 0x10) ? "non-RGB multicolor" :
                     "undefined"),
                buffer[0x18]);
-        return 0;
       }
 
       /* Now analyze the first Detailed Timing Block and see
@@ -10400,21 +9821,33 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
       paneltype = Panel_Custom;
       checkexpand = FALSE;
 
+      panelvendor = buffer[9] | (buffer[8] << 8);
+      panelproduct = buffer[10] | (buffer[11] << 8);
+
+      /* Overrule bogus preferred modes from database */
+      if((indb = SiS_FindPanelFromDB(pSiS, panelvendor, panelproduct, &maxx, &maxy, &prefx, &prefy))) {
+         if(prefx) SiS_Pr->CP_PreferredX = xres = prefx;
+        if(prefy) SiS_Pr->CP_PreferredY = yres = prefy;
+      }
+
       if(buffer[0x18] & 0x02) {
 
-         xres = buffer[0x38] | ((buffer[0x3a] & 0xf0) << 4);
-         yres = buffer[0x3b] | ((buffer[0x3d] & 0xf0) << 4);
+         USHORT pclk = (buffer[0x36] | (buffer[0x37] << 8));
+        USHORT phb  = (buffer[0x39] | ((buffer[0x3a] & 0x0f) << 8));
+        USHORT pvb  = (buffer[0x3c] | ((buffer[0x3d] & 0x0f) << 8));
 
-        SiS_Pr->CP_PreferredX = xres;
-        SiS_Pr->CP_PreferredY = yres;
+        if(!xres) SiS_Pr->CP_PreferredX = xres = buffer[0x38] | ((buffer[0x3a] & 0xf0) << 4);
+         if(!yres) SiS_Pr->CP_PreferredY = yres = buffer[0x3b] | ((buffer[0x3d] & 0xf0) << 4);
 
          switch(xres) {
+#if 0      /* Treat as custom */
             case 800:
                if(yres == 600) {
                   paneltype = Panel_800x600;
                   checkexpand = TRUE;
                }
                break;
+#endif
             case 1024:
                if(yres == 768) {
                   paneltype = Panel_1024x768;
@@ -10432,14 +9865,20 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
                      paneltype = Panel310_1280x960;
                   }
                } else if(yres == 768) {
-                  if( ((buffer[0x36] | (buffer[0x37] << 8)) == 8100) &&
-                      ((buffer[0x39] | ((buffer[0x3a] & 0x0f) << 8)) == (1688 - 1280)) &&
-                      ((buffer[0x3c] | ((buffer[0x3d] & 0x0f) << 8)) == (802 - 768)) ) {
+                  if( (pclk == 8100) &&
+                      (phb == (1688 - 1280)) &&
+                      (pvb == (802 - 768)) ) {
                      paneltype = Panel_1280x768;
                      checkexpand = FALSE;
                      cr37 |= 0x10;
                   }
-               }
+               } else if(yres == 800) {
+                  if( (pclk == 6900) &&
+                      (phb == (1408 - 1280)) &&
+                      (pvb == (816 - 800)) ) {
+                     paneltype = Panel_1280x800;
+                  }
+               }
                break;
            case 1400:
                if(pSiS->VGAEngine == SIS_315_VGA) {
@@ -10449,50 +9888,71 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
                   }
                }
                break;
-#if 0      /* Treat this as custom, as we have no valid timing data yet */
            case 1600:
                if(pSiS->VGAEngine == SIS_315_VGA) {
-                  if(yres == 1200) {
-                     paneltype = Panel310_1600x1200;
-                     checkexpand = TRUE;
+                  if(pSiS->VBFlags & VB_301C) {
+                     if(yres == 1200) {
+                        paneltype = Panel310_1600x1200;
+                        checkexpand = TRUE;
+                     }
                   }
                }
                break;
-#endif
          }
 
-        if(paneltype != Panel_Custom) {
-           if((buffer[0x47] & 0x18) == 0x18) {
-              cr37 |= ((((buffer[0x47] & 0x06) ^ 0x06) << 5) | 0x20);
-           } else {
-              /* What now? There is no digital separate output timing... */
-              xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
-                  "CRT2: Unable to retrieve Sync polarity information\n");
-              cr37 |= 0xc0;  /* Default */
-           }
+        /* Save sync: This is used if "Pass 1:1" is off; in this case
+         * we always use the panel's native mode = this "preferred mode"
+         * we just have been analysing. Hence, we also need its sync.
+         */
+        if((buffer[0x47] & 0x18) == 0x18) {
+           cr37 |= ((((buffer[0x47] & 0x06) ^ 0x06) << 5) | 0x20);
+           havesync = TRUE;
+        } else {
+           /* What now? There is no digital separate output timing... */
+           xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
+                  "LCD sense: Unable to retrieve Sync polarity information\n");
+           cr37 |= 0xc0;  /* Default */
         }
 
       }
 
+      /* Check against our database; eg. Sanyo Z2 projector reports
+       * 1024x768 as preferred mode, although it supports 1280x720
+       * natively in non-HDCP mode. Treat such wrongly reporting
+       * panels as custom and fixup actual maximum resolutions.
+       */
+      if(paneltype != Panel_Custom) {
+         if(indb) {
+           paneltype = Panel_Custom;
+           SiS_Pr->CP_MaxX = maxx;
+           SiS_Pr->CP_MaxY = maxy;
+           /* Leave preferred unchanged (MUST contain a valid mode!) */
+        }
+      }
+
       /* If we still don't know what panel this is, we take it
        * as a custom panel and derive the timing data from the
        * detailed timing blocks
        */
       if(paneltype == Panel_Custom) {
 
-         BOOLEAN havesync = FALSE;
         int i, temp, base = 0x36;
         unsigned long estpack;
-        unsigned short estx[] = {
+        const unsigned short estx[] = {
                720, 720, 640, 640, 640, 640, 800, 800,
                800, 800, 832,1024,1024,1024,1024,1280,
                1152
         };
-        unsigned short esty[] = {
+        const unsigned short esty[] = {
                400, 400, 480, 480, 480, 480, 600, 600,
                600, 600, 624, 768, 768, 768, 768,1024,
                870
         };
+        const int estclk[] = {
+                   0,     0, 25100,   0, 31500, 31500, 36100, 40000,
+               50100, 49500,     0,   0, 65100, 75200, 78700,135200,
+               0
+        };
 
         paneltype = 0;
         SiS_Pr->CP_Supports64048075 = TRUE;
@@ -10505,9 +9965,15 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
             if(estpack & (1 << i)) {
                if(estx[16 - i] > SiS_Pr->CP_MaxX) SiS_Pr->CP_MaxX = estx[16 - i];
                if(esty[16 - i] > SiS_Pr->CP_MaxY) SiS_Pr->CP_MaxY = esty[16 - i];
+               if(estclk[16 - i] > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = estclk[16 - i];
             }
         }
 
+        /* By default we drive the LCD at 75Hz in 640x480 mode; if
+         * the panel does not provide this mode, use 60hz
+         */
+        if(!(buffer[0x23] & 0x04)) SiS_Pr->CP_Supports64048075 = FALSE;
+
         /* 2. From Standard Timings */
         for(i=0x26; i < 0x36; i+=2) {
            if((buffer[i] != 0x01) && (buffer[i+1] != 0x01)) {
@@ -10551,48 +10017,40 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
               SiS_Pr->CP_DataValid[i] = TRUE;
 
               /* Sort out invalid timings, interlace and too high clocks */
-              if((SiS_Pr->CP_HDisplay[i] & 7)                                          ||
-                 (SiS_Pr->CP_HDisplay[i] > SiS_Pr->CP_HSyncStart[i])                   ||
-                 (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HSyncEnd[i])                    ||
-                 (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HTotal[i])                      ||
-                 (SiS_Pr->CP_HSyncStart[i] >= SiS_Pr->CP_HSyncEnd[i])                  ||
-                 (SiS_Pr->CP_HSyncStart[i] > SiS_Pr->CP_HTotal[i])                     ||
-                 (SiS_Pr->CP_HSyncEnd[i] > SiS_Pr->CP_HTotal[i])                       ||
-                 (SiS_Pr->CP_VDisplay[i] > SiS_Pr->CP_VSyncStart[i])                   ||
-                 (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VSyncEnd[i])                    ||
-                 (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VTotal[i])                      ||
-                 (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VSyncEnd[i])                   ||
-                 (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VTotal[i])                     ||
-                 (SiS_Pr->CP_VSyncEnd[i] > SiS_Pr->CP_VTotal[i])                       ||
+              if((SiS_Pr->CP_HDisplay[i] & 7)                                            ||
+                 (SiS_Pr->CP_HDisplay[i] > SiS_Pr->CP_HSyncStart[i])                     ||
+                 (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HSyncEnd[i])                      ||
+                 (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HTotal[i])                        ||
+                 (SiS_Pr->CP_HSyncStart[i] >= SiS_Pr->CP_HSyncEnd[i])                    ||
+                 (SiS_Pr->CP_HSyncStart[i] > SiS_Pr->CP_HTotal[i])                       ||
+                 (SiS_Pr->CP_HSyncEnd[i] > SiS_Pr->CP_HTotal[i])                         ||
+                 (SiS_Pr->CP_VDisplay[i] > SiS_Pr->CP_VSyncStart[i])                     ||
+                 (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VSyncEnd[i])                      ||
+                 (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VTotal[i])                        ||
+                 (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VSyncEnd[i])                     ||
+                 (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VTotal[i])                       ||
+                 (SiS_Pr->CP_VSyncEnd[i] > SiS_Pr->CP_VTotal[i])                         ||
                  (((pSiS->VBFlags & VB_301C) && (SiS_Pr->CP_Clock[i] > 162500)) ||
-                  ((!(pSiS->VBFlags & VB_301C)) && (SiS_Pr->CP_Clock[i] > 108200)))    ||
+                  ((!(pSiS->VBFlags & VB_301C)) &&
+                   ((SiS_Pr->CP_Clock[i] > 108200) || (SiS_Pr->CP_VDisplay[i] > 1024) ||
+                    (SiS_Pr->CP_HDisplay[i] > 1600))))                                   ||
                  (buffer[base+17] & 0x80)) {
 
                  SiS_Pr->CP_DataValid[i] = FALSE;
 
               } else {
 
-                 paneltype = Panel_Custom;
-
                  SiS_Pr->CP_HaveCustomData = TRUE;
 
                  if(xres > SiS_Pr->CP_MaxX) SiS_Pr->CP_MaxX = xres;
                  if(yres > SiS_Pr->CP_MaxY) SiS_Pr->CP_MaxY = yres;
                  if(SiS_Pr->CP_Clock[i] > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = SiS_Pr->CP_Clock[i];
 
-                 SiS_Pr->CP_Vendor = buffer[9] | (buffer[8] << 8);
-                 SiS_Pr->CP_Product = buffer[10] | (buffer[11] << 8);
-
-                 /* By default we drive the LCD at 75Hz in 640x480 mode; if
-                  * the panel does not provide this mode, use 60hz
-                  */
-                 if(!(buffer[0x23] & 0x04)) SiS_Pr->CP_Supports64048075 = FALSE;
-
-                 /* We must assume the panel can scale, since we have
-                  * no scaling data
-                  */
-                 checkexpand = FALSE;
-                 cr37 |= 0x10;
+                 if((SiS_Pr->CP_PreferredX == xres) && (SiS_Pr->CP_PreferredY == yres)) {
+                    SiS_Pr->CP_PreferredIndex = i;
+                    SiS_MakeClockRegs(pSiS->pScrn, SiS_Pr->CP_Clock[i], &SiS_Pr->CP_PrefSR2B, &SiS_Pr->CP_PrefSR2C);
+                    SiS_Pr->CP_PrefClock = (SiS_Pr->CP_Clock[i] / 1000) + 1;
+                 }
 
                  /* Extract the sync polarisation information. This only works
                   * if the Flags indicate a digital separate output.
@@ -10601,20 +10059,37 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
                     SiS_Pr->CP_HSync_P[i] = (buffer[base+17] & 0x02) ? TRUE : FALSE;
                     SiS_Pr->CP_VSync_P[i] = (buffer[base+17] & 0x04) ? TRUE : FALSE;
                     SiS_Pr->CP_SyncValid[i] = TRUE;
-                    if(!havesync) {
+                    if((i == SiS_Pr->CP_PreferredIndex) && (!havesync)) {
                        cr37 |= ((((buffer[base+17] & 0x06) ^ 0x06) << 5) | 0x20);
                        havesync = TRUE;
                     }
                  } else {
                     SiS_Pr->CP_SyncValid[i] = FALSE;
                  }
+
               }
-            }
+
+            } else if((!buffer[base]) && (!buffer[base+1]) && (!buffer[base+2]) && (!buffer[base+4])) {
+
+              /* Maximum pixclock from Monitor Range Limits */
+              if((buffer[base+3] == 0xfd) && (buffer[base+9] != 0xff)) {
+                 int maxclk = buffer[base+9] * 10;
+                 /* More than 170 is not supported anyway */
+                 if(maxclk <= 170) SiS_Pr->CP_MaxClock = maxclk * 1000;
+              }
+
+           }
+
         }
-        if(!havesync) {
-           xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
-                  "CRT2: Unable to retrieve Sync polarity information\n");
-        }
+
+        if(SiS_Pr->CP_MaxX && SiS_Pr->CP_MaxY) {
+           paneltype = Panel_Custom;
+           checkexpand = FALSE;
+           cr37 |= 0x10;
+           SiS_Pr->CP_Vendor = panelvendor;
+           SiS_Pr->CP_Product = panelproduct;
+        }
+
       }
 
       if(paneltype && checkexpand) {
@@ -10637,51 +10112,47 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
 
       if(!(checkedid2(buffer))) {
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: EDID corrupt\n");
+               "LCD sense: EDID corrupt\n");
         return 0;
       }
 
       if((buffer[0x41] & 0x0f) == 0x03) {
          index = 0x42 + 3;
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: Display supports TMDS input on primary interface\n");
+               "LCD sense: Display supports TMDS input on primary interface\n");
       } else if((buffer[0x41] & 0xf0) == 0x30) {
          index = 0x46 + 3;
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: Display supports TMDS input on secondary interface\n");
+               "LCD sense: Display supports TMDS input on secondary interface\n");
       } else {
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: Display does not support TMDS video interface (0x%02x)\n", 
+               "LCD sense: Display does not support TMDS video interface (0x%02x)\n",
                buffer[0x41]);
         return 0;
       }
 
+      SiS_Pr->CP_Vendor = panelvendor = buffer[2] | (buffer[1] << 8);
+      SiS_Pr->CP_Product = panelproduct = buffer[3] | (buffer[4] << 8);
+
       paneltype = Panel_Custom;
-      SiS_Pr->CP_MaxX = xres = buffer[0x76] | (buffer[0x77] << 8);
-      SiS_Pr->CP_MaxY = yres = buffer[0x78] | (buffer[0x79] << 8);
+      SiS_Pr->CP_MaxX = SiS_Pr->CP_PreferredX = xres = buffer[0x76] | (buffer[0x77] << 8);
+      SiS_Pr->CP_MaxY = SiS_Pr->CP_PreferredY = yres = buffer[0x78] | (buffer[0x79] << 8);
+
       switch(xres) {
+#if 0
          case 800:
             if(yres == 600) {
                paneltype = Panel_800x600;
                checkexpand = TRUE;
             }
             break;
+#endif
          case 1024:
             if(yres == 768) {
                paneltype = Panel_1024x768;
                checkexpand = TRUE;
             }
             break;
-        case 1152:
-            if(yres == 768) {
-               if(pSiS->VGAEngine == SIS_300_VGA) {
-                  paneltype = Panel300_1152x768;
-               } else {
-                  paneltype = Panel310_1152x768;
-               }
-               checkexpand = TRUE;
-            }
-            break;
         case 1280:
             if(yres == 960) {
                if(pSiS->VGAEngine == SIS_315_VGA) {
@@ -10703,16 +10174,16 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
                }
             }
             break;
-#if 0    /* Treat this one as custom since we have no timing data yet */
         case 1600:
             if(pSiS->VGAEngine == SIS_315_VGA) {
-               if(yres == 1200) {
-                  paneltype = Panel310_1600x1200;
-                  checkexpand = TRUE;
+               if(pSiS->VBFlags & VB_301C) {
+                  if(yres == 1200) {
+                     paneltype = Panel310_1600x1200;
+                     checkexpand = TRUE;
+                  }
                }
             }
             break;
-#endif
       }
 
       /* Determine if RGB18 or RGB24 */
@@ -10735,7 +10206,25 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
         lumsize++;  /* luminance header byte */
         index += lumsize;
       }
+#if 0 /* "pixel rate" = pixel clock? */
+      if(buffer[0x7e] & 0x1c) {
+         for(i=0; i<((buffer[0x7e] & 0x1c) >> 2); i++) {
+           if(buffer[index + (i*8) + 6] && (buffer[index + (i*8) + 7] & 0x0f)) {
+              int clk = (buffer[index + (i*8) + 6] | ((buffer[index + (i*8) + 7] & 0x0f) << 4)) * 1000;
+              if(clk > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = clk;
+           }
+        }
+      }
+#endif
       index += (((buffer[0x7e] & 0x1c) >> 2) * 8);   /* skip Frequency Ranges */
+      if(buffer[0x7e] & 0x03) {
+         for(i=0; i<(buffer[0x7e] & 0x03); i++) {
+           if((buffer[index + (i*27) + 9]) || (buffer[index + (i*27) + 10])) {
+              int clk = ((buffer[index + (i*27) + 9]) | ((buffer[index + (i*27) + 9]) << 8)) * 10;
+              if(clk > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = clk;
+           }
+        }
+      }
       index += ((buffer[0x7e] & 0x03) * 27);         /* skip Detailed Range Limits */
       numcodes = (buffer[0x7f] & 0xf8) >> 3;
       if(numcodes) {
@@ -10747,13 +10236,29 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
         }
         if(buffer[myindex] == seekcode) {
            cr37 |= ((((buffer[myindex + 1] & 0x0c) ^ 0x0c) << 4) | 0x20);
+           havesync = TRUE;
         } else {
            xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
-               "CRT2: Unable to retrieve Sync polarity information\n");
+               "LCD sense: Unable to retrieve Sync polarity information\n");
         }
       } else {
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
-            "CRT2: Unable to retrieve Sync polarity information\n");
+            "LCD sense: Unable to retrieve Sync polarity information\n");
+      }
+
+      /* Check against our database; Eg. Sanyo projector reports
+       * 1024x768 in non-HDPC mode, although it supports 1280x720.
+       * Treat such wrongly reporting panels as custom.
+       */
+      if(paneltype != Panel_Custom) {
+         int maxx, maxy, prefx, prefy;
+         if((SiS_FindPanelFromDB(pSiS, panelvendor, panelproduct, &maxx, &maxy, &prefx, &prefy))) {
+           paneltype = Panel_Custom;
+           SiS_Pr->CP_MaxX = maxx;
+           SiS_Pr->CP_MaxY = maxy;
+           cr37 |= 0x10;
+           /* Leave preferred unchanged (MUST be a valid mode!) */
+        }
       }
 
       /* Now seek the detailed timing descriptions for custom panels */
@@ -10799,7 +10304,8 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
               (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VTotal[i])                        ||
               (SiS_Pr->CP_VSyncEnd[i] > SiS_Pr->CP_VTotal[i])                          ||
               (((pSiS->VBFlags & VB_301C) && (SiS_Pr->CP_Clock[i] > 162500)) ||
-               ((!(pSiS->VBFlags & VB_301C)) && (SiS_Pr->CP_Clock[i] > 108200)))       ||
+               ((!(pSiS->VBFlags & VB_301C)) &&
+                ((SiS_Pr->CP_Clock[i] > 108200) || (SiS_Pr->CP_VDisplay[i] > 1024))))  ||
               (buffer[index + 17] & 0x80)) {
 
               SiS_Pr->CP_DataValid[i] = FALSE;
@@ -10810,21 +10316,25 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
 
               if(SiS_Pr->CP_Clock[i] > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = SiS_Pr->CP_Clock[i];
 
+              if((SiS_Pr->CP_PreferredX == xres) && (SiS_Pr->CP_PreferredY == yres)) {
+                 SiS_Pr->CP_PreferredIndex = i;
+                 SiS_MakeClockRegs(pSiS->pScrn, SiS_Pr->CP_Clock[i], &SiS_Pr->CP_PrefSR2B, &SiS_Pr->CP_PrefSR2C);
+                 SiS_Pr->CP_PrefClock = (SiS_Pr->CP_Clock[i] / 1000) + 1;
+                 if(!havesync) {
+                    cr37 |= ((((buffer[index + 17] & 0x06) ^ 0x06) << 5) | 0x20);
+                    havesync = TRUE;
+                 }
+              }
+
               SiS_Pr->CP_HSync_P[i] = (buffer[index + 17] & 0x02) ? TRUE : FALSE;
               SiS_Pr->CP_VSync_P[i] = (buffer[index + 17] & 0x04) ? TRUE : FALSE;
               SiS_Pr->CP_SyncValid[i] = TRUE;
 
-              SiS_Pr->CP_Vendor = buffer[2] | (buffer[1] << 8);
-              SiS_Pr->CP_Product = buffer[3] | (buffer[4] << 8);
-
-              /* We must assume the panel can scale, since we have
-               * no scaling data
-               */
-              cr37 |= 0x10;
-
            }
         }
 
+        cr37 |= 0x10;
+
       }
 
       break;
@@ -10843,7 +10353,7 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
    for(i = 0; i < 7; i++) {
       if(SiS_Pr->CP_DataValid[i]) {
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-            "Non-standard LCD timing data no. %d:\n", i);
+            "Non-standard LCD/DVI-D timing data no. %d:\n", i);
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
            "   HDisplay %d HSync %d HSyncEnd %d HTotal %d\n",
            SiS_Pr->CP_HDisplay[i], SiS_Pr->CP_HSyncStart[i],
@@ -10864,14 +10374,18 @@ SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
    if(paneltype) {
        if(!SiS_Pr->CP_PreferredX) SiS_Pr->CP_PreferredX = SiS_Pr->CP_MaxX;
        if(!SiS_Pr->CP_PreferredY) SiS_Pr->CP_PreferredY = SiS_Pr->CP_MaxY;
-       cr37 &= 0xf1;
-       SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x36,0xf0,paneltype);
-       SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x37,0xf1,cr37);
        SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x32,0x08);
+       SiS_SetReg(SiS_Pr->SiS_P3d4,0x36,paneltype);
+       cr37 &= 0xf1;
+       SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x37,0x0c,cr37);
+       SiS_Pr->PanelSelfDetected = TRUE;
 #ifdef TWDEBUG
        xf86DrvMsgVerb(pSiS->pScrn->scrnIndex, X_PROBED, 3, 
-               "CRT2: [DDC LCD results: 0x%02x, 0x%02x]\n", paneltype, cr37);
+                  "LCD sense: [DDC LCD results: 0x%02x, 0x%02x]\n", paneltype, cr37);
 #endif 
+   } else {
+       SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x32,~0x08);
+       SiS_SetReg(SiS_Pr->SiS_P3d4,0x36,0x00);
    }
    return 0;
 }
@@ -10903,7 +10417,7 @@ SiS_SenseVGA2DDC(SiS_Private *SiS_Pr, SISPtr pSiS)
       DDCdatatype = 1;
    } else {
        xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "Do DDC answer\n");
+               "VGA2 sense: Do DDC answer\n");
        return 0;                               /* no DDC support (or no device attached) */
    }
 
@@ -10912,7 +10426,7 @@ SiS_SenseVGA2DDC(SiS_Private *SiS_Pr, SISPtr pSiS)
    do {
       if(SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer)) {
          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: DDC read failed (attempt %d), %s\n",
+               "VGA2 sense: DDC read failed (attempt %d), %s\n",
                (3-retry), (retry == 1) ? "giving up" : "retrying");
         retry--;
         if(retry == 0) return 0xFFFF;
@@ -10925,13 +10439,13 @@ SiS_SenseVGA2DDC(SiS_Private *SiS_Pr, SISPtr pSiS)
    switch(DDCdatatype) {
    case 1:
       if(!(checkedid1(buffer))) {
-          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: EDID corrupt\n");
+          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
+               "VGA2 sense: EDID corrupt\n");
          return 0;
       }
       if(buffer[0x14] & 0x80) {                        /* Display uses digital input */
-          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: Attached display expects digital input\n");
+          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
+               "VGA2 sense: Attached display expects digital input\n");
          return 0;
       }
       SiS_Pr->CP_Vendor = buffer[9] | (buffer[8] << 8);
@@ -10941,16 +10455,16 @@ SiS_SenseVGA2DDC(SiS_Private *SiS_Pr, SISPtr pSiS)
    case 3:
    case 4:
       if(!(checkedid2(buffer))) {
-          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: EDID corrupt\n");
+          xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
+               "VGA2 sense: EDID corrupt\n");
          return 0;
       }
       if( ((buffer[0x41] & 0x0f) != 0x01) &&   /* Display does not support analog input */
           ((buffer[0x41] & 0x0f) != 0x02) &&
          ((buffer[0x41] & 0xf0) != 0x10) &&
          ((buffer[0x41] & 0xf0) != 0x20) ) {
-         xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
-               "CRT2: Attached display does not support analog input (0x%02x)\n",
+         xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
+               "VGA2 sense: Attached display does not support analog input (0x%02x)\n",
                buffer[0x41]);
          return 0;
       }
@@ -10980,7 +10494,7 @@ SiS_SetCH70xxANDOR(SiS_Private *SiS_Pr, USHORT tempax,USHORT tempbh)
 
 /* Generic I2C functions for Chrontel & DDC --------- */
 
-void
+static void
 SiS_SetSwitchDDC2(SiS_Private *SiS_Pr)
 {
   SiS_SetSCLKHigh(SiS_Pr);
@@ -10999,7 +10513,7 @@ SiS_ReadDDC1Bit(SiS_Private *SiS_Pr)
 
 /* Set I2C start condition */
 /* This is done by a SD high-to-low transition while SC is high */
-USHORT
+static USHORT
 SiS_SetStart(SiS_Private *SiS_Pr)
 {
   if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF;                               /* (SC->low)  */
@@ -11018,7 +10532,7 @@ SiS_SetStart(SiS_Private *SiS_Pr)
 
 /* Set I2C stop condition */
 /* This is done by a SD low-to-high transition while SC is high */
-USHORT
+static USHORT
 SiS_SetStop(SiS_Private *SiS_Pr)
 {
   if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF;                               /* (SC->low) */
@@ -11036,7 +10550,7 @@ SiS_SetStop(SiS_Private *SiS_Pr)
 }
 
 /* Write 8 bits of data */
-USHORT
+static USHORT
 SiS_WriteDDC2Data(SiS_Private *SiS_Pr, USHORT tempax)
 {
   USHORT i,flag,temp;
@@ -11062,7 +10576,7 @@ SiS_WriteDDC2Data(SiS_Private *SiS_Pr, USHORT tempax)
   return(temp);
 }
 
-USHORT
+static USHORT
 SiS_ReadDDC2Data(SiS_Private *SiS_Pr, USHORT tempax)
 {
   USHORT i,temp,getdata;
@@ -11082,7 +10596,7 @@ SiS_ReadDDC2Data(SiS_Private *SiS_Pr, USHORT tempax)
   return(getdata);
 }
 
-USHORT
+static USHORT
 SiS_SetSCLKLow(SiS_Private *SiS_Pr)
 {
   SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
@@ -11093,7 +10607,7 @@ SiS_SetSCLKLow(SiS_Private *SiS_Pr)
   return 0;
 }
 
-USHORT
+static USHORT
 SiS_SetSCLKHigh(SiS_Private *SiS_Pr)
 {
   USHORT temp, watchdog=1000;
@@ -11117,7 +10631,7 @@ SiS_SetSCLKHigh(SiS_Private *SiS_Pr)
 
 /* Check I2C acknowledge */
 /* Returns 0 if ack ok, non-0 if ack not ok */
-USHORT
+static USHORT
 SiS_CheckACK(SiS_Private *SiS_Pr)
 {
   USHORT tempah;
@@ -11148,13 +10662,13 @@ GetRAMDACromptr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
   USHORT romptr;
 
   if(HwInfo->jChipType < SIS_330) {
-     romptr = ROMAddr[0x128] | (ROMAddr[0x129] << 8);
+     romptr = SISGETROMW(0x128);
      if(SiS_Pr->SiS_VBType & VB_SIS301B302B)
-        romptr = ROMAddr[0x12a] | (ROMAddr[0x12b] << 8);
+        romptr = SISGETROMW(0x12a);
   } else {
-     romptr = ROMAddr[0x1a8] | (ROMAddr[0x1a9] << 8);
+     romptr = SISGETROMW(0x1a8);
      if(SiS_Pr->SiS_VBType & VB_SIS301B302B)
-        romptr = ROMAddr[0x1aa] | (ROMAddr[0x1ab] << 8);
+        romptr = SISGETROMW(0x1aa);
   }
   return(romptr);
 }
@@ -11166,13 +10680,13 @@ GetLCDromptr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
   USHORT romptr;
 
   if(HwInfo->jChipType < SIS_330) {
-     romptr = ROMAddr[0x120] | (ROMAddr[0x121] << 8);
+     romptr = SISGETROMW(0x120);
      if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)
-        romptr = ROMAddr[0x122] | (ROMAddr[0x123] << 8);
+        romptr = SISGETROMW(0x122);
   } else {
-     romptr = ROMAddr[0x1a0] | (ROMAddr[0x1a1] << 8);
+     romptr = SISGETROMW(0x1a0);
      if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)
-        romptr = ROMAddr[0x1a2] | (ROMAddr[0x1a3] << 8);
+        romptr = SISGETROMW(0x1a2);
   }
   return(romptr);
 }
@@ -11184,13 +10698,13 @@ GetTVromptr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
   USHORT romptr;
 
   if(HwInfo->jChipType < SIS_330) {
-     romptr = ROMAddr[0x114] | (ROMAddr[0x115] << 8);
+     romptr = SISGETROMW(0x114);
      if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)
-        romptr = ROMAddr[0x11a] | (ROMAddr[0x11b] << 8);
+        romptr = SISGETROMW(0x11a);
   } else {
-     romptr = ROMAddr[0x194] | (ROMAddr[0x195] << 8);
+     romptr = SISGETROMW(0x194);
      if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)
-        romptr = ROMAddr[0x19a] | (ROMAddr[0x19b] << 8);
+        romptr = SISGETROMW(0x19a);
   }
   return(romptr);
 }
@@ -11212,9 +10726,9 @@ GetLCDPtrIndexBIOS(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
      }
   }
 
-  index = SiS_Pr->SiS_LCDResInfo & 0x0F;
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050)      index -= 5;
-  else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) index -= 6;
+  index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F;
+  if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)      index -= 5;
+  else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6;
   index--;
   index *= 3;
   if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
@@ -11227,12 +10741,9 @@ GetLCDPtrIndex(SiS_Private *SiS_Pr)
 {
   USHORT index;
 
-  index = SiS_Pr->SiS_LCDResInfo & 0x0F;
-  index--;
-  index *= 3;
-  if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
+  index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3;
+  if(SiS_Pr->SiS_LCDInfo & DontExpandLCD)         index += 2;
   else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
-
   return index;
 }
 
@@ -11258,7 +10769,7 @@ GetTVPtrIndex(SiS_Private *SiS_Pr)
 }
 
 static ULONG
-GetOEMTVPtr661_2(SiS_Private *SiS_Pr)
+GetOEMTVPtr661_2_GEN(SiS_Private *SiS_Pr, int addme)
 {
    USHORT index = 0, temp = 0;
 
@@ -11275,7 +10786,7 @@ GetOEMTVPtr661_2(SiS_Private *SiS_Pr)
    if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
       if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
          (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
-        index += 8;
+        index += addme;
         temp++;
       }
       temp += 0x0100;
@@ -11283,16 +10794,37 @@ GetOEMTVPtr661_2(SiS_Private *SiS_Pr)
    return(ULONG)(index | (temp << 16));
 }
 
+static ULONG
+GetOEMTVPtr661_2_OLD(SiS_Private *SiS_Pr)
+{
+   return(GetOEMTVPtr661_2_GEN(SiS_Pr, 8));
+}
+
+#if 0
+static ULONG
+GetOEMTVPtr661_2_NEW(SiS_Private *SiS_Pr)
+{
+   return(GetOEMTVPtr661_2_GEN(SiS_Pr, 6));
+}
+#endif
+
 static int
 GetOEMTVPtr661(SiS_Private *SiS_Pr)
 {
    int index = 0;
 
-   if(SiS_Pr->SiS_TVMode & TVSetPAL)       index = 2;
-   if(SiS_Pr->SiS_TVMode & TVSetHiVision)  index = 4;
-   if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6;
-   if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8;
-   if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10;
+   if(SiS_Pr->SiS_TVMode & TVSetPAL)          index = 2;
+   if(SiS_Pr->SiS_ROMNew) {
+      if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 4;
+      if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 6;
+      if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 8;
+      if(SiS_Pr->SiS_TVMode & TVSetHiVision)  index = 10;
+   } else {
+      if(SiS_Pr->SiS_TVMode & TVSetHiVision)  index = 4;
+      if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6;
+      if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8;
+      if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10;
+   }
 
    if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) index++;
 
@@ -11306,15 +10838,21 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
   USHORT delay=0,index,myindex,temp,romptr=0;
   BOOLEAN dochiptest = TRUE;
 
+  if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
+     SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf);
+  } else {
+     SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x35,0x7f);
+  }
+
   /* Find delay (from ROM, internal tables, PCI subsystem) */
 
   if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {                   /* ------------ VGA */
      
-     if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+     if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
         romptr = GetRAMDACromptr(SiS_Pr, HwInfo);
-       if(!romptr) return;
-       delay = ROMAddr[romptr];
-     else {
+     }
+     if(romptr) delay = ROMAddr[romptr];
+     else {
         delay = 0x04;
         if(SiS_Pr->SiS_VBType & VB_SIS301B302B) {
           if(IS_SIS650) {
@@ -11326,8 +10864,7 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
           } else {
              delay = 0x0c;
           }
-       }
-        if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
+       } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
            delay = 0x00;
        }
      }
@@ -11336,13 +10873,39 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
 
      BOOLEAN gotitfrompci = FALSE;
 
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom) return;
+     /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */
+
+     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+       if(SiS_Pr->PDC != -1) {
+           SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((SiS_Pr->PDC >> 1) & 0x0f));
+          SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((SiS_Pr->PDC & 0x01) << 7));
+          return;
+       }
+     } else {
+       if(SiS_Pr->PDCA != -1) {
+          SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDCA << 3) & 0xf0));
+          SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((SiS_Pr->PDCA & 0x01) << 6));
+          return;
+       }
+     }
 
-     /* Could we detect a PDC for LCD? If yes, use it */
+     /* Custom Panel? */
 
-     if(SiS_Pr->PDC) {
+     if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) {
         if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
-          SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDC & 0x0f) << 4));
+          delay = 0x00;
+          if((SiS_Pr->PanelXRes <= 1280) && (SiS_Pr->PanelYRes <= 1024)) {
+             delay = 0x20;
+          }
+          SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay);
+       } else {
+          delay = 0x0c;
+          if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x03;
+          else if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
+             if(IS_SIS740) delay = 0x01;
+             else          delay = 0x03;
+          }
+          SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,delay);
        }
         return;
      }
@@ -11355,7 +10918,7 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
      switch(SiS_Pr->SiS_CustomT) {
      case CUT_COMPAQ1280:
      case CUT_COMPAQ12802:
-       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
+       if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
           gotitfrompci = TRUE;
           dochiptest = FALSE;
           delay = 0x03;
@@ -11363,15 +10926,13 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
        break;
      case CUT_CLEVO1400:
      case CUT_CLEVO14002:
-       /* if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { */
-          gotitfrompci = TRUE;
-          dochiptest = FALSE;
-          delay = 0x02;
-       /* } */
+       gotitfrompci = TRUE;
+       dochiptest = FALSE;
+       delay = 0x02;
        break;
      case CUT_CLEVO1024:
      case CUT_CLEVO10242:
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
+        if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
           gotitfrompci = TRUE;
           dochiptest = FALSE;
           delay = 0x33;
@@ -11392,12 +10953,12 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
 
            if(SiS_IsNotM650orLater(SiS_Pr, HwInfo)) {
 
-              if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+              if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
                 /* Always use the second pointer on 650; some BIOSes */
                  /* still carry old 301 data at the first location    */
-                /* romptr = ROMAddr[0x120] | (ROMAddr[0x121] << 8);  */
+                /* romptr = SISGETROMW(0x120);                       */
                 /* if(SiS_Pr->SiS_VBType & VB_SIS302LV)              */
-                romptr = ROMAddr[0x122] | (ROMAddr[0x123] << 8);
+                romptr = SISGETROMW(0x122);
                 if(!romptr) return;
                 delay = ROMAddr[(romptr + index)];
              } else {
@@ -11412,10 +10973,13 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
 
           }
 
-        } else if((ROMAddr) && SiS_Pr->SiS_UseROM &&
-                 (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024)) {
+        } else if(SiS_Pr->SiS_UseROM                         &&
+                 (!(SiS_Pr->SiS_ROMNew))                     &&
+                 (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) &&
+                 (SiS_Pr->SiS_LCDResInfo != Panel_1280x768)  &&
+                 (SiS_Pr->SiS_LCDResInfo != Panel_1280x960)) {
 
-          /* Data for 1280x1024 wrong in BIOS */
+          /* Data for 1280x1024 wrong in 301B BIOS */
            romptr = GetLCDromptr(SiS_Pr, HwInfo);
           if(!romptr) return;
           delay = ROMAddr[(romptr + index)];
@@ -11430,7 +10994,11 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
            delay = SiS310_LCDDelayCompensation_301[myindex];
           if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
              if(IS_SIS740) delay = 0x01;
+             else if(HwInfo->jChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex];
              else          delay = SiS310_LCDDelayCompensation_650301LV[myindex];
+          } else if(SiS_Pr->SiS_VBType & VB_SIS301C) {
+             if(IS_SIS740) delay = 0x01;  /* ? */
+             else          delay = 0x03;
           } else if(SiS_Pr->SiS_VBType & VB_SIS301B302B) {
              if(IS_SIS740) delay = 0x01;
              else          delay = SiS310_LCDDelayCompensation_3xx301B[myindex];
@@ -11453,12 +11021,12 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
 
         if(SiS_IsNotM650orLater(SiS_Pr,HwInfo)) {
 
-           if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+           if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
              /* Always use the second pointer on 650; some BIOSes */
               /* still carry old 301 data at the first location    */
-              /* romptr = ROMAddr[0x114] | (ROMAddr[0x115] << 8);  */
-             /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
-             romptr = ROMAddr[0x11a] | (ROMAddr[0x11b] << 8);
+              /* romptr = SISGETROMW(0x114);                      */
+             /* if(SiS_Pr->SiS_VBType & VB_SIS302LV)              */
+             romptr = SISGETROMW(0x11a);
              if(!romptr) return;
              delay = ROMAddr[romptr + index];
 
@@ -11491,7 +11059,7 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
           }
         }
 
-     } else if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+     } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
 
         romptr = GetTVromptr(SiS_Pr, HwInfo);
        if(!romptr) return;
@@ -11507,14 +11075,16 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
         if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
           if(IS_SIS740) {
              delay = SiS310_TVDelayCompensation_740301B[index];
+             /* LV: use 301 data? BIOS bug? */
           } else {
               delay = SiS310_TVDelayCompensation_301B[index];
+             if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x02;
           }
        }
 
      }
 
-     if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) {  /* LCDA */
+     if(SiS_LCDAEnabled(SiS_Pr, HwInfo)) {
        delay &= 0x0f;
        dochiptest = FALSE;
      }
@@ -11580,15 +11150,18 @@ SetAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   temp >>= 1;            /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
   temp1 = temp;
 
-  if(ROMAddr && SiS_Pr->SiS_UseROM) {
+  if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
      if(HwInfo->jChipType >= SIS_661) {
-       romptr = ROMAddr[0x260] | (ROMAddr[0x261] << 8);
-       temp1 = GetOEMTVPtr661(SiS_Pr);
+        temp1 = GetOEMTVPtr661(SiS_Pr);
         temp1 >>= 1;
+        romptr = SISGETROMW(0x260);
+        if(HwInfo->jChipType >= SIS_760) {
+          romptr = SISGETROMW(0x360);
+       }
      } else if(HwInfo->jChipType >= SIS_330) {
-        romptr = ROMAddr[0x192] | (ROMAddr[0x193] << 8);
+        romptr = SISGETROMW(0x192);
      } else {
-        romptr = ROMAddr[0x112] | (ROMAddr[0x113] << 8);
+        romptr = SISGETROMW(0x112);
      }
   }
 
@@ -11610,24 +11183,25 @@ SetEdgeEnhance(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
   USHORT index,temp,temp1,romptr=0;
 
-  temp = GetTVPtrIndex(SiS_Pr);
-  temp >>= 1;                  /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
-  temp1 = temp;
+  temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1;   /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
 
-  if(ModeNo<=0x13)
+  if(ModeNo <= 0x13)
      index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
   else
      index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
 
-  if(ROMAddr && SiS_Pr->SiS_UseROM) {
+  if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
      if(HwInfo->jChipType >= SIS_661) {
-       romptr = ROMAddr[0x26c] | (ROMAddr[0x26d] << 8);
+        romptr = SISGETROMW(0x26c);
+        if(HwInfo->jChipType >= SIS_760) {
+          romptr = SISGETROMW(0x36c);
+       }
        temp1 = GetOEMTVPtr661(SiS_Pr);
         temp1 >>= 1;
      } else if(HwInfo->jChipType >= SIS_330) {
-        romptr = ROMAddr[0x1a4] | (ROMAddr[0x1a5] << 8);
+        romptr = SISGETROMW(0x1a4);
      } else {
-        romptr = ROMAddr[0x124] | (ROMAddr[0x125] << 8);
+        romptr = SISGETROMW(0x124);
      }
   }
 
@@ -11645,62 +11219,15 @@ static void
 SetYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
            USHORT ModeNo,USHORT ModeIdIndex)
 {
-  UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
-  USHORT index, myindex, oldindex,temp, i, j, flag1 = 0, flag2 = 0, romptr = 0;
-  ULONG  lindex;
+  USHORT index, temp, i, j;
 
-  if(ModeNo<=0x13) {
-    index =  SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
+  if(ModeNo <= 0x13) {
+     index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
   } else {
-    index =  SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
-  }
-
-  oldindex = index;
-
-  if((HwInfo->jChipType >= SIS_661) && ROMAddr && SiS_Pr->SiS_UseROM) {
-     if(ModeNo > 0x13) {
-        index =  SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndexROM661;
-     }
-     lindex = GetOEMTVPtr661_2(SiS_Pr);
-     if(lindex & 0x00ff0000) flag1 = 1;
-     if(lindex & 0xff000000) flag2 = 1;
-     lindex &= 0xffff;
-
-     /* NTSC-J: Use PAL filters */
-     if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) lindex = 1;
-
-     romptr = ROMAddr[0x268] | (ROMAddr[0x269] << 8);
-     if(flag1) myindex = index * 7;
-     else      myindex = index << 2;
-
-     if(romptr) {
-        romptr += (lindex << 1);
-        romptr = (ROMAddr[romptr] | (ROMAddr[romptr+1] << 8)) + myindex;
-       if(romptr) {
-           if((!flag1) && (flag2)) {
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x35,0x00);
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x36,0x00);
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,0x00);
-             SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,ROMAddr[romptr++]);
-           } else {
-             for(i=0x35; i<=0x38; i++) {
-                 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr++]);
-              }
-           }
-           if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-             for(j=0, i=0x48; i<=0x4a; i++, j++) {
-                 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr++]);
-              }
-           }
-           return;
-       }
-     }
+     index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
   }
 
-  index = oldindex;
-
-  temp = GetTVPtrIndex(SiS_Pr);
-  temp >>= 1;                          /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
+  temp = GetTVPtrIndex(SiS_Pr) >> 1;  /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
 
   if(SiS_Pr->SiS_TVMode & TVSetNTSCJ)       temp = 1;  /* NTSC-J uses PAL */
   else if(SiS_Pr->SiS_TVMode & TVSetPALM)    temp = 3;  /* PAL-M */
@@ -11734,21 +11261,11 @@ SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   /* NTSC-J data not in BIOS, and already set in SetGroup2 */
   if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return;
 
-  if(HwInfo->jChipType >= SIS_661) {
-     lindex = GetOEMTVPtr661_2(SiS_Pr) & 0xffff;
+  if((HwInfo->jChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) {
+     lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff;
      lindex <<= 2;
-     if((ROMAddr) && SiS_Pr->SiS_UseROM) {
-        romptr = ROMAddr[0x264] | (ROMAddr[0x265] << 8);
-     }
-     if(romptr) {
-       romptr += lindex;
-       for(j=0, i=0x31; i<=0x34; i++, j++) {
-           SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
-        }
-     } else {
-        for(j=0, i=0x31; i<=0x34; i++, j++) {
-           SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS661_TVPhase[lindex + j]);
-        }
+     for(j=0, i=0x31; i<=0x34; i++, j++) {
+        SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS661_TVPhase[lindex + j]);
      }
      return;
   }
@@ -11766,20 +11283,20 @@ SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   /* 0: NTSC Graphics, 1: NTSC Text,    2: PAL Graphics,
    * 3: PAL Text,      4: HiTV Graphics 5: HiTV Text
    */
-  if((ROMAddr) && SiS_Pr->SiS_UseROM) {
-     romptr = ROMAddr[0x116] | (ROMAddr[0x117] << 8);
+  if(SiS_Pr->SiS_UseROM) {
+     romptr = SISGETROMW(0x116);
      if(HwInfo->jChipType >= SIS_330) {
-        romptr = ROMAddr[0x196] | (ROMAddr[0x197] << 8);
+        romptr = SISGETROMW(0x196);
      }
      if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-        romptr = ROMAddr[0x11c] | (ROMAddr[0x11d] << 8);
+        romptr = SISGETROMW(0x11c);
        if(HwInfo->jChipType >= SIS_330) {
-          romptr = ROMAddr[0x19c] | (ROMAddr[0x19d] << 8);
+          romptr = SISGETROMW(0x19c);
        }
        if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) {
-          romptr = ROMAddr[0x116] | (ROMAddr[0x117] << 8);
+          romptr = SISGETROMW(0x116);
           if(HwInfo->jChipType >= SIS_330) {
-              romptr = ROMAddr[0x196] | (ROMAddr[0x197] << 8);
+              romptr = SISGETROMW(0x196);
            }
        }
      }
@@ -11820,87 +11337,134 @@ SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   }
 }
 
-void
-SiS_OEM310Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
-                  USHORT ModeNo,USHORT ModeIdIndex)
-{
-   SetDelayComp(SiS_Pr,HwInfo,ModeNo);
-
-   if(SiS_Pr->UseCustomMode) return;
-
-   if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
-      SetAntiFlicker(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
-      SetPhaseIncr(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
-      SetYFilter(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
-      if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) {
-         SetEdgeEnhance(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
-      }
-   }
-}
-
 static void
 SetDelayComp661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo,
                 USHORT ModeIdIndex, USHORT RTI)
 {
+   USHORT delay = 0, romptr = 0, index, lcdpdcindex;
    UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
-   USHORT delay = 0, romptr = 0, index;
-   UCHAR  *myptr = NULL;
-   UCHAR  temp;
 
    if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC)))
       return;
 
-   delay = SiS_Pr->SiS_RefIndex[RTI].Ext_PDC;
+   /* 1. New ROM: VGA2 and LCD/LCDA-Pass1:1 */
+   /* (If a custom mode is used, Pass1:1 is always set; hence we do this:) */
+
+   if(SiS_Pr->SiS_ROMNew) {
+      if((SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)                        ||
+         ((SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
+         (SiS_Pr->SiS_LCDInfo & LCDPass11))) {
+         index = 25;
+         if(SiS_Pr->UseCustomMode) {
+           index = SiS_Pr->CSRClock;
+         } else if(ModeNo > 0x13) {
+            index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI,HwInfo);
+            index = SiS_Pr->SiS_VCLKData[index].CLOCK;
+         }
+        if(index < 25) index = 25;
+         index = ((index / 25) - 1) << 1;
+         if((ROMAddr[0x5b] & 0x80) || (SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD))) {
+           index++;
+        }
+        romptr = SISGETROMW(0x104);
+         delay = ROMAddr[romptr + index];
+         if(SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD)) {
+            SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
+            SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
+         } else {
+            SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
+           SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
+         }
+         return;
+      }
+   }
 
-   delay &= 0xf0;
-   delay >>= 4;
-   if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) delay <<= 12;  /* BIOS: 8, wrong */
+   /* 2. Old ROM: VGA2 and LCD/LCDA-Pass 1:1 */
+
+   if(SiS_Pr->UseCustomMode) delay = 0x04;
+   else if(ModeNo <= 0x13)   delay = 0x04;
+   else                      delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4);
+   delay |= (delay << 8);
 
    if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
+
+      /* 3. TV */
+
       index = GetOEMTVPtr661(SiS_Pr);
-      if((ROMAddr) && SiS_Pr->SiS_UseROM) {
-         romptr = ROMAddr[0x25c] | (ROMAddr[0x25d] << 8);
-         if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-            romptr = ROMAddr[0x25e] | (ROMAddr[0x25f] << 8);
-         }
-      }
-      if(romptr) myptr = &ROMAddr[romptr];
-      if(!myptr) {
-         myptr = (UCHAR *)SiS_TVDelay661_301;
-        if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
-           myptr = (UCHAR *)SiS_TVDelay661_301B;
-        }
+      if(SiS_Pr->SiS_ROMNew) {
+         romptr = SISGETROMW(0x106);
+        if(SiS_Pr->SiS_VBType & VB_UMC) romptr += 12;
+         delay = ROMAddr[romptr + index];
+      } else {
+         delay = 0x04;
+        if(index > 3) delay = 0;
       }
-      delay = myptr[index];
-      if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) delay >>= 4;  /* Should test dual edge */
+
    } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
-      if(SiS_Pr->PDC) {
-         delay = SiS_Pr->PDC & 0x0f;
-        if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
-            delay |= (delay << 12);
+
+      /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */
+
+      if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) &&
+          ((romptr = GetLCDStructPtr661_2(SiS_Pr, HwInfo))) ) {
+
+        lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12;
+
+        /* For LVDS (and sometimes TMDS), the BIOS must know about the correct value */
+        delay = ROMAddr[romptr + lcdpdcindex + 1];     /* LCD  */
+        delay |= (ROMAddr[romptr + lcdpdcindex] << 8); /* LCDA */
+
+      } else {
+
+         /* TMDS: Set our own, since BIOS has no idea */
+        /* (This is done on >=661 only, since <661 is calling this only for LVDS) */
+         if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+           switch(SiS_Pr->SiS_LCDResInfo) {
+           case Panel_1024x768:  delay = 0x0008; break;
+           case Panel_1280x720:  delay = 0x0004; break;
+           case Panel_1280x768:
+           case Panel_1280x768_2:delay = 0x0004; break;
+           case Panel_1280x800:
+           case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */
+           case Panel_1280x1024: delay = 0x1e04; break;
+           case Panel_1400x1050: delay = 0x0004; break;
+           case Panel_1600x1200: delay = 0x0400; break;
+           case Panel_1680x1050: delay = 0x0e04; break;
+           default:
+               if((SiS_Pr->PanelXRes <= 1024) && (SiS_Pr->PanelYRes <= 768)) {
+                 delay = 0x0008;
+              } else if((SiS_Pr->PanelXRes == 1280) && (SiS_Pr->PanelYRes == 1024)) {
+                 delay = 0x1e04;
+               } else if((SiS_Pr->PanelXRes <= 1400) && (SiS_Pr->PanelYRes <= 1050)) {
+                 delay = 0x0004;
+              } else if((SiS_Pr->PanelXRes <= 1600) && (SiS_Pr->PanelYRes <= 1200)) {
+                 delay = 0x0400;
+               } else
+                 delay = 0x0e04;
+              break;
+           }
+         }
+
+        /* Override by detected or user-set values */
+        /* (but only if, for some reason, we can't read value from BIOS) */
+         if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->PDC != -1)) {
+            delay = SiS_Pr->PDC & 0x1f;
          }
-      } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom) {
-         delay = 0x4444;  /* TEST THIS */
-      } else if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
-         myptr = GetLCDStructPtr661(SiS_Pr, HwInfo);
-         if(myptr) delay = myptr[4];
-         else delay = 0x44;
-         if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
-            delay |= (delay << 8);
+         if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) && (SiS_Pr->PDCA != -1)) {
+            delay = (SiS_Pr->PDCA & 0x1f) << 8;
          }
+
       }
-   }
 
-   temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2d);
-   if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToRAMDAC)) {
-      temp &= 0xf0;
-      temp |= (delay & 0x000f);
    }
+
    if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
-      temp &= 0x0f;
-      temp |= ((delay & 0xf000) >> 8);
+      delay >>= 8;
+      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
+      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
+   } else {
+      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
+      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
    }
-   SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,temp);
 }
 
 static void
@@ -11909,38 +11473,49 @@ SetCRT2SyncDither661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo, US
    USHORT infoflag;
    UCHAR temp;
 
-   infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag;
-   if(ModeNo <= 0x13) {
-      infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2);
-   }
-   infoflag &= 0xc0;
    if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
-      temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
-      if(temp & 0x20) infoflag = temp;
-      if(temp & 0x01) infoflag |= 0x01;
-   }
-   if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
-      temp = 0x0c;
-      if(infoflag & 0x01) temp ^= 0x14;  /* BIOS: 18, wrong */
-      temp |= (infoflag >> 6);
-      SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp);
-   }
-   if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
-      temp = 0;
-      if(infoflag & 0x01) temp |= 0x80;
-      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp);
-      temp = 0x30;
-      if(infoflag & 0x01) temp = 0x20;
+
+      if(ModeNo <= 0x13) {
+         infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2);
+      } else if(SiS_Pr->UseCustomMode) {
+         infoflag = SiS_Pr->CInfoFlag;
+      } else {
+         infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag;
+      }
+
+      if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
+         infoflag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); /* No longer check D5 */
+      }
+
       infoflag &= 0xc0;
-      temp |= infoflag;
-      SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp);
+
+      if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+         temp = (infoflag >> 6) | 0x0c;
+         if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
+           temp ^= 0x04;
+           if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x10;
+        }
+         SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp);
+      } else {
+         temp = 0x30;
+         if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp = 0x20;
+         temp |= infoflag;
+         SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp);
+         temp = 0;
+         if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
+           if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x80;
+        }
+         SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp);
+      }
+
    }
 }
 
 static void
 SetPanelParms661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
 {
-   UCHAR *myptr;
+   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
+   USHORT romptr, temp1, temp2;
 
    if(SiS_Pr->SiS_VBType & (VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
       if(SiS_Pr->LVDSHL != -1) {
@@ -11948,20 +11523,52 @@ SetPanelParms661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
       }
    }
 
-   myptr = GetLCDStructPtr661(SiS_Pr, HwInfo);
-   if(myptr) {
-      if(SiS_Pr->SiS_VBType & (VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
-         if(SiS_Pr->LVDSHL == -1) {
-            SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xE0,myptr[1] & 0x1f);
-        } else {
-           SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xE3,myptr[1] & 0x1c);
+   if(SiS_Pr->SiS_ROMNew) {
+
+      if((romptr = GetLCDStructPtr661_2(SiS_Pr, HwInfo))) {
+         if(SiS_Pr->SiS_VBType & (VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
+            temp1 = (ROMAddr[romptr] & 0x03) | 0x0c;
+           temp2 = 0xfc;
+           if(SiS_Pr->LVDSHL != -1) {
+             temp1 &= 0xfc;
+             temp2 = 0xf3;
+           }
+           SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,temp2,temp1);
+         }
+        if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
+            temp1 = (ROMAddr[romptr + 1] & 0x80) >> 1;
+            SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0xbf,temp1);
         }
       }
-      SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0x3f,myptr[2] & 0xc0);
+
    }
 }
 
-void
+static void
+SiS_OEM310Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
+                  USHORT ModeNo,USHORT ModeIdIndex,USHORT RRTI)
+{
+   if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
+      SetDelayComp661(SiS_Pr,HwInfo,ModeNo,ModeIdIndex,RRTI);
+      if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
+         SetCRT2SyncDither661(SiS_Pr,HwInfo,ModeNo,RRTI);
+         SetPanelParms661(SiS_Pr,HwInfo);
+      }
+   } else {
+      SetDelayComp(SiS_Pr,HwInfo,ModeNo);
+   }
+
+   if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
+      SetAntiFlicker(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
+      SetPhaseIncr(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
+      SetYFilter(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
+      if(SiS_Pr->SiS_VBType & VB_SIS301) {
+         SetEdgeEnhance(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
+      }
+   }
+}
+
+static void
 SiS_OEM661Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
                   USHORT ModeNo,USHORT ModeIdIndex, USHORT RRTI)
 {
@@ -11978,7 +11585,7 @@ SiS_OEM661Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
          SetPhaseIncr(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
          SetYFilter(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
          SetAntiFlicker(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
-         if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) {
+         if(SiS_Pr->SiS_VBType & VB_SIS301) {
             SetEdgeEnhance(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
          }
       }
@@ -11992,7 +11599,7 @@ SiS_OEM661Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  * function looks quite different in every BIOS, so you better
  * pray that we have a backup...
  */
-void
+static void
 SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                 PSIS_HW_INFO HwInfo)
 {
@@ -12000,6 +11607,7 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
   USHORT resinfo,modeflag;
 
   if(!(SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) return;
+  if(SiS_Pr->SiS_ROMNew) return;
 
   if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
      if(SiS_Pr->LVDSHL != -1) {
@@ -12007,7 +11615,7 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      }
   }
 
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom) return;
+  if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
   if(SiS_Pr->UseCustomMode) return;
 
   switch(SiS_Pr->SiS_CustomT) {
@@ -12037,7 +11645,7 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
   }
 
   if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
         /* Maybe all panels? */
         if(SiS_Pr->LVDSHL == -1) {
            SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
@@ -12048,7 +11656,7 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
   if(SiS_Pr->SiS_CustomT == CUT_CLEVO10242) {
      if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
-        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
+        if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
           if(SiS_Pr->LVDSHL == -1) {
              /* Maybe all panels? */
               SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
@@ -12068,15 +11676,15 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
   }
 
   if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
-     if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
-#ifdef SET_EMI
+     if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
        if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
           SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
+#ifdef SET_EMI
           SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
+#endif
           SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
        }
-#endif
-     } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
+     } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
         if(SiS_Pr->LVDSHL == -1) {
            /* Maybe ACER only? */
            SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
@@ -12084,9 +11692,9 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
      }
      tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
      if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
-       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
+       if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
           SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1f,0x76);
-       } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
+       } else if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
           if(tempch == 0x03) {
              SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
              SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
@@ -12167,7 +11775,7 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
        tempbh >>= 4;
        tempbl = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x04);
        tempbx = (tempbh << 8) | tempbl;
-       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
+       if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
           if((resinfo == SIS_RI_1024x768) || (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD))) {
              if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
                 tempbx = 770;
@@ -12196,7 +11804,7 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
 
 #ifdef SIS300
 
-void
+static void
 SetOEMLCDData2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
                USHORT ModeNo,USHORT ModeIdIndex, USHORT RefTabIndex)
 {
@@ -12256,21 +11864,20 @@ GetOEMLCDPtr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, int Flag)
 
   if(HwInfo->jChipType == SIS_300) {
 
-    tempbx = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f) - 2;
+    tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f;
+    if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07;
+    tempbx -= 2;
     if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4;
-    if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) {
+    if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
        if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 3;
     }
-    if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+    if(SiS_Pr->SiS_UseROM) {
        if(ROMAddr[0x235] & 0x80) {
           tempbx = SiS_Pr->SiS_LCDTypeInfo;
           if(Flag) {
-            romptr = ROMAddr[0x255] | (ROMAddr[0x256] << 8);
-            if(romptr) {
-               tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
-            } else {
-               tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo];
-            }
+            romptr = SISGETROMW(0x255);
+            if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
+            else       tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo];
              if(tempbx == 0xFF) return 0xFFFF;
           }
          tempbx <<= 1;
@@ -12281,13 +11888,10 @@ GetOEMLCDPtr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, int Flag)
   } else {
 
     if(Flag) {
-       if((ROMAddr) && SiS_Pr->SiS_UseROM) {
-          romptr = ROMAddr[0x255] | (ROMAddr[0x256] << 8);
-         if(romptr) {
-            tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
-         } else {
-            tempbx = 0xff;
-         }
+       if(SiS_Pr->SiS_UseROM) {
+          romptr = SISGETROMW(0x255);
+         if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
+         else       tempbx = 0xff;
        } else {
           tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo];
        }
@@ -12300,7 +11904,9 @@ GetOEMLCDPtr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, int Flag)
     tempbx = SiS_Pr->SiS_LCDTypeInfo << 2;
     if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
     if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
+
   }
+
   return tempbx;
 }
 
@@ -12311,12 +11917,12 @@ SetOEMLCDDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
   USHORT index,temp,romptr=0;
 
-  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_PanelCustom) return;
+  if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
 
-  if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+  if(SiS_Pr->SiS_UseROM) {
      if(!(ROMAddr[0x237] & 0x01)) return;
      if(!(ROMAddr[0x237] & 0x02)) return;
-     romptr = ROMAddr[0x24b] | (ROMAddr[0x24c] << 8);
+     romptr = SISGETROMW(0x24b);
   }
 
   /* The Panel Compensation Delay should be set according to tables
@@ -12326,7 +11932,7 @@ SetOEMLCDDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
    * Thus we don't set this if the user select a custom pdc or if
    * we otherwise detected a valid pdc.
    */
-  if(SiS_Pr->PDC) return;
+  if(SiS_Pr->PDC != -1) return;
 
   temp = GetOEMLCDPtr(SiS_Pr,HwInfo, 0);
 
@@ -12338,7 +11944,7 @@ SetOEMLCDDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   if(HwInfo->jChipType != SIS_300) {
      if(romptr) {
        romptr += (temp * 2);
-       romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8);
+       romptr = SISGETROMW(romptr);
        romptr += index;
        temp = ROMAddr[romptr];
      } else {
@@ -12349,21 +11955,21 @@ SetOEMLCDDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
         }
      }
   } else {
-     if((ROMAddr) && SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) {
+     if(SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) {
        if(romptr) {
           romptr += (temp * 2);
-          romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8);
+          romptr = SISGETROMW(romptr);
           romptr += index;
           temp = ROMAddr[romptr];
        } else {
           temp = SiS300_OEMLCDDelay5[temp][index];
        }
      } else {
-        if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+        if(SiS_Pr->SiS_UseROM) {
           romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8);
           if(romptr) {
              romptr += (temp * 2);
-             romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8);
+             romptr = SISGETROMW(romptr);
              romptr += index;
              temp = ROMAddr[romptr];
           } else {
@@ -12386,7 +11992,7 @@ SetOEMLCDData(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
   USHORT index,temp;
 
-  if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+  if((SiS_Pr->SiS_UseROM) {
      if(!(ROMAddr[0x237] & 0x01)) return;
      if(!(ROMAddr[0x237] & 0x04)) return;
      /* No rom pointer in BIOS header! */
@@ -12436,10 +12042,10 @@ SetOEMTVDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
   USHORT index,temp,romptr=0;
 
-  if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+  if(SiS_Pr->SiS_UseROM) {
      if(!(ROMAddr[0x238] & 0x01)) return;
      if(!(ROMAddr[0x238] & 0x02)) return;
-     romptr = ROMAddr[0x241] | (ROMAddr[0x242] << 8);
+     romptr = SISGETROMW(0x241);
   }
 
   temp = GetOEMTVPtr(SiS_Pr);
@@ -12448,7 +12054,7 @@ SetOEMTVDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
 
   if(romptr) {
      romptr += (temp * 2);
-     romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8);
+     romptr = SISGETROMW(romptr);
      romptr += index;
      temp = ROMAddr[romptr];
   } else {
@@ -12459,7 +12065,7 @@ SetOEMTVDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
      }
   }
   temp &= 0x3c;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);  /* index 0A D[6:4] */
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);
 }
 
 static void
@@ -12469,10 +12075,10 @@ SetOEMAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
   USHORT index,temp,romptr=0;
 
-  if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+  if(SiS_Pr->SiS_UseROM) {
      if(!(ROMAddr[0x238] & 0x01)) return;
      if(!(ROMAddr[0x238] & 0x04)) return;
-     romptr = ROMAddr[0x243] | (ROMAddr[0x244] << 8);
+     romptr = SISGETROMW(0x243);
   }
 
   temp = GetOEMTVPtr(SiS_Pr);
@@ -12481,14 +12087,14 @@ SetOEMAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
 
   if(romptr) {
      romptr += (temp * 2);
-     romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8);
+     romptr = SISGETROMW(romptr);
      romptr += index;
      temp = ROMAddr[romptr];
   } else {
      temp = SiS300_OEMTVFlicker[temp][index];
   }
   temp &= 0x70;
-  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp);  /* index 0A D[6:4] */
+  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp);
 }
 
 static void
@@ -12502,10 +12108,10 @@ SetOEMPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
 
   if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetNTSCJ | TVSetPALM | TVSetPALN)) return;
 
-  if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+  if(SiS_Pr->SiS_UseROM) {
      if(!(ROMAddr[0x238] & 0x01)) return;
      if(!(ROMAddr[0x238] & 0x08)) return;
-     romptr = ROMAddr[0x245] | (ROMAddr[0x246] << 8);
+     romptr = SISGETROMW(0x245);
   }
 
   temp = GetOEMTVPtr(SiS_Pr);
@@ -12519,7 +12125,7 @@ SetOEMPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   } else {
      if(romptr) {
         romptr += (temp * 2);
-       romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8);
+       romptr = SISGETROMW(romptr);
        romptr += (index * 4);
         for(i=0x31, j=0; i<=0x34; i++, j++) {
           SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
@@ -12541,10 +12147,10 @@ SetOEMYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
 
   if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return;
 
-  if((ROMAddr) && SiS_Pr->SiS_UseROM) {
+  if(SiS_Pr->SiS_UseROM) {
      if(!(ROMAddr[0x238] & 0x01)) return;
      if(!(ROMAddr[0x238] & 0x10)) return;
-     romptr = ROMAddr[0x247] | (ROMAddr[0x248] << 8);
+     romptr = SISGETROMW(0x247);
   }
 
   temp = GetOEMTVPtr(SiS_Pr);
@@ -12565,7 +12171,7 @@ SetOEMYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
   } else {
       if((romptr) && (!(SiS_Pr->SiS_TVMode & (TVSetPALM|TVSetPALN)))) {
          romptr += (temp * 2);
-        romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8);
+        romptr = SISGETROMW(romptr);
         romptr += (index * 4);
         for(i=0x35, j=0; i<=0x38; i++, j++) {
                    SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
@@ -12602,7 +12208,7 @@ SiS_SearchVBModeID(SiS_Private *SiS_Pr, USHORT *ModeNo)
    return ModeIdIndex;
 }
 
-void
+static void
 SiS_OEM300Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
                  USHORT ModeNo, USHORT ModeIdIndex, USHORT RefTableIndex)
 {