]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/xgifb/vb_setmode.c
5078788f48d03cf465de2fb87f6f4d21743cd958
[mv-sheeva.git] / drivers / staging / xgifb / vb_setmode.c
1 #include "osdef.h"
2
3
4
5
6 #ifdef LINUX_KERNEL
7 #include <asm/io.h>
8 #include <linux/types.h>
9 #include <linux/version.h>
10 #include "XGIfb.h"
11 #endif
12
13
14 #include "vb_def.h"
15 #include "vgatypes.h"
16 #include "vb_struct.h"
17 #include "vb_util.h"
18 #include "vb_table.h"
19
20
21
22 #define  IndexMask 0xff
23 #ifndef XGI_MASK_DUAL_CHIP
24 #define XGI_MASK_DUAL_CHIP        0x04  /* SR3A */
25 #endif
26
27
28
29 BOOLEAN  XGI_IsLCDDualLink(PVB_DEVICE_INFO pVBInfo);
30 BOOLEAN  XGI_SetCRT2Group301(USHORT ModeNo, PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO pVBInfo);
31 BOOLEAN  XGI_BacklightByDrv(PVB_DEVICE_INFO pVBInfo);
32
33 BOOLEAN  XGI_IsLCDON(PVB_DEVICE_INFO pVBInfo);
34 BOOLEAN  XGI_DisableChISLCD(PVB_DEVICE_INFO pVBInfo);
35 BOOLEAN  XGI_EnableChISLCD(PVB_DEVICE_INFO pVBInfo);
36 BOOLEAN  XGI_AjustCRT2Rate(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,USHORT *i, PVB_DEVICE_INFO pVBInfo);
37 BOOLEAN  XGI_SearchModeID( USHORT ModeNo,USHORT  *ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
38 BOOLEAN  XGI_GetLCDInfo(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
39 BOOLEAN  XGISetModeNew( PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT ModeNo ) ;
40 BOOLEAN  XGI_BridgeIsOn(PVB_DEVICE_INFO pVBInfo);
41 UCHAR    XGI_GetModePtr( USHORT ModeNo,USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo);
42 USHORT   XGI_GetOffset(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO pVBInfo);
43 USHORT   XGI_GetRatePtrCRT2( PXGI_HW_DEVICE_INFO pXGIHWDE, USHORT ModeNo,USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo );
44 USHORT   XGI_GetResInfo(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
45 USHORT   XGI_GetColorDepth(USHORT ModeNo,USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo);
46 USHORT   XGI_GetVGAHT2(PVB_DEVICE_INFO pVBInfo);
47 USHORT   XGI_GetVCLK2Ptr(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO pVBInfo);
48 void     XGI_VBLongWait(PVB_DEVICE_INFO pVBInfo);
49 void     XGI_SaveCRT2Info(USHORT ModeNo, PVB_DEVICE_INFO pVBInfo);
50 void     XGI_GetCRT2Data(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
51 void     XGI_GetCRT2ResInfo(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
52 void     XGI_PreSetGroup1(USHORT ModeNo,USHORT ModeIdIndex, PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
53 void     XGI_SetGroup1(USHORT ModeNo,USHORT ModeIdIndex, PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
54 void     XGI_SetLockRegs(USHORT ModeNo,USHORT ModeIdIndex, PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
55 void     XGI_SetLCDRegs(USHORT ModeNo,USHORT ModeIdIndex, PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
56 void     XGI_SetGroup2(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo);
57 void     XGI_SetGroup3(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
58 void     XGI_SetGroup4(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo);
59 void     XGI_SetGroup5(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
60 void*    XGI_GetLcdPtr(USHORT BX,  USHORT ModeNo, USHORT ModeIdIndex, USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
61 void*    XGI_GetTVPtr(USHORT BX, USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
62 void     XGI_FirePWDEnable(PVB_DEVICE_INFO pVBInfo);
63 void     XGI_EnableGatingCRT(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo);
64 void     XGI_DisableGatingCRT(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo);
65 void     XGI_SetPanelDelay(USHORT tempbl, PVB_DEVICE_INFO pVBInfo);
66 void     XGI_SetPanelPower(USHORT tempah,USHORT tempbl, PVB_DEVICE_INFO pVBInfo);
67 void     XGI_EnablePWD( PVB_DEVICE_INFO pVBInfo);
68 void     XGI_DisablePWD( PVB_DEVICE_INFO pVBInfo);
69 void     XGI_AutoThreshold( PVB_DEVICE_INFO pVBInfo);
70 void     XGI_SetTap4Regs( PVB_DEVICE_INFO pVBInfo);
71
72 void     XGI_DisplayOn(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO pVBInfo);
73 void     XGI_DisplayOff( PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO pVBInfo );
74 void     XGI_SetCRT1Group(PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo,USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo);
75 void     XGI_SetXG21CRTC(USHORT ModeNo, USHORT ModeIdIndex, USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
76 void     XGI_SetXG21LCD(PVB_DEVICE_INFO pVBInfo,USHORT RefreshRateTableIndex,USHORT ModeNo);
77 void     XGI_SetXG27CRTC(USHORT ModeNo, USHORT ModeIdIndex, USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
78 void     XGI_SetXG27LCD(PVB_DEVICE_INFO pVBInfo,USHORT RefreshRateTableIndex,USHORT ModeNo);
79 void     XGI_UpdateXG21CRTC(USHORT ModeNo, PVB_DEVICE_INFO pVBInfo, USHORT RefreshRateTableIndex);
80 void     XGI_WaitDisply(PVB_DEVICE_INFO pVBInfo);
81 void     XGI_SenseCRT1(PVB_DEVICE_INFO pVBInfo);
82 void     XGI_SetSeqRegs(USHORT ModeNo,USHORT StandTableIndex,USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo);
83 void     XGI_SetMiscRegs(USHORT StandTableIndex, PVB_DEVICE_INFO pVBInfo);
84 void     XGI_SetCRTCRegs(PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT StandTableIndex, PVB_DEVICE_INFO pVBInfo);
85 void     XGI_SetATTRegs(USHORT ModeNo,USHORT StandTableIndex,USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo );
86 void     XGI_SetGRCRegs(USHORT StandTableIndex, PVB_DEVICE_INFO pVBInfo);
87 void     XGI_ClearExt1Regs(PVB_DEVICE_INFO pVBInfo);
88
89 void     XGI_SetSync(USHORT RefreshRateTableIndex,PVB_DEVICE_INFO pVBInfo);
90 void     XGI_SetCRT1CRTC(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PVB_DEVICE_INFO pVBInfo,PXGI_HW_DEVICE_INFO HwDeviceExtension);
91 void     XGI_SetCRT1Timing_H(PVB_DEVICE_INFO pVBInfo,PXGI_HW_DEVICE_INFO HwDeviceExtension);
92 void     XGI_SetCRT1Timing_V(USHORT ModeIdIndex,USHORT ModeNo,PVB_DEVICE_INFO pVBInfo);
93 void     XGI_SetCRT1DE(PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PVB_DEVICE_INFO pVBInfo);
94 void     XGI_SetCRT1VCLK(USHORT ModeNo,USHORT ModeIdIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
95 void     XGI_SetCRT1FIFO(USHORT ModeNo,PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo);
96 void     XGI_SetCRT1ModeRegs(PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PVB_DEVICE_INFO pVBInfo);
97 void     XGI_SetVCLKState(PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo,USHORT RefreshRateTableIndex,PVB_DEVICE_INFO pVBInfo);
98
99 void     XGI_LoadDAC(USHORT ModeNo,USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo);
100 void     XGI_WriteDAC(USHORT dl, USHORT ah, USHORT al, USHORT dh, PVB_DEVICE_INFO pVBInfo);
101 /*void     XGI_ClearBuffer(PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo,PVB_DEVICE_INFO pVBInfo);*/
102 void     XGI_SetLCDAGroup(USHORT ModeNo,USHORT ModeIdIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO  pVBInfo);
103 void     XGI_GetLVDSResInfo( USHORT ModeNo,USHORT ModeIdIndex,PVB_DEVICE_INFO  pVBInfo);
104 void     XGI_GetLVDSData(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PVB_DEVICE_INFO  pVBInfo);
105 void     XGI_ModCRT1Regs(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO  pVBInfo);
106 void     XGI_SetLVDSRegs(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PVB_DEVICE_INFO  pVBInfo);
107 void     XGI_UpdateModeInfo(PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO  pVBInfo);
108 void     XGI_GetVGAType(PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO  pVBInfo);
109 void     XGI_GetVBType(PVB_DEVICE_INFO  pVBInfo);
110 void     XGI_GetVBInfo(USHORT ModeNo,USHORT ModeIdIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO  pVBInfo);
111 void     XGI_GetTVInfo(USHORT ModeNo,USHORT ModeIdIndex,PVB_DEVICE_INFO  pVBInfo);
112 void     XGI_SetCRT2ECLK( USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PVB_DEVICE_INFO  pVBInfo);
113 void     InitTo330Pointer(UCHAR,PVB_DEVICE_INFO pVBInfo);
114 void     XGI_GetLCDSync(USHORT* HSyncWidth, USHORT* VSyncWidth, PVB_DEVICE_INFO pVBInfo);
115 void     XGI_DisableBridge(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo);
116 void     XGI_EnableBridge(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo);
117 void     XGI_SetCRT2VCLK(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
118 void     XGI_OEM310Setting(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
119 void     XGI_SetDelayComp(PVB_DEVICE_INFO pVBInfo);
120 void     XGI_SetLCDCap(PVB_DEVICE_INFO pVBInfo);
121 void     XGI_SetLCDCap_A(USHORT tempcx,PVB_DEVICE_INFO pVBInfo);
122 void     XGI_SetLCDCap_B(USHORT tempcx,PVB_DEVICE_INFO pVBInfo);
123 void     SetSpectrum(PVB_DEVICE_INFO pVBInfo);
124 void     XGI_SetAntiFlicker(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
125 void     XGI_SetEdgeEnhance(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
126 void     XGI_SetPhaseIncr(PVB_DEVICE_INFO pVBInfo);
127 void     XGI_SetYFilter(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
128 void     XGI_GetTVPtrIndex2(USHORT* tempbx,UCHAR* tempcl,UCHAR* tempch, PVB_DEVICE_INFO pVBInfo);
129 USHORT   XGI_GetTVPtrIndex(  PVB_DEVICE_INFO pVBInfo );
130 void     XGI_SetCRT2ModeRegs(USHORT ModeNo,PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO pVBInfo );
131 void     XGI_CloseCRTC(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO pVBInfo);
132 void     XGI_OpenCRTC(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO pVBInfo);
133 void     XGI_GetRAMDAC2DATA(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo);
134 void     XGI_UnLockCRT2(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO pVBInfo);
135 void     XGI_LockCRT2(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO pVBInfo);
136 void     XGINew_EnableCRT2(PVB_DEVICE_INFO pVBInfo);
137 void     XGINew_LCD_Wait_Time(UCHAR DelayTime, PVB_DEVICE_INFO pVBInfo);
138 void     XGI_LongWait(PVB_DEVICE_INFO pVBInfo);
139 void     XGI_SetCRT1Offset( USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex , PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO pVBInfo );
140 void     XGI_GetLCDVCLKPtr(UCHAR* di_0,UCHAR *di_1, PVB_DEVICE_INFO pVBInfo);
141 UCHAR    XGI_GetVCLKPtr(USHORT RefreshRateTableIndex,USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo);
142 void     XGI_GetVCLKLen(UCHAR tempal,UCHAR* di_0,UCHAR* di_1, PVB_DEVICE_INFO pVBInfo);
143 USHORT   XGI_GetLCDCapPtr(PVB_DEVICE_INFO pVBInfo);
144 USHORT   XGI_GetLCDCapPtr1(PVB_DEVICE_INFO pVBInfo);
145 XGI301C_Tap4TimingStruct* XGI_GetTap4Ptr(USHORT tempcx, PVB_DEVICE_INFO pVBInfo);
146 void     XGI_SetXG21FPBits(PVB_DEVICE_INFO pVBInfo);
147 void     XGI_SetXG27FPBits(PVB_DEVICE_INFO pVBInfo);
148 UCHAR    XGI_XG21GetPSCValue(PVB_DEVICE_INFO pVBInfo);
149 UCHAR    XGI_XG27GetPSCValue(PVB_DEVICE_INFO pVBInfo);
150 void     XGI_XG21BLSignalVDD(USHORT tempbh,USHORT tempbl, PVB_DEVICE_INFO pVBInfo);
151 void     XGI_XG27BLSignalVDD(USHORT tempbh,USHORT tempbl, PVB_DEVICE_INFO pVBInfo);
152 void     XGI_XG21SetPanelDelay(USHORT tempbl, PVB_DEVICE_INFO pVBInfo);
153 BOOLEAN  XGI_XG21CheckLVDSMode(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo );
154 void     XGI_SetXG21LVDSPara(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo );
155 void     XGI_SetXG27LVDSPara(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo );
156 UCHAR    XGI_SetDefaultVCLK( PVB_DEVICE_INFO pVBInfo );
157
158 extern   void     ReadVBIOSTablData( UCHAR ChipType , PVB_DEVICE_INFO pVBInfo);
159
160 /* USHORT XGINew_flag_clearbuffer; 0: no clear frame buffer 1:clear frame buffer */
161
162
163
164
165
166 USHORT XGINew_MDA_DAC[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
167                0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
168                0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
169                0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
170                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
171                0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
172                0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
173                0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F};
174
175 USHORT XGINew_CGA_DAC[]={0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
176                0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
177                0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F,
178                0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F,
179                0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
180                0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
181                0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F,
182                0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F};
183
184 USHORT XGINew_EGA_DAC[]={0x00,0x10,0x04,0x14,0x01,0x11,0x05,0x15,
185                0x20,0x30,0x24,0x34,0x21,0x31,0x25,0x35,
186                0x08,0x18,0x0C,0x1C,0x09,0x19,0x0D,0x1D,
187                0x28,0x38,0x2C,0x3C,0x29,0x39,0x2D,0x3D,
188                0x02,0x12,0x06,0x16,0x03,0x13,0x07,0x17,
189                0x22,0x32,0x26,0x36,0x23,0x33,0x27,0x37,
190                0x0A,0x1A,0x0E,0x1E,0x0B,0x1B,0x0F,0x1F,
191                0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F};
192
193 USHORT XGINew_VGA_DAC[]={0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
194                0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F,
195                0x00,0x05,0x08,0x0B,0x0E,0x11,0x14,0x18,
196                0x1C,0x20,0x24,0x28,0x2D,0x32,0x38,0x3F,
197
198                0x00,0x10,0x1F,0x2F,0x3F,0x1F,0x27,0x2F,
199                0x37,0x3F,0x2D,0x31,0x36,0x3A,0x3F,0x00,
200                0x07,0x0E,0x15,0x1C,0x0E,0x11,0x15,0x18,
201                0x1C,0x14,0x16,0x18,0x1A,0x1C,0x00,0x04,
202                0x08,0x0C,0x10,0x08,0x0A,0x0C,0x0E,0x10,
203                0x0B,0x0C,0x0D,0x0F,0x10};
204
205
206 /* --------------------------------------------------------------------- */
207 /* Function : InitTo330Pointer */
208 /* Input : */
209 /* Output : */
210 /* Description : */
211 /* --------------------------------------------------------------------- */
212 void InitTo330Pointer( UCHAR ChipType ,PVB_DEVICE_INFO pVBInfo)
213 {
214     pVBInfo->SModeIDTable = (XGI_StStruct *) XGI330_SModeIDTable ;
215     pVBInfo->StandTable = (XGI_StandTableStruct *) XGI330_StandTable ;
216     pVBInfo->EModeIDTable = (XGI_ExtStruct *) XGI330_EModeIDTable ;
217     pVBInfo->RefIndex = (XGI_Ext2Struct *) XGI330_RefIndex ;
218     pVBInfo->XGINEWUB_CRT1Table = (XGI_CRT1TableStruct *) XGI_CRT1Table ;
219
220     /* add for new UNIVGABIOS */
221     /* XGINew_UBLCDDataTable = (XGI_LCDDataTablStruct *) XGI_LCDDataTable ; */
222     /* XGINew_UBTVDataTable = (XGI_TVDataTablStruct *) XGI_TVDataTable ; */
223
224
225     if ( ChipType >= XG40 )
226     {
227         pVBInfo->MCLKData = (XGI_MCLKDataStruct *) XGI340New_MCLKData ;
228         pVBInfo->ECLKData = (XGI_ECLKDataStruct *) XGI340_ECLKData ;
229     }
230     else
231     {
232         pVBInfo->MCLKData = (XGI_MCLKDataStruct *) XGI330New_MCLKData ;
233         pVBInfo->ECLKData = (XGI_ECLKDataStruct *) XGI330_ECLKData ;
234     }
235
236     pVBInfo->VCLKData = (XGI_VCLKDataStruct *) XGI_VCLKData ;
237     pVBInfo->VBVCLKData = (XGI_VBVCLKDataStruct *) XGI_VBVCLKData ;
238     pVBInfo->ScreenOffset = XGI330_ScreenOffset ;
239     pVBInfo->StResInfo = (XGI_StResInfoStruct *) XGI330_StResInfo ;
240     pVBInfo->ModeResInfo = (XGI_ModeResInfoStruct *) XGI330_ModeResInfo ;
241
242     pVBInfo->pOutputSelect = &XGI330_OutputSelect ;
243     pVBInfo->pSoftSetting = &XGI330_SoftSetting ;
244     pVBInfo->pSR07 = &XGI330_SR07 ;
245     pVBInfo->LCDResInfo = 0 ;
246     pVBInfo->LCDTypeInfo = 0 ;
247     pVBInfo->LCDInfo = 0 ;
248     pVBInfo->VBInfo = 0 ;
249     pVBInfo->TVInfo = 0;
250
251
252     pVBInfo->SR15 = XGI340_SR13 ;
253     pVBInfo->CR40 = XGI340_cr41 ;
254     pVBInfo->SR25 = XGI330_sr25 ;
255     pVBInfo->pSR31 = &XGI330_sr31 ;
256     pVBInfo->pSR32 = &XGI330_sr32 ;
257     pVBInfo->CR6B = XGI340_CR6B ;
258     pVBInfo->CR6E = XGI340_CR6E ;
259     pVBInfo->CR6F = XGI340_CR6F ;
260     pVBInfo->CR89 = XGI340_CR89 ;
261     pVBInfo->AGPReg = XGI340_AGPReg ;
262     pVBInfo->SR16 = XGI340_SR16 ;
263     pVBInfo->pCRCF = &XG40_CRCF ;
264     pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition ;
265
266
267     pVBInfo->CR49 = XGI330_CR49 ;
268     pVBInfo->pSR1F = &XGI330_SR1F ;
269     pVBInfo->pSR21 = &XGI330_SR21 ;
270     pVBInfo->pSR22 = &XGI330_SR22 ;
271     pVBInfo->pSR23 = &XGI330_SR23 ;
272     pVBInfo->pSR24 = &XGI330_SR24 ;
273     pVBInfo->pSR33 = &XGI330_SR33 ;
274
275
276
277     pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2 ;
278     pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D ;
279     pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E ;
280     pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10 ;
281     pVBInfo->pRGBSenseData = &XGI330_RGBSenseData ;
282     pVBInfo->pVideoSenseData = &XGI330_VideoSenseData ;
283     pVBInfo->pYCSenseData = &XGI330_YCSenseData ;
284     pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2 ;
285     pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2 ;
286     pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2 ;
287
288     pVBInfo->NTSCTiming = XGI330_NTSCTiming ;
289     pVBInfo->PALTiming = XGI330_PALTiming ;
290     pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming ;
291     pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing ;
292     pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing ;
293     pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming ;
294     pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming ;
295     pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming ;
296     pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming ;
297     pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data ;
298     pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu ;
299     pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text ;
300     pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3 ;
301     pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3 ;
302
303
304     pVBInfo->TimingH = (XGI_TimingHStruct *) XGI_TimingH ;
305     pVBInfo->TimingV = (XGI_TimingVStruct *) XGI_TimingV ;
306     pVBInfo->UpdateCRT1 = (XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table ;
307
308     pVBInfo->CHTVVCLKUNTSC = XGI330_CHTVVCLKUNTSC ;
309     pVBInfo->CHTVVCLKONTSC = XGI330_CHTVVCLKONTSC ;
310     pVBInfo->CHTVVCLKUPAL = XGI330_CHTVVCLKUPAL ;
311     pVBInfo->CHTVVCLKOPAL = XGI330_CHTVVCLKOPAL ;
312
313     /* 310 customization related */
314     if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
315         pVBInfo->LCDCapList = XGI_LCDDLCapList ;
316     else
317         pVBInfo->LCDCapList = XGI_LCDCapList ;
318
319     if ( ( ChipType == XG21 ) || ( ChipType == XG27 ) )
320         pVBInfo->XG21_LVDSCapList = XGI21_LCDCapList ;
321
322     pVBInfo->XGI_TVDelayList = XGI301TVDelayList ;
323     pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2 ;
324
325
326     pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition ;
327
328     if ( ChipType >= XG20 )
329         pVBInfo->pXGINew_CR97 = &XG20_CR97 ;
330
331     if ( ChipType == XG27 )
332     {
333         pVBInfo->MCLKData = (XGI_MCLKDataStruct *) XGI27New_MCLKData ;
334         pVBInfo->CR40 = XGI27_cr41 ;
335         pVBInfo->pXGINew_CR97 = &XG27_CR97 ;
336         pVBInfo->pSR36 = &XG27_SR36 ;
337         pVBInfo->pCR8F = &XG27_CR8F ;
338         pVBInfo->pCRD0 = XG27_CRD0 ;
339         pVBInfo->pCRDE = XG27_CRDE ;
340         pVBInfo->pSR40 = &XG27_SR40 ;
341         pVBInfo->pSR41 = &XG27_SR41 ;
342
343     }
344
345     if ( ChipType >= XG20 )
346     {
347         pVBInfo->pDVOSetting = &XG21_DVOSetting ;
348         pVBInfo->pCR2E = &XG21_CR2E ;
349         pVBInfo->pCR2F = &XG21_CR2F ;
350         pVBInfo->pCR46 = &XG21_CR46 ;
351         pVBInfo->pCR47 = &XG21_CR47 ;
352     }
353
354 }
355
356
357
358
359
360
361 /* --------------------------------------------------------------------- */
362 /* Function : XGISetModeNew */
363 /* Input : */
364 /* Output : */
365 /* Description : */
366 /* --------------------------------------------------------------------- */
367 BOOLEAN XGISetModeNew( PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT ModeNo )
368 {
369     USHORT ModeIdIndex ;
370         /* PUCHAR pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress ; */
371     VB_DEVICE_INFO VBINF;
372     PVB_DEVICE_INFO pVBInfo = &VBINF;
373     pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase ;
374     pVBInfo->BaseAddr = (ULONG)HwDeviceExtension->pjIOAddress ;
375     pVBInfo->IF_DEF_LVDS = 0 ;
376     pVBInfo->IF_DEF_CH7005 = 0 ;
377     pVBInfo->IF_DEF_LCDA = 1 ;
378     pVBInfo->IF_DEF_CH7017 = 0 ;
379     pVBInfo->IF_DEF_CH7007 = 0 ;                                /* [Billy] 2007/05/14 */
380     pVBInfo->IF_DEF_VideoCapture = 0 ;
381     pVBInfo->IF_DEF_ScaleLCD = 0 ;
382     pVBInfo->IF_DEF_OEMUtil = 0 ;
383     pVBInfo->IF_DEF_PWD = 0 ;
384
385
386     if ( HwDeviceExtension->jChipType >= XG20 )                 /* kuku 2004/06/25 */
387     {
388         pVBInfo->IF_DEF_YPbPr = 0 ;
389         pVBInfo->IF_DEF_HiVision = 0 ;
390         pVBInfo->IF_DEF_CRT2Monitor = 0 ;
391         pVBInfo->VBType = 0 ;  /*set VBType default 0*/
392     }
393     else if ( HwDeviceExtension->jChipType >= XG40 )
394     {
395         pVBInfo->IF_DEF_YPbPr = 1 ;
396         pVBInfo->IF_DEF_HiVision = 1 ;
397         pVBInfo->IF_DEF_CRT2Monitor = 1 ;
398     }
399     else
400     {
401         pVBInfo->IF_DEF_YPbPr = 1 ;
402         pVBInfo->IF_DEF_HiVision = 1 ;
403         pVBInfo->IF_DEF_CRT2Monitor = 0 ;
404     }
405
406     pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14 ;
407     pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24 ;
408     pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10 ;
409     pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e ;
410     pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12 ;
411     pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C ;
412     pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a ;
413     pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16 ;
414     pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17 ;
415     pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18 ;
416     pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19 ;
417     pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A ;
418     pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00 ;
419     pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04 ;
420     pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10 ;
421     pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12 ;
422     pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 ;
423     pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2 ;
424
425     if ( HwDeviceExtension->jChipType == XG21 )  /* for x86 Linux, XG21 LVDS */
426     {
427         if ( ( XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) & 0xE0 ) == 0xC0 )
428         {
429             pVBInfo->IF_DEF_LVDS = 1 ;
430         }
431     }
432     if ( HwDeviceExtension->jChipType == XG27 )
433     {
434         if ( ( XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) & 0xE0 ) == 0xC0 )
435         {
436           if ( XGINew_GetReg1( pVBInfo->P3d4 , 0x30 ) & 0x20 )
437           {
438             pVBInfo->IF_DEF_LVDS = 1 ;
439           }
440         }
441     }
442
443     if ( HwDeviceExtension->jChipType < XG20 )                  /* kuku 2004/06/25 */
444     XGI_GetVBType( pVBInfo ) ;
445
446     InitTo330Pointer( HwDeviceExtension->jChipType, pVBInfo ) ;
447     if ( ModeNo & 0x80 )
448     {
449         ModeNo = ModeNo & 0x7F ;
450 /* XGINew_flag_clearbuffer = 0 ; */
451     }
452 /*    else
453     {
454         XGINew_flag_clearbuffer = 1 ;
455     }
456 */
457     XGINew_SetReg1( pVBInfo->P3c4 , 0x05 , 0x86 ) ;
458
459     if ( HwDeviceExtension->jChipType < XG20 )                  /* kuku 2004/06/25 1.Openkey */
460     XGI_UnLockCRT2( HwDeviceExtension , pVBInfo ) ;
461
462     XGI_SearchModeID( ModeNo , &ModeIdIndex, pVBInfo ) ;
463
464     XGI_GetVGAType(HwDeviceExtension,  pVBInfo) ;
465
466     if ( HwDeviceExtension->jChipType < XG20 )                  /* kuku 2004/06/25 */
467     {
468         XGI_GetVBInfo(ModeNo , ModeIdIndex , HwDeviceExtension, pVBInfo ) ;
469         XGI_GetTVInfo(ModeNo , ModeIdIndex, pVBInfo ) ;
470         XGI_GetLCDInfo(ModeNo , ModeIdIndex, pVBInfo ) ;
471         XGI_DisableBridge( HwDeviceExtension,pVBInfo ) ;
472 /*        XGI_OpenCRTC( HwDeviceExtension, pVBInfo ) ; */
473
474         if ( pVBInfo->VBInfo & ( SetSimuScanMode | SetCRT2ToLCDA ) )
475         {
476             XGI_SetCRT1Group(HwDeviceExtension , ModeNo , ModeIdIndex, pVBInfo ) ;
477
478             if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
479             {
480                 XGI_SetLCDAGroup(ModeNo , ModeIdIndex , HwDeviceExtension, pVBInfo ) ;
481             }
482         }
483         else
484         {
485             if ( !( pVBInfo->VBInfo & SwitchToCRT2) )
486             {
487                 XGI_SetCRT1Group( HwDeviceExtension , ModeNo , ModeIdIndex, pVBInfo ) ;
488                 if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
489                 {
490                     XGI_SetLCDAGroup( ModeNo , ModeIdIndex , HwDeviceExtension, pVBInfo ) ;
491                 }
492             }
493         }
494
495         if ( pVBInfo->VBInfo & ( SetSimuScanMode | SwitchToCRT2 ) )
496         {
497             switch( HwDeviceExtension->ujVBChipID )
498             {
499                 case VB_CHIP_301:
500                     XGI_SetCRT2Group301( ModeNo , HwDeviceExtension, pVBInfo ) ;                /*add for CRT2 */
501                     break ;
502
503                 case VB_CHIP_302:
504                     XGI_SetCRT2Group301(ModeNo , HwDeviceExtension, pVBInfo ) ;         /*add for CRT2 */
505                     break ;
506
507                 default:
508                     break ;
509             }
510         }
511
512         XGI_SetCRT2ModeRegs( ModeNo, HwDeviceExtension,pVBInfo ) ;
513         XGI_OEM310Setting( ModeNo, ModeIdIndex,pVBInfo ) ; /*0212*/
514         XGI_CloseCRTC( HwDeviceExtension, pVBInfo ) ;
515         XGI_EnableBridge( HwDeviceExtension ,pVBInfo) ;
516     }   /* !XG20 */
517     else
518     {
519
520
521         if ( pVBInfo->IF_DEF_LVDS == 1 )
522         {
523             if ( !XGI_XG21CheckLVDSMode(ModeNo , ModeIdIndex, pVBInfo) )
524             {
525               return FALSE;
526             }
527         }
528
529         if ( ModeNo <= 0x13 )
530         {
531             pVBInfo->ModeType = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag & ModeInfoFlag;
532         }
533         else
534         {
535             pVBInfo->ModeType = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag & ModeInfoFlag;
536         }
537
538         pVBInfo->SetFlag = 0 ;
539         if ( pVBInfo->IF_DEF_CH7007 != 1 )
540         {
541             pVBInfo->VBInfo = DisableCRT2Display ;
542         }
543
544
545         XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
546
547         XGI_SetCRT1Group(HwDeviceExtension , ModeNo , ModeIdIndex, pVBInfo ) ;
548
549         XGI_DisplayOn( HwDeviceExtension, pVBInfo ) ;
550         /*
551         if( HwDeviceExtension->jChipType == XG21 )
552           XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x09 , ~0x80 , 0x80 ) ;
553         */
554     }
555
556
557 /*
558     if ( ModeNo <= 0x13 )
559     {
560         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
561     }
562     else
563     {
564         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
565     }
566     pVBInfo->ModeType = modeflag&ModeInfoFlag ;
567     pVBInfo->SetFlag = 0x00 ;
568     pVBInfo->VBInfo = DisableCRT2Display ;
569     temp = XGINew_CheckMemorySize(  HwDeviceExtension , ModeNo , ModeIdIndex, pVBInfo ) ;
570
571     if ( temp == 0 )
572         return( 0 ) ;
573
574     XGI_DisplayOff( HwDeviceExtension, pVBInfo) ;
575     XGI_SetCRT1Group( HwDeviceExtension , ModeNo , ModeIdIndex, pVBInfo ) ;
576     XGI_DisplayOn( HwDeviceExtension, pVBInfo) ;
577 */
578
579     XGI_UpdateModeInfo( HwDeviceExtension, pVBInfo ) ;
580
581     if ( HwDeviceExtension->jChipType < XG20 )                  /* kuku 2004/06/25 */
582 {
583     XGI_LockCRT2( HwDeviceExtension, pVBInfo ) ;
584 }
585
586     return( TRUE ) ;
587 }
588
589
590 /* --------------------------------------------------------------------- */
591 /* Function : XGI_SetCRT1Group */
592 /* Input : */
593 /* Output : */
594 /* Description : */
595 /* --------------------------------------------------------------------- */
596 void XGI_SetCRT1Group( PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
597 {
598     USHORT StandTableIndex ,
599            RefreshRateTableIndex ,
600            b3CC ,
601            temp ;
602
603     USHORT XGINew_P3cc =  pVBInfo->P3cc;
604
605     /* XGINew_CRT1Mode = ModeNo ; // SaveModeID */
606     StandTableIndex = XGI_GetModePtr( ModeNo , ModeIdIndex, pVBInfo ) ;
607     /* XGI_SetBIOSData(ModeNo , ModeIdIndex ) ; */
608     /* XGI_ClearBankRegs( ModeNo , ModeIdIndex ) ; */
609     XGI_SetSeqRegs( ModeNo , StandTableIndex , ModeIdIndex, pVBInfo ) ;
610     XGI_SetMiscRegs( StandTableIndex,  pVBInfo ) ;
611     XGI_SetCRTCRegs( HwDeviceExtension , StandTableIndex,  pVBInfo) ;
612     XGI_SetATTRegs( ModeNo , StandTableIndex , ModeIdIndex, pVBInfo ) ;
613     XGI_SetGRCRegs(  StandTableIndex, pVBInfo ) ;
614     XGI_ClearExt1Regs(pVBInfo) ;
615
616 /* if ( pVBInfo->IF_DEF_ExpLink ) */
617     if ( HwDeviceExtension->jChipType == XG27 )
618     {
619       if ( pVBInfo->IF_DEF_LVDS == 0 )
620       {
621         XGI_SetDefaultVCLK( pVBInfo ) ;
622       }
623     }
624
625     temp = ~ProgrammingCRT2 ;
626     pVBInfo->SetFlag &= temp ;
627     pVBInfo->SelectCRT2Rate = 0 ;
628
629     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
630     {
631         if ( pVBInfo->VBInfo & ( SetSimuScanMode | SetCRT2ToLCDA | SetInSlaveMode ) )
632         {
633             pVBInfo->SetFlag |= ProgrammingCRT2 ;
634          }
635     }
636
637     RefreshRateTableIndex = XGI_GetRatePtrCRT2( HwDeviceExtension, ModeNo , ModeIdIndex, pVBInfo ) ;
638     if ( RefreshRateTableIndex != 0xFFFF )
639     {
640         XGI_SetSync( RefreshRateTableIndex, pVBInfo ) ;
641         XGI_SetCRT1CRTC( ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo, HwDeviceExtension ) ;
642         XGI_SetCRT1DE( HwDeviceExtension , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
643         XGI_SetCRT1Offset( ModeNo , ModeIdIndex , RefreshRateTableIndex , HwDeviceExtension, pVBInfo ) ;
644         XGI_SetCRT1VCLK( ModeNo , ModeIdIndex , HwDeviceExtension , RefreshRateTableIndex, pVBInfo ) ;
645     }
646
647     if ( ( HwDeviceExtension->jChipType >= XG20 )&&
648          ( HwDeviceExtension->jChipType < XG27 ) ) /* fix H/W DCLK/2 bug */
649     {
650         if ( ( ModeNo == 0x00 ) | (ModeNo == 0x01) )
651         {
652             XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , 0x4E) ;
653             XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , 0xE9) ;
654             b3CC =(UCHAR) XGINew_GetReg2(XGINew_P3cc) ;
655             XGINew_SetReg3(XGINew_P3cc ,  (b3CC |= 0x0C) ) ;
656         }
657         else if ( ( ModeNo == 0x04) | ( ModeNo == 0x05) | ( ModeNo == 0x0D) )
658         {
659             XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , 0x1B) ;
660             XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , 0xE3) ;
661             b3CC = (UCHAR)XGINew_GetReg2(XGINew_P3cc) ;
662             XGINew_SetReg3(XGINew_P3cc ,  (b3CC |= 0x0C) ) ;
663         }
664     }
665
666     if ( HwDeviceExtension->jChipType >= XG21 )
667     {
668       temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) ;
669       if ( temp & 0xA0 )
670       {
671
672         /*XGINew_SetRegAND( pVBInfo->P3d4 , 0x4A , ~0x20 ) ;*/  /* Enable write GPIOF */
673         /*XGINew_SetRegAND( pVBInfo->P3d4 , 0x48 , ~0x20 ) ;*/  /* P. DWN */
674         /* XG21 CRT1 Timing */
675         if ( HwDeviceExtension->jChipType == XG27 )
676           XGI_SetXG27CRTC( ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo );
677         else
678         XGI_SetXG21CRTC( ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo );
679
680         XGI_UpdateXG21CRTC( ModeNo , pVBInfo , RefreshRateTableIndex) ;
681
682         if ( HwDeviceExtension->jChipType == XG27 )
683           XGI_SetXG27LCD( pVBInfo , RefreshRateTableIndex , ModeNo );
684         else
685           XGI_SetXG21LCD( pVBInfo , RefreshRateTableIndex , ModeNo );
686
687         if ( pVBInfo->IF_DEF_LVDS == 1 )
688         {
689           if ( HwDeviceExtension->jChipType == XG27 )
690             XGI_SetXG27LVDSPara(ModeNo,ModeIdIndex, pVBInfo );
691           else
692             XGI_SetXG21LVDSPara(ModeNo,ModeIdIndex, pVBInfo );
693         }
694         /*XGINew_SetRegOR( pVBInfo->P3d4 , 0x48 , 0x20 ) ;*/    /* P. ON */
695       }
696     }
697
698     pVBInfo->SetFlag &= ( ~ProgrammingCRT2 ) ;
699     XGI_SetCRT1FIFO(  ModeNo , HwDeviceExtension,  pVBInfo ) ;
700     XGI_SetCRT1ModeRegs(  HwDeviceExtension , ModeNo , ModeIdIndex , RefreshRateTableIndex , pVBInfo) ;
701
702
703     /* XGI_LoadCharacter(); //dif ifdef TVFont */
704
705     XGI_LoadDAC( ModeNo , ModeIdIndex, pVBInfo ) ;
706     /* XGI_ClearBuffer( HwDeviceExtension , ModeNo, pVBInfo ) ; */
707 }
708
709
710 /* --------------------------------------------------------------------- */
711 /* Function : XGI_GetModePtr */
712 /* Input : */
713 /* Output : */
714 /* Description : */
715 /* --------------------------------------------------------------------- */
716 UCHAR XGI_GetModePtr( USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
717 {
718     UCHAR index ;
719
720     if ( ModeNo <= 0x13 )
721         index = pVBInfo->SModeIDTable[ ModeIdIndex ].St_StTableIndex ;
722     else
723     {
724         if ( pVBInfo->ModeType <= 0x02 )
725             index = 0x1B ;      /* 02 -> ModeEGA */
726         else
727             index = 0x0F ;
728     }
729     return( index ) ;           /* Get pVBInfo->StandTable index */
730 }
731
732
733 /* --------------------------------------------------------------------- */
734 /* Function : XGI_SetBIOSData */
735 /* Input : */
736 /* Output : */
737 /* Description : */
738 /* --------------------------------------------------------------------- */
739 /*UCHAR XGI_SetBIOSData( USHORT ModeNo , USHORT ModeIdIndex )
740 {
741     return( 0 ) ;
742 }
743 */
744
745 /* --------------------------------------------------------------------- */
746 /* Function : XGI_ClearBankRegs */
747 /* Input : */
748 /* Output : */
749 /* Description : */
750 /* --------------------------------------------------------------------- */
751 /*UCHAR XGI_ClearBankRegs( USHORT ModeNo , USHORT ModeIdIndex )
752 {
753     return( 0 ) ;
754 }
755 */
756
757 /* --------------------------------------------------------------------- */
758 /* Function : XGI_SetSeqRegs */
759 /* Input : */
760 /* Output : */
761 /* Description : */
762 /* --------------------------------------------------------------------- */
763 void XGI_SetSeqRegs(  USHORT ModeNo , USHORT StandTableIndex , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
764 {
765     UCHAR tempah ,
766           SRdata ;
767
768     USHORT i ,
769            modeflag ;
770
771     if ( ModeNo <= 0x13 )
772         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
773     else
774         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
775
776     XGINew_SetReg1( pVBInfo->P3c4 , 0x00 , 0x03 ) ;             /* Set SR0 */
777     tempah=pVBInfo->StandTable[ StandTableIndex ].SR[ 0 ] ;
778
779     i = SetCRT2ToLCDA ;
780     if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
781     {
782         tempah |= 0x01 ;
783     }
784     else
785     {
786         if ( pVBInfo->VBInfo & ( SetCRT2ToTV | SetCRT2ToLCD ) )
787         {
788             if ( pVBInfo->VBInfo & SetInSlaveMode )
789                 tempah |= 0x01 ;
790         }
791     }
792
793     tempah |= 0x20 ;            /* screen off */
794     XGINew_SetReg1( pVBInfo->P3c4 , 0x01 , tempah ) ;           /* Set SR1 */
795
796     for( i = 02 ; i <= 04 ; i++ )
797     {
798         SRdata = pVBInfo->StandTable[ StandTableIndex ].SR[ i - 1 ] ;   /* Get SR2,3,4 from file */
799         XGINew_SetReg1( pVBInfo->P3c4 , i , SRdata ) ;                          /* Set SR2 3 4 */
800     }
801 }
802
803
804 /* --------------------------------------------------------------------- */
805 /* Function : XGI_SetMiscRegs */
806 /* Input : */
807 /* Output : */
808 /* Description : */
809 /* --------------------------------------------------------------------- */
810 void XGI_SetMiscRegs( USHORT StandTableIndex, PVB_DEVICE_INFO pVBInfo )
811 {
812     UCHAR Miscdata ;
813
814     Miscdata = pVBInfo->StandTable[ StandTableIndex ].MISC ;    /* Get Misc from file */
815 /*
816     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
817     {
818         if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
819         {
820             Miscdata |= 0x0C ;
821         }
822     }
823 */
824
825     XGINew_SetReg3( pVBInfo->P3c2 , Miscdata ) ;                /* Set Misc(3c2) */
826 }
827
828
829 /* --------------------------------------------------------------------- */
830 /* Function : XGI_SetCRTCRegs */
831 /* Input : */
832 /* Output : */
833 /* Description : */
834 /* --------------------------------------------------------------------- */
835 void XGI_SetCRTCRegs( PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT StandTableIndex, PVB_DEVICE_INFO pVBInfo )
836 {
837     UCHAR CRTCdata ;
838     USHORT i ;
839
840     CRTCdata = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x11 ) ;
841     CRTCdata &= 0x7f ;
842     XGINew_SetReg1( pVBInfo->P3d4 , 0x11 , CRTCdata ) ;         /* Unlock CRTC */
843
844     for( i = 0 ; i <= 0x18 ; i++ )
845     {
846         CRTCdata = pVBInfo->StandTable[ StandTableIndex ].CRTC[ i ] ;   /* Get CRTC from file */
847         XGINew_SetReg1( pVBInfo->P3d4 , i , CRTCdata ) ;                                /* Set CRTC( 3d4 ) */
848     }
849 /*
850     if ( ( HwDeviceExtension->jChipType == XGI_630 )&& ( HwDeviceExtension->jChipRevision == 0x30 ) )
851     {
852         if ( pVBInfo->VBInfo & SetInSlaveMode )
853         {
854             if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToTV ) )
855             {
856                 XGINew_SetReg1( pVBInfo->P3d4 , 0x18 , 0xFE ) ;
857             }
858         }
859     }
860 */
861 }
862
863
864 /* --------------------------------------------------------------------- */
865 /* Function : */
866 /* Input : */
867 /* Output : */
868 /* Description : */
869 /* --------------------------------------------------------------------- */
870 void XGI_SetATTRegs( USHORT ModeNo , USHORT StandTableIndex , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
871 {
872     UCHAR ARdata ;
873     USHORT i ,
874            modeflag ;
875
876     if ( ModeNo <= 0x13 )
877         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
878     else
879         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
880
881     for( i = 0 ; i <= 0x13 ; i++ )
882     {
883         ARdata = pVBInfo->StandTable[ StandTableIndex ].ATTR[ i ] ;
884         if ( modeflag & Charx8Dot )     /* ifndef Dot9 */
885         {
886             if ( i == 0x13 )
887             {
888                 if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
889                     ARdata = 0 ;
890                 else
891                 {
892                     if ( pVBInfo->VBInfo & ( SetCRT2ToTV | SetCRT2ToLCD ) )
893                     {
894                         if ( pVBInfo->VBInfo & SetInSlaveMode )
895                             ARdata = 0 ;
896                     }
897                 }
898             }
899         }
900
901         XGINew_GetReg2( pVBInfo->P3da ) ;                       /* reset 3da */
902         XGINew_SetReg3( pVBInfo->P3c0 , i ) ;           /* set index */
903         XGINew_SetReg3( pVBInfo->P3c0 , ARdata ) ;      /* set data */
904     }
905
906     XGINew_GetReg2( pVBInfo->P3da ) ;                   /* reset 3da */
907     XGINew_SetReg3( pVBInfo->P3c0 , 0x14 ) ;            /* set index */
908     XGINew_SetReg3( pVBInfo->P3c0 , 0x00 ) ;            /* set data */
909     XGINew_GetReg2( pVBInfo->P3da ) ;                   /* Enable Attribute */
910     XGINew_SetReg3( pVBInfo->P3c0 , 0x20 ) ;
911 }
912
913
914 /* --------------------------------------------------------------------- */
915 /* Function : XGI_SetGRCRegs */
916 /* Input : */
917 /* Output : */
918 /* Description : */
919 /* --------------------------------------------------------------------- */
920 void XGI_SetGRCRegs( USHORT StandTableIndex, PVB_DEVICE_INFO pVBInfo )
921 {
922     UCHAR GRdata ;
923     USHORT i ;
924
925     for( i = 0 ; i <= 0x08 ; i++ )
926     {
927         GRdata = pVBInfo->StandTable[ StandTableIndex ].GRC[ i ] ;      /* Get GR from file */
928         XGINew_SetReg1( pVBInfo->P3ce , i , GRdata ) ;                  /* Set GR(3ce) */
929     }
930
931     if ( pVBInfo->ModeType > ModeVGA )
932     {
933         GRdata = ( UCHAR )XGINew_GetReg1( pVBInfo->P3ce , 0x05 ) ;
934         GRdata &= 0xBF ;                                                /* 256 color disable */
935         XGINew_SetReg1( pVBInfo->P3ce , 0x05 , GRdata ) ;
936     }
937 }
938
939
940 /* --------------------------------------------------------------------- */
941 /* Function : XGI_ClearExt1Regs */
942 /* Input : */
943 /* Output : */
944 /* Description : */
945 /* --------------------------------------------------------------------- */
946 void XGI_ClearExt1Regs(PVB_DEVICE_INFO pVBInfo)
947 {
948     USHORT i ;
949
950     for( i = 0x0A ; i <= 0x0E ; i++ )
951         XGINew_SetReg1( pVBInfo->P3c4 , i , 0x00 ) ;    /* Clear SR0A-SR0E */
952 }
953
954
955 /* --------------------------------------------------------------------- */
956 /* Function : XGI_SetDefaultVCLK */
957 /* Input : */
958 /* Output : */
959 /* Description : */
960 /* --------------------------------------------------------------------- */
961 UCHAR XGI_SetDefaultVCLK( PVB_DEVICE_INFO pVBInfo )
962 {
963
964     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x31 , ~0x30 , 0x20 ) ;
965     XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , pVBInfo->VCLKData[ 0 ].SR2B ) ;
966     XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , pVBInfo->VCLKData[ 0 ].SR2C ) ;
967
968     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x31 , ~0x30 , 0x10 ) ;
969     XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , pVBInfo->VCLKData[ 1 ].SR2B ) ;
970     XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , pVBInfo->VCLKData[ 1 ].SR2C ) ;
971
972     XGINew_SetRegAND( pVBInfo->P3c4 , 0x31 , ~0x30 ) ;
973     return( 0 ) ;
974 }
975
976
977 /* --------------------------------------------------------------------- */
978 /* Function : XGI_GetRatePtrCRT2 */
979 /* Input : */
980 /* Output : */
981 /* Description : */
982 /* --------------------------------------------------------------------- */
983 USHORT XGI_GetRatePtrCRT2( PXGI_HW_DEVICE_INFO pXGIHWDE, USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
984 {
985     SHORT  LCDRefreshIndex[] = { 0x00 , 0x00 , 0x03 , 0x01 } ,
986            LCDARefreshIndex[] = { 0x00 , 0x00 , 0x03 , 0x01 , 0x01 , 0x01 , 0x01 } ;
987
988     USHORT RefreshRateTableIndex , i ,
989          modeflag , index , temp ;
990
991     if ( ModeNo <= 0x13 )
992     {
993         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
994     }
995     else
996     {
997         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
998     }
999
1000     if ( pVBInfo->IF_DEF_CH7005 == 1 )
1001     {
1002         if ( pVBInfo->VBInfo & SetCRT2ToTV )
1003         {
1004             if ( modeflag & HalfDCLK )
1005                 return( 0 ) ;
1006         }
1007     }
1008
1009     if ( ModeNo < 0x14 )
1010         return( 0xFFFF ) ;
1011
1012     index = XGINew_GetReg1( pVBInfo->P3d4 , 0x33 ) ;
1013     index = index >> pVBInfo->SelectCRT2Rate ;
1014     index &= 0x0F ;
1015
1016     if ( pVBInfo->LCDInfo & LCDNonExpanding )
1017         index = 0 ;
1018
1019     if ( index > 0 )
1020         index-- ;
1021
1022     if ( pVBInfo->SetFlag & ProgrammingCRT2 )
1023     {
1024         if ( pVBInfo->IF_DEF_CH7005 == 1 )
1025         {
1026             if ( pVBInfo->VBInfo & SetCRT2ToTV )
1027             {
1028                 index = 0 ;
1029             }
1030         }
1031
1032         if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
1033         {
1034             if( pVBInfo->IF_DEF_LVDS == 0 )
1035             {
1036                 if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
1037                     temp = LCDARefreshIndex[ pVBInfo->LCDResInfo & 0x0F ] ;     /* 301b */
1038                 else
1039                     temp = LCDRefreshIndex[ pVBInfo->LCDResInfo & 0x0F ] ;
1040
1041                 if ( index > temp )
1042                 {
1043                     index = temp ;
1044                 }
1045             }
1046             else
1047             {
1048                 index = 0 ;
1049             }
1050         }
1051     }
1052
1053     RefreshRateTableIndex = pVBInfo->EModeIDTable[ ModeIdIndex ].REFindex ;
1054     ModeNo = pVBInfo->RefIndex[ RefreshRateTableIndex ].ModeID ;
1055     if ( pXGIHWDE->jChipType >= XG20 )  /* for XG20, XG21, XG27 */
1056     {
1057       /*
1058       if ( pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_InfoFlag & XG2xNotSupport )
1059       {
1060         index++;
1061       }
1062       */
1063       if ( ( pVBInfo->RefIndex[ RefreshRateTableIndex ].XRes == 800 ) &&
1064            ( pVBInfo->RefIndex[ RefreshRateTableIndex ].YRes == 600 ) )
1065       {
1066         index++;
1067       }
1068 /* Alan 10/19/2007; do the similiar adjustment like XGISearchCRT1Rate() */
1069       if ( ( pVBInfo->RefIndex[ RefreshRateTableIndex ].XRes == 1024 ) &&
1070            ( pVBInfo->RefIndex[ RefreshRateTableIndex ].YRes == 768 ) )
1071       {
1072         index++;
1073       }
1074       if ( ( pVBInfo->RefIndex[ RefreshRateTableIndex ].XRes == 1280 ) &&
1075            ( pVBInfo->RefIndex[ RefreshRateTableIndex ].YRes == 1024 ) )
1076       {
1077         index++;
1078       }
1079     }
1080
1081     i = 0 ;
1082     do
1083     {
1084         if ( pVBInfo->RefIndex[ RefreshRateTableIndex + i ].ModeID != ModeNo )
1085             break ;
1086         temp = pVBInfo->RefIndex[ RefreshRateTableIndex + i ].Ext_InfoFlag ;
1087         temp &= ModeInfoFlag ;
1088         if ( temp < pVBInfo->ModeType )
1089             break ;
1090         i++ ;
1091         index-- ;
1092
1093     } while( index != 0xFFFF ) ;
1094     if ( !( pVBInfo->VBInfo & SetCRT2ToRAMDAC ) )
1095     {
1096         if ( pVBInfo->VBInfo & SetInSlaveMode )
1097         {
1098             temp = pVBInfo->RefIndex[ RefreshRateTableIndex + i - 1 ].Ext_InfoFlag ;
1099             if ( temp & InterlaceMode )
1100             {
1101                 i++ ;
1102             }
1103         }
1104     }
1105     i-- ;
1106     if ( ( pVBInfo->SetFlag & ProgrammingCRT2 ) )
1107     {
1108         temp = XGI_AjustCRT2Rate( ModeNo , ModeIdIndex , RefreshRateTableIndex , &i, pVBInfo) ;
1109     }
1110     return( RefreshRateTableIndex + i ) ;                /*return(0x01|(temp1<<1));   */
1111 }
1112
1113
1114 /* --------------------------------------------------------------------- */
1115 /* Function : XGI_AjustCRT2Rate */
1116 /* Input : */
1117 /* Output : */
1118 /* Description : */
1119 /* --------------------------------------------------------------------- */
1120 BOOLEAN XGI_AjustCRT2Rate( USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex , USHORT *i, PVB_DEVICE_INFO pVBInfo )
1121 {
1122     USHORT tempax ,
1123            tempbx ,
1124            resinfo ,
1125            modeflag ,
1126            infoflag ;
1127
1128     if ( ModeNo <= 0x13 )
1129     {
1130         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;   /* si+St_ModeFlag */
1131     }
1132     else
1133     {
1134         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
1135     }
1136
1137     resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;
1138     tempbx = pVBInfo->RefIndex[ RefreshRateTableIndex + ( *i ) ].ModeID ;
1139     tempax = 0 ;
1140
1141     if ( pVBInfo->IF_DEF_LVDS == 0 )
1142     {
1143         if ( pVBInfo->VBInfo & SetCRT2ToRAMDAC )
1144         {
1145             tempax |= SupportRAMDAC2 ;
1146
1147             if ( pVBInfo->VBType & VB_XGI301C )
1148                 tempax |= SupportCRT2in301C ;
1149         }
1150
1151         if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )       /* 301b */
1152         {
1153             tempax |= SupportLCD ;
1154
1155             if ( pVBInfo->LCDResInfo != Panel1280x1024 )
1156             {
1157                 if ( pVBInfo->LCDResInfo != Panel1280x960 )
1158                 {
1159                     if ( pVBInfo->LCDInfo & LCDNonExpanding )
1160                     {
1161                         if ( resinfo >= 9 )
1162                         {
1163                             tempax = 0 ;
1164                             return( 0 ) ;
1165                         }
1166                     }
1167                 }
1168             }
1169         }
1170
1171         if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )    /* for HiTV */
1172         {
1173             if ( ( pVBInfo->VBType & VB_XGI301LV ) && ( pVBInfo->VBExtInfo == VB_YPbPr1080i ) )
1174             {
1175                 tempax |= SupportYPbPr ;
1176                 if ( pVBInfo->VBInfo & SetInSlaveMode )
1177                 {
1178                     if ( resinfo == 4 )
1179                         return( 0 ) ;
1180
1181                     if ( resinfo == 3 )
1182                         return( 0 ) ;
1183
1184                     if ( resinfo > 7 )
1185                         return( 0 ) ;
1186                 }
1187             }
1188             else
1189             {
1190                 tempax |= SupportHiVisionTV ;
1191                 if ( pVBInfo->VBInfo & SetInSlaveMode )
1192                 {
1193                     if ( resinfo == 4 )
1194                         return( 0 ) ;
1195
1196                     if ( resinfo == 3 )
1197                     {
1198                         if ( pVBInfo->SetFlag & TVSimuMode )
1199                             return( 0 ) ;
1200                     }
1201
1202                     if ( resinfo > 7 )
1203                         return( 0 ) ;
1204                 }
1205             }
1206         }
1207         else
1208         {
1209             if ( pVBInfo->VBInfo & ( SetCRT2ToAVIDEO | SetCRT2ToSVIDEO | SetCRT2ToSCART | SetCRT2ToYPbPr | SetCRT2ToHiVisionTV ) )
1210             {
1211                 tempax |= SupportTV ;
1212
1213                 if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
1214                 {
1215                     tempax |= SupportTV1024 ;
1216                 }
1217
1218                 if ( !( pVBInfo->VBInfo & SetPALTV ) )
1219                 {
1220                     if ( modeflag & NoSupportSimuTV )
1221                     {
1222                         if ( pVBInfo->VBInfo & SetInSlaveMode )
1223                         {
1224                             if ( !( pVBInfo->VBInfo & SetNotSimuMode ) )
1225                             {
1226                                return( 0 ) ;
1227                             }
1228                         }
1229                     }
1230                 }
1231             }
1232         }
1233     }
1234     else                /* for LVDS */
1235     {
1236         if ( pVBInfo->IF_DEF_CH7005 == 1 )
1237         {
1238             if ( pVBInfo->VBInfo & SetCRT2ToTV )
1239             {
1240                 tempax |= SupportCHTV ;
1241             }
1242         }
1243
1244         if ( pVBInfo->VBInfo & SetCRT2ToLCD )
1245         {
1246             tempax |= SupportLCD ;
1247
1248             if ( resinfo > 0x08 )
1249                 return( 0 ) ;           /* 1024x768 */
1250
1251             if ( pVBInfo->LCDResInfo < Panel1024x768 )
1252             {
1253                 if ( resinfo > 0x07 )
1254                     return( 0 ) ;       /* 800x600 */
1255
1256                 if ( resinfo == 0x04 )
1257                     return( 0 ) ;       /* 512x384 */
1258             }
1259         }
1260     }
1261
1262     for( ; pVBInfo->RefIndex[ RefreshRateTableIndex + ( *i ) ].ModeID == tempbx ; ( *i )-- )
1263     {
1264         infoflag = pVBInfo->RefIndex[ RefreshRateTableIndex + ( *i ) ].Ext_InfoFlag ;
1265         if ( infoflag & tempax )
1266         {
1267             return( 1 ) ;
1268         }
1269         if ( ( *i ) == 0 )
1270             break ;
1271     }
1272
1273     for( ( *i ) = 0 ; ; ( *i )++ )
1274     {
1275         infoflag = pVBInfo->RefIndex[ RefreshRateTableIndex + ( *i ) ].Ext_InfoFlag ;
1276         if ( pVBInfo->RefIndex[ RefreshRateTableIndex + ( *i ) ].ModeID != tempbx )
1277         {
1278             return( 0 ) ;
1279         }
1280
1281         if ( infoflag & tempax )
1282         {
1283             return( 1 ) ;
1284         }
1285     }
1286     return( 1 ) ;
1287 }
1288
1289
1290 /* --------------------------------------------------------------------- */
1291 /* Function : XGI_SetSync */
1292 /* Input : */
1293 /* Output : */
1294 /* Description : */
1295 /* --------------------------------------------------------------------- */
1296 void XGI_SetSync(USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
1297 {
1298     USHORT sync ,
1299            temp ;
1300
1301     sync = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_InfoFlag >> 8 ;       /* di+0x00 */
1302     sync &= 0xC0 ;
1303     temp = 0x2F ;
1304     temp |= sync ;
1305     XGINew_SetReg3( pVBInfo->P3c2 , temp ) ;                            /* Set Misc(3c2) */
1306 }
1307
1308
1309 /* --------------------------------------------------------------------- */
1310 /* Function : XGI_SetCRT1CRTC */
1311 /* Input : */
1312 /* Output : */
1313 /* Description : */
1314 /* --------------------------------------------------------------------- */
1315 void XGI_SetCRT1CRTC( USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex,PVB_DEVICE_INFO pVBInfo, PXGI_HW_DEVICE_INFO HwDeviceExtension )
1316 {
1317     UCHAR  index ,
1318            data ;
1319
1320     USHORT i ;
1321
1322     index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC ;   /* Get index */
1323     index = index&IndexMask ;
1324
1325     data =( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x11 ) ;
1326     data &= 0x7F ;
1327     XGINew_SetReg1(pVBInfo->P3d4,0x11,data);                            /* Unlock CRTC */
1328
1329     for( i = 0 ; i < 8 ; i++ )
1330         pVBInfo->TimingH[ 0 ].data[ i ] = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ i ] ;
1331
1332     for( i = 0 ; i < 7 ; i++ )
1333         pVBInfo->TimingV[ 0 ].data[ i ] = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ i + 8 ] ;
1334
1335     XGI_SetCRT1Timing_H( pVBInfo, HwDeviceExtension ) ;
1336
1337
1338
1339     XGI_SetCRT1Timing_V( ModeIdIndex , ModeNo, pVBInfo ) ;
1340
1341
1342     if( pVBInfo->ModeType > 0x03 )
1343         XGINew_SetReg1( pVBInfo->P3d4 , 0x14 , 0x4F ) ;
1344 }
1345
1346
1347 /* --------------------------------------------------------------------- */
1348 /* Function : XGI_SetCRT1Timing_H */
1349 /* Input : */
1350 /* Output : */
1351 /* Description : */
1352 /* --------------------------------------------------------------------- */
1353 void XGI_SetCRT1Timing_H( PVB_DEVICE_INFO pVBInfo, PXGI_HW_DEVICE_INFO HwDeviceExtension )
1354 {
1355     UCHAR data , data1, pushax;
1356     USHORT i , j ;
1357
1358     /* XGINew_SetReg1( pVBInfo->P3d4 , 0x51 , 0 ) ; */
1359     /* XGINew_SetReg1( pVBInfo->P3d4 , 0x56 , 0 ) ; */
1360     /* XGINew_SetRegANDOR( pVBInfo->P3d4 ,0x11 , 0x7f , 0x00 ) ; */
1361
1362     data = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x11 ) ;            /* unlock cr0-7 */
1363     data &= 0x7F ;
1364     XGINew_SetReg1( pVBInfo->P3d4 , 0x11 , data ) ;
1365
1366     data = pVBInfo->TimingH[ 0 ].data[ 0 ] ;
1367     XGINew_SetReg1( pVBInfo->P3d4 , 0 , data ) ;
1368
1369     for( i = 0x01 ; i <= 0x04 ; i++ )
1370     {
1371         data = pVBInfo->TimingH[ 0 ].data[ i ] ;
1372         XGINew_SetReg1( pVBInfo->P3d4 , ( USHORT )( i + 1 ) , data ) ;
1373     }
1374
1375     for( i = 0x05 ; i <= 0x06 ; i++ )
1376     {
1377         data = pVBInfo->TimingH[ 0 ].data[ i ];
1378         XGINew_SetReg1( pVBInfo->P3c4 ,( USHORT )( i + 6 ) , data ) ;
1379     }
1380
1381     j = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x0e ) ;
1382     j &= 0x1F ;
1383     data = pVBInfo->TimingH[ 0 ].data[ 7 ] ;
1384     data &= 0xE0 ;
1385     data |= j ;
1386     XGINew_SetReg1( pVBInfo->P3c4 , 0x0e , data ) ;
1387
1388     if ( HwDeviceExtension->jChipType >= XG20 )
1389     {
1390         data = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x04 ) ;
1391         data = data - 1 ;
1392         XGINew_SetReg1( pVBInfo->P3d4 , 0x04 , data ) ;
1393         data = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x05 ) ;
1394         data1 = data ;
1395         data1 &= 0xE0 ;
1396         data &= 0x1F ;
1397         if ( data == 0 )
1398         {
1399             pushax = data ;
1400             data = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x0c ) ;
1401             data &= 0xFB ;
1402             XGINew_SetReg1( pVBInfo->P3c4 , 0x0c , data ) ;
1403             data = pushax ;
1404         }
1405         data = data - 1 ;
1406         data |= data1 ;
1407         XGINew_SetReg1( pVBInfo->P3d4 , 0x05 , data ) ;
1408         data = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x0e ) ;
1409         data = data >> 5 ;
1410         data = data + 3 ;
1411         if ( data > 7 )
1412             data = data - 7 ;
1413         data = data << 5 ;
1414         XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0e , ~0xE0 , data ) ;
1415     }
1416 }
1417
1418
1419 /* --------------------------------------------------------------------- */
1420 /* Function : XGI_SetCRT1Timing_V */
1421 /* Input : */
1422 /* Output : */
1423 /* Description : */
1424 /* --------------------------------------------------------------------- */
1425 void XGI_SetCRT1Timing_V( USHORT ModeIdIndex , USHORT ModeNo,PVB_DEVICE_INFO pVBInfo )
1426 {
1427     UCHAR data ;
1428     USHORT i , j ;
1429
1430     /* XGINew_SetReg1( pVBInfo->P3d4 , 0x51 , 0 ) ; */
1431     /* XGINew_SetReg1( pVBInfo->P3d4 , 0x56 , 0 ) ; */
1432     /* XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x11 , 0x7f , 0x00 ) ; */
1433
1434     for( i = 0x00 ; i <= 0x01 ; i++ )
1435     {
1436         data = pVBInfo->TimingV[ 0 ].data[ i ] ;
1437         XGINew_SetReg1( pVBInfo->P3d4 , ( USHORT )( i + 6 ) , data ) ;
1438     }
1439
1440     for( i = 0x02 ; i <= 0x03 ; i++ )
1441     {
1442         data = pVBInfo->TimingV[ 0 ].data[ i ] ;
1443         XGINew_SetReg1( pVBInfo->P3d4 , ( USHORT )( i + 0x0e ) , data ) ;
1444     }
1445
1446     for( i = 0x04 ; i <= 0x05 ; i++ )
1447     {
1448         data = pVBInfo->TimingV[ 0 ].data[ i ] ;
1449         XGINew_SetReg1( pVBInfo->P3d4 , ( USHORT )( i + 0x11 ) , data ) ;
1450     }
1451
1452     j = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x0a ) ;
1453     j &= 0xC0 ;
1454     data = pVBInfo->TimingV[ 0 ].data[ 6 ] ;
1455     data &= 0x3F ;
1456     data |= j ;
1457     XGINew_SetReg1( pVBInfo->P3c4 , 0x0a , data ) ;
1458
1459     data = pVBInfo->TimingV[ 0 ].data[ 6 ] ;
1460     data &= 0x80 ;
1461     data = data >> 2 ;
1462
1463     if ( ModeNo <= 0x13 )
1464         i = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
1465     else
1466         i = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
1467
1468     i &= DoubleScanMode ;
1469     if ( i )
1470         data |= 0x80 ;
1471
1472     j = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x09 ) ;
1473     j &= 0x5F ;
1474     data |= j ;
1475     XGINew_SetReg1( pVBInfo->P3d4 , 0x09 , data ) ;
1476 }
1477
1478
1479 /* --------------------------------------------------------------------- */
1480 /* Function : XGI_SetXG21CRTC */
1481 /* Input : Stand or enhance CRTC table */
1482 /* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
1483 /* Description : Set LCD timing */
1484 /* --------------------------------------------------------------------- */
1485 void XGI_SetXG21CRTC(USHORT ModeNo, USHORT ModeIdIndex, USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo)
1486 {
1487   UCHAR StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx ;
1488   USHORT Temp1, Temp2, Temp3 ;
1489
1490   if ( ModeNo <= 0x13 )
1491   {
1492     StandTableIndex = XGI_GetModePtr( ModeNo , ModeIdIndex, pVBInfo ) ;
1493     Tempax = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 4 ] ;         /* CR04 HRS */
1494     XGINew_SetReg1( pVBInfo->P3c4 , 0x2E , Tempax ) ;                   /* SR2E [7:0]->HRS */
1495     Tempbx = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 5 ] ;         /* Tempbx: CR05 HRE */
1496     Tempbx &= 0x1F ;                                                    /* Tempbx: HRE[4:0] */
1497     Tempcx = Tempax ;
1498     Tempcx &=  0xE0 ;                                                   /* Tempcx: HRS[7:5] */
1499     Tempdx = Tempcx | Tempbx ;                                          /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
1500     if ( Tempbx < ( Tempax & 0x1F ) )                                   /* IF HRE < HRS */
1501       Tempdx |= 0x20 ;                                                  /* Tempdx: HRE = HRE + 0x20 */
1502     Tempdx <<= 2 ;                                                      /* Tempdx << 2 */
1503     XGINew_SetReg1( pVBInfo->P3c4 , 0x2F , Tempdx ) ;                   /* SR2F [7:2]->HRE */
1504     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x30 , 0xE3 , 00 ) ;
1505
1506     Tempax = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 16 ] ;        /* Tempax: CR16 VRS */
1507     Tempbx = Tempax ;                                                   /* Tempbx=Tempax */
1508     Tempax &= 0x01 ;                                                    /* Tempax: VRS[0] */
1509     XGINew_SetRegOR( pVBInfo->P3c4 , 0x33 , Tempax ) ;                  /* SR33[0]->VRS */
1510     Tempax = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 7 ] ;         /* Tempax: CR7 VRS */
1511     Tempdx = Tempbx >> 1 ;                                              /* Tempdx: VRS[7:1] */
1512     Tempcx = Tempax & 0x04 ;                                            /* Tempcx: CR7[2] */
1513     Tempcx <<= 5 ;                                                      /* Tempcx[7]: VRS[8] */
1514     Tempdx |= Tempcx ;                                                  /* Tempdx: VRS[8:1] */
1515     XGINew_SetReg1( pVBInfo->P3c4 , 0x34 , Tempdx ) ;                   /* SR34[7:0]: VRS[8:1] */
1516
1517     Temp1 = Tempcx << 1 ;                                               /* Temp1[8]: VRS[8] UCHAR -> USHORT */
1518     Temp1 |= Tempbx ;                                                   /* Temp1[8:0]: VRS[8:0] */
1519     Tempax &= 0x80 ;                                                    /* Tempax[7]: CR7[7] */
1520     Temp2 = Tempax << 2 ;                                               /* Temp2[9]: VRS[9] */
1521     Temp1 |= Temp2 ;                                                    /* Temp1[9:0]: VRS[9:0] */
1522
1523     Tempax = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 17 ] ;        /* CR16 VRE */
1524     Tempax &= 0x0F ;                                                    /* Tempax[3:0]: VRE[3:0] */
1525     Temp2 = Temp1 & 0x3F0 ;                                             /* Temp2[9:4]: VRS[9:4] */
1526     Temp2 |= Tempax ;                                                   /* Temp2[9:0]: VRE[9:0] */
1527     Temp3 = Temp1 & 0x0F ;                                              /* Temp3[3:0]: VRS[3:0] */
1528     if ( Tempax < Temp3 )                                               /* VRE[3:0]<VRS[3:0] */
1529       Temp2 |= 0x10 ;                                                   /* Temp2: VRE + 0x10 */
1530     Temp2 &= 0xFF ;                                                     /* Temp2[7:0]: VRE[7:0] */
1531     Tempax = (UCHAR)Temp2 ;                                             /* Tempax[7:0]: VRE[7:0] */
1532     Tempax <<= 2 ;                                                      /* Tempax << 2: VRE[5:0] */
1533     Temp1 &= 0x600 ;                                                    /* Temp1[10:9]: VRS[10:9] */
1534     Temp1 >>= 9 ;                                                       /* [10:9]->[1:0] */
1535     Tempbx = (UCHAR)Temp1 ;                                             /* Tempbx[1:0]: VRS[10:9] */
1536     Tempax |= Tempbx ;                                                  /* VRE[5:0]VRS[10:9] */
1537     Tempax &= 0x7F ;
1538     XGINew_SetReg1( pVBInfo->P3c4 , 0x3F , Tempax ) ;                   /* SR3F D[7:2]->VRE D[1:0]->VRS */
1539   }
1540   else
1541   {
1542     index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC ;
1543     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 3 ] ;             /* Tempax: CR4 HRS */
1544     Tempcx = Tempax ;                                                   /* Tempcx: HRS */
1545     XGINew_SetReg1( pVBInfo->P3c4 , 0x2E , Tempax ) ;                   /* SR2E[7:0]->HRS */
1546
1547     Tempdx = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 5 ] ;             /* SRB */
1548     Tempdx &= 0xC0 ;                                                    /* Tempdx[7:6]: SRB[7:6] */
1549     Temp1 = Tempdx ;                                                    /* Temp1[7:6]: HRS[9:8] */
1550     Temp1 <<= 2 ;                                                       /* Temp1[9:8]: HRS[9:8] */
1551     Temp1 |= Tempax ;                                                   /* Temp1[9:0]: HRS[9:0] */
1552
1553     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 4 ] ;             /* CR5 HRE */
1554     Tempax &= 0x1F ;                                                    /* Tempax[4:0]: HRE[4:0] */
1555
1556     Tempbx = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 6 ] ;             /* SRC */
1557     Tempbx &= 0x04 ;                                                    /* Tempbx[2]: HRE[5] */
1558     Tempbx <<= 3 ;                                                      /* Tempbx[5]: HRE[5] */
1559     Tempax |= Tempbx ;                                                  /* Tempax[5:0]: HRE[5:0] */
1560
1561     Temp2 = Temp1 & 0x3C0 ;                                             /* Temp2[9:6]: HRS[9:6] */
1562     Temp2 |= Tempax ;                                                   /* Temp2[9:0]: HRE[9:0] */
1563
1564     Tempcx &= 0x3F ;                                                    /* Tempcx[5:0]: HRS[5:0] */
1565     if( Tempax < Tempcx )                                               /* HRE < HRS */
1566       Temp2 |= 0x40 ;                                                   /* Temp2 + 0x40 */
1567
1568     Temp2 &= 0xFF ;
1569     Tempax = (UCHAR)Temp2 ;                                             /* Tempax: HRE[7:0] */
1570     Tempax <<= 2 ;                                                      /* Tempax[7:2]: HRE[5:0] */
1571     Tempdx >>= 6 ;                                                      /* Tempdx[7:6]->[1:0] HRS[9:8] */
1572     Tempax |= Tempdx ;                                                  /* HRE[5:0]HRS[9:8] */
1573     XGINew_SetReg1( pVBInfo->P3c4 , 0x2F , Tempax ) ;                   /* SR2F D[7:2]->HRE, D[1:0]->HRS */
1574     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x30 , 0xE3 , 00 ) ;
1575
1576     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 10 ] ;            /* CR10 VRS */
1577     Tempbx = Tempax ;                                                   /* Tempbx: VRS */
1578     Tempax &= 0x01 ;                                                    /* Tempax[0]: VRS[0] */
1579     XGINew_SetRegOR( pVBInfo->P3c4 , 0x33 , Tempax ) ;                  /* SR33[0]->VRS[0] */
1580     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 9 ] ;             /* CR7[2][7] VRE */
1581     Tempcx = Tempbx >> 1 ;                                              /* Tempcx[6:0]: VRS[7:1] */
1582     Tempdx = Tempax & 0x04 ;                                            /* Tempdx[2]: CR7[2] */
1583     Tempdx <<= 5 ;                                                      /* Tempdx[7]: VRS[8] */
1584     Tempcx |= Tempdx ;                                                  /* Tempcx[7:0]: VRS[8:1] */
1585     XGINew_SetReg1( pVBInfo->P3c4 , 0x34 , Tempcx ) ;                   /* SR34[8:1]->VRS */
1586
1587     Temp1 = Tempdx ;                                                    /* Temp1[7]: Tempdx[7] */
1588     Temp1 <<= 1 ;                                                       /* Temp1[8]: VRS[8] */
1589     Temp1 |= Tempbx ;                                                   /* Temp1[8:0]: VRS[8:0] */
1590     Tempax &= 0x80 ;
1591     Temp2 = Tempax << 2 ;                                               /* Temp2[9]: VRS[9] */
1592     Temp1 |= Temp2 ;                                                    /* Temp1[9:0]: VRS[9:0] */
1593     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 14 ] ;            /* Tempax: SRA */
1594     Tempax &= 0x08 ;                                                    /* Tempax[3]: VRS[3] */
1595     Temp2 = Tempax ;
1596     Temp2 <<= 7 ;                                                       /* Temp2[10]: VRS[10] */
1597     Temp1 |= Temp2 ;                                                    /* Temp1[10:0]: VRS[10:0] */
1598
1599     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 11 ] ;            /* Tempax: CR11 VRE */
1600     Tempax &= 0x0F ;                                                    /* Tempax[3:0]: VRE[3:0] */
1601     Tempbx = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 14 ] ;            /* Tempbx: SRA */
1602     Tempbx &= 0x20 ;                                                    /* Tempbx[5]: VRE[5] */
1603     Tempbx >>= 1 ;                                                      /* Tempbx[4]: VRE[4] */
1604     Tempax |= Tempbx ;                                                  /* Tempax[4:0]: VRE[4:0] */
1605     Temp2 = Temp1 & 0x7E0 ;                                             /* Temp2[10:5]: VRS[10:5] */
1606     Temp2 |= Tempax ;                                                   /* Temp2[10:5]: VRE[10:5] */
1607
1608     Temp3 = Temp1 & 0x1F ;                                              /* Temp3[4:0]: VRS[4:0] */
1609     if ( Tempax < Temp3 )                                               /* VRE < VRS */
1610       Temp2 |= 0x20 ;                                                   /* VRE + 0x20 */
1611
1612     Temp2 &= 0xFF ;
1613     Tempax = (UCHAR)Temp2 ;                                             /* Tempax: VRE[7:0] */
1614     Tempax <<= 2 ;                                                      /* Tempax[7:0]; VRE[5:0]00 */
1615     Temp1 &= 0x600 ;                                                    /* Temp1[10:9]: VRS[10:9] */
1616     Temp1 >>= 9 ;                                                       /* Temp1[1:0]: VRS[10:9] */
1617     Tempbx = (UCHAR)Temp1 ;
1618     Tempax |= Tempbx ;                                                  /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
1619     Tempax &= 0x7F ;
1620     XGINew_SetReg1( pVBInfo->P3c4 , 0x3F , Tempax ) ;                   /* SR3F D[7:2]->VRE D[1:0]->VRS */
1621   }
1622 }
1623
1624 void XGI_SetXG27CRTC(USHORT ModeNo, USHORT ModeIdIndex, USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo)
1625 {
1626   USHORT StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx ;
1627
1628   if ( ModeNo <= 0x13 )
1629   {
1630     StandTableIndex = XGI_GetModePtr( ModeNo , ModeIdIndex, pVBInfo ) ;
1631     Tempax = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 4 ] ;         /* CR04 HRS */
1632     XGINew_SetReg1( pVBInfo->P3c4 , 0x2E , Tempax ) ;                   /* SR2E [7:0]->HRS */
1633     Tempbx = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 5 ] ;         /* Tempbx: CR05 HRE */
1634     Tempbx &= 0x1F ;                                                    /* Tempbx: HRE[4:0] */
1635     Tempcx = Tempax ;
1636     Tempcx &=  0xE0 ;                                                   /* Tempcx: HRS[7:5] */
1637     Tempdx = Tempcx | Tempbx ;                                          /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
1638     if ( Tempbx < ( Tempax & 0x1F ) )                                   /* IF HRE < HRS */
1639       Tempdx |= 0x20 ;                                                  /* Tempdx: HRE = HRE + 0x20 */
1640     Tempdx <<= 2 ;                                                      /* Tempdx << 2 */
1641     XGINew_SetReg1( pVBInfo->P3c4 , 0x2F , Tempdx ) ;                   /* SR2F [7:2]->HRE */
1642     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x30 , 0xE3 , 00 ) ;
1643
1644     Tempax = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 16 ] ;        /* Tempax: CR10 VRS */
1645     XGINew_SetReg1( pVBInfo->P3c4 , 0x34 , Tempax ) ;                   /* SR34[7:0]->VRS */
1646     Tempcx = Tempax ;                                                   /* Tempcx=Tempax=VRS[7:0] */
1647     Tempax = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 7 ] ;         /* Tempax[7][2]: CR7[7][2] VRS[9][8] */
1648     Tempbx = Tempax ;                                                   /* Tempbx=CR07 */
1649     Tempax &= 0x04 ;                                                    /* Tempax[2]: CR07[2] VRS[8] */
1650     Tempax >>= 2;
1651     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x35 , ~0x01, Tempax ) ;        /* SR35 D[0]->VRS D[8] */
1652     Tempcx |= (Tempax << 8) ;                                           /* Tempcx[8] |= VRS[8] */
1653     Tempcx |= (Tempbx & 0x80)<<2;                                       /* Tempcx[9] |= VRS[9] */
1654
1655
1656     Tempax = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 17 ] ;        /* CR11 VRE */
1657     Tempax &= 0x0F ;                                                    /* Tempax: VRE[3:0] */
1658     Tempbx = Tempcx ;                                                   /* Tempbx=Tempcx=VRS[9:0] */
1659     Tempbx &= 0x3F0 ;                                                   /* Tempbx[9:4]: VRS[9:4] */
1660     Tempbx |= Tempax ;                                                  /* Tempbx[9:0]: VRE[9:0] */
1661     if ( Tempax <= (Tempcx & 0x0F) )                                    /* VRE[3:0]<=VRS[3:0] */
1662       Tempbx |= 0x10 ;                                                  /* Tempbx: VRE + 0x10 */
1663     Tempax = (UCHAR)Tempbx & 0xFF;                                      /* Tempax[7:0]: VRE[7:0] */
1664     Tempax <<= 2 ;                                                      /* Tempax << 2: VRE[5:0] */
1665     Tempcx = (Tempcx&0x600)>>8;                                         /* Tempcx VRS[10:9] */
1666     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x3F , ~0xFC, Tempax ) ;        /* SR3F D[7:2]->VRE D[5:0] */
1667     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x35 , ~0x06, Tempcx ) ;        /* SR35 D[2:1]->VRS[10:9] */
1668   }
1669   else
1670   {
1671     index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC ;
1672     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 3 ] ;             /* Tempax: CR4 HRS */
1673     Tempbx = Tempax ;                                                   /* Tempbx: HRS[7:0] */
1674     XGINew_SetReg1( pVBInfo->P3c4 , 0x2E , Tempax ) ;                   /* SR2E[7:0]->HRS */
1675
1676     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 5 ] ;             /* SR0B */
1677     Tempax &= 0xC0 ;                                                    /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
1678     Tempbx |= (Tempax << 2);                                    /* Tempbx: HRS[9:0] */
1679
1680     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 4 ] ;             /* CR5 HRE */
1681     Tempax &= 0x1F ;                                                    /* Tempax[4:0]: HRE[4:0] */
1682     Tempcx = Tempax ;                                                   /* Tempcx: HRE[4:0] */
1683
1684     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 6 ] ;             /* SRC */
1685     Tempax &= 0x04 ;                                                    /* Tempax[2]: HRE[5] */
1686     Tempax <<= 3 ;                                                          /* Tempax[5]: HRE[5] */
1687     Tempcx |= Tempax ;                                                  /* Tempcx[5:0]: HRE[5:0] */
1688
1689     Tempbx = Tempbx & 0x3C0 ;                                   /* Tempbx[9:6]: HRS[9:6] */
1690     Tempbx |= Tempcx ;                                                  /* Tempbx: HRS[9:6]HRE[5:0] */
1691
1692     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 3 ] ;             /* Tempax: CR4 HRS */
1693     Tempax &= 0x3F ;                                                    /* Tempax: HRS[5:0] */
1694     if( Tempcx <= Tempax )                                              /* HRE[5:0] < HRS[5:0] */
1695       Tempbx += 0x40 ;                          /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
1696
1697     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 5 ] ;             /* SR0B */
1698     Tempax &= 0xC0 ;                                                    /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
1699     Tempax >>= 6;                               /* Tempax[1:0]: HRS[9:8]*/
1700     Tempax |= ((Tempbx << 2) & 0xFF);           /* Tempax[7:2]: HRE[5:0] */
1701     XGINew_SetReg1( pVBInfo->P3c4 , 0x2F , Tempax ) ;                   /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
1702     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x30 , 0xE3 , 00 ) ;
1703
1704     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 10 ] ;            /* CR10 VRS */
1705     XGINew_SetReg1( pVBInfo->P3c4 , 0x34 , Tempax ) ;                   /* SR34[7:0]->VRS[7:0] */
1706
1707     Tempcx = Tempax ;                                                   /* Tempcx <= VRS[7:0] */
1708     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 9 ] ;             /* CR7[7][2] VRS[9][8] */
1709     Tempbx = Tempax ;                                                   /* Tempbx <= CR07[7:0] */
1710     Tempax = Tempax & 0x04 ;                                    /* Tempax[2]: CR7[2]: VRS[8] */
1711     Tempax >>= 2 ;                                                          /* Tempax[0]: VRS[8] */
1712     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x35 , ~0x01 , Tempax ) ;       /* SR35[0]: VRS[8] */
1713     Tempcx |= (Tempax<<8) ;                                             /* Tempcx <= VRS[8:0] */
1714     Tempcx |= ((Tempbx&0x80)<<2) ;                              /* Tempcx <= VRS[9:0] */
1715     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 14 ] ;            /* Tempax: SR0A */
1716     Tempax &= 0x08;                             /* SR0A[3] VRS[10] */
1717     Tempcx |= (Tempax<<7) ;                                     /* Tempcx <= VRS[10:0] */
1718
1719
1720     Tempax = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 11 ] ;            /* Tempax: CR11 VRE */
1721     Tempax &= 0x0F ;                                                    /* Tempax[3:0]: VRE[3:0] */
1722     Tempbx = pVBInfo->XGINEWUB_CRT1Table[ index ].CR[ 14 ] ;            /* Tempbx: SR0A */
1723     Tempbx &= 0x20 ;                                                    /* Tempbx[5]: SR0A[5]: VRE[4] */
1724     Tempbx >>= 1 ;                                                          /* Tempbx[4]: VRE[4] */
1725     Tempax |= Tempbx ;                                                  /* Tempax[4:0]: VRE[4:0] */
1726     Tempbx = Tempcx ;                                                   /* Tempbx: VRS[10:0] */
1727     Tempbx &= 0x7E0 ;                                               /* Tempbx[10:5]: VRS[10:5] */
1728     Tempbx |= Tempax ;                                                  /* Tempbx: VRS[10:5]VRE[4:0] */
1729
1730     if ( Tempbx <= Tempcx )                                             /* VRE <= VRS */
1731       Tempbx |= 0x20 ;                                                  /* VRE + 0x20 */
1732
1733     Tempax = (Tempbx<<2) & 0xFF ;                                       /* Tempax: Tempax[7:0]; VRE[5:0]00 */
1734     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x3F , ~0xFC , Tempax ) ;       /* SR3F[7:2]:VRE[5:0] */
1735     Tempax = Tempcx >> 8;
1736     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x35 , ~0x07 , Tempax ) ;       /* SR35[2:0]:VRS[10:8] */
1737   }
1738 }
1739
1740
1741 /* --------------------------------------------------------------------- */
1742 /* Function : XGI_SetXG21LCD */
1743 /* Input : */
1744 /* Output : FCLK duty cycle, FCLK delay compensation */
1745 /* Description : All values set zero */
1746 /* --------------------------------------------------------------------- */
1747 void XGI_SetXG21LCD(PVB_DEVICE_INFO pVBInfo,USHORT RefreshRateTableIndex,USHORT ModeNo)
1748 {
1749   USHORT Data , Temp , b3CC ;
1750   USHORT XGI_P3cc ;
1751
1752   XGI_P3cc = pVBInfo->P3cc ;
1753
1754   XGINew_SetReg1( pVBInfo->P3d4 , 0x2E , 0x00 ) ;
1755   XGINew_SetReg1( pVBInfo->P3d4 , 0x2F , 0x00 ) ;
1756   XGINew_SetReg1( pVBInfo->P3d4 , 0x46 , 0x00 ) ;
1757   XGINew_SetReg1( pVBInfo->P3d4 , 0x47 , 0x00 ) ;
1758   if ( ((*pVBInfo->pDVOSetting)&0xC0) == 0xC0 )
1759   {
1760     XGINew_SetReg1( pVBInfo->P3d4 , 0x2E , *pVBInfo->pCR2E ) ;
1761     XGINew_SetReg1( pVBInfo->P3d4 , 0x2F , *pVBInfo->pCR2F ) ;
1762     XGINew_SetReg1( pVBInfo->P3d4 , 0x46 , *pVBInfo->pCR46 ) ;
1763     XGINew_SetReg1( pVBInfo->P3d4 , 0x47 , *pVBInfo->pCR47 ) ;
1764   }
1765
1766   Temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x37 ) ;
1767
1768   if ( Temp & 0x01 )
1769   {
1770     XGINew_SetRegOR( pVBInfo->P3c4 , 0x06 , 0x40 ) ; /* 18 bits FP */
1771     XGINew_SetRegOR( pVBInfo->P3c4 , 0x09 , 0x40 ) ;
1772   }
1773
1774   XGINew_SetRegOR( pVBInfo->P3c4 , 0x1E , 0x01 ) ;   /* Negative blank polarity */
1775
1776   XGINew_SetRegAND( pVBInfo->P3c4 , 0x30 , ~0x20 ) ;
1777   XGINew_SetRegAND( pVBInfo->P3c4 , 0x35 , ~0x80 ) ;
1778
1779   if ( ModeNo <= 0x13 )
1780   {
1781     b3CC = (UCHAR) XGINew_GetReg2( XGI_P3cc ) ;
1782     if ( b3CC & 0x40 )
1783       XGINew_SetRegOR( pVBInfo->P3c4 , 0x30 , 0x20 ) ; /* Hsync polarity */
1784     if ( b3CC & 0x80 )
1785       XGINew_SetRegOR( pVBInfo->P3c4 , 0x35 , 0x80 ) ; /* Vsync polarity */
1786   }
1787   else
1788   {
1789     Data = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_InfoFlag ;
1790     if ( Data & 0x4000 )
1791       XGINew_SetRegOR( pVBInfo->P3c4 , 0x30 , 0x20 ) ; /* Hsync polarity */
1792     if ( Data & 0x8000 )
1793       XGINew_SetRegOR( pVBInfo->P3c4 , 0x35 , 0x80 ) ; /* Vsync polarity */
1794   }
1795 }
1796
1797 void XGI_SetXG27LCD(PVB_DEVICE_INFO pVBInfo,USHORT RefreshRateTableIndex,USHORT ModeNo)
1798 {
1799   USHORT Data , Temp , b3CC ;
1800   USHORT XGI_P3cc ;
1801
1802   XGI_P3cc = pVBInfo->P3cc ;
1803
1804   XGINew_SetReg1( pVBInfo->P3d4 , 0x2E , 0x00 ) ;
1805   XGINew_SetReg1( pVBInfo->P3d4 , 0x2F , 0x00 ) ;
1806   XGINew_SetReg1( pVBInfo->P3d4 , 0x46 , 0x00 ) ;
1807   XGINew_SetReg1( pVBInfo->P3d4 , 0x47 , 0x00 ) ;
1808
1809   Temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x37 ) ;
1810   if ( ( Temp & 0x03 ) == 0 )  /* dual 12 */
1811   {
1812     XGINew_SetReg1( pVBInfo->P3d4 , 0x46 , 0x13 ) ;
1813     XGINew_SetReg1( pVBInfo->P3d4 , 0x47 , 0x13 ) ;
1814   }
1815
1816   if ( ((*pVBInfo->pDVOSetting)&0xC0) == 0xC0 )
1817   {
1818     XGINew_SetReg1( pVBInfo->P3d4 , 0x2E , *pVBInfo->pCR2E ) ;
1819     XGINew_SetReg1( pVBInfo->P3d4 , 0x2F , *pVBInfo->pCR2F ) ;
1820     XGINew_SetReg1( pVBInfo->P3d4 , 0x46 , *pVBInfo->pCR46 ) ;
1821     XGINew_SetReg1( pVBInfo->P3d4 , 0x47 , *pVBInfo->pCR47 ) ;
1822   }
1823
1824   XGI_SetXG27FPBits(pVBInfo);
1825
1826   XGINew_SetRegOR( pVBInfo->P3c4 , 0x1E , 0x01 ) ;   /* Negative blank polarity */
1827
1828   XGINew_SetRegAND( pVBInfo->P3c4 , 0x30 , ~0x20 ) ; /* Hsync polarity */
1829   XGINew_SetRegAND( pVBInfo->P3c4 , 0x35 , ~0x80 ) ; /* Vsync polarity */
1830
1831   if ( ModeNo <= 0x13 )
1832   {
1833     b3CC = (UCHAR) XGINew_GetReg2( XGI_P3cc ) ;
1834     if ( b3CC & 0x40 )
1835       XGINew_SetRegOR( pVBInfo->P3c4 , 0x30 , 0x20 ) ; /* Hsync polarity */
1836     if ( b3CC & 0x80 )
1837       XGINew_SetRegOR( pVBInfo->P3c4 , 0x35 , 0x80 ) ; /* Vsync polarity */
1838   }
1839   else
1840   {
1841     Data = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_InfoFlag ;
1842     if ( Data & 0x4000 )
1843       XGINew_SetRegOR( pVBInfo->P3c4 , 0x30 , 0x20 ) ; /* Hsync polarity */
1844     if ( Data & 0x8000 )
1845       XGINew_SetRegOR( pVBInfo->P3c4 , 0x35 , 0x80 ) ; /* Vsync polarity */
1846   }
1847 }
1848
1849 /* --------------------------------------------------------------------- */
1850 /* Function : XGI_UpdateXG21CRTC */
1851 /* Input : */
1852 /* Output : CRT1 CRTC */
1853 /* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
1854 /* --------------------------------------------------------------------- */
1855 void XGI_UpdateXG21CRTC( USHORT ModeNo , PVB_DEVICE_INFO pVBInfo , USHORT RefreshRateTableIndex )
1856 {
1857   int i , index = -1;
1858
1859   XGINew_SetRegAND( pVBInfo->P3d4 , 0x11 , 0x7F ) ;             /* Unlock CR0~7 */
1860   if ( ModeNo <= 0x13 )
1861   {
1862     for( i = 0 ; i < 12 ; i++ )
1863     {
1864       if ( ModeNo == pVBInfo->UpdateCRT1[ i ].ModeID )
1865         index = i ;
1866     }
1867   }
1868   else
1869   {
1870     if ( ModeNo == 0x2E && ( pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC ==  RES640x480x60 ) )
1871       index = 12 ;
1872     else if ( ModeNo == 0x2E && ( pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC == RES640x480x72 ) )
1873       index = 13 ;
1874     else if ( ModeNo == 0x2F )
1875       index = 14 ;
1876     else if ( ModeNo == 0x50 )
1877       index = 15 ;
1878     else if ( ModeNo == 0x59 )
1879       index = 16 ;
1880   }
1881
1882   if( index != -1 )
1883   {
1884     XGINew_SetReg1( pVBInfo->P3d4 , 0x02 , pVBInfo->UpdateCRT1[ index ].CR02 ) ;
1885     XGINew_SetReg1( pVBInfo->P3d4 , 0x03 , pVBInfo->UpdateCRT1[ index ].CR03 ) ;
1886     XGINew_SetReg1( pVBInfo->P3d4 , 0x15 , pVBInfo->UpdateCRT1[ index ].CR15 ) ;
1887     XGINew_SetReg1( pVBInfo->P3d4 , 0x16 , pVBInfo->UpdateCRT1[ index ].CR16 ) ;
1888   }
1889 }
1890
1891
1892 /* --------------------------------------------------------------------- */
1893 /* Function : XGI_SetCRT1DE */
1894 /* Input : */
1895 /* Output : */
1896 /* Description : */
1897 /* --------------------------------------------------------------------- */
1898 void XGI_SetCRT1DE( PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT ModeNo,USHORT ModeIdIndex , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
1899 {
1900     USHORT resindex ,
1901            tempax ,
1902            tempbx ,
1903            tempcx ,
1904            temp ,
1905            modeflag ;
1906
1907     UCHAR data ;
1908
1909     resindex = XGI_GetResInfo( ModeNo , ModeIdIndex, pVBInfo ) ;
1910
1911     if ( ModeNo <= 0x13 )
1912     {
1913         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
1914         tempax = pVBInfo->StResInfo[ resindex ].HTotal ;
1915         tempbx = pVBInfo->StResInfo[ resindex ].VTotal ;
1916     }
1917     else
1918     {
1919         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
1920         tempax = pVBInfo->ModeResInfo[ resindex ].HTotal ;
1921         tempbx = pVBInfo->ModeResInfo[ resindex ].VTotal ;
1922     }
1923
1924     if ( modeflag & HalfDCLK )
1925         tempax = tempax >> 1 ;
1926
1927     if ( ModeNo > 0x13 )
1928     {
1929         if ( modeflag & HalfDCLK )
1930             tempax = tempax << 1 ;
1931
1932         temp = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_InfoFlag ;
1933
1934         if ( temp & InterlaceMode )
1935             tempbx = tempbx >> 1 ;
1936
1937         if ( modeflag & DoubleScanMode )
1938             tempbx = tempbx << 1 ;
1939     }
1940
1941     tempcx = 8 ;
1942
1943     /* if ( !( modeflag & Charx8Dot ) ) */
1944     /* tempcx = 9 ; */
1945
1946     tempax /= tempcx ;
1947     tempax -= 1 ;
1948     tempbx -= 1 ;
1949     tempcx = tempax ;
1950     temp = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x11 ) ;
1951     data = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x11 ) ;
1952     data &= 0x7F ;
1953     XGINew_SetReg1( pVBInfo->P3d4 , 0x11 , data ) ;             /* Unlock CRTC */
1954     XGINew_SetReg1( pVBInfo->P3d4 , 0x01 , ( USHORT )( tempcx & 0xff ) ) ;
1955     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x0b , ~0x0c , ( USHORT )( ( tempcx & 0x0ff00 ) >> 10 ) ) ;
1956     XGINew_SetReg1( pVBInfo->P3d4 , 0x12 , ( USHORT )( tempbx & 0xff ) ) ;
1957     tempax = 0 ;
1958     tempbx = tempbx >> 8 ;
1959
1960     if ( tempbx & 0x01 )
1961         tempax |= 0x02 ;
1962
1963     if ( tempbx & 0x02 )
1964         tempax |= 0x40 ;
1965
1966     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x42 , tempax ) ;
1967     data =( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x07 ) ;
1968     data &= 0xFF ;
1969     tempax = 0 ;
1970
1971     if ( tempbx & 0x04 )
1972         tempax |= 0x02 ;
1973
1974     XGINew_SetRegANDOR( pVBInfo->P3d4 ,0x0a , ~0x02 , tempax ) ;
1975     XGINew_SetReg1( pVBInfo->P3d4 , 0x11 , temp ) ;
1976 }
1977
1978
1979 /* --------------------------------------------------------------------- */
1980 /* Function : XGI_GetResInfo */
1981 /* Input : */
1982 /* Output : */
1983 /* Description : */
1984 /* --------------------------------------------------------------------- */
1985 USHORT  XGI_GetResInfo(USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
1986 {
1987     USHORT resindex ;
1988
1989     if ( ModeNo <= 0x13 )
1990     {
1991         resindex = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ResInfo ;    /* si+St_ResInfo */
1992     }
1993     else
1994     {
1995         resindex = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;   /* si+Ext_ResInfo */
1996     }
1997     return( resindex ) ;
1998 }
1999
2000
2001 /* --------------------------------------------------------------------- */
2002 /* Function : XGI_SetCRT1Offset */
2003 /* Input : */
2004 /* Output : */
2005 /* Description : */
2006 /* --------------------------------------------------------------------- */
2007 void XGI_SetCRT1Offset(  USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex , PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo )
2008 {
2009     USHORT temp ,
2010            ah ,
2011            al ,
2012            temp2 ,
2013            i ,
2014            DisplayUnit ;
2015
2016     /* GetOffset */
2017     temp = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeInfo ;
2018     temp = temp >> 8 ;
2019     temp = pVBInfo->ScreenOffset[ temp ] ;
2020
2021     temp2 = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_InfoFlag ;
2022     temp2 &= InterlaceMode ;
2023
2024     if ( temp2 )
2025         temp = temp << 1;
2026
2027     temp2 = pVBInfo->ModeType - ModeEGA ;
2028
2029     switch( temp2 )
2030     {
2031         case 0:
2032             temp2 = 1 ;
2033             break ;
2034         case 1:
2035             temp2 = 2 ;
2036             break ;
2037         case 2:
2038             temp2 = 4 ;
2039             break ;
2040         case 3:
2041             temp2 = 4 ;
2042             break ;
2043         case 4:
2044             temp2 = 6 ;
2045             break;
2046         case 5:
2047             temp2 = 8 ;
2048             break ;
2049         default:
2050             break ;
2051     }
2052
2053     if ( ( ModeNo >= 0x26 ) && ( ModeNo <= 0x28 ) )
2054         temp = temp * temp2 + temp2 / 2 ;
2055     else
2056         temp *= temp2 ;
2057
2058     /* SetOffset */
2059     DisplayUnit = temp ;
2060     temp2 = temp ;
2061     temp = temp >> 8 ;          /* ah */
2062     temp &= 0x0F ;
2063     i = XGINew_GetReg1( pVBInfo->P3c4 , 0x0E ) ;
2064     i &= 0xF0 ;
2065     i |= temp ;
2066     XGINew_SetReg1( pVBInfo->P3c4 , 0x0E , i ) ;
2067
2068     temp =( UCHAR )temp2 ;
2069     temp &= 0xFF ;              /* al */
2070     XGINew_SetReg1( pVBInfo->P3d4 , 0x13 , temp ) ;
2071
2072     /* SetDisplayUnit */
2073     temp2 = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_InfoFlag ;
2074     temp2 &= InterlaceMode ;
2075     if ( temp2 )
2076         DisplayUnit >>= 1 ;
2077
2078     DisplayUnit = DisplayUnit << 5 ;
2079     ah = ( DisplayUnit & 0xff00 ) >> 8 ;
2080     al = DisplayUnit & 0x00ff ;
2081     if ( al == 0 )
2082         ah += 1 ;
2083     else
2084         ah += 2 ;
2085
2086     if ( HwDeviceExtension->jChipType >= XG20 )
2087         if ( ( ModeNo == 0x4A ) | (ModeNo == 0x49 ) )
2088             ah -= 1 ;
2089
2090     XGINew_SetReg1( pVBInfo->P3c4 , 0x10 , ah ) ;
2091 }
2092
2093
2094 /* --------------------------------------------------------------------- */
2095 /* Function : XGI_SetCRT1VCLK */
2096 /* Input : */
2097 /* Output : */
2098 /* Description : */
2099 /* --------------------------------------------------------------------- */
2100 void XGI_SetCRT1VCLK( USHORT ModeNo , USHORT ModeIdIndex ,
2101                         PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
2102 {
2103     UCHAR index , data ;
2104     USHORT vclkindex ;
2105
2106     if ( pVBInfo->IF_DEF_LVDS == 1 )
2107     {
2108         index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRTVCLK ;
2109         data = XGINew_GetReg1( pVBInfo->P3c4 , 0x31 ) & 0xCF ;
2110         XGINew_SetReg1( pVBInfo->P3c4 , 0x31 , data ) ;
2111         XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , pVBInfo->VCLKData[ index ].SR2B ) ;
2112         XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , pVBInfo->VCLKData[ index ].SR2C ) ;
2113         XGINew_SetReg1( pVBInfo->P3c4 , 0x2D , 0x01 ) ;
2114     }
2115     else if ( ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) ) && ( pVBInfo->VBInfo & SetCRT2ToLCDA ) )
2116     {
2117         vclkindex = XGI_GetVCLK2Ptr( ModeNo , ModeIdIndex , RefreshRateTableIndex , HwDeviceExtension, pVBInfo ) ;
2118         data = XGINew_GetReg1( pVBInfo->P3c4 , 0x31 ) & 0xCF ;
2119         XGINew_SetReg1( pVBInfo->P3c4 , 0x31 , data ) ;
2120         data = pVBInfo->VBVCLKData[ vclkindex ].Part4_A ;
2121         XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , data ) ;
2122         data = pVBInfo->VBVCLKData[ vclkindex ].Part4_B ;
2123         XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , data ) ;
2124         XGINew_SetReg1( pVBInfo->P3c4 , 0x2D , 0x01 ) ;
2125     }
2126     else
2127     {
2128         index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRTVCLK ;
2129         data = XGINew_GetReg1( pVBInfo->P3c4 , 0x31 ) & 0xCF ;
2130         XGINew_SetReg1( pVBInfo->P3c4 , 0x31 , data ) ;
2131         XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , pVBInfo->VCLKData[ index ].SR2B ) ;
2132         XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , pVBInfo->VCLKData[ index ].SR2C ) ;
2133         XGINew_SetReg1( pVBInfo->P3c4 , 0x2D , 0x01 ) ;
2134     }
2135
2136     if ( HwDeviceExtension->jChipType >= XG20 )
2137     {
2138         if ( pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag & HalfDCLK )
2139         {
2140         data = XGINew_GetReg1( pVBInfo->P3c4 , 0x2B ) ;
2141         XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , data ) ;
2142         data = XGINew_GetReg1( pVBInfo->P3c4 , 0x2C ) ;
2143         index = data ;
2144         index &= 0xE0 ;
2145         data &= 0x1F ;
2146         data = data << 1 ;
2147         data += 1 ;
2148         data |= index ;
2149         XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , data ) ;
2150         }
2151     }
2152 }
2153
2154
2155 /* --------------------------------------------------------------------- */
2156 /* Function : XGI_SetCRT1FIFO */
2157 /* Input : */
2158 /* Output : */
2159 /* Description : */
2160 /* --------------------------------------------------------------------- */
2161 void XGI_SetCRT1FIFO( USHORT ModeNo , PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO pVBInfo )
2162 {
2163     USHORT data ;
2164
2165     data = XGINew_GetReg1( pVBInfo->P3c4 , 0x3D ) ;
2166     data &= 0xfe ;
2167     XGINew_SetReg1( pVBInfo->P3c4 , 0x3D , data ) ;     /* diable auto-threshold */
2168
2169     if ( ModeNo > 0x13 )
2170     {
2171         XGINew_SetReg1( pVBInfo->P3c4 , 0x08 , 0x34 ) ;
2172         data = XGINew_GetReg1( pVBInfo->P3c4 , 0x09 ) ;
2173         data &= 0xC0 ;
2174         XGINew_SetReg1( pVBInfo->P3c4 , 0x09 , data | 0x30) ;
2175         data = XGINew_GetReg1( pVBInfo->P3c4 , 0x3D ) ;
2176         data |= 0x01 ;
2177         XGINew_SetReg1( pVBInfo->P3c4 , 0x3D , data ) ;
2178     }
2179     else
2180     {
2181         if (HwDeviceExtension->jChipType == XG27)
2182         {
2183           XGINew_SetReg1( pVBInfo->P3c4 , 0x08 , 0x0E ) ;
2184           data = XGINew_GetReg1( pVBInfo->P3c4 , 0x09 ) ;
2185           data &= 0xC0 ;
2186           XGINew_SetReg1( pVBInfo->P3c4 , 0x09 , data | 0x20 ) ;
2187         }
2188         else
2189         {
2190           XGINew_SetReg1( pVBInfo->P3c4 , 0x08 , 0xAE ) ;
2191           data = XGINew_GetReg1( pVBInfo->P3c4 , 0x09 ) ;
2192           data &= 0xF0 ;
2193           XGINew_SetReg1( pVBInfo->P3c4 , 0x09 , data ) ;
2194         }
2195     }
2196
2197     if (HwDeviceExtension->jChipType == XG21)
2198     {
2199         XGI_SetXG21FPBits(pVBInfo);                 /* Fix SR9[7:6] can't read back */
2200     }
2201 }
2202
2203
2204 /* --------------------------------------------------------------------- */
2205 /* Function : XGI_SetCRT1ModeRegs */
2206 /* Input : */
2207 /* Output : */
2208 /* Description : */
2209 /* --------------------------------------------------------------------- */
2210 void XGI_SetCRT1ModeRegs( PXGI_HW_DEVICE_INFO HwDeviceExtension ,
2211                             USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex,PVB_DEVICE_INFO pVBInfo )
2212 {
2213     USHORT data ,
2214            data2 ,
2215            data3 ,
2216            infoflag = 0 ,
2217            modeflag ,
2218            resindex ,
2219            xres ;
2220
2221     if ( ModeNo > 0x13 )
2222     {
2223         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
2224         infoflag = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_InfoFlag ;
2225     }
2226     else
2227         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;    /* si+St_ModeFlag */
2228
2229     if ( XGINew_GetReg1( pVBInfo->P3d4 , 0x31 ) & 0x01 )
2230       XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x1F , 0x3F , 0x00 ) ;
2231
2232     if ( ModeNo > 0x13 )
2233         data = infoflag ;
2234     else
2235         data = 0 ;
2236
2237     data2 = 0 ;
2238
2239     if ( ModeNo > 0x13 )
2240     {
2241         if ( pVBInfo->ModeType > 0x02 )
2242         {
2243             data2 |= 0x02 ;
2244             data3 = pVBInfo->ModeType - ModeVGA ;
2245             data3 = data3 << 2 ;
2246             data2 |= data3 ;
2247         }
2248     }
2249
2250     data &= InterlaceMode ;
2251
2252     if ( data )
2253         data2 |= 0x20 ;
2254
2255     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x06 , ~0x3F , data2 ) ;
2256     /* XGINew_SetReg1(pVBInfo->P3c4,0x06,data2); */
2257     resindex = XGI_GetResInfo( ModeNo , ModeIdIndex, pVBInfo ) ;
2258     if ( ModeNo <= 0x13 )
2259         xres = pVBInfo->StResInfo[ resindex ].HTotal ;
2260     else
2261         xres = pVBInfo->ModeResInfo[ resindex ].HTotal ;                         /* xres->ax */
2262
2263     data = 0x0000 ;
2264     if ( infoflag & InterlaceMode )
2265     {
2266         if ( xres == 1024 )
2267             data = 0x0035 ;
2268         else if ( xres == 1280 )
2269             data = 0x0048 ;
2270     }
2271
2272     data2 = data & 0x00FF ;
2273     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x19 , 0xFF , data2 ) ;
2274     data2 = ( data & 0xFF00 ) >> 8 ;
2275     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x19 , 0xFC , data2 ) ;
2276
2277     if( modeflag & HalfDCLK )
2278         XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x01 , 0xF7 , 0x08 ) ;
2279
2280     data2 = 0 ;
2281
2282     if ( modeflag & LineCompareOff )
2283         data2 |= 0x08 ;
2284
2285     if ( ModeNo > 0x13 )
2286     {
2287         if ( pVBInfo->ModeType == ModeEGA )
2288             data2 |= 0x40 ;
2289     }
2290
2291     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0F , ~0x48 , data2 ) ;
2292     data = 0x60 ;
2293     if ( pVBInfo->ModeType != ModeText )
2294     {
2295         data = data ^ 0x60 ;
2296         if ( pVBInfo->ModeType != ModeEGA )
2297         {
2298             data = data ^ 0xA0 ;
2299         }
2300     }
2301     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x21 , 0x1F , data ) ;
2302
2303     XGI_SetVCLKState( HwDeviceExtension , ModeNo , RefreshRateTableIndex, pVBInfo) ;
2304
2305     /* if(modeflag&HalfDCLK)//030305 fix lowresolution bug */
2306     /* if(XGINew_IF_DEF_NEW_LOWRES) */
2307     /* XGI_VesaLowResolution(ModeNo,ModeIdIndex);//030305 fix lowresolution bug */
2308
2309     data=XGINew_GetReg1( pVBInfo->P3d4 , 0x31 ) ;
2310
2311     if (HwDeviceExtension->jChipType == XG27 )
2312     {
2313         if ( data & 0x40 )
2314             data = 0x2c ;
2315         else
2316             data = 0x6c ;
2317         XGINew_SetReg1( pVBInfo->P3d4 , 0x52 , data ) ;
2318         XGINew_SetRegOR( pVBInfo->P3d4 , 0x51 , 0x10 ) ;
2319     }
2320     else
2321     if (HwDeviceExtension->jChipType >= XG20 )
2322     {
2323         if ( data & 0x40 )
2324             data = 0x33 ;
2325         else
2326             data = 0x73 ;
2327         XGINew_SetReg1( pVBInfo->P3d4 , 0x52 , data ) ;
2328         XGINew_SetReg1( pVBInfo->P3d4 , 0x51 , 0x02 ) ;
2329     }
2330     else
2331     {
2332     if ( data & 0x40 )
2333         data = 0x2c ;
2334     else
2335         data = 0x6c ;
2336     XGINew_SetReg1( pVBInfo->P3d4 , 0x52 , data ) ;
2337     }
2338
2339 }
2340
2341
2342 /* --------------------------------------------------------------------- */
2343 /* Function : XGI_SetVCLKState */
2344 /* Input : */
2345 /* Output : */
2346 /* Description : */
2347 /* --------------------------------------------------------------------- */
2348 void XGI_SetVCLKState(  PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT ModeNo , USHORT RefreshRateTableIndex,PVB_DEVICE_INFO pVBInfo )
2349 {
2350     USHORT data ,
2351            data2 = 0 ;
2352     SHORT  VCLK ;
2353
2354     UCHAR  index ;
2355
2356     if ( ModeNo <= 0x13 )
2357         VCLK = 0 ;
2358     else
2359     {
2360         index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRTVCLK ;
2361         index &= IndexMask ;
2362         VCLK = pVBInfo->VCLKData[ index ].CLOCK ;
2363     }
2364
2365     data = XGINew_GetReg1( pVBInfo->P3c4 , 0x32 ) ;
2366     data &= 0xf3 ;
2367     if ( VCLK >= 200 )
2368         data |= 0x0c ;  /* VCLK > 200 */
2369
2370     if ( HwDeviceExtension->jChipType >= XG20 )
2371         data &= ~0x04 ; /* 2 pixel mode */
2372
2373     XGINew_SetReg1( pVBInfo->P3c4 , 0x32 , data ) ;
2374
2375     if ( HwDeviceExtension->jChipType < XG20 )
2376     {
2377     data = XGINew_GetReg1( pVBInfo->P3c4 , 0x1F ) ;
2378     data &= 0xE7 ;
2379     if ( VCLK < 200 )
2380         data |= 0x10 ;
2381     XGINew_SetReg1( pVBInfo->P3c4 , 0x1F , data ) ;
2382     }
2383
2384 /*  Jong for Adavantech LCD ripple issue
2385     if ( ( VCLK >= 0 ) && ( VCLK < 135 ) )
2386         data2 = 0x03 ;
2387     else if ( ( VCLK >= 135 ) && ( VCLK < 160 ) )
2388         data2 = 0x02 ;
2389     else if ( ( VCLK >= 160 ) && ( VCLK < 260 ) )
2390         data2 = 0x01 ;
2391     else if ( VCLK > 260 )
2392           data2 = 0x00 ;
2393 */
2394     data2 = 0x00 ;
2395
2396     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x07 , 0xFC , data2 ) ;
2397     if (HwDeviceExtension->jChipType >= XG27 )
2398     {
2399       XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x40 , 0xFC , data2&0x03 ) ;
2400     }
2401
2402
2403 }
2404
2405
2406 /* --------------------------------------------------------------------- */
2407 /* Function : XGI_VesaLowResolution */
2408 /* Input : */
2409 /* Output : */
2410 /* Description : */
2411 /* --------------------------------------------------------------------- */
2412 /*void XGI_VesaLowResolution( USHORT ModeNo , USHORT ModeIdIndex ,PVB_DEVICE_INFO pVBInfo)
2413 {
2414     USHORT modeflag;
2415
2416     if ( ModeNo > 0x13 )
2417         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
2418     else
2419         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
2420
2421     if ( ModeNo > 0x13 )
2422     {
2423         if ( modeflag & DoubleScanMode )
2424         {
2425             if ( modeflag & HalfDCLK )
2426             {
2427                 if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
2428                 {
2429                     if ( !( pVBInfo->VBInfo & SetCRT2ToRAMDAC ) )
2430                     {
2431                         if ( pVBInfo->VBInfo & SetInSlaveMode )
2432                         {
2433                             XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x01 , 0xf7 , 0x00 ) ;
2434                             XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0f , 0x7f , 0x00 ) ;
2435                             return ;
2436                         }
2437                     }
2438                 }
2439                 XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0f , 0xff , 0x80 ) ;
2440                 XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x01 , 0xf7 , 0x00 ) ;
2441                 return ;
2442             }
2443         }
2444     }
2445     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0f , 0x7f , 0x00 ) ;
2446 }
2447 */
2448
2449 /* --------------------------------------------------------------------- */
2450 /* Function : XGI_LoadDAC */
2451 /* Input : */
2452 /* Output : */
2453 /* Description : */
2454 /* --------------------------------------------------------------------- */
2455 void XGI_LoadDAC( USHORT ModeNo , USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo )
2456 {
2457     USHORT data , data2 , time ,
2458            i  , j , k , m , n , o ,
2459            si , di , bx , dl , al , ah , dh ,
2460            *table = NULL ;
2461
2462     if ( ModeNo <= 0x13 )
2463         data = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
2464     else
2465         data = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
2466
2467     data &= DACInfoFlag ;
2468     time = 64 ;
2469
2470     if ( data == 0x00 )
2471         table = XGINew_MDA_DAC ;
2472     else if ( data == 0x08 )
2473         table = XGINew_CGA_DAC ;
2474     else if ( data == 0x10 )
2475         table = XGINew_EGA_DAC ;
2476     else if ( data == 0x18 )
2477     {
2478         time = 256 ;
2479         table = XGINew_VGA_DAC ;
2480     }
2481
2482     if ( time == 256 )
2483         j = 16 ;
2484     else
2485         j = time ;
2486
2487     XGINew_SetReg3( pVBInfo->P3c6 , 0xFF ) ;
2488     XGINew_SetReg3( pVBInfo->P3c8 , 0x00 ) ;
2489
2490     for( i = 0 ; i < j ; i++ )
2491     {
2492         data = table[ i ] ;
2493
2494         for( k = 0 ; k < 3 ; k++ )
2495         {
2496             data2 = 0 ;
2497
2498             if ( data & 0x01 )
2499                 data2 = 0x2A ;
2500
2501             if ( data & 0x02 )
2502                 data2 += 0x15 ;
2503
2504             XGINew_SetReg3( pVBInfo->P3c9 , data2 ) ;
2505             data = data >> 2 ;
2506         }
2507     }
2508
2509     if ( time == 256 )
2510     {
2511         for( i = 16 ; i < 32 ; i++ )
2512         {
2513             data = table[ i ] ;
2514
2515             for( k = 0 ; k < 3 ; k++ )
2516                 XGINew_SetReg3( pVBInfo->P3c9 , data ) ;
2517         }
2518
2519         si = 32 ;
2520
2521         for( m = 0 ; m < 9 ; m++ )
2522         {
2523             di = si ;
2524             bx = si + 0x04 ;
2525             dl = 0 ;
2526
2527             for( n = 0 ; n < 3 ; n++ )
2528             {
2529                 for( o = 0 ; o < 5 ; o++ )
2530                 {
2531                     dh = table[ si ] ;
2532                     ah = table[ di ] ;
2533                     al = table[ bx ] ;
2534                     si++ ;
2535                     XGI_WriteDAC( dl , ah , al , dh, pVBInfo ) ;
2536                 }
2537
2538                 si -= 2 ;
2539
2540                 for( o = 0 ; o < 3 ; o++ )
2541                 {
2542                     dh = table[ bx ] ;
2543                     ah = table[ di ] ;
2544                     al = table[ si ] ;
2545                     si-- ;
2546                     XGI_WriteDAC( dl , ah , al , dh, pVBInfo ) ;
2547                 }
2548
2549                 dl++ ;
2550             }
2551
2552             si += 5 ;
2553         }
2554     }
2555 }
2556
2557
2558 /* --------------------------------------------------------------------- */
2559 /* Function : XGI_WriteDAC */
2560 /* Input : */
2561 /* Output : */
2562 /* Description : */
2563 /* --------------------------------------------------------------------- */
2564 void XGI_WriteDAC( USHORT dl , USHORT ah , USHORT al , USHORT dh,PVB_DEVICE_INFO pVBInfo )
2565 {
2566     USHORT temp , bh , bl ;
2567
2568     bh = ah ;
2569     bl = al ;
2570
2571     if ( dl != 0 )
2572     {
2573         temp = bh ;
2574         bh = dh ;
2575         dh = temp ;
2576         if ( dl == 1 )
2577         {
2578             temp = bl ;
2579             bl = dh ;
2580             dh = temp ;
2581         }
2582         else
2583         {
2584             temp = bl ;
2585             bl = bh ;
2586             bh = temp ;
2587         }
2588     }
2589     XGINew_SetReg3( pVBInfo->P3c9 , ( USHORT )dh ) ;
2590     XGINew_SetReg3( pVBInfo->P3c9 , ( USHORT )bh ) ;
2591     XGINew_SetReg3( pVBInfo->P3c9 , ( USHORT )bl ) ;
2592 }
2593
2594 #if 0
2595 /* --------------------------------------------------------------------- */
2596 /* Function : XGI_ClearBuffer */
2597 /* Input : */
2598 /* Output : */
2599 /* Description : */
2600 /* --------------------------------------------------------------------- */
2601 void XGI_ClearBuffer( PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT ModeNo, PVB_DEVICE_INFO  pVBInfo)
2602 {
2603     PVOID VideoMemoryAddress = ( PVOID )HwDeviceExtension->pjVideoMemoryAddress ;
2604     ULONG AdapterMemorySize  = ( ULONG )HwDeviceExtension->ulVideoMemorySize ;
2605     PUSHORT pBuffer ;
2606     int i ;
2607
2608     if ( pVBInfo->ModeType >= ModeEGA )
2609     {
2610         if ( ModeNo > 0x13 )
2611         {
2612             AdapterMemorySize = 0x40000 ;       /* clear 256k */
2613             /* GetDRAMSize( HwDeviceExtension ) ; */
2614             XGI_SetMemory( VideoMemoryAddress , AdapterMemorySize , 0 ) ;
2615         }
2616         else
2617         {
2618 /*
2619             pBuffer = VideoMemoryAddress ;
2620             for( i = 0 ; i < 0x4000 ; i++ )
2621                 pBuffer[ i ] = 0x0000 ;
2622 */
2623         }
2624     }
2625     else
2626     {
2627         pBuffer = VideoMemoryAddress ;
2628         if ( pVBInfo->ModeType < ModeCGA )
2629         {
2630 /*
2631             for ( i = 0 ; i < 0x4000 ; i++ )
2632                 pBuffer[ i ] = 0x0720 ;
2633 */
2634         }
2635         else
2636             XGI_SetMemory( VideoMemoryAddress , 0x8000 , 0 ) ;
2637     }
2638 }
2639
2640 #endif
2641 /* --------------------------------------------------------------------- */
2642 /* Function : XGI_SetLCDAGroup */
2643 /* Input : */
2644 /* Output : */
2645 /* Description : */
2646 /* --------------------------------------------------------------------- */
2647 void XGI_SetLCDAGroup( USHORT ModeNo , USHORT ModeIdIndex , PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO  pVBInfo )
2648 {
2649     USHORT RefreshRateTableIndex ;
2650     /* USHORT temp ; */
2651
2652     /* pVBInfo->SelectCRT2Rate = 0 ; */
2653
2654     pVBInfo->SetFlag |= ProgrammingCRT2 ;
2655     RefreshRateTableIndex = XGI_GetRatePtrCRT2( HwDeviceExtension, ModeNo , ModeIdIndex, pVBInfo ) ;
2656     XGI_GetLVDSResInfo(  ModeNo , ModeIdIndex,  pVBInfo ) ;
2657     XGI_GetLVDSData( ModeNo , ModeIdIndex , RefreshRateTableIndex,  pVBInfo);
2658     XGI_ModCRT1Regs( ModeNo , ModeIdIndex , RefreshRateTableIndex , HwDeviceExtension, pVBInfo ) ;
2659     XGI_SetLVDSRegs( ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2660     XGI_SetCRT2ECLK( ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2661 }
2662
2663
2664 /* --------------------------------------------------------------------- */
2665 /* Function : XGI_GetLVDSResInfo */
2666 /* Input : */
2667 /* Output : */
2668 /* Description : */
2669 /* --------------------------------------------------------------------- */
2670 void XGI_GetLVDSResInfo( USHORT ModeNo , USHORT ModeIdIndex,PVB_DEVICE_INFO  pVBInfo )
2671 {
2672     USHORT resindex , xres , yres , modeflag ;
2673
2674     if ( ModeNo <= 0x13 )
2675     {
2676         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ResInfo ;    /* si+St_ResInfo */
2677     }
2678     else
2679     {
2680         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;   /* si+Ext_ResInfo */
2681     }
2682
2683
2684     /* if ( ModeNo > 0x13 ) */
2685     /* modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ; */
2686     /* else */
2687     /* modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ; */
2688
2689     if ( ModeNo <= 0x13 )
2690     {
2691         resindex = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ResInfo ;    /* si+St_ResInfo */
2692     }
2693     else
2694     {
2695         resindex = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;   /* si+Ext_ResInfo */
2696     }
2697
2698     /* resindex = XGI_GetResInfo( ModeNo , ModeIdIndex, pVBInfo ) ; */
2699
2700     if ( ModeNo <= 0x13 )
2701     {
2702         xres = pVBInfo->StResInfo[ resindex ].HTotal ;
2703         yres = pVBInfo->StResInfo[ resindex ].VTotal ;
2704     }
2705     else
2706     {
2707         xres = pVBInfo->ModeResInfo[ resindex ].HTotal ;
2708         yres = pVBInfo->ModeResInfo[ resindex ].VTotal ;
2709     }
2710     if ( ModeNo > 0x13 )
2711     {
2712         if ( modeflag & HalfDCLK )
2713             xres = xres << 1 ;
2714
2715         if ( modeflag & DoubleScanMode )
2716             yres = yres << 1 ;
2717     }
2718     /* if ( modeflag & Charx8Dot ) */
2719     /* { */
2720
2721     if ( xres == 720 )
2722         xres = 640 ;
2723
2724     /* } */
2725     pVBInfo->VGAHDE = xres ;
2726     pVBInfo->HDE = xres ;
2727     pVBInfo->VGAVDE = yres ;
2728     pVBInfo->VDE = yres ;
2729 }
2730
2731
2732 /* --------------------------------------------------------------------- */
2733 /* Function : XGI_GetLVDSData */
2734 /* Input : */
2735 /* Output : */
2736 /* Description : */
2737 /* --------------------------------------------------------------------- */
2738 void XGI_GetLVDSData(  USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO  pVBInfo )
2739 {
2740     USHORT tempbx ;
2741     XGI330_LVDSDataStruct *LCDPtr = NULL ;
2742     XGI330_CHTVDataStruct  *TVPtr = NULL ;
2743
2744     tempbx = 2 ;
2745
2746     if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
2747     {
2748         LCDPtr = ( XGI330_LVDSDataStruct * )XGI_GetLcdPtr( tempbx, ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo) ;
2749         pVBInfo->VGAHT = LCDPtr->VGAHT ;
2750         pVBInfo->VGAVT = LCDPtr->VGAVT ;
2751         pVBInfo->HT = LCDPtr->LCDHT ;
2752         pVBInfo->VT = LCDPtr->LCDVT ;
2753     }
2754     if ( pVBInfo->IF_DEF_CH7017 == 1 )
2755     {
2756         if ( pVBInfo->VBInfo & SetCRT2ToTV )
2757         {
2758             TVPtr = ( XGI330_CHTVDataStruct * )XGI_GetTVPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2759             pVBInfo->VGAHT = TVPtr->VGAHT ;
2760             pVBInfo->VGAVT = TVPtr->VGAVT ;
2761             pVBInfo->HT = TVPtr->LCDHT ;
2762             pVBInfo->VT = TVPtr->LCDVT ;
2763         }
2764     }
2765
2766     if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
2767     {
2768         if ( !( pVBInfo->LCDInfo & ( SetLCDtoNonExpanding | EnableScalingLCD ) ) )
2769         {
2770             if ( ( pVBInfo->LCDResInfo == Panel1024x768 ) || ( pVBInfo->LCDResInfo == Panel1024x768x75 ) )
2771             {
2772                 pVBInfo->HDE = 1024 ;
2773                 pVBInfo->VDE = 768 ;
2774             }
2775             else if ( ( pVBInfo->LCDResInfo == Panel1280x1024 ) || ( pVBInfo->LCDResInfo == Panel1280x1024x75 ) )
2776             {
2777                 pVBInfo->HDE = 1280 ;
2778                 pVBInfo->VDE = 1024 ;
2779             }
2780             else if ( pVBInfo->LCDResInfo == Panel1400x1050 )
2781             {
2782                 pVBInfo->HDE = 1400 ;
2783                 pVBInfo->VDE = 1050 ;
2784             }
2785             else
2786             {
2787                 pVBInfo->HDE = 1600 ;
2788                 pVBInfo->VDE = 1200 ;
2789             }
2790         }
2791     }
2792 }
2793
2794
2795 /* --------------------------------------------------------------------- */
2796 /* Function : XGI_ModCRT1Regs */
2797 /* Input : */
2798 /* Output : */
2799 /* Description : */
2800 /* --------------------------------------------------------------------- */
2801 void XGI_ModCRT1Regs( USHORT ModeNo , USHORT ModeIdIndex ,
2802                         USHORT RefreshRateTableIndex , PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO  pVBInfo )
2803 {
2804     UCHAR index ;
2805     USHORT tempbx , i ;
2806     XGI_LVDSCRT1HDataStruct  *LCDPtr = NULL ;
2807     XGI_LVDSCRT1VDataStruct  *LCDPtr1 =NULL ;
2808     /* XGI330_CHTVDataStruct *TVPtr = NULL ; */
2809     XGI_CH7007TV_TimingHStruct *CH7007TV_TimingHPtr = NULL;
2810     XGI_CH7007TV_TimingVStruct *CH7007TV_TimingVPtr = NULL;
2811
2812     if( ModeNo <= 0x13 )
2813         index = pVBInfo->SModeIDTable[ ModeIdIndex ].St_CRT2CRTC ;
2814     else
2815         index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2816
2817     index= index & IndexMask ;
2818
2819     if ( ( pVBInfo->IF_DEF_ScaleLCD == 0 ) || ( ( pVBInfo->IF_DEF_ScaleLCD == 1 ) && ( !( pVBInfo->LCDInfo & EnableScalingLCD ) ) ) )
2820     {
2821         tempbx = 0 ;
2822
2823         if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
2824         {
2825             LCDPtr = ( XGI_LVDSCRT1HDataStruct * )XGI_GetLcdPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2826
2827             for( i = 0 ; i < 8 ; i++ )
2828                 pVBInfo->TimingH[ 0 ].data[ i ] = LCDPtr[ 0 ].Reg[ i ] ;
2829         }
2830
2831         if ( pVBInfo->IF_DEF_CH7007 == 1 )
2832         {
2833             if ( pVBInfo->VBInfo & SetCRT2ToTV )
2834             {
2835                 CH7007TV_TimingHPtr = ( XGI_CH7007TV_TimingHStruct *)XGI_GetTVPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2836
2837                 for( i = 0 ; i < 8 ; i++ )
2838                     pVBInfo->TimingH[ 0 ].data[ i ] = CH7007TV_TimingHPtr[ 0 ].data[ i ] ;
2839             }
2840         }
2841
2842         /* if ( pVBInfo->IF_DEF_CH7017 == 1 )
2843         {
2844             if ( pVBInfo->VBInfo & SetCRT2ToTV )
2845                 TVPtr = ( XGI330_CHTVDataStruct *)XGI_GetTVPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2846         } */
2847
2848         XGI_SetCRT1Timing_H(pVBInfo,HwDeviceExtension) ;
2849
2850         if ( pVBInfo->IF_DEF_CH7007 == 1 )
2851         {
2852             XGINew_SetReg1( pVBInfo->P3c4 , 0x2E , CH7007TV_TimingHPtr[ 0 ].data[ 8 ] ) ;
2853             XGINew_SetReg1( pVBInfo->P3c4 , 0x2F , CH7007TV_TimingHPtr[ 0 ].data[ 9 ] ) ;
2854         }
2855
2856         tempbx = 1 ;
2857
2858         if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
2859         {
2860             LCDPtr1 = ( XGI_LVDSCRT1VDataStruct * )XGI_GetLcdPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2861             for( i = 0 ; i < 7 ; i++ )
2862                 pVBInfo->TimingV[ 0 ].data[ i ] = LCDPtr1[ 0 ].Reg[ i ] ;
2863         }
2864
2865         if ( pVBInfo->IF_DEF_CH7007 == 1 )
2866         {
2867             if ( pVBInfo->VBInfo & SetCRT2ToTV )
2868             {
2869                 CH7007TV_TimingVPtr = ( XGI_CH7007TV_TimingVStruct *)XGI_GetTVPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2870
2871                 for( i = 0 ; i < 7 ; i++ )
2872                     pVBInfo->TimingV[ 0 ].data[ i ] = CH7007TV_TimingVPtr[ 0 ].data[ i ] ;
2873             }
2874         }
2875         /* if ( pVBInfo->IF_DEF_CH7017 == 1 )
2876         {
2877             if ( pVBInfo->VBInfo & SetCRT2ToTV )
2878                 TVPtr = ( XGI330_CHTVDataStruct *)XGI_GetTVPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2879         } */
2880
2881         XGI_SetCRT1Timing_V( ModeIdIndex , ModeNo , pVBInfo) ;
2882
2883         if ( pVBInfo->IF_DEF_CH7007 == 1 )
2884         {
2885             XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x33 , ~0x01 , CH7007TV_TimingVPtr[ 0 ].data[ 7 ]&0x01 ) ;
2886             XGINew_SetReg1( pVBInfo->P3c4 , 0x34 , CH7007TV_TimingVPtr[ 0 ].data[8 ] ) ;
2887             XGINew_SetReg1( pVBInfo->P3c4 , 0x3F , CH7007TV_TimingVPtr[ 0 ].data[9 ] ) ;
2888
2889         }
2890     }
2891 }
2892
2893
2894
2895 /* --------------------------------------------------------------------- */
2896 /* Function : XGI_SetLVDSRegs */
2897 /* Input : */
2898 /* Output : */
2899 /* Description : */
2900 /* --------------------------------------------------------------------- */
2901 void XGI_SetLVDSRegs( USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO  pVBInfo )
2902 {
2903     USHORT tempbx , tempax , tempcx , tempdx , push1 , push2 , modeflag ;
2904     unsigned long temp , temp1 , temp2 , temp3 , push3 ;
2905     XGI330_LCDDataDesStruct  *LCDPtr = NULL ;
2906     XGI330_LCDDataDesStruct2  *LCDPtr1 = NULL ;
2907
2908     if ( ModeNo > 0x13 )
2909         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
2910     else
2911         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
2912
2913     if ( !( pVBInfo->SetFlag & Win9xDOSMode ) )
2914     {
2915         if ( ( pVBInfo->IF_DEF_CH7017 == 0 ) || ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) ) )
2916         {
2917             if ( pVBInfo->IF_DEF_OEMUtil == 1 )
2918             {
2919                 tempbx = 8 ;
2920                 LCDPtr = ( XGI330_LCDDataDesStruct * )XGI_GetLcdPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2921             }
2922
2923             if ( ( pVBInfo->IF_DEF_OEMUtil == 0 ) || ( LCDPtr == 0 ) )
2924             {
2925                 tempbx = 3 ;
2926                 if ( pVBInfo->LCDInfo & EnableScalingLCD )
2927                     LCDPtr1 = ( XGI330_LCDDataDesStruct2 * )XGI_GetLcdPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2928                 else
2929                     LCDPtr = ( XGI330_LCDDataDesStruct * )XGI_GetLcdPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
2930             }
2931
2932             XGI_GetLCDSync( &tempax , &tempbx ,pVBInfo) ;
2933             push1 = tempbx ;
2934             push2 = tempax ;
2935
2936             /* GetLCDResInfo */
2937             if ( ( pVBInfo->LCDResInfo == Panel1024x768 ) || ( pVBInfo->LCDResInfo == Panel1024x768x75 ) )
2938             {
2939                 tempax = 1024 ;
2940                 tempbx = 768 ;
2941             }
2942             else if ( ( pVBInfo->LCDResInfo == Panel1280x1024 ) || ( pVBInfo->LCDResInfo == Panel1280x1024x75 ) )
2943             {
2944                 tempax = 1280 ;
2945                 tempbx = 1024 ;
2946             }
2947             else if ( pVBInfo->LCDResInfo == Panel1400x1050 )
2948             {
2949                 tempax = 1400 ;
2950                 tempbx = 1050 ;
2951             }
2952             else
2953             {
2954                 tempax = 1600 ;
2955                 tempbx = 1200 ;
2956             }
2957
2958             if ( pVBInfo->LCDInfo & SetLCDtoNonExpanding )
2959             {
2960                 pVBInfo->HDE=tempax;
2961                 pVBInfo->VDE=tempbx;
2962                 pVBInfo->VGAHDE=tempax;
2963                 pVBInfo->VGAVDE=tempbx;
2964             }
2965
2966             if ( ( pVBInfo->IF_DEF_ScaleLCD == 1 ) && ( pVBInfo->LCDInfo & EnableScalingLCD ) )
2967             {
2968                 tempax=pVBInfo->HDE;
2969                 tempbx=pVBInfo->VDE;
2970             }
2971
2972             tempax = pVBInfo->HT ;
2973
2974             if ( pVBInfo->LCDInfo & EnableScalingLCD )
2975                 tempbx = LCDPtr1->LCDHDES ;
2976             else
2977                 tempbx = LCDPtr->LCDHDES ;
2978
2979             tempcx = pVBInfo->HDE ;
2980             tempbx = tempbx & 0x0fff ;
2981             tempcx += tempbx ;
2982
2983             if ( tempcx >= tempax )
2984                 tempcx -= tempax ;
2985
2986             XGINew_SetReg1( pVBInfo->Part1Port , 0x1A , tempbx & 0x07 ) ;
2987
2988             tempcx = tempcx >> 3 ;
2989             tempbx = tempbx >> 3 ;
2990
2991             XGINew_SetReg1( pVBInfo->Part1Port , 0x16 , ( USHORT )( tempbx & 0xff ) ) ;
2992             XGINew_SetReg1( pVBInfo->Part1Port , 0x17 , ( USHORT )( tempcx & 0xff ) ) ;
2993
2994             tempax = pVBInfo->HT ;
2995
2996             if ( pVBInfo->LCDInfo & EnableScalingLCD )
2997                 tempbx = LCDPtr1->LCDHRS ;
2998             else
2999                 tempbx = LCDPtr->LCDHRS ;
3000
3001             tempcx = push2 ;
3002
3003             if ( pVBInfo->LCDInfo & EnableScalingLCD )
3004                 tempcx = LCDPtr1->LCDHSync ;
3005
3006             tempcx += tempbx ;
3007
3008             if ( tempcx >= tempax )
3009                 tempcx -= tempax ;
3010
3011             tempax = tempbx & 0x07 ;
3012             tempax = tempax >> 5 ;
3013             tempcx = tempcx >> 3 ;
3014             tempbx = tempbx >> 3 ;
3015
3016             tempcx &= 0x1f ;
3017             tempax |= tempcx ;
3018
3019             XGINew_SetReg1( pVBInfo->Part1Port , 0x15 , tempax ) ;
3020             XGINew_SetReg1( pVBInfo->Part1Port , 0x14 , ( USHORT )( tempbx & 0xff ) ) ;
3021
3022             tempax = pVBInfo->VT ;
3023             if ( pVBInfo->LCDInfo & EnableScalingLCD )
3024                 tempbx = LCDPtr1->LCDVDES ;
3025             else
3026                 tempbx = LCDPtr->LCDVDES ;
3027             tempcx = pVBInfo->VDE ;
3028
3029             tempbx = tempbx & 0x0fff ;
3030             tempcx += tempbx ;
3031             if ( tempcx >= tempax )
3032                 tempcx -= tempax ;
3033
3034             XGINew_SetReg1( pVBInfo->Part1Port , 0x1b , ( USHORT )( tempbx & 0xff ) ) ;
3035             XGINew_SetReg1( pVBInfo->Part1Port , 0x1c , ( USHORT )( tempcx & 0xff ) ) ;
3036
3037             tempbx = ( tempbx >> 8 ) & 0x07 ;
3038             tempcx = ( tempcx >> 8 ) & 0x07 ;
3039
3040             XGINew_SetReg1( pVBInfo->Part1Port , 0x1d , ( USHORT )( ( tempcx << 3 ) | tempbx ) ) ;
3041
3042             tempax = pVBInfo->VT ;
3043             if ( pVBInfo->LCDInfo & EnableScalingLCD )
3044                 tempbx = LCDPtr1->LCDVRS ;
3045             else
3046                 tempbx = LCDPtr->LCDVRS ;
3047
3048             /* tempbx = tempbx >> 4 ; */
3049               tempcx = push1 ;
3050
3051             if ( pVBInfo->LCDInfo & EnableScalingLCD )
3052                 tempcx = LCDPtr1->LCDVSync ;
3053
3054             tempcx += tempbx ;
3055             if ( tempcx >= tempax )
3056                 tempcx -= tempax ;
3057
3058             XGINew_SetReg1( pVBInfo->Part1Port , 0x18 , ( USHORT )( tempbx & 0xff ) ) ;
3059             XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x19 , ~0x0f , ( USHORT )( tempcx & 0x0f ) ) ;
3060
3061             tempax = ( ( tempbx >> 8 ) & 0x07 ) << 3 ;
3062
3063             tempbx = pVBInfo->VGAVDE ;
3064             if ( tempbx != pVBInfo->VDE )
3065                 tempax |= 0x40 ;
3066
3067             if ( pVBInfo->LCDInfo & EnableLVDSDDA )
3068                 tempax |= 0x40 ;
3069
3070             XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x1a , 0x07 , tempax ) ;
3071
3072             tempcx = pVBInfo->VGAVT ;
3073             tempbx = pVBInfo->VDE ;
3074             tempax = pVBInfo->VGAVDE ;
3075             tempcx -= tempax ;
3076
3077             temp = tempax ;            /* 0430 ylshieh */
3078             temp1 = ( temp << 18 ) / tempbx ;
3079
3080             tempdx = ( USHORT )( ( temp << 18 ) % tempbx ) ;
3081
3082             if ( tempdx != 0 )
3083             temp1 += 1 ;
3084
3085             temp2 = temp1 ;
3086             push3 = temp2 ;
3087
3088             XGINew_SetReg1( pVBInfo->Part1Port , 0x37 , ( USHORT )( temp2 & 0xff ) ) ;
3089             XGINew_SetReg1( pVBInfo->Part1Port , 0x36 , ( USHORT )( ( temp2 >> 8 ) & 0xff ) ) ;
3090
3091             tempbx = ( USHORT )( temp2 >> 16 ) ;
3092             tempax = tempbx & 0x03 ;
3093
3094             tempbx = pVBInfo->VGAVDE ;
3095             if ( tempbx == pVBInfo->VDE )
3096                 tempax |= 0x04 ;
3097
3098             XGINew_SetReg1( pVBInfo->Part1Port , 0x35 , tempax ) ;
3099
3100             if ( pVBInfo->VBType & VB_XGI301C )
3101             {
3102                 temp2 = push3 ;
3103                 XGINew_SetReg1( pVBInfo->Part4Port , 0x3c , ( USHORT )( temp2 & 0xff ) ) ;
3104                 XGINew_SetReg1( pVBInfo->Part4Port , 0x3b , ( USHORT )( ( temp2 >> 8 ) & 0xff ) ) ;
3105                 tempbx = ( USHORT )( temp2 >> 16 ) ;
3106                 XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x3a , ~0xc0 , ( USHORT )( ( tempbx & 0xff ) << 6 ) ) ;
3107
3108                 tempcx = pVBInfo->VGAVDE ;
3109                 if ( tempcx == pVBInfo->VDE )
3110                     XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x30 , ~0x0c , 0x00 ) ;
3111                 else
3112                     XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x30 , ~0x0c , 0x08 ) ;
3113             }
3114
3115             tempcx = pVBInfo->VGAHDE ;
3116             tempbx = pVBInfo->HDE ;
3117
3118             temp1 = tempcx << 16 ;
3119
3120             tempax = ( USHORT )( temp1 / tempbx ) ;
3121
3122             if ( ( tempbx & 0xffff ) == ( tempcx & 0xffff ) )
3123                 tempax = 65535 ;
3124
3125             temp3 = tempax ;
3126             temp1 = pVBInfo->VGAHDE << 16 ;
3127
3128             temp1 /= temp3 ;
3129             temp3 = temp3 << 16 ;
3130             temp1 -= 1 ;
3131
3132             temp3 = ( temp3 & 0xffff0000 ) + ( temp1 & 0xffff ) ;
3133
3134             tempax = ( USHORT )( temp3 & 0xff ) ;
3135             XGINew_SetReg1( pVBInfo->Part1Port , 0x1f , tempax ) ;
3136
3137             temp1 = pVBInfo->VGAVDE << 18 ;
3138             temp1 = temp1 / push3 ;
3139             tempbx = ( USHORT )( temp1 & 0xffff ) ;
3140
3141             if ( pVBInfo->LCDResInfo == Panel1024x768 )
3142                 tempbx -= 1 ;
3143
3144             tempax = ( ( tempbx >> 8 ) & 0xff ) << 3 ;
3145             tempax |= ( USHORT )( ( temp3 >> 8 ) & 0x07 ) ;
3146             XGINew_SetReg1( pVBInfo->Part1Port , 0x20 , ( USHORT )( tempax & 0xff ) ) ;
3147             XGINew_SetReg1( pVBInfo->Part1Port , 0x21 , ( USHORT )( tempbx & 0xff ) ) ;
3148
3149             temp3 = temp3 >> 16 ;
3150
3151             if ( modeflag & HalfDCLK )
3152                 temp3 = temp3 >> 1 ;
3153
3154             XGINew_SetReg1(pVBInfo->Part1Port , 0x22 , ( USHORT )( ( temp3 >> 8 ) & 0xff ) ) ;
3155             XGINew_SetReg1(pVBInfo->Part1Port , 0x23 , ( USHORT )( temp3 & 0xff ) ) ;
3156         }
3157     }
3158 }
3159
3160
3161 /* --------------------------------------------------------------------- */
3162 /* Function : XGI_SetCRT2ECLK */
3163 /* Input : */
3164 /* Output : */
3165 /* Description : */
3166 /* --------------------------------------------------------------------- */
3167 void XGI_SetCRT2ECLK( USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO  pVBInfo )
3168 {
3169     UCHAR di_0 , di_1 , tempal ;
3170     int i ;
3171
3172     tempal = XGI_GetVCLKPtr( RefreshRateTableIndex , ModeNo , ModeIdIndex, pVBInfo ) ;
3173     XGI_GetVCLKLen( tempal , &di_0 , &di_1, pVBInfo ) ;
3174     XGI_GetLCDVCLKPtr( &di_0 , &di_1, pVBInfo ) ;
3175
3176     for( i = 0 ; i < 4 ; i++ )
3177     {
3178         XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x31 , ~0x30 , ( USHORT )( 0x10 * i ) ) ;
3179         if ( pVBInfo->IF_DEF_CH7007 == 1 )
3180         {
3181             XGINew_SetReg1( pVBInfo->P3c4 , 0x2b , di_0 ) ;
3182             XGINew_SetReg1( pVBInfo->P3c4 , 0x2c , di_1 ) ;
3183         }
3184         else if ( ( !( pVBInfo->VBInfo & SetCRT2ToLCDA ) ) && ( !( pVBInfo->VBInfo & SetInSlaveMode ) ) )
3185         {
3186             XGINew_SetReg1( pVBInfo->P3c4 , 0x2e , di_0 ) ;
3187             XGINew_SetReg1( pVBInfo->P3c4 , 0x2f , di_1 ) ;
3188         }
3189         else
3190         {
3191             XGINew_SetReg1( pVBInfo->P3c4 , 0x2b , di_0 ) ;
3192             XGINew_SetReg1( pVBInfo->P3c4 , 0x2c , di_1 ) ;
3193         }
3194     }
3195 }
3196
3197
3198 /* --------------------------------------------------------------------- */
3199 /* Function : XGI_UpdateModeInfo */
3200 /* Input : */
3201 /* Output : */
3202 /* Description : */
3203 /* --------------------------------------------------------------------- */
3204 void XGI_UpdateModeInfo( PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO  pVBInfo )
3205 {
3206     USHORT tempcl ,
3207            tempch ,
3208            temp ,
3209            tempbl ,
3210            tempax ;
3211
3212     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
3213     {
3214         tempcl = 0 ;
3215         tempch = 0 ;
3216         temp = XGINew_GetReg1( pVBInfo->P3c4 , 0x01 ) ;
3217
3218         if ( !( temp & 0x20 ) )
3219         {
3220             temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x17 ) ;
3221             if ( temp & 0x80 )
3222             {
3223                 if ( ( HwDeviceExtension->jChipType >= XG20 ) || ( HwDeviceExtension->jChipType >= XG40 ) )
3224                     temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x53 ) ;
3225                 else
3226                     temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x63 ) ;
3227
3228                 if ( !( temp & 0x40 ) )
3229                     tempcl |= ActiveCRT1 ;
3230             }
3231         }
3232
3233         temp = XGINew_GetReg1( pVBInfo->Part1Port , 0x2e ) ;
3234         temp &= 0x0f ;
3235
3236         if ( !( temp == 0x08 ) )
3237         {
3238             tempax = XGINew_GetReg1( pVBInfo->Part1Port , 0x13 ) ;      /* Check ChannelA by Part1_13 [2003/10/03] */
3239             if ( tempax & 0x04 )
3240                 tempcl = tempcl | ActiveLCD ;
3241
3242             temp &= 0x05 ;
3243
3244             if ( !( tempcl & ActiveLCD ) )
3245                 if ( temp == 0x01 )
3246                     tempcl |= ActiveCRT2 ;
3247
3248             if ( temp == 0x04 )
3249                 tempcl |= ActiveLCD ;
3250
3251             if ( temp == 0x05 )
3252             {
3253                 temp = XGINew_GetReg1( pVBInfo->Part2Port , 0x00 ) ;
3254
3255                 if( !( temp & 0x08 ) )
3256                     tempch |= ActiveAVideo ;
3257
3258                 if ( !( temp & 0x04 ) )
3259                     tempch |= ActiveSVideo ;
3260
3261                 if ( temp & 0x02 )
3262                     tempch |= ActiveSCART ;
3263
3264                 if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
3265                 {
3266                     if ( temp & 0x01 )
3267                         tempch |= ActiveHiTV ;
3268                 }
3269
3270                 if ( pVBInfo->VBInfo & SetCRT2ToYPbPr )
3271                 {
3272                     temp = XGINew_GetReg1( pVBInfo->Part2Port , 0x4d ) ;
3273
3274                     if ( temp & 0x10 )
3275                         tempch |= ActiveYPbPr ;
3276                 }
3277
3278                 if ( tempch != 0 )
3279                     tempcl |= ActiveTV ;
3280             }
3281         }
3282
3283         temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x3d ) ;
3284         if ( tempcl & ActiveLCD )
3285         {
3286             if ( ( pVBInfo->SetFlag & ReserveTVOption ) )
3287             {
3288                 if ( temp & ActiveTV )
3289                     tempcl |= ActiveTV ;
3290             }
3291         }
3292         temp = tempcl ;
3293         tempbl = ~ModeSwitchStatus ;
3294         XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x3d , tempbl , temp ) ;
3295
3296         if ( !( pVBInfo->SetFlag & ReserveTVOption ) )
3297             XGINew_SetReg1( pVBInfo->P3d4 , 0x3e , tempch ) ;
3298     }
3299     else
3300     {
3301         return ;
3302     }
3303 }
3304
3305
3306 /* --------------------------------------------------------------------- */
3307 /* Function : XGI_GetVGAType */
3308 /* Input : */
3309 /* Output : */
3310 /* Description : */
3311 /* --------------------------------------------------------------------- */
3312 void XGI_GetVGAType( PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO  pVBInfo)
3313 {
3314     /*
3315     if ( HwDeviceExtension->jChipType >= XG20 )
3316     {
3317         pVBInfo->Set_VGAType = XG20;
3318     }
3319     else if ( HwDeviceExtension->jChipType >= XG40 )
3320     {
3321         pVBInfo->Set_VGAType = VGA_XGI340 ;
3322     }
3323     */
3324     pVBInfo->Set_VGAType = HwDeviceExtension->jChipType;
3325 }
3326
3327
3328 /* --------------------------------------------------------------------- */
3329 /* Function : XGI_GetVBType */
3330 /* Input : */
3331 /* Output : */
3332 /* Description : */
3333 /* --------------------------------------------------------------------- */
3334 void XGI_GetVBType(PVB_DEVICE_INFO  pVBInfo)
3335 {
3336     USHORT flag , tempbx , tempah ;
3337
3338     if ( pVBInfo->IF_DEF_CH7007 == 1 )
3339     {
3340         pVBInfo->VBType = VB_CH7007 ;
3341         return;
3342     }
3343     if ( pVBInfo->IF_DEF_LVDS == 0 )
3344     {
3345         tempbx = VB_XGI302B ;
3346         flag = XGINew_GetReg1( pVBInfo->Part4Port , 0x00 ) ;
3347         if ( flag != 0x02 )
3348         {
3349             tempbx = VB_XGI301 ;
3350             flag = XGINew_GetReg1( pVBInfo->Part4Port , 0x01 ) ;
3351             if ( flag >= 0xB0 )
3352             {
3353                 tempbx = VB_XGI301B ;
3354                 if ( flag >= 0xC0 )
3355                 {
3356                     tempbx = VB_XGI301C ;
3357                     if ( flag >= 0xD0 )
3358                     {
3359                         tempbx = VB_XGI301LV ;
3360                         if ( flag >= 0xE0 )
3361                         {
3362                             tempbx = VB_XGI302LV ;
3363                             tempah = XGINew_GetReg1( pVBInfo->Part4Port , 0x39 ) ;
3364                             if ( tempah != 0xFF )
3365                                 tempbx = VB_XGI301C ;
3366                         }
3367                     }
3368                 }
3369
3370                 if ( tempbx & ( VB_XGI301B | VB_XGI302B ) )
3371                 {
3372                     flag = XGINew_GetReg1( pVBInfo->Part4Port , 0x23 ) ;
3373
3374                     if ( !( flag & 0x02 ) )
3375                         tempbx = tempbx | VB_NoLCD ;
3376                 }
3377             }
3378         }
3379         pVBInfo->VBType = tempbx ;
3380     }
3381 /*
3382     else if ( pVBInfo->IF_DEF_CH7017 == 1 )
3383         pVBInfo->VBType = VB_CH7017 ;
3384     else  //LVDS
3385         pVBInfo->VBType = VB_LVDS_NS ;
3386 */
3387
3388 }
3389
3390
3391 /* --------------------------------------------------------------------- */
3392 /* Function : XGI_GetVBInfo */
3393 /* Input : */
3394 /* Output : */
3395 /* Description : */
3396 /* --------------------------------------------------------------------- */
3397 void XGI_GetVBInfo( USHORT ModeNo , USHORT ModeIdIndex , PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO  pVBInfo )
3398 {
3399     USHORT tempax ,
3400            push ,
3401            tempbx ,
3402            temp ,
3403            modeflag ;
3404
3405     if ( ModeNo <= 0x13 )
3406     {
3407         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
3408     }
3409     else
3410     {
3411         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
3412     }
3413
3414     pVBInfo->SetFlag = 0 ;
3415     pVBInfo->ModeType = modeflag & ModeInfoFlag ;
3416     tempbx = 0 ;
3417
3418     if ( pVBInfo->VBType & 0xFFFF )
3419     {
3420         temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x30 ) ;           /* Check Display Device */
3421         tempbx = tempbx | temp ;
3422         temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x31 ) ;
3423         push = temp ;
3424         push = push << 8 ;
3425         tempax = temp << 8 ;
3426         tempbx = tempbx | tempax ;
3427         temp = ( SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA | SetInSlaveMode | DisableCRT2Display ) ;
3428         temp = 0xFFFF ^ temp ;
3429         tempbx &= temp ;
3430
3431         temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) ;
3432
3433         if ( pVBInfo->IF_DEF_LCDA == 1 )
3434         {
3435
3436             if ( ( pVBInfo->Set_VGAType >= XG20 ) || ( pVBInfo->Set_VGAType >= XG40 ))
3437             {
3438                 if ( pVBInfo->IF_DEF_LVDS == 0 )
3439                 {
3440                     /* if ( ( pVBInfo->VBType & VB_XGI302B ) || ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) || ( pVBInfo->VBType & VB_XGI301C ) ) */
3441                     if ( pVBInfo->VBType & ( VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
3442                     {
3443                         if ( temp & EnableDualEdge )
3444                         {
3445                             tempbx |= SetCRT2ToDualEdge ;
3446
3447                             if ( temp & SetToLCDA )
3448                                 tempbx |= SetCRT2ToLCDA ;
3449                         }
3450                     }
3451                 }
3452                 else if ( pVBInfo->IF_DEF_CH7017 == 1 )
3453                 {
3454                     if ( pVBInfo->VBType & VB_CH7017 )
3455                     {
3456                         if ( temp & EnableDualEdge )
3457                         {
3458                             tempbx |= SetCRT2ToDualEdge ;
3459
3460                             if ( temp & SetToLCDA )
3461                                 tempbx |= SetCRT2ToLCDA ;
3462                         }
3463                     }
3464                 }
3465             }
3466         }
3467
3468         if ( pVBInfo->IF_DEF_YPbPr == 1 )
3469         {
3470             if ( ( ( pVBInfo->IF_DEF_LVDS == 0 ) && ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) || ( pVBInfo->VBType & VB_XGI301C ) ) )
3471             || ( ( pVBInfo->IF_DEF_CH7017 == 1 ) && ( pVBInfo->VBType&VB_CH7017 ) ) || ( (pVBInfo->IF_DEF_CH7007 == 1) && (pVBInfo->VBType&VB_CH7007) ) )    /* [Billy] 07/05/04 */
3472             {
3473                 if ( temp & SetYPbPr )  /* temp = CR38 */
3474                 {
3475                     if ( pVBInfo->IF_DEF_HiVision == 1 )
3476                     {
3477                         temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x35 ) ;  /* shampoo add for new scratch */
3478                         temp &= YPbPrMode ;
3479                         tempbx |= SetCRT2ToHiVisionTV ;
3480
3481                         if ( temp != YPbPrMode1080i ) {
3482                             tempbx &= ( ~SetCRT2ToHiVisionTV ) ;
3483                             tempbx |= SetCRT2ToYPbPr ; }
3484                     }
3485
3486                     /* tempbx |= SetCRT2ToYPbPr ; */
3487                 }
3488             }
3489         }
3490
3491         tempax = push ;  /* restore CR31 */
3492
3493         if ( pVBInfo->IF_DEF_LVDS == 0 )
3494         {
3495             if ( pVBInfo->IF_DEF_YPbPr == 1 )
3496             {
3497                 if ( pVBInfo->IF_DEF_HiVision == 1 )
3498                     temp = 0x09FC ;
3499                 else
3500                     temp = 0x097C ;
3501             }
3502             else
3503             {
3504                 if ( pVBInfo->IF_DEF_HiVision == 1 )
3505                     temp = 0x01FC ;
3506                 else
3507                     temp = 0x017C ;
3508             }
3509         }
3510         else    /* 3nd party chip */
3511         {
3512             if ( pVBInfo->IF_DEF_CH7017 == 1 )
3513                 temp = ( SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA ) ;
3514             else if ( pVBInfo->IF_DEF_CH7007 == 1 )  /* [Billy] 07/05/03 */
3515             {
3516                 temp = SetCRT2ToTV ;
3517             }
3518             else
3519                 temp = SetCRT2ToLCD ;
3520         }
3521
3522         if ( !( tempbx & temp ) )
3523         {
3524             tempax |= DisableCRT2Display ;
3525             tempbx = 0 ;
3526         }
3527
3528         if ( pVBInfo->IF_DEF_LCDA == 1 )        /* Select Display Device */
3529         {
3530             if ( !( pVBInfo->VBType & VB_NoLCD ) )
3531             {
3532                 if ( tempbx & SetCRT2ToLCDA )
3533                 {
3534                     if ( tempbx & SetSimuScanMode )
3535                         tempbx &= ( ~( SetCRT2ToLCD | SetCRT2ToRAMDAC | SwitchToCRT2 ) ) ;
3536                     else
3537                         tempbx &= ( ~( SetCRT2ToLCD | SetCRT2ToRAMDAC | SetCRT2ToTV | SwitchToCRT2 ) ) ;
3538                 }
3539             }
3540         }
3541
3542         /* shampoo add */
3543         if ( !( tempbx & ( SwitchToCRT2 | SetSimuScanMode ) ) ) /* for driver abnormal */
3544         {
3545             if ( pVBInfo->IF_DEF_CRT2Monitor == 1 )
3546             {
3547                 if ( tempbx & SetCRT2ToRAMDAC )
3548                 {
3549                     tempbx &= ( 0xFF00 | SetCRT2ToRAMDAC | SwitchToCRT2 | SetSimuScanMode ) ;
3550                     tempbx &= ( 0x00FF | ( ~SetCRT2ToYPbPr ) ) ;
3551                 }
3552             }
3553             else
3554                 tempbx &= ( ~( SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV ) ) ;
3555         }
3556
3557         if ( !( pVBInfo->VBType & VB_NoLCD ) )
3558         {
3559             if ( tempbx & SetCRT2ToLCD )
3560             {
3561                 tempbx &= ( 0xFF00 | SetCRT2ToLCD | SwitchToCRT2 | SetSimuScanMode ) ;
3562                 tempbx &= ( 0x00FF | ( ~SetCRT2ToYPbPr ) ) ;
3563             }
3564         }
3565
3566         if ( tempbx & SetCRT2ToSCART )
3567         {
3568             tempbx &= ( 0xFF00 | SetCRT2ToSCART | SwitchToCRT2 | SetSimuScanMode ) ;
3569             tempbx &= ( 0x00FF | ( ~SetCRT2ToYPbPr ) ) ;
3570         }
3571
3572         if ( pVBInfo->IF_DEF_YPbPr == 1 )
3573         {
3574             if ( tempbx & SetCRT2ToYPbPr )
3575                 tempbx &= ( 0xFF00 | SwitchToCRT2 | SetSimuScanMode ) ;
3576         }
3577
3578         if ( pVBInfo->IF_DEF_HiVision == 1 )
3579         {
3580             if ( tempbx & SetCRT2ToHiVisionTV )
3581                 tempbx &= ( 0xFF00 | SetCRT2ToHiVisionTV | SwitchToCRT2 | SetSimuScanMode ) ;
3582         }
3583
3584         if ( tempax & DisableCRT2Display )      /* Set Display Device Info */
3585         {
3586             if ( !( tempbx & ( SwitchToCRT2 | SetSimuScanMode ) ) )
3587                 tempbx = DisableCRT2Display ;
3588         }
3589
3590         if ( !( tempbx & DisableCRT2Display ) )
3591         {
3592             if ( ( !( tempbx & DriverMode ) ) || ( !( modeflag & CRT2Mode ) ) )
3593             {
3594                 if ( pVBInfo->IF_DEF_LCDA == 1 )
3595                 {
3596                     if ( !( tempbx & SetCRT2ToLCDA ) )
3597                         tempbx |= ( SetInSlaveMode | SetSimuScanMode ) ;
3598                 }
3599
3600                 if ( pVBInfo->IF_DEF_VideoCapture == 1 )
3601                 {
3602                     if ( ( ( HwDeviceExtension->jChipType == XG40 ) && ( pVBInfo->Set_VGAType == XG40 ) )
3603                     || ( ( HwDeviceExtension->jChipType == XG41 ) && ( pVBInfo->Set_VGAType == XG41 ) )
3604                     || ( ( HwDeviceExtension->jChipType == XG42 ) && ( pVBInfo->Set_VGAType == XG42 ) )
3605                     || ( ( HwDeviceExtension->jChipType == XG45 ) && ( pVBInfo->Set_VGAType == XG45 ) ) )
3606                     {
3607                         if ( ModeNo <= 13 )
3608                         {
3609                             if ( !( tempbx & SetCRT2ToRAMDAC ) )        /*CRT2 not need to support*/
3610                             {
3611                                 tempbx &= ( 0x00FF | ( ~SetInSlaveMode ) ) ;
3612                                 pVBInfo->SetFlag |= EnableVCMode ;
3613                             }
3614                         }
3615                     }
3616                 }
3617             }
3618
3619             /*LCD+TV can't support in slave mode (Force LCDA+TV->LCDB)*/
3620             if ( ( tempbx & SetInSlaveMode ) && ( tempbx & SetCRT2ToLCDA ) )
3621             {
3622                 tempbx ^= ( SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToDualEdge ) ;
3623                 pVBInfo->SetFlag |= ReserveTVOption ;
3624             }
3625         }
3626     }
3627
3628     pVBInfo->VBInfo = tempbx ;
3629 }
3630
3631
3632 /* --------------------------------------------------------------------- */
3633 /* Function : XGI_GetTVInfo */
3634 /* Input : */
3635 /* Output : */
3636 /* Description : */
3637 /* --------------------------------------------------------------------- */
3638 void XGI_GetTVInfo( USHORT ModeNo , USHORT ModeIdIndex ,PVB_DEVICE_INFO  pVBInfo )
3639 {
3640     USHORT temp ,
3641            tempbx = 0 ,
3642            resinfo = 0 ,
3643            modeflag ,
3644            index1 ;
3645
3646     tempbx = 0 ;
3647     resinfo = 0 ;
3648
3649     if ( pVBInfo->VBInfo & SetCRT2ToTV )
3650     {
3651         if ( ModeNo <= 0x13 )
3652         {
3653             modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;       /* si+St_ModeFlag */
3654             resinfo = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ResInfo ; /* si+St_ResInfo */
3655         }
3656         else
3657         {
3658             modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
3659             resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ; /* si+Ext_ResInfo */
3660         }
3661
3662         if ( pVBInfo->VBInfo & SetCRT2ToTV )
3663         {
3664             temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x35 ) ;
3665             tempbx = temp;
3666             if ( tempbx & SetPALTV )
3667             {
3668                 tempbx &= ( SetCHTVOverScan | SetPALMTV | SetPALNTV | SetPALTV ) ;
3669                 if ( tempbx & SetPALMTV )
3670                     tempbx &= ~SetPALTV ; /* set to NTSC if PAL-M */
3671             }
3672             else
3673                 tempbx &= ( SetCHTVOverScan | SetNTSCJ | SetPALTV ) ;
3674 /*
3675             if ( pVBInfo->IF_DEF_LVDS == 0 )
3676             {
3677                 index1 = XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) ; //PAL-M/PAL-N Info
3678                 temp2 = ( index1 & 0xC0 ) >> 5 ;                //00:PAL, 01:PAL-M, 10:PAL-N
3679                 tempbx |= temp2 ;
3680                 if ( temp2 & 0x02 )          //PAL-M
3681                     tempbx &= ( ~SetPALTV ) ;
3682             }
3683 */
3684         }
3685
3686         if ( pVBInfo->IF_DEF_CH7017 == 1 )
3687         {
3688             tempbx = XGINew_GetReg1( pVBInfo->P3d4 , 0x35 ) ;
3689
3690             if ( tempbx & TVOverScan )
3691                 tempbx |= SetCHTVOverScan ;
3692         }
3693
3694         if ( pVBInfo->IF_DEF_CH7007 == 1 ) /* [Billy] 07/05/04 */
3695         {
3696             tempbx = XGINew_GetReg1( pVBInfo->P3d4 , 0x35 ) ;
3697
3698             if ( tempbx & TVOverScan )
3699             {
3700                 tempbx |= SetCHTVOverScan ;
3701             }
3702         }
3703
3704
3705         if ( pVBInfo->IF_DEF_LVDS == 0 )
3706         {
3707             if ( pVBInfo->VBInfo & SetCRT2ToSCART )
3708                 tempbx |= SetPALTV ;
3709         }
3710
3711         if ( pVBInfo->IF_DEF_YPbPr == 1 )
3712         {
3713             if ( pVBInfo->VBInfo & SetCRT2ToYPbPr )
3714             {
3715                 index1 = XGINew_GetReg1( pVBInfo->P3d4 , 0x35 ) ;
3716                 index1 &= YPbPrMode ;
3717
3718                 if ( index1 == YPbPrMode525i )
3719                     tempbx |= SetYPbPrMode525i ;
3720
3721                 if ( index1 == YPbPrMode525p )
3722                     tempbx = tempbx | SetYPbPrMode525p;
3723                 if ( index1 == YPbPrMode750p)
3724                     tempbx = tempbx | SetYPbPrMode750p;
3725             }
3726         }
3727
3728         if ( pVBInfo->IF_DEF_HiVision == 1 )
3729         {
3730             if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
3731             {
3732                 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV ;
3733             }
3734         }
3735
3736         if ( pVBInfo->IF_DEF_LVDS == 0 )
3737         {      /* shampoo */
3738             if ( ( pVBInfo->VBInfo & SetInSlaveMode ) && ( !( pVBInfo->VBInfo & SetNotSimuMode ) ) )
3739                 tempbx |= TVSimuMode ;
3740
3741             if ( !( tempbx & SetPALTV ) && ( modeflag > 13 ) && ( resinfo == 8 ) ) /* NTSC 1024x768, */
3742                 tempbx |= NTSC1024x768 ;
3743
3744             tempbx |= RPLLDIV2XO ;
3745
3746             if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
3747             {
3748                 if ( pVBInfo->VBInfo & SetInSlaveMode )
3749                     tempbx &=( ~RPLLDIV2XO ) ;
3750             }
3751             else
3752             {
3753                 if ( tempbx & ( SetYPbPrMode525p | SetYPbPrMode750p ) )
3754                     tempbx &= ( ~RPLLDIV2XO ) ;
3755                 else if ( !( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) ) )
3756                 {
3757                     if ( tempbx & TVSimuMode )
3758                         tempbx &= ( ~RPLLDIV2XO ) ;
3759                 }
3760             }
3761         }
3762     }
3763     pVBInfo->TVInfo = tempbx ;
3764 }
3765
3766
3767 /* --------------------------------------------------------------------- */
3768 /* Function : XGI_GetLCDInfo */
3769 /* Input : */
3770 /* Output : */
3771 /* Description : */
3772 /* --------------------------------------------------------------------- */
3773 BOOLEAN XGI_GetLCDInfo( USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo)
3774 {
3775     USHORT temp ,
3776            tempax ,
3777            tempbx ,
3778            modeflag ,
3779            resinfo = 0 ,
3780            LCDIdIndex ;
3781
3782     pVBInfo->LCDResInfo = 0 ;
3783     pVBInfo->LCDTypeInfo = 0 ;
3784     pVBInfo->LCDInfo = 0 ;
3785
3786     if ( ModeNo <= 0x13 )
3787     {
3788         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;  /* si+St_ModeFlag // */
3789     }
3790     else
3791     {
3792         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
3793         resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ; /* si+Ext_ResInfo// */
3794     }
3795
3796     temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x36 ) ; /* Get LCD Res.Info */
3797     tempbx = temp & 0x0F ;
3798
3799     if ( tempbx == 0 )
3800         tempbx = Panel1024x768 ; /* default */
3801
3802     /* LCD75 [2003/8/22] Vicent */
3803     if ( ( tempbx == Panel1024x768 ) || ( tempbx == Panel1280x1024 ) )
3804     {
3805         if ( pVBInfo->VBInfo & DriverMode )
3806         {
3807             tempax = XGINew_GetReg1( pVBInfo->P3d4 , 0x33 ) ;
3808             if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
3809                 tempax &= 0x0F ;
3810             else
3811                 tempax = tempax >> 4 ;
3812
3813             if ( ( resinfo == 6 ) || ( resinfo == 9 ) )
3814             {
3815                 if ( tempax >= 3 )
3816                     tempbx |= PanelRef75Hz ;
3817             }
3818             else if ( ( resinfo == 7 ) || ( resinfo == 8 ) )
3819             {
3820                 if ( tempax >= 4 )
3821                     tempbx |= PanelRef75Hz ;
3822             }
3823         }
3824     }
3825
3826     pVBInfo->LCDResInfo = tempbx ;
3827
3828     /* End of LCD75 */
3829
3830     if( pVBInfo->IF_DEF_OEMUtil == 1 )
3831     {
3832         pVBInfo->LCDTypeInfo = ( temp & 0xf0 ) >> 4 ;
3833     }
3834
3835     if ( !( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) ) )
3836     {
3837         return 0;
3838     }
3839
3840     tempbx = 0 ;
3841
3842     temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x37 ) ;
3843
3844     temp &= ( ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable ) ;
3845
3846     if ( ( pVBInfo->IF_DEF_ScaleLCD == 1 ) && ( temp & LCDNonExpanding ) )
3847         temp &= ~EnableScalingLCD ;
3848
3849     tempbx |= temp ;
3850
3851     LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo) ;
3852
3853     tempax = pVBInfo->LCDCapList[ LCDIdIndex ].LCD_Capability ;
3854
3855     if ( pVBInfo->IF_DEF_LVDS == 0 )    /* shampoo */
3856     {
3857         if ( ( ( pVBInfo->VBType & VB_XGI302LV ) || ( pVBInfo->VBType & VB_XGI301C ) ) && ( tempax & LCDDualLink ) )
3858         {
3859             tempbx |= SetLCDDualLink ;
3860         }
3861     }
3862
3863     if ( pVBInfo->IF_DEF_CH7017 == 1 )
3864     {
3865         if ( tempax & LCDDualLink )
3866         {
3867             tempbx |= SetLCDDualLink ;
3868         }
3869     }
3870
3871     if ( pVBInfo->IF_DEF_LVDS == 0 )
3872     {
3873         if ( ( pVBInfo->LCDResInfo == Panel1400x1050 ) && ( pVBInfo->VBInfo & SetCRT2ToLCD ) && ( ModeNo > 0x13 ) && ( resinfo == 9 ) && ( !( tempbx & EnableScalingLCD ) ) )
3874             tempbx |= SetLCDtoNonExpanding ;    /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3875     }
3876
3877 /*
3878     if ( tempax & LCDBToA )
3879     {
3880         tempbx |= SetLCDBToA ;
3881     }
3882 */
3883
3884     if ( pVBInfo->IF_DEF_ExpLink == 1 )
3885     {
3886         if ( modeflag & HalfDCLK )
3887         {
3888             /* if ( !( pVBInfo->LCDInfo&LCDNonExpanding ) ) */
3889             if ( !( tempbx & SetLCDtoNonExpanding ) )
3890             {
3891                 tempbx |= EnableLVDSDDA ;
3892             }
3893             else
3894             {
3895                 if ( ModeNo > 0x13 )
3896                 {
3897                     if ( pVBInfo->LCDResInfo == Panel1024x768 )
3898                     {
3899                         if ( resinfo == 4 )
3900                         {                                /* 512x384  */
3901                             tempbx |= EnableLVDSDDA ;
3902                         }
3903                     }
3904                 }
3905             }
3906         }
3907     }
3908
3909     if ( pVBInfo->VBInfo & SetInSlaveMode )
3910     {
3911         if ( pVBInfo->VBInfo & SetNotSimuMode )
3912         {
3913             tempbx |= LCDVESATiming ;
3914         }
3915     }
3916     else
3917     {
3918         tempbx |= LCDVESATiming ;
3919     }
3920
3921     pVBInfo->LCDInfo = tempbx ;
3922
3923     if ( pVBInfo->IF_DEF_PWD == 1 )
3924     {
3925         if ( pVBInfo->LCDInfo & SetPWDEnable )
3926         {
3927             if ( ( pVBInfo->VBType & VB_XGI302LV ) || ( pVBInfo->VBType & VB_XGI301C ) )
3928             {
3929                 if ( !( tempax & PWDEnable ) )
3930                 {
3931                     pVBInfo->LCDInfo &= ~SetPWDEnable ;
3932                 }
3933             }
3934         }
3935     }
3936
3937     if ( pVBInfo->IF_DEF_LVDS == 0 )
3938     {
3939         if ( tempax & ( LockLCDBToA | StLCDBToA ) )
3940         {
3941             if ( pVBInfo->VBInfo & SetInSlaveMode )
3942             {
3943                 if ( !( tempax & LockLCDBToA ) )
3944                 {
3945                     if ( ModeNo <= 0x13 )
3946                     {
3947                         pVBInfo->VBInfo &= ~( SetSimuScanMode | SetInSlaveMode | SetCRT2ToLCD ) ;
3948                         pVBInfo->VBInfo |= SetCRT2ToLCDA | SetCRT2ToDualEdge ;
3949                     }
3950                 }
3951             }
3952         }
3953     }
3954
3955 /*
3956     if ( pVBInfo->IF_DEF_LVDS == 0 )
3957     {
3958         if ( tempax & ( LockLCDBToA | StLCDBToA ) )
3959         {
3960             if ( pVBInfo->VBInfo & SetInSlaveMode )
3961             {
3962                 if ( !( ( !( tempax & LockLCDBToA ) ) && ( ModeNo > 0x13 ) ) )
3963                 {
3964                     pVBInfo->VBInfo&=~(SetSimuScanMode|SetInSlaveMode|SetCRT2ToLCD);
3965                     pVBInfo->VBInfo|=SetCRT2ToLCDA|SetCRT2ToDualEdge;
3966                 }
3967             }
3968         }
3969     }
3970 */
3971
3972     return( 1 ) ;
3973 }
3974
3975
3976 /* --------------------------------------------------------------------- */
3977 /* Function : XGI_SearchModeID */
3978 /* Input : */
3979 /* Output : */
3980 /* Description : */
3981 /* --------------------------------------------------------------------- */
3982 BOOLEAN XGI_SearchModeID( USHORT ModeNo , USHORT *ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
3983 {
3984
3985
3986
3987 #ifdef LINUX /* chiawen for linux solution */
3988
3989     if ( ModeNo <= 5 )
3990         ModeNo |= 1 ;
3991     if ( ModeNo <= 0x13 )
3992     {
3993         /* for (*ModeIdIndex=0;*ModeIdIndex<sizeof(pVBInfo->SModeIDTable)/sizeof(XGI_StStruct);(*ModeIdIndex)++) */
3994         for( *ModeIdIndex = 0 ; ; ( *ModeIdIndex )++ )
3995         {
3996             if ( pVBInfo->SModeIDTable[ *ModeIdIndex ].St_ModeID == ModeNo )
3997                 break ;
3998             if ( pVBInfo->SModeIDTable[ *ModeIdIndex ].St_ModeID == 0xFF )
3999                 return( FALSE ) ;
4000         }
4001
4002         if ( ModeNo == 0x07 )
4003             ( *ModeIdIndex )++ ; /* 400 lines */
4004
4005         if ( ModeNo <= 3 )
4006             ( *ModeIdIndex ) += 2 ; /* 400 lines */
4007         /* else 350 lines */
4008     }
4009     else
4010     {
4011         /* for (*ModeIdIndex=0;*ModeIdIndex<sizeof(pVBInfo->EModeIDTable)/sizeof(XGI_ExtStruct);(*ModeIdIndex)++) */
4012         for( *ModeIdIndex = 0 ; ; ( *ModeIdIndex )++ )
4013         {
4014             if ( pVBInfo->EModeIDTable[ *ModeIdIndex ].Ext_ModeID == ModeNo )
4015                 break ;
4016             if ( pVBInfo->EModeIDTable[ *ModeIdIndex ].Ext_ModeID == 0xFF )
4017                 return( FALSE ) ;
4018         }
4019     }
4020
4021 #endif
4022
4023     return( TRUE ) ;
4024 }
4025
4026
4027
4028
4029 /* win2000 MM adapter not support standard mode! */
4030
4031 /* --------------------------------------------------------------------- */
4032 /* Function : */
4033 /* Input : */
4034 /* Output : */
4035 /* Description : */
4036 /* --------------------------------------------------------------------- */
4037 BOOLEAN XGINew_CheckMemorySize(PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo,USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo)
4038 {
4039     USHORT memorysize ,
4040            modeflag ,
4041            temp ,
4042            temp1 ,
4043            tmp ;
4044
4045 /*  if ( ( HwDeviceExtension->jChipType == XGI_650 ) ||
4046          ( HwDeviceExtension->jChipType == XGI_650M ) )
4047     {
4048         return( TRUE ) ;
4049     } */
4050
4051     if ( ModeNo <= 0x13 )
4052     {
4053         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
4054     }
4055     else  {
4056         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
4057     }
4058
4059     /* ModeType = modeflag&ModeInfoFlag ; // Get mode type */
4060
4061     memorysize = modeflag & MemoryInfoFlag ;
4062     memorysize = memorysize > MemorySizeShift ;
4063     memorysize++ ;                                      /* Get memory size */
4064
4065     temp = XGINew_GetReg1( pVBInfo->P3c4 , 0x14 ) ;     /* Get DRAM Size */
4066     tmp = temp ;
4067
4068     if ( HwDeviceExtension->jChipType == XG40 )
4069     {
4070         temp = 1 << ( ( temp & 0x0F0 ) >> 4 ) ;         /* memory size per channel SR14[7:4] */
4071         if ( ( tmp & 0x0c ) == 0x0C )                   /* Qual channels */
4072         {
4073             temp <<= 2 ;
4074         }
4075         else if ( ( tmp & 0x0c ) == 0x08 )              /* Dual channels */
4076         {
4077             temp <<= 1 ;
4078         }
4079     }
4080     else if ( HwDeviceExtension->jChipType == XG42 )
4081     {
4082         temp = 1 << ( ( temp & 0x0F0 ) >> 4 ) ;         /* memory size per channel SR14[7:4] */
4083         if ( ( tmp & 0x04 ) == 0x04 )                   /* Dual channels */
4084         {
4085             temp <<= 1 ;
4086         }
4087     }
4088     else if ( HwDeviceExtension->jChipType == XG45 )
4089     {
4090         temp = 1 << ( ( temp & 0x0F0 ) >> 4 ) ;         /* memory size per channel SR14[7:4] */
4091         if ( ( tmp & 0x0c ) == 0x0C )                   /* Qual channels */
4092         {
4093             temp <<= 2 ;
4094         }
4095         else if ( ( tmp & 0x0c ) == 0x08 )              /* triple channels */
4096         {
4097             temp1 = temp ;
4098             temp <<= 1 ;
4099             temp += temp1 ;
4100         }
4101         else if ( ( tmp & 0x0c ) == 0x04 )              /* Dual channels */
4102         {
4103             temp <<= 1 ;
4104         }
4105     }
4106     if ( temp < memorysize )
4107         return( FALSE ) ;
4108     else
4109         return( TRUE ) ;
4110 }
4111
4112
4113 /* --------------------------------------------------------------------- */
4114 /* Function : XGINew_IsLowResolution */
4115 /* Input : */
4116 /* Output : */
4117 /* Description : */
4118 /* --------------------------------------------------------------------- */
4119 /*void XGINew_IsLowResolution( USHORT ModeNo , USHORT ModeIdIndex, BOOLEAN XGINew_CheckMemorySize(PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo,USHORT ModeIdIndex,PVB_DEVICE_INFO pVBInfo)
4120 {
4121     USHORT data ;
4122     USHORT ModeFlag ;
4123
4124     data = XGINew_GetReg1( pVBInfo->P3c4 , 0x0F ) ;
4125     data &= 0x7F ;
4126     XGINew_SetReg1( pVBInfo->P3c4 , 0x0F , data ) ;
4127
4128     if ( ModeNo > 0x13 )
4129     {
4130         ModeFlag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
4131         if ( ( ModeFlag & HalfDCLK ) && ( ModeFlag & DoubleScanMode ) )
4132         {
4133             data = XGINew_GetReg1( pVBInfo->P3c4 , 0x0F ) ;
4134             data |= 0x80 ;
4135             XGINew_SetReg1( pVBInfo->P3c4 , 0x0F , data ) ;
4136             data = XGINew_GetReg1( pVBInfo->P3c4 , 0x01 ) ;
4137             data &= 0xF7 ;
4138             XGINew_SetReg1( pVBInfo->P3c4 , 0x01 , data ) ;
4139         }
4140     }
4141 }
4142
4143 */
4144
4145 /* --------------------------------------------------------------------- */
4146 /* Function : XGI_DisplayOn */
4147 /* Input : */
4148 /* Output : */
4149 /* Description : */
4150 /* --------------------------------------------------------------------- */
4151 void XGI_DisplayOn( PXGI_HW_DEVICE_INFO pXGIHWDE , PVB_DEVICE_INFO pVBInfo )
4152 {
4153
4154     XGINew_SetRegANDOR(pVBInfo->P3c4,0x01,0xDF,0x00);
4155     if ( pXGIHWDE->jChipType == XG21 )
4156     {
4157        if ( pVBInfo->IF_DEF_LVDS == 1 )
4158        {
4159          if (!(XGI_XG21GetPSCValue( pVBInfo )&0x1))
4160          {
4161             XGI_XG21BLSignalVDD( 0x01 , 0x01, pVBInfo ) ; /* LVDS VDD on */
4162             XGI_XG21SetPanelDelay( 2,pVBInfo ) ;
4163          }
4164          if (!(XGI_XG21GetPSCValue( pVBInfo )&0x20))
4165          {
4166             XGI_XG21BLSignalVDD( 0x20 , 0x20, pVBInfo ) ; /* LVDS signal on */
4167          }
4168          XGI_XG21SetPanelDelay( 3,pVBInfo ) ;
4169          XGI_XG21BLSignalVDD( 0x02 , 0x02, pVBInfo ) ; /* LVDS backlight on */
4170        }
4171        else
4172        {
4173             XGI_XG21BLSignalVDD( 0x20 , 0x20, pVBInfo ) ; /* DVO/DVI signal on */
4174        }
4175
4176     }
4177
4178     if (pVBInfo->IF_DEF_CH7007 == 1) /* [Billy] 07/05/23 For CH7007 */
4179     {
4180
4181     }
4182
4183
4184     if ( pXGIHWDE->jChipType == XG27 )
4185     {
4186        if ( pVBInfo->IF_DEF_LVDS == 1 )
4187        {
4188          if (!(XGI_XG27GetPSCValue( pVBInfo )&0x1))
4189          {
4190             XGI_XG27BLSignalVDD( 0x01 , 0x01, pVBInfo ) ; /* LVDS VDD on */
4191             XGI_XG21SetPanelDelay( 2,pVBInfo ) ;
4192          }
4193          if (!(XGI_XG27GetPSCValue( pVBInfo )&0x20))
4194          {
4195             XGI_XG27BLSignalVDD( 0x20 , 0x20, pVBInfo ) ; /* LVDS signal on */
4196          }
4197          XGI_XG21SetPanelDelay( 3,pVBInfo ) ;
4198          XGI_XG27BLSignalVDD( 0x02 , 0x02, pVBInfo ) ; /* LVDS backlight on */
4199        }
4200        else
4201        {
4202             XGI_XG27BLSignalVDD( 0x20 , 0x20, pVBInfo ) ; /* DVO/DVI signal on */
4203        }
4204
4205     }
4206 }
4207
4208
4209 /* --------------------------------------------------------------------- */
4210 /* Function : XGI_DisplayOff */
4211 /* Input : */
4212 /* Output : */
4213 /* Description : */
4214 /* --------------------------------------------------------------------- */
4215 void XGI_DisplayOff( PXGI_HW_DEVICE_INFO pXGIHWDE , PVB_DEVICE_INFO pVBInfo )
4216 {
4217
4218     if ( pXGIHWDE->jChipType == XG21 )
4219     {
4220        if ( pVBInfo->IF_DEF_LVDS == 1 )
4221        {
4222          XGI_XG21BLSignalVDD( 0x02 , 0x00, pVBInfo ) ; /* LVDS backlight off */
4223          XGI_XG21SetPanelDelay( 3,pVBInfo ) ;
4224        }
4225        else
4226        {
4227             XGI_XG21BLSignalVDD( 0x20 , 0x00, pVBInfo ) ; /* DVO/DVI signal off */
4228        }
4229     }
4230
4231     if (pVBInfo->IF_DEF_CH7007 == 1) /*[Billy] 07/05/23 For CH7007 */
4232     {
4233        /* if( IsCH7007TVMode( pVBInfo ) == 0 ) */
4234        {
4235        }
4236     }
4237
4238
4239     if ( pXGIHWDE->jChipType == XG27 )
4240     {
4241        if ((XGI_XG27GetPSCValue( pVBInfo )&0x2))
4242        {
4243          XGI_XG27BLSignalVDD( 0x02 , 0x00, pVBInfo ) ; /* LVDS backlight off */
4244          XGI_XG21SetPanelDelay( 3,pVBInfo ) ;
4245        }
4246
4247        if ( pVBInfo->IF_DEF_LVDS == 0 )
4248        {
4249             XGI_XG27BLSignalVDD( 0x20 , 0x00, pVBInfo ) ; /* DVO/DVI signal off */
4250        }
4251     }
4252
4253     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x01 , 0xDF , 0x20 ) ;
4254 }
4255
4256
4257 /* --------------------------------------------------------------------- */
4258 /* Function : XGI_WaitDisply */
4259 /* Input : */
4260 /* Output : */
4261 /* Description : chiawen for sensecrt1 */
4262 /* --------------------------------------------------------------------- */
4263 void XGI_WaitDisply( PVB_DEVICE_INFO pVBInfo )
4264 {
4265     while( ( XGINew_GetReg2( pVBInfo->P3da ) & 0x01 ) )
4266         break ;
4267
4268     while( !( XGINew_GetReg2( pVBInfo->P3da ) & 0x01 ) )
4269         break ;
4270 }
4271
4272 /* --------------------------------------------------------------------- */
4273 /* Function : XGI_SenseCRT1 */
4274 /* Input : */
4275 /* Output : */
4276 /* Description : */
4277 /* --------------------------------------------------------------------- */
4278
4279 void XGI_SenseCRT1( PVB_DEVICE_INFO pVBInfo )
4280 {
4281     UCHAR CRTCData[ 17 ] = { 0x5F , 0x4F , 0x50 , 0x82 , 0x55 , 0x81 ,
4282                              0x0B , 0x3E , 0xE9 , 0x0B , 0xDF , 0xE7 ,
4283                              0x04 , 0x00 , 0x00 , 0x05 , 0x00 } ;
4284
4285     UCHAR SR01 = 0 , SR1F = 0 , SR07 = 0 , SR06 = 0 ;
4286
4287     UCHAR CR17 , CR63 , SR31 ;
4288     USHORT temp ;
4289     UCHAR DAC_TEST_PARMS[ 3 ] = { 0x0F , 0x0F , 0x0F } ;
4290
4291     int i ;
4292     XGINew_SetReg1( pVBInfo->P3c4 , 0x05 , 0x86 ) ;
4293
4294     /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
4295     XGINew_SetReg1( pVBInfo->P3d4 , 0x57 , 0x4A ) ;
4296     XGINew_SetReg1( pVBInfo->P3d4 , 0x53 , ( UCHAR )( XGINew_GetReg1( pVBInfo->P3d4 , 0x53 ) | 0x02 ) ) ;
4297
4298     SR31 = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x31 ) ;
4299     CR63 = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x63 ) ;
4300     SR01 = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x01 ) ;
4301
4302     XGINew_SetReg1( pVBInfo->P3c4 , 0x01 , ( UCHAR )( SR01 & 0xDF ) ) ;
4303     XGINew_SetReg1( pVBInfo->P3d4 , 0x63 , ( UCHAR )( CR63 & 0xBF ) ) ;
4304
4305     CR17 = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x17 ) ;
4306     XGINew_SetReg1( pVBInfo->P3d4 , 0x17 , ( UCHAR )( CR17 | 0x80 ) ) ;
4307
4308     SR1F = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x1F ) ;
4309     XGINew_SetReg1( pVBInfo->P3c4 , 0x1F , ( UCHAR )( SR1F | 0x04 ) ) ;
4310
4311     SR07 = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x07 ) ;
4312     XGINew_SetReg1( pVBInfo->P3c4 , 0x07 , ( UCHAR )( SR07 & 0xFB ) ) ;
4313     SR06 = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x06 ) ;
4314     XGINew_SetReg1( pVBInfo->P3c4 , 0x06 , ( UCHAR )( SR06 & 0xC3 ) ) ;
4315
4316     XGINew_SetReg1( pVBInfo->P3d4 , 0x11 , 0x00 ) ;
4317
4318     for( i = 0 ; i < 8 ; i++ )
4319         XGINew_SetReg1( pVBInfo->P3d4 , ( USHORT )i , CRTCData[ i ] ) ;
4320
4321     for( i = 8 ; i < 11 ; i++ )
4322         XGINew_SetReg1( pVBInfo->P3d4 , ( USHORT )( i + 8 ) , CRTCData[ i ] ) ;
4323
4324     for( i = 11 ; i < 13 ; i++ )
4325         XGINew_SetReg1( pVBInfo->P3d4 , ( USHORT )( i + 4 ) , CRTCData[ i ] ) ;
4326
4327     for( i = 13 ; i < 16 ; i++ )
4328         XGINew_SetReg1( pVBInfo->P3c4 , ( USHORT )( i - 3 ) , CRTCData[ i ] ) ;
4329
4330     XGINew_SetReg1( pVBInfo->P3c4 , 0x0E , ( UCHAR )( CRTCData[ 16 ] & 0xE0 ) ) ;
4331
4332     XGINew_SetReg1( pVBInfo->P3c4 , 0x31 , 0x00 ) ;
4333     XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , 0x1B ) ;
4334     XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , 0xE1 ) ;
4335
4336     XGINew_SetReg3( pVBInfo->P3c8 , 0x00 ) ;
4337
4338     for( i = 0 ; i < 256 ; i++ )
4339     {
4340         XGINew_SetReg3( ( pVBInfo->P3c8 + 1 ) , ( UCHAR )DAC_TEST_PARMS[ 0 ] ) ;
4341         XGINew_SetReg3( ( pVBInfo->P3c8 + 1 ) , ( UCHAR )DAC_TEST_PARMS[ 1 ] ) ;
4342         XGINew_SetReg3( ( pVBInfo->P3c8 + 1 ) , ( UCHAR )DAC_TEST_PARMS[ 2 ] ) ;
4343     }
4344
4345     XGI_VBLongWait( pVBInfo ) ;
4346     XGI_VBLongWait( pVBInfo ) ;
4347     XGI_VBLongWait( pVBInfo ) ;
4348
4349     XGINew_LCD_Wait_Time( 0x01 , pVBInfo ) ;
4350
4351     XGI_WaitDisply( pVBInfo ) ;
4352     temp = XGINew_GetReg2( pVBInfo->P3c2 ) ;
4353
4354     if( temp & 0x10 )
4355     {
4356         XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x32 , 0xDF , 0x20 ) ;
4357     }
4358     else
4359     {
4360         XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x32 , 0xDF , 0x00 ) ;
4361     }
4362
4363     /* alan, avoid display something, set BLACK DAC if not restore DAC */
4364     XGINew_SetReg3( pVBInfo->P3c8 , 0x00 ) ;
4365
4366     for( i = 0 ; i < 256 ; i++ )
4367     {
4368       XGINew_SetReg3( ( pVBInfo->P3c8 + 1 ) , 0 ) ;
4369       XGINew_SetReg3( ( pVBInfo->P3c8 + 1 ) , 0 ) ;
4370       XGINew_SetReg3( ( pVBInfo->P3c8 + 1 ) , 0 ) ;
4371     }
4372
4373     XGINew_SetReg1( pVBInfo->P3c4 , 0x01 , SR01 ) ;
4374     XGINew_SetReg1( pVBInfo->P3d4 , 0x63 , CR63 ) ;
4375     XGINew_SetReg1( pVBInfo->P3c4 , 0x31 , SR31 ) ;
4376
4377     /* [2004/05/11] Vicent */
4378     XGINew_SetReg1( pVBInfo->P3d4 , 0x53 , ( UCHAR )( XGINew_GetReg1( pVBInfo->P3d4 , 0x53 ) & 0xFD ) ) ;
4379     XGINew_SetReg1( pVBInfo->P3c4 , 0x1F , ( UCHAR ) SR1F ) ;
4380 }
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391 /* --------------------------------------------------------------------- */
4392 /* Function : XGI_WaitDisplay */
4393 /* Input : */
4394 /* Output : */
4395 /* Description : */
4396 /* --------------------------------------------------------------------- */
4397 void XGI_WaitDisplay( PVB_DEVICE_INFO pVBInfo )
4398 {
4399     while( !( XGINew_GetReg2( pVBInfo->P3da ) & 0x01 ) ) ;
4400
4401     while( XGINew_GetReg2( pVBInfo->P3da ) & 0x01 ) ;
4402 }
4403
4404
4405
4406
4407 /* --------------------------------------------------------------------- */
4408 /* Function : XGI_SetCRT2Group301 */
4409 /* Input : */
4410 /* Output : */
4411 /* Description : */
4412 /* --------------------------------------------------------------------- */
4413 BOOLEAN XGI_SetCRT2Group301( USHORT ModeNo , PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo )
4414 {
4415     USHORT tempbx ,
4416            ModeIdIndex ,
4417            RefreshRateTableIndex ;
4418
4419     tempbx=pVBInfo->VBInfo ;
4420     pVBInfo->SetFlag |= ProgrammingCRT2 ;
4421     XGI_SearchModeID( ModeNo , &ModeIdIndex,  pVBInfo ) ;
4422     pVBInfo->SelectCRT2Rate = 4 ;
4423     RefreshRateTableIndex = XGI_GetRatePtrCRT2( HwDeviceExtension, ModeNo , ModeIdIndex, pVBInfo ) ;
4424     XGI_SaveCRT2Info( ModeNo, pVBInfo ) ;
4425     XGI_GetCRT2ResInfo( ModeNo , ModeIdIndex, pVBInfo) ;
4426     XGI_GetCRT2Data( ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
4427     XGI_PreSetGroup1( ModeNo , ModeIdIndex , HwDeviceExtension , RefreshRateTableIndex, pVBInfo ) ;
4428     XGI_SetGroup1( ModeNo , ModeIdIndex , HwDeviceExtension , RefreshRateTableIndex, pVBInfo ) ;
4429     XGI_SetLockRegs( ModeNo , ModeIdIndex , HwDeviceExtension , RefreshRateTableIndex, pVBInfo ) ;
4430     XGI_SetGroup2(  ModeNo , ModeIdIndex , RefreshRateTableIndex , HwDeviceExtension, pVBInfo ) ;
4431     XGI_SetLCDRegs(ModeNo , ModeIdIndex , HwDeviceExtension , RefreshRateTableIndex, pVBInfo ) ;
4432     XGI_SetTap4Regs(pVBInfo) ;
4433     XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
4434     XGI_SetGroup4( ModeNo , ModeIdIndex , RefreshRateTableIndex , HwDeviceExtension, pVBInfo ) ;
4435     XGI_SetCRT2VCLK( ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
4436     XGI_SetGroup5( ModeNo , ModeIdIndex, pVBInfo) ;
4437     XGI_AutoThreshold( pVBInfo) ;
4438     return 1 ;
4439 }
4440
4441
4442 /* --------------------------------------------------------------------- */
4443 /* Function : XGI_AutoThreshold */
4444 /* Input : */
4445 /* Output : */
4446 /* Description : */
4447 /* --------------------------------------------------------------------- */
4448 void XGI_AutoThreshold(  PVB_DEVICE_INFO pVBInfo )
4449 {
4450     if ( !( pVBInfo->SetFlag & Win9xDOSMode ) )
4451       XGINew_SetRegOR( pVBInfo->Part1Port , 0x01 , 0x40 ) ;
4452 }
4453
4454
4455 /* --------------------------------------------------------------------- */
4456 /* Function : XGI_SaveCRT2Info */
4457 /* Input : */
4458 /* Output : */
4459 /* Description : */
4460 /* --------------------------------------------------------------------- */
4461 void XGI_SaveCRT2Info( USHORT ModeNo , PVB_DEVICE_INFO pVBInfo)
4462 {
4463     USHORT temp1 ,
4464            temp2 ;
4465
4466     XGINew_SetReg1( pVBInfo->P3d4 , 0x34 , ModeNo ) ;  /* reserve CR34 for CRT1 Mode No */
4467     temp1 = ( pVBInfo->VBInfo&SetInSlaveMode ) >> 8 ;
4468     temp2 = ~( SetInSlaveMode >> 8 ) ;
4469     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x31 , temp2 , temp1 ) ;
4470 }
4471
4472
4473 /* --------------------------------------------------------------------- */
4474 /* Function : XGI_GetCRT2ResInfo */
4475 /* Input : */
4476 /* Output : */
4477 /* Description : */
4478 /* --------------------------------------------------------------------- */
4479 void XGI_GetCRT2ResInfo( USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
4480 {
4481     USHORT xres ,
4482            yres ,
4483            modeflag ,
4484            resindex ;
4485
4486     resindex = XGI_GetResInfo( ModeNo , ModeIdIndex, pVBInfo) ;
4487     if ( ModeNo <= 0x13 )
4488     {
4489         xres = pVBInfo->StResInfo[ resindex ].HTotal ;
4490         yres = pVBInfo->StResInfo[ resindex ].VTotal ;
4491      /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; si+St_ResInfo */
4492     }
4493     else
4494     {
4495         xres = pVBInfo->ModeResInfo[ resindex ].HTotal ;                        /* xres->ax */
4496         yres = pVBInfo->ModeResInfo[ resindex ].VTotal ;                        /* yres->bx */
4497         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex].Ext_ModeFlag ;           /* si+St_ModeFlag */
4498
4499 /*        if ( pVBInfo->IF_DEF_FSTN )
4500         {
4501             xres *= 2 ;
4502             yres *= 2 ;
4503         }
4504         else
4505         {
4506 */
4507             if ( modeflag & HalfDCLK )
4508                 xres *= 2;
4509
4510             if ( modeflag & DoubleScanMode )
4511                 yres *= 2 ;
4512 /* } */
4513     }
4514
4515     if ( pVBInfo->VBInfo & SetCRT2ToLCD )
4516     {
4517         if ( pVBInfo->IF_DEF_LVDS == 0 )
4518         {
4519             if ( pVBInfo->LCDResInfo == Panel1600x1200 )
4520             {
4521                 if ( !( pVBInfo->LCDInfo & LCDVESATiming ) )
4522                 {
4523                     if ( yres == 1024 )
4524                         yres = 1056 ;
4525                 }
4526             }
4527
4528             if ( pVBInfo->LCDResInfo == Panel1280x1024 )
4529             {
4530                 if ( yres == 400 )
4531                     yres = 405 ;
4532                 else if ( yres == 350 )
4533                     yres = 360 ;
4534
4535                 if ( pVBInfo->LCDInfo & LCDVESATiming )
4536                 {
4537                     if ( yres == 360 )
4538                         yres = 375 ;
4539                 }
4540             }
4541
4542             if ( pVBInfo->LCDResInfo == Panel1024x768 )
4543             {
4544                 if ( !( pVBInfo->LCDInfo & LCDVESATiming ) )
4545                 {
4546                     if ( !( pVBInfo->LCDInfo & LCDNonExpanding ) )
4547                     {
4548                         if ( yres == 350 )
4549                             yres = 357 ;
4550                         else if ( yres == 400 )
4551                             yres = 420 ;
4552                         else if ( yres == 480 )
4553                             yres = 525 ;
4554                     }
4555                 }
4556             }
4557         }
4558
4559         if ( xres == 720 )
4560             xres = 640 ;
4561     }
4562
4563     pVBInfo->VGAHDE = xres ;
4564     pVBInfo->HDE = xres ;
4565     pVBInfo->VGAVDE = yres ;
4566     pVBInfo->VDE = yres ;
4567 }
4568
4569
4570 /* --------------------------------------------------------------------- */
4571 /* Function : XGI_IsLCDDualLink */
4572 /* Input : */
4573 /* Output : */
4574 /* Description : */
4575 /* --------------------------------------------------------------------- */
4576 BOOLEAN XGI_IsLCDDualLink( PVB_DEVICE_INFO pVBInfo )
4577 {
4578
4579     if ( ( ( ( pVBInfo->VBInfo & SetCRT2ToLCD ) | SetCRT2ToLCDA ) ) && ( pVBInfo->LCDInfo & SetLCDDualLink ) ) /* shampoo0129 */
4580         return ( 1 ) ;
4581
4582     return( 0 ) ;
4583 }
4584
4585
4586 /* --------------------------------------------------------------------- */
4587 /* Function : XGI_GetCRT2Data */
4588 /* Input : */
4589 /* Output : */
4590 /* Description : */
4591 /* --------------------------------------------------------------------- */
4592 void XGI_GetCRT2Data(  USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
4593 {
4594     USHORT tempax = 0,
4595            tempbx ,
4596            modeflag ,
4597            resinfo ;
4598
4599     XGI_LCDDataStruct *LCDPtr = NULL ;
4600     XGI_TVDataStruct  *TVPtr = NULL ;
4601
4602     if ( ModeNo <= 0x13 )
4603     {
4604         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;      /* si+St_ResInfo */
4605         resinfo = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ResInfo ;
4606     }
4607     else
4608     {
4609         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;     /* si+Ext_ResInfo */
4610         resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;
4611     }
4612
4613     pVBInfo->NewFlickerMode = 0 ;
4614     pVBInfo->RVBHRS = 50 ;
4615
4616     if ( pVBInfo->VBInfo & SetCRT2ToRAMDAC )
4617     {
4618         XGI_GetRAMDAC2DATA( ModeNo , ModeIdIndex , RefreshRateTableIndex,pVBInfo ) ;
4619         return ;
4620     }
4621
4622     tempbx = 4 ;
4623
4624     if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
4625     {
4626         LCDPtr = (XGI_LCDDataStruct* )XGI_GetLcdPtr( tempbx, ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
4627
4628         pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX ;
4629         pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT ;
4630         pVBInfo->VGAHT = LCDPtr->VGAHT ;
4631         pVBInfo->VGAVT = LCDPtr->VGAVT ;
4632         pVBInfo->HT = LCDPtr->LCDHT ;
4633         pVBInfo->VT = LCDPtr->LCDVT ;
4634
4635         if ( pVBInfo->LCDResInfo == Panel1024x768 )
4636         {
4637             tempax = 1024 ;
4638             tempbx = 768 ;
4639
4640             if ( !( pVBInfo->LCDInfo & LCDVESATiming ) )
4641             {
4642                 if ( pVBInfo->VGAVDE == 357 )
4643                     tempbx = 527 ;
4644                 else if ( pVBInfo->VGAVDE == 420 )
4645                     tempbx = 620 ;
4646                 else if ( pVBInfo->VGAVDE == 525 )
4647                     tempbx = 775 ;
4648                 else if ( pVBInfo->VGAVDE == 600 )
4649                     tempbx = 775 ;
4650                 /* else if(pVBInfo->VGAVDE==350) tempbx=560; */
4651                 /* else if(pVBInfo->VGAVDE==400) tempbx=640; */
4652                 else
4653                   tempbx = 768 ;
4654             }
4655             else
4656                 tempbx = 768 ;
4657         }
4658         else if ( pVBInfo->LCDResInfo == Panel1024x768x75 )
4659         {
4660             tempax = 1024 ;
4661             tempbx = 768 ;
4662         }
4663         else if ( pVBInfo->LCDResInfo == Panel1280x1024 )
4664         {
4665             tempax = 1280 ;
4666             if ( pVBInfo->VGAVDE == 360 )
4667                 tempbx = 768 ;
4668             else if ( pVBInfo->VGAVDE == 375 )
4669                 tempbx = 800 ;
4670             else if ( pVBInfo->VGAVDE == 405 )
4671                 tempbx = 864 ;
4672             else
4673                 tempbx = 1024 ;
4674         }
4675         else if ( pVBInfo->LCDResInfo == Panel1280x1024x75 )
4676         {
4677             tempax = 1280 ;
4678             tempbx = 1024 ;
4679         }
4680         else if ( pVBInfo->LCDResInfo == Panel1280x960 )
4681         {
4682             tempax = 1280 ;
4683             if ( pVBInfo->VGAVDE == 350 )
4684                 tempbx = 700 ;
4685             else if ( pVBInfo->VGAVDE == 400 )
4686                 tempbx = 800 ;
4687             else if ( pVBInfo->VGAVDE == 1024 )
4688                 tempbx = 960 ;
4689             else
4690                 tempbx = 960 ;
4691         }
4692         else if ( pVBInfo->LCDResInfo == Panel1400x1050 )
4693         {
4694             tempax = 1400 ;
4695             tempbx = 1050 ;
4696
4697             if ( pVBInfo->VGAVDE == 1024 )
4698             {
4699                 tempax = 1280 ;
4700                 tempbx = 1024 ;
4701             }
4702         }
4703         else if ( pVBInfo->LCDResInfo == Panel1600x1200 )
4704         {
4705             tempax = 1600 ;
4706             tempbx = 1200 ;  /* alan 10/14/2003 */
4707             if ( !( pVBInfo->LCDInfo & LCDVESATiming ) )
4708             {
4709               if ( pVBInfo->VGAVDE == 350 )
4710                 tempbx = 875 ;
4711               else if ( pVBInfo->VGAVDE == 400 )
4712                 tempbx = 1000 ;
4713             }
4714         }
4715
4716         if ( pVBInfo->LCDInfo & LCDNonExpanding )
4717         {
4718             tempax = pVBInfo->VGAHDE ;
4719             tempbx = pVBInfo->VGAVDE ;
4720         }
4721
4722         pVBInfo->HDE = tempax ;
4723         pVBInfo->VDE = tempbx ;
4724         return ;
4725     }
4726
4727     if ( pVBInfo->VBInfo & ( SetCRT2ToTV ) )
4728     {
4729         tempbx = 4 ;
4730         TVPtr = ( XGI_TVDataStruct * )XGI_GetTVPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
4731
4732         pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX ;
4733         pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT ;
4734         pVBInfo->VGAHT = TVPtr->VGAHT ;
4735         pVBInfo->VGAVT = TVPtr->VGAVT ;
4736         pVBInfo->HDE = TVPtr->TVHDE ;
4737         pVBInfo->VDE = TVPtr->TVVDE ;
4738         pVBInfo->RVBHRS = TVPtr->RVBHRS ;
4739         pVBInfo->NewFlickerMode = TVPtr->FlickerMode ;
4740
4741         if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
4742         {
4743             if ( resinfo == 0x08 )
4744                 pVBInfo->NewFlickerMode = 0x40 ;
4745             else if ( resinfo == 0x09 )
4746                 pVBInfo->NewFlickerMode = 0x40 ;
4747             else if ( resinfo == 0x12 )
4748                 pVBInfo->NewFlickerMode = 0x40 ;
4749
4750             if ( pVBInfo->VGAVDE == 350 )
4751                 pVBInfo->TVInfo |= TVSimuMode ;
4752
4753             tempax = ExtHiTVHT ;
4754             tempbx = ExtHiTVVT ;
4755
4756             if ( pVBInfo->VBInfo & SetInSlaveMode )
4757             {
4758                 if ( pVBInfo->TVInfo & TVSimuMode )
4759                 {
4760                     tempax = StHiTVHT ;
4761                     tempbx = StHiTVVT ;
4762
4763                     if ( !( modeflag & Charx8Dot ) )
4764                     {
4765                         tempax = StHiTextTVHT ;
4766                         tempbx = StHiTextTVVT ;
4767                     }
4768                 }
4769             }
4770         }
4771         else if ( pVBInfo->VBInfo & SetCRT2ToYPbPr )
4772         {
4773             if ( pVBInfo->TVInfo & SetYPbPrMode750p )
4774             {
4775                 tempax = YPbPrTV750pHT ;        /* Ext750pTVHT */
4776                 tempbx = YPbPrTV750pVT ;        /* Ext750pTVVT */
4777             }
4778
4779             if ( pVBInfo->TVInfo & SetYPbPrMode525p )
4780             {
4781                 tempax = YPbPrTV525pHT ;        /* Ext525pTVHT */
4782                 tempbx = YPbPrTV525pVT ;        /* Ext525pTVVT */
4783             }
4784             else if ( pVBInfo->TVInfo & SetYPbPrMode525i )
4785             {
4786                 tempax = YPbPrTV525iHT ;        /* Ext525iTVHT */
4787                 tempbx = YPbPrTV525iVT ;        /* Ext525iTVVT */
4788                 if ( pVBInfo->TVInfo & NTSC1024x768 )
4789                     tempax = NTSC1024x768HT ;
4790             }
4791         }
4792         else
4793         {
4794             tempax = PALHT ;
4795             tempbx = PALVT ;
4796             if ( !( pVBInfo->TVInfo & SetPALTV ) )
4797             {
4798                 tempax = NTSCHT ;
4799                 tempbx = NTSCVT ;
4800                 if ( pVBInfo->TVInfo & NTSC1024x768 )
4801                     tempax = NTSC1024x768HT ;
4802             }
4803         }
4804
4805         pVBInfo->HT = tempax ;
4806         pVBInfo->VT = tempbx ;
4807         return ;
4808     }
4809 }
4810
4811
4812 /* --------------------------------------------------------------------- */
4813 /* Function : XGI_SetCRT2VCLK */
4814 /* Input : */
4815 /* Output : */
4816 /* Description : */
4817 /* --------------------------------------------------------------------- */
4818 void XGI_SetCRT2VCLK( USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
4819 {
4820     UCHAR di_0 ,
4821           di_1 ,
4822           tempal ;
4823
4824     tempal = XGI_GetVCLKPtr( RefreshRateTableIndex , ModeNo , ModeIdIndex, pVBInfo ) ;
4825     XGI_GetVCLKLen( tempal, &di_0 , &di_1, pVBInfo ) ;
4826     XGI_GetLCDVCLKPtr( &di_0 , &di_1, pVBInfo ) ;
4827
4828     if ( pVBInfo->VBType & VB_XGI301 ) /* shampoo 0129 */
4829     {                           /* 301 */
4830         XGINew_SetReg1(pVBInfo->Part4Port , 0x0A , 0x10 ) ;
4831         XGINew_SetReg1(pVBInfo->Part4Port , 0x0B , di_1 ) ;
4832         XGINew_SetReg1(pVBInfo->Part4Port , 0x0A , di_0 ) ;
4833     }
4834     else
4835     {                           /* 301b/302b/301lv/302lv */
4836         XGINew_SetReg1( pVBInfo->Part4Port , 0x0A , di_0 ) ;
4837         XGINew_SetReg1( pVBInfo->Part4Port , 0x0B , di_1 ) ;
4838     }
4839
4840     XGINew_SetReg1( pVBInfo->Part4Port , 0x00 , 0x12 ) ;
4841
4842     if ( pVBInfo->VBInfo & SetCRT2ToRAMDAC )
4843         XGINew_SetRegOR( pVBInfo->Part4Port , 0x12 , 0x28 ) ;
4844     else
4845         XGINew_SetRegOR( pVBInfo->Part4Port , 0x12 , 0x08 ) ;
4846 }
4847
4848
4849 /* --------------------------------------------------------------------- */
4850 /* Function : XGI_GETLCDVCLKPtr */
4851 /* Input : */
4852 /* Output : al -> VCLK Index */
4853 /* Description : */
4854 /* --------------------------------------------------------------------- */
4855 void XGI_GetLCDVCLKPtr( UCHAR* di_0 , UCHAR *di_1, PVB_DEVICE_INFO pVBInfo )
4856 {
4857     USHORT index ;
4858
4859     if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
4860     {
4861         if ( pVBInfo->IF_DEF_ScaleLCD == 1 )
4862         {
4863             if ( pVBInfo->LCDInfo & EnableScalingLCD )
4864                 return ;
4865         }
4866
4867         /* index = XGI_GetLCDCapPtr(pVBInfo) ; */
4868         index = XGI_GetLCDCapPtr1( pVBInfo) ;
4869
4870         if ( pVBInfo->VBInfo & SetCRT2ToLCD )
4871         {       /* LCDB */
4872             *di_0 = pVBInfo->LCDCapList[ index ].LCUCHAR_VCLKData1 ;
4873             *di_1 = pVBInfo->LCDCapList[ index ].LCUCHAR_VCLKData2 ;
4874         }
4875         else
4876         {       /* LCDA */
4877             *di_0 = pVBInfo->LCDCapList[ index ].LCDA_VCLKData1 ;
4878             *di_1 = pVBInfo->LCDCapList[ index ].LCDA_VCLKData2 ;
4879         }
4880     }
4881     return ;
4882 }
4883
4884
4885 /* --------------------------------------------------------------------- */
4886 /* Function : XGI_GetVCLKPtr */
4887 /* Input : */
4888 /* Output : */
4889 /* Description : */
4890 /* --------------------------------------------------------------------- */
4891 UCHAR XGI_GetVCLKPtr(USHORT RefreshRateTableIndex,USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo)
4892 {
4893
4894     USHORT index ,
4895            modeflag ;
4896     USHORT tempbx ;
4897     UCHAR tempal ;
4898     UCHAR *CHTVVCLKPtr = NULL ;
4899
4900     if ( ModeNo <= 0x13 )
4901         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;      /* si+St_ResInfo */
4902     else
4903         modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;    /* si+Ext_ResInfo */
4904
4905
4906     if ( ( pVBInfo->SetFlag & ProgrammingCRT2 ) && ( !( pVBInfo->LCDInfo & EnableScalingLCD ) ) )
4907     {   /* {LCDA/LCDB} */
4908         index = XGI_GetLCDCapPtr(pVBInfo) ;
4909         tempal = pVBInfo->LCDCapList[ index ].LCD_VCLK ;
4910
4911         if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
4912             return tempal ;
4913
4914         /* {TV} */
4915         if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV| VB_XGI302LV| VB_XGI301C ) )
4916         {
4917             if(pVBInfo->VBInfo&SetCRT2ToHiVisionTV)
4918            {
4919                 tempal = HiTVVCLKDIV2;
4920                 if(!(pVBInfo->TVInfo & RPLLDIV2XO))
4921                     tempal = HiTVVCLK;
4922                 if(pVBInfo->TVInfo & TVSimuMode)
4923                 {
4924                     tempal = HiTVSimuVCLK;
4925                     if(!(modeflag & Charx8Dot))
4926                         tempal = HiTVTextVCLK;
4927
4928                  }
4929                  return tempal;
4930              }
4931
4932             if ( pVBInfo->TVInfo & SetYPbPrMode750p )
4933             {
4934                 tempal = YPbPr750pVCLK ;
4935                 return tempal ;
4936             }
4937
4938             if ( pVBInfo->TVInfo & SetYPbPrMode525p )
4939             {
4940                 tempal = YPbPr525pVCLK ;
4941                 return tempal ;
4942             }
4943
4944             tempal = NTSC1024VCLK ;
4945
4946             if ( !( pVBInfo->TVInfo & NTSC1024x768 ) )
4947             {
4948                 tempal = TVVCLKDIV2 ;
4949                 if ( !( pVBInfo->TVInfo & RPLLDIV2XO ) )
4950                     tempal = TVVCLK ;
4951             }
4952
4953             if ( pVBInfo->VBInfo & SetCRT2ToTV )
4954                 return tempal ;
4955         }
4956         /*else
4957         if((pVBInfo->IF_DEF_CH7017==1)&&(pVBInfo->VBType&VB_CH7017))
4958         {
4959             if(ModeNo<=0x13)
4960                 *tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4961             else
4962                 *tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
4963             *tempal = *tempal & 0x1F;
4964
4965             tempbx = 0;
4966             if(pVBInfo->TVInfo & SetPALTV)
4967                 tempbx = tempbx + 2;
4968             if(pVBInfo->TVInfo & SetCHTVOverScan)
4969                 tempbx++;
4970             tempbx = tempbx << 1;
4971         }  */
4972     }   /* {End of VB} */
4973
4974     if((pVBInfo->IF_DEF_CH7007==1)&&(pVBInfo->VBType&VB_CH7007)) /* [Billy] 07/05/08 CH7007 */
4975     {
4976        /* VideoDebugPrint((0, "XGI_GetVCLKPtr: pVBInfo->IF_DEF_CH7007==1\n")); */
4977        if ( (pVBInfo->VBInfo & SetCRT2ToTV) )
4978        {
4979            if( ModeNo <= 0x13 )
4980            {
4981               tempal = pVBInfo->SModeIDTable[ ModeIdIndex ].St_CRT2CRTC ;
4982            }
4983            else
4984            {
4985               tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
4986            }
4987
4988            tempal = tempal & 0x0F;
4989            tempbx = 0;
4990
4991            if(pVBInfo->TVInfo & SetPALTV)
4992            {
4993               tempbx = tempbx + 2;
4994            }
4995            if(pVBInfo->TVInfo & SetCHTVOverScan)
4996            {
4997               tempbx++;
4998            }
4999            /** tempbx = tempbx << 1; CH7007 ? **/
5000
5001 /*[Billy]07/05/29 CH7007*/
5002            if ( pVBInfo->IF_DEF_CH7007 == 1 )
5003            {
5004              switch( tempbx )
5005              {
5006                case 0:
5007                    CHTVVCLKPtr = XGI7007_CHTVVCLKUNTSC ;
5008                    break ;
5009                case 1:
5010                    CHTVVCLKPtr = XGI7007_CHTVVCLKONTSC ;
5011                    break ;
5012                case 2:
5013                    CHTVVCLKPtr = XGI7007_CHTVVCLKUPAL ;
5014                    break ;
5015                case 3:
5016                    CHTVVCLKPtr = XGI7007_CHTVVCLKOPAL ;
5017                    break ;
5018                default:
5019                    break ;
5020
5021              }
5022            }
5023            /*else
5024            {
5025             switch( tempbx )
5026             {
5027                case 0:
5028                    CHTVVCLKPtr = pVBInfo->CHTVVCLKUNTSC ;
5029                    break ;
5030                case 1:
5031                    CHTVVCLKPtr = pVBInfo->CHTVVCLKONTSC ;
5032                    break ;
5033                case 2:
5034                    CHTVVCLKPtr = pVBInfo->CHTVVCLKUPAL ;
5035                    break ;
5036                case 3:
5037                    CHTVVCLKPtr = pVBInfo->CHTVVCLKOPAL ;
5038                    break ;
5039                default:
5040                    break ;
5041             }
5042            }*/
5043
5044            tempal = CHTVVCLKPtr[ tempal ] ;
5045            return tempal ;
5046        }
5047
5048     }
5049
5050     tempal = ( UCHAR )XGINew_GetReg2( ( pVBInfo->P3ca + 0x02 ) ) ;
5051     tempal = tempal >> 2 ;
5052     tempal &= 0x03 ;
5053
5054     if ( ( pVBInfo->LCDInfo & EnableScalingLCD ) && ( modeflag & Charx8Dot ) )  /* for Dot8 Scaling LCD */
5055         tempal = tempal ^ tempal ;                   /* ; set to VCLK25MHz always */
5056
5057     if ( ModeNo <= 0x13 )
5058         return tempal ;
5059
5060     tempal = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRTVCLK ;
5061     return tempal ;
5062 }
5063
5064
5065 /* --------------------------------------------------------------------- */
5066 /* Function : XGI_GetVCLKLen */
5067 /* Input : */
5068 /* Output : */
5069 /* Description : */
5070 /* --------------------------------------------------------------------- */
5071 void XGI_GetVCLKLen(UCHAR tempal,UCHAR* di_0,UCHAR* di_1, PVB_DEVICE_INFO pVBInfo)
5072 {
5073     if ( pVBInfo->IF_DEF_CH7007 == 1 ) /* [Billy] 2007/05/16 */
5074     {
5075        /* VideoDebugPrint((0, "XGI_GetVCLKLen: pVBInfo->IF_DEF_CH7007==1\n")); */
5076         *di_0 = ( UCHAR )XGI_CH7007VCLKData[ tempal ].SR2B ;
5077         *di_1 = ( UCHAR )XGI_CH7007VCLKData[ tempal ].SR2C ;
5078     }
5079     else if ( pVBInfo->VBType & ( VB_XGI301 | VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
5080     {
5081         if ( ( !( pVBInfo->VBInfo & SetCRT2ToLCDA ) ) && ( pVBInfo->SetFlag & ProgrammingCRT2 ) )
5082         {
5083             *di_0 = ( UCHAR )XGI_VBVCLKData[ tempal ].SR2B ;
5084             *di_1 = XGI_VBVCLKData[ tempal ].SR2C ;
5085         }
5086     }
5087     else
5088     {
5089         *di_0 = XGI_VCLKData[ tempal ].SR2B ;
5090         *di_1 = XGI_VCLKData[ tempal ].SR2C ;
5091     }
5092 }
5093
5094
5095 /* --------------------------------------------------------------------- */
5096 /* Function : XGI_SetCRT2Offset */
5097 /* Input : */
5098 /* Output : */
5099 /* Description : */
5100 /* --------------------------------------------------------------------- */
5101 void XGI_SetCRT2Offset( USHORT ModeNo ,
5102                                    USHORT ModeIdIndex , USHORT RefreshRateTableIndex , PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo )
5103 {
5104     USHORT offset ;
5105     UCHAR temp ;
5106
5107     if ( pVBInfo->VBInfo & SetInSlaveMode )
5108     {
5109         return ;
5110     }
5111
5112     offset = XGI_GetOffset(  ModeNo , ModeIdIndex , RefreshRateTableIndex , HwDeviceExtension, pVBInfo ) ;
5113     temp = ( UCHAR )( offset & 0xFF ) ;
5114     XGINew_SetReg1( pVBInfo->Part1Port , 0x07 , temp ) ;
5115     temp =( UCHAR)( ( offset & 0xFF00 ) >> 8 ) ;
5116     XGINew_SetReg1( pVBInfo->Part1Port , 0x09 , temp ) ;
5117     temp =( UCHAR )( ( ( offset >> 3 ) & 0xFF ) + 1 ) ;
5118     XGINew_SetReg1( pVBInfo->Part1Port , 0x03 , temp ) ;
5119 }
5120
5121
5122 /* --------------------------------------------------------------------- */
5123 /* Function : XGI_GetOffset */
5124 /* Input : */
5125 /* Output : */
5126 /* Description : */
5127 /* --------------------------------------------------------------------- */
5128 USHORT XGI_GetOffset(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension,PVB_DEVICE_INFO pVBInfo)
5129 {
5130     USHORT temp ,
5131            colordepth ,
5132            modeinfo ,
5133            index ,
5134            infoflag ,
5135            ColorDepth[] = { 0x01 , 0x02 , 0x04 } ;
5136
5137     modeinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeInfo ;
5138     if ( ModeNo <= 0x14 )
5139         infoflag = 0 ;
5140     else
5141         infoflag = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_InfoFlag ;
5142
5143
5144     index = ( modeinfo >> 8 ) & 0xFF ;
5145
5146     temp = pVBInfo->ScreenOffset[ index ] ;
5147
5148     if ( infoflag & InterlaceMode )
5149     {
5150         temp = temp << 1 ;
5151     }
5152
5153     colordepth = XGI_GetColorDepth( ModeNo , ModeIdIndex, pVBInfo ) ;
5154
5155     if ( ( ModeNo >= 0x7C ) && ( ModeNo <= 0x7E ) )
5156     {
5157         temp = ModeNo - 0x7C ;
5158         colordepth = ColorDepth[ temp ] ;
5159         temp = 0x6B ;
5160         if ( infoflag & InterlaceMode )
5161         {
5162             temp = temp << 1 ;
5163         }
5164         return( temp * colordepth ) ;
5165     }
5166     else
5167         return( temp * colordepth ) ;
5168 }
5169
5170
5171 /* --------------------------------------------------------------------- */
5172 /* Function : XGI_SetCRT2FIFO */
5173 /* Input : */
5174 /* Output : */
5175 /* Description : */
5176 /* --------------------------------------------------------------------- */
5177 void XGI_SetCRT2FIFO( PVB_DEVICE_INFO pVBInfo)
5178 {
5179     XGINew_SetReg1( pVBInfo->Part1Port , 0x01 , 0x3B ) ;                        /* threshold high ,disable auto threshold */
5180     XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x02 , ~( 0x3F ) , 0x04 ) ;        /* threshold low default 04h */
5181 }
5182
5183
5184 /* --------------------------------------------------------------------- */
5185 /* Function : XGI_PreSetGroup1 */
5186 /* Input : */
5187 /* Output : */
5188 /* Description : */
5189 /* --------------------------------------------------------------------- */
5190 void XGI_PreSetGroup1(USHORT ModeNo , USHORT ModeIdIndex ,PXGI_HW_DEVICE_INFO HwDeviceExtension,
5191                        USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
5192 {
5193     USHORT tempcx = 0 ,
5194            CRT1Index = 0 ,
5195            resinfo = 0 ;
5196
5197     if ( ModeNo > 0x13 )
5198     {
5199         CRT1Index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC ;
5200         CRT1Index &= IndexMask ;
5201         resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;
5202     }
5203
5204     XGI_SetCRT2Offset( ModeNo , ModeIdIndex , RefreshRateTableIndex , HwDeviceExtension, pVBInfo ) ;
5205     XGI_SetCRT2FIFO(pVBInfo) ;
5206     /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
5207
5208     for( tempcx = 4 ; tempcx < 7 ; tempcx++ )
5209     {
5210         XGINew_SetReg1( pVBInfo->Part1Port , tempcx , 0x0 ) ;
5211     }
5212
5213     XGINew_SetReg1( pVBInfo->Part1Port , 0x50 , 0x00 ) ;
5214     XGINew_SetReg1( pVBInfo->Part1Port , 0x02 , 0x44 ) ;        /* temp 0206 */
5215 }
5216
5217
5218 /* --------------------------------------------------------------------- */
5219 /* Function : XGI_SetGroup1 */
5220 /* Input : */
5221 /* Output : */
5222 /* Description : */
5223 /* --------------------------------------------------------------------- */
5224 void XGI_SetGroup1( USHORT ModeNo , USHORT ModeIdIndex ,
5225                             PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
5226 {
5227     USHORT temp = 0 ,
5228            tempax = 0 ,
5229            tempbx = 0 ,
5230            tempcx = 0 ,
5231            pushbx = 0 ,
5232            CRT1Index = 0 ,
5233            modeflag ,
5234            resinfo = 0 ;
5235
5236     if ( ModeNo > 0x13 )
5237     {
5238         CRT1Index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC ;
5239         CRT1Index &= IndexMask ;
5240         resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;
5241     }
5242
5243     if ( ModeNo <= 0x13 )
5244     {
5245         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
5246     }
5247     else
5248     {
5249         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
5250     }
5251
5252     /* bainy change table name */
5253     if ( modeflag & HalfDCLK )
5254     {
5255         temp = ( pVBInfo->VGAHT / 2 - 1 ) & 0x0FF ;                     /* BTVGA2HT 0x08,0x09 */
5256         XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , temp ) ;
5257         temp = ( ( ( pVBInfo->VGAHT / 2 - 1 ) & 0xFF00 ) >> 8 ) << 4 ;
5258         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x09 , ~0x0F0 , temp ) ;
5259         temp = ( pVBInfo->VGAHDE / 2 + 16 ) & 0x0FF ;                   /* BTVGA2HDEE 0x0A,0x0C */
5260         XGINew_SetReg1( pVBInfo->Part1Port , 0x0A , temp ) ;
5261         tempcx = ( ( pVBInfo->VGAHT - pVBInfo->VGAHDE ) / 2 ) >> 2 ;
5262         pushbx = pVBInfo->VGAHDE / 2 + 16 ;
5263         tempcx = tempcx >> 1 ;
5264         tempbx = pushbx + tempcx ;                                      /* bx BTVGA@HRS 0x0B,0x0C */
5265         tempcx += tempbx ;
5266
5267         if ( pVBInfo->VBInfo & SetCRT2ToRAMDAC )
5268         {
5269             tempbx = pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 4 ] ;
5270             tempbx |= ( ( pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 14 ] & 0xC0 ) << 2 ) ;
5271             tempbx = ( tempbx - 3 ) << 3 ;                              /* (VGAHRS-3)*8 */
5272             tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[ 5 ] ;
5273             tempcx &= 0x1F ;
5274             temp = pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 15 ] ;
5275             temp = ( temp & 0x04 ) << ( 5 - 2 ) ;                       /* VGAHRE D[5] */
5276             tempcx = ( ( tempcx | temp ) - 3 ) << 3 ;                   /* (VGAHRE-3)*8 */
5277         }
5278
5279         tempbx += 4 ;
5280         tempcx += 4 ;
5281
5282         if ( tempcx > ( pVBInfo->VGAHT / 2 ) )
5283             tempcx = pVBInfo->VGAHT / 2 ;
5284
5285         temp = tempbx & 0x00FF ;
5286
5287         XGINew_SetReg1( pVBInfo->Part1Port , 0x0B , temp ) ;
5288     }
5289     else
5290     {
5291         temp = ( pVBInfo->VGAHT - 1 ) & 0x0FF ;                         /* BTVGA2HT 0x08,0x09 */
5292         XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , temp ) ;
5293         temp = ( ( ( pVBInfo->VGAHT - 1 ) & 0xFF00 ) >> 8 ) << 4 ;
5294         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x09 , ~0x0F0 , temp ) ;
5295         temp = ( pVBInfo->VGAHDE + 16 ) & 0x0FF ;                               /* BTVGA2HDEE 0x0A,0x0C */
5296         XGINew_SetReg1( pVBInfo->Part1Port , 0x0A , temp ) ;
5297         tempcx = ( pVBInfo->VGAHT - pVBInfo->VGAHDE ) >> 2 ;            /* cx */
5298         pushbx = pVBInfo->VGAHDE + 16 ;
5299         tempcx = tempcx >> 1 ;
5300         tempbx = pushbx + tempcx ;                                      /* bx BTVGA@HRS 0x0B,0x0C */
5301         tempcx += tempbx ;
5302
5303         if ( pVBInfo->VBInfo & SetCRT2ToRAMDAC )
5304         {
5305             tempbx = pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 3 ] ;
5306             tempbx |= ( ( pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 5 ] & 0xC0 ) << 2 ) ;
5307             tempbx = ( tempbx - 3 ) << 3 ;                              /* (VGAHRS-3)*8 */
5308             tempcx = pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 4 ] ;
5309             tempcx &= 0x1F ;
5310             temp = pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 6 ] ;
5311             temp = ( temp & 0x04 ) << ( 5 - 2 ) ;                       /* VGAHRE D[5] */
5312             tempcx = ( ( tempcx | temp ) - 3 ) << 3 ;                   /* (VGAHRE-3)*8 */
5313             tempbx += 16 ;
5314             tempcx += 16 ;
5315         }
5316
5317         if ( tempcx > pVBInfo->VGAHT )
5318             tempcx = pVBInfo->VGAHT ;
5319
5320         temp = tempbx & 0x00FF ;
5321         XGINew_SetReg1( pVBInfo->Part1Port , 0x0B , temp ) ;
5322     }
5323
5324     tempax = ( tempax & 0x00FF ) | ( tempbx & 0xFF00 ) ;
5325     tempbx = pushbx ;
5326     tempbx = ( tempbx & 0x00FF ) | ( ( tempbx & 0xFF00 ) << 4 ) ;
5327     tempax |= ( tempbx & 0xFF00 ) ;
5328     temp = ( tempax & 0xFF00 ) >> 8 ;
5329     XGINew_SetReg1( pVBInfo->Part1Port , 0x0C , temp ) ;
5330     temp = tempcx & 0x00FF ;
5331     XGINew_SetReg1( pVBInfo->Part1Port , 0x0D , temp ) ;
5332     tempcx = ( pVBInfo->VGAVT - 1 ) ;
5333     temp = tempcx & 0x00FF ;
5334
5335     if ( pVBInfo->IF_DEF_CH7005 == 1 )
5336     {
5337         if ( pVBInfo->VBInfo & 0x0C )
5338         {
5339             temp-- ;
5340         }
5341     }
5342
5343     XGINew_SetReg1( pVBInfo->Part1Port , 0x0E , temp ) ;
5344     tempbx = pVBInfo->VGAVDE - 1 ;
5345     temp = tempbx & 0x00FF ;
5346     XGINew_SetReg1( pVBInfo->Part1Port , 0x0F , temp ) ;
5347     temp = ( ( tempbx & 0xFF00 ) << 3 ) >> 8 ;
5348     temp |= ( ( tempcx & 0xFF00 ) >> 8 ) ;
5349     XGINew_SetReg1( pVBInfo->Part1Port , 0x12 , temp ) ;
5350
5351     tempax = pVBInfo->VGAVDE ;
5352     tempbx = pVBInfo->VGAVDE ;
5353     tempcx = pVBInfo->VGAVT ;
5354     tempbx = ( pVBInfo->VGAVT + pVBInfo->VGAVDE ) >> 1 ;                                /* BTVGA2VRS 0x10,0x11 */
5355     tempcx = ( ( pVBInfo->VGAVT - pVBInfo->VGAVDE ) >> 4 ) + tempbx + 1 ;               /* BTVGA2VRE 0x11 */
5356
5357     if ( pVBInfo->VBInfo & SetCRT2ToRAMDAC )
5358     {
5359         tempbx = pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 10 ] ;
5360         temp = pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 9 ] ;
5361
5362         if ( temp & 0x04 )
5363             tempbx |= 0x0100 ;
5364
5365         if ( temp & 0x080 )
5366             tempbx |= 0x0200 ;
5367
5368         temp = pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 14 ] ;
5369
5370         if ( temp & 0x08 )
5371             tempbx |= 0x0400 ;
5372
5373         temp = pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 11 ] ;
5374         tempcx = ( tempcx & 0xFF00 ) | ( temp & 0x00FF ) ;
5375     }
5376
5377     temp = tempbx & 0x00FF ;
5378     XGINew_SetReg1( pVBInfo->Part1Port , 0x10 , temp ) ;
5379     temp = ( ( tempbx & 0xFF00 ) >> 8 ) << 4 ;
5380     temp = ( ( tempcx & 0x000F ) | ( temp ) ) ;
5381     XGINew_SetReg1( pVBInfo->Part1Port , 0x11 , temp ) ;
5382     tempax = 0 ;
5383
5384     if ( modeflag & DoubleScanMode )
5385         tempax |= 0x80 ;
5386
5387     if ( modeflag & HalfDCLK )
5388         tempax |= 0x40 ;
5389
5390     XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2C , ~0x0C0 , tempax ) ;
5391 }
5392
5393
5394 /* --------------------------------------------------------------------- */
5395 /* Function : XGI_SetLockRegs */
5396 /* Input : */
5397 /* Output : */
5398 /* Description : */
5399 /* --------------------------------------------------------------------- */
5400 void  XGI_SetLockRegs( USHORT ModeNo , USHORT ModeIdIndex ,
5401                                 PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
5402 {
5403     USHORT push1 ,
5404            push2 ,
5405            tempax ,
5406            tempbx = 0 ,
5407            tempcx ,
5408            temp ,
5409            resinfo ,
5410            modeflag ,
5411            CRT1Index ;
5412
5413     if ( ModeNo <= 0x13 )
5414     {
5415         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;   /* si+St_ResInfo */
5416         resinfo = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ResInfo ;
5417     }
5418     else
5419     {
5420         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;  /* si+Ext_ResInfo */
5421         resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;
5422         CRT1Index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC ;
5423         CRT1Index &= IndexMask;
5424     }
5425
5426     if ( !( pVBInfo->VBInfo & SetInSlaveMode ) )
5427     {
5428         return ;
5429     }
5430
5431     temp = 0xFF ;                                                       /* set MAX HT */
5432     XGINew_SetReg1( pVBInfo->Part1Port , 0x03 , temp ) ;
5433     /* if ( modeflag & Charx8Dot ) tempcx = 0x08 ; */
5434     /* else */
5435     tempcx=0x08;
5436
5437     if ( pVBInfo->VBType & ( VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
5438         modeflag |= Charx8Dot ;
5439
5440     tempax = pVBInfo->VGAHDE ;                                          /* 0x04 Horizontal Display End */
5441
5442     if ( modeflag & HalfDCLK )
5443         tempax = tempax >> 1 ;
5444
5445     tempax = ( tempax / tempcx ) - 1 ;
5446     tempbx |= ( ( tempax & 0x00FF ) << 8 ) ;
5447     temp = tempax & 0x00FF ;
5448     XGINew_SetReg1( pVBInfo->Part1Port , 0x04 , temp ) ;
5449
5450     temp = ( tempbx & 0xFF00 ) >> 8 ;
5451
5452     if ( pVBInfo->VBInfo & SetCRT2ToTV )
5453     {
5454         if ( !( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) ) )
5455             temp += 2 ;
5456
5457         if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
5458         {
5459             if ( pVBInfo->VBType & VB_XGI301LV )
5460             {
5461                 if ( pVBInfo->VBExtInfo == VB_YPbPr1080i )
5462                 {
5463                     if ( resinfo == 7 )
5464                         temp -= 2 ;
5465                 }
5466             }
5467             else
5468                 if ( resinfo == 7 )
5469                     temp -= 2 ;
5470         }
5471     }
5472
5473     XGINew_SetReg1( pVBInfo->Part1Port , 0x05 , temp ) ;                        /* 0x05 Horizontal Display Start */
5474     XGINew_SetReg1( pVBInfo->Part1Port , 0x06 , 0x03 ) ;                        /* 0x06 Horizontal Blank end */
5475
5476     if ( !( pVBInfo->VBInfo & DisableCRT2Display ) )
5477     {                                                                   /* 030226 bainy */
5478         if ( pVBInfo->VBInfo & SetCRT2ToTV )
5479             tempax = pVBInfo->VGAHT ;
5480         else
5481             tempax = XGI_GetVGAHT2( pVBInfo) ;
5482     }
5483
5484     if ( tempax >= pVBInfo->VGAHT )
5485     {
5486         tempax = pVBInfo->VGAHT ;
5487     }
5488
5489     if ( modeflag & HalfDCLK )
5490     {
5491         tempax = tempax >> 1 ;
5492     }
5493
5494     tempax = ( tempax / tempcx ) - 5 ;
5495     tempcx = tempax ;                           /* 20030401 0x07 horizontal Retrace Start */
5496     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
5497     {
5498         temp = ( tempbx & 0x00FF ) - 1 ;
5499         if ( !( modeflag & HalfDCLK ) )
5500         {
5501             temp -= 6 ;
5502             if ( pVBInfo->TVInfo & TVSimuMode )
5503             {
5504                 temp -= 4 ;
5505                 if ( ModeNo > 0x13 )
5506                     temp -= 10 ;
5507             }
5508         }
5509     }
5510     else
5511     {
5512         /* tempcx = tempbx & 0x00FF ; */
5513         tempbx = ( tempbx & 0xFF00 ) >> 8 ;
5514         tempcx = ( tempcx + tempbx ) >> 1 ;
5515         temp = ( tempcx & 0x00FF ) + 2 ;
5516
5517         if ( pVBInfo->VBInfo & SetCRT2ToTV )
5518         {
5519             temp -= 1 ;
5520             if ( !( modeflag & HalfDCLK ) )
5521             {
5522                 if ( ( modeflag & Charx8Dot ) )
5523                 {
5524                     temp += 4 ;
5525                     if ( pVBInfo->VGAHDE >= 800 )
5526                     {
5527                         temp -= 6 ;
5528                     }
5529                 }
5530             }
5531         }
5532         else
5533         {
5534             if ( !( modeflag & HalfDCLK ) )
5535             {
5536                 temp -= 4 ;
5537                 if ( pVBInfo->LCDResInfo != Panel1280x960 )
5538                 {
5539                     if( pVBInfo->VGAHDE >= 800 )
5540                     {
5541                         temp -= 7 ;
5542                         if ( pVBInfo->ModeType == ModeEGA )
5543                         {
5544                             if ( pVBInfo->VGAVDE == 1024 )
5545                             {
5546                                 temp += 15 ;
5547                                 if ( pVBInfo->LCDResInfo != Panel1280x1024 )
5548                                 {
5549                                     temp += 7 ;
5550                                 }
5551                             }
5552                         }
5553
5554                         if ( pVBInfo->VGAHDE >= 1280 )
5555                         {
5556                             if ( pVBInfo->LCDResInfo != Panel1280x960 )
5557                             {
5558                                 if ( pVBInfo->LCDInfo & LCDNonExpanding )
5559                                 {
5560                                     temp += 28 ;
5561                                 }
5562                             }
5563                         }
5564                     }
5565                 }
5566             }
5567         }
5568     }
5569
5570     XGINew_SetReg1( pVBInfo->Part1Port , 0x07 , temp ) ;                /* 0x07 Horizontal Retrace Start */
5571     XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , 0 ) ;           /* 0x08 Horizontal Retrace End */
5572
5573     if ( pVBInfo->VBInfo & SetCRT2ToTV )
5574     {
5575         if ( pVBInfo->TVInfo & TVSimuMode )
5576         {
5577             if ( ( ModeNo == 0x06 ) || ( ModeNo == 0x10 ) || ( ModeNo == 0x11 ) || ( ModeNo == 0x13 ) || ( ModeNo == 0x0F ) )
5578             {
5579                 XGINew_SetReg1( pVBInfo->Part1Port , 0x07 , 0x5b ) ;
5580                 XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , 0x03 ) ;
5581             }
5582
5583             if ( ( ModeNo == 0x00 ) || ( ModeNo == 0x01 ) )
5584             {
5585                 if ( pVBInfo->TVInfo & SetNTSCTV )
5586                 {
5587                     XGINew_SetReg1( pVBInfo->Part1Port , 0x07 , 0x2A ) ;
5588                     XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , 0x61 ) ;
5589                 }
5590                 else
5591                 {
5592                     XGINew_SetReg1( pVBInfo->Part1Port , 0x07 , 0x2A ) ;
5593                     XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , 0x41 ) ;
5594                     XGINew_SetReg1( pVBInfo->Part1Port , 0x0C , 0xF0 ) ;
5595                 }
5596             }
5597
5598             if ( ( ModeNo == 0x02 ) || ( ModeNo == 0x03 ) || ( ModeNo == 0x07 ) )
5599             {
5600                 if ( pVBInfo->TVInfo & SetNTSCTV )
5601                 {
5602                     XGINew_SetReg1( pVBInfo->Part1Port , 0x07 , 0x54 ) ;
5603                     XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , 0x00 ) ;
5604                 }
5605                 else
5606                 {
5607                     XGINew_SetReg1( pVBInfo->Part1Port , 0x07 , 0x55 ) ;
5608                     XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , 0x00 ) ;
5609                     XGINew_SetReg1( pVBInfo->Part1Port , 0x0C , 0xF0 ) ;
5610                 }
5611             }
5612
5613             if ( ( ModeNo == 0x04 ) || ( ModeNo == 0x05 ) || ( ModeNo == 0x0D ) || ( ModeNo == 0x50 ) )
5614             {
5615                 if ( pVBInfo->TVInfo & SetNTSCTV )
5616                 {
5617                     XGINew_SetReg1( pVBInfo->Part1Port , 0x07 , 0x30 ) ;
5618                     XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , 0x03 ) ;
5619                 }
5620                 else
5621                 {
5622                     XGINew_SetReg1( pVBInfo->Part1Port , 0x07 , 0x2f ) ;
5623                     XGINew_SetReg1( pVBInfo->Part1Port , 0x08 , 0x02 ) ;
5624                 }
5625             }
5626         }
5627     }
5628
5629     XGINew_SetReg1( pVBInfo->Part1Port , 0x18 , 0x03 ) ;                                /* 0x18 SR0B */
5630     XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x19 , 0xF0 , 0x00 ) ;
5631     XGINew_SetReg1( pVBInfo->Part1Port , 0x09 , 0xFF ) ;                                /* 0x09 Set Max VT */
5632
5633     tempbx = pVBInfo->VGAVT ;
5634     push1 = tempbx ;
5635     tempcx = 0x121 ;
5636     tempbx = pVBInfo->VGAVDE ;                                                  /* 0x0E Virtical Display End */
5637
5638     if ( tempbx == 357 )
5639         tempbx = 350 ;
5640     if ( tempbx == 360 )
5641         tempbx =350 ;
5642     if ( tempbx == 375 )
5643         tempbx = 350 ;
5644     if ( tempbx == 405 )
5645         tempbx = 400 ;
5646     if ( tempbx == 525 )
5647         tempbx = 480 ;
5648
5649     push2 = tempbx ;
5650
5651     if ( pVBInfo->VBInfo & SetCRT2ToLCD )
5652     {
5653         if ( pVBInfo->LCDResInfo == Panel1024x768 )
5654         {
5655             if ( !( pVBInfo->LCDInfo & LCDVESATiming ) )
5656             {
5657                 if ( tempbx == 350 )
5658                     tempbx += 5 ;
5659                 if ( tempbx == 480 )
5660                     tempbx += 5 ;
5661             }
5662         }
5663     }
5664     tempbx-- ;
5665     temp = tempbx & 0x00FF ;
5666     tempbx-- ;
5667     temp = tempbx & 0x00FF ;
5668     XGINew_SetReg1( pVBInfo->Part1Port , 0x10 ,temp ) ;                         /* 0x10 vertical Blank Start */
5669     tempbx = push2 ;
5670     tempbx-- ;
5671     temp = tempbx & 0x00FF ;
5672     XGINew_SetReg1( pVBInfo->Part1Port , 0x0E , temp ) ;
5673
5674     if ( tempbx & 0x0100 )
5675     {
5676         tempcx |= 0x0002 ;
5677     }
5678
5679     tempax = 0x000B ;
5680
5681     if ( modeflag & DoubleScanMode )
5682     {
5683         tempax |= 0x08000 ;
5684     }
5685
5686     if ( tempbx & 0x0200 )
5687     {
5688         tempcx |= 0x0040 ;
5689     }
5690
5691     temp = ( tempax & 0xFF00 ) >> 8 ;
5692     XGINew_SetReg1( pVBInfo->Part1Port , 0x0B , temp ) ;
5693
5694     if ( tempbx & 0x0400 )
5695     {
5696         tempcx |= 0x0600 ;
5697     }
5698
5699     XGINew_SetReg1( pVBInfo->Part1Port , 0x11 , 0x00 ) ;                                /* 0x11 Vertival Blank End */
5700
5701     tempax = push1 ;
5702     tempax -= tempbx ;                                                          /* 0x0C Vertical Retrace Start */
5703     tempax = tempax >> 2 ;
5704     push1 = tempax ;                                                            /* push ax */
5705
5706     if ( resinfo != 0x09 )
5707     {
5708         tempax = tempax << 1 ;
5709         tempbx += tempax ;
5710     }
5711
5712     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
5713     {
5714         if ( pVBInfo->VBType & VB_XGI301LV )
5715         {
5716             if ( pVBInfo->TVInfo & SetYPbPrMode1080i )
5717                 tempbx -= 10 ;
5718             else
5719             {
5720                 if ( pVBInfo->TVInfo & TVSimuMode )
5721                 {
5722                     if ( pVBInfo->TVInfo & SetPALTV )
5723                     {
5724                         if ( pVBInfo->VBType & VB_XGI301LV )
5725                         {
5726                             if ( !( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p | SetYPbPrMode1080i ) ) )
5727                                 tempbx += 40 ;
5728                         }
5729                         else
5730                             tempbx += 40 ;
5731                     }
5732                 }
5733             }
5734         }
5735         else
5736             tempbx -= 10 ;
5737     }
5738     else
5739     {
5740         if ( pVBInfo->TVInfo & TVSimuMode )
5741         {
5742             if ( pVBInfo->TVInfo & SetPALTV )
5743             {
5744                 if ( pVBInfo->VBType & VB_XGI301LV )
5745                 {
5746                     if ( !( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p | SetYPbPrMode1080i ) ) )
5747                         tempbx += 40 ;
5748                 }
5749                 else
5750                     tempbx += 40 ;
5751             }
5752         }
5753     }
5754     tempax = push1 ;
5755     tempax = tempax >> 2 ;
5756     tempax++ ;
5757     tempax += tempbx ;
5758     push1 = tempax ;                                            /* push ax */
5759
5760     if ( ( pVBInfo->TVInfo & SetPALTV ) )
5761     {
5762         if ( tempbx <= 513 )
5763         {
5764             if ( tempax >= 513 )
5765             {
5766                 tempbx = 513 ;
5767             }
5768         }
5769     }
5770
5771     temp = tempbx & 0x00FF ;
5772     XGINew_SetReg1( pVBInfo->Part1Port , 0x0C , temp ) ;
5773     tempbx-- ;
5774     temp = tempbx & 0x00FF ;
5775     XGINew_SetReg1( pVBInfo->Part1Port , 0x10 , temp ) ;
5776
5777     if ( tempbx & 0x0100 )
5778     {
5779         tempcx |= 0x0008 ;
5780     }
5781
5782     if ( tempbx & 0x0200 )
5783     {
5784         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x0B , 0x0FF , 0x20 ) ;
5785     }
5786
5787     tempbx++ ;
5788
5789     if ( tempbx & 0x0100 )
5790     {
5791         tempcx |= 0x0004 ;
5792     }
5793
5794     if ( tempbx & 0x0200 )
5795     {
5796         tempcx |= 0x0080 ;
5797     }
5798
5799     if ( tempbx & 0x0400 )
5800     {
5801         tempcx |= 0x0C00 ;
5802     }
5803
5804     tempbx = push1 ;                                            /* pop ax */
5805     temp = tempbx & 0x00FF ;
5806     temp &= 0x0F ;
5807     XGINew_SetReg1( pVBInfo->Part1Port , 0x0D , temp ) ;                /* 0x0D vertical Retrace End */
5808
5809     if ( tempbx & 0x0010 )
5810     {
5811         tempcx |= 0x2000 ;
5812     }
5813
5814     temp = tempcx & 0x00FF ;
5815     XGINew_SetReg1( pVBInfo->Part1Port , 0x0A , temp ) ;                /* 0x0A CR07 */
5816     temp = ( tempcx & 0x0FF00 ) >> 8 ;
5817     XGINew_SetReg1( pVBInfo->Part1Port , 0x17 , temp ) ;                /* 0x17 SR0A */
5818     tempax = modeflag ;
5819     temp = ( tempax & 0xFF00 ) >> 8 ;
5820
5821     temp = ( temp >> 1 ) & 0x09 ;
5822
5823     if ( pVBInfo->VBType & ( VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
5824         temp |= 0x01 ;
5825
5826     XGINew_SetReg1( pVBInfo->Part1Port , 0x16 , temp ) ;                        /* 0x16 SR01 */
5827     XGINew_SetReg1( pVBInfo->Part1Port , 0x0F , 0 ) ;                   /* 0x0F CR14 */
5828     XGINew_SetReg1( pVBInfo->Part1Port , 0x12 , 0 ) ;                   /* 0x12 CR17 */
5829
5830     if ( pVBInfo->LCDInfo & LCDRGB18Bit )
5831         temp = 0x80 ;
5832     else
5833         temp = 0x00 ;
5834
5835     XGINew_SetReg1( pVBInfo->Part1Port , 0x1A , temp ) ;                        /* 0x1A SR0E */
5836
5837     return ;
5838 }
5839
5840
5841 /* --------------------------------------------------------------------- */
5842 /* Function : XGI_SetGroup2 */
5843 /* Input : */
5844 /* Output : */
5845 /* Description : */
5846 /* --------------------------------------------------------------------- */
5847 void XGI_SetGroup2( USHORT ModeNo, USHORT ModeIdIndex, USHORT RefreshRateTableIndex,
5848                     PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo )
5849 {
5850     USHORT i ,
5851            j ,
5852            tempax ,
5853            tempbx ,
5854            tempcx ,
5855            temp ,
5856            push1 ,
5857            push2 ,
5858            modeflag ,
5859            resinfo ,
5860            crt2crtc ;
5861     UCHAR *TimingPoint ;
5862
5863     ULONG longtemp ,
5864           tempeax ,
5865           tempebx ,
5866           temp2 ,
5867           tempecx ;
5868
5869     if ( ModeNo <= 0x13 )
5870     {
5871         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;           /* si+St_ResInfo */
5872         resinfo = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ResInfo ;
5873         crt2crtc = pVBInfo->SModeIDTable[ ModeIdIndex ].St_CRT2CRTC ;
5874     }
5875     else
5876     {
5877         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;          /* si+Ext_ResInfo */
5878         resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;
5879         crt2crtc = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT2CRTC ;
5880     }
5881
5882     tempax = 0 ;
5883
5884     if ( !( pVBInfo->VBInfo & SetCRT2ToAVIDEO ) )
5885         tempax |= 0x0800 ;
5886
5887     if ( !( pVBInfo->VBInfo & SetCRT2ToSVIDEO ) )
5888         tempax |= 0x0400 ;
5889
5890     if ( pVBInfo->VBInfo & SetCRT2ToSCART )
5891         tempax |= 0x0200 ;
5892
5893     if ( !( pVBInfo->TVInfo & SetPALTV ) )
5894         tempax |= 0x1000 ;
5895
5896     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
5897         tempax |= 0x0100 ;
5898
5899     if ( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p ) )
5900         tempax &= 0xfe00 ;
5901
5902     tempax = ( tempax & 0xff00 ) >> 8 ;
5903
5904     XGINew_SetReg1( pVBInfo->Part2Port , 0x0 , tempax ) ;
5905     TimingPoint = pVBInfo->NTSCTiming ;
5906
5907     if ( pVBInfo->TVInfo & SetPALTV )
5908     {
5909         TimingPoint = pVBInfo->PALTiming ;
5910     }
5911
5912     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
5913     {
5914         TimingPoint = pVBInfo->HiTVExtTiming ;
5915
5916         if ( pVBInfo->VBInfo & SetInSlaveMode )
5917             TimingPoint = pVBInfo->HiTVSt2Timing ;
5918
5919         if ( pVBInfo->SetFlag & TVSimuMode )
5920             TimingPoint = pVBInfo->HiTVSt1Timing ;
5921
5922         if ( !(modeflag & Charx8Dot) )
5923             TimingPoint = pVBInfo->HiTVTextTiming ;
5924     }
5925
5926     if ( pVBInfo->VBInfo & SetCRT2ToYPbPr )
5927     {
5928         if ( pVBInfo->TVInfo & SetYPbPrMode525i )
5929             TimingPoint = pVBInfo->YPbPr525iTiming ;
5930
5931         if ( pVBInfo->TVInfo & SetYPbPrMode525p )
5932             TimingPoint = pVBInfo->YPbPr525pTiming ;
5933
5934         if ( pVBInfo->TVInfo & SetYPbPrMode750p )
5935             TimingPoint = pVBInfo->YPbPr750pTiming ;
5936     }
5937
5938     for( i = 0x01 , j = 0 ; i <= 0x2D ; i++ , j++ )
5939     {
5940         XGINew_SetReg1( pVBInfo->Part2Port , i , TimingPoint[ j ] ) ;
5941     }
5942
5943     for( i = 0x39 ; i <= 0x45 ; i++ , j++ )
5944     {
5945         XGINew_SetReg1( pVBInfo->Part2Port , i , TimingPoint[ j ] ) ;   /* di->temp2[j] */
5946     }
5947
5948     if ( pVBInfo->VBInfo & SetCRT2ToTV )
5949     {
5950         XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x3A , 0x1F , 0x00 ) ;
5951     }
5952
5953     temp = pVBInfo->NewFlickerMode ;
5954     temp &= 0x80 ;
5955     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x0A , 0xFF , temp ) ;
5956
5957     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
5958         tempax = 950 ;
5959
5960     if ( pVBInfo->TVInfo & SetPALTV )
5961         tempax = 520 ;
5962     else
5963         tempax = 440 ;
5964
5965     if ( pVBInfo->VDE <= tempax )
5966     {
5967         tempax -= pVBInfo->VDE ;
5968         tempax = tempax >> 2 ;
5969         tempax = ( tempax & 0x00FF ) | ( ( tempax & 0x00FF ) << 8 ) ;
5970         push1 = tempax ;
5971         temp = ( tempax & 0xFF00 ) >> 8 ;
5972         temp += ( USHORT )TimingPoint[ 0 ] ;
5973
5974         if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
5975         {
5976             if ( pVBInfo->VBInfo & ( SetCRT2ToAVIDEO | SetCRT2ToSVIDEO | SetCRT2ToSCART | SetCRT2ToYPbPr ) )
5977             {
5978                 tempcx=pVBInfo->VGAHDE;
5979                 if ( tempcx >= 1024 )
5980                 {
5981                     temp = 0x17 ;               /* NTSC */
5982                     if ( pVBInfo->TVInfo & SetPALTV )
5983                         temp = 0x19 ;           /* PAL */
5984                 }
5985             }
5986         }
5987
5988         XGINew_SetReg1( pVBInfo->Part2Port , 0x01 , temp ) ;
5989         tempax = push1 ;
5990         temp = ( tempax & 0xFF00 ) >> 8 ;
5991         temp += TimingPoint[ 1 ] ;
5992
5993         if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
5994         {
5995             if ( ( pVBInfo->VBInfo & ( SetCRT2ToAVIDEO | SetCRT2ToSVIDEO | SetCRT2ToSCART | SetCRT2ToYPbPr ) ) )
5996             {
5997                 tempcx = pVBInfo->VGAHDE ;
5998                 if ( tempcx >= 1024 )
5999                 {
6000                     temp = 0x1D ;               /* NTSC */
6001                     if ( pVBInfo->TVInfo & SetPALTV )
6002                         temp = 0x52 ;           /* PAL */
6003                 }
6004             }
6005         }
6006         XGINew_SetReg1( pVBInfo->Part2Port , 0x02 , temp ) ;
6007     }
6008
6009     /* 301b */
6010     tempcx = pVBInfo->HT ;
6011
6012     if ( XGI_IsLCDDualLink( pVBInfo ) )
6013         tempcx = tempcx >> 1 ;
6014
6015     tempcx -= 2 ;
6016     temp = tempcx & 0x00FF ;
6017     XGINew_SetReg1( pVBInfo->Part2Port , 0x1B , temp ) ;
6018
6019     temp = ( tempcx & 0xFF00 ) >> 8 ;
6020     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x1D , ~0x0F , temp ) ;
6021
6022     tempcx = pVBInfo->HT >> 1 ;
6023     push1 = tempcx ;                            /* push cx */
6024     tempcx += 7 ;
6025
6026     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
6027     {
6028         tempcx -= 4 ;
6029     }
6030
6031     temp = tempcx & 0x00FF ;
6032     temp = temp << 4 ;
6033     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x22 , 0x0F , temp ) ;
6034
6035     tempbx = TimingPoint[ j ] | ( ( TimingPoint[ j + 1 ] ) << 8 ) ;
6036     tempbx += tempcx ;
6037     push2 = tempbx ;
6038     temp = tempbx & 0x00FF ;
6039     XGINew_SetReg1( pVBInfo->Part2Port , 0x24 , temp ) ;
6040     temp = ( tempbx & 0xFF00 ) >> 8 ;
6041     temp = temp << 4 ;
6042     XGINew_SetRegANDOR(pVBInfo->Part2Port,0x25,0x0F,temp);
6043
6044     tempbx=push2;
6045     tempbx=tempbx+8;
6046     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
6047     {
6048         tempbx=tempbx-4;
6049         tempcx=tempbx;
6050     }
6051
6052     temp = ( tempbx & 0x00FF ) << 4 ;
6053     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x29 , 0x0F , temp ) ;
6054
6055     j += 2 ;
6056     tempcx += ( TimingPoint[ j ] | ( ( TimingPoint[ j + 1 ] ) << 8 ) ) ;
6057     temp = tempcx & 0x00FF ;
6058     XGINew_SetReg1( pVBInfo->Part2Port , 0x27 , temp ) ;
6059     temp = ( ( tempcx & 0xFF00 ) >> 8 ) << 4 ;
6060     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x28 , 0x0F , temp ) ;
6061
6062     tempcx += 8 ;
6063     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
6064     {
6065         tempcx -= 4 ;
6066     }
6067
6068     temp = tempcx & 0xFF ;
6069     temp = temp << 4 ;
6070     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x2A , 0x0F , temp ) ;
6071
6072     tempcx = push1 ;                                    /* pop cx */
6073     j += 2 ;
6074     temp = TimingPoint[ j ] | ( ( TimingPoint[ j + 1 ] ) << 8 ) ;
6075     tempcx -= temp ;
6076     temp = tempcx & 0x00FF ;
6077     temp = temp << 4 ;
6078     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x2D , 0x0F ,temp ) ;
6079
6080     tempcx -= 11 ;
6081
6082     if ( !( pVBInfo->VBInfo & SetCRT2ToTV ) )
6083     {
6084         tempax = XGI_GetVGAHT2( pVBInfo) ;
6085         tempcx = tempax - 1 ;
6086     }
6087     temp = tempcx & 0x00FF ;
6088     XGINew_SetReg1( pVBInfo->Part2Port , 0x2E , temp ) ;
6089
6090     tempbx = pVBInfo->VDE ;
6091
6092     if ( pVBInfo->VGAVDE == 360 )
6093         tempbx = 746 ;
6094     if ( pVBInfo->VGAVDE == 375 )
6095         tempbx = 746 ;
6096     if ( pVBInfo->VGAVDE == 405 )
6097         tempbx = 853 ;
6098
6099     if ( pVBInfo->VBInfo & SetCRT2ToTV )
6100     {
6101         if ( pVBInfo->VBType & ( VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
6102         {
6103             if ( !( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p ) ) )
6104                 tempbx = tempbx >> 1 ;
6105         }
6106         else
6107             tempbx = tempbx >> 1 ;
6108     }
6109
6110     tempbx -= 2 ;
6111     temp = tempbx & 0x00FF ;
6112
6113     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
6114     {
6115         if ( pVBInfo->VBType & VB_XGI301LV )
6116         {
6117             if ( pVBInfo->TVInfo & SetYPbPrMode1080i )
6118             {
6119                 if ( pVBInfo->VBInfo & SetInSlaveMode )
6120                 {
6121                     if ( ModeNo == 0x2f )
6122                         temp += 1 ;
6123                 }
6124             }
6125         }
6126         else
6127         {
6128             if ( pVBInfo->VBInfo & SetInSlaveMode )
6129             {
6130                 if ( ModeNo == 0x2f )
6131                     temp += 1 ;
6132             }
6133         }
6134     }
6135
6136     XGINew_SetReg1( pVBInfo->Part2Port , 0x2F , temp ) ;
6137
6138     temp = ( tempcx & 0xFF00 ) >> 8 ;
6139     temp |= ( ( tempbx & 0xFF00 ) >> 8 ) << 6 ;
6140
6141     if ( !( pVBInfo->VBInfo & SetCRT2ToHiVisionTV ) )
6142     {
6143         if ( pVBInfo->VBType & VB_XGI301LV )
6144         {
6145             if ( pVBInfo->TVInfo & SetYPbPrMode1080i )
6146             {
6147                 temp |= 0x10 ;
6148
6149                 if ( !( pVBInfo->VBInfo & SetCRT2ToSVIDEO ) )
6150                     temp |= 0x20 ;
6151             }
6152         }
6153         else
6154         {
6155             temp |= 0x10 ;
6156             if ( !( pVBInfo->VBInfo & SetCRT2ToSVIDEO ) )
6157                 temp |= 0x20 ;
6158         }
6159     }
6160
6161     XGINew_SetReg1( pVBInfo->Part2Port , 0x30 , temp ) ;
6162
6163     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )       /* TV gatingno */
6164     {
6165         tempbx = pVBInfo->VDE ;
6166         tempcx = tempbx - 2 ;
6167
6168         if ( pVBInfo->VBInfo & SetCRT2ToTV )
6169         {
6170             if ( !( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p ) ) )
6171                 tempbx = tempbx >> 1 ;
6172         }
6173
6174         if ( pVBInfo->VBType & ( VB_XGI302LV | VB_XGI301C ) )
6175         {
6176             temp=0;
6177             if( tempcx & 0x0400 )
6178                 temp |= 0x20 ;
6179
6180             if ( tempbx & 0x0400 )
6181                 temp |= 0x40 ;
6182
6183             XGINew_SetReg1( pVBInfo->Part4Port , 0x10 , temp ) ;
6184         }
6185
6186         temp = ( ( ( tempbx - 3 ) & 0x0300 ) >> 8 ) << 5 ;
6187         XGINew_SetReg1( pVBInfo->Part2Port , 0x46 , temp ) ;
6188         temp = ( tempbx - 3 ) & 0x00FF ;
6189         XGINew_SetReg1( pVBInfo->Part2Port , 0x47 , temp ) ;
6190     }
6191
6192     tempbx = tempbx & 0x00FF ;
6193
6194     if ( !( modeflag & HalfDCLK ) )
6195     {
6196         tempcx = pVBInfo->VGAHDE ;
6197         if ( tempcx >= pVBInfo->HDE )
6198         {
6199             tempbx |= 0x2000 ;
6200             tempax &= 0x00FF ;
6201         }
6202     }
6203
6204     tempcx = 0x0101 ;
6205
6206     if( pVBInfo->VBInfo & SetCRT2ToTV ) { /*301b*/
6207         if(pVBInfo->VGAHDE>=1024)
6208         {
6209             tempcx=0x1920;
6210             if(pVBInfo->VGAHDE>=1280)
6211             {
6212                 tempcx=0x1420;
6213                 tempbx=tempbx&0xDFFF;
6214             }
6215         }
6216     }
6217
6218     if ( !( tempbx & 0x2000 ) )
6219     {
6220         if ( modeflag & HalfDCLK )
6221         {
6222             tempcx = ( tempcx & 0xFF00 ) | ( ( tempcx & 0x00FF ) << 1 ) ;
6223         }
6224
6225         push1 = tempbx ;
6226         tempeax = pVBInfo->VGAHDE ;
6227         tempebx = ( tempcx & 0xFF00 ) >> 8 ;
6228         longtemp = tempeax * tempebx ;
6229         tempecx = tempcx & 0x00FF ;
6230         longtemp = longtemp / tempecx ;
6231
6232         /* 301b */
6233         tempecx = 8 * 1024 ;
6234
6235         if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
6236         {
6237             tempecx = tempecx * 8 ;
6238         }
6239
6240         longtemp = longtemp * tempecx ;
6241         tempecx = pVBInfo->HDE ;
6242         temp2 = longtemp % tempecx ;
6243         tempeax = longtemp / tempecx ;
6244         if ( temp2 != 0 )
6245         {
6246             tempeax += 1 ;
6247         }
6248
6249         tempax = ( USHORT )tempeax ;
6250
6251         /* 301b */
6252         if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
6253         {
6254             tempcx = ( ( tempax & 0xFF00 ) >> 5 ) >> 8 ;
6255         }
6256         /* end 301b */
6257
6258         tempbx = push1 ;
6259         tempbx =( USHORT )( ( ( tempeax & 0x0000FF00 ) & 0x1F00 ) | ( tempbx & 0x00FF ) ) ;
6260         tempax =( USHORT )( ( ( tempeax & 0x000000FF ) << 8 ) | ( tempax & 0x00FF ) ) ;
6261         temp = ( tempax & 0xFF00 ) >> 8 ;
6262     }
6263     else
6264     {
6265         temp = ( tempax & 0x00FF ) >> 8 ;
6266     }
6267
6268     XGINew_SetReg1( pVBInfo->Part2Port , 0x44 , temp ) ;
6269     temp = ( tempbx & 0xFF00 ) >> 8 ;
6270     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x45 , ~0x03F , temp ) ;
6271     temp = tempcx & 0x00FF ;
6272
6273     if ( tempbx & 0x2000 )
6274         temp = 0 ;
6275
6276     if ( !( pVBInfo->VBInfo & SetCRT2ToLCD ) )
6277         temp |= 0x18 ;
6278
6279     XGINew_SetRegANDOR(pVBInfo->Part2Port,0x46,~0x1F,temp);
6280     if ( pVBInfo->TVInfo & SetPALTV )
6281     {
6282         tempbx = 0x0382 ;
6283         tempcx = 0x007e ;
6284     }
6285     else
6286     {
6287         tempbx = 0x0369 ;
6288         tempcx = 0x0061 ;
6289     }
6290
6291     temp = tempbx & 0x00FF ;
6292     XGINew_SetReg1( pVBInfo->Part2Port , 0x4b , temp ) ;
6293     temp = tempcx & 0x00FF ;
6294     XGINew_SetReg1( pVBInfo->Part2Port , 0x4c , temp ) ;
6295
6296     temp = ( ( tempcx & 0xFF00 ) >> 8 ) & 0x03 ;
6297     temp = temp << 2 ;
6298     temp |= ( ( tempbx & 0xFF00 ) >> 8 ) & 0x03 ;
6299
6300     if ( pVBInfo->VBInfo & SetCRT2ToYPbPr )
6301     {
6302         temp |= 0x10 ;
6303
6304         if ( pVBInfo->TVInfo & SetYPbPrMode525p )
6305             temp |= 0x20 ;
6306
6307         if ( pVBInfo->TVInfo & SetYPbPrMode750p )
6308             temp |= 0x60 ;
6309     }
6310
6311     XGINew_SetReg1( pVBInfo->Part2Port , 0x4d , temp ) ;
6312     temp=XGINew_GetReg1( pVBInfo->Part2Port , 0x43 ) ;          /* 301b change */
6313     XGINew_SetReg1( pVBInfo->Part2Port , 0x43 , ( USHORT )( temp - 3 ) ) ;
6314
6315     if ( !( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p ) ) )
6316     {
6317         if ( pVBInfo->TVInfo & NTSC1024x768 )
6318         {
6319             TimingPoint = XGI_NTSC1024AdjTime ;
6320             for( i = 0x1c , j = 0 ; i <= 0x30 ; i++ , j++ )
6321             {
6322                 XGINew_SetReg1( pVBInfo->Part2Port , i , TimingPoint[ j ] ) ;
6323             }
6324             XGINew_SetReg1( pVBInfo->Part2Port , 0x43 , 0x72 ) ;
6325         }
6326     }
6327
6328     /* [ycchen] 01/14/03 Modify for 301C PALM Support */
6329     if ( pVBInfo->VBType & VB_XGI301C )
6330     {
6331         if ( pVBInfo->TVInfo & SetPALMTV )
6332             XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x4E , ~0x08 , 0x08 ) ;    /* PALM Mode */
6333     }
6334
6335     if ( pVBInfo->TVInfo & SetPALMTV )
6336     {
6337         tempax = ( UCHAR )XGINew_GetReg1( pVBInfo->Part2Port , 0x01 ) ;
6338         tempax-- ;
6339         XGINew_SetRegAND( pVBInfo->Part2Port , 0x01 , tempax ) ;
6340
6341         /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
6342         XGINew_SetRegAND( pVBInfo->Part2Port , 0x00 , 0xEF ) ;
6343     }
6344
6345     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
6346     {
6347         if ( !( pVBInfo->VBInfo & SetInSlaveMode ) )
6348         {
6349             XGINew_SetReg1( pVBInfo->Part2Port , 0x0B , 0x00 ) ;
6350         }
6351     }
6352
6353     if ( pVBInfo->VBInfo & SetCRT2ToTV )
6354     {
6355         return ;
6356     }
6357 }
6358
6359
6360 /* --------------------------------------------------------------------- */
6361 /* Function : XGI_SetLCDRegs */
6362 /* Input : */
6363 /* Output : */
6364 /* Description : */
6365 /* --------------------------------------------------------------------- */
6366 void  XGI_SetLCDRegs(USHORT ModeNo,USHORT ModeIdIndex, PXGI_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo)
6367 {
6368     USHORT push1 ,
6369            push2 ,
6370            pushbx ,
6371            tempax ,
6372            tempbx ,
6373            tempcx ,
6374            temp ,
6375            tempah ,
6376            tempbh ,
6377            tempch ,
6378            resinfo ,
6379            modeflag ,
6380            CRT1Index ;
6381
6382     XGI_LCDDesStruct *LCDBDesPtr = NULL ;
6383
6384
6385     if ( ModeNo <= 0x13 )
6386     {
6387         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;   /* si+St_ResInfo */
6388         resinfo = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ResInfo ;
6389     }
6390     else
6391     {
6392         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;  /* si+Ext_ResInfo */
6393         resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;
6394         CRT1Index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC ;
6395         CRT1Index &= IndexMask ;
6396     }
6397
6398     if ( !( pVBInfo->VBInfo & SetCRT2ToLCD ) )
6399     {
6400         return ;
6401     }
6402
6403     tempbx = pVBInfo->HDE ;                     /* RHACTE=HDE-1 */
6404
6405     if ( XGI_IsLCDDualLink( pVBInfo ) )
6406         tempbx = tempbx >> 1 ;
6407
6408     tempbx -= 1 ;
6409     temp = tempbx & 0x00FF ;
6410     XGINew_SetReg1( pVBInfo->Part2Port , 0x2C , temp ) ;
6411     temp = ( tempbx & 0xFF00 ) >> 8 ;
6412     temp = temp << 4 ;
6413     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x2B , 0x0F , temp ) ;
6414     temp = 0x01 ;
6415
6416     if ( pVBInfo->LCDResInfo == Panel1280x1024 )
6417     {
6418         if ( pVBInfo->ModeType == ModeEGA )
6419         {
6420             if ( pVBInfo->VGAHDE >= 1024 )
6421             {
6422                 temp = 0x02 ;
6423                 if ( pVBInfo->LCDInfo & LCDVESATiming )
6424                     temp = 0x01 ;
6425             }
6426         }
6427     }
6428
6429     XGINew_SetReg1( pVBInfo->Part2Port , 0x0B , temp ) ;
6430     tempbx = pVBInfo->VDE ;                     /* RTVACTEO=(VDE-1)&0xFF */
6431     push1 = tempbx ;
6432     tempbx-- ;
6433     temp = tempbx & 0x00FF ;
6434     XGINew_SetReg1( pVBInfo->Part2Port , 0x03 , temp ) ;
6435     temp = ( ( tempbx & 0xFF00 ) >> 8 ) & 0x07 ;
6436     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x0C , ~0x07 , temp ) ;
6437
6438     tempcx = pVBInfo->VT - 1 ;
6439     push2 = tempcx + 1 ;
6440     temp = tempcx & 0x00FF ;                    /* RVTVT=VT-1 */
6441     XGINew_SetReg1( pVBInfo->Part2Port , 0x19 , temp ) ;
6442     temp = ( tempcx & 0xFF00 ) >> 8 ;
6443     temp = temp << 5 ;
6444     XGINew_SetReg1( pVBInfo->Part2Port , 0x1A , temp ) ;
6445     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x09 , 0xF0 , 0x00 ) ;
6446     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x0A , 0xF0 , 0x00 ) ;
6447     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x17 , 0xFB , 0x00 ) ;
6448     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x18 , 0xDF , 0x00 ) ;
6449
6450     /* Customized LCDB Des no add */
6451     tempbx = 5 ;
6452     LCDBDesPtr = ( XGI_LCDDesStruct * )XGI_GetLcdPtr( tempbx , ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
6453     tempah = pVBInfo->LCDResInfo ;
6454     tempah &= PanelResInfo ;
6455
6456     if ( ( tempah == Panel1024x768 ) || ( tempah == Panel1024x768x75 ) )
6457     {
6458         tempbx = 1024 ;
6459         tempcx = 768 ;
6460     }
6461     else if ( ( tempah == Panel1280x1024 ) || ( tempah == Panel1280x1024x75 ) )
6462     {
6463         tempbx = 1280 ;
6464         tempcx = 1024 ;
6465     }
6466     else if ( tempah == Panel1400x1050 )
6467     {
6468         tempbx = 1400 ;
6469         tempcx = 1050 ;
6470     }
6471     else
6472     {
6473         tempbx = 1600 ;
6474         tempcx = 1200 ;
6475     }
6476
6477     if ( pVBInfo->LCDInfo & EnableScalingLCD )
6478     {
6479         tempbx = pVBInfo->HDE ;
6480         tempcx = pVBInfo->VDE ;
6481     }
6482
6483     pushbx = tempbx ;
6484     tempax = pVBInfo->VT ;
6485     pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES ;
6486     pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS ;
6487     pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES ;
6488     pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS ;
6489     tempbx = pVBInfo->LCDVDES ;
6490     tempcx += tempbx ;
6491
6492     if ( tempcx >= tempax )
6493         tempcx -= tempax ;      /* lcdvdes */
6494
6495     temp = tempbx & 0x00FF ;    /* RVEQ1EQ=lcdvdes */
6496     XGINew_SetReg1( pVBInfo->Part2Port , 0x05 , temp ) ;
6497     temp = tempcx & 0x00FF ;
6498     XGINew_SetReg1( pVBInfo->Part2Port , 0x06 , temp ) ;
6499     tempch = ( ( tempcx & 0xFF00 ) >> 8 ) & 0x07 ;
6500     tempbh = ( ( tempbx & 0xFF00 ) >> 8 ) & 0x07 ;
6501     tempah = tempch ;
6502     tempah = tempah << 3 ;
6503     tempah |= tempbh ;
6504     XGINew_SetReg1( pVBInfo->Part2Port , 0x02 , tempah ) ;
6505
6506     /* getlcdsync() */
6507     XGI_GetLCDSync( &tempax , &tempbx,pVBInfo ) ;
6508     tempcx = tempbx ;
6509     tempax = pVBInfo->VT ;
6510     tempbx = pVBInfo->LCDVRS ;
6511
6512     /* if ( SetLCD_Info & EnableScalingLCD ) */
6513     tempcx += tempbx ;
6514     if ( tempcx >= tempax )
6515         tempcx -= tempax ;
6516
6517     temp = tempbx & 0x00FF ;    /* RTVACTEE=lcdvrs */
6518     XGINew_SetReg1( pVBInfo->Part2Port , 0x04 , temp ) ;
6519     temp = ( tempbx & 0xFF00 ) >> 8 ;
6520     temp = temp << 4 ;
6521     temp |= ( tempcx & 0x000F ) ;
6522     XGINew_SetReg1( pVBInfo->Part2Port , 0x01 , temp ) ;
6523     tempcx = pushbx ;
6524     tempax = pVBInfo->HT ;
6525     tempbx = pVBInfo->LCDHDES ;
6526     tempbx &= 0x0FFF ;
6527
6528     if ( XGI_IsLCDDualLink(  pVBInfo ) )
6529     {
6530         tempax = tempax >> 1 ;
6531         tempbx = tempbx >> 1 ;
6532         tempcx = tempcx >> 1 ;
6533     }
6534
6535     if ( pVBInfo->VBType & VB_XGI302LV )
6536         tempbx += 1 ;
6537
6538     if ( pVBInfo->VBType & VB_XGI301C )  /* tap4 */
6539         tempbx += 1 ;
6540
6541     tempcx += tempbx ;
6542
6543     if ( tempcx >= tempax )
6544         tempcx -= tempax ;
6545
6546     temp = tempbx & 0x00FF ;
6547     XGINew_SetReg1( pVBInfo->Part2Port , 0x1F , temp ) ;        /* RHBLKE=lcdhdes */
6548     temp = ( ( tempbx & 0xFF00 ) >> 8 ) << 4 ;
6549     XGINew_SetReg1( pVBInfo->Part2Port , 0x20 , temp ) ;
6550     temp = tempcx & 0x00FF ;
6551     XGINew_SetReg1( pVBInfo->Part2Port , 0x23 , temp ) ;        /* RHEQPLE=lcdhdee */
6552     temp = ( tempcx & 0xFF00 ) >> 8 ;
6553     XGINew_SetReg1( pVBInfo->Part2Port , 0x25 , temp ) ;
6554
6555     /* getlcdsync() */
6556     XGI_GetLCDSync( &tempax , &tempbx ,pVBInfo) ;
6557     tempcx = tempax ;
6558     tempax = pVBInfo->HT ;
6559     tempbx = pVBInfo->LCDHRS ;
6560     /* if ( SetLCD_Info & EnableScalingLCD) */
6561     if ( XGI_IsLCDDualLink( pVBInfo) )
6562     {
6563         tempax = tempax >> 1 ;
6564         tempbx = tempbx >> 1 ;
6565         tempcx = tempcx >> 1 ;
6566     }
6567
6568     if ( pVBInfo->VBType & VB_XGI302LV )
6569         tempbx += 1 ;
6570
6571     tempcx += tempbx ;
6572
6573     if ( tempcx >= tempax )
6574         tempcx -= tempax ;
6575
6576     temp = tempbx & 0x00FF ;    /* RHBURSTS=lcdhrs */
6577     XGINew_SetReg1( pVBInfo->Part2Port , 0x1C , temp ) ;
6578
6579     temp = ( tempbx & 0xFF00 ) >> 8 ;
6580     temp = temp << 4 ;
6581     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x1D , ~0x0F0 , temp ) ;
6582     temp = tempcx & 0x00FF ;    /* RHSYEXP2S=lcdhre */
6583     XGINew_SetReg1( pVBInfo->Part2Port , 0x21 , temp ) ;
6584
6585     if ( !( pVBInfo->LCDInfo & LCDVESATiming ) )
6586     {
6587         if ( pVBInfo->VGAVDE == 525 )
6588         {
6589             if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
6590             {
6591                 temp = 0xC6 ;
6592             }
6593             else
6594                 temp = 0xC4 ;
6595
6596             XGINew_SetReg1( pVBInfo->Part2Port , 0x2f , temp ) ;
6597             XGINew_SetReg1( pVBInfo->Part2Port , 0x30 , 0xB3 ) ;
6598         }
6599
6600         if ( pVBInfo->VGAVDE == 420 )
6601         {
6602             if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
6603             {
6604                 temp = 0x4F ;
6605             }
6606             else
6607                 temp = 0x4E ;
6608             XGINew_SetReg1( pVBInfo->Part2Port , 0x2f , temp ) ;
6609         }
6610     }
6611 }
6612
6613
6614 /* --------------------------------------------------------------------- */
6615 /* Function : XGI_GetTap4Ptr */
6616 /* Input : */
6617 /* Output : di -> Tap4 Reg. Setting Pointer */
6618 /* Description : */
6619 /* --------------------------------------------------------------------- */
6620 XGI301C_Tap4TimingStruct* XGI_GetTap4Ptr(USHORT tempcx, PVB_DEVICE_INFO pVBInfo)
6621 {
6622     USHORT tempax ,
6623            tempbx ,
6624            i ;
6625
6626     XGI301C_Tap4TimingStruct *Tap4TimingPtr ;
6627
6628     if ( tempcx == 0 )
6629     {
6630         tempax = pVBInfo->VGAHDE ;
6631         tempbx = pVBInfo->HDE ;
6632     }
6633     else
6634     {
6635         tempax = pVBInfo->VGAVDE ;
6636         tempbx = pVBInfo->VDE ;
6637     }
6638
6639     if ( tempax < tempbx )
6640         return &EnlargeTap4Timing[ 0 ] ;
6641     else if( tempax == tempbx )
6642         return &NoScaleTap4Timing[ 0 ] ;        /* 1:1 */
6643     else
6644         Tap4TimingPtr = NTSCTap4Timing ;        /* NTSC */
6645
6646     if ( pVBInfo->TVInfo & SetPALTV )
6647         Tap4TimingPtr = PALTap4Timing ;
6648
6649
6650     if ( pVBInfo->VBInfo & SetCRT2ToYPbPr )
6651     {
6652         if ( pVBInfo->TVInfo & SetYPbPrMode525i )
6653             Tap4TimingPtr = YPbPr525iTap4Timing ;
6654         if ( pVBInfo->TVInfo & SetYPbPrMode525p )
6655             Tap4TimingPtr = YPbPr525pTap4Timing ;
6656         if ( pVBInfo->TVInfo & SetYPbPrMode750p )
6657             Tap4TimingPtr = YPbPr750pTap4Timing ;
6658     }
6659
6660     if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
6661         Tap4TimingPtr = HiTVTap4Timing ;
6662
6663     i = 0 ;
6664     while( Tap4TimingPtr[ i ].DE != 0xFFFF )
6665     {
6666         if ( Tap4TimingPtr[ i ].DE == tempax )
6667             break ;
6668         i++ ;
6669     }
6670     return &Tap4TimingPtr[ i ] ;
6671 }
6672
6673
6674 /* --------------------------------------------------------------------- */
6675 /* Function : XGI_SetTap4Regs */
6676 /* Input : */
6677 /* Output : */
6678 /* Description : */
6679 /* --------------------------------------------------------------------- */
6680 void XGI_SetTap4Regs( PVB_DEVICE_INFO pVBInfo)
6681 {
6682     USHORT i ,
6683            j ;
6684
6685     XGI301C_Tap4TimingStruct *Tap4TimingPtr ;
6686
6687     if ( !( pVBInfo->VBType & VB_XGI301C ) )
6688         return ;
6689
6690 #ifndef Tap4
6691     XGINew_SetRegAND( pVBInfo->Part2Port , 0x4E , 0xEB ) ;      /* Disable Tap4 */
6692 #else            /* Tap4 Setting */
6693
6694     Tap4TimingPtr = XGI_GetTap4Ptr( 0 , pVBInfo) ;  /* Set Horizontal Scaling */
6695     for( i = 0x80 , j = 0 ; i <= 0xBF ; i++ , j++ )
6696         XGINew_SetReg1( pVBInfo->Part2Port , i , Tap4TimingPtr->Reg[ j ] ) ;
6697
6698     if ( ( pVBInfo->VBInfo & SetCRT2ToTV ) && ( !( pVBInfo->VBInfo & SetCRT2ToHiVisionTV ) ) )
6699     {
6700         Tap4TimingPtr = XGI_GetTap4Ptr( 1 , pVBInfo);   /* Set Vertical Scaling */
6701         for( i = 0xC0 , j = 0 ; i < 0xFF ; i++ , j++ )
6702             XGINew_SetReg1( pVBInfo->Part2Port , i , Tap4TimingPtr->Reg[ j ] ) ;
6703     }
6704
6705     if ( ( pVBInfo->VBInfo & SetCRT2ToTV ) && ( !( pVBInfo->VBInfo & SetCRT2ToHiVisionTV ) ) )
6706         XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x4E , ~0x14 , 0x04 ) ;        /* Enable V.Scaling */
6707     else
6708         XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x4E , ~0x14 , 0x10 ) ;        /* Enable H.Scaling */
6709 #endif
6710 }
6711
6712 /* --------------------------------------------------------------------- */
6713 /* Function : XGI_SetGroup3 */
6714 /* Input : */
6715 /* Output : */
6716 /* Description : */
6717 /* --------------------------------------------------------------------- */
6718 void XGI_SetGroup3(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo)
6719 {
6720     USHORT i;
6721     UCHAR *tempdi;
6722     USHORT  modeflag;
6723
6724     if(ModeNo<=0x13)
6725     {
6726         modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;      /* si+St_ResInfo */
6727     }
6728     else
6729     {
6730         modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;     /* si+Ext_ResInfo */
6731     }
6732
6733
6734     XGINew_SetReg1(pVBInfo->Part3Port,0x00,0x00);
6735     if(pVBInfo->TVInfo&SetPALTV)
6736     {
6737         XGINew_SetReg1(pVBInfo->Part3Port,0x13,0xFA);
6738         XGINew_SetReg1(pVBInfo->Part3Port,0x14,0xC8);
6739     }
6740     else
6741     {
6742         XGINew_SetReg1(pVBInfo->Part3Port,0x13,0xF5);
6743         XGINew_SetReg1(pVBInfo->Part3Port,0x14,0xB7);
6744     }
6745
6746     if(!(pVBInfo->VBInfo&SetCRT2ToTV))
6747     {
6748         return;
6749     }
6750
6751     if(pVBInfo->TVInfo&SetPALMTV)
6752     {
6753         XGINew_SetReg1(pVBInfo->Part3Port,0x13,0xFA);
6754         XGINew_SetReg1(pVBInfo->Part3Port,0x14,0xC8);
6755         XGINew_SetReg1(pVBInfo->Part3Port,0x3D,0xA8);
6756     }
6757
6758     if((pVBInfo->VBInfo&SetCRT2ToHiVisionTV)|| (pVBInfo->VBInfo&SetCRT2ToYPbPr))
6759     {
6760         if(pVBInfo->TVInfo & SetYPbPrMode525i)
6761         {
6762             return;
6763         }
6764         tempdi=pVBInfo->HiTVGroup3Data;
6765         if(pVBInfo->SetFlag&TVSimuMode)
6766         {
6767             tempdi=pVBInfo->HiTVGroup3Simu;
6768             if(!(modeflag&Charx8Dot))
6769             {
6770                 tempdi=pVBInfo->HiTVGroup3Text;
6771             }
6772         }
6773
6774         if(pVBInfo->TVInfo & SetYPbPrMode525p)
6775         {
6776             tempdi=pVBInfo->Ren525pGroup3;
6777         }
6778         if(pVBInfo->TVInfo & SetYPbPrMode750p)
6779         {
6780              tempdi=pVBInfo->Ren750pGroup3;
6781         }
6782
6783         for(i=0;i<=0x3E;i++)
6784         {
6785             XGINew_SetReg1(pVBInfo->Part3Port,i,tempdi[i]);
6786         }
6787         if(pVBInfo->VBType&VB_XGI301C)  /* Marcovision */
6788         {
6789             if(pVBInfo->TVInfo & SetYPbPrMode525p)
6790             {
6791                 XGINew_SetReg1(pVBInfo->Part3Port,0x28,0x3f);
6792             }
6793         }
6794     }
6795     return;
6796 }  /* {end of XGI_SetGroup3} */
6797
6798
6799 /* --------------------------------------------------------------------- */
6800 /* Function : XGI_SetGroup4 */
6801 /* Input : */
6802 /* Output : */
6803 /* Description : */
6804 /* --------------------------------------------------------------------- */
6805 void XGI_SetGroup4(USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex,PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
6806 {
6807     USHORT tempax ,
6808            tempcx ,
6809            tempbx ,
6810            modeflag ,
6811            temp ,
6812            temp2 ;
6813
6814     ULONG tempebx ,
6815           tempeax ,
6816           templong ;
6817
6818
6819     if ( ModeNo <= 0x13 )
6820     {
6821         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;   /* si+St_ResInfo */
6822     }
6823     else
6824     {
6825         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;  /* si+Ext_ResInfo */
6826     }
6827
6828     temp = pVBInfo->RVBHCFACT ;
6829     XGINew_SetReg1( pVBInfo->Part4Port , 0x13 , temp ) ;
6830
6831     tempbx = pVBInfo->RVBHCMAX ;
6832     temp = tempbx & 0x00FF ;
6833     XGINew_SetReg1( pVBInfo->Part4Port , 0x14 , temp ) ;
6834     temp2 = ( ( tempbx & 0xFF00 ) >> 8 ) << 7 ;
6835     tempcx = pVBInfo->VGAHT - 1 ;
6836     temp = tempcx & 0x00FF ;
6837     XGINew_SetReg1( pVBInfo->Part4Port , 0x16 , temp ) ;
6838
6839     temp =( ( tempcx & 0xFF00 ) >> 8 ) << 3 ;
6840     temp2 |= temp ;
6841
6842     tempcx = pVBInfo->VGAVT - 1 ;
6843     if ( !( pVBInfo->VBInfo & SetCRT2ToTV ) )
6844     {
6845         tempcx -= 5 ;
6846     }
6847
6848     temp = tempcx & 0x00FF ;
6849     XGINew_SetReg1( pVBInfo->Part4Port , 0x17 , temp ) ;
6850     temp = temp2 | ( ( tempcx & 0xFF00 ) >> 8 ) ;
6851     XGINew_SetReg1( pVBInfo->Part4Port , 0x15 , temp ) ;
6852     XGINew_SetRegOR( pVBInfo->Part4Port , 0x0D , 0x08 ) ;
6853     tempcx = pVBInfo->VBInfo ;
6854     tempbx = pVBInfo->VGAHDE ;
6855
6856     if ( modeflag & HalfDCLK )
6857     {
6858         tempbx = tempbx >> 1 ;
6859     }
6860
6861     if ( XGI_IsLCDDualLink( pVBInfo ) )
6862         tempbx = tempbx >> 1 ;
6863
6864     if(tempcx&SetCRT2ToHiVisionTV)
6865     {
6866         temp=0;
6867         if(tempbx<=1024)
6868             temp=0xA0;
6869        if(tempbx == 1280)
6870           temp = 0xC0;
6871     }
6872     else if(tempcx&SetCRT2ToTV)
6873     {
6874          temp=0xA0;
6875          if(tempbx <= 800)
6876              temp=0x80;
6877     }
6878     else
6879     {
6880          temp=0x80;
6881          if(pVBInfo->VBInfo&SetCRT2ToLCD)
6882          {
6883              temp=0;
6884              if(tempbx>800)
6885                  temp=0x60;
6886          }
6887     }
6888
6889     if ( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p ) )
6890     {
6891         temp = 0x00 ;
6892         if ( pVBInfo->VGAHDE == 1280 )
6893             temp = 0x40 ;
6894         if ( pVBInfo->VGAHDE == 1024 )
6895             temp = 0x20 ;
6896     }
6897     XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x0E , ~0xEF , temp ) ;
6898
6899     tempebx = pVBInfo->VDE ;
6900
6901     if ( tempcx & SetCRT2ToHiVisionTV )
6902     {
6903         if ( !( temp & 0xE000 ) )
6904             tempbx = tempbx >> 1 ;
6905     }
6906
6907     tempcx = pVBInfo->RVBHRS ;
6908     temp = tempcx & 0x00FF ;
6909     XGINew_SetReg1( pVBInfo->Part4Port , 0x18 , temp );
6910
6911     tempeax = pVBInfo->VGAVDE ;
6912     tempcx |= 0x04000 ;
6913
6914
6915     if ( tempeax <= tempebx )
6916     {
6917         tempcx=(tempcx&(~0x4000));
6918         tempeax = pVBInfo->VGAVDE ;
6919     }
6920     else
6921     {
6922         tempeax -= tempebx ;
6923     }
6924
6925
6926     templong = ( tempeax * 256 * 1024 ) % tempebx ;
6927     tempeax = ( tempeax * 256 * 1024 ) / tempebx ;
6928     tempebx = tempeax ;
6929
6930     if ( templong != 0 )
6931     {
6932         tempebx++ ;
6933     }
6934
6935
6936     temp = ( USHORT )( tempebx & 0x000000FF ) ;
6937     XGINew_SetReg1( pVBInfo->Part4Port , 0x1B , temp ) ;
6938
6939     temp = ( USHORT )( ( tempebx & 0x0000FF00 ) >> 8 ) ;
6940     XGINew_SetReg1( pVBInfo->Part4Port , 0x1A , temp ) ;
6941     tempbx = ( USHORT )( tempebx >> 16 ) ;
6942     temp = tempbx & 0x00FF ;
6943     temp = temp << 4 ;
6944     temp |= ( ( tempcx & 0xFF00 ) >> 8 ) ;
6945     XGINew_SetReg1( pVBInfo->Part4Port , 0x19 , temp ) ;
6946
6947     /* 301b */
6948     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
6949     {
6950         temp = 0x0028 ;
6951         XGINew_SetReg1( pVBInfo->Part4Port , 0x1C , temp ) ;
6952         tempax = pVBInfo->VGAHDE ;
6953         if ( modeflag & HalfDCLK )
6954         {
6955             tempax = tempax >> 1 ;
6956         }
6957
6958         if ( XGI_IsLCDDualLink( pVBInfo ) )
6959             tempax = tempax >> 1 ;
6960
6961         /* if((pVBInfo->VBInfo&(SetCRT2ToLCD))||((pVBInfo->TVInfo&SetYPbPrMode525p)||(pVBInfo->TVInfo&SetYPbPrMode750p))) { */
6962         if ( pVBInfo->VBInfo & SetCRT2ToLCD )
6963         {
6964             if ( tempax > 800 )
6965                 tempax -= 800 ;
6966         }
6967         else
6968         {
6969             if ( pVBInfo->VGAHDE > 800 )
6970             {
6971                 if ( pVBInfo->VGAHDE == 1024 )
6972                     tempax = ( tempax * 25 / 32 ) - 1 ;
6973                 else
6974                     tempax = ( tempax * 20 / 32 ) - 1 ;
6975             }
6976         }
6977         tempax -= 1 ;
6978
6979 /*
6980         if ( pVBInfo->VBInfo & ( SetCRT2ToTV | SetCRT2ToHiVisionTV ) )
6981         {
6982             if ( pVBInfo->VBType & VB_XGI301LV )
6983             {
6984                 if ( !( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p | SetYPbPrMode1080i ) ) )
6985                 {
6986                     if ( pVBInfo->VGAHDE > 800 )
6987                     {
6988                         if ( pVBInfo->VGAHDE == 1024 )
6989                             tempax = ( tempax * 25 / 32 ) - 1 ;
6990                         else
6991                             tempax = ( tempax * 20 / 32 ) - 1 ;
6992                     }
6993                 }
6994             }
6995             else
6996             {
6997                 if ( pVBInfo->VGAHDE > 800 )
6998                 {
6999                     if ( pVBInfo->VGAHDE == 1024 )
7000                         tempax = ( tempax * 25 / 32 ) - 1 ;
7001                     else
7002                         tempax = ( tempax * 20 / 32 ) - 1 ;
7003                 }
7004             }
7005         }
7006 */
7007
7008         temp = ( tempax & 0xFF00 ) >> 8 ;
7009         temp = ( ( temp & 0x0003 ) << 4 ) ;
7010         XGINew_SetReg1( pVBInfo->Part4Port , 0x1E , temp ) ;
7011         temp = ( tempax & 0x00FF ) ;
7012         XGINew_SetReg1( pVBInfo->Part4Port , 0x1D , temp ) ;
7013
7014         if ( pVBInfo->VBInfo & ( SetCRT2ToTV | SetCRT2ToHiVisionTV ) )
7015         {
7016             if ( pVBInfo->VGAHDE > 800 )
7017             {
7018                 XGINew_SetRegOR( pVBInfo->Part4Port , 0x1E , 0x08 ) ;
7019             }
7020         }
7021         temp = 0x0036 ;
7022
7023         if ( pVBInfo->VBInfo & SetCRT2ToTV )
7024         {
7025             if ( !( pVBInfo->TVInfo & ( NTSC1024x768 | SetYPbPrMode525p | SetYPbPrMode750p | SetYPbPrMode1080i ) ) )
7026             {
7027                 temp |= 0x0001 ;
7028                 if ( ( pVBInfo->VBInfo & SetInSlaveMode ) && ( !( pVBInfo->TVInfo & TVSimuMode ) ) )
7029                     temp &= ( ~0x0001 ) ;
7030             }
7031         }
7032
7033         XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x1F , 0x00C0 , temp ) ;
7034         tempbx = pVBInfo->HT ;
7035         if ( XGI_IsLCDDualLink( pVBInfo ) )
7036             tempbx = tempbx >> 1 ;
7037         tempbx = ( tempbx >> 1 ) - 2 ;
7038         temp = ( ( tempbx & 0x0700 ) >> 8 ) << 3 ;
7039         XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x21 , 0x00C0 , temp ) ;
7040         temp = tempbx & 0x00FF ;
7041         XGINew_SetReg1( pVBInfo->Part4Port , 0x22 , temp ) ;
7042     }
7043     /* end 301b */
7044
7045     if ( pVBInfo->ISXPDOS == 0 )
7046         XGI_SetCRT2VCLK( ModeNo , ModeIdIndex , RefreshRateTableIndex, pVBInfo ) ;
7047 }
7048
7049
7050 /* --------------------------------------------------------------------- */
7051 /* Function : XGI_SetGroup5 */
7052 /* Input : */
7053 /* Output : */
7054 /* Description : */
7055 /* --------------------------------------------------------------------- */
7056 void XGI_SetGroup5( USHORT ModeNo , USHORT ModeIdIndex , PVB_DEVICE_INFO pVBInfo)
7057 {
7058     USHORT Pindex ,
7059            Pdata ;
7060
7061     Pindex = pVBInfo->Part5Port ;
7062     Pdata = pVBInfo->Part5Port + 1 ;
7063     if ( pVBInfo->ModeType == ModeVGA )
7064     {
7065         if ( !( pVBInfo->VBInfo & ( SetInSlaveMode | LoadDACFlag | CRT2DisplayFlag ) ) )
7066         {
7067             XGINew_EnableCRT2(pVBInfo) ;
7068             /* LoadDAC2(pVBInfo->Part5Port,ModeNo,ModeIdIndex); */
7069         }
7070     }
7071     return ;
7072 }
7073
7074
7075 /* --------------------------------------------------------------------- */
7076 /* Function : XGI_GetLcdPtr */
7077 /* Input : */
7078 /* Output : */
7079 /* Description : */
7080 /* --------------------------------------------------------------------- */
7081 void* XGI_GetLcdPtr( USHORT BX , USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
7082 {
7083     USHORT i ,
7084            tempdx ,
7085            tempcx ,
7086            tempbx ,
7087            tempal ,
7088            modeflag ,
7089            table ;
7090
7091     XGI330_LCDDataTablStruct *tempdi = 0 ;
7092
7093
7094     tempbx = BX;
7095
7096     if ( ModeNo <= 0x13 )
7097     {
7098         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
7099         tempal = pVBInfo->SModeIDTable[ ModeIdIndex ].St_CRT2CRTC ;
7100     }
7101     else
7102     {
7103         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
7104         tempal = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT2CRTC ;
7105     }
7106
7107     tempal = tempal & 0x0f ;
7108
7109     if ( tempbx <= 1 )          /* ExpLink */
7110     {
7111         if ( ModeNo <= 0x13 )
7112         {
7113             tempal = pVBInfo->SModeIDTable[ ModeIdIndex ].St_CRT2CRTC ; /* find no Ext_CRT2CRTC2 */
7114         }
7115         else
7116         {
7117             tempal= pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT2CRTC ;
7118         }
7119
7120         if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
7121         {
7122             if ( ModeNo <= 0x13 )
7123                 tempal = pVBInfo->SModeIDTable[ ModeIdIndex ].St_CRT2CRTC2 ;
7124             else
7125                 tempal= pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT2CRTC2 ;
7126         }
7127
7128         if ( tempbx & 0x01 )
7129             tempal = ( tempal >> 4 ) ;
7130
7131         tempal = ( tempal & 0x0f ) ;
7132     }
7133
7134     tempcx = LCDLenList[ tempbx ] ;     /* mov cl,byte ptr cs:LCDLenList[bx] */
7135
7136     if ( pVBInfo->LCDInfo & EnableScalingLCD )  /* ScaleLCD */
7137     {
7138         if ( ( tempbx == 5 ) || ( tempbx ) == 7 )
7139             tempcx = LCDDesDataLen2 ;
7140         else if ( ( tempbx == 3 ) || ( tempbx == 8 ) )
7141             tempcx = LVDSDesDataLen2 ;
7142     }
7143     /* mov di, word ptr cs:LCDDataList[bx] */
7144     /* tempdi=pVideoMemory[LCDDataList+tempbx*2]|(pVideoMemory[LCDDataList+tempbx*2+1]<<8); */
7145
7146     switch( tempbx )
7147     {
7148         case 0:
7149             tempdi = XGI_EPLLCDCRT1Ptr_H ;
7150             break ;
7151         case 1:
7152             tempdi = XGI_EPLLCDCRT1Ptr_V ;
7153              break ;
7154         case 2:
7155             tempdi = XGI_EPLLCDDataPtr ;
7156             break ;
7157         case 3:
7158             tempdi = XGI_EPLLCDDesDataPtr ;
7159             break ;
7160         case 4:
7161             tempdi = XGI_LCDDataTable ;
7162             break ;
7163         case 5:
7164             tempdi = XGI_LCDDesDataTable ;
7165             break ;
7166         case 6:
7167             tempdi = XGI_EPLCHLCDRegPtr ;
7168             break ;
7169         case 7:
7170         case 8:
7171         case 9:
7172             tempdi = 0 ;
7173             break ;
7174         default:
7175         break ;
7176     }
7177
7178     if ( tempdi == 0x00 )  /* OEMUtil */
7179         return 0 ;
7180
7181     table = tempbx ;
7182     i = 0 ;
7183
7184     while( tempdi[ i ].PANELID != 0xff )
7185     {
7186         tempdx = pVBInfo->LCDResInfo ;
7187         if ( tempbx & 0x0080 )     /* OEMUtil */
7188         {
7189             tempbx &= ( ~0x0080 ) ;
7190             tempdx = pVBInfo->LCDTypeInfo ;
7191         }
7192
7193         if ( pVBInfo->LCDInfo & EnableScalingLCD )
7194         tempdx &= ( ~PanelResInfo ) ;
7195
7196         if ( tempdi[ i ].PANELID == tempdx )
7197         {
7198             tempbx = tempdi[ i ].MASK ;
7199             tempdx = pVBInfo->LCDInfo ;
7200
7201             if ( ModeNo <= 0x13 )         /* alan 09/10/2003 */
7202                 tempdx |= SetLCDStdMode ;
7203
7204             if ( modeflag & HalfDCLK )
7205                 tempdx |= SetLCDLowResolution ;
7206
7207             tempbx &= tempdx;
7208             if ( tempbx == tempdi[ i ].CAP )
7209                 break ;
7210         }
7211         i++ ;
7212     }
7213
7214     if ( table == 0 )
7215     {
7216         switch( tempdi[ i ].DATAPTR )
7217         {
7218             case 0:
7219                 return &XGI_LVDSCRT11024x768_1_H[ tempal ] ;
7220                 break ;
7221             case 1:
7222                 return &XGI_LVDSCRT11024x768_2_H[ tempal ] ;
7223                 break ;
7224             case 2:
7225                 return &XGI_LVDSCRT11280x1024_1_H[ tempal ] ;
7226                 break ;
7227             case 3:
7228                 return &XGI_LVDSCRT11280x1024_2_H[ tempal ] ;
7229                 break ;
7230             case 4:
7231                 return &XGI_LVDSCRT11400x1050_1_H[ tempal ] ;
7232                 break ;
7233             case 5:
7234                 return &XGI_LVDSCRT11400x1050_2_H[ tempal ] ;
7235                 break ;
7236             case 6:
7237                 return &XGI_LVDSCRT11600x1200_1_H[ tempal ] ;
7238                 break ;
7239             case 7:
7240                 return &XGI_LVDSCRT11024x768_1_Hx75[ tempal ] ;
7241                 break ;
7242             case 8:
7243                 return &XGI_LVDSCRT11024x768_2_Hx75[ tempal ] ;
7244                 break ;
7245             case 9:
7246                 return &XGI_LVDSCRT11280x1024_1_Hx75[ tempal ] ;
7247                 break ;
7248             case 10:
7249                 return &XGI_LVDSCRT11280x1024_2_Hx75[ tempal ] ;
7250                 break ;
7251             default:
7252                 break ;
7253         }
7254     }
7255     else if ( table == 1 )
7256     {
7257         switch( tempdi[ i ].DATAPTR )
7258         {
7259             case 0:
7260                 return &XGI_LVDSCRT11024x768_1_V[ tempal ] ;
7261                 break ;
7262             case 1:
7263                 return &XGI_LVDSCRT11024x768_2_V[ tempal ] ;
7264                 break ;
7265             case 2:
7266                 return &XGI_LVDSCRT11280x1024_1_V[ tempal ] ;
7267                 break ;
7268             case 3:
7269                 return &XGI_LVDSCRT11280x1024_2_V[ tempal ] ;
7270                 break ;
7271             case 4:
7272                 return &XGI_LVDSCRT11400x1050_1_V[ tempal ] ;
7273                 break ;
7274             case 5:
7275                 return &XGI_LVDSCRT11400x1050_2_V[ tempal ] ;
7276                 break ;
7277             case 6:
7278                 return &XGI_LVDSCRT11600x1200_1_V[ tempal ] ;
7279                 break ;
7280             case 7:
7281                 return &XGI_LVDSCRT11024x768_1_Vx75[ tempal ] ;
7282                 break ;
7283             case 8:
7284                 return &XGI_LVDSCRT11024x768_2_Vx75[ tempal ] ;
7285                 break ;
7286             case 9:
7287                 return &XGI_LVDSCRT11280x1024_1_Vx75[ tempal ] ;
7288                 break ;
7289             case 10:
7290                 return &XGI_LVDSCRT11280x1024_2_Vx75[ tempal ] ;
7291                 break ;
7292             default:
7293                 break ;
7294         }
7295     }
7296     else if ( table == 2 )
7297     {
7298         switch( tempdi[ i ].DATAPTR )
7299         {
7300             case 0:
7301                 return &XGI_LVDS1024x768Data_1[ tempal ] ;
7302                 break ;
7303             case 1:
7304                 return &XGI_LVDS1024x768Data_2[ tempal ] ;
7305                 break ;
7306             case 2:
7307                 return &XGI_LVDS1280x1024Data_1[ tempal ] ;
7308                 break ;
7309             case 3:
7310                 return &XGI_LVDS1280x1024Data_2[ tempal ] ;
7311                 break ;
7312             case 4:
7313                 return &XGI_LVDS1400x1050Data_1[ tempal ] ;
7314                 break ;
7315             case 5:
7316                 return &XGI_LVDS1400x1050Data_2[ tempal ] ;
7317                 break ;
7318             case 6:
7319                 return &XGI_LVDS1600x1200Data_1[ tempal ] ;
7320                 break ;
7321             case 7:
7322                 return &XGI_LVDSNoScalingData[ tempal ] ;
7323                 break ;
7324             case 8:
7325                 return &XGI_LVDS1024x768Data_1x75[ tempal ] ;
7326                 break ;
7327             case 9:
7328                 return &XGI_LVDS1024x768Data_2x75[ tempal ] ;
7329                 break ;
7330             case 10:
7331                 return &XGI_LVDS1280x1024Data_1x75[ tempal ] ;
7332                 break ;
7333             case 11:
7334                 return &XGI_LVDS1280x1024Data_2x75[ tempal ] ;
7335                 break ;
7336             case 12:
7337                 return &XGI_LVDSNoScalingDatax75[ tempal ] ;
7338                 break ;
7339             default:
7340                 break ;
7341         }
7342     }
7343     else if ( table == 3 )
7344     {
7345         switch( tempdi[ i ].DATAPTR )
7346         {
7347             case 0:
7348                 return &XGI_LVDS1024x768Des_1[ tempal ] ;
7349                 break ;
7350             case 1:
7351                 return &XGI_LVDS1024x768Des_3[ tempal ] ;
7352                 break ;
7353             case 2:
7354                 return &XGI_LVDS1024x768Des_2[ tempal ] ;
7355                 break ;
7356             case 3:
7357                 return &XGI_LVDS1280x1024Des_1[ tempal ] ;
7358                 break ;
7359             case 4:
7360                 return &XGI_LVDS1280x1024Des_2[ tempal ] ;
7361                 break ;
7362             case 5:
7363                 return &XGI_LVDS1400x1050Des_1[ tempal ] ;
7364                 break ;
7365             case 6:
7366                 return &XGI_LVDS1400x1050Des_2[ tempal ] ;
7367                 break ;
7368             case 7:
7369                 return &XGI_LVDS1600x1200Des_1[ tempal ] ;
7370                 break ;
7371             case 8:
7372                 return &XGI_LVDSNoScalingDesData[ tempal ] ;
7373                 break ;
7374             case 9:
7375                 return &XGI_LVDS1024x768Des_1x75[ tempal ] ;
7376                 break ;
7377             case 10:
7378                 return &XGI_LVDS1024x768Des_3x75[ tempal ] ;
7379                 break ;
7380             case 11:
7381                 return &XGI_LVDS1024x768Des_2x75[ tempal ] ;
7382                 break;
7383             case 12:
7384                 return &XGI_LVDS1280x1024Des_1x75[ tempal ] ;
7385                 break ;
7386             case 13:
7387                 return &XGI_LVDS1280x1024Des_2x75[ tempal ] ;
7388                 break ;
7389             case 14:
7390                 return &XGI_LVDSNoScalingDesDatax75[ tempal ] ;
7391                 break ;
7392             default:
7393                 break ;
7394         }
7395     }
7396     else if ( table == 4 )
7397     {
7398         switch( tempdi[ i ].DATAPTR )
7399         {
7400             case 0:
7401                 return &XGI_ExtLCD1024x768Data[ tempal ] ;
7402                 break ;
7403             case 1:
7404                 return &XGI_StLCD1024x768Data[ tempal ] ;
7405                 break ;
7406             case 2:
7407                 return &XGI_CetLCD1024x768Data[ tempal ] ;
7408                 break ;
7409             case 3:
7410                 return &XGI_ExtLCD1280x1024Data[ tempal ] ;
7411                 break ;
7412             case 4:
7413                 return &XGI_StLCD1280x1024Data[ tempal ] ;
7414                 break ;
7415             case 5:
7416                 return &XGI_CetLCD1280x1024Data[ tempal ] ;
7417                 break ;
7418             case 6:
7419                 return &XGI_ExtLCD1400x1050Data[ tempal ] ;
7420                 break ;
7421             case 7:
7422                 return &XGI_StLCD1400x1050Data[ tempal ] ;
7423                 break ;
7424             case 8:
7425                 return &XGI_CetLCD1400x1050Data[ tempal ] ;
7426                 break ;
7427             case 9:
7428                 return &XGI_ExtLCD1600x1200Data[ tempal ] ;
7429                 break  ;
7430             case 10:
7431                 return &XGI_StLCD1600x1200Data[ tempal ] ;
7432                 break ;
7433             case 11:
7434                 return &XGI_NoScalingData[ tempal ] ;
7435                 break ;
7436             case 12:
7437                 return &XGI_ExtLCD1024x768x75Data[ tempal ] ;
7438                 break ;
7439             case 13:
7440                 return &XGI_ExtLCD1024x768x75Data[ tempal ] ;
7441                 break ;
7442             case 14:
7443                 return &XGI_CetLCD1024x768x75Data[ tempal ] ;
7444                 break ;
7445             case 15:
7446                  return &XGI_ExtLCD1280x1024x75Data[ tempal ] ;
7447                 break ;
7448             case 16:
7449                 return &XGI_StLCD1280x1024x75Data[ tempal ] ;
7450                 break;
7451             case 17:
7452                 return &XGI_CetLCD1280x1024x75Data[ tempal ] ;
7453                 break;
7454             case 18:
7455                 return &XGI_NoScalingDatax75[ tempal ] ;
7456                 break ;
7457             default:
7458                 break ;
7459         }
7460     }
7461     else if ( table == 5 )
7462     {
7463         switch( tempdi[ i ].DATAPTR )
7464         {
7465             case 0:
7466                 return &XGI_ExtLCDDes1024x768Data[ tempal ] ;
7467                 break ;
7468             case 1:
7469                 return &XGI_StLCDDes1024x768Data[ tempal ] ;
7470                 break ;
7471             case 2:
7472                 return &XGI_CetLCDDes1024x768Data[ tempal ] ;
7473                 break ;
7474             case 3:
7475                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7476                     return &XGI_ExtLCDDLDes1280x1024Data[ tempal ] ;
7477                 else
7478                     return &XGI_ExtLCDDes1280x1024Data[ tempal ] ;
7479                 break ;
7480             case 4:
7481                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7482                     return &XGI_StLCDDLDes1280x1024Data[ tempal ] ;
7483                 else
7484                     return &XGI_StLCDDes1280x1024Data[ tempal ] ;
7485                 break ;
7486             case 5:
7487                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7488                     return &XGI_CetLCDDLDes1280x1024Data[ tempal ] ;
7489                 else
7490                     return &XGI_CetLCDDes1280x1024Data[ tempal ] ;
7491                 break ;
7492             case 6:
7493                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7494                     return &XGI_ExtLCDDLDes1400x1050Data[ tempal ] ;
7495                 else
7496                     return &XGI_ExtLCDDes1400x1050Data[ tempal ] ;
7497                 break ;
7498             case 7:
7499                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7500                     return &XGI_StLCDDLDes1400x1050Data[ tempal ] ;
7501                 else
7502                     return &XGI_StLCDDes1400x1050Data[ tempal ] ;
7503                 break ;
7504             case 8:
7505                 return &XGI_CetLCDDes1400x1050Data[ tempal ] ;
7506                 break ;
7507             case 9:
7508                 return &XGI_CetLCDDes1400x1050Data2[ tempal ] ;
7509                 break ;
7510             case 10:
7511                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7512                     return &XGI_ExtLCDDLDes1600x1200Data[ tempal ] ;
7513                 else
7514                     return &XGI_ExtLCDDes1600x1200Data[ tempal ] ;
7515                 break ;
7516             case 11:
7517                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7518                     return &XGI_StLCDDLDes1600x1200Data[ tempal ] ;
7519                 else
7520                     return &XGI_StLCDDes1600x1200Data[ tempal ] ;
7521                 break ;
7522             case 12:
7523                 return &XGI_NoScalingDesData[ tempal ] ;
7524                 break;
7525             case 13:
7526                 return &XGI_ExtLCDDes1024x768x75Data[ tempal ] ;
7527                 break ;
7528             case 14:
7529                 return &XGI_StLCDDes1024x768x75Data[ tempal ] ;
7530                 break ;
7531             case 15:
7532                 return &XGI_CetLCDDes1024x768x75Data[ tempal ] ;
7533                 break ;
7534             case 16:
7535                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7536                     return &XGI_ExtLCDDLDes1280x1024x75Data[ tempal ] ;
7537                 else
7538                     return &XGI_ExtLCDDes1280x1024x75Data[ tempal ] ;
7539                 break ;
7540             case 17:
7541                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7542                     return &XGI_StLCDDLDes1280x1024x75Data[ tempal ] ;
7543                 else
7544                     return &XGI_StLCDDes1280x1024x75Data[ tempal ] ;
7545                 break ;
7546             case 18:
7547                 if ( ( pVBInfo->VBType & VB_XGI301LV ) || ( pVBInfo->VBType & VB_XGI302LV ) )
7548                     return &XGI_CetLCDDLDes1280x1024x75Data[ tempal ] ;
7549                 else
7550                     return &XGI_CetLCDDes1280x1024x75Data[ tempal ] ;
7551                 break ;
7552             case 19:
7553                 return &XGI_NoScalingDesDatax75[ tempal ] ;
7554                 break ;
7555             default:
7556                 break ;
7557         }
7558     }
7559     else if ( table == 6 )
7560     {
7561         switch( tempdi[ i ].DATAPTR )
7562         {
7563             case 0:
7564                 return &XGI_CH7017LV1024x768[ tempal ] ;
7565                 break ;
7566             case 1:
7567                 return &XGI_CH7017LV1400x1050[ tempal ] ;
7568                 break ;
7569             default:
7570                 break ;
7571         }
7572     }
7573     return 0 ;
7574 }
7575
7576
7577 /* --------------------------------------------------------------------- */
7578 /* Function : XGI_GetTVPtr */
7579 /* Input : */
7580 /* Output : */
7581 /* Description : */
7582 /* --------------------------------------------------------------------- */
7583 void* XGI_GetTVPtr (USHORT BX,USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
7584 {
7585     USHORT i , tempdx , tempbx , tempal , modeflag , table ;
7586     XGI330_TVDataTablStruct *tempdi = 0 ;
7587
7588     tempbx = BX ;
7589
7590     if ( ModeNo <= 0x13 )
7591     {
7592         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
7593         tempal = pVBInfo->SModeIDTable[ ModeIdIndex ].St_CRT2CRTC ;
7594     }
7595     else
7596     {
7597         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
7598         tempal = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT2CRTC ;
7599     }
7600
7601     tempal = tempal & 0x3f ;
7602     table = tempbx ;
7603
7604     switch( tempbx )
7605     {
7606         case 0:
7607             tempdi = 0 ;        /*EPLCHTVCRT1Ptr_H;*/
7608             if ( pVBInfo->IF_DEF_CH7007 == 1 )
7609             {
7610                 tempdi = XGI_EPLCHTVCRT1Ptr;
7611             }
7612             break ;
7613         case 1:
7614             tempdi = 0 ;        /*EPLCHTVCRT1Ptr_V;*/
7615             if ( pVBInfo->IF_DEF_CH7007 == 1 )
7616             {
7617                 tempdi = XGI_EPLCHTVCRT1Ptr;
7618             }
7619             break ;
7620         case 2:
7621             tempdi = XGI_EPLCHTVDataPtr ;
7622             break ;
7623         case 3:
7624             tempdi = 0 ;
7625             break ;
7626         case 4:
7627             tempdi = XGI_TVDataTable ;
7628             break ;
7629         case 5:
7630             tempdi = 0 ;
7631             break ;
7632         case 6:
7633             tempdi = XGI_EPLCHTVRegPtr ;
7634             break ;
7635         default:
7636             break ;
7637     }
7638
7639     if ( tempdi == 0x00 )  /* OEMUtil */
7640         return( 0 ) ;
7641
7642     tempdx = pVBInfo->TVInfo ;
7643
7644     if ( pVBInfo->VBInfo & SetInSlaveMode )
7645         tempdx = tempdx | SetTVLockMode ;
7646
7647     if ( modeflag & HalfDCLK )
7648         tempdx = tempdx | SetTVLowResolution ;
7649
7650     i = 0 ;
7651
7652     while( tempdi[ i ].MASK != 0xffff )
7653     {
7654         if ( ( tempdx & tempdi[ i ].MASK ) == tempdi[ i ].CAP )
7655             break ;
7656         i++ ;
7657     }
7658
7659     if ( table == 0x00 ) /* 07/05/22 */
7660     {
7661     }
7662     else if ( table == 0x01 )
7663     {
7664     }
7665     else if ( table == 0x04 )
7666     {
7667         switch( tempdi[ i ].DATAPTR )
7668         {
7669             case 0:
7670                 return &XGI_ExtPALData[ tempal ] ;
7671                 break ;
7672             case 1:
7673                 return &XGI_ExtNTSCData[ tempal ] ;
7674                 break ;
7675             case 2:
7676                 return &XGI_StPALData[ tempal ] ;
7677                 break ;
7678             case 3:
7679                 return &XGI_StNTSCData[ tempal ] ;
7680                 break ;
7681             case 4:
7682                 return &XGI_ExtHiTVData[ tempal ] ;
7683                 break ;
7684             case 5:
7685                 return &XGI_St2HiTVData[ tempal ] ;
7686                 break ;
7687             case 6:
7688                 return &XGI_ExtYPbPr525iData[ tempal ] ;
7689                 break ;
7690             case 7:
7691                 return &XGI_ExtYPbPr525pData[ tempal ] ;
7692                 break ;
7693             case 8:
7694                 return &XGI_ExtYPbPr750pData[ tempal ] ;
7695                 break ;
7696             case 9:
7697                 return &XGI_StYPbPr525iData[ tempal ] ;
7698                 break ;
7699             case 10:
7700                 return &XGI_StYPbPr525pData[ tempal ] ;
7701                 break ;
7702             case 11:
7703                 return &XGI_StYPbPr750pData[ tempal ] ;
7704                 break;
7705             case 12:    /* avoid system hang */
7706                 return &XGI_ExtNTSCData[ tempal ] ;
7707                 break ;
7708             case 13:
7709                 return &XGI_St1HiTVData[ tempal ] ;
7710                 break ;
7711             default:
7712                 break ;
7713         }
7714     }
7715     else if( table == 0x02 )
7716     {
7717         switch( tempdi[ i ].DATAPTR )
7718         {
7719             case 0:
7720                 return &XGI_CHTVUNTSCData[ tempal ] ;
7721                 break ;
7722             case 1:
7723                 return &XGI_CHTVONTSCData[ tempal ] ;
7724                 break ;
7725             case 2:
7726                 return &XGI_CHTVUPALData[ tempal ] ;
7727                 break ;
7728             case 3:
7729                 return &XGI_CHTVOPALData[ tempal ] ;
7730                 break ;
7731             default:
7732                 break ;
7733         }
7734     }
7735     else if( table == 0x06 )
7736     {
7737     }
7738     return( 0 ) ;
7739 }
7740
7741
7742 /* --------------------------------------------------------------------- */
7743 /* Function : XGI_BacklightByDrv */
7744 /* Input : */
7745 /* Output : TRUE -> Skip backlight control */
7746 /* Description : */
7747 /* --------------------------------------------------------------------- */
7748 BOOLEAN XGI_BacklightByDrv( PVB_DEVICE_INFO pVBInfo )
7749 {
7750     UCHAR tempah ;
7751
7752     tempah = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x3A ) ;
7753     if ( tempah & BacklightControlBit )
7754         return TRUE ;
7755     else
7756         return FALSE ;
7757 }
7758
7759
7760 /* --------------------------------------------------------------------- */
7761 /* Function : XGI_FirePWDDisable */
7762 /* Input : */
7763 /* Output : */
7764 /* Description : Turn off VDD & Backlight : Fire disable procedure */
7765 /* --------------------------------------------------------------------- */
7766 /*
7767 void XGI_FirePWDDisable( PVB_DEVICE_INFO pVBInfo )
7768 {
7769     XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x26 , 0x00 , 0xFC ) ;
7770 }
7771 */
7772
7773 /* --------------------------------------------------------------------- */
7774 /* Function : XGI_FirePWDEnable */
7775 /* Input : */
7776 /* Output : */
7777 /* Description : Turn on VDD & Backlight : Fire enable procedure */
7778 /* --------------------------------------------------------------------- */
7779 void XGI_FirePWDEnable(PVB_DEVICE_INFO pVBInfo )
7780 {
7781     XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x26 , 0x03 , 0xFC ) ;
7782 }
7783
7784
7785 /* --------------------------------------------------------------------- */
7786 /* Function : XGI_EnableGatingCRT */
7787 /* Input : */
7788 /* Output : */
7789 /* Description : */
7790 /* --------------------------------------------------------------------- */
7791 void XGI_EnableGatingCRT(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
7792 {
7793     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x63 , 0xBF , 0x40 ) ;
7794 }
7795
7796
7797 /* --------------------------------------------------------------------- */
7798 /* Function : XGI_DisableGatingCRT */
7799 /* Input : */
7800 /* Output : */
7801 /* Description : */
7802 /* --------------------------------------------------------------------- */
7803 void XGI_DisableGatingCRT(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
7804 {
7805
7806     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x63 , 0xBF , 0x00 ) ;
7807 }
7808
7809
7810 /* --------------------------------------------------------------------- */
7811 /* Function : XGI_SetPanelDelay */
7812 /* Input : */
7813 /* Output : */
7814 /* Description : */
7815 /* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
7816 /* : bl : 2 ; T2 : the duration signal on and Vdd on */
7817 /* : bl : 3 ; T3 : the duration between CPL off and signal off */
7818 /* : bl : 4 ; T4 : the duration signal off and Vdd off */
7819 /* --------------------------------------------------------------------- */
7820 void XGI_SetPanelDelay(USHORT tempbl, PVB_DEVICE_INFO pVBInfo)
7821 {
7822     USHORT index ;
7823
7824     index = XGI_GetLCDCapPtr(pVBInfo) ;
7825
7826     if ( tempbl == 1 )
7827         XGINew_LCD_Wait_Time( pVBInfo->LCDCapList[ index ].PSC_S1, pVBInfo ) ;
7828
7829     if ( tempbl == 2 )
7830         XGINew_LCD_Wait_Time( pVBInfo->LCDCapList[ index ].PSC_S2, pVBInfo ) ;
7831
7832     if ( tempbl == 3 )
7833         XGINew_LCD_Wait_Time( pVBInfo->LCDCapList[ index ].PSC_S3, pVBInfo ) ;
7834
7835     if ( tempbl == 4 )
7836         XGINew_LCD_Wait_Time( pVBInfo->LCDCapList[ index ].PSC_S4, pVBInfo ) ;
7837 }
7838
7839
7840 /* --------------------------------------------------------------------- */
7841 /* Function : XGI_SetPanelPower */
7842 /* Input : */
7843 /* Output : */
7844 /* Description : */
7845 /* I/O : ah = 0011b = 03h ; Backlight on, Power on */
7846 /* = 0111b = 07h ; Backlight on, Power off */
7847 /* = 1011b = 0Bh ; Backlight off, Power on */
7848 /* = 1111b = 0Fh ; Backlight off, Power off */
7849 /* --------------------------------------------------------------------- */
7850 void XGI_SetPanelPower(USHORT tempah,USHORT tempbl, PVB_DEVICE_INFO pVBInfo)
7851 {
7852     if ( pVBInfo->VBType & ( VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
7853         XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x26 , tempbl , tempah ) ;
7854     else
7855         XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x11 , tempbl , tempah ) ;
7856 }
7857
7858 UCHAR XG21GPIODataTransfer(UCHAR ujDate)
7859 {
7860     UCHAR  ujRet = 0;
7861     UCHAR  i = 0;
7862
7863     for (i=0; i<8; i++)
7864         {
7865         ujRet = ujRet << 1;
7866         /* ujRet |= GETBITS(ujDate >> i, 0:0); */
7867         ujRet |= (ujDate >> i) & 1;
7868     }
7869
7870         return ujRet;
7871 }
7872
7873 /*----------------------------------------------------------------------------*/
7874 /* output                                                                     */
7875 /*      bl[5] : LVDS signal                                                   */
7876 /*      bl[1] : LVDS backlight                                                */
7877 /*      bl[0] : LVDS VDD                                                      */
7878 /*----------------------------------------------------------------------------*/
7879 UCHAR XGI_XG21GetPSCValue(PVB_DEVICE_INFO pVBInfo)
7880 {
7881     UCHAR CR4A,temp;
7882
7883     CR4A = XGINew_GetReg1( pVBInfo->P3d4 , 0x4A ) ;
7884     XGINew_SetRegAND( pVBInfo->P3d4 , 0x4A , ~0x23 ) ; /* enable GPIO write */
7885
7886     temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x48 ) ;
7887
7888     temp = XG21GPIODataTransfer(temp);
7889     temp &= 0x23;
7890     XGINew_SetReg1( pVBInfo->P3d4 , 0x4A , CR4A ) ;
7891     return temp;
7892 }
7893
7894 /*----------------------------------------------------------------------------*/
7895 /* output                                                                     */
7896 /*      bl[5] : LVDS signal                                                   */
7897 /*      bl[1] : LVDS backlight                                                */
7898 /*      bl[0] : LVDS VDD                                                      */
7899 /*----------------------------------------------------------------------------*/
7900 UCHAR XGI_XG27GetPSCValue(PVB_DEVICE_INFO pVBInfo)
7901 {
7902     UCHAR CR4A,CRB4,temp;
7903
7904     CR4A = XGINew_GetReg1( pVBInfo->P3d4 , 0x4A ) ;
7905     XGINew_SetRegAND( pVBInfo->P3d4 , 0x4A , ~0x0C ) ; /* enable GPIO write */
7906
7907     temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x48 ) ;
7908
7909     temp &= 0x0C;
7910     temp >>= 2;
7911     XGINew_SetReg1( pVBInfo->P3d4 , 0x4A , CR4A ) ;
7912     CRB4 = XGINew_GetReg1( pVBInfo->P3d4 , 0xB4 ) ;
7913     temp |= ((CRB4&0x04)<<3);
7914     return temp;
7915 }
7916 /*----------------------------------------------------------------------------*/
7917 /* input                                                                      */
7918 /*      bl[5] : 1;LVDS signal on                                              */
7919 /*      bl[1] : 1;LVDS backlight on                                           */
7920 /*      bl[0] : 1:LVDS VDD on                                                 */
7921 /*      bh: 100000b : clear bit 5, to set bit5                                */
7922 /*          000010b : clear bit 1, to set bit1                                */
7923 /*          000001b : clear bit 0, to set bit0                                */
7924 /*----------------------------------------------------------------------------*/
7925 void XGI_XG21BLSignalVDD(USHORT tempbh,USHORT tempbl, PVB_DEVICE_INFO pVBInfo)
7926 {
7927     UCHAR CR4A,temp;
7928
7929     CR4A = XGINew_GetReg1( pVBInfo->P3d4 , 0x4A ) ;
7930     tempbh &= 0x23;
7931     tempbl &= 0x23;
7932     XGINew_SetRegAND( pVBInfo->P3d4 , 0x4A , ~tempbh ) ; /* enable GPIO write */
7933
7934     if (tempbh&0x20)
7935     {
7936       temp = (tempbl>>4)&0x02;
7937
7938       XGINew_SetRegANDOR( pVBInfo->P3d4 , 0xB4 , ~0x02 , temp) ; /* CR B4[1] */
7939
7940     }
7941
7942     temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x48 ) ;
7943
7944     temp = XG21GPIODataTransfer(temp);
7945     temp &= ~tempbh;
7946     temp |= tempbl;
7947     XGINew_SetReg1( pVBInfo->P3d4 , 0x48 , temp ) ;
7948 }
7949
7950 void XGI_XG27BLSignalVDD(USHORT tempbh,USHORT tempbl, PVB_DEVICE_INFO pVBInfo)
7951 {
7952     UCHAR CR4A,temp;
7953     USHORT tempbh0,tempbl0;
7954
7955     tempbh0 = tempbh;
7956     tempbl0 = tempbl;
7957     tempbh0 &= 0x20;
7958     tempbl0 &= 0x20;
7959     tempbh0 >>= 3;
7960     tempbl0 >>= 3;
7961
7962     if (tempbh&0x20)
7963     {
7964       temp = (tempbl>>4)&0x02;
7965
7966       XGINew_SetRegANDOR( pVBInfo->P3d4 , 0xB4 , ~0x02 , temp) ; /* CR B4[1] */
7967
7968     }
7969     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0xB4 , ~tempbh0 , tempbl0 ) ;
7970
7971     CR4A = XGINew_GetReg1( pVBInfo->P3d4 , 0x4A ) ;
7972     tempbh &= 0x03;
7973     tempbl &= 0x03;
7974     tempbh <<= 2;
7975     tempbl <<= 2;                                       /* GPIOC,GPIOD */
7976     XGINew_SetRegAND( pVBInfo->P3d4 , 0x4A , ~tempbh ) ; /* enable GPIO write */
7977     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x48 , ~tempbh , tempbl ) ;
7978 }
7979
7980 /* --------------------------------------------------------------------- */
7981 USHORT XGI_GetLVDSOEMTableIndex(PVB_DEVICE_INFO pVBInfo)
7982 {
7983     USHORT index ;
7984
7985     index = XGINew_GetReg1( pVBInfo->P3d4 , 0x36 ) ;
7986     if (index<sizeof(XGI21_LCDCapList)/sizeof(XGI21_LVDSCapStruct))
7987     {
7988       return index;
7989     }
7990     return 0;
7991 }
7992
7993 /* --------------------------------------------------------------------- */
7994 /* Function : XGI_XG21SetPanelDelay */
7995 /* Input : */
7996 /* Output : */
7997 /* Description : */
7998 /* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
7999 /* : bl : 2 ; T2 : the duration signal on and Vdd on */
8000 /* : bl : 3 ; T3 : the duration between CPL off and signal off */
8001 /* : bl : 4 ; T4 : the duration signal off and Vdd off */
8002 /* --------------------------------------------------------------------- */
8003 void XGI_XG21SetPanelDelay(USHORT tempbl, PVB_DEVICE_INFO pVBInfo)
8004 {
8005     USHORT index ;
8006
8007     index = XGI_GetLVDSOEMTableIndex( pVBInfo );
8008     if ( tempbl == 1 )
8009         XGINew_LCD_Wait_Time( pVBInfo->XG21_LVDSCapList[ index ].PSC_S1, pVBInfo ) ;
8010
8011     if ( tempbl == 2 )
8012         XGINew_LCD_Wait_Time( pVBInfo->XG21_LVDSCapList[ index ].PSC_S2, pVBInfo ) ;
8013
8014     if ( tempbl == 3 )
8015         XGINew_LCD_Wait_Time( pVBInfo->XG21_LVDSCapList[ index ].PSC_S3, pVBInfo ) ;
8016
8017     if ( tempbl == 4 )
8018         XGINew_LCD_Wait_Time( pVBInfo->XG21_LVDSCapList[ index ].PSC_S4, pVBInfo ) ;
8019 }
8020
8021 BOOLEAN XGI_XG21CheckLVDSMode(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
8022 {
8023     USHORT xres ,
8024            yres ,
8025            colordepth ,
8026            modeflag ,
8027            resindex ,
8028            lvdstableindex;
8029
8030     resindex = XGI_GetResInfo( ModeNo , ModeIdIndex, pVBInfo ) ;
8031     if ( ModeNo <= 0x13 )
8032     {
8033         xres = pVBInfo->StResInfo[ resindex ].HTotal ;
8034         yres = pVBInfo->StResInfo[ resindex ].VTotal ;
8035         modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;    /* si+St_ResInfo */
8036     }
8037     else
8038     {
8039         xres = pVBInfo->ModeResInfo[ resindex ].HTotal ;                          /* xres->ax */
8040         yres = pVBInfo->ModeResInfo[ resindex ].VTotal ;                          /* yres->bx */
8041         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex].Ext_ModeFlag ; /* si+St_ModeFlag */
8042     }
8043
8044     if ( !( modeflag & Charx8Dot ) )
8045     {
8046         xres /= 9;
8047         xres *= 8;
8048     }
8049
8050     if ( ModeNo > 0x13 )
8051     {
8052         if ( ( ModeNo>0x13 ) && ( modeflag & HalfDCLK ) )
8053         {
8054           xres *=  2 ;
8055         }
8056         if ( ( ModeNo>0x13 ) && ( modeflag & DoubleScanMode ) )
8057         {
8058           yres *=  2 ;
8059         }
8060     }
8061
8062     lvdstableindex = XGI_GetLVDSOEMTableIndex( pVBInfo );
8063     if ( xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE) )
8064       return FALSE;
8065
8066     if ( yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE) )
8067       return FALSE;
8068
8069     if ( ModeNo > 0x13 )
8070     {
8071       if ( ( xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE) ) ||
8072            ( yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE)) )
8073       {
8074           colordepth = XGI_GetColorDepth( ModeNo , ModeIdIndex, pVBInfo ) ;
8075           if ( colordepth > 2 )
8076           {
8077             return FALSE;
8078           }
8079       }
8080     }
8081     return TRUE;
8082 }
8083
8084 void XGI_SetXG21FPBits(PVB_DEVICE_INFO pVBInfo)
8085 {
8086     UCHAR temp;
8087
8088     temp = XGINew_GetReg1( pVBInfo->P3d4  , 0x37 ) ;  /* D[0] 1: 18bit */
8089     temp = ( temp & 1 ) << 6;
8090     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x06 , ~0x40 , temp ) ;      /* SR06[6] 18bit Dither */
8091     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x09 , ~0xc0 , temp | 0x80 ) ;  /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
8092
8093 }
8094
8095 void XGI_SetXG27FPBits(PVB_DEVICE_INFO pVBInfo)
8096 {
8097     UCHAR temp;
8098
8099     temp = XGINew_GetReg1( pVBInfo->P3d4  , 0x37 ) ;  /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
8100     temp = ( temp & 3 ) << 6;
8101     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x06 , ~0xc0 , temp & 0x80 ) ;  /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
8102     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x09 , ~0xc0 , temp | 0x80 ) ;  /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
8103
8104 }
8105
8106 void XGI_SetXG21LVDSPara(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
8107 {
8108     UCHAR temp,Miscdata;
8109     USHORT xres ,
8110            yres ,
8111            modeflag ,
8112            resindex ,
8113            lvdstableindex ;
8114     USHORT LVDSHT,LVDSHBS,LVDSHRS,LVDSHRE,LVDSHBE;
8115     USHORT LVDSVT,LVDSVBS,LVDSVRS,LVDSVRE,LVDSVBE;
8116     USHORT value;
8117
8118     lvdstableindex = XGI_GetLVDSOEMTableIndex( pVBInfo );
8119
8120     temp = (UCHAR) ( ( pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDS_Capability & (LCDPolarity << 8 ) ) >> 8 );
8121     temp &= LCDPolarity;
8122     Miscdata =(UCHAR) XGINew_GetReg2(pVBInfo->P3cc) ;
8123
8124     XGINew_SetReg3( pVBInfo->P3c2 , (Miscdata & 0x3F) | temp ) ;
8125
8126     temp = (UCHAR) ( pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDS_Capability & LCDPolarity ) ;
8127     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x35 , ~0x80 , temp&0x80 ) ;      /* SR35[7] FP VSync polarity */
8128     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x30 , ~0x20 , (temp&0x40)>>1 ) ;   /* SR30[5] FP HSync polarity */
8129
8130     XGI_SetXG21FPBits(pVBInfo);
8131     resindex = XGI_GetResInfo( ModeNo , ModeIdIndex, pVBInfo ) ;
8132     if ( ModeNo <= 0x13 )
8133     {
8134         xres = pVBInfo->StResInfo[ resindex ].HTotal ;
8135         yres = pVBInfo->StResInfo[ resindex ].VTotal ;
8136         modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;    /* si+St_ResInfo */
8137     }
8138     else
8139     {
8140         xres = pVBInfo->ModeResInfo[ resindex ].HTotal ;                          /* xres->ax */
8141         yres = pVBInfo->ModeResInfo[ resindex ].VTotal ;                          /* yres->bx */
8142         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex].Ext_ModeFlag ; /* si+St_ModeFlag */
8143     }
8144
8145     if (!( modeflag & Charx8Dot ))
8146       xres = xres * 8 / 9;
8147
8148     LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
8149
8150     LVDSHBS = xres + ( pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE - xres ) / 2 ;
8151     if ( ( ModeNo<=0x13 ) && ( modeflag & HalfDCLK ) )
8152     {
8153       LVDSHBS -=  xres/4 ;
8154     }
8155     if (LVDSHBS > LVDSHT) LVDSHBS -= LVDSHT ;
8156
8157     LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP ;
8158     if (LVDSHRS > LVDSHT) LVDSHRS -= LVDSHT ;
8159
8160     LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC ;
8161     if (LVDSHRE > LVDSHT) LVDSHRE -= LVDSHT ;
8162
8163     LVDSHBE = LVDSHBS + LVDSHT - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE ;
8164
8165     LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
8166
8167     LVDSVBS = yres + ( pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE - yres ) / 2 ;
8168     if ( ( ModeNo>0x13 ) && ( modeflag & DoubleScanMode ) )
8169     {
8170       LVDSVBS +=  yres/2 ;
8171     }
8172     if (LVDSVBS > LVDSVT) LVDSVBS -= LVDSVT ;
8173
8174     LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP ;
8175     if (LVDSVRS > LVDSVT) LVDSVRS -= LVDSVT ;
8176
8177     LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVSYNC ;
8178     if (LVDSVRE > LVDSVT) LVDSVRE -= LVDSVT ;
8179
8180     LVDSVBE = LVDSVBS + LVDSVT - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE ;
8181
8182     temp = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x11 ) ;
8183     XGINew_SetReg1( pVBInfo->P3d4 , 0x11 , temp & 0x7f ) ;              /* Unlock CRTC */
8184
8185     if (!( modeflag & Charx8Dot ))
8186     {
8187         XGINew_SetRegOR( pVBInfo->P3c4 , 0x1 , 0x1 ) ;
8188     }
8189
8190     /* HT SR0B[1:0] CR00 */
8191     value = ( LVDSHT >> 3 ) - 5;
8192     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0B , ~0x03 , ( value & 0x300 ) >> 8 ) ;
8193     XGINew_SetReg1( pVBInfo->P3d4 , 0x0 , (value & 0xFF) ) ;
8194
8195     /* HBS SR0B[5:4] CR02 */
8196     value = ( LVDSHBS >> 3 ) - 1;
8197     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0B , ~0x30 , ( value & 0x300 ) >> 4 ) ;
8198     XGINew_SetReg1( pVBInfo->P3d4 , 0x2 , (value & 0xFF) ) ;
8199
8200     /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
8201     value = ( LVDSHBE >> 3 ) - 1;
8202     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0C , ~0x03 , ( value & 0xC0 ) >> 6 ) ;
8203     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x05 , ~0x80 , ( value & 0x20 ) << 2 ) ;
8204     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x03 , ~0x1F , value & 0x1F ) ;
8205
8206     /* HRS SR0B[7:6] CR04 */
8207     value = ( LVDSHRS >> 3 ) + 2;
8208     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0B , ~0xC0 , ( value & 0x300 ) >> 2 ) ;
8209     XGINew_SetReg1( pVBInfo->P3d4 , 0x4 , (value & 0xFF) ) ;
8210
8211     /* Panel HRS SR2F[1:0] SR2E[7:0]  */
8212     value--;
8213     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x2F , ~0x03 , ( value & 0x300 ) >> 8 ) ;
8214     XGINew_SetReg1( pVBInfo->P3c4 , 0x2E , (value & 0xFF) ) ;
8215
8216     /* HRE SR0C[2] CR05[4:0] */
8217     value = ( LVDSHRE >> 3 ) + 2;
8218     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0C , ~0x04 , ( value & 0x20 ) >> 3 ) ;
8219     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x05 , ~0x1F , value & 0x1F ) ;
8220
8221     /* Panel HRE SR2F[7:2]  */
8222     value--;
8223     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x2F , ~0xFC , value << 2 ) ;
8224
8225     /* VT SR0A[0] CR07[5][0] CR06 */
8226     value = LVDSVT - 2 ;
8227     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x01 , ( value & 0x400 ) >> 10 ) ;
8228     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x20 , ( value & 0x200 ) >> 4 ) ;
8229     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x01 , ( value & 0x100 ) >> 8 ) ;
8230     XGINew_SetReg1( pVBInfo->P3d4 , 0x06 , (value & 0xFF) ) ;
8231
8232     /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
8233     value = LVDSVBS - 1 ;
8234     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x04 , ( value & 0x400 ) >> 8 ) ;
8235     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x09 , ~0x20 , ( value & 0x200 ) >> 4 ) ;
8236     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x08 , ( value & 0x100 ) >> 5 ) ;
8237     XGINew_SetReg1( pVBInfo->P3d4 , 0x15 , (value & 0xFF) ) ;
8238
8239     /* VBE SR0A[4] CR16 */
8240     value = LVDSVBE - 1;
8241     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x10 , ( value & 0x100 ) >> 4 ) ;
8242     XGINew_SetReg1( pVBInfo->P3d4 , 0x16 , (value & 0xFF) ) ;
8243
8244     /* VRS SR0A[3] CR7[7][2] CR10 */
8245     value = LVDSVRS - 1 ;
8246     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x08 , ( value & 0x400 ) >> 7 ) ;
8247     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x80 , ( value & 0x200 ) >> 2 ) ;
8248     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x04 , ( value & 0x100 ) >> 6 ) ;
8249     XGINew_SetReg1( pVBInfo->P3d4 , 0x10 , (value & 0xFF) ) ;
8250
8251     /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
8252     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x3F , ~0x03 , ( value & 0x600 ) >> 9 ) ;
8253     XGINew_SetReg1( pVBInfo->P3c4 , 0x34 , (value >> 1) & 0xFF ) ;
8254     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x33 , ~0x01 , value & 0x01 ) ;
8255
8256     /* VRE SR0A[5] CR11[3:0] */
8257     value = LVDSVRE - 1;
8258     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x20 , ( value & 0x10 ) << 1 ) ;
8259     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x11 , ~0x0F , value & 0x0F ) ;
8260
8261     /* Panel VRE SR3F[7:2] */ /* SR3F[7] has to be 0, h/w bug */
8262     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x3F , ~0xFC , ( value << 2 ) & 0x7C ) ;
8263
8264     for ( temp=0, value = 0; temp < 3; temp++)
8265     {
8266
8267         XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x31 , ~0x30 , value ) ;
8268         XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , pVBInfo->XG21_LVDSCapList[lvdstableindex].VCLKData1) ;
8269         XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , pVBInfo->XG21_LVDSCapList[lvdstableindex].VCLKData2) ;
8270         value += 0x10;
8271     }
8272
8273     if (!( modeflag & Charx8Dot ))
8274     {
8275         XGINew_GetReg2( pVBInfo->P3da ) ;           /* reset 3da */
8276         XGINew_SetReg3( pVBInfo->P3c0 , 0x13 ) ;    /* set index */
8277         XGINew_SetReg3( pVBInfo->P3c0 , 0x00 ) ;    /* set data, panning = 0, shift left 1 dot*/
8278
8279         XGINew_GetReg2( pVBInfo->P3da ) ;           /* Enable Attribute */
8280         XGINew_SetReg3( pVBInfo->P3c0 , 0x20 ) ;
8281
8282         XGINew_GetReg2( pVBInfo->P3da ) ;           /* reset 3da */
8283     }
8284
8285
8286 }
8287
8288 /* no shadow case */
8289 void XGI_SetXG27LVDSPara(USHORT ModeNo,USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
8290 {
8291     UCHAR temp,Miscdata;
8292     USHORT xres ,
8293            yres ,
8294            modeflag ,
8295            resindex ,
8296            lvdstableindex ;
8297     USHORT LVDSHT,LVDSHBS,LVDSHRS,LVDSHRE,LVDSHBE;
8298     USHORT LVDSVT,LVDSVBS,LVDSVRS,LVDSVRE,LVDSVBE;
8299     USHORT value;
8300
8301     lvdstableindex = XGI_GetLVDSOEMTableIndex( pVBInfo );
8302     temp = (UCHAR) ( ( pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDS_Capability & (LCDPolarity << 8 ) ) >> 8 );
8303     temp &= LCDPolarity;
8304     Miscdata =(UCHAR) XGINew_GetReg2(pVBInfo->P3cc) ;
8305
8306     XGINew_SetReg3( pVBInfo->P3c2 , (Miscdata & 0x3F) | temp ) ;
8307
8308     temp = (UCHAR) ( pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDS_Capability & LCDPolarity ) ;
8309     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x35 , ~0x80 , temp&0x80 ) ;      /* SR35[7] FP VSync polarity */
8310     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x30 , ~0x20 , (temp&0x40)>>1 ) ;   /* SR30[5] FP HSync polarity */
8311
8312     XGI_SetXG27FPBits(pVBInfo);
8313     resindex = XGI_GetResInfo( ModeNo , ModeIdIndex, pVBInfo ) ;
8314     if ( ModeNo <= 0x13 )
8315     {
8316         xres = pVBInfo->StResInfo[ resindex ].HTotal ;
8317         yres = pVBInfo->StResInfo[ resindex ].VTotal ;
8318         modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;    /* si+St_ResInfo */
8319     }
8320     else
8321     {
8322         xres = pVBInfo->ModeResInfo[ resindex ].HTotal ;                          /* xres->ax */
8323         yres = pVBInfo->ModeResInfo[ resindex ].VTotal ;                          /* yres->bx */
8324         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex].Ext_ModeFlag ; /* si+St_ModeFlag */
8325     }
8326
8327     if (!( modeflag & Charx8Dot ))
8328       xres = xres * 8 / 9;
8329
8330     LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
8331
8332     LVDSHBS = xres + ( pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE - xres ) / 2 ;
8333     if ( ( ModeNo<=0x13 ) && ( modeflag & HalfDCLK ) )
8334     {
8335       LVDSHBS -=  xres/4 ;
8336     }
8337     if (LVDSHBS > LVDSHT) LVDSHBS -= LVDSHT ;
8338
8339     LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP ;
8340     if (LVDSHRS > LVDSHT) LVDSHRS -= LVDSHT ;
8341
8342     LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC ;
8343     if (LVDSHRE > LVDSHT) LVDSHRE -= LVDSHT ;
8344
8345     LVDSHBE = LVDSHBS + LVDSHT - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE ;
8346
8347     LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
8348
8349     LVDSVBS = yres + ( pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE - yres ) / 2 ;
8350     if ( ( ModeNo>0x13 ) && ( modeflag & DoubleScanMode ) )
8351     {
8352       LVDSVBS +=  yres/2 ;
8353     }
8354     if (LVDSVBS > LVDSVT) LVDSVBS -= LVDSVT ;
8355
8356     LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP ;
8357     if (LVDSVRS > LVDSVT) LVDSVRS -= LVDSVT ;
8358
8359     LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVSYNC ;
8360     if (LVDSVRE > LVDSVT) LVDSVRE -= LVDSVT ;
8361
8362     LVDSVBE = LVDSVBS + LVDSVT - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE ;
8363
8364     temp = ( UCHAR )XGINew_GetReg1( pVBInfo->P3d4 , 0x11 ) ;
8365     XGINew_SetReg1( pVBInfo->P3d4 , 0x11 , temp & 0x7f ) ;              /* Unlock CRTC */
8366
8367     if (!( modeflag & Charx8Dot ))
8368     {
8369         XGINew_SetRegOR( pVBInfo->P3c4 , 0x1 , 0x1 ) ;
8370     }
8371
8372     /* HT SR0B[1:0] CR00 */
8373     value = ( LVDSHT >> 3 ) - 5;
8374     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0B , ~0x03 , ( value & 0x300 ) >> 8 ) ;
8375     XGINew_SetReg1( pVBInfo->P3d4 , 0x0 , (value & 0xFF) ) ;
8376
8377     /* HBS SR0B[5:4] CR02 */
8378     value = ( LVDSHBS >> 3 ) - 1;
8379     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0B , ~0x30 , ( value & 0x300 ) >> 4 ) ;
8380     XGINew_SetReg1( pVBInfo->P3d4 , 0x2 , (value & 0xFF) ) ;
8381
8382     /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
8383     value = ( LVDSHBE >> 3 ) - 1;
8384     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0C , ~0x03 , ( value & 0xC0 ) >> 6 ) ;
8385     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x05 , ~0x80 , ( value & 0x20 ) << 2 ) ;
8386     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x03 , ~0x1F , value & 0x1F ) ;
8387
8388     /* HRS SR0B[7:6] CR04 */
8389     value = ( LVDSHRS >> 3 ) + 2;
8390     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0B , ~0xC0 , ( value & 0x300 ) >> 2 ) ;
8391     XGINew_SetReg1( pVBInfo->P3d4 , 0x4 , (value & 0xFF) ) ;
8392
8393     /* Panel HRS SR2F[1:0] SR2E[7:0]  */
8394     value--;
8395     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x2F , ~0x03 , ( value & 0x300 ) >> 8 ) ;
8396     XGINew_SetReg1( pVBInfo->P3c4 , 0x2E , (value & 0xFF) ) ;
8397
8398     /* HRE SR0C[2] CR05[4:0] */
8399     value = ( LVDSHRE >> 3 ) + 2;
8400     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0C , ~0x04 , ( value & 0x20 ) >> 3 ) ;
8401     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x05 , ~0x1F , value & 0x1F ) ;
8402
8403     /* Panel HRE SR2F[7:2]  */
8404     value--;
8405     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x2F , ~0xFC , value << 2 ) ;
8406
8407     /* VT SR0A[0] CR07[5][0] CR06 */
8408     value = LVDSVT - 2 ;
8409     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x01 , ( value & 0x400 ) >> 10 ) ;
8410     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x20 , ( value & 0x200 ) >> 4 ) ;
8411     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x01 , ( value & 0x100 ) >> 8 ) ;
8412     XGINew_SetReg1( pVBInfo->P3d4 , 0x06 , (value & 0xFF) ) ;
8413
8414     /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
8415     value = LVDSVBS - 1 ;
8416     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x04 , ( value & 0x400 ) >> 8 ) ;
8417     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x09 , ~0x20 , ( value & 0x200 ) >> 4 ) ;
8418     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x08 , ( value & 0x100 ) >> 5 ) ;
8419     XGINew_SetReg1( pVBInfo->P3d4 , 0x15 , (value & 0xFF) ) ;
8420
8421     /* VBE SR0A[4] CR16 */
8422     value = LVDSVBE - 1;
8423     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x10 , ( value & 0x100 ) >> 4 ) ;
8424     XGINew_SetReg1( pVBInfo->P3d4 , 0x16 , (value & 0xFF) ) ;
8425
8426     /* VRS SR0A[3] CR7[7][2] CR10 */
8427     value = LVDSVRS - 1 ;
8428     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x08 , ( value & 0x400 ) >> 7 ) ;
8429     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x80 , ( value & 0x200 ) >> 2 ) ;
8430     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x07 , ~0x04 , ( value & 0x100 ) >> 6 ) ;
8431     XGINew_SetReg1( pVBInfo->P3d4 , 0x10 , (value & 0xFF) ) ;
8432
8433     /* Panel VRS SR35[2:0] SR34[7:0] */
8434     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x35 , ~0x07 , ( value & 0x700 ) >> 8 ) ;
8435     XGINew_SetReg1( pVBInfo->P3c4 , 0x34 , value & 0xFF ) ;
8436
8437     /* VRE SR0A[5] CR11[3:0] */
8438     value = LVDSVRE - 1;
8439     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x0A , ~0x20 , ( value & 0x10 ) << 1 ) ;
8440     XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x11 , ~0x0F , value & 0x0F ) ;
8441
8442     /* Panel VRE SR3F[7:2] */
8443     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x3F , ~0xFC , ( value << 2 ) & 0xFC ) ;
8444
8445     for ( temp=0, value = 0; temp < 3; temp++)
8446     {
8447
8448         XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x31 , ~0x30 , value ) ;
8449         XGINew_SetReg1( pVBInfo->P3c4 , 0x2B , pVBInfo->XG21_LVDSCapList[lvdstableindex].VCLKData1) ;
8450         XGINew_SetReg1( pVBInfo->P3c4 , 0x2C , pVBInfo->XG21_LVDSCapList[lvdstableindex].VCLKData2) ;
8451         value += 0x10;
8452     }
8453
8454     if (!( modeflag & Charx8Dot ))
8455     {
8456         XGINew_GetReg2( pVBInfo->P3da ) ;           /* reset 3da */
8457         XGINew_SetReg3( pVBInfo->P3c0 , 0x13 ) ;    /* set index */
8458         XGINew_SetReg3( pVBInfo->P3c0 , 0x00 ) ;    /* set data, panning = 0, shift left 1 dot*/
8459
8460         XGINew_GetReg2( pVBInfo->P3da ) ;           /* Enable Attribute */
8461         XGINew_SetReg3( pVBInfo->P3c0 , 0x20 ) ;
8462
8463         XGINew_GetReg2( pVBInfo->P3da ) ;           /* reset 3da */
8464     }
8465
8466
8467 }
8468
8469 /* --------------------------------------------------------------------- */
8470 /* Function : XGI_IsLCDON */
8471 /* Input : */
8472 /* Output : FALSE : Skip PSC Control */
8473 /* TRUE: Disable PSC */
8474 /* Description : */
8475 /* --------------------------------------------------------------------- */
8476 BOOLEAN XGI_IsLCDON(PVB_DEVICE_INFO pVBInfo)
8477 {
8478     USHORT tempax ;
8479
8480     tempax = pVBInfo->VBInfo ;
8481     if ( tempax & SetCRT2ToDualEdge )
8482         return FALSE ;
8483     else if ( tempax & ( DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode ) )
8484         return TRUE ;
8485
8486     return FALSE ;
8487 }
8488
8489
8490 /* --------------------------------------------------------------------- */
8491 /* Function : XGI_EnablePWD */
8492 /* Input : */
8493 /* Output : */
8494 /* Description : */
8495 /* --------------------------------------------------------------------- */
8496 void XGI_EnablePWD(  PVB_DEVICE_INFO pVBInfo )
8497 {
8498     USHORT index ,
8499            temp ;
8500
8501     index = XGI_GetLCDCapPtr(pVBInfo) ;
8502     temp = pVBInfo->LCDCapList[ index ].PWD_2B ;
8503     XGINew_SetReg1( pVBInfo->Part4Port , 0x2B , temp ) ;
8504     XGINew_SetReg1( pVBInfo->Part4Port , 0x2C , pVBInfo->LCDCapList[ index ].PWD_2C ) ;
8505     XGINew_SetReg1( pVBInfo->Part4Port , 0x2D , pVBInfo->LCDCapList[ index ].PWD_2D ) ;
8506     XGINew_SetReg1( pVBInfo->Part4Port , 0x2E , pVBInfo->LCDCapList[ index ].PWD_2E ) ;
8507     XGINew_SetReg1( pVBInfo->Part4Port , 0x2F , pVBInfo->LCDCapList[ index ].PWD_2F ) ;
8508     XGINew_SetRegOR( pVBInfo->Part4Port , 0x27 , 0x80 ) ;       /* enable PWD */
8509 }
8510
8511
8512 /* --------------------------------------------------------------------- */
8513 /* Function : XGI_DisablePWD */
8514 /* Input : */
8515 /* Output : */
8516 /* Description : */
8517 /* --------------------------------------------------------------------- */
8518 void XGI_DisablePWD( PVB_DEVICE_INFO pVBInfo )
8519 {
8520     XGINew_SetRegAND( pVBInfo->Part4Port , 0x27 , 0x7F ) ;      /* disable PWD */
8521 }
8522
8523
8524 /* --------------------------------------------------------------------- */
8525 /* Function : XGI_DisableChISLCD */
8526 /* Input : */
8527 /* Output : FALSE -> Not LCD Mode */
8528 /* Description : */
8529 /* --------------------------------------------------------------------- */
8530 BOOLEAN XGI_DisableChISLCD(PVB_DEVICE_INFO pVBInfo)
8531 {
8532     USHORT tempbx ,
8533            tempah ;
8534
8535     tempbx = pVBInfo->SetFlag & ( DisableChA | DisableChB ) ;
8536     tempah = ~( ( USHORT )XGINew_GetReg1( pVBInfo->Part1Port  , 0x2E ) ) ;
8537
8538     if ( tempbx & ( EnableChA | DisableChA ) )
8539     {
8540         if ( !( tempah & 0x08 ) )               /* Chk LCDA Mode */
8541             return FALSE ;
8542     }
8543
8544     if ( !( tempbx & ( EnableChB | DisableChB ) ) )
8545         return FALSE ;
8546
8547     if ( tempah & 0x01 )       /* Chk LCDB Mode */
8548         return TRUE ;
8549
8550     return FALSE ;
8551 }
8552
8553
8554 /* --------------------------------------------------------------------- */
8555 /* Function : XGI_EnableChISLCD */
8556 /* Input : */
8557 /* Output : 0 -> Not LCD mode */
8558 /* Description : */
8559 /* --------------------------------------------------------------------- */
8560 BOOLEAN XGI_EnableChISLCD(PVB_DEVICE_INFO pVBInfo)
8561 {
8562     USHORT tempbx ,
8563            tempah ;
8564
8565
8566     tempbx = pVBInfo->SetFlag & ( EnableChA | EnableChB ) ;
8567     tempah = ~( ( USHORT )XGINew_GetReg1( pVBInfo->Part1Port , 0x2E ) ) ;
8568
8569     if ( tempbx & ( EnableChA | DisableChA ) )
8570     {
8571         if ( !( tempah & 0x08 ) )               /* Chk LCDA Mode */
8572             return FALSE ;
8573     }
8574
8575     if ( !( tempbx & ( EnableChB | DisableChB ) ) )
8576         return FALSE ;
8577
8578     if ( tempah & 0x01 )       /* Chk LCDB Mode */
8579         return TRUE ;
8580
8581     return FALSE ;
8582 }
8583
8584
8585 /* --------------------------------------------------------------------- */
8586 /* Function : XGI_GetLCDCapPtr */
8587 /* Input : */
8588 /* Output : */
8589 /* Description : */
8590 /* --------------------------------------------------------------------- */
8591 USHORT XGI_GetLCDCapPtr(  PVB_DEVICE_INFO pVBInfo )
8592 {
8593     UCHAR tempal ,
8594           tempah ,
8595           tempbl ,
8596           i ;
8597
8598     tempah = XGINew_GetReg1( pVBInfo->P3d4 , 0x36 ) ;
8599     tempal = tempah & 0x0F ;
8600     tempah = tempah & 0xF0 ;
8601     i = 0 ;
8602     tempbl =  pVBInfo->LCDCapList[ i ].LCD_ID ;
8603
8604     while( tempbl != 0xFF )
8605     {
8606         if ( tempbl & 0x80 )   /* OEMUtil */
8607         {
8608             tempal = tempah ;
8609             tempbl = tempbl & ~( 0x80 ) ;
8610         }
8611
8612         if ( tempal == tempbl )
8613             break ;
8614
8615         i++ ;
8616
8617         tempbl = pVBInfo->LCDCapList[ i ].LCD_ID ;
8618     }
8619
8620     return i ;
8621 }
8622
8623
8624 /* --------------------------------------------------------------------- */
8625 /* Function : XGI_GetLCDCapPtr1 */
8626 /* Input : */
8627 /* Output : */
8628 /* Description : */
8629 /* --------------------------------------------------------------------- */
8630 USHORT XGI_GetLCDCapPtr1( PVB_DEVICE_INFO pVBInfo )
8631 {
8632     USHORT tempah ,
8633            tempal ,
8634            tempbl ,
8635            i ;
8636
8637     tempal = pVBInfo->LCDResInfo ;
8638     tempah = pVBInfo->LCDTypeInfo ;
8639
8640     i = 0 ;
8641     tempbl =  pVBInfo->LCDCapList[ i ].LCD_ID;
8642
8643     while( tempbl != 0xFF )
8644     {
8645         if ( ( tempbl & 0x80 ) && ( tempbl != 0x80 ) )
8646         {
8647             tempal = tempah ;
8648             tempbl &= ~0x80 ;
8649         }
8650
8651         if ( tempal == tempbl )
8652             break ;
8653
8654         i++ ;
8655         tempbl = pVBInfo->LCDCapList[ i ].LCD_ID ;
8656     }
8657
8658     if ( tempbl == 0xFF )
8659     {
8660         pVBInfo->LCDResInfo = Panel1024x768 ;
8661         pVBInfo->LCDTypeInfo = 0 ;
8662         i = 0 ;
8663     }
8664
8665     return i ;
8666 }
8667
8668
8669 /* --------------------------------------------------------------------- */
8670 /* Function : XGI_GetLCDSync */
8671 /* Input : */
8672 /* Output : */
8673 /* Description : */
8674 /* --------------------------------------------------------------------- */
8675 void XGI_GetLCDSync( USHORT* HSyncWidth , USHORT* VSyncWidth, PVB_DEVICE_INFO pVBInfo )
8676 {
8677     USHORT Index ;
8678
8679     Index = XGI_GetLCDCapPtr(pVBInfo) ;
8680     *HSyncWidth = pVBInfo->LCDCapList[ Index ].LCD_HSyncWidth ;
8681     *VSyncWidth = pVBInfo->LCDCapList[ Index ].LCD_VSyncWidth ;
8682
8683     return ;
8684 }
8685
8686
8687
8688 /* --------------------------------------------------------------------- */
8689 /* Function : XGI_EnableBridge */
8690 /* Input : */
8691 /* Output : */
8692 /* Description : */
8693 /* --------------------------------------------------------------------- */
8694 void XGI_EnableBridge( PXGI_HW_DEVICE_INFO HwDeviceExtension , PVB_DEVICE_INFO pVBInfo)
8695 {
8696     USHORT tempbl ,
8697            tempah ;
8698
8699     if ( pVBInfo->SetFlag == Win9xDOSMode )
8700     {
8701         if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
8702         {
8703             XGI_DisplayOn( HwDeviceExtension, pVBInfo) ;
8704             return ;
8705         }
8706         else  /* LVDS or CH7017 */
8707             return ;
8708     }
8709
8710
8711     if ( HwDeviceExtension->jChipType < XG40 )
8712     {
8713         if ( !XGI_DisableChISLCD(pVBInfo) )
8714         {
8715             if ( ( XGI_EnableChISLCD(pVBInfo) ) || ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) ) )
8716             {
8717                 if ( pVBInfo->LCDInfo & SetPWDEnable )
8718                 {
8719                     XGI_EnablePWD( pVBInfo);
8720                 }
8721                 else
8722                 {
8723                     pVBInfo->LCDInfo &= ( ~SetPWDEnable ) ;
8724                     if ( pVBInfo->VBType & ( VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
8725                     {
8726                         tempbl = 0xFD ;
8727                         tempah = 0x02 ;
8728                     }
8729                     else
8730                     {
8731                         tempbl = 0xFB ;
8732                         tempah = 0x00 ;
8733                     }
8734
8735                     XGI_SetPanelPower( tempah , tempbl, pVBInfo ) ;
8736                     XGI_SetPanelDelay( 1,pVBInfo ) ;
8737                 }
8738             }
8739         }
8740     }   /* Not 340 */
8741
8742
8743
8744     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
8745     {
8746         if ( !( pVBInfo->SetFlag & DisableChA ) )
8747         {
8748             if ( pVBInfo->SetFlag & EnableChA )
8749             {
8750                 XGINew_SetReg1( pVBInfo->Part1Port , 0x1E , 0x20 ) ;  /* Power on */
8751             }
8752             else
8753             {
8754                 if ( pVBInfo->VBInfo & SetCRT2ToDualEdge ) /* SetCRT2ToLCDA ) */
8755                 {
8756                     XGINew_SetReg1(pVBInfo->Part1Port,0x1E,0x20);  /* Power on */
8757                 }
8758             }
8759         }
8760
8761         if ( !( pVBInfo->SetFlag & DisableChB ) )
8762         {
8763             if ( ( pVBInfo->SetFlag & EnableChB ) || ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToTV | SetCRT2ToRAMDAC ) ) )
8764             {
8765                 tempah = ( UCHAR )XGINew_GetReg1( pVBInfo->P3c4 , 0x32 ) ;
8766                 tempah &= 0xDF;
8767                 if ( pVBInfo->VBInfo & SetInSlaveMode )
8768                 {
8769                     if ( !( pVBInfo->VBInfo & SetCRT2ToRAMDAC ) )
8770                         tempah |= 0x20 ;
8771                 }
8772                 XGINew_SetReg1( pVBInfo->P3c4 , 0x32 , tempah ) ;
8773                 XGINew_SetRegOR( pVBInfo->P3c4 , 0x1E , 0x20 ) ;
8774
8775
8776                 tempah = ( UCHAR )XGINew_GetReg1( pVBInfo->Part1Port , 0x2E ) ;
8777
8778                 if ( !( tempah & 0x80 ) )
8779                     XGINew_SetRegOR( pVBInfo->Part1Port , 0x2E , 0x80 ) ;       /* BVBDOENABLE = 1 */
8780
8781                 XGINew_SetRegAND( pVBInfo->Part1Port , 0x00 , 0x7F ) ;          /* BScreenOFF = 0 */
8782             }
8783         }
8784
8785         if ( ( pVBInfo->SetFlag & ( EnableChA | EnableChB ) ) || ( !( pVBInfo->VBInfo & DisableCRT2Display ) ) )
8786         {
8787             XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x00 , ~0xE0 , 0x20 ) ;   /* shampoo 0129 */
8788             if ( pVBInfo->VBType & ( VB_XGI302LV | VB_XGI301C ) )
8789             {
8790                 if ( !XGI_DisableChISLCD(pVBInfo) )
8791                 {
8792                     if ( XGI_EnableChISLCD( pVBInfo) || ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) ) )
8793                         XGINew_SetRegAND( pVBInfo->Part4Port ,0x2A , 0x7F ) ;   /* LVDS PLL power on */
8794                 }
8795                 XGINew_SetRegAND( pVBInfo->Part4Port , 0x30 , 0x7F ) ;          /* LVDS Driver power on */
8796             }
8797         }
8798
8799         tempah = 0x00 ;
8800
8801         if ( !( pVBInfo->VBInfo & DisableCRT2Display ) )
8802         {
8803             tempah = 0xc0 ;
8804
8805             if ( !( pVBInfo->VBInfo & SetSimuScanMode ) )
8806             {
8807                 if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
8808                 {
8809                     if ( pVBInfo->VBInfo & SetCRT2ToDualEdge )
8810                     {
8811                         tempah = tempah & 0x40;
8812                         if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
8813                             tempah = tempah ^ 0xC0 ;
8814
8815                         if ( pVBInfo->SetFlag & DisableChB )
8816                             tempah &= 0xBF ;
8817
8818                         if ( pVBInfo->SetFlag & DisableChA )
8819                             tempah &= 0x7F ;
8820
8821                         if ( pVBInfo->SetFlag & EnableChB )
8822                             tempah |= 0x40 ;
8823
8824                         if ( pVBInfo->SetFlag & EnableChA )
8825                             tempah |= 0x80 ;
8826                     }
8827                 }
8828             }
8829         }
8830
8831         XGINew_SetRegOR( pVBInfo->Part4Port , 0x1F , tempah ) ;          /* EnablePart4_1F */
8832
8833         if ( pVBInfo->SetFlag & Win9xDOSMode )
8834         {
8835             XGI_DisplayOn( HwDeviceExtension, pVBInfo) ;
8836             return ;
8837         }
8838
8839         if ( !( pVBInfo->SetFlag & DisableChA ) )
8840         {
8841             XGI_VBLongWait( pVBInfo) ;
8842             if ( !( pVBInfo->SetFlag & GatingCRT ) )
8843             {
8844                 XGI_DisableGatingCRT( HwDeviceExtension, pVBInfo ) ;
8845                 XGI_DisplayOn( HwDeviceExtension, pVBInfo) ;
8846                 XGI_VBLongWait( pVBInfo) ;
8847             }
8848         }
8849     }   /* 301 */
8850     else        /* LVDS */
8851     {
8852         if ( pVBInfo->VBInfo & ( SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA ) )
8853             XGINew_SetRegOR( pVBInfo->Part1Port , 0x1E , 0x20 ) ;       /* enable CRT2 */
8854
8855
8856
8857         tempah = ( UCHAR )XGINew_GetReg1( pVBInfo->Part1Port , 0x2E ) ;
8858         if ( !( tempah & 0x80 ) )
8859             XGINew_SetRegOR( pVBInfo->Part1Port , 0x2E , 0x80 ) ;       /* BVBDOENABLE = 1 */
8860
8861         XGINew_SetRegAND(pVBInfo->Part1Port,0x00,0x7F);
8862         XGI_DisplayOn( HwDeviceExtension, pVBInfo);
8863     } /* End of VB */
8864
8865
8866     if ( HwDeviceExtension->jChipType < XG40 )
8867     {
8868         if ( !XGI_EnableChISLCD(pVBInfo) )
8869         {
8870             if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
8871             {
8872                 if ( XGI_BacklightByDrv(pVBInfo) )
8873                     return ;
8874             }
8875             else
8876                 return ;
8877         }
8878
8879         if ( pVBInfo->LCDInfo & SetPWDEnable )
8880         {
8881             XGI_FirePWDEnable(pVBInfo) ;
8882             return ;
8883         }
8884
8885         XGI_SetPanelDelay( 2,pVBInfo ) ;
8886
8887         if ( pVBInfo->VBType & ( VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
8888         {
8889             tempah = 0x01 ;
8890             tempbl = 0xFE ;             /* turn on backlght */
8891         }
8892         else
8893         {
8894             tempbl = 0xF7 ;
8895             tempah = 0x00 ;
8896         }
8897         XGI_SetPanelPower( tempah , tempbl , pVBInfo) ;
8898     }
8899 }
8900
8901
8902 /* --------------------------------------------------------------------- */
8903 /* Function : XGI_DisableBridge */
8904 /* Input : */
8905 /* Output : */
8906 /* Description : */
8907 /* --------------------------------------------------------------------- */
8908 void XGI_DisableBridge(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
8909 {
8910     USHORT tempax ,
8911            tempbx ,
8912            tempah = 0 ,
8913            tempbl = 0 ;
8914
8915     if ( pVBInfo->SetFlag == Win9xDOSMode )
8916         return ;
8917
8918
8919     if ( HwDeviceExtension->jChipType < XG40 )
8920     {
8921         if ( ( !( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) ) ) || ( XGI_DisableChISLCD(pVBInfo) ) )
8922         {
8923             if ( !XGI_IsLCDON(pVBInfo) )
8924             {
8925                 if ( pVBInfo->LCDInfo & SetPWDEnable )
8926                     XGI_EnablePWD( pVBInfo) ;
8927                 else
8928                 {
8929                     pVBInfo->LCDInfo &= ~SetPWDEnable ;
8930                     XGI_DisablePWD(pVBInfo) ;
8931                     if ( pVBInfo->VBType & ( VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
8932                     {
8933                         tempbx = 0xFE ;  /* not 01h */
8934                         tempax = 0 ;
8935                     }
8936                     else
8937                     {
8938                         tempbx = 0xF7 ;  /* not 08h */
8939                         tempax = 0x08 ;
8940                     }
8941                     XGI_SetPanelPower( tempax , tempbx , pVBInfo) ;
8942                     XGI_SetPanelDelay( 3,pVBInfo ) ;
8943                 }
8944             }   /* end if(!XGI_IsLCDON(pVBInfo)) */
8945         }
8946     }
8947
8948 /*  if ( CH7017 )
8949     {
8950         if ( !( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2toLCDA ) ) || ( XGI_DisableChISLCD(pVBInfo) ) )
8951         {
8952             if ( !XGI_IsLCDON(pVBInfo) )
8953             {
8954                 if ( DISCHARGE )
8955                 {
8956                     tempbx = XGINew_GetCH7005( 0x61 ) ;
8957                     if ( tempbx < 0x01 )   //first time we power up
8958                         XGINew_SetCH7005( 0x0066 ) ;    //and disable power sequence
8959                     else
8960                         XGINew_SetCH7005( 0x5f66 ) ; //leave VDD on - disable power
8961                 }
8962             }
8963         }
8964     }        */
8965
8966     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B| VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
8967     {
8968         tempah = 0x3F ;
8969         if ( !( pVBInfo->VBInfo & ( DisableCRT2Display | SetSimuScanMode ) ) )
8970         {
8971             if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
8972             {
8973                 if ( pVBInfo->VBInfo & SetCRT2ToDualEdge )
8974                 {
8975                     tempah = 0x7F;                      /* Disable Channel A */
8976                     if ( !( pVBInfo->VBInfo & SetCRT2ToLCDA ) )
8977                         tempah = 0xBF ;         /* Disable Channel B */
8978
8979                     if ( pVBInfo->SetFlag & DisableChB )
8980                         tempah &= 0xBF ;                /* force to disable Cahnnel */
8981
8982                     if ( pVBInfo->SetFlag & DisableChA )
8983                         tempah &= 0x7F ;                /* Force to disable Channel B */
8984                 }
8985             }
8986         }
8987
8988         XGINew_SetRegAND( pVBInfo->Part4Port , 0x1F , tempah ) ;   /* disable part4_1f */
8989
8990         if ( pVBInfo->VBType & ( VB_XGI302LV | VB_XGI301C ) )
8991         {
8992             if ( ( ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) ) ) || ( XGI_DisableChISLCD(pVBInfo) ) || ( XGI_IsLCDON(pVBInfo) ) )
8993                 XGINew_SetRegOR( pVBInfo->Part4Port , 0x30 , 0x80 ) ;  /* LVDS Driver power down */
8994         }
8995
8996         if ( ( pVBInfo->SetFlag & DisableChA ) || ( pVBInfo->VBInfo & ( DisableCRT2Display | SetCRT2ToLCDA | SetSimuScanMode ) ) )
8997         {
8998             if ( pVBInfo->SetFlag & GatingCRT )
8999                 XGI_EnableGatingCRT( HwDeviceExtension, pVBInfo ) ;
9000             XGI_DisplayOff( HwDeviceExtension, pVBInfo) ;
9001         }
9002
9003         if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
9004         {
9005             if ( ( pVBInfo->SetFlag & DisableChA ) || ( pVBInfo->VBInfo & SetCRT2ToLCDA ) )
9006                 XGINew_SetRegAND( pVBInfo->Part1Port , 0x1e , 0xdf ) ;  /* Power down */
9007         }
9008
9009         XGINew_SetRegAND( pVBInfo->P3c4 , 0x32 , 0xdf ) ;               /* disable TV as primary VGA swap */
9010
9011         if ( ( pVBInfo->VBInfo & ( SetSimuScanMode | SetCRT2ToDualEdge  ) ) )
9012             XGINew_SetRegAND(pVBInfo->Part2Port,0x00,0xdf);
9013
9014         if ( ( pVBInfo->SetFlag & DisableChB ) || ( pVBInfo->VBInfo & ( DisableCRT2Display | SetSimuScanMode ) )
9015         || ( ( !( pVBInfo->VBInfo & SetCRT2ToLCDA ) ) && ( pVBInfo->VBInfo & ( SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV ) ) ) )
9016             XGINew_SetRegOR( pVBInfo->Part1Port , 0x00 , 0x80 ) ;       /* BScreenOff=1 */
9017
9018         if ( ( pVBInfo->SetFlag & DisableChB ) || ( pVBInfo->VBInfo & ( DisableCRT2Display | SetSimuScanMode ) )
9019         || ( !( pVBInfo->VBInfo & SetCRT2ToLCDA ) ) || ( pVBInfo->VBInfo & ( SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV ) ) )
9020         {
9021             tempah= XGINew_GetReg1( pVBInfo->Part1Port , 0x00 ) ;       /* save Part1 index 0 */
9022             XGINew_SetRegOR( pVBInfo->Part1Port , 0x00 , 0x10 ) ;       /* BTDAC = 1, avoid VB reset */
9023             XGINew_SetRegAND( pVBInfo->Part1Port , 0x1E , 0xDF ) ;      /* disable CRT2 */
9024             XGINew_SetReg1( pVBInfo->Part1Port , 0x00 , tempah ) ;      /* restore Part1 index 0 */
9025         }
9026     }
9027     else /* {301} */
9028     {
9029         if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToTV ) )
9030         {
9031             XGINew_SetRegOR( pVBInfo->Part1Port , 0x00 , 0x80 ) ;       /* BScreenOff=1 */
9032             XGINew_SetRegAND( pVBInfo->Part1Port , 0x1E , 0xDF ) ;      /* Disable CRT2 */
9033             XGINew_SetRegAND( pVBInfo->P3c4 , 0x32 , 0xDF ) ;   /* Disable TV asPrimary VGA swap */
9034         }
9035
9036         if ( pVBInfo->VBInfo & ( DisableCRT2Display | SetCRT2ToLCDA | SetSimuScanMode ) )
9037             XGI_DisplayOff( HwDeviceExtension, pVBInfo) ;
9038     }
9039
9040
9041
9042
9043     if ( HwDeviceExtension->jChipType < XG40 )
9044     {
9045         if ( !( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) ) || ( XGI_DisableChISLCD(pVBInfo) ) || ( XGI_IsLCDON(pVBInfo) ) )
9046         {
9047             if ( pVBInfo->LCDInfo & SetPWDEnable )
9048             {
9049                 if ( pVBInfo->LCDInfo & SetPWDEnable )
9050                     XGI_BacklightByDrv(pVBInfo) ;
9051                 else
9052                 {
9053                     XGI_SetPanelDelay( 4 ,pVBInfo) ;
9054                     if ( pVBInfo->VBType & VB_XGI301LV )
9055                     {
9056                         tempbl = 0xFD ;
9057                         tempah = 0x00 ;
9058                     }
9059                     else
9060                     {
9061                         tempbl = 0xFB ;
9062                         tempah = 0x04 ;
9063                     }
9064                 }
9065             }
9066             XGI_SetPanelPower( tempah , tempbl , pVBInfo) ;
9067         }
9068     }
9069 }
9070
9071
9072 /* --------------------------------------------------------------------- */
9073 /* Function : XGI_GetTVPtrIndex */
9074 /* Input : */
9075 /* Output : */
9076 /* Description : bx 0 : ExtNTSC */
9077 /* 1 : StNTSC */
9078 /* 2 : ExtPAL */
9079 /* 3 : StPAL */
9080 /* 4 : ExtHiTV */
9081 /* 5 : StHiTV */
9082 /* 6 : Ext525i */
9083 /* 7 : St525i */
9084 /* 8 : Ext525p */
9085 /* 9 : St525p */
9086 /* A : Ext750p */
9087 /* B : St750p */
9088 /* --------------------------------------------------------------------- */
9089 USHORT XGI_GetTVPtrIndex(  PVB_DEVICE_INFO pVBInfo )
9090 {
9091     USHORT tempbx = 0 ;
9092
9093     if ( pVBInfo->TVInfo & SetPALTV )
9094         tempbx = 2 ;
9095     if ( pVBInfo->TVInfo & SetYPbPrMode1080i )
9096         tempbx = 4 ;
9097     if ( pVBInfo->TVInfo & SetYPbPrMode525i )
9098         tempbx = 6 ;
9099     if ( pVBInfo->TVInfo & SetYPbPrMode525p )
9100         tempbx = 8 ;
9101     if ( pVBInfo->TVInfo & SetYPbPrMode750p )
9102         tempbx = 10 ;
9103     if ( pVBInfo->TVInfo & TVSimuMode )
9104         tempbx++ ;
9105
9106     return tempbx ;
9107 }
9108
9109
9110 /* --------------------------------------------------------------------- */
9111 /* Function : XGI_OEM310Setting */
9112 /* Input : */
9113 /* Output : */
9114 /* Description : Customized Param. for 301 */
9115 /* --------------------------------------------------------------------- */
9116 void XGI_OEM310Setting( USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo)
9117 {
9118     if ( pVBInfo->SetFlag & Win9xDOSMode )
9119         return ;
9120
9121     /* GetPart1IO(); */
9122     XGI_SetDelayComp(pVBInfo) ;
9123
9124     if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
9125         XGI_SetLCDCap(pVBInfo) ;
9126
9127     if ( pVBInfo->VBInfo & SetCRT2ToTV )
9128     {
9129         /* GetPart2IO() */
9130         XGI_SetPhaseIncr(pVBInfo) ;
9131         XGI_SetYFilter( ModeNo , ModeIdIndex,pVBInfo ) ;
9132         XGI_SetAntiFlicker( ModeNo , ModeIdIndex,pVBInfo ) ;
9133
9134         if ( pVBInfo->VBType&VB_XGI301)
9135             XGI_SetEdgeEnhance( ModeNo , ModeIdIndex ,pVBInfo) ;
9136     }
9137 }
9138
9139
9140 /* --------------------------------------------------------------------- */
9141 /* Function : XGI_SetDelayComp */
9142 /* Input : */
9143 /* Output : */
9144 /* Description : */
9145 /* --------------------------------------------------------------------- */
9146 void XGI_SetDelayComp( PVB_DEVICE_INFO pVBInfo )
9147 {
9148     USHORT index ;
9149
9150     UCHAR  tempah ,
9151            tempbl ,
9152            tempbh ;
9153
9154     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9155     {
9156         if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToTV | SetCRT2ToRAMDAC ) )
9157         {
9158             tempbl = 0;
9159             tempbh = 0;
9160
9161             index = XGI_GetTVPtrIndex(pVBInfo ) ;           /* Get TV Delay */
9162             tempbl = pVBInfo->XGI_TVDelayList[ index ] ;
9163
9164             if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9165                 tempbl = pVBInfo->XGI_TVDelayList2[ index ] ;
9166
9167             if ( pVBInfo->VBInfo & SetCRT2ToDualEdge )
9168                 tempbl = tempbl >> 4 ;
9169 /*
9170             if ( pVBInfo->VBInfo & SetCRT2ToRAMDAC )
9171                 tempbl = CRT2Delay1 ;                   // Get CRT2 Delay
9172
9173             if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9174                 tempbl = CRT2Delay2 ;
9175 */
9176             if ( pVBInfo->VBInfo & ( SetCRT2ToLCD | SetCRT2ToLCDA ) )
9177             {
9178                 index = XGI_GetLCDCapPtr(pVBInfo) ;             /* Get LCD Delay */
9179                 tempbh=pVBInfo->LCDCapList[ index ].LCD_DelayCompensation ;
9180
9181                 if ( !( pVBInfo->VBInfo & SetCRT2ToLCDA ) )
9182                      tempbl = tempbh ;
9183             }
9184
9185             tempbl  &= 0x0F ;
9186             tempbh  &= 0xF0 ;
9187             tempah = XGINew_GetReg1( pVBInfo->Part1Port , 0x2D ) ;
9188
9189             if ( pVBInfo->VBInfo & ( SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV ) )  /* Channel B */
9190             {
9191                 tempah &= 0xF0 ;
9192                 tempah |= tempbl ;
9193             }
9194
9195             if ( pVBInfo->VBInfo & SetCRT2ToLCDA )              /* Channel A */
9196             {
9197                 tempah &= 0x0F ;
9198                 tempah |= tempbh ;
9199             }
9200             XGINew_SetReg1(pVBInfo->Part1Port,0x2D,tempah);
9201         }
9202     }
9203     else if ( pVBInfo->IF_DEF_LVDS == 1 )
9204     {
9205         tempbl = 0;
9206         tempbh = 0;
9207         if ( pVBInfo->VBInfo & SetCRT2ToLCD )
9208         {
9209             tempah = pVBInfo->LCDCapList[ XGI_GetLCDCapPtr(pVBInfo) ].LCD_DelayCompensation ;           /* / Get LCD Delay */
9210             tempah &= 0x0f ;
9211             tempah = tempah << 4 ;
9212             XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2D , 0x0f , tempah ) ;
9213         }
9214     }
9215 }
9216
9217
9218 /* --------------------------------------------------------------------- */
9219 /* Function : XGI_SetLCDCap */
9220 /* Input : */
9221 /* Output : */
9222 /* Description : */
9223 /* --------------------------------------------------------------------- */
9224 void XGI_SetLCDCap( PVB_DEVICE_INFO pVBInfo )
9225 {
9226     USHORT tempcx ;
9227
9228     tempcx = pVBInfo->LCDCapList[ XGI_GetLCDCapPtr(pVBInfo) ].LCD_Capability ;
9229
9230     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9231     {
9232         if ( pVBInfo->VBType & ( VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9233         {                                       /* 301LV/302LV only */
9234             /* Set 301LV Capability */
9235             XGINew_SetReg1( pVBInfo->Part4Port , 0x24 , ( UCHAR )( tempcx & 0x1F ) ) ;
9236         }
9237         /* VB Driving */
9238         XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x0D , ~( ( EnableVBCLKDRVLOW | EnablePLLSPLOW ) >> 8 ) , ( USHORT )( ( tempcx & ( EnableVBCLKDRVLOW | EnablePLLSPLOW ) ) >> 8 ) ) ;
9239     }
9240
9241     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9242     {
9243         if ( pVBInfo->VBInfo & SetCRT2ToLCD )
9244             XGI_SetLCDCap_B( tempcx,pVBInfo ) ;
9245         else if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
9246             XGI_SetLCDCap_A( tempcx,pVBInfo ) ;
9247
9248         if ( pVBInfo->VBType & ( VB_XGI302LV | VB_XGI301C ) )
9249         {
9250             if ( tempcx & EnableSpectrum )
9251                 SetSpectrum( pVBInfo) ;
9252         }
9253     }
9254     else      /* LVDS,CH7017 */
9255         XGI_SetLCDCap_A( tempcx, pVBInfo ) ;
9256 }
9257
9258
9259 /* --------------------------------------------------------------------- */
9260 /* Function : XGI_SetLCDCap_A */
9261 /* Input : */
9262 /* Output : */
9263 /* Description : */
9264 /* --------------------------------------------------------------------- */
9265 void XGI_SetLCDCap_A(USHORT tempcx,PVB_DEVICE_INFO pVBInfo)
9266 {
9267     USHORT temp ;
9268
9269     temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x37 ) ;
9270
9271     if ( temp & LCDRGB18Bit )
9272     {
9273         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x19 , 0x0F , ( USHORT )( 0x20 | ( tempcx & 0x00C0 ) ) ) ; /* Enable Dither */
9274         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x1A , 0x7F , 0x80 ) ;
9275     }
9276     else
9277     {
9278         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x19 , 0x0F , ( USHORT )( 0x30 | ( tempcx & 0x00C0 ) ) ) ;
9279         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x1A , 0x7F , 0x00 ) ;
9280     }
9281
9282 /*
9283     if ( tempcx & EnableLCD24bpp )      // 24bits
9284     {
9285         XGINew_SetRegANDOR(pVBInfo->Part1Port,0x19, 0x0F,(USHORT)(0x30|(tempcx&0x00C0)) );
9286         XGINew_SetRegANDOR(pVBInfo->Part1Port,0x1A,0x7F,0x00);
9287     }
9288     else
9289     {
9290         XGINew_SetRegANDOR(pVBInfo->Part1Port,0x19, 0x0F,(USHORT)(0x20|(tempcx&0x00C0)) );//Enable Dither
9291         XGINew_SetRegANDOR(pVBInfo->Part1Port,0x1A,0x7F,0x80);
9292     }
9293 */
9294 }
9295
9296
9297 /* --------------------------------------------------------------------- */
9298 /* Function : XGI_SetLCDCap_B */
9299 /* Input : cx -> LCD Capability */
9300 /* Output : */
9301 /* Description : */
9302 /* --------------------------------------------------------------------- */
9303 void XGI_SetLCDCap_B(USHORT tempcx,PVB_DEVICE_INFO pVBInfo)
9304 {
9305     if ( tempcx & EnableLCD24bpp )      /* 24bits */
9306         XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x1A , 0xE0 , ( USHORT )( ( ( tempcx & 0x00ff ) >> 6 ) | 0x0c ) ) ;
9307     else
9308         XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x1A , 0xE0 , ( USHORT )( ( ( tempcx & 0x00ff ) >> 6 ) | 0x18 ) ) ; /* Enable Dither */
9309 }
9310
9311
9312 /* --------------------------------------------------------------------- */
9313 /* Function : SetSpectrum */
9314 /* Input : */
9315 /* Output : */
9316 /* Description : */
9317 /* --------------------------------------------------------------------- */
9318 void SetSpectrum( PVB_DEVICE_INFO pVBInfo )
9319 {
9320     USHORT index ;
9321
9322     index = XGI_GetLCDCapPtr(pVBInfo) ;
9323
9324     XGINew_SetRegAND( pVBInfo->Part4Port , 0x30 , 0x8F ) ;   /* disable down spectrum D[4] */
9325     XGI_LongWait(pVBInfo) ;
9326     XGINew_SetRegOR( pVBInfo->Part4Port , 0x30 , 0x20 ) ;        /* reset spectrum */
9327     XGI_LongWait(pVBInfo) ;
9328
9329     XGINew_SetReg1( pVBInfo->Part4Port , 0x31 , pVBInfo->LCDCapList[ index ].Spectrum_31 ) ;
9330     XGINew_SetReg1( pVBInfo->Part4Port , 0x32 , pVBInfo->LCDCapList[ index ].Spectrum_32 ) ;
9331     XGINew_SetReg1( pVBInfo->Part4Port , 0x33 , pVBInfo->LCDCapList[ index ].Spectrum_33 ) ;
9332     XGINew_SetReg1( pVBInfo->Part4Port , 0x34 , pVBInfo->LCDCapList[ index ].Spectrum_34 ) ;
9333     XGI_LongWait(pVBInfo) ;
9334     XGINew_SetRegOR( pVBInfo->Part4Port , 0x30 , 0x40 ) ; /* enable spectrum */
9335 }
9336
9337
9338 /* --------------------------------------------------------------------- */
9339 /* Function : XGI_SetAntiFlicker */
9340 /* Input : */
9341 /* Output : */
9342 /* Description : Set TV Customized Param. */
9343 /* --------------------------------------------------------------------- */
9344 void XGI_SetAntiFlicker( USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo )
9345 {
9346     USHORT tempbx ,
9347            index ;
9348
9349     UCHAR tempah ;
9350
9351     if (pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p ) )
9352         return ;
9353
9354     tempbx = XGI_GetTVPtrIndex(pVBInfo ) ;
9355     tempbx &= 0xFE ;
9356
9357     if ( ModeNo <= 0x13 )
9358     {
9359         index = pVBInfo->SModeIDTable[ ModeIdIndex ].VB_StTVFlickerIndex ;
9360     }
9361     else
9362     {
9363         index = pVBInfo->EModeIDTable[ ModeIdIndex ].VB_ExtTVFlickerIndex ;
9364     }
9365
9366     tempbx += index ;
9367     tempah = TVAntiFlickList[ tempbx ] ;
9368     tempah = tempah << 4 ;
9369
9370     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x0A , 0x8F , tempah ) ;
9371 }
9372
9373
9374 /* --------------------------------------------------------------------- */
9375 /* Function : XGI_SetEdgeEnhance */
9376 /* Input : */
9377 /* Output : */
9378 /* Description : */
9379 /* --------------------------------------------------------------------- */
9380 void XGI_SetEdgeEnhance( USHORT ModeNo , USHORT ModeIdIndex , PVB_DEVICE_INFO pVBInfo)
9381 {
9382     USHORT tempbx ,
9383            index ;
9384
9385     UCHAR tempah ;
9386
9387
9388     tempbx = XGI_GetTVPtrIndex(pVBInfo ) ;
9389     tempbx &= 0xFE ;
9390
9391     if ( ModeNo <= 0x13 )
9392     {
9393         index = pVBInfo->SModeIDTable[ ModeIdIndex ].VB_StTVEdgeIndex ;
9394     }
9395     else
9396     {
9397         index = pVBInfo->EModeIDTable[ ModeIdIndex ].VB_ExtTVEdgeIndex ;
9398     }
9399
9400     tempbx += index ;
9401     tempah = TVEdgeList[ tempbx ] ;
9402     tempah = tempah << 5 ;
9403
9404     XGINew_SetRegANDOR( pVBInfo->Part2Port , 0x3A , 0x1F , tempah ) ;
9405 }
9406
9407
9408 /* --------------------------------------------------------------------- */
9409 /* Function : XGI_SetPhaseIncr */
9410 /* Input : */
9411 /* Output : */
9412 /* Description : */
9413 /* --------------------------------------------------------------------- */
9414 void XGI_SetPhaseIncr( PVB_DEVICE_INFO pVBInfo )
9415 {
9416     USHORT tempbx ;
9417
9418     UCHAR tempcl ,
9419           tempch ;
9420
9421     ULONG tempData ;
9422
9423     XGI_GetTVPtrIndex2( &tempbx , &tempcl , &tempch, pVBInfo ) ; /* bx, cl, ch */
9424     tempData = TVPhaseList[ tempbx ] ;
9425
9426     XGINew_SetReg1( pVBInfo->Part2Port , 0x31 , ( USHORT )( tempData & 0x000000FF ) ) ;
9427     XGINew_SetReg1( pVBInfo->Part2Port , 0x32 , ( USHORT )( ( tempData & 0x0000FF00 ) >> 8 ) ) ;
9428     XGINew_SetReg1( pVBInfo->Part2Port , 0x33 , ( USHORT )( ( tempData & 0x00FF0000 ) >> 16 ) ) ;
9429     XGINew_SetReg1( pVBInfo->Part2Port , 0x34 , ( USHORT )( ( tempData & 0xFF000000 ) >> 24 ) ) ;
9430 }
9431
9432
9433 /* --------------------------------------------------------------------- */
9434 /* Function : XGI_SetYFilter */
9435 /* Input : */
9436 /* Output : */
9437 /* Description : */
9438 /* --------------------------------------------------------------------- */
9439 void XGI_SetYFilter( USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo)
9440 {
9441     USHORT tempbx ,
9442            index ;
9443
9444     UCHAR tempcl ,
9445           tempch ,
9446           tempal ,
9447           *filterPtr ;
9448
9449     XGI_GetTVPtrIndex2( &tempbx , &tempcl , &tempch, pVBInfo ) ; /* bx, cl, ch */
9450
9451     switch( tempbx )
9452     {
9453         case 0x00:
9454         case 0x04:
9455             filterPtr = NTSCYFilter1 ;
9456             break ;
9457
9458         case 0x01:
9459             filterPtr = PALYFilter1 ;
9460             break ;
9461
9462         case 0x02:
9463         case 0x05:
9464         case 0x0D:
9465             filterPtr = PALMYFilter1 ;
9466             break ;
9467
9468         case 0x03:
9469             filterPtr = PALNYFilter1 ;
9470             break ;
9471
9472         case 0x08:
9473         case 0x0C:
9474             filterPtr = NTSCYFilter2 ;
9475             break ;
9476
9477         case 0x0A:
9478             filterPtr = PALMYFilter2 ;
9479             break ;
9480
9481         case 0x0B:
9482             filterPtr = PALNYFilter2 ;
9483             break ;
9484
9485         case 0x09:
9486             filterPtr = PALYFilter2 ;
9487             break ;
9488
9489         default:
9490             return ;
9491     }
9492
9493     if ( ModeNo <= 0x13 )
9494         tempal = pVBInfo->SModeIDTable[ ModeIdIndex ].VB_StTVYFilterIndex ;
9495     else
9496         tempal = pVBInfo->EModeIDTable[ ModeIdIndex ].VB_ExtTVYFilterIndex ;
9497
9498     if ( tempcl == 0 )
9499         index = tempal * 4;
9500     else
9501         index = tempal * 7;
9502
9503     if ( ( tempcl == 0 ) && ( tempch == 1 ) )
9504     {
9505         XGINew_SetReg1( pVBInfo->Part2Port , 0x35 , 0 ) ;
9506         XGINew_SetReg1( pVBInfo->Part2Port , 0x36 , 0 ) ;
9507         XGINew_SetReg1( pVBInfo->Part2Port , 0x37 , 0 ) ;
9508         XGINew_SetReg1( pVBInfo->Part2Port , 0x38 , filterPtr[ index++ ] ) ;
9509     }
9510     else
9511     {
9512         XGINew_SetReg1( pVBInfo->Part2Port , 0x35 , filterPtr[ index++ ] ) ;
9513         XGINew_SetReg1( pVBInfo->Part2Port , 0x36 , filterPtr[ index++ ] ) ;
9514         XGINew_SetReg1( pVBInfo->Part2Port , 0x37 , filterPtr[ index++ ] ) ;
9515         XGINew_SetReg1( pVBInfo->Part2Port , 0x38 , filterPtr[ index++ ] ) ;
9516     }
9517
9518     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9519     {
9520         XGINew_SetReg1( pVBInfo->Part2Port , 0x48 , filterPtr[ index++ ] ) ;
9521         XGINew_SetReg1( pVBInfo->Part2Port , 0x49 , filterPtr[ index++ ] ) ;
9522         XGINew_SetReg1( pVBInfo->Part2Port , 0x4A , filterPtr[ index++ ] ) ;
9523     }
9524 }
9525
9526
9527 /* --------------------------------------------------------------------- */
9528 /* Function : XGI_GetTVPtrIndex2 */
9529 /* Input : */
9530 /* Output : bx 0 : NTSC */
9531 /* 1 : PAL */
9532 /* 2 : PALM */
9533 /* 3 : PALN */
9534 /* 4 : NTSC1024x768 */
9535 /* 5 : PAL-M 1024x768 */
9536 /* 6-7: reserved */
9537 /* cl 0 : YFilter1 */
9538 /* 1 : YFilter2 */
9539 /* ch 0 : 301A */
9540 /* 1 : 301B/302B/301LV/302LV */
9541 /* Description : */
9542 /* --------------------------------------------------------------------- */
9543 void XGI_GetTVPtrIndex2(USHORT* tempbx,UCHAR* tempcl,UCHAR* tempch, PVB_DEVICE_INFO pVBInfo)
9544 {
9545     *tempbx = 0 ;
9546     *tempcl = 0 ;
9547     *tempch = 0 ;
9548
9549     if ( pVBInfo->TVInfo & SetPALTV )
9550         *tempbx = 1 ;
9551
9552     if ( pVBInfo->TVInfo & SetPALMTV )
9553         *tempbx = 2 ;
9554
9555     if ( pVBInfo->TVInfo & SetPALNTV )
9556         *tempbx = 3 ;
9557
9558     if ( pVBInfo->TVInfo & NTSC1024x768 )
9559     {
9560         *tempbx = 4 ;
9561         if ( pVBInfo->TVInfo & SetPALMTV )
9562             *tempbx = 5 ;
9563     }
9564
9565     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9566     {
9567         if ( ( !( pVBInfo->VBInfo & SetInSlaveMode ) ) || ( pVBInfo->TVInfo & TVSimuMode ) )
9568         {
9569             *tempbx += 8 ;
9570             *tempcl += 1 ;
9571         }
9572     }
9573
9574     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9575         (*tempch)++ ;
9576 }
9577
9578
9579 /* --------------------------------------------------------------------- */
9580 /* Function : XGI_SetCRT2ModeRegs */
9581 /* Input : */
9582 /* Output : */
9583 /* Description : Origin code for crt2group */
9584 /* --------------------------------------------------------------------- */
9585 void XGI_SetCRT2ModeRegs(USHORT ModeNo,PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
9586 {
9587     USHORT tempbl ;
9588     SHORT  tempcl ;
9589
9590     UCHAR  tempah ;
9591
9592     /* XGINew_SetReg1( pVBInfo->Part1Port , 0x03 , 0x00 ) ; // fix write part1 index 0 BTDRAM bit Bug */
9593     tempah=0;
9594     if ( !( pVBInfo->VBInfo & DisableCRT2Display ) )
9595     {
9596         tempah=XGINew_GetReg1( pVBInfo->Part1Port , 0x00 ) ;
9597         tempah &= ~0x10 ;       /* BTRAMDAC */
9598         tempah |=  0x40 ;       /* BTRAM */
9599
9600         if ( pVBInfo->VBInfo & ( SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD ) )
9601         {
9602             tempah=0x40;        /* BTDRAM */
9603             if ( ModeNo > 0x13 )
9604             {
9605                 tempcl = pVBInfo->ModeType ;
9606                 tempcl -= ModeVGA ;
9607                 if ( tempcl >= 0 )
9608                 {
9609                     tempah = ( 0x008 >> tempcl ) ;      /* BT Color */
9610                     if ( tempah == 0 )
9611                         tempah = 1 ;
9612                     tempah |= 0x040 ;
9613                 }
9614             }
9615             if ( pVBInfo->VBInfo & SetInSlaveMode )
9616                 tempah ^= 0x50 ;        /* BTDAC */
9617         }
9618     }
9619
9620 /*      0210 shampoo
9621     if ( pVBInfo->VBInfo & DisableCRT2Display )
9622     {
9623         tempah = 0 ;
9624     }
9625
9626     XGINew_SetReg1( pVBInfo->Part1Port , 0x00 , tempah ) ;
9627     if ( pVBInfo->VBInfo & ( SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD ) )
9628     {
9629         tempcl = pVBInfo->ModeType ;
9630         if ( ModeNo > 0x13 )
9631         {
9632             tempcl -= ModeVGA ;
9633             if ( ( tempcl > 0 ) || ( tempcl == 0 ) )
9634             {
9635                 tempah=(0x008>>tempcl) ;
9636                 if ( tempah == 0 )
9637                     tempah = 1 ;
9638                 tempah |= 0x040;
9639             }
9640         }
9641         else
9642         {
9643             tempah = 0x040 ;
9644         }
9645
9646         if ( pVBInfo->VBInfo & SetInSlaveMode )
9647         {
9648             tempah = ( tempah ^ 0x050 ) ;
9649         }
9650     }
9651 */
9652
9653     XGINew_SetReg1( pVBInfo->Part1Port , 0x00 , tempah ) ;
9654     tempah = 0x08 ;
9655     tempbl = 0xf0 ;
9656
9657     if ( pVBInfo->VBInfo & DisableCRT2Display )
9658         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2e , tempbl , tempah ) ;
9659     else
9660     {
9661         tempah = 0x00 ;
9662         tempbl = 0xff ;
9663
9664         if ( pVBInfo->VBInfo & ( SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA ) )
9665         {
9666             if ( ( pVBInfo->VBInfo & SetCRT2ToLCDA ) && ( !( pVBInfo->VBInfo & SetSimuScanMode ) ) )
9667             {
9668                 tempbl &= 0xf7 ;
9669                 tempah |= 0x01 ;
9670                 XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2e , tempbl , tempah ) ;
9671             }
9672             else
9673             {
9674                 if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
9675                 {
9676                     tempbl &= 0xf7 ;
9677                     tempah |= 0x01 ;
9678                 }
9679
9680                 if ( pVBInfo->VBInfo & ( SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD ) )
9681                 {
9682                     tempbl &= 0xf8 ;
9683                     tempah = 0x01 ;
9684
9685                     if ( !( pVBInfo->VBInfo & SetInSlaveMode ) )
9686                         tempah |= 0x02 ;
9687
9688                     if ( !( pVBInfo->VBInfo & SetCRT2ToRAMDAC ) )
9689                     {
9690                         tempah = tempah ^ 0x05 ;
9691                         if ( !( pVBInfo->VBInfo & SetCRT2ToLCD ) )
9692                             tempah = tempah ^ 0x01 ;
9693                     }
9694
9695                     if ( !( pVBInfo->VBInfo & SetCRT2ToDualEdge ) )
9696                         tempah |= 0x08 ;
9697                     XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2e , tempbl , tempah ) ;
9698                 }
9699                 else
9700                     XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2e , tempbl , tempah ) ;
9701             }
9702         }
9703         else
9704             XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2e , tempbl , tempah ) ;
9705     }
9706
9707     if ( pVBInfo->VBInfo & ( SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA ) )
9708     {
9709         tempah &= ( ~0x08 ) ;
9710         if ( ( pVBInfo->ModeType == ModeVGA ) && ( !( pVBInfo->VBInfo & SetInSlaveMode ) ) )
9711         {
9712             tempah |= 0x010 ;
9713         }
9714         tempah |= 0x080 ;
9715
9716         if ( pVBInfo->VBInfo & SetCRT2ToTV )
9717         {
9718             /* if ( !( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p ) ) ) */
9719             /* { */
9720             tempah |= 0x020 ;
9721             if ( ModeNo > 0x13 )
9722             {
9723                 if ( pVBInfo->VBInfo & DriverMode )
9724                     tempah = tempah ^ 0x20 ;
9725             }
9726         /* } */
9727         }
9728
9729         XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x0D , ~0x0BF , tempah ) ;
9730         tempah = 0 ;
9731
9732         if ( pVBInfo->LCDInfo & SetLCDDualLink )
9733             tempah |= 0x40 ;
9734
9735         if ( pVBInfo->VBInfo & SetCRT2ToTV )
9736         {
9737             /* if ( ( !( pVBInfo->VBInfo & SetCRT2ToHiVisionTV ) ) && ( !( pVBInfo->TVInfo & ( SetYPbPrMode525p | SetYPbPrMode750p ) ) ) ) */
9738             /* { */
9739                 if ( pVBInfo->TVInfo & RPLLDIV2XO )
9740                     tempah |= 0x40 ;
9741             /* } */
9742         }
9743
9744         if ( ( pVBInfo->LCDResInfo == Panel1280x1024 ) || ( pVBInfo->LCDResInfo == Panel1280x1024x75 ) )
9745             tempah |= 0x80 ;
9746
9747         if ( pVBInfo->LCDResInfo == Panel1280x960 )
9748             tempah |= 0x80 ;
9749
9750         XGINew_SetReg1( pVBInfo->Part4Port , 0x0C , tempah ) ;
9751     }
9752
9753     if ( pVBInfo->VBType & ( VB_XGI301B | VB_XGI302B | VB_XGI301LV | VB_XGI302LV | VB_XGI301C ) )
9754     {
9755         tempah = 0 ;
9756         tempbl = 0xfb ;
9757
9758         if ( pVBInfo->VBInfo & SetCRT2ToDualEdge )
9759         {
9760             tempbl=0xff;
9761             if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
9762                 tempah |= 0x04 ; /* shampoo 0129 */
9763         }
9764
9765         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x13 , tempbl , tempah ) ;
9766         tempah = 0x00 ;
9767         tempbl = 0xcf ;
9768         if ( !( pVBInfo->VBInfo & DisableCRT2Display ) )
9769         {
9770             if ( pVBInfo->VBInfo & SetCRT2ToDualEdge )
9771                 tempah |= 0x30 ;
9772         }
9773
9774         XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2c , tempbl , tempah ) ;
9775         tempah = 0 ;
9776         tempbl = 0x3f ;
9777
9778         if ( !( pVBInfo->VBInfo & DisableCRT2Display ) )
9779         {
9780             if ( pVBInfo->VBInfo & SetCRT2ToDualEdge )
9781                 tempah |= 0xc0 ;
9782         }
9783         XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x21 , tempbl , tempah ) ;
9784     }
9785
9786     tempah = 0 ;
9787     tempbl = 0x7f ;
9788     if ( !( pVBInfo->VBInfo & SetCRT2ToLCDA ) )
9789     {
9790         tempbl = 0xff ;
9791         if ( !( pVBInfo->VBInfo & SetCRT2ToDualEdge ) )
9792             tempah |= 0x80 ;
9793     }
9794
9795     XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x23 , tempbl , tempah ) ;
9796
9797     if ( pVBInfo->VBType & ( VB_XGI302LV | VB_XGI301C ) )
9798     {
9799         if ( pVBInfo->LCDInfo & SetLCDDualLink )
9800         {
9801             XGINew_SetRegOR( pVBInfo->Part4Port , 0x27 , 0x20 ) ;
9802             XGINew_SetRegOR( pVBInfo->Part4Port , 0x34 , 0x10 ) ;
9803         }
9804     }
9805 }
9806
9807
9808 /* --------------------------------------------------------------------- */
9809 /* Function : XGI_CloseCRTC */
9810 /* Input : */
9811 /* Output : */
9812 /* Description : */
9813 /* --------------------------------------------------------------------- */
9814 void XGI_CloseCRTC( PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo )
9815 {
9816     USHORT tempbx ;
9817
9818     tempbx = 0 ;
9819
9820     if ( pVBInfo->VBInfo & SetCRT2ToLCDA )
9821         tempbx = 0x08A0 ;
9822
9823
9824 }
9825
9826
9827 /* --------------------------------------------------------------------- */
9828 /* Function : XGI_OpenCRTC */
9829 /* Input : */
9830 /* Output : */
9831 /* Description : */
9832 /* --------------------------------------------------------------------- */
9833 void XGI_OpenCRTC( PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo )
9834 {
9835     USHORT tempbx ;
9836
9837     tempbx = 0 ;
9838
9839
9840 }
9841
9842
9843 /* --------------------------------------------------------------------- */
9844 /* Function : XGI_GetRAMDAC2DATA */
9845 /* Input : */
9846 /* Output : */
9847 /* Description : */
9848 /* --------------------------------------------------------------------- */
9849 void XGI_GetRAMDAC2DATA(USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex, PVB_DEVICE_INFO pVBInfo )
9850 {
9851     USHORT tempax ,
9852            tempbx ,
9853            temp1 ,
9854            temp2 ,
9855            modeflag = 0 ,
9856            tempcx ,
9857            StandTableIndex ,
9858            CRT1Index ;
9859
9860     pVBInfo->RVBHCMAX = 1 ;
9861     pVBInfo->RVBHCFACT = 1 ;
9862
9863     if ( ModeNo <= 0x13 )
9864     {
9865         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
9866         StandTableIndex = XGI_GetModePtr( ModeNo , ModeIdIndex, pVBInfo ) ;
9867         tempax = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 0 ] ;
9868         tempbx = pVBInfo->StandTable[StandTableIndex ].CRTC[ 6 ] ;
9869         temp1 = pVBInfo->StandTable[ StandTableIndex ].CRTC[ 7 ] ;
9870     }
9871     else
9872     {
9873         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
9874         CRT1Index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT1CRTC ;
9875         CRT1Index &= IndexMask ;
9876         temp1 = ( USHORT )pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 0 ] ;
9877         temp2 = ( USHORT )pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 5 ] ;
9878         tempax = ( temp1 & 0xFF ) | ( ( temp2 & 0x03 ) << 8 ) ;
9879         tempbx = ( USHORT )pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 8 ] ;
9880         tempcx = ( USHORT )pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 14 ] << 8 ;
9881         tempcx &= 0x0100 ;
9882         tempcx = tempcx << 2 ;
9883         tempbx |= tempcx;
9884         temp1 = ( USHORT )pVBInfo->XGINEWUB_CRT1Table[ CRT1Index ].CR[ 9 ] ;
9885     }
9886
9887     if ( temp1 & 0x01 )
9888         tempbx |= 0x0100 ;
9889
9890     if ( temp1 & 0x20 )
9891         tempbx |= 0x0200 ;
9892     tempax += 5 ;
9893
9894     if ( modeflag & Charx8Dot )
9895         tempax *= 8 ;
9896     else
9897         tempax *= 9 ;
9898
9899     pVBInfo->VGAHT = tempax ;
9900     pVBInfo->HT = tempax ;
9901     tempbx++ ;
9902     pVBInfo->VGAVT = tempbx ;
9903     pVBInfo->VT = tempbx ;
9904 }
9905
9906
9907
9908 /* --------------------------------------------------------------------- */
9909 /* Function : XGI_GetColorDepth */
9910 /* Input : */
9911 /* Output : */
9912 /* Description : */
9913 /* --------------------------------------------------------------------- */
9914 USHORT XGI_GetColorDepth(USHORT ModeNo , USHORT ModeIdIndex, PVB_DEVICE_INFO pVBInfo)
9915 {
9916     USHORT ColorDepth[ 6 ] = { 1 , 2 , 4 , 4 , 6 , 8 } ;
9917     SHORT  index ;
9918     USHORT modeflag ;
9919
9920     if ( ModeNo <= 0x13 )
9921     {
9922         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;
9923     }
9924     else
9925     {
9926         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;
9927     }
9928
9929     index=(modeflag&ModeInfoFlag)-ModeEGA;
9930
9931     if ( index < 0 )
9932         index = 0 ;
9933
9934     return( ColorDepth[ index ] ) ;
9935 }
9936
9937
9938
9939 /* --------------------------------------------------------------------- */
9940 /* Function : XGI_UnLockCRT2 */
9941 /* Input : */
9942 /* Output : */
9943 /* Description : */
9944 /* --------------------------------------------------------------------- */
9945 void XGI_UnLockCRT2( PXGI_HW_DEVICE_INFO HwDeviceExtension,  PVB_DEVICE_INFO pVBInfo )
9946 {
9947
9948     XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2f , 0xFF , 0x01 ) ;
9949
9950 }
9951
9952
9953 /* --------------------------------------------------------------------- */
9954 /* Function : XGI_LockCRT2 */
9955 /* Input : */
9956 /* Output : */
9957 /* Description : */
9958 /* --------------------------------------------------------------------- */
9959 void XGI_LockCRT2( PXGI_HW_DEVICE_INFO HwDeviceExtension,  PVB_DEVICE_INFO pVBInfo )
9960 {
9961
9962     XGINew_SetRegANDOR( pVBInfo->Part1Port , 0x2F , 0xFE , 0x00 ) ;
9963
9964
9965 }
9966
9967
9968 /* --------------------------------------------------------------------- */
9969 /* Function : XGINew_EnableCRT2 */
9970 /* Input : */
9971 /* Output : */
9972 /* Description : */
9973 /* --------------------------------------------------------------------- */
9974 void XGINew_EnableCRT2( PVB_DEVICE_INFO pVBInfo)
9975 {
9976     XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x1E , 0xFF , 0x20 ) ;
9977 }
9978
9979
9980
9981 /* --------------------------------------------------------------------- */
9982 /* Function : */
9983 /* Input : */
9984 /* Output : */
9985 /* Description : */
9986 /* --------------------------------------------------------------------- */
9987 void XGINew_LCD_Wait_Time(UCHAR DelayTime, PVB_DEVICE_INFO pVBInfo)
9988 {
9989     USHORT i ,
9990            j ;
9991
9992     ULONG temp ,
9993           flag ;
9994
9995     flag = 0 ;
9996 //printk("XGINew_LCD_Wait_Time");
9997 //return;
9998     for( i = 0 ; i < DelayTime ; i++ )
9999     {
10000         for( j = 0 ; j < 66 ; j++ )
10001         {
10002
10003             temp =  XGINew_GetReg3( 0x61 ) ;
10004
10005             //temp &= 0x10000000;
10006             temp &= 0x10;
10007             if ( temp == flag )
10008                 continue ;
10009
10010             flag = temp ;
10011         }
10012     }
10013 }
10014
10015
10016
10017
10018 /* --------------------------------------------------------------------- */
10019 /* Function : XGI_BridgeIsOn */
10020 /* Input : */
10021 /* Output : */
10022 /* Description : */
10023 /* --------------------------------------------------------------------- */
10024 BOOLEAN XGI_BridgeIsOn( PVB_DEVICE_INFO pVBInfo )
10025 {
10026     USHORT flag ;
10027
10028     if ( pVBInfo->IF_DEF_LVDS == 1 )
10029     {
10030         return( 1 ) ;
10031     }
10032     else
10033     {
10034         flag = XGINew_GetReg1( pVBInfo->Part4Port , 0x00 ) ;
10035         if ( ( flag == 1 ) || ( flag == 2 ) )
10036             return( 1 ) ;       /* 301b */
10037         else
10038             return( 0 ) ;
10039     }
10040 }
10041
10042
10043
10044 /* --------------------------------------------------------------------- */
10045 /* Function : XGI_LongWait */
10046 /* Input : */
10047 /* Output : */
10048 /* Description : */
10049 /* --------------------------------------------------------------------- */
10050 void XGI_LongWait(PVB_DEVICE_INFO pVBInfo)
10051 {
10052     USHORT i ;
10053
10054     i = XGINew_GetReg1( pVBInfo->P3c4 , 0x1F ) ;
10055
10056     if ( !( i & 0xC0 ) )
10057     {
10058         for( i = 0 ; i < 0xFFFF ; i++ )
10059         {
10060             if ( !( XGINew_GetReg2( pVBInfo->P3da ) & 0x08 ) )
10061                 break ;
10062         }
10063
10064         for( i = 0 ; i < 0xFFFF ; i++ )
10065         {
10066             if ( ( XGINew_GetReg2( pVBInfo->P3da ) & 0x08 ) )
10067                 break ;
10068         }
10069     }
10070 }
10071
10072
10073 /* --------------------------------------------------------------------- */
10074 /* Function : XGI_VBLongWait */
10075 /* Input : */
10076 /* Output : */
10077 /* Description : */
10078 /* --------------------------------------------------------------------- */
10079 void XGI_VBLongWait( PVB_DEVICE_INFO pVBInfo )
10080 {
10081     USHORT tempal ,
10082            temp ,
10083            i ,
10084            j ;
10085 return ;
10086     if ( !( pVBInfo->VBInfo & SetCRT2ToTV ) )
10087     {
10088         temp = 0 ;
10089         for( i = 0 ; i < 3 ; i++ )
10090         {
10091             for( j = 0 ; j < 100 ; j++ )
10092             {
10093                 tempal = XGINew_GetReg2( pVBInfo->P3da ) ;
10094                 if ( temp & 0x01 )
10095                 {                       /* VBWaitMode2 */
10096                     if ( ( tempal & 0x08 ) )
10097                     {
10098                         continue ;
10099                     }
10100
10101                     if ( !( tempal & 0x08 ) )
10102                     {
10103                         break ;
10104                     }
10105                 }
10106                 else
10107                 {                       /* VBWaitMode1 */
10108                     if ( !( tempal & 0x08 ) )
10109                     {
10110                         continue ;
10111                     }
10112
10113                     if ( ( tempal & 0x08 ) )
10114                     {
10115                         break ;
10116                     }
10117                 }
10118             }
10119             temp = temp ^ 0x01 ;
10120         }
10121     }
10122     else
10123     {
10124         XGI_LongWait(pVBInfo) ;
10125     }
10126     return ;
10127 }
10128
10129
10130
10131
10132 /* --------------------------------------------------------------------- */
10133 /* Function : XGI_GetVGAHT2 */
10134 /* Input : */
10135 /* Output : */
10136 /* Description : */
10137 /* --------------------------------------------------------------------- */
10138 USHORT XGI_GetVGAHT2( PVB_DEVICE_INFO pVBInfo )
10139 {
10140     ULONG tempax ,
10141           tempbx ;
10142
10143     tempbx = ( ( pVBInfo->VGAVT - pVBInfo->VGAVDE ) * pVBInfo->RVBHCMAX ) & 0xFFFF ;
10144     tempax = ( pVBInfo->VT - pVBInfo->VDE ) * pVBInfo->RVBHCFACT ;
10145     tempax = ( tempax * pVBInfo->HT ) /tempbx ;
10146
10147     return( ( USHORT )tempax ) ;
10148 }
10149
10150
10151 /* --------------------------------------------------------------------- */
10152 /* Function : XGI_GetVCLK2Ptr */
10153 /* Input : */
10154 /* Output : */
10155 /* Description : */
10156 /* --------------------------------------------------------------------- */
10157 USHORT XGI_GetVCLK2Ptr( USHORT ModeNo , USHORT ModeIdIndex , USHORT RefreshRateTableIndex , PXGI_HW_DEVICE_INFO HwDeviceExtension ,PVB_DEVICE_INFO pVBInfo)
10158 {
10159     USHORT tempbx ;
10160
10161     USHORT LCDXlat1VCLK[ 4 ] = { VCLK65 + 2 , VCLK65 + 2 , VCLK65 + 2 , VCLK65 + 2 } ;
10162     USHORT LCDXlat2VCLK[ 4 ] = { VCLK108_2 + 5 , VCLK108_2 + 5 , VCLK108_2 + 5 , VCLK108_2 + 5 } ;
10163     USHORT LVDSXlat1VCLK[ 4 ] = { VCLK40 , VCLK40 , VCLK40 , VCLK40 } ;
10164     USHORT LVDSXlat2VCLK[ 4 ] = { VCLK65 + 2 , VCLK65 + 2 , VCLK65 + 2 , VCLK65 + 2 } ;
10165     USHORT LVDSXlat3VCLK[ 4 ] = { VCLK65 + 2 , VCLK65 + 2 , VCLK65 + 2 , VCLK65 + 2 } ;
10166
10167     USHORT CRT2Index , VCLKIndex ;
10168     USHORT modeflag , resinfo ;
10169     UCHAR *CHTVVCLKPtr = NULL ;
10170
10171     if ( ModeNo <= 0x13 )
10172     {
10173         modeflag = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ModeFlag ;      /* si+St_ResInfo */
10174         resinfo = pVBInfo->SModeIDTable[ ModeIdIndex ].St_ResInfo ;
10175         CRT2Index = pVBInfo->SModeIDTable[ ModeIdIndex ].St_CRT2CRTC ;
10176     }
10177     else
10178     {
10179         modeflag = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeFlag ;     /* si+Ext_ResInfo */
10180         resinfo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_RESINFO ;
10181         CRT2Index = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRT2CRTC ;
10182     }
10183
10184     if ( pVBInfo->IF_DEF_LVDS == 0 )
10185     {
10186         CRT2Index = CRT2Index >> 6 ;        /*  for LCD */
10187         if ( ( ( pVBInfo->VBInfo & SetCRT2ToLCD ) | SetCRT2ToLCDA ) )    /*301b*/
10188         {
10189             if ( pVBInfo->LCDResInfo != Panel1024x768 )
10190             {
10191                 VCLKIndex = LCDXlat2VCLK[ CRT2Index ] ;
10192             }
10193             else
10194             {
10195                  VCLKIndex = LCDXlat1VCLK[ CRT2Index ] ;
10196             }
10197         }
10198         else    /* for TV */
10199         {
10200             if ( pVBInfo->VBInfo & SetCRT2ToTV )
10201             {
10202                 if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
10203                 {
10204                     if ( pVBInfo->SetFlag & RPLLDIV2XO )
10205                     {
10206                         VCLKIndex = HiTVVCLKDIV2 ;
10207
10208
10209                             VCLKIndex += 25 ;
10210
10211                     }
10212                     else
10213                     {
10214                         VCLKIndex = HiTVVCLK ;
10215
10216
10217                             VCLKIndex += 25 ;
10218
10219                     }
10220
10221                     if ( pVBInfo->SetFlag & TVSimuMode )
10222                     {
10223                         if( modeflag & Charx8Dot )
10224                         {
10225                             VCLKIndex = HiTVSimuVCLK ;
10226
10227
10228                                 VCLKIndex += 25 ;
10229
10230                         }
10231                         else
10232                         {
10233                             VCLKIndex = HiTVTextVCLK ;
10234
10235
10236                                 VCLKIndex += 25 ;
10237
10238                         }
10239                     }
10240
10241                     if ( pVBInfo->VBType & VB_XGI301LV )        /* 301lv */
10242                     {
10243                         if ( !( pVBInfo->VBExtInfo == VB_YPbPr1080i ) )
10244                         {
10245                             VCLKIndex = YPbPr750pVCLK ;
10246                             if ( !( pVBInfo->VBExtInfo == VB_YPbPr750p ) )
10247                             {
10248                                 VCLKIndex = YPbPr525pVCLK ;
10249                                 if ( !( pVBInfo->VBExtInfo == VB_YPbPr525p ) )
10250                                 {
10251                                     VCLKIndex = YPbPr525iVCLK_2 ;
10252                                     if ( !( pVBInfo->SetFlag & RPLLDIV2XO ) )
10253                                         VCLKIndex = YPbPr525iVCLK ;
10254                                 }
10255                             }
10256                         }
10257                     }
10258                 }
10259                 else
10260                 {
10261                     if ( pVBInfo->VBInfo & SetCRT2ToTV )
10262                     {
10263                         if ( pVBInfo->SetFlag & RPLLDIV2XO )
10264                         {
10265                             VCLKIndex = TVVCLKDIV2 ;
10266
10267
10268                             VCLKIndex += 25 ;
10269
10270                         }
10271                         else
10272                         {
10273                             VCLKIndex = TVVCLK ;
10274
10275
10276                             VCLKIndex += 25 ;
10277
10278                         }
10279                     }
10280                 }
10281             }
10282             else
10283             {   /* for CRT2 */
10284                 VCLKIndex = ( UCHAR )XGINew_GetReg2( ( pVBInfo->P3ca + 0x02 ) ) ;       /* Port 3cch */
10285                 VCLKIndex = ( ( VCLKIndex >> 2 ) & 0x03 ) ;
10286                 if ( ModeNo > 0x13 )
10287                 {
10288                     VCLKIndex = pVBInfo->RefIndex[ RefreshRateTableIndex ].Ext_CRTVCLK ;        /* di+Ext_CRTVCLK */
10289                     VCLKIndex &= IndexMask ;
10290                 }
10291             }
10292         }
10293     }
10294     else
10295     {           /* LVDS */
10296         if ( ModeNo <= 0x13 )
10297             VCLKIndex = CRT2Index ;
10298         else
10299             VCLKIndex = CRT2Index ;
10300
10301         if ( pVBInfo->IF_DEF_CH7005 == 1 )
10302         {
10303             if ( !( pVBInfo->VBInfo & SetCRT2ToLCD ) )
10304             {
10305                 VCLKIndex &= 0x1f ;
10306                 tempbx = 0 ;
10307
10308                 if ( pVBInfo->VBInfo & SetPALTV )
10309                     tempbx += 2 ;
10310
10311                 if ( pVBInfo->VBInfo & SetCHTVOverScan )
10312                     tempbx += 1 ;
10313
10314                 switch( tempbx )
10315                 {
10316                     case 0:
10317                         CHTVVCLKPtr = pVBInfo->CHTVVCLKUNTSC ;
10318                         break ;
10319                     case 1:
10320                         CHTVVCLKPtr = pVBInfo->CHTVVCLKONTSC ;
10321                         break;
10322                     case 2:
10323                         CHTVVCLKPtr = pVBInfo->CHTVVCLKUPAL ;
10324                         break ;
10325                     case 3:
10326                         CHTVVCLKPtr = pVBInfo->CHTVVCLKOPAL ;
10327                         break ;
10328                     default:
10329                         break ;
10330                 }
10331
10332                 VCLKIndex = CHTVVCLKPtr[ VCLKIndex ] ;
10333             }
10334         }
10335         else
10336         {
10337             VCLKIndex = VCLKIndex >> 6 ;
10338             if ( ( pVBInfo->LCDResInfo == Panel800x600 ) || ( pVBInfo->LCDResInfo == Panel320x480 ) )
10339                 VCLKIndex = LVDSXlat1VCLK[ VCLKIndex ] ;
10340             else if ( ( pVBInfo->LCDResInfo == Panel1024x768 ) || ( pVBInfo->LCDResInfo == Panel1024x768x75 ) )
10341                 VCLKIndex = LVDSXlat2VCLK[ VCLKIndex ] ;
10342             else
10343                 VCLKIndex = LVDSXlat3VCLK[ VCLKIndex ] ;
10344         }
10345     }
10346     /* VCLKIndex = VCLKIndex&IndexMask ; */
10347
10348
10349
10350     return( VCLKIndex ) ;
10351 }
10352