Enscript Output

extractedLnx/linux-2.4.24/drivers/video/sis/init301.c_SiS_SetGroup2.c

void
SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr, USHORT ModeNo,
              USHORT ModeIdIndex,USHORT RefreshRateTableIndex,
	      PSIS_HW_DEVICE_INFO HwDeviceExtension)
{
  USHORT      i, j, tempax, tempbx, tempcx, temp, temp1;
  USHORT      push1, push2;
  const       UCHAR *PhasePoint;
  const       UCHAR *TimingPoint;
#ifdef SIS315H   
  const       SiS_Part2PortTblStruct *CRT2Part2Ptr = NULL;
  USHORT      resindex, CRT2Index;
#endif
  USHORT      modeflag, resinfo, crt2crtc;
  ULONG       longtemp, tempeax;
#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) {
     /* 650/30xLV 1.10.6s: (Is at end of SetGroup2!) */
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
	   SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xfc,0x03);
	   temp = 0x01;
	   if(ModeNo <= 0x13) temp = 0x03;
	   SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x0b,temp);
	}
     }
     SiS_SetTVSpecial(SiS_Pr, ModeNo);
     return;
  }
#endif

  if(ModeNo <= 0x13) {
     modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
     resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
     crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  } else {
     if(SiS_Pr->UseCustomMode) {
        modeflag = SiS_Pr->CModeFlag;
	resinfo = 0;
	crt2crtc = 0;
     } else {
        modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
    	resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
    	crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
     }
  }

  tempcx = SiS_Pr->SiS_VBInfo;
  tempax = (tempcx & 0x00FF) << 8;
  tempbx = (tempcx & 0x00FF) | ((tempcx & 0x00FF) << 8);
  tempbx &= 0x0410;
  temp = (tempax & 0x0800) >> 8;
  temp >>= 1;
  temp |= (((tempbx & 0xFF00) >> 8) << 1);
  temp |= ((tempbx & 0x00FF) >> 3);
  temp ^= 0x0C;

  /* From 1.10.7w (no vb check there; don't care - this only disables SVIDEO and CVBS signal) */
  if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
     temp |= 0x0c;
  }

  PhasePoint  = SiS_Pr->SiS_PALPhase;
  TimingPoint = SiS_Pr->SiS_PALTiming;
  
  if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) {          
  
     temp ^= 0x01;
     if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
        TimingPoint = SiS_Pr->SiS_HiTVSt2Timing;
        if(SiS_Pr->SiS_SetFlag & TVSimuMode) {
           if(modeflag & Charx8Dot) TimingPoint = SiS_Pr->SiS_HiTVSt1Timing;
           else TimingPoint = SiS_Pr->SiS_HiTVTextTiming;
        }
     } else TimingPoint = SiS_Pr->SiS_HiTVExtTiming;

     if(SiS_Pr->SiS_HiVision & 0x03) temp &= 0xfe;

  } else {

     if(SiS_Pr->SiS_VBInfo & SetPALTV){

        TimingPoint = SiS_Pr->SiS_PALTiming;
        PhasePoint  = SiS_Pr->SiS_PALPhase;

        if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
            ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
	      (SiS_Pr->SiS_SetFlag & TVSimuMode) ) ) {
           PhasePoint = SiS_Pr->SiS_PALPhase2;
        }

     } else {

        temp |= 0x10;
        TimingPoint = SiS_Pr->SiS_NTSCTiming;
        PhasePoint  = SiS_Pr->SiS_NTSCPhase;

        if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
	    ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
	      (SiS_Pr->SiS_SetFlag & TVSimuMode) ) ) {
           PhasePoint = SiS_Pr->SiS_NTSCPhase2;
        }

     }

  }
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x00,temp);

  temp = 0;
  if((HwDeviceExtension->jChipType == SIS_630)||
     (HwDeviceExtension->jChipType == SIS_730)) {
     temp = 0x35;
  }
  if(HwDeviceExtension->jChipType >= SIS_315H) {
     temp = 0x38;
  }
  if(temp) {
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
        if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & 0x01) {
           temp1 = SiS_GetReg1(SiS_Pr->SiS_P3d4,temp);
           if(temp1 & EnablePALM) {	/* 0x40 */
              PhasePoint = SiS_Pr->SiS_PALMPhase;
	      if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
		  ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
		    (SiS_Pr->SiS_SetFlag & TVSimuMode) ) ) {
	         PhasePoint = SiS_Pr->SiS_PALMPhase2;
	      }
	   }
           if(temp1 & EnablePALN) {	/* 0x80 */
              PhasePoint = SiS_Pr->SiS_PALNPhase;
	      if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
		  ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
		    (SiS_Pr->SiS_SetFlag & TVSimuMode) ) ) {
	         PhasePoint = SiS_Pr->SiS_PALNPhase2;
	      }
	   }
        }
     }
  }

