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