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