#ifdef SIS315H
  if(HwDeviceExtension->jChipType >= SIS_315H) {
     if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {  
        if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
           if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) {
              if((ModeNo == 0x64) || (ModeNo == 0x4a) || (ModeNo == 0x38)) {
	         PhasePoint = SiS_Pr->SiS_SpecialPhase;
	      }
           }
        }
     }
  }
#endif

  for(i=0x31, j=0; i<=0x34; i++, j++) {
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,PhasePoint[j]);
  }

  for(i=0x01, j=0; i<=0x2D; i++, j++) {
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  }
  for(i=0x39; i<=0x45; i++, j++) {
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  }

  if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
     if(HwDeviceExtension->jChipType >= SIS_315H) {
        if(!(SiS_Pr->SiS_ModeType & 0x07))
           SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F);
     } else {
        SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F);
     }
  }

  SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode);

  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE);
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE);
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE);
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE);

  if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) {
     if(SiS_Pr->SiS_HiVision == 3) tempax = 950;
     else tempax = 440;
  } else {
     if(SiS_Pr->SiS_VBInfo & SetPALTV) tempax = 520;
     else tempax = 440;
  }

  if( ( ( (!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_HiVision == 3) ) && (SiS_Pr->SiS_VDE <= tempax) ) ||
      ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (SiS_Pr->SiS_HiVision != 3) &&
        ( (SiS_Pr->SiS_VGAHDE == 1024) || ((SiS_Pr->SiS_VGAHDE != 1024) && (SiS_Pr->SiS_VDE <= tempax)) ) ) ) {

     tempax -= SiS_Pr->SiS_VDE;
     tempax >>= 2;
     tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);

     temp = (tempax & 0xFF00) >> 8;
     temp += (USHORT)TimingPoint[0];
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,temp);

     temp = (tempax & 0xFF00) >> 8;
     temp += (USHORT)TimingPoint[1];
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,temp);

     if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToTV - SetCRT2ToHiVisionTV)) &&
         (SiS_Pr->SiS_HiVision != 3) &&
         (SiS_Pr->SiS_VGAHDE >= 1024) ) {
        if(SiS_Pr->SiS_VBInfo & SetPALTV) {
           SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x19);
           SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x52);
        } else {
           if(HwDeviceExtension->jChipType >= SIS_315H) {
              SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x17);
              SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x1d);
	   } else {
              SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x0b);
              SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x11);
	   }
        }
     }

  }

  tempcx = SiS_Pr->SiS_HT;

  /* 650/30xLV 1.10.6s */
  if(SiS_IsDualLink(SiS_Pr, HwDeviceExtension, BaseAddr)) {
     tempcx >>= 1;
  }

  tempcx--;
  if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
        tempcx--;
  }
  temp = tempcx & 0x00FF;
  SiS_SetReg1(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;

  tempcx += 7;
  if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) &&
     (SiS_Pr->SiS_HiVision == 3)) {
     tempcx -= 4;
  }
  temp = (tempcx & 0x00FF) << 4;
  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,temp);

  tempbx = TimingPoint[j] | ((TimingPoint[j+1]) << 8);
  tempbx += tempcx;

  push2 = tempbx;

  temp = tempbx & 0x00FF;
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x24,temp);
  temp = ((tempbx & 0xFF00) >> 8) << 4;
  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,temp);

  tempbx = push2;

  tempbx += 8;
  if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) &&
     (SiS_Pr->SiS_HiVision == 3)) {
     tempbx -= 4;
     tempcx = tempbx;
  }
  temp = (tempbx & 0x00FF) << 4;
  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,temp);

  j += 2;
  tempcx += ((TimingPoint[j] | ((TimingPoint[j+1]) << 8)));
  temp = tempcx & 0x00FF;
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x27,temp);
  temp = ((tempcx & 0xFF00) >> 8) << 4;
  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,temp);

  tempcx += 8;
  if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) &&
     (SiS_Pr->SiS_HiVision == 3)) {
     tempcx -= 4; 
  }
  temp = (tempcx & 0x00FF) << 4;
  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,temp);

  tempcx = push1;

  j += 2;
  tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
  temp = (tempcx & 0x00FF) << 4;
  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,temp);

  tempcx -= 11;
  if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
     tempax = SiS_GetVGAHT2(SiS_Pr) - 1;
     tempcx = tempax;
  }
  temp = tempcx & 0x00FF;
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2E,temp);

  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(HwDeviceExtension->jChipType < SIS_315H) {
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempbx >>= 1;
  } else {
     if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (!(SiS_Pr->SiS_HiVision & 0x03))) {
	tempbx >>= 1;
	if(SiS_Pr->SiS_SetFlag & TVSimuMode) {
	   if(ModeNo <= 0x13) {
	      if(crt2crtc == 1) {
	         tempbx++;
              }
	   }
	} else {
           if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
	      if(crt2crtc == 4)   /* BIOS calls GetRatePtrCRT2 here - does not make sense */
                 if(SiS_Pr->SiS_ModeType <= 3) tempbx++;
	   }
	}
     }
  }
  tempbx -= 2;
  temp = tempbx & 0x00FF;
  if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) &&
     (SiS_Pr->SiS_HiVision == 3)) {
     if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
        if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) temp++;
     }
  }
  /* From 1.10.7w - doesn't make sense */
  if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
     if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
        if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) {
	   if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {   /* SetFlag?? */
	      if(ModeNo == 0x03) temp++;
	   }
	}
     }
  }
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2F,temp);

  tempax = (tempcx & 0xFF00) | (tempax & 0x00FF);
  tempbx = ((tempbx & 0xFF00) << 6) | (tempbx & 0x00FF);
  tempax |= (tempbx & 0xFF00);
  if(HwDeviceExtension->jChipType < SIS_315H) {
     if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV)) {
        if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART)) {		/* New from 630/301B (II) BIOS */
           tempax |= 0x1000;
           if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO))  tempax |= 0x2000;
        }
     }
  } else {
     /* TODO Check this with other BIOSes */
     if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV))
         /* && (SiS_Pr->SiS_HiVision == 3) */ ) {
	tempax |= 0x1000;
        if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO))  tempax |= 0x2000;
     }
  }
  temp = (tempax & 0xFF00) >> 8;
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x30,temp);

  /* 650/30xLV 1.10.6s */
  if(HwDeviceExtension->jChipType > SIS_315H) {
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
        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_VBInfo & SetCRT2ToHiVisionTV) {
     if(SiS_Pr->SiS_HiVision != 3) {
	for(i=0, j=0; i<=0x2d; i++, j++) {
	    SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS_HiVisionTable[SiS_Pr->SiS_HiVision][j]);
	}
	for(i=0x39; i<=0x45; i++, j++) {
	    SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS_HiVisionTable[SiS_Pr->SiS_HiVision][j]);
	}
     }
  }

  if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
     tempbx = SiS_Pr->SiS_VDE;
     if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (!(SiS_Pr->SiS_HiVision & 0x03))) {
        tempbx >>= 1;
     }
     tempbx -= 3;
     tempbx &= 0x03ff;
     temp = ((tempbx & 0xFF00) >> 8) << 5;
     temp |= 0x18;
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x46,temp);
     temp = tempbx & 0x00FF;
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x47,temp);
     if(HwDeviceExtension->jChipType >= SIS_315H) {
        if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
           tempax = 0;
           if(SiS_Pr->SiS_HiVision & 0x03) {
 	      tempax = 0x3000;
	      if(SiS_Pr->SiS_HiVision & 0x01) tempax = 0x5000;
	   }
	   temp = (tempax & 0xFF00) >> 8;
           SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x4d,temp);
        }
     }
  }

  tempbx &= 0x00FF;
  if(!(modeflag & HalfDCLK)) {
     if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) {
        tempbx |= 0x2000;
        tempax &= 0x00FF;
     }
  }

  tempcx = 0x0101;
