i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / staging / xgifb / vb_setmode.c
blob67a316c3c1087c844f82ec7201fed06e3d38b580
2 #include <linux/io.h>
3 #include <linux/delay.h>
4 #include <linux/types.h>
5 #include "XGIfb.h"
8 #include "vb_def.h"
9 #include "vgatypes.h"
10 #include "vb_struct.h"
11 #include "vb_init.h"
12 #include "vb_util.h"
13 #include "vb_table.h"
14 #include "vb_setmode.h"
17 #define IndexMask 0xff
19 static const unsigned short XGINew_MDA_DAC[] = {
20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
22 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
23 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
26 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
27 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
29 static const unsigned short XGINew_CGA_DAC[] = {
30 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
31 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
32 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
33 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
34 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
35 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
36 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
37 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
39 static const unsigned short XGINew_EGA_DAC[] = {
40 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x05, 0x15,
41 0x20, 0x30, 0x24, 0x34, 0x21, 0x31, 0x25, 0x35,
42 0x08, 0x18, 0x0C, 0x1C, 0x09, 0x19, 0x0D, 0x1D,
43 0x28, 0x38, 0x2C, 0x3C, 0x29, 0x39, 0x2D, 0x3D,
44 0x02, 0x12, 0x06, 0x16, 0x03, 0x13, 0x07, 0x17,
45 0x22, 0x32, 0x26, 0x36, 0x23, 0x33, 0x27, 0x37,
46 0x0A, 0x1A, 0x0E, 0x1E, 0x0B, 0x1B, 0x0F, 0x1F,
47 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
49 static const unsigned short XGINew_VGA_DAC[] = {
50 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
51 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
52 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
53 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
54 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
55 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
56 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
57 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
58 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
59 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
61 void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
63 pVBInfo->SModeIDTable = (struct XGI_StStruct *) XGI330_SModeIDTable;
64 pVBInfo->StandTable = (struct XGI_StandTableStruct *) XGI330_StandTable;
65 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
66 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
67 pVBInfo->XGINEWUB_CRT1Table
68 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
70 pVBInfo->MCLKData = (struct XGI_MCLKDataStruct *) XGI340New_MCLKData;
71 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
72 pVBInfo->VCLKData = (struct XGI_VCLKDataStruct *) XGI_VCLKData;
73 pVBInfo->VBVCLKData = (struct XGI_VBVCLKDataStruct *) XGI_VBVCLKData;
74 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
75 pVBInfo->StResInfo = (struct XGI_StResInfoStruct *) XGI330_StResInfo;
76 pVBInfo->ModeResInfo
77 = (struct XGI_ModeResInfoStruct *) XGI330_ModeResInfo;
79 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
80 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
81 pVBInfo->pSR07 = &XGI330_SR07;
82 pVBInfo->LCDResInfo = 0;
83 pVBInfo->LCDTypeInfo = 0;
84 pVBInfo->LCDInfo = 0;
85 pVBInfo->VBInfo = 0;
86 pVBInfo->TVInfo = 0;
88 pVBInfo->SR15 = XGI340_SR13;
89 pVBInfo->CR40 = XGI340_cr41;
90 pVBInfo->SR25 = XGI330_sr25;
91 pVBInfo->pSR31 = &XGI330_sr31;
92 pVBInfo->pSR32 = &XGI330_sr32;
93 pVBInfo->CR6B = XGI340_CR6B;
94 pVBInfo->CR6E = XGI340_CR6E;
95 pVBInfo->CR6F = XGI340_CR6F;
96 pVBInfo->CR89 = XGI340_CR89;
97 pVBInfo->AGPReg = XGI340_AGPReg;
98 pVBInfo->SR16 = XGI340_SR16;
99 pVBInfo->pCRCF = &XG40_CRCF;
100 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
102 pVBInfo->CR49 = XGI330_CR49;
103 pVBInfo->pSR1F = &XGI330_SR1F;
104 pVBInfo->pSR21 = &XGI330_SR21;
105 pVBInfo->pSR22 = &XGI330_SR22;
106 pVBInfo->pSR23 = &XGI330_SR23;
107 pVBInfo->pSR24 = &XGI330_SR24;
108 pVBInfo->pSR33 = &XGI330_SR33;
110 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
111 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
112 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
113 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
114 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
115 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
116 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
117 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
118 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
119 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
121 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
122 pVBInfo->PALTiming = XGI330_PALTiming;
123 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
124 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
125 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
126 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
127 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
128 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
129 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
130 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
131 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
132 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
133 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
134 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
136 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
137 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
138 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
140 /* 310 customization related */
141 if ((pVBInfo->VBType & VB_XGI301LV) || (pVBInfo->VBType & VB_XGI302LV))
142 pVBInfo->LCDCapList = XGI_LCDDLCapList;
143 else
144 pVBInfo->LCDCapList = XGI_LCDCapList;
146 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
147 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
149 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
151 if (ChipType >= XG20)
152 pVBInfo->pXGINew_CR97 = &XG20_CR97;
154 if (ChipType == XG27) {
155 pVBInfo->MCLKData
156 = (struct XGI_MCLKDataStruct *) XGI27New_MCLKData;
157 pVBInfo->CR40 = XGI27_cr41;
158 pVBInfo->pXGINew_CR97 = &XG27_CR97;
159 pVBInfo->pSR36 = &XG27_SR36;
160 pVBInfo->pCR8F = &XG27_CR8F;
161 pVBInfo->pCRD0 = XG27_CRD0;
162 pVBInfo->pCRDE = XG27_CRDE;
163 pVBInfo->pSR40 = &XG27_SR40;
164 pVBInfo->pSR41 = &XG27_SR41;
168 if (ChipType >= XG20) {
169 pVBInfo->pDVOSetting = &XG21_DVOSetting;
170 pVBInfo->pCR2E = &XG21_CR2E;
171 pVBInfo->pCR2F = &XG21_CR2F;
172 pVBInfo->pCR46 = &XG21_CR46;
173 pVBInfo->pCR47 = &XG21_CR47;
178 static unsigned char XGI_GetModePtr(unsigned short ModeNo,
179 unsigned short ModeIdIndex,
180 struct vb_device_info *pVBInfo)
182 unsigned char index;
184 if (ModeNo <= 0x13)
185 index = pVBInfo->SModeIDTable[ModeIdIndex].St_StTableIndex;
186 else {
187 if (pVBInfo->ModeType <= 0x02)
188 index = 0x1B; /* 02 -> ModeEGA */
189 else
190 index = 0x0F;
192 return index; /* Get pVBInfo->StandTable index */
195 static void XGI_SetSeqRegs(unsigned short ModeNo,
196 unsigned short StandTableIndex,
197 unsigned short ModeIdIndex,
198 struct vb_device_info *pVBInfo)
200 unsigned char tempah, SRdata;
201 unsigned short i, modeflag;
203 if (ModeNo <= 0x13)
204 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
205 else
206 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
208 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
209 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
211 i = SetCRT2ToLCDA;
212 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
213 tempah |= 0x01;
214 } else {
215 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
216 if (pVBInfo->VBInfo & SetInSlaveMode)
217 tempah |= 0x01;
221 tempah |= 0x20; /* screen off */
222 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
224 for (i = 02; i <= 04; i++) {
225 /* Get SR2,3,4 from file */
226 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
227 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
231 static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
232 unsigned short StandTableIndex,
233 struct vb_device_info *pVBInfo)
235 unsigned char CRTCdata;
236 unsigned short i;
238 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
239 CRTCdata &= 0x7f;
240 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
242 for (i = 0; i <= 0x18; i++) {
243 /* Get CRTC from file */
244 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
245 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
249 static void XGI_SetATTRegs(unsigned short ModeNo,
250 unsigned short StandTableIndex,
251 unsigned short ModeIdIndex,
252 struct vb_device_info *pVBInfo)
254 unsigned char ARdata;
255 unsigned short i, modeflag;
257 if (ModeNo <= 0x13)
258 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
259 else
260 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
262 for (i = 0; i <= 0x13; i++) {
263 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
264 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
265 if (i == 0x13) {
266 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
267 ARdata = 0;
268 } else {
269 if (pVBInfo->VBInfo & (SetCRT2ToTV
270 | SetCRT2ToLCD)) {
271 if (pVBInfo->VBInfo &
272 SetInSlaveMode)
273 ARdata = 0;
279 inb(pVBInfo->P3da); /* reset 3da */
280 outb(i, pVBInfo->P3c0); /* set index */
281 outb(ARdata, pVBInfo->P3c0); /* set data */
284 inb(pVBInfo->P3da); /* reset 3da */
285 outb(0x14, pVBInfo->P3c0); /* set index */
286 outb(0x00, pVBInfo->P3c0); /* set data */
287 inb(pVBInfo->P3da); /* Enable Attribute */
288 outb(0x20, pVBInfo->P3c0);
291 static void XGI_SetGRCRegs(unsigned short StandTableIndex,
292 struct vb_device_info *pVBInfo)
294 unsigned char GRdata;
295 unsigned short i;
297 for (i = 0; i <= 0x08; i++) {
298 /* Get GR from file */
299 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
300 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
303 if (pVBInfo->ModeType > ModeVGA) {
304 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
305 GRdata &= 0xBF; /* 256 color disable */
306 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
310 static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
312 unsigned short i;
314 for (i = 0x0A; i <= 0x0E; i++)
315 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
318 static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
321 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
322 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
323 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
325 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
326 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
327 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
329 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
330 return 0;
333 static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
334 unsigned short ModeIdIndex,
335 unsigned short RefreshRateTableIndex, unsigned short *i,
336 struct vb_device_info *pVBInfo)
338 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
340 if (ModeNo <= 0x13)
341 /* si+St_ModeFlag */
342 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
343 else
344 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
346 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
347 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
348 tempax = 0;
350 if (pVBInfo->IF_DEF_LVDS == 0) {
351 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
352 tempax |= SupportRAMDAC2;
354 if (pVBInfo->VBType & VB_XGI301C)
355 tempax |= SupportCRT2in301C;
358 /* 301b */
359 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
360 tempax |= SupportLCD;
362 if (pVBInfo->LCDResInfo != Panel1280x1024) {
363 if (pVBInfo->LCDResInfo != Panel1280x960) {
364 if (pVBInfo->LCDInfo &
365 LCDNonExpanding) {
366 if (resinfo >= 9) {
367 tempax = 0;
368 return 0;
375 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiTV */
376 if ((pVBInfo->VBType & VB_XGI301LV) &&
377 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
378 tempax |= SupportYPbPr;
379 if (pVBInfo->VBInfo & SetInSlaveMode) {
380 if (resinfo == 4)
381 return 0;
383 if (resinfo == 3)
384 return 0;
386 if (resinfo > 7)
387 return 0;
389 } else {
390 tempax |= SupportHiVisionTV;
391 if (pVBInfo->VBInfo & SetInSlaveMode) {
392 if (resinfo == 4)
393 return 0;
395 if (resinfo == 3) {
396 if (pVBInfo->SetFlag
397 & TVSimuMode)
398 return 0;
401 if (resinfo > 7)
402 return 0;
405 } else {
406 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
407 SetCRT2ToSVIDEO |
408 SetCRT2ToSCART |
409 SetCRT2ToYPbPr |
410 SetCRT2ToHiVisionTV)) {
411 tempax |= SupportTV;
413 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
414 | VB_XGI301LV | VB_XGI302LV
415 | VB_XGI301C)) {
416 tempax |= SupportTV1024;
419 if (!(pVBInfo->VBInfo & SetPALTV)) {
420 if (modeflag & NoSupportSimuTV) {
421 if (pVBInfo->VBInfo &
422 SetInSlaveMode) {
423 if (!(pVBInfo->VBInfo &
424 SetNotSimuMode)) {
425 return 0;
432 } else { /* for LVDS */
433 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
434 tempax |= SupportLCD;
436 if (resinfo > 0x08)
437 return 0; /* 1024x768 */
439 if (pVBInfo->LCDResInfo < Panel1024x768) {
440 if (resinfo > 0x07)
441 return 0; /* 800x600 */
443 if (resinfo == 0x04)
444 return 0; /* 512x384 */
449 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
450 tempbx; (*i)--) {
451 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
452 Ext_InfoFlag;
453 if (infoflag & tempax)
454 return 1;
456 if ((*i) == 0)
457 break;
460 for ((*i) = 0;; (*i)++) {
461 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
462 Ext_InfoFlag;
463 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
464 != tempbx) {
465 return 0;
468 if (infoflag & tempax)
469 return 1;
471 return 1;
474 static void XGI_SetSync(unsigned short RefreshRateTableIndex,
475 struct vb_device_info *pVBInfo)
477 unsigned short sync, temp;
479 /* di+0x00 */
480 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
481 sync &= 0xC0;
482 temp = 0x2F;
483 temp |= sync;
484 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
487 static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
488 struct xgi_hw_device_info *HwDeviceExtension)
490 unsigned char data, data1, pushax;
491 unsigned short i, j;
493 /* unlock cr0-7 */
494 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
495 data &= 0x7F;
496 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
498 data = pVBInfo->TimingH[0].data[0];
499 xgifb_reg_set(pVBInfo->P3d4, 0, data);
501 for (i = 0x01; i <= 0x04; i++) {
502 data = pVBInfo->TimingH[0].data[i];
503 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
506 for (i = 0x05; i <= 0x06; i++) {
507 data = pVBInfo->TimingH[0].data[i];
508 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
511 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
512 j &= 0x1F;
513 data = pVBInfo->TimingH[0].data[7];
514 data &= 0xE0;
515 data |= j;
516 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
518 if (HwDeviceExtension->jChipType >= XG20) {
519 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
520 data = data - 1;
521 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
522 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
523 data1 = data;
524 data1 &= 0xE0;
525 data &= 0x1F;
526 if (data == 0) {
527 pushax = data;
528 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
529 0x0c);
530 data &= 0xFB;
531 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
532 data = pushax;
534 data = data - 1;
535 data |= data1;
536 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
537 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
538 data = data >> 5;
539 data = data + 3;
540 if (data > 7)
541 data = data - 7;
542 data = data << 5;
543 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
547 static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
548 unsigned short ModeNo,
549 struct vb_device_info *pVBInfo)
551 unsigned char data;
552 unsigned short i, j;
554 for (i = 0x00; i <= 0x01; i++) {
555 data = pVBInfo->TimingV[0].data[i];
556 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
559 for (i = 0x02; i <= 0x03; i++) {
560 data = pVBInfo->TimingV[0].data[i];
561 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
564 for (i = 0x04; i <= 0x05; i++) {
565 data = pVBInfo->TimingV[0].data[i];
566 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
569 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
570 j &= 0xC0;
571 data = pVBInfo->TimingV[0].data[6];
572 data &= 0x3F;
573 data |= j;
574 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
576 data = pVBInfo->TimingV[0].data[6];
577 data &= 0x80;
578 data = data >> 2;
580 if (ModeNo <= 0x13)
581 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
582 else
583 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
585 i &= DoubleScanMode;
586 if (i)
587 data |= 0x80;
589 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
590 j &= 0x5F;
591 data |= j;
592 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
595 static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
596 unsigned short RefreshRateTableIndex,
597 struct vb_device_info *pVBInfo,
598 struct xgi_hw_device_info *HwDeviceExtension)
600 unsigned char index, data;
601 unsigned short i;
603 /* Get index */
604 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
605 index = index & IndexMask;
607 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
608 data &= 0x7F;
609 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
611 for (i = 0; i < 8; i++)
612 pVBInfo->TimingH[0].data[i]
613 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
615 for (i = 0; i < 7; i++)
616 pVBInfo->TimingV[0].data[i]
617 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
619 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
621 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
623 if (pVBInfo->ModeType > 0x03)
624 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
627 /* --------------------------------------------------------------------- */
628 /* Function : XGI_SetXG21CRTC */
629 /* Input : Stand or enhance CRTC table */
630 /* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
631 /* Description : Set LCD timing */
632 /* --------------------------------------------------------------------- */
633 static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
634 unsigned short RefreshRateTableIndex,
635 struct vb_device_info *pVBInfo)
637 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
638 unsigned short Temp1, Temp2, Temp3;
640 if (ModeNo <= 0x13) {
641 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
642 /* CR04 HRS */
643 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
644 /* SR2E [7:0]->HRS */
645 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
646 /* Tempbx: CR05 HRE */
647 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
648 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
649 Tempcx = Tempax;
650 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
651 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
652 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
653 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
654 Tempdx <<= 2; /* Tempdx << 2 */
655 /* SR2F [7:2]->HRE */
656 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
657 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
659 /* Tempax: CR16 VRS */
660 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
661 Tempbx = Tempax; /* Tempbx=Tempax */
662 Tempax &= 0x01; /* Tempax: VRS[0] */
663 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS */
665 /* Tempax: CR7 VRS */
666 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
667 Tempdx = Tempbx >> 1; /* Tempdx: VRS[7:1] */
668 Tempcx = Tempax & 0x04; /* Tempcx: CR7[2] */
669 Tempcx <<= 5; /* Tempcx[7]: VRS[8] */
670 Tempdx |= Tempcx; /* Tempdx: VRS[8:1] */
671 /* SR34[7:0]: VRS[8:1] */
672 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempdx);
674 /* Temp1[8]: VRS[8] unsigned char -> unsigned short */
675 Temp1 = Tempcx << 1;
676 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
677 Tempax &= 0x80; /* Tempax[7]: CR7[7] */
678 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
679 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
681 /* CR16 VRE */
682 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
683 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
684 Temp2 = Temp1 & 0x3F0; /* Temp2[9:4]: VRS[9:4] */
685 Temp2 |= Tempax; /* Temp2[9:0]: VRE[9:0] */
686 Temp3 = Temp1 & 0x0F; /* Temp3[3:0]: VRS[3:0] */
687 if (Tempax < Temp3) /* VRE[3:0]<VRS[3:0] */
688 Temp2 |= 0x10; /* Temp2: VRE + 0x10 */
689 Temp2 &= 0xFF; /* Temp2[7:0]: VRE[7:0] */
690 Tempax = (unsigned char) Temp2; /* Tempax[7:0]: VRE[7:0] */
691 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
692 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
693 Temp1 >>= 9; /* [10:9]->[1:0] */
694 Tempbx = (unsigned char) Temp1; /* Tempbx[1:0]: VRS[10:9] */
695 Tempax |= Tempbx; /* VRE[5:0]VRS[10:9] */
696 Tempax &= 0x7F;
697 /* SR3F D[7:2]->VRE D[1:0]->VRS */
698 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
699 } else {
700 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
701 /* Tempax: CR4 HRS */
702 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
703 Tempcx = Tempax; /* Tempcx: HRS */
704 /* SR2E[7:0]->HRS */
705 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
707 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
708 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
709 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
710 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
711 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
713 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
714 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
716 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
717 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
718 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
719 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
721 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
722 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
724 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
725 if (Tempax < Tempcx) /* HRE < HRS */
726 Temp2 |= 0x40; /* Temp2 + 0x40 */
728 Temp2 &= 0xFF;
729 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
730 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
731 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
732 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
733 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
734 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
735 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
737 /* CR10 VRS */
738 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
739 Tempbx = Tempax; /* Tempbx: VRS */
740 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
741 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
742 /* CR7[2][7] VRE */
743 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
744 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
745 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
746 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
747 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
748 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
750 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
751 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
752 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
753 Tempax &= 0x80;
754 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
755 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
756 /* Tempax: SRA */
757 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
758 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
759 Temp2 = Tempax;
760 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
761 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
763 /* Tempax: CR11 VRE */
764 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
765 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
766 /* Tempbx: SRA */
767 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
768 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
769 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
770 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
771 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
772 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
774 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
775 if (Tempax < Temp3) /* VRE < VRS */
776 Temp2 |= 0x20; /* VRE + 0x20 */
778 Temp2 &= 0xFF;
779 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
780 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
781 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
782 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
783 Tempbx = (unsigned char) Temp1;
784 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
785 Tempax &= 0x7F;
786 /* SR3F D[7:2]->VRE D[1:0]->VRS */
787 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
791 static void XGI_SetXG27CRTC(unsigned short ModeNo,
792 unsigned short ModeIdIndex,
793 unsigned short RefreshRateTableIndex,
794 struct vb_device_info *pVBInfo)
796 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
798 if (ModeNo <= 0x13) {
799 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
800 /* CR04 HRS */
801 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
802 /* SR2E [7:0]->HRS */
803 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
804 /* Tempbx: CR05 HRE */
805 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
806 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
807 Tempcx = Tempax;
808 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
809 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
810 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
811 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
812 Tempdx <<= 2; /* Tempdx << 2 */
813 /* SR2F [7:2]->HRE */
814 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
815 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
817 /* Tempax: CR10 VRS */
818 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
819 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax); /* SR34[7:0]->VRS */
820 Tempcx = Tempax; /* Tempcx=Tempax=VRS[7:0] */
821 /* Tempax[7][2]: CR7[7][2] VRS[9][8] */
822 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
823 Tempbx = Tempax; /* Tempbx=CR07 */
824 Tempax &= 0x04; /* Tempax[2]: CR07[2] VRS[8] */
825 Tempax >>= 2;
826 /* SR35 D[0]->VRS D[8] */
827 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
828 Tempcx |= (Tempax << 8); /* Tempcx[8] |= VRS[8] */
829 Tempcx |= (Tempbx & 0x80) << 2; /* Tempcx[9] |= VRS[9] */
831 /* CR11 VRE */
832 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
833 Tempax &= 0x0F; /* Tempax: VRE[3:0] */
834 Tempbx = Tempcx; /* Tempbx=Tempcx=VRS[9:0] */
835 Tempbx &= 0x3F0; /* Tempbx[9:4]: VRS[9:4] */
836 Tempbx |= Tempax; /* Tempbx[9:0]: VRE[9:0] */
837 if (Tempax <= (Tempcx & 0x0F)) /* VRE[3:0]<=VRS[3:0] */
838 Tempbx |= 0x10; /* Tempbx: VRE + 0x10 */
839 /* Tempax[7:0]: VRE[7:0] */
840 Tempax = (unsigned char) Tempbx & 0xFF;
841 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
842 Tempcx = (Tempcx & 0x600) >> 8; /* Tempcx VRS[10:9] */
843 /* SR3F D[7:2]->VRE D[5:0] */
844 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
845 /* SR35 D[2:1]->VRS[10:9] */
846 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x06, Tempcx);
847 } else {
848 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
849 /* Tempax: CR4 HRS */
850 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
851 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
852 /* SR2E[7:0]->HRS */
853 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
855 /* SR0B */
856 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
857 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
858 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
860 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
861 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
862 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
864 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
865 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
866 Tempax <<= 3; /* Tempax[5]: HRE[5] */
867 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
869 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
870 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
872 /* Tempax: CR4 HRS */
873 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
874 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
875 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
876 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
878 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
879 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
880 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
881 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
882 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
883 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
884 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
886 /* CR10 VRS */
887 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
888 /* SR34[7:0]->VRS[7:0] */
889 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
891 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
892 /* CR7[7][2] VRS[9][8] */
893 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
894 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
895 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
896 Tempax >>= 2; /* Tempax[0]: VRS[8] */
897 /* SR35[0]: VRS[8] */
898 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
899 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
900 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
901 /* Tempax: SR0A */
902 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
903 Tempax &= 0x08; /* SR0A[3] VRS[10] */
904 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
906 /* Tempax: CR11 VRE */
907 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
908 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
909 /* Tempbx: SR0A */
910 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
911 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
912 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
913 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
914 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
915 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
916 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
918 if (Tempbx <= Tempcx) /* VRE <= VRS */
919 Tempbx |= 0x20; /* VRE + 0x20 */
921 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
922 Tempax = (Tempbx << 2) & 0xFF;
923 /* SR3F[7:2]:VRE[5:0] */
924 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
925 Tempax = Tempcx >> 8;
926 /* SR35[2:0]:VRS[10:8] */
927 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
931 static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
933 unsigned char temp;
935 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
936 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
937 temp = (temp & 3) << 6;
938 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
939 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
940 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
941 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
945 static void xgifb_set_lcd(int chip_id,
946 struct vb_device_info *pVBInfo,
947 unsigned short RefreshRateTableIndex,
948 unsigned short ModeNo)
950 unsigned short Data, Temp, b3CC;
951 unsigned short XGI_P3cc;
953 XGI_P3cc = pVBInfo->P3cc;
955 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
956 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
957 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
958 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
960 if (chip_id == XG27) {
961 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
962 if ((Temp & 0x03) == 0) { /* dual 12 */
963 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
964 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
968 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
969 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
970 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
971 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
972 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
975 if (chip_id == XG27) {
976 XGI_SetXG27FPBits(pVBInfo);
977 } else {
978 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
979 if (Temp & 0x01) {
980 /* 18 bits FP */
981 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
982 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
986 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
988 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
989 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
991 if (ModeNo <= 0x13) {
992 b3CC = (unsigned char) inb(XGI_P3cc);
993 if (b3CC & 0x40)
994 /* Hsync polarity */
995 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
996 if (b3CC & 0x80)
997 /* Vsync polarity */
998 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
999 } else {
1000 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1001 if (Data & 0x4000)
1002 /* Hsync polarity */
1003 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
1004 if (Data & 0x8000)
1005 /* Vsync polarity */
1006 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1010 /* --------------------------------------------------------------------- */
1011 /* Function : XGI_UpdateXG21CRTC */
1012 /* Input : */
1013 /* Output : CRT1 CRTC */
1014 /* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
1015 /* --------------------------------------------------------------------- */
1016 static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1017 struct vb_device_info *pVBInfo,
1018 unsigned short RefreshRateTableIndex)
1020 int i, index = -1;
1022 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
1023 if (ModeNo <= 0x13) {
1024 for (i = 0; i < 12; i++) {
1025 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID)
1026 index = i;
1028 } else {
1029 if (ModeNo == 0x2E &&
1030 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1031 RES640x480x60))
1032 index = 12;
1033 else if (ModeNo == 0x2E &&
1034 (pVBInfo->RefIndex[RefreshRateTableIndex].
1035 Ext_CRT1CRTC == RES640x480x72))
1036 index = 13;
1037 else if (ModeNo == 0x2F)
1038 index = 14;
1039 else if (ModeNo == 0x50)
1040 index = 15;
1041 else if (ModeNo == 0x59)
1042 index = 16;
1045 if (index != -1) {
1046 xgifb_reg_set(pVBInfo->P3d4, 0x02,
1047 pVBInfo->UpdateCRT1[index].CR02);
1048 xgifb_reg_set(pVBInfo->P3d4, 0x03,
1049 pVBInfo->UpdateCRT1[index].CR03);
1050 xgifb_reg_set(pVBInfo->P3d4, 0x15,
1051 pVBInfo->UpdateCRT1[index].CR15);
1052 xgifb_reg_set(pVBInfo->P3d4, 0x16,
1053 pVBInfo->UpdateCRT1[index].CR16);
1057 static unsigned short XGI_GetResInfo(unsigned short ModeNo,
1058 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
1060 unsigned short resindex;
1062 if (ModeNo <= 0x13)
1063 /* si+St_ResInfo */
1064 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1065 else
1066 /* si+Ext_ResInfo */
1067 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1068 return resindex;
1071 static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
1072 unsigned short ModeNo, unsigned short ModeIdIndex,
1073 unsigned short RefreshRateTableIndex,
1074 struct vb_device_info *pVBInfo)
1076 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
1078 unsigned char data;
1080 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1082 if (ModeNo <= 0x13) {
1083 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1084 tempax = pVBInfo->StResInfo[resindex].HTotal;
1085 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1086 } else {
1087 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1088 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1089 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1092 if (modeflag & HalfDCLK)
1093 tempax = tempax >> 1;
1095 if (ModeNo > 0x13) {
1096 if (modeflag & HalfDCLK)
1097 tempax = tempax << 1;
1099 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1101 if (temp & InterlaceMode)
1102 tempbx = tempbx >> 1;
1104 if (modeflag & DoubleScanMode)
1105 tempbx = tempbx << 1;
1108 tempcx = 8;
1110 tempax /= tempcx;
1111 tempax -= 1;
1112 tempbx -= 1;
1113 tempcx = tempax;
1114 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1115 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1116 data &= 0x7F;
1117 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
1118 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
1119 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
1120 (unsigned short) ((tempcx & 0x0ff00) >> 10));
1121 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
1122 tempax = 0;
1123 tempbx = tempbx >> 8;
1125 if (tempbx & 0x01)
1126 tempax |= 0x02;
1128 if (tempbx & 0x02)
1129 tempax |= 0x40;
1131 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
1132 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
1133 data &= 0xFF;
1134 tempax = 0;
1136 if (tempbx & 0x04)
1137 tempax |= 0x02;
1139 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
1140 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
1143 static void XGI_SetCRT1Offset(unsigned short ModeNo,
1144 unsigned short ModeIdIndex,
1145 unsigned short RefreshRateTableIndex,
1146 struct xgi_hw_device_info *HwDeviceExtension,
1147 struct vb_device_info *pVBInfo)
1149 unsigned short temp, ah, al, temp2, i, DisplayUnit;
1151 /* GetOffset */
1152 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1153 temp = temp >> 8;
1154 temp = pVBInfo->ScreenOffset[temp];
1156 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1157 temp2 &= InterlaceMode;
1159 if (temp2)
1160 temp = temp << 1;
1162 temp2 = pVBInfo->ModeType - ModeEGA;
1164 switch (temp2) {
1165 case 0:
1166 temp2 = 1;
1167 break;
1168 case 1:
1169 temp2 = 2;
1170 break;
1171 case 2:
1172 temp2 = 4;
1173 break;
1174 case 3:
1175 temp2 = 4;
1176 break;
1177 case 4:
1178 temp2 = 6;
1179 break;
1180 case 5:
1181 temp2 = 8;
1182 break;
1183 default:
1184 break;
1187 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1188 temp = temp * temp2 + temp2 / 2;
1189 else
1190 temp *= temp2;
1192 /* SetOffset */
1193 DisplayUnit = temp;
1194 temp2 = temp;
1195 temp = temp >> 8; /* ah */
1196 temp &= 0x0F;
1197 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
1198 i &= 0xF0;
1199 i |= temp;
1200 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
1202 temp = (unsigned char) temp2;
1203 temp &= 0xFF; /* al */
1204 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
1206 /* SetDisplayUnit */
1207 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1208 temp2 &= InterlaceMode;
1209 if (temp2)
1210 DisplayUnit >>= 1;
1212 DisplayUnit = DisplayUnit << 5;
1213 ah = (DisplayUnit & 0xff00) >> 8;
1214 al = DisplayUnit & 0x00ff;
1215 if (al == 0)
1216 ah += 1;
1217 else
1218 ah += 2;
1220 if (HwDeviceExtension->jChipType >= XG20)
1221 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1222 ah -= 1;
1224 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
1227 static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1228 unsigned short ModeIdIndex,
1229 unsigned short RefreshRateTableIndex,
1230 struct xgi_hw_device_info *HwDeviceExtension,
1231 struct vb_device_info *pVBInfo)
1233 unsigned short LCDXlat1VCLK[4] = { VCLK65 + 2,
1234 VCLK65 + 2,
1235 VCLK65 + 2,
1236 VCLK65 + 2 };
1237 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1238 VCLK108_2 + 5,
1239 VCLK108_2 + 5,
1240 VCLK108_2 + 5 };
1241 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
1242 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1243 VCLK65 + 2,
1244 VCLK65 + 2,
1245 VCLK65 + 2 };
1246 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1247 VCLK65 + 2,
1248 VCLK65 + 2,
1249 VCLK65 + 2 };
1251 unsigned short CRT2Index, VCLKIndex;
1252 unsigned short modeflag, resinfo;
1254 if (ModeNo <= 0x13) {
1255 /* si+St_ResInfo */
1256 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1257 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1258 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1259 } else {
1260 /* si+Ext_ResInfo */
1261 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1262 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1263 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1264 Ext_CRT2CRTC;
1267 if (pVBInfo->IF_DEF_LVDS == 0) {
1268 CRT2Index = CRT2Index >> 6; /* for LCD */
1269 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /*301b*/
1270 if (pVBInfo->LCDResInfo != Panel1024x768)
1271 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1272 else
1273 VCLKIndex = LCDXlat1VCLK[CRT2Index];
1274 } else if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
1275 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1276 VCLKIndex = HiTVVCLKDIV2;
1277 VCLKIndex += 25;
1278 } else {
1279 VCLKIndex = HiTVVCLK;
1280 VCLKIndex += 25;
1283 if (pVBInfo->SetFlag & TVSimuMode) {
1284 if (modeflag & Charx8Dot) {
1285 VCLKIndex = HiTVSimuVCLK;
1286 VCLKIndex += 25;
1287 } else {
1288 VCLKIndex = HiTVTextVCLK;
1289 VCLKIndex += 25;
1293 /* 301lv */
1294 if ((pVBInfo->VBType & VB_XGI301LV) &&
1295 !(pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
1296 if (pVBInfo->VBExtInfo == VB_YPbPr750p)
1297 VCLKIndex = YPbPr750pVCLK;
1298 else if (pVBInfo->VBExtInfo == VB_YPbPr525p)
1299 VCLKIndex = YPbPr525pVCLK;
1300 else if (pVBInfo->SetFlag & RPLLDIV2XO)
1301 VCLKIndex = YPbPr525iVCLK_2;
1302 else
1303 VCLKIndex = YPbPr525iVCLK;
1305 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
1306 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1307 VCLKIndex = TVVCLKDIV2;
1308 VCLKIndex += 25;
1309 } else {
1310 VCLKIndex = TVVCLK;
1311 VCLKIndex += 25;
1313 } else { /* for CRT2 */
1314 /* Port 3cch */
1315 VCLKIndex = (unsigned char) inb((pVBInfo->P3ca + 0x02));
1316 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1317 if (ModeNo > 0x13) {
1318 /* di+Ext_CRTVCLK */
1319 VCLKIndex = pVBInfo->RefIndex[
1320 RefreshRateTableIndex].
1321 Ext_CRTVCLK;
1322 VCLKIndex &= IndexMask;
1325 } else { /* LVDS */
1326 if (ModeNo <= 0x13)
1327 VCLKIndex = CRT2Index;
1328 else
1329 VCLKIndex = CRT2Index;
1331 VCLKIndex = VCLKIndex >> 6;
1332 if ((pVBInfo->LCDResInfo == Panel800x600) ||
1333 (pVBInfo->LCDResInfo == Panel320x480))
1334 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
1335 else if ((pVBInfo->LCDResInfo == Panel1024x768) ||
1336 (pVBInfo->LCDResInfo == Panel1024x768x75))
1337 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1338 else
1339 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
1342 return VCLKIndex;
1345 static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1346 unsigned short ModeIdIndex,
1347 struct xgi_hw_device_info *HwDeviceExtension,
1348 unsigned short RefreshRateTableIndex,
1349 struct vb_device_info *pVBInfo)
1351 unsigned char index, data;
1352 unsigned short vclkindex;
1354 if (pVBInfo->IF_DEF_LVDS == 1) {
1355 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1356 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1357 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1358 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
1359 pVBInfo->VCLKData[index].SR2B);
1360 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
1361 pVBInfo->VCLKData[index].SR2C);
1362 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1363 } else if ((pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
1364 | VB_XGI302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1365 & SetCRT2ToLCDA)) {
1366 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1367 RefreshRateTableIndex, HwDeviceExtension,
1368 pVBInfo);
1369 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1370 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1371 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
1372 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
1373 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
1374 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1375 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1376 } else {
1377 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1378 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1379 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1380 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
1381 pVBInfo->VCLKData[index].SR2B);
1382 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
1383 pVBInfo->VCLKData[index].SR2C);
1384 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1387 if (HwDeviceExtension->jChipType >= XG20) {
1388 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1389 HalfDCLK) {
1390 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
1391 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
1392 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
1393 index = data;
1394 index &= 0xE0;
1395 data &= 0x1F;
1396 data = data << 1;
1397 data += 1;
1398 data |= index;
1399 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1404 static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1406 unsigned char temp;
1408 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1409 temp = (temp & 1) << 6;
1410 /* SR06[6] 18bit Dither */
1411 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1412 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1413 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1417 static void XGI_SetCRT1FIFO(unsigned short ModeNo,
1418 struct xgi_hw_device_info *HwDeviceExtension,
1419 struct vb_device_info *pVBInfo)
1421 unsigned short data;
1423 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1424 data &= 0xfe;
1425 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
1427 if (ModeNo > 0x13) {
1428 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1429 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1430 data &= 0xC0;
1431 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1432 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1433 data |= 0x01;
1434 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
1435 } else {
1436 if (HwDeviceExtension->jChipType == XG27) {
1437 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
1438 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1439 data &= 0xC0;
1440 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
1441 } else {
1442 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
1443 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1444 data &= 0xF0;
1445 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
1449 if (HwDeviceExtension->jChipType == XG21)
1450 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
1453 static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1454 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1455 struct vb_device_info *pVBInfo)
1457 unsigned short data, data2 = 0;
1458 short VCLK;
1460 unsigned char index;
1462 if (ModeNo <= 0x13)
1463 VCLK = 0;
1464 else {
1465 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1466 index &= IndexMask;
1467 VCLK = pVBInfo->VCLKData[index].CLOCK;
1470 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
1471 data &= 0xf3;
1472 if (VCLK >= 200)
1473 data |= 0x0c; /* VCLK > 200 */
1475 if (HwDeviceExtension->jChipType >= XG20)
1476 data &= ~0x04; /* 2 pixel mode */
1478 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
1480 if (HwDeviceExtension->jChipType < XG20) {
1481 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
1482 data &= 0xE7;
1483 if (VCLK < 200)
1484 data |= 0x10;
1485 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
1488 data2 = 0x00;
1490 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
1491 if (HwDeviceExtension->jChipType >= XG27)
1492 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
1496 static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
1497 unsigned short ModeNo, unsigned short ModeIdIndex,
1498 unsigned short RefreshRateTableIndex,
1499 struct vb_device_info *pVBInfo)
1501 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1502 xres;
1504 if (ModeNo > 0x13) {
1505 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1506 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1507 Ext_InfoFlag;
1508 } else
1509 /* si+St_ModeFlag */
1510 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1512 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
1513 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
1515 if (ModeNo > 0x13)
1516 data = infoflag;
1517 else
1518 data = 0;
1520 data2 = 0;
1522 if (ModeNo > 0x13) {
1523 if (pVBInfo->ModeType > 0x02) {
1524 data2 |= 0x02;
1525 data3 = pVBInfo->ModeType - ModeVGA;
1526 data3 = data3 << 2;
1527 data2 |= data3;
1531 data &= InterlaceMode;
1533 if (data)
1534 data2 |= 0x20;
1536 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
1537 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1538 if (ModeNo <= 0x13)
1539 xres = pVBInfo->StResInfo[resindex].HTotal;
1540 else
1541 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
1543 data = 0x0000;
1544 if (infoflag & InterlaceMode) {
1545 if (xres == 1024)
1546 data = 0x0035;
1547 else if (xres == 1280)
1548 data = 0x0048;
1551 data2 = data & 0x00FF;
1552 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
1553 data2 = (data & 0xFF00) >> 8;
1554 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
1556 if (modeflag & HalfDCLK)
1557 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
1559 data2 = 0;
1561 if (modeflag & LineCompareOff)
1562 data2 |= 0x08;
1564 if (ModeNo > 0x13) {
1565 if (pVBInfo->ModeType == ModeEGA)
1566 data2 |= 0x40;
1569 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
1570 data = 0x60;
1571 if (pVBInfo->ModeType != ModeText) {
1572 data = data ^ 0x60;
1573 if (pVBInfo->ModeType != ModeEGA)
1574 data = data ^ 0xA0;
1576 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
1578 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1579 pVBInfo);
1581 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1583 if (HwDeviceExtension->jChipType == XG27) {
1584 if (data & 0x40)
1585 data = 0x2c;
1586 else
1587 data = 0x6c;
1588 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1589 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
1590 } else if (HwDeviceExtension->jChipType >= XG20) {
1591 if (data & 0x40)
1592 data = 0x33;
1593 else
1594 data = 0x73;
1595 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1596 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
1597 } else {
1598 if (data & 0x40)
1599 data = 0x2c;
1600 else
1601 data = 0x6c;
1602 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1607 static void XGI_WriteDAC(unsigned short dl,
1608 unsigned short ah,
1609 unsigned short al,
1610 unsigned short dh,
1611 struct vb_device_info *pVBInfo)
1613 unsigned short temp, bh, bl;
1615 bh = ah;
1616 bl = al;
1618 if (dl != 0) {
1619 temp = bh;
1620 bh = dh;
1621 dh = temp;
1622 if (dl == 1) {
1623 temp = bl;
1624 bl = dh;
1625 dh = temp;
1626 } else {
1627 temp = bl;
1628 bl = bh;
1629 bh = temp;
1632 outb((unsigned short) dh, pVBInfo->P3c9);
1633 outb((unsigned short) bh, pVBInfo->P3c9);
1634 outb((unsigned short) bl, pVBInfo->P3c9);
1637 static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
1638 struct vb_device_info *pVBInfo)
1640 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
1641 ah, dh;
1642 const unsigned short *table = NULL;
1644 if (ModeNo <= 0x13)
1645 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1646 else
1647 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1649 data &= DACInfoFlag;
1650 time = 64;
1652 if (data == 0x00)
1653 table = XGINew_MDA_DAC;
1654 else if (data == 0x08)
1655 table = XGINew_CGA_DAC;
1656 else if (data == 0x10)
1657 table = XGINew_EGA_DAC;
1658 else if (data == 0x18) {
1659 time = 256;
1660 table = XGINew_VGA_DAC;
1663 if (time == 256)
1664 j = 16;
1665 else
1666 j = time;
1668 outb(0xFF, pVBInfo->P3c6);
1669 outb(0x00, pVBInfo->P3c8);
1671 for (i = 0; i < j; i++) {
1672 data = table[i];
1674 for (k = 0; k < 3; k++) {
1675 data2 = 0;
1677 if (data & 0x01)
1678 data2 = 0x2A;
1680 if (data & 0x02)
1681 data2 += 0x15;
1683 outb(data2, pVBInfo->P3c9);
1684 data = data >> 2;
1688 if (time == 256) {
1689 for (i = 16; i < 32; i++) {
1690 data = table[i];
1692 for (k = 0; k < 3; k++)
1693 outb(data, pVBInfo->P3c9);
1696 si = 32;
1698 for (m = 0; m < 9; m++) {
1699 di = si;
1700 bx = si + 0x04;
1701 dl = 0;
1703 for (n = 0; n < 3; n++) {
1704 for (o = 0; o < 5; o++) {
1705 dh = table[si];
1706 ah = table[di];
1707 al = table[bx];
1708 si++;
1709 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1712 si -= 2;
1714 for (o = 0; o < 3; o++) {
1715 dh = table[bx];
1716 ah = table[di];
1717 al = table[si];
1718 si--;
1719 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1722 dl++;
1725 si += 5;
1730 static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1731 unsigned short ModeIdIndex,
1732 struct vb_device_info *pVBInfo)
1734 unsigned short resindex, xres, yres, modeflag;
1736 if (ModeNo <= 0x13)
1737 /* si+St_ResInfo */
1738 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1739 else
1740 /* si+Ext_ResInfo */
1741 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1743 if (ModeNo <= 0x13)
1744 /* si+St_ResInfo */
1745 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1746 else
1747 /* si+Ext_ResInfo */
1748 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1750 if (ModeNo <= 0x13) {
1751 xres = pVBInfo->StResInfo[resindex].HTotal;
1752 yres = pVBInfo->StResInfo[resindex].VTotal;
1753 } else {
1754 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1755 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1757 if (ModeNo > 0x13) {
1758 if (modeflag & HalfDCLK)
1759 xres = xres << 1;
1761 if (modeflag & DoubleScanMode)
1762 yres = yres << 1;
1765 if (xres == 720)
1766 xres = 640;
1768 pVBInfo->VGAHDE = xres;
1769 pVBInfo->HDE = xres;
1770 pVBInfo->VGAVDE = yres;
1771 pVBInfo->VDE = yres;
1774 static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1775 unsigned short ModeIdIndex,
1776 unsigned short RefreshRateTableIndex,
1777 struct vb_device_info *pVBInfo)
1779 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1781 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1783 tempbx = BX;
1785 if (ModeNo <= 0x13) {
1786 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1787 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1788 } else {
1789 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1790 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1793 tempal = tempal & 0x0f;
1795 if (tempbx <= 1) { /* ExpLink */
1796 if (ModeNo <= 0x13) {
1797 /* find no Ext_CRT2CRTC2 */
1798 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1799 } else {
1800 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1801 Ext_CRT2CRTC;
1804 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1805 if (ModeNo <= 0x13)
1806 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1807 St_CRT2CRTC2;
1808 else
1809 tempal = pVBInfo->RefIndex[
1810 RefreshRateTableIndex].
1811 Ext_CRT2CRTC2;
1814 if (tempbx & 0x01)
1815 tempal = (tempal >> 4);
1817 tempal = (tempal & 0x0f);
1820 tempcx = LCDLenList[tempbx];
1822 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1823 if ((tempbx == 5) || (tempbx) == 7)
1824 tempcx = LCDDesDataLen2;
1825 else if ((tempbx == 3) || (tempbx == 8))
1826 tempcx = LVDSDesDataLen2;
1829 switch (tempbx) {
1830 case 0:
1831 case 1:
1832 tempdi = xgifb_epllcd_crt1;
1833 break;
1834 case 2:
1835 tempdi = XGI_EPLLCDDataPtr;
1836 break;
1837 case 3:
1838 tempdi = XGI_EPLLCDDesDataPtr;
1839 break;
1840 case 4:
1841 tempdi = XGI_LCDDataTable;
1842 break;
1843 case 5:
1844 tempdi = XGI_LCDDesDataTable;
1845 break;
1846 case 6:
1847 tempdi = XGI_EPLCHLCDRegPtr;
1848 break;
1849 case 7:
1850 case 8:
1851 case 9:
1852 tempdi = NULL;
1853 break;
1854 default:
1855 break;
1858 if (tempdi == NULL) /* OEMUtil */
1859 return NULL;
1861 table = tempbx;
1862 i = 0;
1864 while (tempdi[i].PANELID != 0xff) {
1865 tempdx = pVBInfo->LCDResInfo;
1866 if (tempbx & 0x0080) { /* OEMUtil */
1867 tempbx &= (~0x0080);
1868 tempdx = pVBInfo->LCDTypeInfo;
1871 if (pVBInfo->LCDInfo & EnableScalingLCD)
1872 tempdx &= (~PanelResInfo);
1874 if (tempdi[i].PANELID == tempdx) {
1875 tempbx = tempdi[i].MASK;
1876 tempdx = pVBInfo->LCDInfo;
1878 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1879 tempdx |= SetLCDStdMode;
1881 if (modeflag & HalfDCLK)
1882 tempdx |= SetLCDLowResolution;
1884 tempbx &= tempdx;
1885 if (tempbx == tempdi[i].CAP)
1886 break;
1888 i++;
1891 if (table == 0) {
1892 switch (tempdi[i].DATAPTR) {
1893 case 0:
1894 return &XGI_LVDSCRT11024x768_1_H[tempal];
1895 break;
1896 case 1:
1897 return &XGI_LVDSCRT11024x768_2_H[tempal];
1898 break;
1899 case 2:
1900 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1901 break;
1902 case 3:
1903 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1904 break;
1905 case 4:
1906 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1907 break;
1908 case 5:
1909 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1910 break;
1911 case 6:
1912 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1913 break;
1914 case 7:
1915 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1916 break;
1917 case 8:
1918 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1919 break;
1920 case 9:
1921 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1922 break;
1923 case 10:
1924 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
1925 break;
1926 default:
1927 break;
1929 } else if (table == 1) {
1930 switch (tempdi[i].DATAPTR) {
1931 case 0:
1932 return &XGI_LVDSCRT11024x768_1_V[tempal];
1933 break;
1934 case 1:
1935 return &XGI_LVDSCRT11024x768_2_V[tempal];
1936 break;
1937 case 2:
1938 return &XGI_LVDSCRT11280x1024_1_V[tempal];
1939 break;
1940 case 3:
1941 return &XGI_LVDSCRT11280x1024_2_V[tempal];
1942 break;
1943 case 4:
1944 return &XGI_LVDSCRT11400x1050_1_V[tempal];
1945 break;
1946 case 5:
1947 return &XGI_LVDSCRT11400x1050_2_V[tempal];
1948 break;
1949 case 6:
1950 return &XGI_LVDSCRT11600x1200_1_V[tempal];
1951 break;
1952 case 7:
1953 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
1954 break;
1955 case 8:
1956 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
1957 break;
1958 case 9:
1959 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
1960 break;
1961 case 10:
1962 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
1963 break;
1964 default:
1965 break;
1967 } else if (table == 2) {
1968 switch (tempdi[i].DATAPTR) {
1969 case 0:
1970 return &XGI_LVDS1024x768Data_1[tempal];
1971 break;
1972 case 1:
1973 return &XGI_LVDS1024x768Data_2[tempal];
1974 break;
1975 case 2:
1976 return &XGI_LVDS1280x1024Data_1[tempal];
1977 break;
1978 case 3:
1979 return &XGI_LVDS1280x1024Data_2[tempal];
1980 break;
1981 case 4:
1982 return &XGI_LVDS1400x1050Data_1[tempal];
1983 break;
1984 case 5:
1985 return &XGI_LVDS1400x1050Data_2[tempal];
1986 break;
1987 case 6:
1988 return &XGI_LVDS1600x1200Data_1[tempal];
1989 break;
1990 case 7:
1991 return &XGI_LVDSNoScalingData[tempal];
1992 break;
1993 case 8:
1994 return &XGI_LVDS1024x768Data_1x75[tempal];
1995 break;
1996 case 9:
1997 return &XGI_LVDS1024x768Data_2x75[tempal];
1998 break;
1999 case 10:
2000 return &XGI_LVDS1280x1024Data_1x75[tempal];
2001 break;
2002 case 11:
2003 return &XGI_LVDS1280x1024Data_2x75[tempal];
2004 break;
2005 case 12:
2006 return &XGI_LVDSNoScalingDatax75[tempal];
2007 break;
2008 default:
2009 break;
2011 } else if (table == 3) {
2012 switch (tempdi[i].DATAPTR) {
2013 case 0:
2014 return &XGI_LVDS1024x768Des_1[tempal];
2015 break;
2016 case 1:
2017 return &XGI_LVDS1024x768Des_3[tempal];
2018 break;
2019 case 2:
2020 return &XGI_LVDS1024x768Des_2[tempal];
2021 break;
2022 case 3:
2023 return &XGI_LVDS1280x1024Des_1[tempal];
2024 break;
2025 case 4:
2026 return &XGI_LVDS1280x1024Des_2[tempal];
2027 break;
2028 case 5:
2029 return &XGI_LVDS1400x1050Des_1[tempal];
2030 break;
2031 case 6:
2032 return &XGI_LVDS1400x1050Des_2[tempal];
2033 break;
2034 case 7:
2035 return &XGI_LVDS1600x1200Des_1[tempal];
2036 break;
2037 case 8:
2038 return &XGI_LVDSNoScalingDesData[tempal];
2039 break;
2040 case 9:
2041 return &XGI_LVDS1024x768Des_1x75[tempal];
2042 break;
2043 case 10:
2044 return &XGI_LVDS1024x768Des_3x75[tempal];
2045 break;
2046 case 11:
2047 return &XGI_LVDS1024x768Des_2x75[tempal];
2048 break;
2049 case 12:
2050 return &XGI_LVDS1280x1024Des_1x75[tempal];
2051 break;
2052 case 13:
2053 return &XGI_LVDS1280x1024Des_2x75[tempal];
2054 break;
2055 case 14:
2056 return &XGI_LVDSNoScalingDesDatax75[tempal];
2057 break;
2058 default:
2059 break;
2061 } else if (table == 4) {
2062 switch (tempdi[i].DATAPTR) {
2063 case 0:
2064 return &XGI_ExtLCD1024x768Data[tempal];
2065 break;
2066 case 1:
2067 return &XGI_StLCD1024x768Data[tempal];
2068 break;
2069 case 2:
2070 return &XGI_CetLCD1024x768Data[tempal];
2071 break;
2072 case 3:
2073 return &XGI_ExtLCD1280x1024Data[tempal];
2074 break;
2075 case 4:
2076 return &XGI_StLCD1280x1024Data[tempal];
2077 break;
2078 case 5:
2079 return &XGI_CetLCD1280x1024Data[tempal];
2080 break;
2081 case 6:
2082 case 7:
2083 return &xgifb_lcd_1400x1050[tempal];
2084 break;
2085 case 8:
2086 return &XGI_CetLCD1400x1050Data[tempal];
2087 break;
2088 case 9:
2089 return &XGI_ExtLCD1600x1200Data[tempal];
2090 break;
2091 case 10:
2092 return &XGI_StLCD1600x1200Data[tempal];
2093 break;
2094 case 11:
2095 return &XGI_NoScalingData[tempal];
2096 break;
2097 case 12:
2098 return &XGI_ExtLCD1024x768x75Data[tempal];
2099 break;
2100 case 13:
2101 return &XGI_ExtLCD1024x768x75Data[tempal];
2102 break;
2103 case 14:
2104 return &XGI_CetLCD1024x768x75Data[tempal];
2105 break;
2106 case 15:
2107 case 16:
2108 return &xgifb_lcd_1280x1024x75[tempal];
2109 break;
2110 case 17:
2111 return &XGI_CetLCD1280x1024x75Data[tempal];
2112 break;
2113 case 18:
2114 return &XGI_NoScalingDatax75[tempal];
2115 break;
2116 default:
2117 break;
2119 } else if (table == 5) {
2120 switch (tempdi[i].DATAPTR) {
2121 case 0:
2122 return &XGI_ExtLCDDes1024x768Data[tempal];
2123 break;
2124 case 1:
2125 return &XGI_StLCDDes1024x768Data[tempal];
2126 break;
2127 case 2:
2128 return &XGI_CetLCDDes1024x768Data[tempal];
2129 break;
2130 case 3:
2131 if ((pVBInfo->VBType & VB_XGI301LV) ||
2132 (pVBInfo->VBType & VB_XGI302LV))
2133 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
2134 else
2135 return &XGI_ExtLCDDes1280x1024Data[tempal];
2136 break;
2137 case 4:
2138 if ((pVBInfo->VBType & VB_XGI301LV) ||
2139 (pVBInfo->VBType & VB_XGI302LV))
2140 return &XGI_StLCDDLDes1280x1024Data[tempal];
2141 else
2142 return &XGI_StLCDDes1280x1024Data[tempal];
2143 break;
2144 case 5:
2145 if ((pVBInfo->VBType & VB_XGI301LV) ||
2146 (pVBInfo->VBType & VB_XGI302LV))
2147 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2148 else
2149 return &XGI_CetLCDDes1280x1024Data[tempal];
2150 break;
2151 case 6:
2152 case 7:
2153 if ((pVBInfo->VBType & VB_XGI301LV) ||
2154 (pVBInfo->VBType & VB_XGI302LV))
2155 return &xgifb_lcddldes_1400x1050[tempal];
2156 else
2157 return &xgifb_lcddes_1400x1050[tempal];
2158 break;
2159 case 8:
2160 return &XGI_CetLCDDes1400x1050Data[tempal];
2161 break;
2162 case 9:
2163 return &XGI_CetLCDDes1400x1050Data2[tempal];
2164 break;
2165 case 10:
2166 if ((pVBInfo->VBType & VB_XGI301LV) ||
2167 (pVBInfo->VBType & VB_XGI302LV))
2168 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2169 else
2170 return &XGI_ExtLCDDes1600x1200Data[tempal];
2171 break;
2172 case 11:
2173 if ((pVBInfo->VBType & VB_XGI301LV) ||
2174 (pVBInfo->VBType & VB_XGI302LV))
2175 return &XGI_StLCDDLDes1600x1200Data[tempal];
2176 else
2177 return &XGI_StLCDDes1600x1200Data[tempal];
2178 break;
2179 case 12:
2180 return &XGI_NoScalingDesData[tempal];
2181 break;
2182 case 13:
2183 case 14:
2184 return &xgifb_lcddes_1024x768x75[tempal];
2185 break;
2186 case 15:
2187 return &XGI_CetLCDDes1024x768x75Data[tempal];
2188 break;
2189 case 16:
2190 case 17:
2191 if ((pVBInfo->VBType & VB_XGI301LV) ||
2192 (pVBInfo->VBType & VB_XGI302LV))
2193 return &xgifb_lcddldes_1280x1024x75[tempal];
2194 else
2195 return &xgifb_lcddes_1280x1024x75[tempal];
2196 break;
2197 case 18:
2198 if ((pVBInfo->VBType & VB_XGI301LV) ||
2199 (pVBInfo->VBType & VB_XGI302LV))
2200 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2201 else
2202 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2203 break;
2204 case 19:
2205 return &XGI_NoScalingDesDatax75[tempal];
2206 break;
2207 default:
2208 break;
2210 } else if (table == 6) {
2211 switch (tempdi[i].DATAPTR) {
2212 case 0:
2213 return &XGI_CH7017LV1024x768[tempal];
2214 break;
2215 case 1:
2216 return &XGI_CH7017LV1400x1050[tempal];
2217 break;
2218 default:
2219 break;
2222 return NULL;
2225 static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2226 unsigned short ModeIdIndex,
2227 unsigned short RefreshRateTableIndex,
2228 struct vb_device_info *pVBInfo)
2230 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2231 struct XGI330_TVDataTablStruct *tempdi = NULL;
2233 tempbx = BX;
2235 if (ModeNo <= 0x13) {
2236 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2237 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2238 } else {
2239 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2240 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2243 tempal = tempal & 0x3f;
2244 table = tempbx;
2246 switch (tempbx) {
2247 case 0:
2248 tempdi = NULL;
2249 break;
2250 case 1:
2251 tempdi = NULL;
2252 break;
2253 case 2:
2254 case 6:
2255 tempdi = xgifb_chrontel_tv;
2256 break;
2257 case 3:
2258 tempdi = NULL;
2259 break;
2260 case 4:
2261 tempdi = XGI_TVDataTable;
2262 break;
2263 case 5:
2264 tempdi = NULL;
2265 break;
2266 default:
2267 break;
2270 if (tempdi == NULL) /* OEMUtil */
2271 return NULL;
2273 tempdx = pVBInfo->TVInfo;
2275 if (pVBInfo->VBInfo & SetInSlaveMode)
2276 tempdx = tempdx | SetTVLockMode;
2278 if (modeflag & HalfDCLK)
2279 tempdx = tempdx | SetTVLowResolution;
2281 i = 0;
2283 while (tempdi[i].MASK != 0xffff) {
2284 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2285 break;
2286 i++;
2289 /* 07/05/22 */
2290 if (table == 0x04) {
2291 switch (tempdi[i].DATAPTR) {
2292 case 0:
2293 return &XGI_ExtPALData[tempal];
2294 break;
2295 case 1:
2296 return &XGI_ExtNTSCData[tempal];
2297 break;
2298 case 2:
2299 return &XGI_StPALData[tempal];
2300 break;
2301 case 3:
2302 return &XGI_StNTSCData[tempal];
2303 break;
2304 case 4:
2305 return &XGI_ExtHiTVData[tempal];
2306 break;
2307 case 5:
2308 return &XGI_St2HiTVData[tempal];
2309 break;
2310 case 6:
2311 return &XGI_ExtYPbPr525iData[tempal];
2312 break;
2313 case 7:
2314 return &XGI_ExtYPbPr525pData[tempal];
2315 break;
2316 case 8:
2317 return &XGI_ExtYPbPr750pData[tempal];
2318 break;
2319 case 9:
2320 return &XGI_StYPbPr525iData[tempal];
2321 break;
2322 case 10:
2323 return &XGI_StYPbPr525pData[tempal];
2324 break;
2325 case 11:
2326 return &XGI_StYPbPr750pData[tempal];
2327 break;
2328 case 12: /* avoid system hang */
2329 return &XGI_ExtNTSCData[tempal];
2330 break;
2331 case 13:
2332 return &XGI_St1HiTVData[tempal];
2333 break;
2334 default:
2335 break;
2337 } else if (table == 0x02) {
2338 switch (tempdi[i].DATAPTR) {
2339 case 0:
2340 return &XGI_CHTVUNTSCData[tempal];
2341 break;
2342 case 1:
2343 return &XGI_CHTVONTSCData[tempal];
2344 break;
2345 case 2:
2346 return &XGI_CHTVUPALData[tempal];
2347 break;
2348 case 3:
2349 return &XGI_CHTVOPALData[tempal];
2350 break;
2351 default:
2352 break;
2355 return NULL;
2358 static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
2359 unsigned short RefreshRateTableIndex,
2360 struct vb_device_info *pVBInfo)
2362 unsigned short tempbx;
2363 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
2365 tempbx = 2;
2367 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2368 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2369 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2370 pVBInfo);
2371 pVBInfo->VGAHT = LCDPtr->VGAHT;
2372 pVBInfo->VGAVT = LCDPtr->VGAVT;
2373 pVBInfo->HT = LCDPtr->LCDHT;
2374 pVBInfo->VT = LCDPtr->LCDVT;
2377 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2378 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2379 | EnableScalingLCD))) {
2380 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2381 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2382 pVBInfo->HDE = 1024;
2383 pVBInfo->VDE = 768;
2384 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2385 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2386 pVBInfo->HDE = 1280;
2387 pVBInfo->VDE = 1024;
2388 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2389 pVBInfo->HDE = 1400;
2390 pVBInfo->VDE = 1050;
2391 } else {
2392 pVBInfo->HDE = 1600;
2393 pVBInfo->VDE = 1200;
2399 static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
2400 unsigned short RefreshRateTableIndex,
2401 struct xgi_hw_device_info *HwDeviceExtension,
2402 struct vb_device_info *pVBInfo)
2404 unsigned char index;
2405 unsigned short tempbx, i;
2406 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2407 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
2409 if (ModeNo <= 0x13)
2410 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2411 else
2412 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2414 index = index & IndexMask;
2416 tempbx = 0;
2418 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2419 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2420 XGI_GetLcdPtr(tempbx, ModeNo,
2421 ModeIdIndex,
2422 RefreshRateTableIndex,
2423 pVBInfo);
2425 for (i = 0; i < 8; i++)
2426 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
2429 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2431 tempbx = 1;
2433 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2434 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2435 XGI_GetLcdPtr(
2436 tempbx,
2437 ModeNo,
2438 ModeIdIndex,
2439 RefreshRateTableIndex,
2440 pVBInfo);
2441 for (i = 0; i < 7; i++)
2442 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2445 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
2448 static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2450 unsigned char tempal, tempah, tempbl, i;
2452 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
2453 tempal = tempah & 0x0F;
2454 tempah = tempah & 0xF0;
2455 i = 0;
2456 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2458 while (tempbl != 0xFF) {
2459 if (tempbl & 0x80) { /* OEMUtil */
2460 tempal = tempah;
2461 tempbl = tempbl & ~(0x80);
2464 if (tempal == tempbl)
2465 break;
2467 i++;
2469 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2472 return i;
2475 static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2477 unsigned short tempah, tempal, tempbl, i;
2479 tempal = pVBInfo->LCDResInfo;
2480 tempah = pVBInfo->LCDTypeInfo;
2482 i = 0;
2483 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2485 while (tempbl != 0xFF) {
2486 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2487 tempal = tempah;
2488 tempbl &= ~0x80;
2491 if (tempal == tempbl)
2492 break;
2494 i++;
2495 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2498 if (tempbl == 0xFF) {
2499 pVBInfo->LCDResInfo = Panel1024x768;
2500 pVBInfo->LCDTypeInfo = 0;
2501 i = 0;
2504 return i;
2507 static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2508 unsigned short *VSyncWidth,
2509 struct vb_device_info *pVBInfo)
2511 unsigned short Index;
2513 Index = XGI_GetLCDCapPtr(pVBInfo);
2514 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2515 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2517 return;
2520 static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2521 unsigned short RefreshRateTableIndex,
2522 struct vb_device_info *pVBInfo)
2524 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2525 unsigned long temp, temp1, temp2, temp3, push3;
2526 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2527 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
2529 if (ModeNo > 0x13)
2530 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2531 else
2532 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2534 tempbx = 3;
2535 if (pVBInfo->LCDInfo & EnableScalingLCD)
2536 LCDPtr1 =
2537 (struct XGI330_LCDDataDesStruct2 *)
2538 XGI_GetLcdPtr(
2539 tempbx,
2540 ModeNo,
2541 ModeIdIndex,
2542 RefreshRateTableIndex,
2543 pVBInfo);
2544 else
2545 LCDPtr =
2546 (struct XGI330_LCDDataDesStruct *)
2547 XGI_GetLcdPtr(
2548 tempbx,
2549 ModeNo,
2550 ModeIdIndex,
2551 RefreshRateTableIndex,
2552 pVBInfo);
2554 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2555 push1 = tempbx;
2556 push2 = tempax;
2558 /* GetLCDResInfo */
2559 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2560 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2561 tempax = 1024;
2562 tempbx = 768;
2563 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2564 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2565 tempax = 1280;
2566 tempbx = 1024;
2567 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2568 tempax = 1400;
2569 tempbx = 1050;
2570 } else {
2571 tempax = 1600;
2572 tempbx = 1200;
2575 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2576 pVBInfo->HDE = tempax;
2577 pVBInfo->VDE = tempbx;
2578 pVBInfo->VGAHDE = tempax;
2579 pVBInfo->VGAVDE = tempbx;
2582 tempax = pVBInfo->HT;
2584 if (pVBInfo->LCDInfo & EnableScalingLCD)
2585 tempbx = LCDPtr1->LCDHDES;
2586 else
2587 tempbx = LCDPtr->LCDHDES;
2589 tempcx = pVBInfo->HDE;
2590 tempbx = tempbx & 0x0fff;
2591 tempcx += tempbx;
2593 if (tempcx >= tempax)
2594 tempcx -= tempax;
2596 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
2598 tempcx = tempcx >> 3;
2599 tempbx = tempbx >> 3;
2601 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2602 (unsigned short) (tempbx & 0xff));
2603 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2604 (unsigned short) (tempcx & 0xff));
2606 tempax = pVBInfo->HT;
2608 if (pVBInfo->LCDInfo & EnableScalingLCD)
2609 tempbx = LCDPtr1->LCDHRS;
2610 else
2611 tempbx = LCDPtr->LCDHRS;
2613 tempcx = push2;
2615 if (pVBInfo->LCDInfo & EnableScalingLCD)
2616 tempcx = LCDPtr1->LCDHSync;
2618 tempcx += tempbx;
2620 if (tempcx >= tempax)
2621 tempcx -= tempax;
2623 tempax = tempbx & 0x07;
2624 tempax = tempax >> 5;
2625 tempcx = tempcx >> 3;
2626 tempbx = tempbx >> 3;
2628 tempcx &= 0x1f;
2629 tempax |= tempcx;
2631 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2632 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2633 (unsigned short) (tempbx & 0xff));
2635 tempax = pVBInfo->VT;
2636 if (pVBInfo->LCDInfo & EnableScalingLCD)
2637 tempbx = LCDPtr1->LCDVDES;
2638 else
2639 tempbx = LCDPtr->LCDVDES;
2640 tempcx = pVBInfo->VDE;
2642 tempbx = tempbx & 0x0fff;
2643 tempcx += tempbx;
2644 if (tempcx >= tempax)
2645 tempcx -= tempax;
2647 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2648 (unsigned short) (tempbx & 0xff));
2649 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2650 (unsigned short) (tempcx & 0xff));
2652 tempbx = (tempbx >> 8) & 0x07;
2653 tempcx = (tempcx >> 8) & 0x07;
2655 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2656 (unsigned short) ((tempcx << 3)
2657 | tempbx));
2659 tempax = pVBInfo->VT;
2660 if (pVBInfo->LCDInfo & EnableScalingLCD)
2661 tempbx = LCDPtr1->LCDVRS;
2662 else
2663 tempbx = LCDPtr->LCDVRS;
2665 tempcx = push1;
2667 if (pVBInfo->LCDInfo & EnableScalingLCD)
2668 tempcx = LCDPtr1->LCDVSync;
2670 tempcx += tempbx;
2671 if (tempcx >= tempax)
2672 tempcx -= tempax;
2674 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2675 (unsigned short) (tempbx & 0xff));
2676 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2677 (unsigned short) (tempcx & 0x0f));
2679 tempax = ((tempbx >> 8) & 0x07) << 3;
2681 tempbx = pVBInfo->VGAVDE;
2682 if (tempbx != pVBInfo->VDE)
2683 tempax |= 0x40;
2685 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2686 tempax |= 0x40;
2688 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2689 tempax);
2691 tempcx = pVBInfo->VGAVT;
2692 tempbx = pVBInfo->VDE;
2693 tempax = pVBInfo->VGAVDE;
2694 tempcx -= tempax;
2696 temp = tempax; /* 0430 ylshieh */
2697 temp1 = (temp << 18) / tempbx;
2699 tempdx = (unsigned short) ((temp << 18) % tempbx);
2701 if (tempdx != 0)
2702 temp1 += 1;
2704 temp2 = temp1;
2705 push3 = temp2;
2707 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2708 (unsigned short) (temp2 & 0xff));
2709 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2710 (unsigned short) ((temp2 >> 8) & 0xff));
2712 tempbx = (unsigned short) (temp2 >> 16);
2713 tempax = tempbx & 0x03;
2715 tempbx = pVBInfo->VGAVDE;
2716 if (tempbx == pVBInfo->VDE)
2717 tempax |= 0x04;
2719 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2721 if (pVBInfo->VBType & VB_XGI301C) {
2722 temp2 = push3;
2723 xgifb_reg_set(pVBInfo->Part4Port,
2724 0x3c,
2725 (unsigned short) (temp2 & 0xff));
2726 xgifb_reg_set(pVBInfo->Part4Port,
2727 0x3b,
2728 (unsigned short) ((temp2 >> 8) &
2729 0xff));
2730 tempbx = (unsigned short) (temp2 >> 16);
2731 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2732 ~0xc0,
2733 (unsigned short) ((tempbx &
2734 0xff) << 6));
2736 tempcx = pVBInfo->VGAVDE;
2737 if (tempcx == pVBInfo->VDE)
2738 xgifb_reg_and_or(pVBInfo->Part4Port,
2739 0x30, ~0x0c, 0x00);
2740 else
2741 xgifb_reg_and_or(pVBInfo->Part4Port,
2742 0x30, ~0x0c, 0x08);
2745 tempcx = pVBInfo->VGAHDE;
2746 tempbx = pVBInfo->HDE;
2748 temp1 = tempcx << 16;
2750 tempax = (unsigned short) (temp1 / tempbx);
2752 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2753 tempax = 65535;
2755 temp3 = tempax;
2756 temp1 = pVBInfo->VGAHDE << 16;
2758 temp1 /= temp3;
2759 temp3 = temp3 << 16;
2760 temp1 -= 1;
2762 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2764 tempax = (unsigned short) (temp3 & 0xff);
2765 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2767 temp1 = pVBInfo->VGAVDE << 18;
2768 temp1 = temp1 / push3;
2769 tempbx = (unsigned short) (temp1 & 0xffff);
2771 if (pVBInfo->LCDResInfo == Panel1024x768)
2772 tempbx -= 1;
2774 tempax = ((tempbx >> 8) & 0xff) << 3;
2775 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2776 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2777 (unsigned short) (tempax & 0xff));
2778 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2779 (unsigned short) (tempbx & 0xff));
2781 temp3 = temp3 >> 16;
2783 if (modeflag & HalfDCLK)
2784 temp3 = temp3 >> 1;
2786 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2787 (unsigned short) ((temp3 >> 8) & 0xff));
2788 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2789 (unsigned short) (temp3 & 0xff));
2792 /* --------------------------------------------------------------------- */
2793 /* Function : XGI_GETLCDVCLKPtr */
2794 /* Input : */
2795 /* Output : al -> VCLK Index */
2796 /* Description : */
2797 /* --------------------------------------------------------------------- */
2798 static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2799 struct vb_device_info *pVBInfo)
2801 unsigned short index;
2803 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2804 index = XGI_GetLCDCapPtr1(pVBInfo);
2806 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2807 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2808 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2809 } else { /* LCDA */
2810 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2811 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2814 return;
2817 static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2818 unsigned short ModeNo, unsigned short ModeIdIndex,
2819 struct vb_device_info *pVBInfo)
2822 unsigned short index, modeflag;
2823 unsigned char tempal;
2825 if (ModeNo <= 0x13)
2826 /* si+St_ResInfo */
2827 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2828 else
2829 /* si+Ext_ResInfo */
2830 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2832 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2833 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
2834 index = XGI_GetLCDCapPtr(pVBInfo);
2835 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2837 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
2838 return tempal;
2840 /* {TV} */
2841 if (pVBInfo->VBType &
2842 (VB_XGI301B |
2843 VB_XGI302B |
2844 VB_XGI301LV |
2845 VB_XGI302LV |
2846 VB_XGI301C)) {
2847 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2848 tempal = HiTVVCLKDIV2;
2849 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2850 tempal = HiTVVCLK;
2851 if (pVBInfo->TVInfo & TVSimuMode) {
2852 tempal = HiTVSimuVCLK;
2853 if (!(modeflag & Charx8Dot))
2854 tempal = HiTVTextVCLK;
2857 return tempal;
2860 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
2861 tempal = YPbPr750pVCLK;
2862 return tempal;
2865 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
2866 tempal = YPbPr525pVCLK;
2867 return tempal;
2870 tempal = NTSC1024VCLK;
2872 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
2873 tempal = TVVCLKDIV2;
2874 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2875 tempal = TVVCLK;
2878 if (pVBInfo->VBInfo & SetCRT2ToTV)
2879 return tempal;
2881 } /* {End of VB} */
2883 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
2884 tempal = tempal >> 2;
2885 tempal &= 0x03;
2887 /* for Dot8 Scaling LCD */
2888 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
2889 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2891 if (ModeNo <= 0x13)
2892 return tempal;
2894 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2895 return tempal;
2898 static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2899 unsigned char *di_1, struct vb_device_info *pVBInfo)
2901 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
2902 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
2903 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
2904 & ProgrammingCRT2)) {
2905 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
2906 *di_1 = XGI_VBVCLKData[tempal].SR2C;
2908 } else {
2909 *di_0 = XGI_VCLKData[tempal].SR2B;
2910 *di_1 = XGI_VCLKData[tempal].SR2C;
2914 static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
2915 unsigned short RefreshRateTableIndex,
2916 struct vb_device_info *pVBInfo)
2918 unsigned char di_0, di_1, tempal;
2919 int i;
2921 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2922 pVBInfo);
2923 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2924 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
2926 for (i = 0; i < 4; i++) {
2927 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
2928 (unsigned short) (0x10 * i));
2929 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
2930 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
2931 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
2932 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
2933 } else {
2934 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
2935 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
2940 static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
2941 struct vb_device_info *pVBInfo)
2943 unsigned short tempcl, tempch, temp, tempbl, tempax;
2945 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
2946 | VB_XGI302LV | VB_XGI301C)) {
2947 tempcl = 0;
2948 tempch = 0;
2949 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
2951 if (!(temp & 0x20)) {
2952 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
2953 if (temp & 0x80) {
2954 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
2955 if (!(temp & 0x40))
2956 tempcl |= ActiveCRT1;
2960 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
2961 temp &= 0x0f;
2963 if (!(temp == 0x08)) {
2964 /* Check ChannelA by Part1_13 [2003/10/03] */
2965 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
2966 if (tempax & 0x04)
2967 tempcl = tempcl | ActiveLCD;
2969 temp &= 0x05;
2971 if (!(tempcl & ActiveLCD))
2972 if (temp == 0x01)
2973 tempcl |= ActiveCRT2;
2975 if (temp == 0x04)
2976 tempcl |= ActiveLCD;
2978 if (temp == 0x05) {
2979 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
2981 if (!(temp & 0x08))
2982 tempch |= ActiveAVideo;
2984 if (!(temp & 0x04))
2985 tempch |= ActiveSVideo;
2987 if (temp & 0x02)
2988 tempch |= ActiveSCART;
2990 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2991 if (temp & 0x01)
2992 tempch |= ActiveHiTV;
2995 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
2996 temp = xgifb_reg_get(
2997 pVBInfo->Part2Port,
2998 0x4d);
3000 if (temp & 0x10)
3001 tempch |= ActiveYPbPr;
3004 if (tempch != 0)
3005 tempcl |= ActiveTV;
3009 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
3010 if (tempcl & ActiveLCD) {
3011 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3012 if (temp & ActiveTV)
3013 tempcl |= ActiveTV;
3016 temp = tempcl;
3017 tempbl = ~ModeSwitchStatus;
3018 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
3020 if (!(pVBInfo->SetFlag & ReserveTVOption))
3021 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
3022 } else {
3023 return;
3027 void XGI_GetVBType(struct vb_device_info *pVBInfo)
3029 unsigned short flag, tempbx, tempah;
3031 if (pVBInfo->IF_DEF_LVDS == 0) {
3032 tempbx = VB_XGI302B;
3033 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
3034 if (flag != 0x02) {
3035 tempbx = VB_XGI301;
3036 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
3037 if (flag >= 0xB0) {
3038 tempbx = VB_XGI301B;
3039 if (flag >= 0xC0) {
3040 tempbx = VB_XGI301C;
3041 if (flag >= 0xD0) {
3042 tempbx = VB_XGI301LV;
3043 if (flag >= 0xE0) {
3044 tempbx = VB_XGI302LV;
3045 tempah = xgifb_reg_get(
3046 pVBInfo->Part4Port,
3047 0x39);
3048 if (tempah != 0xFF)
3049 tempbx =
3050 VB_XGI301C;
3055 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
3056 flag = xgifb_reg_get(
3057 pVBInfo->Part4Port,
3058 0x23);
3060 if (!(flag & 0x02))
3061 tempbx = tempbx | VB_NoLCD;
3065 pVBInfo->VBType = tempbx;
3069 static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3070 struct xgi_hw_device_info *HwDeviceExtension,
3071 struct vb_device_info *pVBInfo)
3073 unsigned short tempax, push, tempbx, temp, modeflag;
3075 if (ModeNo <= 0x13)
3076 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3077 else
3078 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3080 pVBInfo->SetFlag = 0;
3081 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3082 tempbx = 0;
3084 if (pVBInfo->VBType & 0xFFFF) {
3085 /* Check Display Device */
3086 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
3087 tempbx = tempbx | temp;
3088 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
3089 push = temp;
3090 push = push << 8;
3091 tempax = temp << 8;
3092 tempbx = tempbx | tempax;
3093 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3094 | SetInSlaveMode | DisableCRT2Display);
3095 temp = 0xFFFF ^ temp;
3096 tempbx &= temp;
3098 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3100 if (pVBInfo->IF_DEF_LCDA == 1) {
3102 if ((HwDeviceExtension->jChipType >= XG20) ||
3103 (HwDeviceExtension->jChipType >= XG40)) {
3104 if (pVBInfo->IF_DEF_LVDS == 0) {
3105 if (pVBInfo->VBType &
3106 (VB_XGI302B |
3107 VB_XGI301LV |
3108 VB_XGI302LV |
3109 VB_XGI301C)) {
3110 if (temp & EnableDualEdge) {
3111 tempbx |=
3112 SetCRT2ToDualEdge;
3114 if (temp & SetToLCDA)
3115 tempbx |=
3116 SetCRT2ToLCDA;
3123 if (pVBInfo->IF_DEF_YPbPr == 1) {
3124 /* [Billy] 07/05/04 */
3125 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3126 ((pVBInfo->VBType & VB_XGI301LV) ||
3127 (pVBInfo->VBType & VB_XGI302LV) ||
3128 (pVBInfo->VBType & VB_XGI301C)))) {
3129 if (temp & SetYPbPr) {
3130 if (pVBInfo->IF_DEF_HiVision == 1) {
3131 /* shampoo add for new
3132 * scratch */
3133 temp = xgifb_reg_get(
3134 pVBInfo->P3d4,
3135 0x35);
3136 temp &= YPbPrMode;
3137 tempbx |= SetCRT2ToHiVisionTV;
3139 if (temp != YPbPrMode1080i) {
3140 tempbx &=
3141 (~SetCRT2ToHiVisionTV);
3142 tempbx |=
3143 SetCRT2ToYPbPr;
3150 tempax = push; /* restore CR31 */
3152 if (pVBInfo->IF_DEF_LVDS == 0) {
3153 if (pVBInfo->IF_DEF_YPbPr == 1) {
3154 if (pVBInfo->IF_DEF_HiVision == 1)
3155 temp = 0x09FC;
3156 else
3157 temp = 0x097C;
3158 } else {
3159 if (pVBInfo->IF_DEF_HiVision == 1)
3160 temp = 0x01FC;
3161 else
3162 temp = 0x017C;
3164 } else { /* 3nd party chip */
3165 temp = SetCRT2ToLCD;
3168 if (!(tempbx & temp)) {
3169 tempax |= DisableCRT2Display;
3170 tempbx = 0;
3173 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3174 if (!(pVBInfo->VBType & VB_NoLCD)) {
3175 if (tempbx & SetCRT2ToLCDA) {
3176 if (tempbx & SetSimuScanMode)
3177 tempbx &= (~(SetCRT2ToLCD |
3178 SetCRT2ToRAMDAC |
3179 SwitchToCRT2));
3180 else
3181 tempbx &= (~(SetCRT2ToLCD |
3182 SetCRT2ToRAMDAC |
3183 SetCRT2ToTV |
3184 SwitchToCRT2));
3189 /* shampoo add */
3190 /* for driver abnormal */
3191 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
3192 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3193 if (tempbx & SetCRT2ToRAMDAC) {
3194 tempbx &= (0xFF00 |
3195 SetCRT2ToRAMDAC |
3196 SwitchToCRT2 |
3197 SetSimuScanMode);
3198 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3200 } else {
3201 tempbx &= (~(SetCRT2ToRAMDAC |
3202 SetCRT2ToLCD |
3203 SetCRT2ToTV));
3207 if (!(pVBInfo->VBType & VB_NoLCD)) {
3208 if (tempbx & SetCRT2ToLCD) {
3209 tempbx &= (0xFF00 |
3210 SetCRT2ToLCD |
3211 SwitchToCRT2 |
3212 SetSimuScanMode);
3213 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3217 if (tempbx & SetCRT2ToSCART) {
3218 tempbx &= (0xFF00 |
3219 SetCRT2ToSCART |
3220 SwitchToCRT2 |
3221 SetSimuScanMode);
3222 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3225 if (pVBInfo->IF_DEF_YPbPr == 1) {
3226 if (tempbx & SetCRT2ToYPbPr)
3227 tempbx &= (0xFF00 |
3228 SwitchToCRT2 |
3229 SetSimuScanMode);
3232 if (pVBInfo->IF_DEF_HiVision == 1) {
3233 if (tempbx & SetCRT2ToHiVisionTV)
3234 tempbx &= (0xFF00 |
3235 SetCRT2ToHiVisionTV |
3236 SwitchToCRT2 |
3237 SetSimuScanMode);
3240 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3241 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3242 tempbx = DisableCRT2Display;
3245 if (!(tempbx & DisableCRT2Display)) {
3246 if ((!(tempbx & DriverMode)) ||
3247 (!(modeflag & CRT2Mode))) {
3248 if (pVBInfo->IF_DEF_LCDA == 1) {
3249 if (!(tempbx & SetCRT2ToLCDA))
3250 tempbx |= (SetInSlaveMode |
3251 SetSimuScanMode);
3255 /* LCD+TV can't support in slave mode
3256 * (Force LCDA+TV->LCDB) */
3257 if ((tempbx & SetInSlaveMode) &&
3258 (tempbx & SetCRT2ToLCDA)) {
3259 tempbx ^= (SetCRT2ToLCD |
3260 SetCRT2ToLCDA |
3261 SetCRT2ToDualEdge);
3262 pVBInfo->SetFlag |= ReserveTVOption;
3267 pVBInfo->VBInfo = tempbx;
3270 static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3271 struct vb_device_info *pVBInfo)
3273 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
3275 tempbx = 0;
3276 resinfo = 0;
3278 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3279 if (ModeNo <= 0x13) {
3280 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3281 St_ModeFlag; /* si+St_ModeFlag */
3282 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3283 St_ResInfo; /* si+St_ResInfo */
3284 } else {
3285 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3286 Ext_ModeFlag;
3287 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3288 Ext_RESINFO; /* si+Ext_ResInfo */
3291 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3292 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
3293 tempbx = temp;
3294 if (tempbx & SetPALTV) {
3295 tempbx &= (SetCHTVOverScan |
3296 SetPALMTV |
3297 SetPALNTV |
3298 SetPALTV);
3299 if (tempbx & SetPALMTV)
3300 /* set to NTSC if PAL-M */
3301 tempbx &= ~SetPALTV;
3302 } else
3303 tempbx &= (SetCHTVOverScan |
3304 SetNTSCJ |
3305 SetPALTV);
3308 if (pVBInfo->IF_DEF_LVDS == 0) {
3309 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3310 tempbx |= SetPALTV;
3313 if (pVBInfo->IF_DEF_YPbPr == 1) {
3314 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
3315 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
3316 index1 &= YPbPrMode;
3318 if (index1 == YPbPrMode525i)
3319 tempbx |= SetYPbPrMode525i;
3321 if (index1 == YPbPrMode525p)
3322 tempbx = tempbx | SetYPbPrMode525p;
3323 if (index1 == YPbPrMode750p)
3324 tempbx = tempbx | SetYPbPrMode750p;
3328 if (pVBInfo->IF_DEF_HiVision == 1) {
3329 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3330 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3333 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3334 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3335 (!(pVBInfo->VBInfo & SetNotSimuMode)))
3336 tempbx |= TVSimuMode;
3338 if (!(tempbx & SetPALTV) &&
3339 (modeflag > 13) &&
3340 (resinfo == 8)) /* NTSC 1024x768, */
3341 tempbx |= NTSC1024x768;
3343 tempbx |= RPLLDIV2XO;
3345 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3346 if (pVBInfo->VBInfo & SetInSlaveMode)
3347 tempbx &= (~RPLLDIV2XO);
3348 } else {
3349 if (tempbx &
3350 (SetYPbPrMode525p | SetYPbPrMode750p))
3351 tempbx &= (~RPLLDIV2XO);
3352 else if (!(pVBInfo->VBType &
3353 (VB_XGI301B |
3354 VB_XGI302B |
3355 VB_XGI301LV |
3356 VB_XGI302LV |
3357 VB_XGI301C))) {
3358 if (tempbx & TVSimuMode)
3359 tempbx &= (~RPLLDIV2XO);
3364 pVBInfo->TVInfo = tempbx;
3367 static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
3368 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
3370 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
3372 pVBInfo->LCDResInfo = 0;
3373 pVBInfo->LCDTypeInfo = 0;
3374 pVBInfo->LCDInfo = 0;
3376 if (ModeNo <= 0x13) {
3377 /* si+St_ModeFlag // */
3378 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3379 } else {
3380 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3381 /* si+Ext_ResInfo // */
3382 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3385 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
3386 tempbx = temp & 0x0F;
3388 if (tempbx == 0)
3389 tempbx = Panel1024x768; /* default */
3391 /* LCD75 [2003/8/22] Vicent */
3392 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3393 if (pVBInfo->VBInfo & DriverMode) {
3394 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
3395 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3396 tempax &= 0x0F;
3397 else
3398 tempax = tempax >> 4;
3400 if ((resinfo == 6) || (resinfo == 9)) {
3401 if (tempax >= 3)
3402 tempbx |= PanelRef75Hz;
3403 } else if ((resinfo == 7) || (resinfo == 8)) {
3404 if (tempax >= 4)
3405 tempbx |= PanelRef75Hz;
3410 pVBInfo->LCDResInfo = tempbx;
3412 /* End of LCD75 */
3414 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3415 return 0;
3417 tempbx = 0;
3419 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
3421 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
3423 tempbx |= temp;
3425 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
3427 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
3429 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3430 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3431 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3432 tempbx |= SetLCDDualLink;
3436 if (pVBInfo->IF_DEF_LVDS == 0) {
3437 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3438 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3439 == 9) && (!(tempbx & EnableScalingLCD)))
3440 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3441 tempbx |= SetLCDtoNonExpanding;
3444 if (pVBInfo->IF_DEF_ExpLink == 1) {
3445 if (modeflag & HalfDCLK) {
3446 if (!(tempbx & SetLCDtoNonExpanding)) {
3447 tempbx |= EnableLVDSDDA;
3448 } else {
3449 if (ModeNo > 0x13) {
3450 if (pVBInfo->LCDResInfo
3451 == Panel1024x768) {
3452 if (resinfo == 4) {/* 512x384 */
3453 tempbx |= EnableLVDSDDA;
3461 if (pVBInfo->VBInfo & SetInSlaveMode) {
3462 if (pVBInfo->VBInfo & SetNotSimuMode)
3463 tempbx |= LCDVESATiming;
3464 } else {
3465 tempbx |= LCDVESATiming;
3468 pVBInfo->LCDInfo = tempbx;
3470 if (pVBInfo->IF_DEF_LVDS == 0) {
3471 if (tempax & (LockLCDBToA | StLCDBToA)) {
3472 if (pVBInfo->VBInfo & SetInSlaveMode) {
3473 if (!(tempax & LockLCDBToA)) {
3474 if (ModeNo <= 0x13) {
3475 pVBInfo->VBInfo &=
3476 ~(SetSimuScanMode |
3477 SetInSlaveMode |
3478 SetCRT2ToLCD);
3479 pVBInfo->VBInfo |=
3480 SetCRT2ToLCDA |
3481 SetCRT2ToDualEdge;
3488 return 1;
3491 unsigned char XGI_SearchModeID(unsigned short ModeNo,
3492 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
3494 if (ModeNo <= 5)
3495 ModeNo |= 1;
3496 if (ModeNo <= 0x13) {
3497 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3498 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3499 ModeNo)
3500 break;
3501 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3502 0xFF)
3503 return 0;
3506 if (ModeNo == 0x07)
3507 (*ModeIdIndex)++; /* 400 lines */
3508 if (ModeNo <= 3)
3509 (*ModeIdIndex) += 2; /* 400 lines */
3510 /* else 350 lines */
3511 } else {
3512 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3513 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3514 ModeNo)
3515 break;
3516 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3517 0xFF)
3518 return 0;
3522 return 1;
3525 static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3527 unsigned char ujRet = 0;
3528 unsigned char i = 0;
3530 for (i = 0; i < 8; i++) {
3531 ujRet = ujRet << 1;
3532 ujRet |= (ujDate >> i) & 1;
3535 return ujRet;
3538 /*----------------------------------------------------------------------------*/
3539 /* output */
3540 /* bl[5] : LVDS signal */
3541 /* bl[1] : LVDS backlight */
3542 /* bl[0] : LVDS VDD */
3543 /*----------------------------------------------------------------------------*/
3544 static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3546 unsigned char CR4A, temp;
3548 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3549 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
3551 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3553 temp = XG21GPIODataTransfer(temp);
3554 temp &= 0x23;
3555 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3556 return temp;
3559 /*----------------------------------------------------------------------------*/
3560 /* output */
3561 /* bl[5] : LVDS signal */
3562 /* bl[1] : LVDS backlight */
3563 /* bl[0] : LVDS VDD */
3564 /*----------------------------------------------------------------------------*/
3565 static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3567 unsigned char CR4A, CRB4, temp;
3569 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3570 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
3572 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3574 temp &= 0x0C;
3575 temp >>= 2;
3576 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3577 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
3578 temp |= ((CRB4 & 0x04) << 3);
3579 return temp;
3582 /*----------------------------------------------------------------------------*/
3583 /* input */
3584 /* bl[5] : 1;LVDS signal on */
3585 /* bl[1] : 1;LVDS backlight on */
3586 /* bl[0] : 1:LVDS VDD on */
3587 /* bh: 100000b : clear bit 5, to set bit5 */
3588 /* 000010b : clear bit 1, to set bit1 */
3589 /* 000001b : clear bit 0, to set bit0 */
3590 /*----------------------------------------------------------------------------*/
3591 static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3592 struct vb_device_info *pVBInfo)
3594 unsigned char CR4A, temp;
3596 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3597 tempbh &= 0x23;
3598 tempbl &= 0x23;
3599 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3601 if (tempbh & 0x20) {
3602 temp = (tempbl >> 4) & 0x02;
3604 /* CR B4[1] */
3605 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3609 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3611 temp = XG21GPIODataTransfer(temp);
3612 temp &= ~tempbh;
3613 temp |= tempbl;
3614 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
3617 static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3618 struct vb_device_info *pVBInfo)
3620 unsigned char CR4A, temp;
3621 unsigned short tempbh0, tempbl0;
3623 tempbh0 = tempbh;
3624 tempbl0 = tempbl;
3625 tempbh0 &= 0x20;
3626 tempbl0 &= 0x20;
3627 tempbh0 >>= 3;
3628 tempbl0 >>= 3;
3630 if (tempbh & 0x20) {
3631 temp = (tempbl >> 4) & 0x02;
3633 /* CR B4[1] */
3634 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3637 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
3639 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3640 tempbh &= 0x03;
3641 tempbl &= 0x03;
3642 tempbh <<= 2;
3643 tempbl <<= 2; /* GPIOC,GPIOD */
3644 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3645 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
3648 /* --------------------------------------------------------------------- */
3649 /* Function : XGI_XG21SetPanelDelay */
3650 /* Input : */
3651 /* Output : */
3652 /* Description : */
3653 /* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
3654 /* : bl : 2 ; T2 : the duration signal on and Vdd on */
3655 /* : bl : 3 ; T3 : the duration between CPL off and signal off */
3656 /* : bl : 4 ; T4 : the duration signal off and Vdd off */
3657 /* --------------------------------------------------------------------- */
3658 static void XGI_XG21SetPanelDelay(struct xgifb_video_info *xgifb_info,
3659 unsigned short tempbl,
3660 struct vb_device_info *pVBInfo)
3662 if (tempbl == 1)
3663 mdelay(xgifb_info->lvds_data.PSC_S1);
3665 if (tempbl == 2)
3666 mdelay(xgifb_info->lvds_data.PSC_S2);
3668 if (tempbl == 3)
3669 mdelay(xgifb_info->lvds_data.PSC_S3);
3671 if (tempbl == 4)
3672 mdelay(xgifb_info->lvds_data.PSC_S4);
3675 static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
3676 struct xgi_hw_device_info *pXGIHWDE,
3677 struct vb_device_info *pVBInfo)
3680 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
3681 if (pXGIHWDE->jChipType == XG21) {
3682 if (pVBInfo->IF_DEF_LVDS == 1) {
3683 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
3684 /* LVDS VDD on */
3685 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
3686 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
3688 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
3689 /* LVDS signal on */
3690 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3691 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
3692 /* LVDS backlight on */
3693 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
3694 } else {
3695 /* DVO/DVI signal on */
3696 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3701 if (pXGIHWDE->jChipType == XG27) {
3702 if (pVBInfo->IF_DEF_LVDS == 1) {
3703 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
3704 /* LVDS VDD on */
3705 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
3706 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
3708 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
3709 /* LVDS signal on */
3710 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3711 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
3712 /* LVDS backlight on */
3713 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
3714 } else {
3715 /* DVO/DVI signal on */
3716 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3722 void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
3723 struct xgi_hw_device_info *pXGIHWDE,
3724 struct vb_device_info *pVBInfo)
3727 if (pXGIHWDE->jChipType == XG21) {
3728 if (pVBInfo->IF_DEF_LVDS == 1) {
3729 /* LVDS backlight off */
3730 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
3731 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
3732 } else {
3733 /* DVO/DVI signal off */
3734 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
3738 if (pXGIHWDE->jChipType == XG27) {
3739 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
3740 /* LVDS backlight off */
3741 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
3742 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
3745 if (pVBInfo->IF_DEF_LVDS == 0)
3746 /* DVO/DVI signal off */
3747 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
3750 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
3753 static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
3755 while ((inb(pVBInfo->P3da) & 0x01))
3756 break;
3758 while (!(inb(pVBInfo->P3da) & 0x01))
3759 break;
3762 static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
3764 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
3767 static void XGI_SaveCRT2Info(unsigned short ModeNo,
3768 struct vb_device_info *pVBInfo)
3770 unsigned short temp1, temp2;
3772 /* reserve CR34 for CRT1 Mode No */
3773 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
3774 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3775 temp2 = ~(SetInSlaveMode >> 8);
3776 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
3779 static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3780 unsigned short ModeIdIndex,
3781 struct vb_device_info *pVBInfo)
3783 unsigned short xres, yres, modeflag, resindex;
3785 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
3786 if (ModeNo <= 0x13) {
3787 xres = pVBInfo->StResInfo[resindex].HTotal;
3788 yres = pVBInfo->StResInfo[resindex].VTotal;
3789 } else {
3790 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3791 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3792 /* si+St_ModeFlag */
3793 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3795 if (modeflag & HalfDCLK)
3796 xres *= 2;
3798 if (modeflag & DoubleScanMode)
3799 yres *= 2;
3802 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3803 if (pVBInfo->IF_DEF_LVDS == 0) {
3804 if (pVBInfo->LCDResInfo == Panel1600x1200) {
3805 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3806 if (yres == 1024)
3807 yres = 1056;
3811 if (pVBInfo->LCDResInfo == Panel1280x1024) {
3812 if (yres == 400)
3813 yres = 405;
3814 else if (yres == 350)
3815 yres = 360;
3817 if (pVBInfo->LCDInfo & LCDVESATiming) {
3818 if (yres == 360)
3819 yres = 375;
3823 if (pVBInfo->LCDResInfo == Panel1024x768) {
3824 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3825 if (!(pVBInfo->LCDInfo
3826 & LCDNonExpanding)) {
3827 if (yres == 350)
3828 yres = 357;
3829 else if (yres == 400)
3830 yres = 420;
3831 else if (yres == 480)
3832 yres = 525;
3838 if (xres == 720)
3839 xres = 640;
3842 pVBInfo->VGAHDE = xres;
3843 pVBInfo->HDE = xres;
3844 pVBInfo->VGAVDE = yres;
3845 pVBInfo->VDE = yres;
3848 static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
3851 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
3852 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
3853 return 1;
3855 return 0;
3858 static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3859 unsigned short ModeIdIndex,
3860 unsigned short RefreshRateTableIndex,
3861 struct vb_device_info *pVBInfo)
3863 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
3864 StandTableIndex, CRT1Index;
3866 pVBInfo->RVBHCMAX = 1;
3867 pVBInfo->RVBHCFACT = 1;
3869 if (ModeNo <= 0x13) {
3870 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3871 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
3872 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
3873 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
3874 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
3875 } else {
3876 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3877 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
3878 Ext_CRT1CRTC;
3879 CRT1Index &= IndexMask;
3880 temp1 = (unsigned short) pVBInfo->
3881 XGINEWUB_CRT1Table[CRT1Index].CR[0];
3882 temp2 = (unsigned short) pVBInfo->
3883 XGINEWUB_CRT1Table[CRT1Index].CR[5];
3884 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3885 tempbx = (unsigned short) pVBInfo->
3886 XGINEWUB_CRT1Table[CRT1Index].CR[8];
3887 tempcx = (unsigned short) pVBInfo->
3888 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3889 tempcx &= 0x0100;
3890 tempcx = tempcx << 2;
3891 tempbx |= tempcx;
3892 temp1 = (unsigned short) pVBInfo->
3893 XGINEWUB_CRT1Table[CRT1Index].CR[9];
3896 if (temp1 & 0x01)
3897 tempbx |= 0x0100;
3899 if (temp1 & 0x20)
3900 tempbx |= 0x0200;
3901 tempax += 5;
3903 if (modeflag & Charx8Dot)
3904 tempax *= 8;
3905 else
3906 tempax *= 9;
3908 pVBInfo->VGAHT = tempax;
3909 pVBInfo->HT = tempax;
3910 tempbx++;
3911 pVBInfo->VGAVT = tempbx;
3912 pVBInfo->VT = tempbx;
3915 static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
3916 unsigned short RefreshRateTableIndex,
3917 struct vb_device_info *pVBInfo)
3919 unsigned short tempax = 0, tempbx, modeflag, resinfo;
3921 struct XGI_LCDDataStruct *LCDPtr = NULL;
3922 struct XGI_TVDataStruct *TVPtr = NULL;
3924 if (ModeNo <= 0x13) {
3925 /* si+St_ResInfo */
3926 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3927 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
3928 } else {
3929 /* si+Ext_ResInfo */
3930 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3931 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3934 pVBInfo->NewFlickerMode = 0;
3935 pVBInfo->RVBHRS = 50;
3937 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3938 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3939 pVBInfo);
3940 return;
3943 tempbx = 4;
3945 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
3946 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
3947 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3948 pVBInfo);
3950 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
3951 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
3952 pVBInfo->VGAHT = LCDPtr->VGAHT;
3953 pVBInfo->VGAVT = LCDPtr->VGAVT;
3954 pVBInfo->HT = LCDPtr->LCDHT;
3955 pVBInfo->VT = LCDPtr->LCDVT;
3957 if (pVBInfo->LCDResInfo == Panel1024x768) {
3958 tempax = 1024;
3959 tempbx = 768;
3961 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3962 if (pVBInfo->VGAVDE == 357)
3963 tempbx = 527;
3964 else if (pVBInfo->VGAVDE == 420)
3965 tempbx = 620;
3966 else if (pVBInfo->VGAVDE == 525)
3967 tempbx = 775;
3968 else if (pVBInfo->VGAVDE == 600)
3969 tempbx = 775;
3970 else
3971 tempbx = 768;
3972 } else
3973 tempbx = 768;
3974 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
3975 tempax = 1024;
3976 tempbx = 768;
3977 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
3978 tempax = 1280;
3979 if (pVBInfo->VGAVDE == 360)
3980 tempbx = 768;
3981 else if (pVBInfo->VGAVDE == 375)
3982 tempbx = 800;
3983 else if (pVBInfo->VGAVDE == 405)
3984 tempbx = 864;
3985 else
3986 tempbx = 1024;
3987 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
3988 tempax = 1280;
3989 tempbx = 1024;
3990 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
3991 tempax = 1280;
3992 if (pVBInfo->VGAVDE == 350)
3993 tempbx = 700;
3994 else if (pVBInfo->VGAVDE == 400)
3995 tempbx = 800;
3996 else if (pVBInfo->VGAVDE == 1024)
3997 tempbx = 960;
3998 else
3999 tempbx = 960;
4000 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4001 tempax = 1400;
4002 tempbx = 1050;
4004 if (pVBInfo->VGAVDE == 1024) {
4005 tempax = 1280;
4006 tempbx = 1024;
4008 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4009 tempax = 1600;
4010 tempbx = 1200; /* alan 10/14/2003 */
4011 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4012 if (pVBInfo->VGAVDE == 350)
4013 tempbx = 875;
4014 else if (pVBInfo->VGAVDE == 400)
4015 tempbx = 1000;
4019 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4020 tempax = pVBInfo->VGAHDE;
4021 tempbx = pVBInfo->VGAVDE;
4024 pVBInfo->HDE = tempax;
4025 pVBInfo->VDE = tempbx;
4026 return;
4029 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4030 tempbx = 4;
4031 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4032 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4033 pVBInfo);
4035 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4036 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4037 pVBInfo->VGAHT = TVPtr->VGAHT;
4038 pVBInfo->VGAVT = TVPtr->VGAVT;
4039 pVBInfo->HDE = TVPtr->TVHDE;
4040 pVBInfo->VDE = TVPtr->TVVDE;
4041 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4042 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
4044 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4045 if (resinfo == 0x08)
4046 pVBInfo->NewFlickerMode = 0x40;
4047 else if (resinfo == 0x09)
4048 pVBInfo->NewFlickerMode = 0x40;
4049 else if (resinfo == 0x12)
4050 pVBInfo->NewFlickerMode = 0x40;
4052 if (pVBInfo->VGAVDE == 350)
4053 pVBInfo->TVInfo |= TVSimuMode;
4055 tempax = ExtHiTVHT;
4056 tempbx = ExtHiTVVT;
4058 if (pVBInfo->VBInfo & SetInSlaveMode) {
4059 if (pVBInfo->TVInfo & TVSimuMode) {
4060 tempax = StHiTVHT;
4061 tempbx = StHiTVVT;
4063 if (!(modeflag & Charx8Dot)) {
4064 tempax = StHiTextTVHT;
4065 tempbx = StHiTextTVVT;
4069 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4070 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4071 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4072 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4075 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4076 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4077 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4078 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4079 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4080 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4081 if (pVBInfo->TVInfo & NTSC1024x768)
4082 tempax = NTSC1024x768HT;
4084 } else {
4085 tempax = PALHT;
4086 tempbx = PALVT;
4087 if (!(pVBInfo->TVInfo & SetPALTV)) {
4088 tempax = NTSCHT;
4089 tempbx = NTSCVT;
4090 if (pVBInfo->TVInfo & NTSC1024x768)
4091 tempax = NTSC1024x768HT;
4095 pVBInfo->HT = tempax;
4096 pVBInfo->VT = tempbx;
4097 return;
4101 static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
4102 unsigned short RefreshRateTableIndex,
4103 struct vb_device_info *pVBInfo)
4105 unsigned char di_0, di_1, tempal;
4107 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4108 pVBInfo);
4109 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4110 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
4112 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4113 /* 301 */
4114 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4115 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4116 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4117 } else { /* 301b/302b/301lv/302lv */
4118 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4119 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4122 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
4124 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
4125 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
4126 else
4127 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
4130 static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4131 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
4133 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4134 short index;
4135 unsigned short modeflag;
4137 if (ModeNo <= 0x13)
4138 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4139 else
4140 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4142 index = (modeflag & ModeInfoFlag) - ModeEGA;
4144 if (index < 0)
4145 index = 0;
4147 return ColorDepth[index];
4150 static unsigned short XGI_GetOffset(unsigned short ModeNo,
4151 unsigned short ModeIdIndex,
4152 unsigned short RefreshRateTableIndex,
4153 struct xgi_hw_device_info *HwDeviceExtension,
4154 struct vb_device_info *pVBInfo)
4156 unsigned short temp, colordepth, modeinfo, index, infoflag,
4157 ColorDepth[] = { 0x01, 0x02, 0x04 };
4159 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4160 if (ModeNo <= 0x14)
4161 infoflag = 0;
4162 else
4163 infoflag = pVBInfo->
4164 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
4166 index = (modeinfo >> 8) & 0xFF;
4168 temp = pVBInfo->ScreenOffset[index];
4170 if (infoflag & InterlaceMode)
4171 temp = temp << 1;
4173 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4175 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4176 temp = ModeNo - 0x7C;
4177 colordepth = ColorDepth[temp];
4178 temp = 0x6B;
4179 if (infoflag & InterlaceMode)
4180 temp = temp << 1;
4181 return temp * colordepth;
4182 } else {
4183 return temp * colordepth;
4187 static void XGI_SetCRT2Offset(unsigned short ModeNo,
4188 unsigned short ModeIdIndex,
4189 unsigned short RefreshRateTableIndex,
4190 struct xgi_hw_device_info *HwDeviceExtension,
4191 struct vb_device_info *pVBInfo)
4193 unsigned short offset;
4194 unsigned char temp;
4196 if (pVBInfo->VBInfo & SetInSlaveMode)
4197 return;
4199 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4200 HwDeviceExtension, pVBInfo);
4201 temp = (unsigned char) (offset & 0xFF);
4202 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4203 temp = (unsigned char) ((offset & 0xFF00) >> 8);
4204 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
4205 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
4206 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
4209 static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
4211 /* threshold high ,disable auto threshold */
4212 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4213 /* threshold low default 04h */
4214 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
4217 static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4218 struct xgi_hw_device_info *HwDeviceExtension,
4219 unsigned short RefreshRateTableIndex,
4220 struct vb_device_info *pVBInfo)
4222 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
4224 if (ModeNo > 0x13) {
4225 CRT1Index = pVBInfo->
4226 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4227 CRT1Index &= IndexMask;
4228 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4231 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4232 HwDeviceExtension, pVBInfo);
4233 XGI_SetCRT2FIFO(pVBInfo);
4235 for (tempcx = 4; tempcx < 7; tempcx++)
4236 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
4238 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4239 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
4242 static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4243 struct xgi_hw_device_info *HwDeviceExtension,
4244 unsigned short RefreshRateTableIndex,
4245 struct vb_device_info *pVBInfo)
4247 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4248 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
4250 if (ModeNo > 0x13) {
4251 CRT1Index = pVBInfo->
4252 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4253 CRT1Index &= IndexMask;
4254 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4257 if (ModeNo <= 0x13)
4258 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4259 else
4260 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4262 /* bainy change table name */
4263 if (modeflag & HalfDCLK) {
4264 /* BTVGA2HT 0x08,0x09 */
4265 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
4266 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
4267 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
4268 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
4269 /* BTVGA2HDEE 0x0A,0x0C */
4270 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
4271 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
4272 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4273 pushbx = pVBInfo->VGAHDE / 2 + 16;
4274 tempcx = tempcx >> 1;
4275 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4276 tempcx += tempbx;
4278 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4279 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4280 tempbx |= ((pVBInfo->
4281 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4282 0xC0) << 2);
4283 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4284 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4285 tempcx &= 0x1F;
4286 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4287 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4288 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4291 tempbx += 4;
4292 tempcx += 4;
4294 if (tempcx > (pVBInfo->VGAHT / 2))
4295 tempcx = pVBInfo->VGAHT / 2;
4297 temp = tempbx & 0x00FF;
4299 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4300 } else {
4301 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
4302 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
4303 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
4304 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
4305 /* BTVGA2HDEE 0x0A,0x0C */
4306 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
4307 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
4308 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4309 pushbx = pVBInfo->VGAHDE + 16;
4310 tempcx = tempcx >> 1;
4311 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4312 tempcx += tempbx;
4314 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4315 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
4316 tempbx |= ((pVBInfo->
4317 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4318 0xC0) << 2);
4319 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4320 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4321 tempcx &= 0x1F;
4322 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4323 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4324 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4325 tempbx += 16;
4326 tempcx += 16;
4329 if (tempcx > pVBInfo->VGAHT)
4330 tempcx = pVBInfo->VGAHT;
4332 temp = tempbx & 0x00FF;
4333 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4336 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4337 tempbx = pushbx;
4338 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4339 tempax |= (tempbx & 0xFF00);
4340 temp = (tempax & 0xFF00) >> 8;
4341 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
4342 temp = tempcx & 0x00FF;
4343 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
4344 tempcx = (pVBInfo->VGAVT - 1);
4345 temp = tempcx & 0x00FF;
4347 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
4348 tempbx = pVBInfo->VGAVDE - 1;
4349 temp = tempbx & 0x00FF;
4350 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
4351 temp = ((tempbx & 0xFF00) << 3) >> 8;
4352 temp |= ((tempcx & 0xFF00) >> 8);
4353 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
4355 tempax = pVBInfo->VGAVDE;
4356 tempbx = pVBInfo->VGAVDE;
4357 tempcx = pVBInfo->VGAVT;
4358 /* BTVGA2VRS 0x10,0x11 */
4359 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4360 /* BTVGA2VRE 0x11 */
4361 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
4363 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4364 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4365 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
4367 if (temp & 0x04)
4368 tempbx |= 0x0100;
4370 if (temp & 0x080)
4371 tempbx |= 0x0200;
4373 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
4375 if (temp & 0x08)
4376 tempbx |= 0x0400;
4378 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4379 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4382 temp = tempbx & 0x00FF;
4383 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4384 temp = ((tempbx & 0xFF00) >> 8) << 4;
4385 temp = ((tempcx & 0x000F) | (temp));
4386 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
4387 tempax = 0;
4389 if (modeflag & DoubleScanMode)
4390 tempax |= 0x80;
4392 if (modeflag & HalfDCLK)
4393 tempax |= 0x40;
4395 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
4398 static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4400 unsigned long tempax, tempbx;
4402 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4403 & 0xFFFF;
4404 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4405 tempax = (tempax * pVBInfo->HT) / tempbx;
4407 return (unsigned short) tempax;
4410 static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4411 struct xgi_hw_device_info *HwDeviceExtension,
4412 unsigned short RefreshRateTableIndex,
4413 struct vb_device_info *pVBInfo)
4415 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4416 modeflag, CRT1Index;
4418 if (ModeNo <= 0x13) {
4419 /* si+St_ResInfo */
4420 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4421 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4422 } else {
4423 /* si+Ext_ResInfo */
4424 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4425 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4426 CRT1Index = pVBInfo->
4427 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4428 CRT1Index &= IndexMask;
4431 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4432 return;
4434 temp = 0xFF; /* set MAX HT */
4435 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
4436 tempcx = 0x08;
4438 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4439 modeflag |= Charx8Dot;
4441 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
4443 if (modeflag & HalfDCLK)
4444 tempax = tempax >> 1;
4446 tempax = (tempax / tempcx) - 1;
4447 tempbx |= ((tempax & 0x00FF) << 8);
4448 temp = tempax & 0x00FF;
4449 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
4451 temp = (tempbx & 0xFF00) >> 8;
4453 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4454 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4455 | VB_XGI302LV | VB_XGI301C)))
4456 temp += 2;
4458 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4459 if (pVBInfo->VBType & VB_XGI301LV) {
4460 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4461 if (resinfo == 7)
4462 temp -= 2;
4464 } else if (resinfo == 7) {
4465 temp -= 2;
4470 /* 0x05 Horizontal Display Start */
4471 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4472 /* 0x06 Horizontal Blank end */
4473 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
4475 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4476 if (pVBInfo->VBInfo & SetCRT2ToTV)
4477 tempax = pVBInfo->VGAHT;
4478 else
4479 tempax = XGI_GetVGAHT2(pVBInfo);
4482 if (tempax >= pVBInfo->VGAHT)
4483 tempax = pVBInfo->VGAHT;
4485 if (modeflag & HalfDCLK)
4486 tempax = tempax >> 1;
4488 tempax = (tempax / tempcx) - 5;
4489 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4490 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4491 temp = (tempbx & 0x00FF) - 1;
4492 if (!(modeflag & HalfDCLK)) {
4493 temp -= 6;
4494 if (pVBInfo->TVInfo & TVSimuMode) {
4495 temp -= 4;
4496 if (ModeNo > 0x13)
4497 temp -= 10;
4500 } else {
4501 tempbx = (tempbx & 0xFF00) >> 8;
4502 tempcx = (tempcx + tempbx) >> 1;
4503 temp = (tempcx & 0x00FF) + 2;
4505 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4506 temp -= 1;
4507 if (!(modeflag & HalfDCLK)) {
4508 if ((modeflag & Charx8Dot)) {
4509 temp += 4;
4510 if (pVBInfo->VGAHDE >= 800)
4511 temp -= 6;
4514 } else if (!(modeflag & HalfDCLK)) {
4515 temp -= 4;
4516 if (pVBInfo->LCDResInfo != Panel1280x960 &&
4517 pVBInfo->VGAHDE >= 800) {
4518 temp -= 7;
4519 if (pVBInfo->ModeType == ModeEGA &&
4520 pVBInfo->VGAVDE == 1024) {
4521 temp += 15;
4522 if (pVBInfo->LCDResInfo !=
4523 Panel1280x1024)
4524 temp += 7;
4527 if (pVBInfo->VGAHDE >= 1280 &&
4528 pVBInfo->LCDResInfo != Panel1280x960 &&
4529 (pVBInfo->LCDInfo & LCDNonExpanding))
4530 temp += 28;
4535 /* 0x07 Horizontal Retrace Start */
4536 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4537 /* 0x08 Horizontal Retrace End */
4538 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
4540 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4541 if (pVBInfo->TVInfo & TVSimuMode) {
4542 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4543 == 0x11) || (ModeNo == 0x13) || (ModeNo
4544 == 0x0F)) {
4545 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4546 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
4549 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4550 if (pVBInfo->TVInfo & SetNTSCTV) {
4551 xgifb_reg_set(pVBInfo->Part1Port,
4552 0x07, 0x2A);
4553 xgifb_reg_set(pVBInfo->Part1Port,
4554 0x08, 0x61);
4555 } else {
4556 xgifb_reg_set(pVBInfo->Part1Port,
4557 0x07, 0x2A);
4558 xgifb_reg_set(pVBInfo->Part1Port,
4559 0x08, 0x41);
4560 xgifb_reg_set(pVBInfo->Part1Port,
4561 0x0C, 0xF0);
4565 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4566 == 0x07)) {
4567 if (pVBInfo->TVInfo & SetNTSCTV) {
4568 xgifb_reg_set(pVBInfo->Part1Port,
4569 0x07, 0x54);
4570 xgifb_reg_set(pVBInfo->Part1Port,
4571 0x08, 0x00);
4572 } else {
4573 xgifb_reg_set(pVBInfo->Part1Port,
4574 0x07, 0x55);
4575 xgifb_reg_set(pVBInfo->Part1Port,
4576 0x08, 0x00);
4577 xgifb_reg_set(pVBInfo->Part1Port,
4578 0x0C, 0xF0);
4582 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4583 == 0x0D) || (ModeNo == 0x50)) {
4584 if (pVBInfo->TVInfo & SetNTSCTV) {
4585 xgifb_reg_set(pVBInfo->Part1Port,
4586 0x07, 0x30);
4587 xgifb_reg_set(pVBInfo->Part1Port,
4588 0x08, 0x03);
4589 } else {
4590 xgifb_reg_set(pVBInfo->Part1Port,
4591 0x07, 0x2f);
4592 xgifb_reg_set(pVBInfo->Part1Port,
4593 0x08, 0x02);
4599 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
4600 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
4601 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
4603 tempbx = pVBInfo->VGAVT;
4604 push1 = tempbx;
4605 tempcx = 0x121;
4606 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
4608 if (tempbx == 357)
4609 tempbx = 350;
4610 if (tempbx == 360)
4611 tempbx = 350;
4612 if (tempbx == 375)
4613 tempbx = 350;
4614 if (tempbx == 405)
4615 tempbx = 400;
4616 if (tempbx == 525)
4617 tempbx = 480;
4619 push2 = tempbx;
4621 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4622 if (pVBInfo->LCDResInfo == Panel1024x768) {
4623 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4624 if (tempbx == 350)
4625 tempbx += 5;
4626 if (tempbx == 480)
4627 tempbx += 5;
4631 tempbx--;
4632 temp = tempbx & 0x00FF;
4633 tempbx--;
4634 temp = tempbx & 0x00FF;
4635 /* 0x10 vertical Blank Start */
4636 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4637 tempbx = push2;
4638 tempbx--;
4639 temp = tempbx & 0x00FF;
4640 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
4642 if (tempbx & 0x0100)
4643 tempcx |= 0x0002;
4645 tempax = 0x000B;
4647 if (modeflag & DoubleScanMode)
4648 tempax |= 0x08000;
4650 if (tempbx & 0x0200)
4651 tempcx |= 0x0040;
4653 temp = (tempax & 0xFF00) >> 8;
4654 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4656 if (tempbx & 0x0400)
4657 tempcx |= 0x0600;
4659 /* 0x11 Vertival Blank End */
4660 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
4662 tempax = push1;
4663 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4664 tempax = tempax >> 2;
4665 push1 = tempax; /* push ax */
4667 if (resinfo != 0x09) {
4668 tempax = tempax << 1;
4669 tempbx += tempax;
4672 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4673 if (pVBInfo->VBType & VB_XGI301LV) {
4674 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
4675 tempbx -= 10;
4676 } else {
4677 if (pVBInfo->TVInfo & TVSimuMode) {
4678 if (pVBInfo->TVInfo & SetPALTV) {
4679 if (pVBInfo->VBType &
4680 VB_XGI301LV) {
4681 if (!(pVBInfo->TVInfo &
4682 (SetYPbPrMode525p |
4683 SetYPbPrMode750p |
4684 SetYPbPrMode1080i)))
4685 tempbx += 40;
4686 } else {
4687 tempbx += 40;
4692 } else {
4693 tempbx -= 10;
4695 } else {
4696 if (pVBInfo->TVInfo & TVSimuMode) {
4697 if (pVBInfo->TVInfo & SetPALTV) {
4698 if (pVBInfo->VBType & VB_XGI301LV) {
4699 if (!(pVBInfo->TVInfo &
4700 (SetYPbPrMode525p |
4701 SetYPbPrMode750p |
4702 SetYPbPrMode1080i)))
4703 tempbx += 40;
4704 } else {
4705 tempbx += 40;
4710 tempax = push1;
4711 tempax = tempax >> 2;
4712 tempax++;
4713 tempax += tempbx;
4714 push1 = tempax; /* push ax */
4716 if ((pVBInfo->TVInfo & SetPALTV)) {
4717 if (tempbx <= 513) {
4718 if (tempax >= 513)
4719 tempbx = 513;
4723 temp = tempbx & 0x00FF;
4724 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
4725 tempbx--;
4726 temp = tempbx & 0x00FF;
4727 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4729 if (tempbx & 0x0100)
4730 tempcx |= 0x0008;
4732 if (tempbx & 0x0200)
4733 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
4735 tempbx++;
4737 if (tempbx & 0x0100)
4738 tempcx |= 0x0004;
4740 if (tempbx & 0x0200)
4741 tempcx |= 0x0080;
4743 if (tempbx & 0x0400)
4744 tempcx |= 0x0C00;
4746 tempbx = push1; /* pop ax */
4747 temp = tempbx & 0x00FF;
4748 temp &= 0x0F;
4749 /* 0x0D vertical Retrace End */
4750 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
4752 if (tempbx & 0x0010)
4753 tempcx |= 0x2000;
4755 temp = tempcx & 0x00FF;
4756 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
4757 temp = (tempcx & 0x0FF00) >> 8;
4758 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
4759 tempax = modeflag;
4760 temp = (tempax & 0xFF00) >> 8;
4762 temp = (temp >> 1) & 0x09;
4764 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4765 temp |= 0x01;
4767 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4768 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4769 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
4771 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4772 temp = 0x80;
4773 else
4774 temp = 0x00;
4776 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
4778 return;
4781 static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
4782 unsigned short RefreshRateTableIndex,
4783 struct xgi_hw_device_info *HwDeviceExtension,
4784 struct vb_device_info *pVBInfo)
4786 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4787 modeflag, resinfo, crt2crtc;
4788 unsigned char *TimingPoint;
4790 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4792 if (ModeNo <= 0x13) {
4793 /* si+St_ResInfo */
4794 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4795 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4796 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4797 } else {
4798 /* si+Ext_ResInfo */
4799 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4800 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4801 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
4802 Ext_CRT2CRTC;
4805 tempax = 0;
4807 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4808 tempax |= 0x0800;
4810 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4811 tempax |= 0x0400;
4813 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4814 tempax |= 0x0200;
4816 if (!(pVBInfo->TVInfo & SetPALTV))
4817 tempax |= 0x1000;
4819 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4820 tempax |= 0x0100;
4822 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
4823 tempax &= 0xfe00;
4825 tempax = (tempax & 0xff00) >> 8;
4827 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
4828 TimingPoint = pVBInfo->NTSCTiming;
4830 if (pVBInfo->TVInfo & SetPALTV)
4831 TimingPoint = pVBInfo->PALTiming;
4833 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4834 TimingPoint = pVBInfo->HiTVExtTiming;
4836 if (pVBInfo->VBInfo & SetInSlaveMode)
4837 TimingPoint = pVBInfo->HiTVSt2Timing;
4839 if (pVBInfo->SetFlag & TVSimuMode)
4840 TimingPoint = pVBInfo->HiTVSt1Timing;
4842 if (!(modeflag & Charx8Dot))
4843 TimingPoint = pVBInfo->HiTVTextTiming;
4846 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4847 if (pVBInfo->TVInfo & SetYPbPrMode525i)
4848 TimingPoint = pVBInfo->YPbPr525iTiming;
4850 if (pVBInfo->TVInfo & SetYPbPrMode525p)
4851 TimingPoint = pVBInfo->YPbPr525pTiming;
4853 if (pVBInfo->TVInfo & SetYPbPrMode750p)
4854 TimingPoint = pVBInfo->YPbPr750pTiming;
4857 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
4858 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
4860 for (i = 0x39; i <= 0x45; i++, j++)
4861 /* di->temp2[j] */
4862 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
4864 if (pVBInfo->VBInfo & SetCRT2ToTV)
4865 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
4867 temp = pVBInfo->NewFlickerMode;
4868 temp &= 0x80;
4869 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
4871 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4872 tempax = 950;
4874 if (pVBInfo->TVInfo & SetPALTV)
4875 tempax = 520;
4876 else
4877 tempax = 440;
4879 if (pVBInfo->VDE <= tempax) {
4880 tempax -= pVBInfo->VDE;
4881 tempax = tempax >> 2;
4882 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4883 push1 = tempax;
4884 temp = (tempax & 0xFF00) >> 8;
4885 temp += (unsigned short) TimingPoint[0];
4887 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4888 | VB_XGI302LV | VB_XGI301C)) {
4889 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4890 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4891 | SetCRT2ToYPbPr)) {
4892 tempcx = pVBInfo->VGAHDE;
4893 if (tempcx >= 1024) {
4894 temp = 0x17; /* NTSC */
4895 if (pVBInfo->TVInfo & SetPALTV)
4896 temp = 0x19; /* PAL */
4901 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
4902 tempax = push1;
4903 temp = (tempax & 0xFF00) >> 8;
4904 temp += TimingPoint[1];
4906 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4907 | VB_XGI302LV | VB_XGI301C)) {
4908 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4909 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4910 | SetCRT2ToYPbPr))) {
4911 tempcx = pVBInfo->VGAHDE;
4912 if (tempcx >= 1024) {
4913 temp = 0x1D; /* NTSC */
4914 if (pVBInfo->TVInfo & SetPALTV)
4915 temp = 0x52; /* PAL */
4919 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
4922 /* 301b */
4923 tempcx = pVBInfo->HT;
4925 if (XGI_IsLCDDualLink(pVBInfo))
4926 tempcx = tempcx >> 1;
4928 tempcx -= 2;
4929 temp = tempcx & 0x00FF;
4930 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
4932 temp = (tempcx & 0xFF00) >> 8;
4933 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
4935 tempcx = pVBInfo->HT >> 1;
4936 push1 = tempcx; /* push cx */
4937 tempcx += 7;
4939 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4940 tempcx -= 4;
4942 temp = tempcx & 0x00FF;
4943 temp = temp << 4;
4944 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
4946 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4947 tempbx += tempcx;
4948 push2 = tempbx;
4949 temp = tempbx & 0x00FF;
4950 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
4951 temp = (tempbx & 0xFF00) >> 8;
4952 temp = temp << 4;
4953 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
4955 tempbx = push2;
4956 tempbx = tempbx + 8;
4957 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4958 tempbx = tempbx - 4;
4959 tempcx = tempbx;
4962 temp = (tempbx & 0x00FF) << 4;
4963 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
4965 j += 2;
4966 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
4967 temp = tempcx & 0x00FF;
4968 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
4969 temp = ((tempcx & 0xFF00) >> 8) << 4;
4970 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
4972 tempcx += 8;
4973 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4974 tempcx -= 4;
4976 temp = tempcx & 0xFF;
4977 temp = temp << 4;
4978 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
4980 tempcx = push1; /* pop cx */
4981 j += 2;
4982 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4983 tempcx -= temp;
4984 temp = tempcx & 0x00FF;
4985 temp = temp << 4;
4986 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
4988 tempcx -= 11;
4990 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
4991 tempax = XGI_GetVGAHT2(pVBInfo);
4992 tempcx = tempax - 1;
4994 temp = tempcx & 0x00FF;
4995 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
4997 tempbx = pVBInfo->VDE;
4999 if (pVBInfo->VGAVDE == 360)
5000 tempbx = 746;
5001 if (pVBInfo->VGAVDE == 375)
5002 tempbx = 746;
5003 if (pVBInfo->VGAVDE == 405)
5004 tempbx = 853;
5006 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5007 if (pVBInfo->VBType &
5008 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5009 if (!(pVBInfo->TVInfo &
5010 (SetYPbPrMode525p | SetYPbPrMode750p)))
5011 tempbx = tempbx >> 1;
5012 } else
5013 tempbx = tempbx >> 1;
5016 tempbx -= 2;
5017 temp = tempbx & 0x00FF;
5019 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5020 if (pVBInfo->VBType & VB_XGI301LV) {
5021 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5022 if (pVBInfo->VBInfo & SetInSlaveMode) {
5023 if (ModeNo == 0x2f)
5024 temp += 1;
5027 } else {
5028 if (pVBInfo->VBInfo & SetInSlaveMode) {
5029 if (ModeNo == 0x2f)
5030 temp += 1;
5035 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
5037 temp = (tempcx & 0xFF00) >> 8;
5038 temp |= ((tempbx & 0xFF00) >> 8) << 6;
5040 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5041 if (pVBInfo->VBType & VB_XGI301LV) {
5042 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5043 temp |= 0x10;
5045 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5046 temp |= 0x20;
5048 } else {
5049 temp |= 0x10;
5050 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5051 temp |= 0x20;
5055 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
5057 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5058 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5059 tempbx = pVBInfo->VDE;
5060 tempcx = tempbx - 2;
5062 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5063 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5064 | SetYPbPrMode750p)))
5065 tempbx = tempbx >> 1;
5068 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5069 temp = 0;
5070 if (tempcx & 0x0400)
5071 temp |= 0x20;
5073 if (tempbx & 0x0400)
5074 temp |= 0x40;
5076 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
5079 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
5080 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
5081 temp = (tempbx - 3) & 0x00FF;
5082 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
5085 tempbx = tempbx & 0x00FF;
5087 if (!(modeflag & HalfDCLK)) {
5088 tempcx = pVBInfo->VGAHDE;
5089 if (tempcx >= pVBInfo->HDE) {
5090 tempbx |= 0x2000;
5091 tempax &= 0x00FF;
5095 tempcx = 0x0101;
5097 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5098 if (pVBInfo->VGAHDE >= 1024) {
5099 tempcx = 0x1920;
5100 if (pVBInfo->VGAHDE >= 1280) {
5101 tempcx = 0x1420;
5102 tempbx = tempbx & 0xDFFF;
5107 if (!(tempbx & 0x2000)) {
5108 if (modeflag & HalfDCLK)
5109 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
5111 push1 = tempbx;
5112 tempeax = pVBInfo->VGAHDE;
5113 tempebx = (tempcx & 0xFF00) >> 8;
5114 longtemp = tempeax * tempebx;
5115 tempecx = tempcx & 0x00FF;
5116 longtemp = longtemp / tempecx;
5118 /* 301b */
5119 tempecx = 8 * 1024;
5121 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5122 | VB_XGI302LV | VB_XGI301C)) {
5123 tempecx = tempecx * 8;
5126 longtemp = longtemp * tempecx;
5127 tempecx = pVBInfo->HDE;
5128 temp2 = longtemp % tempecx;
5129 tempeax = longtemp / tempecx;
5130 if (temp2 != 0)
5131 tempeax += 1;
5133 tempax = (unsigned short) tempeax;
5135 /* 301b */
5136 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5137 | VB_XGI302LV | VB_XGI301C)) {
5138 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5140 /* end 301b */
5142 tempbx = push1;
5143 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5144 | (tempbx & 0x00FF));
5145 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5146 | (tempax & 0x00FF));
5147 temp = (tempax & 0xFF00) >> 8;
5148 } else {
5149 temp = (tempax & 0x00FF) >> 8;
5152 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
5153 temp = (tempbx & 0xFF00) >> 8;
5154 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
5155 temp = tempcx & 0x00FF;
5157 if (tempbx & 0x2000)
5158 temp = 0;
5160 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5161 temp |= 0x18;
5163 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
5164 if (pVBInfo->TVInfo & SetPALTV) {
5165 tempbx = 0x0382;
5166 tempcx = 0x007e;
5167 } else {
5168 tempbx = 0x0369;
5169 tempcx = 0x0061;
5172 temp = tempbx & 0x00FF;
5173 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
5174 temp = tempcx & 0x00FF;
5175 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
5177 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5178 temp = temp << 2;
5179 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
5181 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5182 temp |= 0x10;
5184 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5185 temp |= 0x20;
5187 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5188 temp |= 0x60;
5191 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
5192 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
5193 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
5195 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5196 if (pVBInfo->TVInfo & NTSC1024x768) {
5197 TimingPoint = XGI_NTSC1024AdjTime;
5198 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
5199 xgifb_reg_set(pVBInfo->Part2Port, i,
5200 TimingPoint[j]);
5202 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
5206 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5207 if (pVBInfo->VBType & VB_XGI301C) {
5208 if (pVBInfo->TVInfo & SetPALMTV)
5209 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
5210 0x08); /* PALM Mode */
5213 if (pVBInfo->TVInfo & SetPALMTV) {
5214 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
5215 0x01);
5216 tempax--;
5217 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
5219 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
5222 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5223 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5224 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
5227 if (pVBInfo->VBInfo & SetCRT2ToTV)
5228 return;
5231 static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
5232 struct xgi_hw_device_info *HwDeviceExtension,
5233 unsigned short RefreshRateTableIndex,
5234 struct vb_device_info *pVBInfo)
5236 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5237 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
5239 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5241 if (ModeNo <= 0x13) {
5242 /* si+St_ResInfo */
5243 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5244 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5245 } else {
5246 /* si+Ext_ResInfo */
5247 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5248 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5249 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5250 Ext_CRT1CRTC;
5251 CRT1Index &= IndexMask;
5254 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5255 return;
5257 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
5259 if (XGI_IsLCDDualLink(pVBInfo))
5260 tempbx = tempbx >> 1;
5262 tempbx -= 1;
5263 temp = tempbx & 0x00FF;
5264 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
5265 temp = (tempbx & 0xFF00) >> 8;
5266 temp = temp << 4;
5267 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
5268 temp = 0x01;
5270 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5271 if (pVBInfo->ModeType == ModeEGA) {
5272 if (pVBInfo->VGAHDE >= 1024) {
5273 temp = 0x02;
5274 if (pVBInfo->LCDInfo & LCDVESATiming)
5275 temp = 0x01;
5280 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
5281 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5282 push1 = tempbx;
5283 tempbx--;
5284 temp = tempbx & 0x00FF;
5285 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
5286 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
5287 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
5289 tempcx = pVBInfo->VT - 1;
5290 push2 = tempcx + 1;
5291 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
5292 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
5293 temp = (tempcx & 0xFF00) >> 8;
5294 temp = temp << 5;
5295 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
5296 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5297 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5298 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5299 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
5301 /* Customized LCDB Des no add */
5302 tempbx = 5;
5303 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5304 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5305 tempah = pVBInfo->LCDResInfo;
5306 tempah &= PanelResInfo;
5308 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5309 tempbx = 1024;
5310 tempcx = 768;
5311 } else if ((tempah == Panel1280x1024) ||
5312 (tempah == Panel1280x1024x75)) {
5313 tempbx = 1280;
5314 tempcx = 1024;
5315 } else if (tempah == Panel1400x1050) {
5316 tempbx = 1400;
5317 tempcx = 1050;
5318 } else {
5319 tempbx = 1600;
5320 tempcx = 1200;
5323 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5324 tempbx = pVBInfo->HDE;
5325 tempcx = pVBInfo->VDE;
5328 pushbx = tempbx;
5329 tempax = pVBInfo->VT;
5330 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5331 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5332 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5333 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5334 tempbx = pVBInfo->LCDVDES;
5335 tempcx += tempbx;
5337 if (tempcx >= tempax)
5338 tempcx -= tempax; /* lcdvdes */
5340 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
5341 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
5342 temp = tempcx & 0x00FF;
5343 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
5344 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5345 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5346 tempah = tempch;
5347 tempah = tempah << 3;
5348 tempah |= tempbh;
5349 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
5351 /* getlcdsync() */
5352 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5353 tempcx = tempbx;
5354 tempax = pVBInfo->VT;
5355 tempbx = pVBInfo->LCDVRS;
5357 tempcx += tempbx;
5358 if (tempcx >= tempax)
5359 tempcx -= tempax;
5361 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
5362 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
5363 temp = (tempbx & 0xFF00) >> 8;
5364 temp = temp << 4;
5365 temp |= (tempcx & 0x000F);
5366 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
5367 tempcx = pushbx;
5368 tempax = pVBInfo->HT;
5369 tempbx = pVBInfo->LCDHDES;
5370 tempbx &= 0x0FFF;
5372 if (XGI_IsLCDDualLink(pVBInfo)) {
5373 tempax = tempax >> 1;
5374 tempbx = tempbx >> 1;
5375 tempcx = tempcx >> 1;
5378 if (pVBInfo->VBType & VB_XGI302LV)
5379 tempbx += 1;
5381 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5382 tempbx += 1;
5384 tempcx += tempbx;
5386 if (tempcx >= tempax)
5387 tempcx -= tempax;
5389 temp = tempbx & 0x00FF;
5390 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
5391 temp = ((tempbx & 0xFF00) >> 8) << 4;
5392 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
5393 temp = tempcx & 0x00FF;
5394 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
5395 temp = (tempcx & 0xFF00) >> 8;
5396 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
5398 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5399 tempcx = tempax;
5400 tempax = pVBInfo->HT;
5401 tempbx = pVBInfo->LCDHRS;
5402 if (XGI_IsLCDDualLink(pVBInfo)) {
5403 tempax = tempax >> 1;
5404 tempbx = tempbx >> 1;
5405 tempcx = tempcx >> 1;
5408 if (pVBInfo->VBType & VB_XGI302LV)
5409 tempbx += 1;
5411 tempcx += tempbx;
5413 if (tempcx >= tempax)
5414 tempcx -= tempax;
5416 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
5417 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
5419 temp = (tempbx & 0xFF00) >> 8;
5420 temp = temp << 4;
5421 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
5422 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
5423 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
5425 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5426 if (pVBInfo->VGAVDE == 525) {
5427 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5428 | VB_XGI301LV | VB_XGI302LV
5429 | VB_XGI301C)) {
5430 temp = 0xC6;
5431 } else
5432 temp = 0xC4;
5434 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5435 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
5438 if (pVBInfo->VGAVDE == 420) {
5439 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5440 | VB_XGI301LV | VB_XGI302LV
5441 | VB_XGI301C)) {
5442 temp = 0x4F;
5443 } else
5444 temp = 0x4E;
5445 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5450 /* --------------------------------------------------------------------- */
5451 /* Function : XGI_GetTap4Ptr */
5452 /* Input : */
5453 /* Output : di -> Tap4 Reg. Setting Pointer */
5454 /* Description : */
5455 /* --------------------------------------------------------------------- */
5456 static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
5457 struct vb_device_info *pVBInfo)
5459 unsigned short tempax, tempbx, i;
5461 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5463 if (tempcx == 0) {
5464 tempax = pVBInfo->VGAHDE;
5465 tempbx = pVBInfo->HDE;
5466 } else {
5467 tempax = pVBInfo->VGAVDE;
5468 tempbx = pVBInfo->VDE;
5471 if (tempax <= tempbx)
5472 return &xgifb_tap4_timing[0];
5473 else
5474 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
5476 if (pVBInfo->TVInfo & SetPALTV)
5477 Tap4TimingPtr = PALTap4Timing;
5479 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5480 if ((pVBInfo->TVInfo & SetYPbPrMode525i) ||
5481 (pVBInfo->TVInfo & SetYPbPrMode525p))
5482 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
5483 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5484 Tap4TimingPtr = YPbPr750pTap4Timing;
5487 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5488 Tap4TimingPtr = xgifb_tap4_timing;
5490 i = 0;
5491 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5492 if (Tap4TimingPtr[i].DE == tempax)
5493 break;
5494 i++;
5496 return &Tap4TimingPtr[i];
5499 static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
5501 unsigned short i, j;
5503 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5505 if (!(pVBInfo->VBType & VB_XGI301C))
5506 return;
5508 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5509 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
5510 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
5512 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5513 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5514 /* Set Vertical Scaling */
5515 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
5516 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
5517 xgifb_reg_set(pVBInfo->Part2Port,
5519 Tap4TimingPtr->Reg[j]);
5522 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5523 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5524 /* Enable V.Scaling */
5525 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
5526 else
5527 /* Enable H.Scaling */
5528 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
5531 static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
5532 struct vb_device_info *pVBInfo)
5534 unsigned short i;
5535 unsigned char *tempdi;
5536 unsigned short modeflag;
5538 if (ModeNo <= 0x13)
5539 /* si+St_ResInfo */
5540 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5541 else
5542 /* si+Ext_ResInfo */
5543 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5545 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
5546 if (pVBInfo->TVInfo & SetPALTV) {
5547 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5548 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5549 } else {
5550 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5551 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
5554 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5555 return;
5557 if (pVBInfo->TVInfo & SetPALMTV) {
5558 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5559 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5560 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
5563 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5564 & SetCRT2ToYPbPr)) {
5565 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5566 return;
5568 tempdi = pVBInfo->HiTVGroup3Data;
5569 if (pVBInfo->SetFlag & TVSimuMode) {
5570 tempdi = pVBInfo->HiTVGroup3Simu;
5571 if (!(modeflag & Charx8Dot))
5572 tempdi = pVBInfo->HiTVGroup3Text;
5575 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5576 tempdi = pVBInfo->Ren525pGroup3;
5578 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5579 tempdi = pVBInfo->Ren750pGroup3;
5581 for (i = 0; i <= 0x3E; i++)
5582 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
5584 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5585 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5586 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
5589 return;
5590 } /* {end of XGI_SetGroup3} */
5592 static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
5593 unsigned short RefreshRateTableIndex,
5594 struct xgi_hw_device_info *HwDeviceExtension,
5595 struct vb_device_info *pVBInfo)
5597 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
5599 unsigned long tempebx, tempeax, templong;
5601 if (ModeNo <= 0x13)
5602 /* si+St_ResInfo */
5603 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5604 else
5605 /* si+Ext_ResInfo */
5606 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5608 temp = pVBInfo->RVBHCFACT;
5609 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
5611 tempbx = pVBInfo->RVBHCMAX;
5612 temp = tempbx & 0x00FF;
5613 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
5614 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5615 tempcx = pVBInfo->VGAHT - 1;
5616 temp = tempcx & 0x00FF;
5617 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
5619 temp = ((tempcx & 0xFF00) >> 8) << 3;
5620 temp2 |= temp;
5622 tempcx = pVBInfo->VGAVT - 1;
5623 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5624 tempcx -= 5;
5626 temp = tempcx & 0x00FF;
5627 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
5628 temp = temp2 | ((tempcx & 0xFF00) >> 8);
5629 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
5630 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
5631 tempcx = pVBInfo->VBInfo;
5632 tempbx = pVBInfo->VGAHDE;
5634 if (modeflag & HalfDCLK)
5635 tempbx = tempbx >> 1;
5637 if (XGI_IsLCDDualLink(pVBInfo))
5638 tempbx = tempbx >> 1;
5640 if (tempcx & SetCRT2ToHiVisionTV) {
5641 temp = 0;
5642 if (tempbx <= 1024)
5643 temp = 0xA0;
5644 if (tempbx == 1280)
5645 temp = 0xC0;
5646 } else if (tempcx & SetCRT2ToTV) {
5647 temp = 0xA0;
5648 if (tempbx <= 800)
5649 temp = 0x80;
5650 } else {
5651 temp = 0x80;
5652 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5653 temp = 0;
5654 if (tempbx > 800)
5655 temp = 0x60;
5659 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
5660 temp = 0x00;
5661 if (pVBInfo->VGAHDE == 1280)
5662 temp = 0x40;
5663 if (pVBInfo->VGAHDE == 1024)
5664 temp = 0x20;
5666 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
5668 tempebx = pVBInfo->VDE;
5670 if (tempcx & SetCRT2ToHiVisionTV) {
5671 if (!(temp & 0xE000))
5672 tempbx = tempbx >> 1;
5675 tempcx = pVBInfo->RVBHRS;
5676 temp = tempcx & 0x00FF;
5677 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
5679 tempeax = pVBInfo->VGAVDE;
5680 tempcx |= 0x04000;
5682 if (tempeax <= tempebx) {
5683 tempcx = (tempcx & (~0x4000));
5684 tempeax = pVBInfo->VGAVDE;
5685 } else {
5686 tempeax -= tempebx;
5689 templong = (tempeax * 256 * 1024) % tempebx;
5690 tempeax = (tempeax * 256 * 1024) / tempebx;
5691 tempebx = tempeax;
5693 if (templong != 0)
5694 tempebx++;
5696 temp = (unsigned short) (tempebx & 0x000000FF);
5697 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
5699 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
5700 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
5701 tempbx = (unsigned short) (tempebx >> 16);
5702 temp = tempbx & 0x00FF;
5703 temp = temp << 4;
5704 temp |= ((tempcx & 0xFF00) >> 8);
5705 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
5707 /* 301b */
5708 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5709 | VB_XGI302LV | VB_XGI301C)) {
5710 temp = 0x0028;
5711 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
5712 tempax = pVBInfo->VGAHDE;
5713 if (modeflag & HalfDCLK)
5714 tempax = tempax >> 1;
5716 if (XGI_IsLCDDualLink(pVBInfo))
5717 tempax = tempax >> 1;
5719 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5720 if (tempax > 800)
5721 tempax -= 800;
5722 } else {
5723 if (pVBInfo->VGAHDE > 800) {
5724 if (pVBInfo->VGAHDE == 1024)
5725 tempax = (tempax * 25 / 32) - 1;
5726 else
5727 tempax = (tempax * 20 / 32) - 1;
5730 tempax -= 1;
5732 temp = (tempax & 0xFF00) >> 8;
5733 temp = ((temp & 0x0003) << 4);
5734 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
5735 temp = (tempax & 0x00FF);
5736 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
5738 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5739 if (pVBInfo->VGAHDE > 800)
5740 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
5743 temp = 0x0036;
5745 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5746 if (!(pVBInfo->TVInfo & (NTSC1024x768
5747 | SetYPbPrMode525p | SetYPbPrMode750p
5748 | SetYPbPrMode1080i))) {
5749 temp |= 0x0001;
5750 if ((pVBInfo->VBInfo & SetInSlaveMode)
5751 && (!(pVBInfo->TVInfo
5752 & TVSimuMode)))
5753 temp &= (~0x0001);
5757 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
5758 tempbx = pVBInfo->HT;
5759 if (XGI_IsLCDDualLink(pVBInfo))
5760 tempbx = tempbx >> 1;
5761 tempbx = (tempbx >> 1) - 2;
5762 temp = ((tempbx & 0x0700) >> 8) << 3;
5763 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
5764 temp = tempbx & 0x00FF;
5765 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
5767 /* end 301b */
5769 if (pVBInfo->ISXPDOS == 0)
5770 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5771 pVBInfo);
5774 static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5776 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
5779 static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
5780 struct vb_device_info *pVBInfo)
5782 unsigned short Pindex, Pdata;
5784 Pindex = pVBInfo->Part5Port;
5785 Pdata = pVBInfo->Part5Port + 1;
5786 if (pVBInfo->ModeType == ModeVGA) {
5787 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
5788 | CRT2DisplayFlag))) {
5789 XGINew_EnableCRT2(pVBInfo);
5792 return;
5795 static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
5796 struct vb_device_info *pVBInfo)
5798 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
5801 static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
5802 struct vb_device_info *pVBInfo)
5805 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
5808 static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
5809 unsigned short ModeNo, unsigned short ModeIdIndex,
5810 struct vb_device_info *pVBInfo)
5812 unsigned short xres, yres, colordepth, modeflag, resindex;
5814 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
5815 if (ModeNo <= 0x13) {
5816 xres = pVBInfo->StResInfo[resindex].HTotal;
5817 yres = pVBInfo->StResInfo[resindex].VTotal;
5818 /* si+St_ResInfo */
5819 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5820 } else {
5821 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5822 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5823 /* si+St_ModeFlag */
5824 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5827 if (!(modeflag & Charx8Dot)) {
5828 xres /= 9;
5829 xres *= 8;
5832 if (ModeNo > 0x13) {
5833 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
5834 xres *= 2;
5836 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
5837 yres *= 2;
5841 if (xres > xgifb_info->lvds_data.LVDSHDE)
5842 return 0;
5844 if (yres > xgifb_info->lvds_data.LVDSVDE)
5845 return 0;
5847 if (ModeNo > 0x13) {
5848 if (xres != xgifb_info->lvds_data.LVDSHDE ||
5849 yres != xgifb_info->lvds_data.LVDSVDE) {
5850 colordepth = XGI_GetColorDepth(ModeNo,
5851 ModeIdIndex,
5852 pVBInfo);
5853 if (colordepth > 2)
5854 return 0;
5858 return 1;
5861 static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
5862 int chip_id,
5863 unsigned short ModeNo,
5864 unsigned short ModeIdIndex,
5865 struct vb_device_info *pVBInfo)
5867 unsigned char temp, Miscdata;
5868 unsigned short xres, yres, modeflag, resindex;
5869 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
5870 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
5871 unsigned short value;
5873 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
5874 (LCDPolarity << 8)) >> 8);
5875 temp &= LCDPolarity;
5876 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
5878 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
5880 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
5881 /* SR35[7] FP VSync polarity */
5882 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
5883 /* SR30[5] FP HSync polarity */
5884 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
5886 if (chip_id == XG27)
5887 XGI_SetXG27FPBits(pVBInfo);
5888 else
5889 XGI_SetXG21FPBits(pVBInfo);
5891 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
5892 if (ModeNo <= 0x13) {
5893 xres = pVBInfo->StResInfo[resindex].HTotal;
5894 yres = pVBInfo->StResInfo[resindex].VTotal;
5895 /* si+St_ResInfo */
5896 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5897 } else {
5898 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5899 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5900 /* si+St_ModeFlag */
5901 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5904 if (!(modeflag & Charx8Dot))
5905 xres = xres * 8 / 9;
5907 LVDSHT = xgifb_info->lvds_data.LVDSHT;
5909 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
5910 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
5911 LVDSHBS -= xres / 4;
5913 if (LVDSHBS > LVDSHT)
5914 LVDSHBS -= LVDSHT;
5916 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
5917 if (LVDSHRS > LVDSHT)
5918 LVDSHRS -= LVDSHT;
5920 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
5921 if (LVDSHRE > LVDSHT)
5922 LVDSHRE -= LVDSHT;
5924 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
5926 LVDSVT = xgifb_info->lvds_data.LVDSVT;
5928 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
5929 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
5930 LVDSVBS += yres / 2;
5932 if (LVDSVBS > LVDSVT)
5933 LVDSVBS -= LVDSVT;
5935 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
5936 if (LVDSVRS > LVDSVT)
5937 LVDSVRS -= LVDSVT;
5939 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
5940 if (LVDSVRE > LVDSVT)
5941 LVDSVRE -= LVDSVT;
5943 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
5945 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
5946 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
5948 if (!(modeflag & Charx8Dot))
5949 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
5951 /* HT SR0B[1:0] CR00 */
5952 value = (LVDSHT >> 3) - 5;
5953 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
5954 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
5956 /* HBS SR0B[5:4] CR02 */
5957 value = (LVDSHBS >> 3) - 1;
5958 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
5959 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
5961 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
5962 value = (LVDSHBE >> 3) - 1;
5963 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
5964 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
5965 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
5967 /* HRS SR0B[7:6] CR04 */
5968 value = (LVDSHRS >> 3) + 2;
5969 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
5970 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
5972 /* Panel HRS SR2F[1:0] SR2E[7:0] */
5973 value--;
5974 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
5975 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
5977 /* HRE SR0C[2] CR05[4:0] */
5978 value = (LVDSHRE >> 3) + 2;
5979 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
5980 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
5982 /* Panel HRE SR2F[7:2] */
5983 value--;
5984 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
5986 /* VT SR0A[0] CR07[5][0] CR06 */
5987 value = LVDSVT - 2;
5988 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
5989 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
5990 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
5991 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
5993 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
5994 value = LVDSVBS - 1;
5995 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
5996 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
5997 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
5998 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
6000 /* VBE SR0A[4] CR16 */
6001 value = LVDSVBE - 1;
6002 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
6003 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
6005 /* VRS SR0A[3] CR7[7][2] CR10 */
6006 value = LVDSVRS - 1;
6007 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6008 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6009 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
6010 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
6012 if (chip_id == XG27) {
6013 /* Panel VRS SR35[2:0] SR34[7:0] */
6014 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
6015 (value & 0x700) >> 8);
6016 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
6017 } else {
6018 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
6019 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
6020 (value & 0x600) >> 9);
6021 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
6022 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
6025 /* VRE SR0A[5] CR11[3:0] */
6026 value = LVDSVRE - 1;
6027 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6028 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
6030 /* Panel VRE SR3F[7:2] */
6031 if (chip_id == XG27)
6032 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6033 (value << 2) & 0xFC);
6034 else
6035 /* SR3F[7] has to be 0, h/w bug */
6036 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6037 (value << 2) & 0x7C);
6039 for (temp = 0, value = 0; temp < 3; temp++) {
6041 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
6042 xgifb_reg_set(pVBInfo->P3c4,
6043 0x2B, xgifb_info->lvds_data.VCLKData1);
6044 xgifb_reg_set(pVBInfo->P3c4,
6045 0x2C, xgifb_info->lvds_data.VCLKData2);
6046 value += 0x10;
6049 if (!(modeflag & Charx8Dot)) {
6050 inb(pVBInfo->P3da); /* reset 3da */
6051 outb(0x13, pVBInfo->P3c0); /* set index */
6052 /* set data, panning = 0, shift left 1 dot*/
6053 outb(0x00, pVBInfo->P3c0);
6055 inb(pVBInfo->P3da); /* Enable Attribute */
6056 outb(0x20, pVBInfo->P3c0);
6058 inb(pVBInfo->P3da); /* reset 3da */
6063 /* --------------------------------------------------------------------- */
6064 /* Function : XGI_IsLCDON */
6065 /* Input : */
6066 /* Output : 0 : Skip PSC Control */
6067 /* 1: Disable PSC */
6068 /* Description : */
6069 /* --------------------------------------------------------------------- */
6070 static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
6072 unsigned short tempax;
6074 tempax = pVBInfo->VBInfo;
6075 if (tempax & SetCRT2ToDualEdge)
6076 return 0;
6077 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6078 return 1;
6080 return 0;
6083 /* --------------------------------------------------------------------- */
6084 /* Function : XGI_DisableChISLCD */
6085 /* Input : */
6086 /* Output : 0 -> Not LCD Mode */
6087 /* Description : */
6088 /* --------------------------------------------------------------------- */
6089 static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
6091 unsigned short tempbx, tempah;
6093 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
6094 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
6096 if (tempbx & (EnableChA | DisableChA)) {
6097 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6098 return 0;
6101 if (!(tempbx & (EnableChB | DisableChB)))
6102 return 0;
6104 if (tempah & 0x01) /* Chk LCDB Mode */
6105 return 1;
6107 return 0;
6110 /* --------------------------------------------------------------------- */
6111 /* Function : XGI_EnableChISLCD */
6112 /* Input : */
6113 /* Output : 0 -> Not LCD mode */
6114 /* Description : */
6115 /* --------------------------------------------------------------------- */
6116 static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
6118 unsigned short tempbx, tempah;
6120 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
6121 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
6123 if (tempbx & (EnableChA | DisableChA)) {
6124 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6125 return 0;
6128 if (!(tempbx & (EnableChB | DisableChB)))
6129 return 0;
6131 if (tempah & 0x01) /* Chk LCDB Mode */
6132 return 1;
6134 return 0;
6137 static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
6138 struct xgi_hw_device_info *HwDeviceExtension,
6139 struct vb_device_info *pVBInfo)
6141 unsigned short tempah = 0;
6143 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6144 | VB_XGI302LV | VB_XGI301C)) {
6145 tempah = 0x3F;
6146 if (!(pVBInfo->VBInfo &
6147 (DisableCRT2Display | SetSimuScanMode))) {
6148 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6149 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6150 tempah = 0x7F; /* Disable Channel A */
6151 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6152 /* Disable Channel B */
6153 tempah = 0xBF;
6155 if (pVBInfo->SetFlag & DisableChB)
6156 /* force to disable Cahnnel */
6157 tempah &= 0xBF;
6159 if (pVBInfo->SetFlag & DisableChA)
6160 /* Force to disable Channel B */
6161 tempah &= 0x7F;
6166 /* disable part4_1f */
6167 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
6169 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6170 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6171 || (XGI_DisableChISLCD(pVBInfo))
6172 || (XGI_IsLCDON(pVBInfo)))
6173 /* LVDS Driver power down */
6174 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
6177 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6178 & (DisableCRT2Display | SetCRT2ToLCDA
6179 | SetSimuScanMode))) {
6180 if (pVBInfo->SetFlag & GatingCRT)
6181 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6182 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
6185 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6186 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6187 & SetCRT2ToLCDA))
6188 /* Power down */
6189 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
6192 /* disable TV as primary VGA swap */
6193 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
6195 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
6196 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
6198 if ((pVBInfo->SetFlag & DisableChB) ||
6199 (pVBInfo->VBInfo &
6200 (DisableCRT2Display | SetSimuScanMode)) ||
6201 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6202 (pVBInfo->VBInfo &
6203 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6204 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6206 if ((pVBInfo->SetFlag & DisableChB) ||
6207 (pVBInfo->VBInfo &
6208 (DisableCRT2Display | SetSimuScanMode)) ||
6209 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6210 (pVBInfo->VBInfo &
6211 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6212 /* save Part1 index 0 */
6213 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6214 /* BTDAC = 1, avoid VB reset */
6215 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6216 /* disable CRT2 */
6217 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6218 /* restore Part1 index 0 */
6219 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
6221 } else { /* {301} */
6222 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
6223 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6224 /* Disable CRT2 */
6225 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6226 /* Disable TV asPrimary VGA swap */
6227 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
6230 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6231 | SetSimuScanMode))
6232 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
6236 /* --------------------------------------------------------------------- */
6237 /* Function : XGI_GetTVPtrIndex */
6238 /* Input : */
6239 /* Output : */
6240 /* Description : bx 0 : ExtNTSC */
6241 /* 1 : StNTSC */
6242 /* 2 : ExtPAL */
6243 /* 3 : StPAL */
6244 /* 4 : ExtHiTV */
6245 /* 5 : StHiTV */
6246 /* 6 : Ext525i */
6247 /* 7 : St525i */
6248 /* 8 : Ext525p */
6249 /* 9 : St525p */
6250 /* A : Ext750p */
6251 /* B : St750p */
6252 /* --------------------------------------------------------------------- */
6253 static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
6255 unsigned short tempbx = 0;
6257 if (pVBInfo->TVInfo & SetPALTV)
6258 tempbx = 2;
6259 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
6260 tempbx = 4;
6261 if (pVBInfo->TVInfo & SetYPbPrMode525i)
6262 tempbx = 6;
6263 if (pVBInfo->TVInfo & SetYPbPrMode525p)
6264 tempbx = 8;
6265 if (pVBInfo->TVInfo & SetYPbPrMode750p)
6266 tempbx = 10;
6267 if (pVBInfo->TVInfo & TVSimuMode)
6268 tempbx++;
6270 return tempbx;
6273 /* --------------------------------------------------------------------- */
6274 /* Function : XGI_GetTVPtrIndex2 */
6275 /* Input : */
6276 /* Output : bx 0 : NTSC */
6277 /* 1 : PAL */
6278 /* 2 : PALM */
6279 /* 3 : PALN */
6280 /* 4 : NTSC1024x768 */
6281 /* 5 : PAL-M 1024x768 */
6282 /* 6-7: reserved */
6283 /* cl 0 : YFilter1 */
6284 /* 1 : YFilter2 */
6285 /* ch 0 : 301A */
6286 /* 1 : 301B/302B/301LV/302LV */
6287 /* Description : */
6288 /* --------------------------------------------------------------------- */
6289 static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
6290 unsigned char *tempch, struct vb_device_info *pVBInfo)
6292 *tempbx = 0;
6293 *tempcl = 0;
6294 *tempch = 0;
6296 if (pVBInfo->TVInfo & SetPALTV)
6297 *tempbx = 1;
6299 if (pVBInfo->TVInfo & SetPALMTV)
6300 *tempbx = 2;
6302 if (pVBInfo->TVInfo & SetPALNTV)
6303 *tempbx = 3;
6305 if (pVBInfo->TVInfo & NTSC1024x768) {
6306 *tempbx = 4;
6307 if (pVBInfo->TVInfo & SetPALMTV)
6308 *tempbx = 5;
6311 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6312 | VB_XGI302LV | VB_XGI301C)) {
6313 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
6314 & TVSimuMode)) {
6315 *tempbx += 8;
6316 *tempcl += 1;
6320 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6321 | VB_XGI302LV | VB_XGI301C))
6322 (*tempch)++;
6325 static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
6327 unsigned short index;
6329 unsigned char tempah, tempbl, tempbh;
6331 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6332 | VB_XGI302LV | VB_XGI301C)) {
6333 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
6334 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
6335 tempbl = 0;
6336 tempbh = 0;
6338 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
6339 tempbl = pVBInfo->XGI_TVDelayList[index];
6341 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6342 | VB_XGI301LV | VB_XGI302LV
6343 | VB_XGI301C))
6344 tempbl = pVBInfo->XGI_TVDelayList2[index];
6346 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6347 tempbl = tempbl >> 4;
6348 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
6349 /* Get LCD Delay */
6350 index = XGI_GetLCDCapPtr(pVBInfo);
6351 tempbh = pVBInfo->LCDCapList[index].
6352 LCD_DelayCompensation;
6354 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6355 tempbl = tempbh;
6358 tempbl &= 0x0F;
6359 tempbh &= 0xF0;
6360 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
6362 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
6363 | SetCRT2ToTV)) { /* Channel B */
6364 tempah &= 0xF0;
6365 tempah |= tempbl;
6368 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
6369 tempah &= 0x0F;
6370 tempah |= tempbh;
6372 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
6374 } else if (pVBInfo->IF_DEF_LVDS == 1) {
6375 tempbl = 0;
6376 tempbh = 0;
6377 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
6378 /* / Get LCD Delay */
6379 tempah = pVBInfo->LCDCapList[
6380 XGI_GetLCDCapPtr(pVBInfo)].
6381 LCD_DelayCompensation;
6382 tempah &= 0x0f;
6383 tempah = tempah << 4;
6384 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
6385 tempah);
6390 static void XGI_SetLCDCap_A(unsigned short tempcx,
6391 struct vb_device_info *pVBInfo)
6393 unsigned short temp;
6395 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
6397 if (temp & LCDRGB18Bit) {
6398 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
6399 /* Enable Dither */
6400 (unsigned short) (0x20 | (tempcx & 0x00C0)));
6401 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
6402 } else {
6403 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
6404 (unsigned short) (0x30 | (tempcx & 0x00C0)));
6405 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
6409 /* --------------------------------------------------------------------- */
6410 /* Function : XGI_SetLCDCap_B */
6411 /* Input : cx -> LCD Capability */
6412 /* Output : */
6413 /* Description : */
6414 /* --------------------------------------------------------------------- */
6415 static void XGI_SetLCDCap_B(unsigned short tempcx,
6416 struct vb_device_info *pVBInfo)
6418 if (tempcx & EnableLCD24bpp) /* 24bits */
6419 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
6420 (unsigned short) (((tempcx & 0x00ff) >> 6)
6421 | 0x0c));
6422 else
6423 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
6424 (unsigned short) (((tempcx & 0x00ff) >> 6)
6425 | 0x18)); /* Enable Dither */
6428 static void XGI_LongWait(struct vb_device_info *pVBInfo)
6430 unsigned short i;
6432 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
6434 if (!(i & 0xC0)) {
6435 for (i = 0; i < 0xFFFF; i++) {
6436 if (!(inb(pVBInfo->P3da) & 0x08))
6437 break;
6440 for (i = 0; i < 0xFFFF; i++) {
6441 if ((inb(pVBInfo->P3da) & 0x08))
6442 break;
6447 static void SetSpectrum(struct vb_device_info *pVBInfo)
6449 unsigned short index;
6451 index = XGI_GetLCDCapPtr(pVBInfo);
6453 /* disable down spectrum D[4] */
6454 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
6455 XGI_LongWait(pVBInfo);
6456 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
6457 XGI_LongWait(pVBInfo);
6459 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
6460 pVBInfo->LCDCapList[index].Spectrum_31);
6461 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
6462 pVBInfo->LCDCapList[index].Spectrum_32);
6463 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
6464 pVBInfo->LCDCapList[index].Spectrum_33);
6465 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
6466 pVBInfo->LCDCapList[index].Spectrum_34);
6467 XGI_LongWait(pVBInfo);
6468 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
6471 static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
6473 unsigned short tempcx;
6475 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
6477 if (pVBInfo->VBType &
6478 (VB_XGI301B |
6479 VB_XGI302B |
6480 VB_XGI301LV |
6481 VB_XGI302LV |
6482 VB_XGI301C)) { /* 301LV/302LV only */
6483 if (pVBInfo->VBType &
6484 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
6485 /* Set 301LV Capability */
6486 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
6487 (unsigned char) (tempcx & 0x1F));
6489 /* VB Driving */
6490 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
6491 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6492 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6493 | EnablePLLSPLOW)) >> 8));
6496 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6497 | VB_XGI302LV | VB_XGI301C)) {
6498 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6499 XGI_SetLCDCap_B(tempcx, pVBInfo);
6500 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6501 XGI_SetLCDCap_A(tempcx, pVBInfo);
6503 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6504 if (tempcx & EnableSpectrum)
6505 SetSpectrum(pVBInfo);
6507 } else {
6508 /* LVDS,CH7017 */
6509 XGI_SetLCDCap_A(tempcx, pVBInfo);
6513 /* --------------------------------------------------------------------- */
6514 /* Function : XGI_SetAntiFlicker */
6515 /* Input : */
6516 /* Output : */
6517 /* Description : Set TV Customized Param. */
6518 /* --------------------------------------------------------------------- */
6519 static void XGI_SetAntiFlicker(unsigned short ModeNo,
6520 unsigned short ModeIdIndex,
6521 struct vb_device_info *pVBInfo)
6523 unsigned short tempbx, index;
6525 unsigned char tempah;
6527 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
6528 return;
6530 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6531 tempbx &= 0xFE;
6533 if (ModeNo <= 0x13)
6534 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6535 else
6536 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
6538 tempbx += index;
6539 tempah = TVAntiFlickList[tempbx];
6540 tempah = tempah << 4;
6542 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
6545 static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6546 unsigned short ModeIdIndex,
6547 struct vb_device_info *pVBInfo)
6549 unsigned short tempbx, index;
6551 unsigned char tempah;
6553 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6554 tempbx &= 0xFE;
6556 if (ModeNo <= 0x13)
6557 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6558 else
6559 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
6561 tempbx += index;
6562 tempah = TVEdgeList[tempbx];
6563 tempah = tempah << 5;
6565 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
6568 static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
6570 unsigned short tempbx;
6572 unsigned char tempcl, tempch;
6574 unsigned long tempData;
6576 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6577 tempData = TVPhaseList[tempbx];
6579 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
6580 & 0x000000FF));
6581 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
6582 & 0x0000FF00) >> 8));
6583 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
6584 & 0x00FF0000) >> 16));
6585 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
6586 & 0xFF000000) >> 24));
6589 static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
6590 struct vb_device_info *pVBInfo)
6592 unsigned short tempbx, index;
6594 unsigned char tempcl, tempch, tempal, *filterPtr;
6596 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6598 switch (tempbx) {
6599 case 0x00:
6600 case 0x04:
6601 filterPtr = NTSCYFilter1;
6602 break;
6604 case 0x01:
6605 filterPtr = PALYFilter1;
6606 break;
6608 case 0x02:
6609 case 0x05:
6610 case 0x0D:
6611 case 0x03:
6612 filterPtr = xgifb_palmn_yfilter1;
6613 break;
6615 case 0x08:
6616 case 0x0C:
6617 case 0x0A:
6618 case 0x0B:
6619 case 0x09:
6620 filterPtr = xgifb_yfilter2;
6621 break;
6623 default:
6624 return;
6627 if (ModeNo <= 0x13)
6628 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
6629 VB_StTVYFilterIndex;
6630 else
6631 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
6632 VB_ExtTVYFilterIndex;
6634 if (tempcl == 0)
6635 index = tempal * 4;
6636 else
6637 index = tempal * 7;
6639 if ((tempcl == 0) && (tempch == 1)) {
6640 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6641 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6642 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6643 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
6644 } else {
6645 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6646 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6647 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6648 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
6651 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6652 | VB_XGI302LV | VB_XGI301C)) {
6653 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6654 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6655 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
6659 /* --------------------------------------------------------------------- */
6660 /* Function : XGI_OEM310Setting */
6661 /* Input : */
6662 /* Output : */
6663 /* Description : Customized Param. for 301 */
6664 /* --------------------------------------------------------------------- */
6665 static void XGI_OEM310Setting(unsigned short ModeNo,
6666 unsigned short ModeIdIndex,
6667 struct vb_device_info *pVBInfo)
6669 XGI_SetDelayComp(pVBInfo);
6671 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
6672 XGI_SetLCDCap(pVBInfo);
6674 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6675 XGI_SetPhaseIncr(pVBInfo);
6676 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6677 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
6679 if (pVBInfo->VBType & VB_XGI301)
6680 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
6684 /* --------------------------------------------------------------------- */
6685 /* Function : XGI_SetCRT2ModeRegs */
6686 /* Input : */
6687 /* Output : */
6688 /* Description : Origin code for crt2group */
6689 /* --------------------------------------------------------------------- */
6690 static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
6691 struct xgi_hw_device_info *HwDeviceExtension,
6692 struct vb_device_info *pVBInfo)
6694 unsigned short tempbl;
6695 short tempcl;
6697 unsigned char tempah;
6699 tempah = 0;
6700 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6701 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6702 tempah &= ~0x10; /* BTRAMDAC */
6703 tempah |= 0x40; /* BTRAM */
6705 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6706 | SetCRT2ToLCD)) {
6707 tempah = 0x40; /* BTDRAM */
6708 if (ModeNo > 0x13) {
6709 tempcl = pVBInfo->ModeType;
6710 tempcl -= ModeVGA;
6711 if (tempcl >= 0) {
6712 /* BT Color */
6713 tempah = (0x008 >> tempcl);
6714 if (tempah == 0)
6715 tempah = 1;
6716 tempah |= 0x040;
6719 if (pVBInfo->VBInfo & SetInSlaveMode)
6720 tempah ^= 0x50; /* BTDAC */
6724 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
6725 tempah = 0x08;
6726 tempbl = 0xf0;
6728 if (pVBInfo->VBInfo & DisableCRT2Display) {
6729 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
6730 } else {
6731 tempah = 0x00;
6732 tempbl = 0xff;
6734 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6735 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
6736 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
6737 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
6738 tempbl &= 0xf7;
6739 tempah |= 0x01;
6740 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
6741 tempbl, tempah);
6742 } else {
6743 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6744 tempbl &= 0xf7;
6745 tempah |= 0x01;
6748 if (pVBInfo->VBInfo &
6749 (SetCRT2ToRAMDAC |
6750 SetCRT2ToTV |
6751 SetCRT2ToLCD)) {
6752 tempbl &= 0xf8;
6753 tempah = 0x01;
6755 if (!(pVBInfo->VBInfo & SetInSlaveMode))
6756 tempah |= 0x02;
6758 if (!(pVBInfo->VBInfo &
6759 SetCRT2ToRAMDAC)) {
6760 tempah = tempah ^ 0x05;
6761 if (!(pVBInfo->VBInfo &
6762 SetCRT2ToLCD))
6763 tempah = tempah ^ 0x01;
6766 if (!(pVBInfo->VBInfo &
6767 SetCRT2ToDualEdge))
6768 tempah |= 0x08;
6769 xgifb_reg_and_or(pVBInfo->Part1Port,
6770 0x2e, tempbl, tempah);
6771 } else {
6772 xgifb_reg_and_or(pVBInfo->Part1Port,
6773 0x2e, tempbl, tempah);
6776 } else {
6777 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
6778 tempah);
6782 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
6783 | SetCRT2ToLCDA)) {
6784 tempah &= (~0x08);
6785 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
6786 & SetInSlaveMode))) {
6787 tempah |= 0x010;
6789 tempah |= 0x080;
6791 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6792 tempah |= 0x020;
6793 if (ModeNo > 0x13) {
6794 if (pVBInfo->VBInfo & DriverMode)
6795 tempah = tempah ^ 0x20;
6799 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
6800 tempah = 0;
6802 if (pVBInfo->LCDInfo & SetLCDDualLink)
6803 tempah |= 0x40;
6805 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6806 if (pVBInfo->TVInfo & RPLLDIV2XO)
6807 tempah |= 0x40;
6810 if ((pVBInfo->LCDResInfo == Panel1280x1024)
6811 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
6812 tempah |= 0x80;
6814 if (pVBInfo->LCDResInfo == Panel1280x960)
6815 tempah |= 0x80;
6817 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
6820 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6821 | VB_XGI302LV | VB_XGI301C)) {
6822 tempah = 0;
6823 tempbl = 0xfb;
6825 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6826 tempbl = 0xff;
6827 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6828 tempah |= 0x04; /* shampoo 0129 */
6831 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
6832 tempah = 0x00;
6833 tempbl = 0xcf;
6834 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6835 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6836 tempah |= 0x30;
6839 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
6840 tempah = 0;
6841 tempbl = 0x3f;
6843 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6844 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6845 tempah |= 0xc0;
6847 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
6850 tempah = 0;
6851 tempbl = 0x7f;
6852 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
6853 tempbl = 0xff;
6854 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
6855 tempah |= 0x80;
6858 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
6860 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6861 if (pVBInfo->LCDInfo & SetLCDDualLink) {
6862 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
6863 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
6868 static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
6869 struct vb_device_info *pVBInfo)
6871 unsigned short tempbx;
6873 tempbx = 0;
6875 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6876 tempbx = 0x08A0;
6880 void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6881 struct vb_device_info *pVBInfo)
6884 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
6888 void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6889 struct vb_device_info *pVBInfo)
6892 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
6896 unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
6898 unsigned short flag;
6900 if (pVBInfo->IF_DEF_LVDS == 1) {
6901 return 1;
6902 } else {
6903 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
6904 if ((flag == 1) || (flag == 2))
6905 return 1; /* 301b */
6906 else
6907 return 0;
6911 unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
6912 unsigned short ModeNo, unsigned short ModeIdIndex,
6913 struct vb_device_info *pVBInfo)
6915 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
6916 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
6917 0x01, 0x01 };
6919 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
6921 if (ModeNo <= 0x13)
6922 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
6923 else
6924 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6926 if (ModeNo < 0x14)
6927 return 0xFFFF;
6929 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
6930 index = index >> pVBInfo->SelectCRT2Rate;
6931 index &= 0x0F;
6933 if (pVBInfo->LCDInfo & LCDNonExpanding)
6934 index = 0;
6936 if (index > 0)
6937 index--;
6939 if (pVBInfo->SetFlag & ProgrammingCRT2) {
6940 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
6941 if (pVBInfo->IF_DEF_LVDS == 0) {
6942 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6943 | VB_XGI301LV | VB_XGI302LV
6944 | VB_XGI301C))
6945 /* 301b */
6946 temp = LCDARefreshIndex[
6947 pVBInfo->LCDResInfo & 0x0F];
6948 else
6949 temp = LCDRefreshIndex[
6950 pVBInfo->LCDResInfo & 0x0F];
6952 if (index > temp)
6953 index = temp;
6954 } else {
6955 index = 0;
6960 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
6961 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
6962 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
6963 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
6964 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
6965 index++;
6967 /* Alan 10/19/2007;
6968 * do the similar adjustment like XGISearchCRT1Rate() */
6969 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
6970 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
6971 index++;
6973 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
6974 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
6975 index++;
6979 i = 0;
6980 do {
6981 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
6982 ModeID != ModeNo)
6983 break;
6984 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
6985 Ext_InfoFlag;
6986 temp &= ModeInfoFlag;
6987 if (temp < pVBInfo->ModeType)
6988 break;
6989 i++;
6990 index--;
6992 } while (index != 0xFFFF);
6993 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
6994 if (pVBInfo->VBInfo & SetInSlaveMode) {
6995 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
6996 Ext_InfoFlag;
6997 if (temp & InterlaceMode)
6998 i++;
7001 i--;
7002 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7003 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7004 RefreshRateTableIndex, &i, pVBInfo);
7006 return RefreshRateTableIndex + i;
7009 static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
7010 struct xgi_hw_device_info *HwDeviceExtension,
7011 struct vb_device_info *pVBInfo)
7013 unsigned short RefreshRateTableIndex;
7015 pVBInfo->SetFlag |= ProgrammingCRT2;
7016 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7017 ModeIdIndex, pVBInfo);
7018 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7019 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7020 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7021 HwDeviceExtension, pVBInfo);
7022 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7023 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7026 static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
7027 struct xgi_hw_device_info *HwDeviceExtension,
7028 struct vb_device_info *pVBInfo)
7030 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
7032 tempbx = pVBInfo->VBInfo;
7033 pVBInfo->SetFlag |= ProgrammingCRT2;
7034 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7035 pVBInfo->SelectCRT2Rate = 4;
7036 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7037 ModeIdIndex, pVBInfo);
7038 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7039 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7040 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7041 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7042 RefreshRateTableIndex, pVBInfo);
7043 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7044 RefreshRateTableIndex, pVBInfo);
7045 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7046 RefreshRateTableIndex, pVBInfo);
7047 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7048 HwDeviceExtension, pVBInfo);
7049 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7050 RefreshRateTableIndex, pVBInfo);
7051 XGI_SetTap4Regs(pVBInfo);
7052 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7053 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7054 HwDeviceExtension, pVBInfo);
7055 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7056 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7057 XGI_AutoThreshold(pVBInfo);
7058 return 1;
7061 void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7063 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7064 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7065 0x05, 0x00 };
7067 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
7069 unsigned char CR17, CR63, SR31;
7070 unsigned short temp;
7071 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
7073 int i;
7074 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
7076 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
7077 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
7078 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
7079 pVBInfo->P3d4, 0x53) | 0x02));
7081 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7082 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7083 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
7085 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7086 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
7088 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
7089 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
7091 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
7092 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
7094 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
7095 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
7096 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
7097 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
7099 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
7101 for (i = 0; i < 8; i++)
7102 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
7104 for (i = 8; i < 11; i++)
7105 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
7106 CRTCData[i]);
7108 for (i = 11; i < 13; i++)
7109 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
7110 CRTCData[i]);
7112 for (i = 13; i < 16; i++)
7113 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
7114 CRTCData[i]);
7116 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
7117 & 0xE0));
7119 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
7120 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7121 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
7123 outb(0x00, pVBInfo->P3c8);
7125 for (i = 0; i < 256; i++) {
7126 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
7127 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
7128 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
7131 mdelay(1);
7133 XGI_WaitDisply(pVBInfo);
7134 temp = inb(pVBInfo->P3c2);
7136 if (temp & 0x10)
7137 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
7138 else
7139 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
7141 /* alan, avoid display something, set BLACK DAC if not restore DAC */
7142 outb(0x00, pVBInfo->P3c8);
7144 for (i = 0; i < 256; i++) {
7145 outb(0, (pVBInfo->P3c8 + 1));
7146 outb(0, (pVBInfo->P3c8 + 1));
7147 outb(0, (pVBInfo->P3c8 + 1));
7150 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
7151 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
7152 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
7154 /* [2004/05/11] Vicent */
7155 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
7156 pVBInfo->P3d4, 0x53) & 0xFD));
7157 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
7160 static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
7161 struct xgi_hw_device_info *HwDeviceExtension,
7162 struct vb_device_info *pVBInfo)
7164 unsigned short tempah;
7166 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7167 | VB_XGI302LV | VB_XGI301C)) {
7168 if (!(pVBInfo->SetFlag & DisableChA)) {
7169 if (pVBInfo->SetFlag & EnableChA) {
7170 /* Power on */
7171 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
7172 } else {
7173 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7174 /* Power on */
7175 xgifb_reg_set(pVBInfo->Part1Port,
7176 0x1E, 0x20);
7181 if (!(pVBInfo->SetFlag & DisableChB)) {
7182 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
7183 & (SetCRT2ToLCD | SetCRT2ToTV
7184 | SetCRT2ToRAMDAC))) {
7185 tempah = (unsigned char) xgifb_reg_get(
7186 pVBInfo->P3c4, 0x32);
7187 tempah &= 0xDF;
7188 if (pVBInfo->VBInfo & SetInSlaveMode) {
7189 if (!(pVBInfo->VBInfo &
7190 SetCRT2ToRAMDAC))
7191 tempah |= 0x20;
7193 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
7194 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
7196 tempah = (unsigned char) xgifb_reg_get(
7197 pVBInfo->Part1Port, 0x2E);
7199 if (!(tempah & 0x80))
7200 xgifb_reg_or(pVBInfo->Part1Port,
7201 0x2E, 0x80);
7202 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
7206 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
7207 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
7208 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
7209 0x20); /* shampoo 0129 */
7210 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7211 if (!XGI_DisableChISLCD(pVBInfo)) {
7212 if (XGI_EnableChISLCD(pVBInfo) ||
7213 (pVBInfo->VBInfo &
7214 (SetCRT2ToLCD | SetCRT2ToLCDA)))
7215 /* LVDS PLL power on */
7216 xgifb_reg_and(
7217 pVBInfo->Part4Port,
7218 0x2A,
7219 0x7F);
7221 /* LVDS Driver power on */
7222 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
7226 tempah = 0x00;
7228 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7229 tempah = 0xc0;
7231 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
7232 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7233 if (pVBInfo->VBInfo &
7234 SetCRT2ToDualEdge) {
7235 tempah = tempah & 0x40;
7236 if (pVBInfo->VBInfo &
7237 SetCRT2ToLCDA)
7238 tempah = tempah ^ 0xC0;
7240 if (pVBInfo->SetFlag &
7241 DisableChB)
7242 tempah &= 0xBF;
7244 if (pVBInfo->SetFlag &
7245 DisableChA)
7246 tempah &= 0x7F;
7248 if (pVBInfo->SetFlag &
7249 EnableChB)
7250 tempah |= 0x40;
7252 if (pVBInfo->SetFlag &
7253 EnableChA)
7254 tempah |= 0x80;
7260 /* EnablePart4_1F */
7261 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
7263 if (!(pVBInfo->SetFlag & DisableChA)) {
7264 if (!(pVBInfo->SetFlag & GatingCRT)) {
7265 XGI_DisableGatingCRT(HwDeviceExtension,
7266 pVBInfo);
7267 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
7268 pVBInfo);
7271 } /* 301 */
7272 else { /* LVDS */
7273 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
7274 | SetCRT2ToLCDA))
7275 /* enable CRT2 */
7276 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
7278 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
7279 0x2E);
7280 if (!(tempah & 0x80))
7281 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
7283 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
7284 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
7285 } /* End of VB */
7288 static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
7289 struct xgi_hw_device_info *HwDeviceExtension,
7290 unsigned short ModeNo, unsigned short ModeIdIndex,
7291 struct vb_device_info *pVBInfo)
7293 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
7295 unsigned short XGINew_P3cc = pVBInfo->P3cc;
7297 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
7298 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7299 outb(pVBInfo->StandTable[StandTableIndex].MISC, pVBInfo->P3c2);
7300 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7301 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7302 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7303 XGI_ClearExt1Regs(pVBInfo);
7305 if (HwDeviceExtension->jChipType == XG27) {
7306 if (pVBInfo->IF_DEF_LVDS == 0)
7307 XGI_SetDefaultVCLK(pVBInfo);
7310 temp = ~ProgrammingCRT2;
7311 pVBInfo->SetFlag &= temp;
7312 pVBInfo->SelectCRT2Rate = 0;
7314 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7315 | VB_XGI302LV | VB_XGI301C)) {
7316 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
7317 | SetInSlaveMode)) {
7318 pVBInfo->SetFlag |= ProgrammingCRT2;
7322 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7323 ModeIdIndex, pVBInfo);
7324 if (RefreshRateTableIndex != 0xFFFF) {
7325 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
7326 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7327 pVBInfo, HwDeviceExtension);
7328 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
7329 RefreshRateTableIndex, pVBInfo);
7330 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7331 HwDeviceExtension, pVBInfo);
7332 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
7333 RefreshRateTableIndex, pVBInfo);
7336 if ((HwDeviceExtension->jChipType >= XG20) &&
7337 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
7338 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
7339 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7340 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
7341 b3CC = (unsigned char) inb(XGINew_P3cc);
7342 outb((b3CC |= 0x0C), XGINew_P3cc);
7343 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7344 == 0x0D)) {
7345 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7346 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
7347 b3CC = (unsigned char) inb(XGINew_P3cc);
7348 outb((b3CC |= 0x0C), XGINew_P3cc);
7352 if (HwDeviceExtension->jChipType >= XG21) {
7353 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
7354 if (temp & 0xA0) {
7356 if (HwDeviceExtension->jChipType == XG27)
7357 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
7358 RefreshRateTableIndex, pVBInfo);
7359 else
7360 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
7361 RefreshRateTableIndex, pVBInfo);
7363 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
7364 RefreshRateTableIndex);
7366 xgifb_set_lcd(HwDeviceExtension->jChipType,
7367 pVBInfo, RefreshRateTableIndex, ModeNo);
7369 if (pVBInfo->IF_DEF_LVDS == 1)
7370 xgifb_set_lvds(xgifb_info,
7371 HwDeviceExtension->jChipType,
7372 ModeNo, ModeIdIndex, pVBInfo);
7376 pVBInfo->SetFlag &= (~ProgrammingCRT2);
7377 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
7378 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
7379 RefreshRateTableIndex, pVBInfo);
7380 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
7383 unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
7384 struct xgi_hw_device_info *HwDeviceExtension,
7385 unsigned short ModeNo)
7387 unsigned short ModeIdIndex;
7388 struct vb_device_info VBINF;
7389 struct vb_device_info *pVBInfo = &VBINF;
7390 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
7391 pVBInfo->IF_DEF_LVDS = 0;
7392 pVBInfo->IF_DEF_LCDA = 1;
7394 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
7395 pVBInfo->IF_DEF_YPbPr = 0;
7396 pVBInfo->IF_DEF_HiVision = 0;
7397 pVBInfo->IF_DEF_CRT2Monitor = 0;
7398 pVBInfo->VBType = 0; /*set VBType default 0*/
7399 } else {
7400 pVBInfo->IF_DEF_YPbPr = 1;
7401 pVBInfo->IF_DEF_HiVision = 1;
7402 pVBInfo->IF_DEF_CRT2Monitor = 1;
7405 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
7406 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
7407 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
7408 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
7409 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
7410 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
7411 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
7412 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
7413 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
7414 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
7415 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
7416 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
7417 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
7418 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
7419 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
7420 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
7421 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
7422 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
7424 /* for x86 Linux, XG21 LVDS */
7425 if (HwDeviceExtension->jChipType == XG21) {
7426 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
7427 pVBInfo->IF_DEF_LVDS = 1;
7429 if (HwDeviceExtension->jChipType == XG27) {
7430 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
7431 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
7432 pVBInfo->IF_DEF_LVDS = 1;
7436 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
7437 XGI_GetVBType(pVBInfo);
7439 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
7440 if (ModeNo & 0x80)
7441 ModeNo = ModeNo & 0x7F;
7442 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
7444 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
7445 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
7447 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7449 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7450 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
7451 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
7452 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
7453 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
7455 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
7456 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
7457 ModeIdIndex, pVBInfo);
7459 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7460 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7461 HwDeviceExtension, pVBInfo);
7463 } else {
7464 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
7465 XGI_SetCRT1Group(xgifb_info,
7466 HwDeviceExtension, ModeNo,
7467 ModeIdIndex, pVBInfo);
7468 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7469 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7470 HwDeviceExtension,
7471 pVBInfo);
7476 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
7477 switch (HwDeviceExtension->ujVBChipID) {
7478 case VB_CHIP_301:
7479 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7480 pVBInfo); /*add for CRT2 */
7481 break;
7483 case VB_CHIP_302:
7484 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7485 pVBInfo); /*add for CRT2 */
7486 break;
7488 default:
7489 break;
7493 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
7494 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
7495 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
7496 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
7497 } /* !XG20 */
7498 else {
7499 if (pVBInfo->IF_DEF_LVDS == 1)
7500 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
7501 ModeIdIndex,
7502 pVBInfo))
7503 return 0;
7505 if (ModeNo <= 0x13) {
7506 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
7507 St_ModeFlag & ModeInfoFlag;
7508 } else {
7509 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
7510 Ext_ModeFlag & ModeInfoFlag;
7513 pVBInfo->SetFlag = 0;
7514 pVBInfo->VBInfo = DisableCRT2Display;
7516 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
7518 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
7519 ModeIdIndex, pVBInfo);
7521 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
7524 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
7526 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7527 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
7530 return 1;