/*if(SiS_Pr->SiS_VBInfo & (SetPALTV | SetCRT2ToTV)) {  */ /* BIOS BUG? */
  if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV - SetCRT2ToHiVisionTV)) {
     if(!(SiS_Pr->SiS_HiVision & 0x03)) {
        if(SiS_Pr->SiS_VGAHDE >= 1024) {
           if((!(modeflag & HalfDCLK)) || (HwDeviceExtension->jChipType < SIS_315H)) {
              tempcx = 0x1920;
              if(SiS_Pr->SiS_VGAHDE >= 1280) {
                 tempcx = 0x1420;
                 tempbx &= 0xDFFF;
              }
           }
        }
     }
  }

  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;
     tempcx = (tempcx & 0xFF00) | ((tempax & 0xFF00) >> (8 + 5));
     tempbx |= (tempax & 0x1F00);
     tempax = ((tempax & 0x00FF) << 8) | (tempax & 0x00FF);
  }

  temp = (tempax & 0xFF00) >> 8;
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x44,temp);
  temp = (tempbx & 0xFF00) >> 8;
  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,temp);

  if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
     temp = tempcx & 0x00FF;
     if(tempbx & 0x2000) temp = 0;
     temp |= 0x18;
     SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xE0,temp);

     if(SiS_Pr->SiS_VBInfo & SetPALTV) {
        tempbx = 0x0382;
        tempcx = 0x007e;
     } else {
        tempbx = 0x0369;
        tempcx = 0x0061;
     }
     temp = (tempbx & 0x00FF) ;
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x4B,temp);
     temp = (tempcx & 0x00FF) ;
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x4C,temp);
     temp = (tempcx & 0x0300) >> (8 - 2);
     temp |= ((tempbx >> 8) & 0x03);
     if(HwDeviceExtension->jChipType < SIS_315H) {
        SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x4D,temp);
     } else {
        SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4D,0xF0,temp);
     }

     temp = SiS_GetReg1(SiS_Pr->SiS_Part2Port,0x43);
     SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x43,(USHORT)(temp - 3));
  }

  temp = 0;
  if((HwDeviceExtension->jChipType == SIS_630) ||
     (HwDeviceExtension->jChipType == SIS_730)) {
     temp = 0x35;
  } else if(HwDeviceExtension->jChipType >= SIS_315H) {
     temp = 0x38;
  }
  if(temp) {
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
        if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & 0x01) {
           if(SiS_GetReg1(SiS_Pr->SiS_P3d4,temp) & EnablePALM) {  /* 0x40 */
              SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF);
              temp = SiS_GetReg1(SiS_Pr->SiS_Part2Port,0x01);
              SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,temp - 1);
           }
        }
     }
  }

  if(HwDeviceExtension->jChipType >= SIS_315H) {
     if((SiS_Pr->SiS_VBType & VB_SIS301B302B) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
        if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
           SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x0B,0x00);
        }
     }
  }

#if 0  /* Old: Why HiVision? */
  if( (SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) &&
      (!(SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) ) {
     if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
        SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x0B,0x00);
     }
  }
#endif

  if(HwDeviceExtension->jChipType < SIS_315H) {
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
     	SiS_Set300Part2Regs(SiS_Pr, HwDeviceExtension, ModeIdIndex,
			    RefreshRateTableIndex, BaseAddr, ModeNo);
	return;
     }
  } else {
     /* !!! The following is a duplicate, done for LCDA as well (see above) */
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
        SiS_SetTVSpecial(SiS_Pr, ModeNo);
        return;
     }
  }

  /* From here: Part2 LCD setup */

  tempbx = SiS_Pr->SiS_HDE;
  if(SiS_IsDualLink(SiS_Pr, HwDeviceExtension, BaseAddr)) tempbx >>= 1;
  tempbx--;			         	/* RHACTE=HDE-1 */
  temp = tempbx & 0x00FF;
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2C,temp);
  temp = (tempbx & 0xFF00) >> 4;
  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,temp);

  temp = 0x01;
  if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) {
     if(SiS_Pr->SiS_ModeType == ModeEGA) {
        if(SiS_Pr->SiS_VGAHDE >= 1024) {
           temp = 0x02;
	   if(HwDeviceExtension->jChipType >= SIS_315H) {
              if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
                 temp = 0x01;
	      }
	   }
        }
     }
  }
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x0B,temp);

  tempbx = SiS_Pr->SiS_VDE;         		/* RTVACTEO = VDE - 1 */
  /* push1 = tempbx; */
  tempbx--;
  temp = tempbx & 0x00FF;
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x03,temp);
  temp = ((tempbx & 0xFF00) >> 8) & 0x07;
  SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,temp);

  tempcx = SiS_Pr->SiS_VT;
  /* push2 = tempcx; */
  tempcx--;
  temp = tempcx & 0x00FF;  			 /* RVTVT = VT - 1 */
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x19,temp);

  temp = (tempcx & 0xFF00) >> 8;
  temp <<= 5;
  
  /* Enable dithering; newer versions only do this for 32bpp mode */
  if((HwDeviceExtension->jChipType == SIS_300) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) {
     if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp |= 0x10;
  } else if(HwDeviceExtension->jChipType < SIS_315H) {
     temp |= 0x10;
  } else {
     if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
        /* 650/30xLV 1.10.6s */
        if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
           if(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {  /* 32bpp mode? */
              temp |= 0x10;
	   }
        }
     } else {
        temp |= 0x10;
     }
  }

  /* 630/301 does not do all this */
  if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
     if((HwDeviceExtension->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
	if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
	   (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024)) {
#ifdef SIS315H
	   if(SiS_Pr->SiS_LCDInfo & LCDSync) {
	      temp |= (SiS_Pr->SiS_LCDInfo >> 6);
	   }
#endif
	} else {
	   /* 650/30xLV 1.10.6s */
           temp |= (SiS_GetReg1(SiS_Pr->SiS_P3d4,0x37) >> 6);
	   temp |= 0x08;   						/* From 1.10.7w */
	   if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) temp |= 0x04; 	/* From 1.10.7w */
	}
     } else {
        if(SiS_Pr->SiS_LCDInfo & LCDSync) {
	   temp |= (SiS_Pr->SiS_LCDInfo >> 6);
	}
     }
  }
  SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1A,temp);

  SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0);
  SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0);

  SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
  SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);

  if((HwDeviceExtension->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 ------------ */

      /* Using this on the 301B with an auto-expanding 1024 panel (CR37=1) results
       * in a black bar in modes < 1024; if the panel is non-expanding, the bridge
       * scales all modes to 1024. All modes in both variants (exp/non-exp) work.
       */

      SiS_GetCRT2Part2Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
                         &CRT2Index,&resindex,HwDeviceExtension,BaseAddr);

      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;
	default:                   CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_3;  break;
      }

      SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
      SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
      for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
        SiS_SetReg1(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
      }
      for(j = 0x1c; j <= 0x1d; i++, j++ ) {
        SiS_SetReg1(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
      }
      for(j = 0x1f; j <= 0x21; i++, j++ ) {
        SiS_SetReg1(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
      }
      SiS_SetReg1(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_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,temp);
	  SiS_SetReg1(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_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,temp);
	}
     }

     /* !!! This is a duplicate, done for LCDA as well - see above */
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
        if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
	   SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xfc,0x03);   /* Not done in 1.10.7w */
	   temp = 1;
	   if(ModeNo <= 0x13) temp = 3;
	   SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x0b,temp);
	}
     }
#endif

  } 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 !!!
       */

    /* cx = VT - 1 */

    tempcx++;

    tempbx = SiS_Pr->PanelYRes;

    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;
          } else {
             tempax -= SiS_Pr->SiS_VDE;
          }
          tempax >>= 1;
       }
       tempcx -= tempax; /* lcdvdes */
       tempbx -= tempax; /* lcdvdee */
    }
#if 0  /* meaningless: 1 / 2 = 0... */
    else {
       tempax >>= 1;
       tempcx -= tempax; /* lcdvdes */
       tempbx -= tempax; /* lcdvdee */
    }
#endif

    /* Non-expanding: lcdvdees = 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_SetReg1(SiS_Pr->SiS_Part2Port,0x05,temp);
    temp = tempbx & 0x00FF;   				/* RVEQ2EQ=lcdvdee */
    SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x06,temp);

    temp = ((tempbx & 0xFF00) >> 8) << 3;
    temp |= ((tempcx & 0xFF00) >> 8);
    SiS_SetReg1(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;

    /* non-expanding: lcdvrs = tempbx = ((VT + VDE) / 2) - 10 */

    if(SiS_Pr->UseCustomMode) {
       tempbx = SiS_Pr->CVSyncStart;
    }

#ifdef TWDEBUG
    xf86DrvMsg(0, X_INFO, "lcdvrs 0x%x\n", tempbx);
#endif

    temp = tempbx & 0x00FF;   				/* RTVACTEE = lcdvrs */
    SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,temp);

    temp = ((tempbx & 0xFF00) >> 8) << 4;
    tempbx += (tempcx + 1);
    temp |= (tempbx & 0x000F);

    if(SiS_Pr->UseCustomMode) {
       temp &= 0xf0;
       temp |= (SiS_Pr->CVSyncEnd & 0x0f);
    }

#ifdef TWDEBUG
    xf86DrvMsg(0, X_INFO, "lcdvre[3:0] 0x%x\n", (temp & 0x0f));
#endif

    SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,temp);

    /* Code from 630/301B (I+II) BIOS */

    if(!SiS_Pr->UseCustomMode) {
       if( ( ( (HwDeviceExtension->jChipType == SIS_630) ||
               (HwDeviceExtension->jChipType == SIS_730) ) &&
             (HwDeviceExtension->jChipRevision > 2) )  &&
           (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) &&
           (!(SiS_Pr->SiS_SetFlag & LCDVESATiming))  &&
           (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
          if(ModeNo == 0x13) {
             SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,0xB9);
             SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x05,0xCC);
             SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x06,0xA6);
          } else {
             if((crt2crtc & 0x3F) == 4) {
                SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x2B);
                SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x13);
                SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,0xE5);
                SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x05,0x08);
                SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x06,0xE2);
             }
          }
       }
    }

#ifdef SIS300
    if(HwDeviceExtension->jChipType < SIS_315H) {
       if(!SiS_Pr->UseCustomMode) {
          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_SetReg1(SiS_Pr->SiS_Part2Port,0x06,0xff);
             }

             if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
                if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
                   if(crt2crtc == 4) {
                      SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x28);
                   }
                }
             }
             SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x18);
             SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
          }
       }
    }
#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;
    }
    push1 = tempbx;

#ifdef TWDEBUG
    xf86DrvMsg(0, X_INFO, "lcdhdee 0x%x\n", tempbx);
#endif

    temp = tempbx & 0x00FF;    			          /* RHEQPLE = lcdhdee */
    SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x23,temp);
    temp = (tempbx & 0xFF00) >> 8;
    SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,temp);

    temp = 7;
    if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
       temp += 2;
    }
    SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1F,temp);  	  /* RHBLKE = lcdhdes[7:0] */
    SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x20,0x0F);	  /* lcdhdes [11:8] */

    tempbx += tempcx;
    push2 = tempbx;

    if(SiS_Pr->UseCustomMode) {
       tempbx = SiS_Pr->CHSyncStart + 7;
       if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
          tempbx += 2;
       }
    }

#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_SetReg1(SiS_Pr->SiS_Part2Port,0x1C,temp);
    temp = (tempbx & 0x0F00) >> 4;
    SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,temp);

    tempbx = push2;
    tempcx <<= 1;
    tempbx += tempcx;

    if(SiS_Pr->UseCustomMode) {
       tempbx = SiS_Pr->CHSyncEnd + 7;
       if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
          tempbx += 2;
       }
    }

#ifdef TWDEBUG
    xf86DrvMsg(0, X_INFO, "lcdhre 0x%x\n", tempbx);
#endif

    temp = tempbx & 0x00FF;            		          /* RHSYEXP2S = lcdhre */
    SiS_SetReg1(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_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,temp);
          SiS_SetReg1(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_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,temp);
       }
    }
    SiS_Set300Part2Regs(SiS_Pr, HwDeviceExtension, ModeIdIndex,
                        RefreshRateTableIndex, BaseAddr, ModeNo);

  } /* HwDeviceExtension */
}

Generated by GNU enscript 1.6.4.