staging/xgifb: Use SiS structs
[linux-2.6.git] / drivers / staging / xgifb / vb_setmode.c
blob183afe4bc24c695c49a199ebbea13603fcec1191
1 #include <linux/delay.h>
2 #include "XGIfb.h"
4 #include "vb_def.h"
5 #include "vb_util.h"
6 #include "vb_table.h"
9 #define IndexMask 0xff
10 #define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
12 static const unsigned short XGINew_VGA_DAC[] = {
13 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
14 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
15 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
16 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
17 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
18 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
19 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
20 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
21 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
22 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
24 void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
26 pVBInfo->StandTable = (struct SiS_StandTable_S *) &XGI330_StandTable;
27 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
28 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
29 pVBInfo->XGINEWUB_CRT1Table
30 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
32 pVBInfo->MCLKData = (struct SiS_MCLKData *) XGI340New_MCLKData;
33 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
34 pVBInfo->VCLKData = (struct SiS_VCLKData *) XGI_VCLKData;
35 pVBInfo->VBVCLKData = (struct SiS_VBVCLKData *) XGI_VBVCLKData;
36 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
37 pVBInfo->StResInfo = (struct SiS_StResInfo_S *) XGI330_StResInfo;
38 pVBInfo->ModeResInfo
39 = (struct SiS_ModeResInfo_S *) XGI330_ModeResInfo;
41 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
42 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
43 pVBInfo->pSR07 = &XGI330_SR07;
44 pVBInfo->LCDResInfo = 0;
45 pVBInfo->LCDTypeInfo = 0;
46 pVBInfo->LCDInfo = 0;
47 pVBInfo->VBInfo = 0;
48 pVBInfo->TVInfo = 0;
50 pVBInfo->SR15 = XGI340_SR13;
51 pVBInfo->CR40 = XGI340_cr41;
52 pVBInfo->SR25 = XGI330_sr25;
53 pVBInfo->pSR31 = &XGI330_sr31;
54 pVBInfo->pSR32 = &XGI330_sr32;
55 pVBInfo->CR6B = XGI340_CR6B;
56 pVBInfo->CR6E = XGI340_CR6E;
57 pVBInfo->CR6F = XGI340_CR6F;
58 pVBInfo->CR89 = XGI340_CR89;
59 pVBInfo->AGPReg = XGI340_AGPReg;
60 pVBInfo->SR16 = XGI340_SR16;
61 pVBInfo->pCRCF = &XG40_CRCF;
62 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
64 pVBInfo->CR49 = XGI330_CR49;
65 pVBInfo->pSR1F = &XGI330_SR1F;
66 pVBInfo->pSR21 = &XGI330_SR21;
67 pVBInfo->pSR22 = &XGI330_SR22;
68 pVBInfo->pSR23 = &XGI330_SR23;
69 pVBInfo->pSR24 = &XGI330_SR24;
70 pVBInfo->pSR33 = &XGI330_SR33;
72 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
73 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
74 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
75 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
76 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
77 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
78 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
79 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
80 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
81 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
83 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
84 pVBInfo->PALTiming = XGI330_PALTiming;
85 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
86 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
87 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
88 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
89 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
90 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
91 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
92 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
93 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
94 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
95 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
96 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
98 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
99 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
100 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
102 /* 310 customization related */
103 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
104 pVBInfo->LCDCapList = XGI_LCDDLCapList;
105 else
106 pVBInfo->LCDCapList = XGI_LCDCapList;
108 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
110 if (ChipType >= XG20)
111 pVBInfo->pXGINew_CR97 = &XG20_CR97;
113 if (ChipType == XG27) {
114 unsigned char temp;
115 pVBInfo->MCLKData
116 = (struct SiS_MCLKData *) XGI27New_MCLKData;
117 pVBInfo->CR40 = XGI27_cr41;
118 pVBInfo->pXGINew_CR97 = &XG27_CR97;
119 pVBInfo->pSR36 = &XG27_SR36;
120 pVBInfo->pCR8F = &XG27_CR8F;
121 pVBInfo->pCRD0 = XG27_CRD0;
122 pVBInfo->pCRDE = XG27_CRDE;
123 pVBInfo->pSR40 = &XG27_SR40;
124 pVBInfo->pSR41 = &XG27_SR41;
125 pVBInfo->SR15 = XG27_SR13;
127 /*Z11m DDR*/
128 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
129 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
130 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
131 pVBInfo->pXGINew_CR97 = &Z11m_CR97;
134 if (ChipType >= XG20) {
135 pVBInfo->pDVOSetting = &XG21_DVOSetting;
136 pVBInfo->pCR2E = &XG21_CR2E;
137 pVBInfo->pCR2F = &XG21_CR2F;
138 pVBInfo->pCR46 = &XG21_CR46;
139 pVBInfo->pCR47 = &XG21_CR47;
144 static void XGI_SetSeqRegs(unsigned short ModeNo,
145 unsigned short ModeIdIndex,
146 struct vb_device_info *pVBInfo)
148 unsigned char tempah, SRdata;
149 unsigned short i, modeflag;
151 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
153 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
154 tempah = pVBInfo->StandTable->SR[0];
156 i = XGI_SetCRT2ToLCDA;
157 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
158 tempah |= 0x01;
159 } else {
160 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
161 if (pVBInfo->VBInfo & SetInSlaveMode)
162 tempah |= 0x01;
166 tempah |= 0x20; /* screen off */
167 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
169 for (i = 02; i <= 04; i++) {
170 /* Get SR2,3,4 from file */
171 SRdata = pVBInfo->StandTable->SR[i - 1];
172 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
176 static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
177 struct vb_device_info *pVBInfo)
179 unsigned char CRTCdata;
180 unsigned short i;
182 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
183 CRTCdata &= 0x7f;
184 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
186 for (i = 0; i <= 0x18; i++) {
187 /* Get CRTC from file */
188 CRTCdata = pVBInfo->StandTable->CRTC[i];
189 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
193 static void XGI_SetATTRegs(unsigned short ModeNo,
194 unsigned short ModeIdIndex,
195 struct vb_device_info *pVBInfo)
197 unsigned char ARdata;
198 unsigned short i, modeflag;
200 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
202 for (i = 0; i <= 0x13; i++) {
203 ARdata = pVBInfo->StandTable->ATTR[i];
204 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
205 if (i == 0x13) {
206 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
207 ARdata = 0;
208 } else {
209 if (pVBInfo->VBInfo & (SetCRT2ToTV
210 | SetCRT2ToLCD)) {
211 if (pVBInfo->VBInfo &
212 SetInSlaveMode)
213 ARdata = 0;
219 inb(pVBInfo->P3da); /* reset 3da */
220 outb(i, pVBInfo->P3c0); /* set index */
221 outb(ARdata, pVBInfo->P3c0); /* set data */
224 inb(pVBInfo->P3da); /* reset 3da */
225 outb(0x14, pVBInfo->P3c0); /* set index */
226 outb(0x00, pVBInfo->P3c0); /* set data */
227 inb(pVBInfo->P3da); /* Enable Attribute */
228 outb(0x20, pVBInfo->P3c0);
231 static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
233 unsigned char GRdata;
234 unsigned short i;
236 for (i = 0; i <= 0x08; i++) {
237 /* Get GR from file */
238 GRdata = pVBInfo->StandTable->GRC[i];
239 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
242 if (pVBInfo->ModeType > ModeVGA) {
243 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
244 GRdata &= 0xBF; /* 256 color disable */
245 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
249 static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
251 unsigned short i;
253 for (i = 0x0A; i <= 0x0E; i++)
254 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
257 static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
260 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
261 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
262 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
264 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
265 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
266 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
268 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
269 return 0;
272 static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
273 unsigned short ModeIdIndex,
274 unsigned short RefreshRateTableIndex, unsigned short *i,
275 struct vb_device_info *pVBInfo)
277 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
279 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
280 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
281 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
282 tempax = 0;
284 if (pVBInfo->IF_DEF_LVDS == 0) {
285 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
286 tempax |= SupportRAMDAC2;
288 if (pVBInfo->VBType & VB_XGI301C)
289 tempax |= SupportCRT2in301C;
292 /* 301b */
293 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
294 tempax |= SupportLCD;
296 if (pVBInfo->LCDResInfo != Panel_1280x1024) {
297 if (pVBInfo->LCDResInfo != Panel_1280x960) {
298 if (pVBInfo->LCDInfo &
299 LCDNonExpanding) {
300 if (resinfo >= 9) {
301 tempax = 0;
302 return 0;
309 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
310 if ((pVBInfo->VBType & VB_SIS301LV) &&
311 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
312 tempax |= SupportYPbPr750p;
313 if (pVBInfo->VBInfo & SetInSlaveMode) {
314 if (resinfo == 4)
315 return 0;
317 if (resinfo == 3)
318 return 0;
320 if (resinfo > 7)
321 return 0;
323 } else {
324 tempax |= SupportHiVision;
325 if (pVBInfo->VBInfo & SetInSlaveMode) {
326 if (resinfo == 4)
327 return 0;
329 if (resinfo == 3) {
330 if (pVBInfo->SetFlag
331 & TVSimuMode)
332 return 0;
335 if (resinfo > 7)
336 return 0;
339 } else {
340 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
341 SetCRT2ToSVIDEO |
342 SetCRT2ToSCART |
343 SetCRT2ToYPbPr525750 |
344 SetCRT2ToHiVision)) {
345 tempax |= SupportTV;
347 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
348 | VB_SIS301LV | VB_SIS302LV
349 | VB_XGI301C)) {
350 tempax |= SupportTV1024;
353 if (!(pVBInfo->VBInfo & TVSetPAL)) {
354 if (modeflag & NoSupportSimuTV) {
355 if (pVBInfo->VBInfo &
356 SetInSlaveMode) {
357 if (!(pVBInfo->VBInfo &
358 SetNotSimuMode)) {
359 return 0;
366 } else { /* for LVDS */
367 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
368 tempax |= SupportLCD;
370 if (resinfo > 0x08)
371 return 0; /* 1024x768 */
373 if (pVBInfo->LCDResInfo < Panel_1024x768) {
374 if (resinfo > 0x07)
375 return 0; /* 800x600 */
377 if (resinfo == 0x04)
378 return 0; /* 512x384 */
383 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
384 tempbx; (*i)--) {
385 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
386 Ext_InfoFlag;
387 if (infoflag & tempax)
388 return 1;
390 if ((*i) == 0)
391 break;
394 for ((*i) = 0;; (*i)++) {
395 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
396 Ext_InfoFlag;
397 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
398 != tempbx) {
399 return 0;
402 if (infoflag & tempax)
403 return 1;
405 return 1;
408 static void XGI_SetSync(unsigned short RefreshRateTableIndex,
409 struct vb_device_info *pVBInfo)
411 unsigned short sync, temp;
413 /* di+0x00 */
414 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
415 sync &= 0xC0;
416 temp = 0x2F;
417 temp |= sync;
418 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
421 static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
422 struct xgi_hw_device_info *HwDeviceExtension)
424 unsigned char data, data1, pushax;
425 unsigned short i, j;
427 /* unlock cr0-7 */
428 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
429 data &= 0x7F;
430 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
432 data = pVBInfo->TimingH[0].data[0];
433 xgifb_reg_set(pVBInfo->P3d4, 0, data);
435 for (i = 0x01; i <= 0x04; i++) {
436 data = pVBInfo->TimingH[0].data[i];
437 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
440 for (i = 0x05; i <= 0x06; i++) {
441 data = pVBInfo->TimingH[0].data[i];
442 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
445 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
446 j &= 0x1F;
447 data = pVBInfo->TimingH[0].data[7];
448 data &= 0xE0;
449 data |= j;
450 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
452 if (HwDeviceExtension->jChipType >= XG20) {
453 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
454 data = data - 1;
455 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
456 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
457 data1 = data;
458 data1 &= 0xE0;
459 data &= 0x1F;
460 if (data == 0) {
461 pushax = data;
462 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
463 0x0c);
464 data &= 0xFB;
465 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
466 data = pushax;
468 data = data - 1;
469 data |= data1;
470 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
471 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
472 data = data >> 5;
473 data = data + 3;
474 if (data > 7)
475 data = data - 7;
476 data = data << 5;
477 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
481 static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
482 unsigned short ModeNo,
483 struct vb_device_info *pVBInfo)
485 unsigned char data;
486 unsigned short i, j;
488 for (i = 0x00; i <= 0x01; i++) {
489 data = pVBInfo->TimingV[0].data[i];
490 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
493 for (i = 0x02; i <= 0x03; i++) {
494 data = pVBInfo->TimingV[0].data[i];
495 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
498 for (i = 0x04; i <= 0x05; i++) {
499 data = pVBInfo->TimingV[0].data[i];
500 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
503 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
504 j &= 0xC0;
505 data = pVBInfo->TimingV[0].data[6];
506 data &= 0x3F;
507 data |= j;
508 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
510 data = pVBInfo->TimingV[0].data[6];
511 data &= 0x80;
512 data = data >> 2;
514 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
515 i &= DoubleScanMode;
516 if (i)
517 data |= 0x80;
519 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
520 j &= 0x5F;
521 data |= j;
522 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
525 static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
526 unsigned short RefreshRateTableIndex,
527 struct vb_device_info *pVBInfo,
528 struct xgi_hw_device_info *HwDeviceExtension)
530 unsigned char index, data;
531 unsigned short i;
533 /* Get index */
534 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
535 index = index & IndexMask;
537 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
538 data &= 0x7F;
539 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
541 for (i = 0; i < 8; i++)
542 pVBInfo->TimingH[0].data[i]
543 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
545 for (i = 0; i < 7; i++)
546 pVBInfo->TimingV[0].data[i]
547 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
549 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
551 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
553 if (pVBInfo->ModeType > 0x03)
554 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
557 /* --------------------------------------------------------------------- */
558 /* Function : XGI_SetXG21CRTC */
559 /* Input : Stand or enhance CRTC table */
560 /* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
561 /* Description : Set LCD timing */
562 /* --------------------------------------------------------------------- */
563 static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
564 unsigned short RefreshRateTableIndex,
565 struct vb_device_info *pVBInfo)
567 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
568 unsigned short Temp1, Temp2, Temp3;
570 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
571 /* Tempax: CR4 HRS */
572 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
573 Tempcx = Tempax; /* Tempcx: HRS */
574 /* SR2E[7:0]->HRS */
575 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
577 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
578 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
579 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
580 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
581 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
583 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
584 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
586 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
587 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
588 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
589 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
591 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
592 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
594 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
595 if (Tempax < Tempcx) /* HRE < HRS */
596 Temp2 |= 0x40; /* Temp2 + 0x40 */
598 Temp2 &= 0xFF;
599 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
600 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
601 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
602 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
603 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
604 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
605 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
607 /* CR10 VRS */
608 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
609 Tempbx = Tempax; /* Tempbx: VRS */
610 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
611 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
612 /* CR7[2][7] VRE */
613 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
614 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
615 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
616 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
617 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
618 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
620 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
621 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
622 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
623 Tempax &= 0x80;
624 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
625 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
626 /* Tempax: SRA */
627 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
628 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
629 Temp2 = Tempax;
630 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
631 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
633 /* Tempax: CR11 VRE */
634 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
635 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
636 /* Tempbx: SRA */
637 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
638 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
639 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
640 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
641 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
642 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
644 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
645 if (Tempax < Temp3) /* VRE < VRS */
646 Temp2 |= 0x20; /* VRE + 0x20 */
648 Temp2 &= 0xFF;
649 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
650 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
651 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
652 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
653 Tempbx = (unsigned char) Temp1;
654 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
655 Tempax &= 0x7F;
656 /* SR3F D[7:2]->VRE D[1:0]->VRS */
657 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
660 static void XGI_SetXG27CRTC(unsigned short ModeNo,
661 unsigned short ModeIdIndex,
662 unsigned short RefreshRateTableIndex,
663 struct vb_device_info *pVBInfo)
665 unsigned short index, Tempax, Tempbx, Tempcx;
667 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
668 /* Tempax: CR4 HRS */
669 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
670 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
671 /* SR2E[7:0]->HRS */
672 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
674 /* SR0B */
675 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
676 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
677 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
679 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
680 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
681 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
683 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
684 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
685 Tempax <<= 3; /* Tempax[5]: HRE[5] */
686 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
688 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
689 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
691 /* Tempax: CR4 HRS */
692 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
693 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
694 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
695 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
697 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
698 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
699 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
700 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
701 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
702 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
703 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
705 /* CR10 VRS */
706 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
707 /* SR34[7:0]->VRS[7:0] */
708 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
710 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
711 /* CR7[7][2] VRS[9][8] */
712 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
713 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
714 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
715 Tempax >>= 2; /* Tempax[0]: VRS[8] */
716 /* SR35[0]: VRS[8] */
717 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
718 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
719 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
720 /* Tempax: SR0A */
721 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
722 Tempax &= 0x08; /* SR0A[3] VRS[10] */
723 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
725 /* Tempax: CR11 VRE */
726 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
727 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
728 /* Tempbx: SR0A */
729 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
730 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
731 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
732 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
733 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
734 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
735 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
737 if (Tempbx <= Tempcx) /* VRE <= VRS */
738 Tempbx |= 0x20; /* VRE + 0x20 */
740 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
741 Tempax = (Tempbx << 2) & 0xFF;
742 /* SR3F[7:2]:VRE[5:0] */
743 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
744 Tempax = Tempcx >> 8;
745 /* SR35[2:0]:VRS[10:8] */
746 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
749 static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
751 unsigned char temp;
753 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
754 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
755 temp = (temp & 3) << 6;
756 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
757 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
758 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
759 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
763 static void xgifb_set_lcd(int chip_id,
764 struct vb_device_info *pVBInfo,
765 unsigned short RefreshRateTableIndex,
766 unsigned short ModeNo)
768 unsigned short Data, Temp;
769 unsigned short XGI_P3cc;
771 XGI_P3cc = pVBInfo->P3cc;
773 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
774 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
775 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
776 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
778 if (chip_id == XG27) {
779 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
780 if ((Temp & 0x03) == 0) { /* dual 12 */
781 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
782 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
786 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
787 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
788 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
789 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
790 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
793 if (chip_id == XG27) {
794 XGI_SetXG27FPBits(pVBInfo);
795 } else {
796 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
797 if (Temp & 0x01) {
798 /* 18 bits FP */
799 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
800 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
804 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
806 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
807 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
809 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
810 if (Data & 0x4000)
811 /* Hsync polarity */
812 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
813 if (Data & 0x8000)
814 /* Vsync polarity */
815 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
818 /* --------------------------------------------------------------------- */
819 /* Function : XGI_UpdateXG21CRTC */
820 /* Input : */
821 /* Output : CRT1 CRTC */
822 /* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
823 /* --------------------------------------------------------------------- */
824 static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
825 struct vb_device_info *pVBInfo,
826 unsigned short RefreshRateTableIndex)
828 int index = -1;
830 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
831 if (ModeNo == 0x2E &&
832 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
833 RES640x480x60))
834 index = 12;
835 else if (ModeNo == 0x2E && (pVBInfo->RefIndex[RefreshRateTableIndex].
836 Ext_CRT1CRTC == RES640x480x72))
837 index = 13;
838 else if (ModeNo == 0x2F)
839 index = 14;
840 else if (ModeNo == 0x50)
841 index = 15;
842 else if (ModeNo == 0x59)
843 index = 16;
845 if (index != -1) {
846 xgifb_reg_set(pVBInfo->P3d4, 0x02,
847 pVBInfo->UpdateCRT1[index].CR02);
848 xgifb_reg_set(pVBInfo->P3d4, 0x03,
849 pVBInfo->UpdateCRT1[index].CR03);
850 xgifb_reg_set(pVBInfo->P3d4, 0x15,
851 pVBInfo->UpdateCRT1[index].CR15);
852 xgifb_reg_set(pVBInfo->P3d4, 0x16,
853 pVBInfo->UpdateCRT1[index].CR16);
857 static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
858 unsigned short ModeNo, unsigned short ModeIdIndex,
859 unsigned short RefreshRateTableIndex,
860 struct vb_device_info *pVBInfo)
862 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
864 unsigned char data;
866 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
868 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
869 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
870 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
872 if (modeflag & HalfDCLK)
873 tempax = tempax >> 1;
875 if (modeflag & HalfDCLK)
876 tempax = tempax << 1;
878 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
880 if (temp & InterlaceMode)
881 tempbx = tempbx >> 1;
883 if (modeflag & DoubleScanMode)
884 tempbx = tempbx << 1;
886 tempcx = 8;
888 tempax /= tempcx;
889 tempax -= 1;
890 tempbx -= 1;
891 tempcx = tempax;
892 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
893 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
894 data &= 0x7F;
895 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
896 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
897 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
898 (unsigned short) ((tempcx & 0x0ff00) >> 10));
899 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
900 tempax = 0;
901 tempbx = tempbx >> 8;
903 if (tempbx & 0x01)
904 tempax |= 0x02;
906 if (tempbx & 0x02)
907 tempax |= 0x40;
909 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
910 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
911 data &= 0xFF;
912 tempax = 0;
914 if (tempbx & 0x04)
915 tempax |= 0x02;
917 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
918 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
921 static void XGI_SetCRT1Offset(unsigned short ModeNo,
922 unsigned short ModeIdIndex,
923 unsigned short RefreshRateTableIndex,
924 struct xgi_hw_device_info *HwDeviceExtension,
925 struct vb_device_info *pVBInfo)
927 unsigned short temp, ah, al, temp2, i, DisplayUnit;
929 /* GetOffset */
930 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
931 temp = temp >> 8;
932 temp = pVBInfo->ScreenOffset[temp];
934 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
935 temp2 &= InterlaceMode;
937 if (temp2)
938 temp = temp << 1;
940 temp2 = pVBInfo->ModeType - ModeEGA;
942 switch (temp2) {
943 case 0:
944 temp2 = 1;
945 break;
946 case 1:
947 temp2 = 2;
948 break;
949 case 2:
950 temp2 = 4;
951 break;
952 case 3:
953 temp2 = 4;
954 break;
955 case 4:
956 temp2 = 6;
957 break;
958 case 5:
959 temp2 = 8;
960 break;
961 default:
962 break;
965 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
966 temp = temp * temp2 + temp2 / 2;
967 else
968 temp *= temp2;
970 /* SetOffset */
971 DisplayUnit = temp;
972 temp2 = temp;
973 temp = temp >> 8; /* ah */
974 temp &= 0x0F;
975 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
976 i &= 0xF0;
977 i |= temp;
978 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
980 temp = (unsigned char) temp2;
981 temp &= 0xFF; /* al */
982 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
984 /* SetDisplayUnit */
985 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
986 temp2 &= InterlaceMode;
987 if (temp2)
988 DisplayUnit >>= 1;
990 DisplayUnit = DisplayUnit << 5;
991 ah = (DisplayUnit & 0xff00) >> 8;
992 al = DisplayUnit & 0x00ff;
993 if (al == 0)
994 ah += 1;
995 else
996 ah += 2;
998 if (HwDeviceExtension->jChipType >= XG20)
999 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1000 ah -= 1;
1002 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
1005 static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1006 unsigned short ModeIdIndex,
1007 unsigned short RefreshRateTableIndex,
1008 struct xgi_hw_device_info *HwDeviceExtension,
1009 struct vb_device_info *pVBInfo)
1011 unsigned short CRT2Index, VCLKIndex;
1012 unsigned short modeflag, resinfo;
1014 /* si+Ext_ResInfo */
1015 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1016 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1017 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1019 if (pVBInfo->IF_DEF_LVDS == 0) {
1020 CRT2Index = CRT2Index >> 6; /* for LCD */
1021 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
1022 if (pVBInfo->LCDResInfo != Panel_1024x768)
1023 VCLKIndex = VCLK108_2_315 + 5; /* LCDXlat2VCLK */
1024 else
1025 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
1026 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
1027 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1028 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
1029 } else {
1030 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
1033 if (pVBInfo->SetFlag & TVSimuMode) {
1034 if (modeflag & Charx8Dot) {
1035 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
1036 } else {
1037 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
1041 /* 301lv */
1042 if ((pVBInfo->VBType & VB_SIS301LV) &&
1043 !(pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
1044 if (pVBInfo->VBExtInfo == YPbPr750p)
1045 VCLKIndex = XGI_YPbPr750pVCLK;
1046 else if (pVBInfo->VBExtInfo == YPbPr525p)
1047 VCLKIndex = YPbPr525pVCLK;
1048 else if (pVBInfo->SetFlag & RPLLDIV2XO)
1049 VCLKIndex = YPbPr525iVCLK_2;
1050 else
1051 VCLKIndex = YPbPr525iVCLK;
1053 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
1054 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1055 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
1056 } else {
1057 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
1059 } else { /* for CRT2 */
1060 /* di+Ext_CRTVCLK */
1061 VCLKIndex = pVBInfo->RefIndex[RefreshRateTableIndex].
1062 Ext_CRTVCLK;
1063 VCLKIndex &= IndexMask;
1065 } else { /* LVDS */
1066 if ((pVBInfo->LCDResInfo == Panel_800x600) ||
1067 (pVBInfo->LCDResInfo == Panel_320x480))
1068 VCLKIndex = VCLK40; /* LVDSXlat1VCLK */
1069 else
1070 VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */
1073 return VCLKIndex;
1076 static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1077 unsigned short ModeIdIndex,
1078 struct xgi_hw_device_info *HwDeviceExtension,
1079 unsigned short RefreshRateTableIndex,
1080 struct vb_device_info *pVBInfo)
1082 unsigned char index, data;
1083 unsigned short vclkindex;
1085 if (pVBInfo->IF_DEF_LVDS == 1) {
1086 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1087 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1088 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1089 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
1090 pVBInfo->VCLKData[index].SR2B);
1091 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
1092 pVBInfo->VCLKData[index].SR2C);
1093 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1094 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1095 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1096 & XGI_SetCRT2ToLCDA)) {
1097 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1098 RefreshRateTableIndex, HwDeviceExtension,
1099 pVBInfo);
1100 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1101 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1102 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
1103 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
1104 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
1105 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1106 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1107 } else {
1108 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1109 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1110 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1111 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
1112 pVBInfo->VCLKData[index].SR2B);
1113 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
1114 pVBInfo->VCLKData[index].SR2C);
1115 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1118 if (HwDeviceExtension->jChipType >= XG20) {
1119 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1120 HalfDCLK) {
1121 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
1122 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
1123 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
1124 index = data;
1125 index &= 0xE0;
1126 data &= 0x1F;
1127 data = data << 1;
1128 data += 1;
1129 data |= index;
1130 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1135 static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1137 unsigned char temp;
1139 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1140 temp = (temp & 1) << 6;
1141 /* SR06[6] 18bit Dither */
1142 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1143 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1144 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1148 static void XGI_SetCRT1FIFO(unsigned short ModeNo,
1149 struct xgi_hw_device_info *HwDeviceExtension,
1150 struct vb_device_info *pVBInfo)
1152 unsigned short data;
1154 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1155 data &= 0xfe;
1156 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
1158 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1159 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1160 data &= 0xC0;
1161 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1162 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1163 data |= 0x01;
1164 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
1166 if (HwDeviceExtension->jChipType == XG21)
1167 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
1170 static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1171 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1172 struct vb_device_info *pVBInfo)
1174 unsigned short data, data2 = 0;
1175 short VCLK;
1177 unsigned char index;
1179 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1180 index &= IndexMask;
1181 VCLK = pVBInfo->VCLKData[index].CLOCK;
1183 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
1184 data &= 0xf3;
1185 if (VCLK >= 200)
1186 data |= 0x0c; /* VCLK > 200 */
1188 if (HwDeviceExtension->jChipType >= XG20)
1189 data &= ~0x04; /* 2 pixel mode */
1191 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
1193 if (HwDeviceExtension->jChipType < XG20) {
1194 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
1195 data &= 0xE7;
1196 if (VCLK < 200)
1197 data |= 0x10;
1198 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
1201 data2 = 0x00;
1203 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
1204 if (HwDeviceExtension->jChipType >= XG27)
1205 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
1209 static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
1210 unsigned short ModeNo, unsigned short ModeIdIndex,
1211 unsigned short RefreshRateTableIndex,
1212 struct vb_device_info *pVBInfo)
1214 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1215 xres;
1217 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1218 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1220 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
1221 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
1223 data = infoflag;
1224 data2 = 0;
1225 data2 |= 0x02;
1226 data3 = pVBInfo->ModeType - ModeVGA;
1227 data3 = data3 << 2;
1228 data2 |= data3;
1229 data &= InterlaceMode;
1231 if (data)
1232 data2 |= 0x20;
1234 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
1235 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1236 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
1238 data = 0x0000;
1239 if (infoflag & InterlaceMode) {
1240 if (xres == 1024)
1241 data = 0x0035;
1242 else if (xres == 1280)
1243 data = 0x0048;
1246 data2 = data & 0x00FF;
1247 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
1248 data2 = (data & 0xFF00) >> 8;
1249 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
1251 if (modeflag & HalfDCLK)
1252 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
1254 data2 = 0;
1256 if (modeflag & LineCompareOff)
1257 data2 |= 0x08;
1259 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
1260 data = 0x60;
1261 data = data ^ 0x60;
1262 data = data ^ 0xA0;
1263 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
1265 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1266 pVBInfo);
1268 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1270 if (HwDeviceExtension->jChipType == XG27) {
1271 if (data & 0x40)
1272 data = 0x2c;
1273 else
1274 data = 0x6c;
1275 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1276 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
1277 } else if (HwDeviceExtension->jChipType >= XG20) {
1278 if (data & 0x40)
1279 data = 0x33;
1280 else
1281 data = 0x73;
1282 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1283 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
1284 } else {
1285 if (data & 0x40)
1286 data = 0x2c;
1287 else
1288 data = 0x6c;
1289 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1294 static void XGI_WriteDAC(unsigned short dl,
1295 unsigned short ah,
1296 unsigned short al,
1297 unsigned short dh,
1298 struct vb_device_info *pVBInfo)
1300 unsigned short temp, bh, bl;
1302 bh = ah;
1303 bl = al;
1305 if (dl != 0) {
1306 temp = bh;
1307 bh = dh;
1308 dh = temp;
1309 if (dl == 1) {
1310 temp = bl;
1311 bl = dh;
1312 dh = temp;
1313 } else {
1314 temp = bl;
1315 bl = bh;
1316 bh = temp;
1319 outb((unsigned short) dh, pVBInfo->P3c9);
1320 outb((unsigned short) bh, pVBInfo->P3c9);
1321 outb((unsigned short) bl, pVBInfo->P3c9);
1324 static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
1325 struct vb_device_info *pVBInfo)
1327 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1328 const unsigned short *table = XGINew_VGA_DAC;
1330 outb(0xFF, pVBInfo->P3c6);
1331 outb(0x00, pVBInfo->P3c8);
1333 for (i = 0; i < 16; i++) {
1334 data = table[i];
1336 for (k = 0; k < 3; k++) {
1337 data2 = 0;
1339 if (data & 0x01)
1340 data2 = 0x2A;
1342 if (data & 0x02)
1343 data2 += 0x15;
1345 outb(data2, pVBInfo->P3c9);
1346 data = data >> 2;
1350 for (i = 16; i < 32; i++) {
1351 data = table[i];
1353 for (k = 0; k < 3; k++)
1354 outb(data, pVBInfo->P3c9);
1357 si = 32;
1359 for (m = 0; m < 9; m++) {
1360 di = si;
1361 bx = si + 0x04;
1362 dl = 0;
1364 for (n = 0; n < 3; n++) {
1365 for (o = 0; o < 5; o++) {
1366 dh = table[si];
1367 ah = table[di];
1368 al = table[bx];
1369 si++;
1370 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1373 si -= 2;
1375 for (o = 0; o < 3; o++) {
1376 dh = table[bx];
1377 ah = table[di];
1378 al = table[si];
1379 si--;
1380 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1383 dl++;
1386 si += 5;
1390 static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1391 unsigned short ModeIdIndex,
1392 struct vb_device_info *pVBInfo)
1394 unsigned short resindex, xres, yres, modeflag;
1396 /* si+Ext_ResInfo */
1397 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1399 /* si+Ext_ResInfo */
1400 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1402 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1403 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1405 if (modeflag & HalfDCLK)
1406 xres = xres << 1;
1408 if (modeflag & DoubleScanMode)
1409 yres = yres << 1;
1411 if (xres == 720)
1412 xres = 640;
1414 pVBInfo->VGAHDE = xres;
1415 pVBInfo->HDE = xres;
1416 pVBInfo->VGAVDE = yres;
1417 pVBInfo->VDE = yres;
1420 static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1421 unsigned short ModeIdIndex,
1422 unsigned short RefreshRateTableIndex,
1423 struct vb_device_info *pVBInfo)
1425 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1427 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1429 tempbx = BX;
1431 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1432 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1434 tempal = tempal & 0x0f;
1436 if (tempbx <= 1) { /* ExpLink */
1437 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1439 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
1440 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1441 Ext_CRT2CRTC2;
1444 if (tempbx & 0x01)
1445 tempal = (tempal >> 4);
1447 tempal = (tempal & 0x0f);
1450 tempcx = LCDLenList[tempbx];
1452 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1453 if ((tempbx == 5) || (tempbx) == 7)
1454 tempcx = LCDDesDataLen2;
1455 else if ((tempbx == 3) || (tempbx == 8))
1456 tempcx = LVDSDesDataLen2;
1459 switch (tempbx) {
1460 case 0:
1461 case 1:
1462 tempdi = xgifb_epllcd_crt1;
1463 break;
1464 case 2:
1465 tempdi = XGI_EPLLCDDataPtr;
1466 break;
1467 case 3:
1468 tempdi = XGI_EPLLCDDesDataPtr;
1469 break;
1470 case 4:
1471 tempdi = XGI_LCDDataTable;
1472 break;
1473 case 5:
1474 tempdi = XGI_LCDDesDataTable;
1475 break;
1476 case 6:
1477 tempdi = XGI_EPLCHLCDRegPtr;
1478 break;
1479 case 7:
1480 case 8:
1481 case 9:
1482 tempdi = NULL;
1483 break;
1484 default:
1485 break;
1488 if (tempdi == NULL) /* OEMUtil */
1489 return NULL;
1491 table = tempbx;
1492 i = 0;
1494 while (tempdi[i].PANELID != 0xff) {
1495 tempdx = pVBInfo->LCDResInfo;
1496 if (tempbx & 0x0080) { /* OEMUtil */
1497 tempbx &= (~0x0080);
1498 tempdx = pVBInfo->LCDTypeInfo;
1501 if (pVBInfo->LCDInfo & EnableScalingLCD)
1502 tempdx &= (~PanelResInfo);
1504 if (tempdi[i].PANELID == tempdx) {
1505 tempbx = tempdi[i].MASK;
1506 tempdx = pVBInfo->LCDInfo;
1508 if (modeflag & HalfDCLK)
1509 tempdx |= SetLCDLowResolution;
1511 tempbx &= tempdx;
1512 if (tempbx == tempdi[i].CAP)
1513 break;
1515 i++;
1518 if (table == 0) {
1519 switch (tempdi[i].DATAPTR) {
1520 case 0:
1521 return &XGI_LVDSCRT11024x768_1_H[tempal];
1522 break;
1523 case 1:
1524 return &XGI_LVDSCRT11024x768_2_H[tempal];
1525 break;
1526 case 2:
1527 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1528 break;
1529 case 3:
1530 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1531 break;
1532 case 4:
1533 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1534 break;
1535 case 5:
1536 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1537 break;
1538 case 6:
1539 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1540 break;
1541 case 7:
1542 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1543 break;
1544 case 8:
1545 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1546 break;
1547 case 9:
1548 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1549 break;
1550 case 10:
1551 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
1552 break;
1553 default:
1554 break;
1556 } else if (table == 1) {
1557 switch (tempdi[i].DATAPTR) {
1558 case 0:
1559 return &XGI_LVDSCRT11024x768_1_V[tempal];
1560 break;
1561 case 1:
1562 return &XGI_LVDSCRT11024x768_2_V[tempal];
1563 break;
1564 case 2:
1565 return &XGI_LVDSCRT11280x1024_1_V[tempal];
1566 break;
1567 case 3:
1568 return &XGI_LVDSCRT11280x1024_2_V[tempal];
1569 break;
1570 case 4:
1571 return &XGI_LVDSCRT11400x1050_1_V[tempal];
1572 break;
1573 case 5:
1574 return &XGI_LVDSCRT11400x1050_2_V[tempal];
1575 break;
1576 case 6:
1577 return &XGI_LVDSCRT11600x1200_1_V[tempal];
1578 break;
1579 case 7:
1580 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
1581 break;
1582 case 8:
1583 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
1584 break;
1585 case 9:
1586 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
1587 break;
1588 case 10:
1589 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
1590 break;
1591 default:
1592 break;
1594 } else if (table == 2) {
1595 switch (tempdi[i].DATAPTR) {
1596 case 0:
1597 return &XGI_LVDS1024x768Data_1[tempal];
1598 break;
1599 case 1:
1600 return &XGI_LVDS1024x768Data_2[tempal];
1601 break;
1602 case 2:
1603 return &XGI_LVDS1280x1024Data_1[tempal];
1604 break;
1605 case 3:
1606 return &XGI_LVDS1280x1024Data_2[tempal];
1607 break;
1608 case 4:
1609 return &XGI_LVDS1400x1050Data_1[tempal];
1610 break;
1611 case 5:
1612 return &XGI_LVDS1400x1050Data_2[tempal];
1613 break;
1614 case 6:
1615 return &XGI_LVDS1600x1200Data_1[tempal];
1616 break;
1617 case 7:
1618 return &XGI_LVDSNoScalingData[tempal];
1619 break;
1620 case 8:
1621 return &XGI_LVDS1024x768Data_1x75[tempal];
1622 break;
1623 case 9:
1624 return &XGI_LVDS1024x768Data_2x75[tempal];
1625 break;
1626 case 10:
1627 return &XGI_LVDS1280x1024Data_1x75[tempal];
1628 break;
1629 case 11:
1630 return &XGI_LVDS1280x1024Data_2x75[tempal];
1631 break;
1632 case 12:
1633 return &XGI_LVDSNoScalingDatax75[tempal];
1634 break;
1635 default:
1636 break;
1638 } else if (table == 3) {
1639 switch (tempdi[i].DATAPTR) {
1640 case 0:
1641 return &XGI_LVDS1024x768Des_1[tempal];
1642 break;
1643 case 1:
1644 return &XGI_LVDS1024x768Des_3[tempal];
1645 break;
1646 case 2:
1647 return &XGI_LVDS1024x768Des_2[tempal];
1648 break;
1649 case 3:
1650 return &XGI_LVDS1280x1024Des_1[tempal];
1651 break;
1652 case 4:
1653 return &XGI_LVDS1280x1024Des_2[tempal];
1654 break;
1655 case 5:
1656 return &XGI_LVDS1400x1050Des_1[tempal];
1657 break;
1658 case 6:
1659 return &XGI_LVDS1400x1050Des_2[tempal];
1660 break;
1661 case 7:
1662 return &XGI_LVDS1600x1200Des_1[tempal];
1663 break;
1664 case 8:
1665 return &XGI_LVDSNoScalingDesData[tempal];
1666 break;
1667 case 9:
1668 return &XGI_LVDS1024x768Des_1x75[tempal];
1669 break;
1670 case 10:
1671 return &XGI_LVDS1024x768Des_3x75[tempal];
1672 break;
1673 case 11:
1674 return &XGI_LVDS1024x768Des_2x75[tempal];
1675 break;
1676 case 12:
1677 return &XGI_LVDS1280x1024Des_1x75[tempal];
1678 break;
1679 case 13:
1680 return &XGI_LVDS1280x1024Des_2x75[tempal];
1681 break;
1682 case 14:
1683 return &XGI_LVDSNoScalingDesDatax75[tempal];
1684 break;
1685 default:
1686 break;
1688 } else if (table == 4) {
1689 switch (tempdi[i].DATAPTR) {
1690 case 0:
1691 return &XGI_ExtLCD1024x768Data[tempal];
1692 break;
1693 case 1:
1694 return &XGI_StLCD1024x768Data[tempal];
1695 break;
1696 case 2:
1697 return &XGI_CetLCD1024x768Data[tempal];
1698 break;
1699 case 3:
1700 return &XGI_ExtLCD1280x1024Data[tempal];
1701 break;
1702 case 4:
1703 return &XGI_StLCD1280x1024Data[tempal];
1704 break;
1705 case 5:
1706 return &XGI_CetLCD1280x1024Data[tempal];
1707 break;
1708 case 6:
1709 case 7:
1710 return &xgifb_lcd_1400x1050[tempal];
1711 break;
1712 case 8:
1713 return &XGI_CetLCD1400x1050Data[tempal];
1714 break;
1715 case 9:
1716 return &XGI_ExtLCD1600x1200Data[tempal];
1717 break;
1718 case 10:
1719 return &XGI_StLCD1600x1200Data[tempal];
1720 break;
1721 case 11:
1722 return &XGI_NoScalingData[tempal];
1723 break;
1724 case 12:
1725 return &XGI_ExtLCD1024x768x75Data[tempal];
1726 break;
1727 case 13:
1728 return &XGI_ExtLCD1024x768x75Data[tempal];
1729 break;
1730 case 14:
1731 return &XGI_CetLCD1024x768x75Data[tempal];
1732 break;
1733 case 15:
1734 case 16:
1735 return &xgifb_lcd_1280x1024x75[tempal];
1736 break;
1737 case 17:
1738 return &XGI_CetLCD1280x1024x75Data[tempal];
1739 break;
1740 case 18:
1741 return &XGI_NoScalingDatax75[tempal];
1742 break;
1743 default:
1744 break;
1746 } else if (table == 5) {
1747 switch (tempdi[i].DATAPTR) {
1748 case 0:
1749 return &XGI_ExtLCDDes1024x768Data[tempal];
1750 break;
1751 case 1:
1752 return &XGI_StLCDDes1024x768Data[tempal];
1753 break;
1754 case 2:
1755 return &XGI_CetLCDDes1024x768Data[tempal];
1756 break;
1757 case 3:
1758 if ((pVBInfo->VBType & VB_SIS301LV) ||
1759 (pVBInfo->VBType & VB_SIS302LV))
1760 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
1761 else
1762 return &XGI_ExtLCDDes1280x1024Data[tempal];
1763 break;
1764 case 4:
1765 if ((pVBInfo->VBType & VB_SIS301LV) ||
1766 (pVBInfo->VBType & VB_SIS302LV))
1767 return &XGI_StLCDDLDes1280x1024Data[tempal];
1768 else
1769 return &XGI_StLCDDes1280x1024Data[tempal];
1770 break;
1771 case 5:
1772 if ((pVBInfo->VBType & VB_SIS301LV) ||
1773 (pVBInfo->VBType & VB_SIS302LV))
1774 return &XGI_CetLCDDLDes1280x1024Data[tempal];
1775 else
1776 return &XGI_CetLCDDes1280x1024Data[tempal];
1777 break;
1778 case 6:
1779 case 7:
1780 if ((pVBInfo->VBType & VB_SIS301LV) ||
1781 (pVBInfo->VBType & VB_SIS302LV))
1782 return &xgifb_lcddldes_1400x1050[tempal];
1783 else
1784 return &xgifb_lcddes_1400x1050[tempal];
1785 break;
1786 case 8:
1787 return &XGI_CetLCDDes1400x1050Data[tempal];
1788 break;
1789 case 9:
1790 return &XGI_CetLCDDes1400x1050Data2[tempal];
1791 break;
1792 case 10:
1793 if ((pVBInfo->VBType & VB_SIS301LV) ||
1794 (pVBInfo->VBType & VB_SIS302LV))
1795 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
1796 else
1797 return &XGI_ExtLCDDes1600x1200Data[tempal];
1798 break;
1799 case 11:
1800 if ((pVBInfo->VBType & VB_SIS301LV) ||
1801 (pVBInfo->VBType & VB_SIS302LV))
1802 return &XGI_StLCDDLDes1600x1200Data[tempal];
1803 else
1804 return &XGI_StLCDDes1600x1200Data[tempal];
1805 break;
1806 case 12:
1807 return &XGI_NoScalingDesData[tempal];
1808 break;
1809 case 13:
1810 case 14:
1811 return &xgifb_lcddes_1024x768x75[tempal];
1812 break;
1813 case 15:
1814 return &XGI_CetLCDDes1024x768x75Data[tempal];
1815 break;
1816 case 16:
1817 case 17:
1818 if ((pVBInfo->VBType & VB_SIS301LV) ||
1819 (pVBInfo->VBType & VB_SIS302LV))
1820 return &xgifb_lcddldes_1280x1024x75[tempal];
1821 else
1822 return &xgifb_lcddes_1280x1024x75[tempal];
1823 break;
1824 case 18:
1825 if ((pVBInfo->VBType & VB_SIS301LV) ||
1826 (pVBInfo->VBType & VB_SIS302LV))
1827 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
1828 else
1829 return &XGI_CetLCDDes1280x1024x75Data[tempal];
1830 break;
1831 case 19:
1832 return &XGI_NoScalingDesDatax75[tempal];
1833 break;
1834 default:
1835 break;
1837 } else if (table == 6) {
1838 switch (tempdi[i].DATAPTR) {
1839 case 0:
1840 return &XGI_CH7017LV1024x768[tempal];
1841 break;
1842 case 1:
1843 return &XGI_CH7017LV1400x1050[tempal];
1844 break;
1845 default:
1846 break;
1849 return NULL;
1852 static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
1853 unsigned short ModeIdIndex,
1854 unsigned short RefreshRateTableIndex,
1855 struct vb_device_info *pVBInfo)
1857 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
1858 struct XGI330_TVDataTablStruct *tempdi = NULL;
1860 tempbx = BX;
1861 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1862 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1863 tempal = tempal & 0x3f;
1864 table = tempbx;
1866 switch (tempbx) {
1867 case 0:
1868 tempdi = NULL;
1869 break;
1870 case 1:
1871 tempdi = NULL;
1872 break;
1873 case 2:
1874 case 6:
1875 tempdi = xgifb_chrontel_tv;
1876 break;
1877 case 3:
1878 tempdi = NULL;
1879 break;
1880 case 4:
1881 tempdi = XGI_TVDataTable;
1882 break;
1883 case 5:
1884 tempdi = NULL;
1885 break;
1886 default:
1887 break;
1890 if (tempdi == NULL) /* OEMUtil */
1891 return NULL;
1893 tempdx = pVBInfo->TVInfo;
1895 if (pVBInfo->VBInfo & SetInSlaveMode)
1896 tempdx = tempdx | SetTVLockMode;
1898 if (modeflag & HalfDCLK)
1899 tempdx = tempdx | SetTVLowResolution;
1901 i = 0;
1903 while (tempdi[i].MASK != 0xffff) {
1904 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
1905 break;
1906 i++;
1909 /* 07/05/22 */
1910 if (table == 0x04) {
1911 switch (tempdi[i].DATAPTR) {
1912 case 0:
1913 return &XGI_ExtPALData[tempal];
1914 break;
1915 case 1:
1916 return &XGI_ExtNTSCData[tempal];
1917 break;
1918 case 2:
1919 return &XGI_StPALData[tempal];
1920 break;
1921 case 3:
1922 return &XGI_StNTSCData[tempal];
1923 break;
1924 case 4:
1925 return &XGI_ExtHiTVData[tempal];
1926 break;
1927 case 5:
1928 return &XGI_St2HiTVData[tempal];
1929 break;
1930 case 6:
1931 return &XGI_ExtYPbPr525iData[tempal];
1932 break;
1933 case 7:
1934 return &XGI_ExtYPbPr525pData[tempal];
1935 break;
1936 case 8:
1937 return &XGI_ExtYPbPr750pData[tempal];
1938 break;
1939 case 9:
1940 return &XGI_StYPbPr525iData[tempal];
1941 break;
1942 case 10:
1943 return &XGI_StYPbPr525pData[tempal];
1944 break;
1945 case 11:
1946 return &XGI_StYPbPr750pData[tempal];
1947 break;
1948 case 12: /* avoid system hang */
1949 return &XGI_ExtNTSCData[tempal];
1950 break;
1951 case 13:
1952 return &XGI_St1HiTVData[tempal];
1953 break;
1954 default:
1955 break;
1957 } else if (table == 0x02) {
1958 switch (tempdi[i].DATAPTR) {
1959 case 0:
1960 return &XGI_CHTVUNTSCData[tempal];
1961 break;
1962 case 1:
1963 return &XGI_CHTVONTSCData[tempal];
1964 break;
1965 case 2:
1966 return &XGI_CHTVUPALData[tempal];
1967 break;
1968 case 3:
1969 return &XGI_CHTVOPALData[tempal];
1970 break;
1971 default:
1972 break;
1975 return NULL;
1978 static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
1979 unsigned short RefreshRateTableIndex,
1980 struct vb_device_info *pVBInfo)
1982 unsigned short tempbx;
1983 struct SiS_LVDSData *LCDPtr = NULL;
1985 tempbx = 2;
1987 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
1988 LCDPtr = (struct SiS_LVDSData *)XGI_GetLcdPtr(tempbx,
1989 ModeNo, ModeIdIndex, RefreshRateTableIndex,
1990 pVBInfo);
1991 pVBInfo->VGAHT = LCDPtr->VGAHT;
1992 pVBInfo->VGAVT = LCDPtr->VGAVT;
1993 pVBInfo->HT = LCDPtr->LCDHT;
1994 pVBInfo->VT = LCDPtr->LCDVT;
1997 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
1998 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
1999 | EnableScalingLCD))) {
2000 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
2001 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
2002 pVBInfo->HDE = 1024;
2003 pVBInfo->VDE = 768;
2004 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
2005 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
2006 pVBInfo->HDE = 1280;
2007 pVBInfo->VDE = 1024;
2008 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
2009 pVBInfo->HDE = 1400;
2010 pVBInfo->VDE = 1050;
2011 } else {
2012 pVBInfo->HDE = 1600;
2013 pVBInfo->VDE = 1200;
2019 static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
2020 unsigned short RefreshRateTableIndex,
2021 struct xgi_hw_device_info *HwDeviceExtension,
2022 struct vb_device_info *pVBInfo)
2024 unsigned char index;
2025 unsigned short tempbx, i;
2026 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2027 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
2029 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2030 index = index & IndexMask;
2032 tempbx = 0;
2034 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
2035 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2036 XGI_GetLcdPtr(tempbx, ModeNo,
2037 ModeIdIndex,
2038 RefreshRateTableIndex,
2039 pVBInfo);
2041 for (i = 0; i < 8; i++)
2042 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
2045 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2047 tempbx = 1;
2049 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
2050 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2051 XGI_GetLcdPtr(
2052 tempbx,
2053 ModeNo,
2054 ModeIdIndex,
2055 RefreshRateTableIndex,
2056 pVBInfo);
2057 for (i = 0; i < 7; i++)
2058 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2061 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
2064 static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2066 unsigned char tempal, tempah, tempbl, i;
2068 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
2069 tempal = tempah & 0x0F;
2070 tempah = tempah & 0xF0;
2071 i = 0;
2072 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2074 while (tempbl != 0xFF) {
2075 if (tempbl & 0x80) { /* OEMUtil */
2076 tempal = tempah;
2077 tempbl = tempbl & ~(0x80);
2080 if (tempal == tempbl)
2081 break;
2083 i++;
2085 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2088 return i;
2091 static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2093 unsigned short tempah, tempal, tempbl, i;
2095 tempal = pVBInfo->LCDResInfo;
2096 tempah = pVBInfo->LCDTypeInfo;
2098 i = 0;
2099 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2101 while (tempbl != 0xFF) {
2102 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2103 tempal = tempah;
2104 tempbl &= ~0x80;
2107 if (tempal == tempbl)
2108 break;
2110 i++;
2111 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2114 if (tempbl == 0xFF) {
2115 pVBInfo->LCDResInfo = Panel_1024x768;
2116 pVBInfo->LCDTypeInfo = 0;
2117 i = 0;
2120 return i;
2123 static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2124 unsigned short *VSyncWidth,
2125 struct vb_device_info *pVBInfo)
2127 unsigned short Index;
2129 Index = XGI_GetLCDCapPtr(pVBInfo);
2130 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2131 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2133 return;
2136 static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2137 unsigned short RefreshRateTableIndex,
2138 struct vb_device_info *pVBInfo)
2140 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2141 unsigned long temp, temp1, temp2, temp3, push3;
2142 struct XGI_LCDDesStruct *LCDPtr = NULL;
2143 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
2145 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2146 tempbx = 3;
2147 if (pVBInfo->LCDInfo & EnableScalingLCD)
2148 LCDPtr1 =
2149 (struct XGI330_LCDDataDesStruct2 *)
2150 XGI_GetLcdPtr(
2151 tempbx,
2152 ModeNo,
2153 ModeIdIndex,
2154 RefreshRateTableIndex,
2155 pVBInfo);
2156 else
2157 LCDPtr =
2158 (struct XGI_LCDDesStruct *)
2159 XGI_GetLcdPtr(
2160 tempbx,
2161 ModeNo,
2162 ModeIdIndex,
2163 RefreshRateTableIndex,
2164 pVBInfo);
2166 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2167 push1 = tempbx;
2168 push2 = tempax;
2170 /* GetLCDResInfo */
2171 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
2172 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
2173 tempax = 1024;
2174 tempbx = 768;
2175 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
2176 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
2177 tempax = 1280;
2178 tempbx = 1024;
2179 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
2180 tempax = 1400;
2181 tempbx = 1050;
2182 } else {
2183 tempax = 1600;
2184 tempbx = 1200;
2187 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2188 pVBInfo->HDE = tempax;
2189 pVBInfo->VDE = tempbx;
2190 pVBInfo->VGAHDE = tempax;
2191 pVBInfo->VGAVDE = tempbx;
2194 tempax = pVBInfo->HT;
2196 if (pVBInfo->LCDInfo & EnableScalingLCD)
2197 tempbx = LCDPtr1->LCDHDES;
2198 else
2199 tempbx = LCDPtr->LCDHDES;
2201 tempcx = pVBInfo->HDE;
2202 tempbx = tempbx & 0x0fff;
2203 tempcx += tempbx;
2205 if (tempcx >= tempax)
2206 tempcx -= tempax;
2208 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
2210 tempcx = tempcx >> 3;
2211 tempbx = tempbx >> 3;
2213 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2214 (unsigned short) (tempbx & 0xff));
2215 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2216 (unsigned short) (tempcx & 0xff));
2218 tempax = pVBInfo->HT;
2220 if (pVBInfo->LCDInfo & EnableScalingLCD)
2221 tempbx = LCDPtr1->LCDHRS;
2222 else
2223 tempbx = LCDPtr->LCDHRS;
2225 tempcx = push2;
2227 if (pVBInfo->LCDInfo & EnableScalingLCD)
2228 tempcx = LCDPtr1->LCDHSync;
2230 tempcx += tempbx;
2232 if (tempcx >= tempax)
2233 tempcx -= tempax;
2235 tempax = tempbx & 0x07;
2236 tempax = tempax >> 5;
2237 tempcx = tempcx >> 3;
2238 tempbx = tempbx >> 3;
2240 tempcx &= 0x1f;
2241 tempax |= tempcx;
2243 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2244 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2245 (unsigned short) (tempbx & 0xff));
2247 tempax = pVBInfo->VT;
2248 if (pVBInfo->LCDInfo & EnableScalingLCD)
2249 tempbx = LCDPtr1->LCDVDES;
2250 else
2251 tempbx = LCDPtr->LCDVDES;
2252 tempcx = pVBInfo->VDE;
2254 tempbx = tempbx & 0x0fff;
2255 tempcx += tempbx;
2256 if (tempcx >= tempax)
2257 tempcx -= tempax;
2259 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2260 (unsigned short) (tempbx & 0xff));
2261 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2262 (unsigned short) (tempcx & 0xff));
2264 tempbx = (tempbx >> 8) & 0x07;
2265 tempcx = (tempcx >> 8) & 0x07;
2267 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2268 (unsigned short) ((tempcx << 3)
2269 | tempbx));
2271 tempax = pVBInfo->VT;
2272 if (pVBInfo->LCDInfo & EnableScalingLCD)
2273 tempbx = LCDPtr1->LCDVRS;
2274 else
2275 tempbx = LCDPtr->LCDVRS;
2277 tempcx = push1;
2279 if (pVBInfo->LCDInfo & EnableScalingLCD)
2280 tempcx = LCDPtr1->LCDVSync;
2282 tempcx += tempbx;
2283 if (tempcx >= tempax)
2284 tempcx -= tempax;
2286 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2287 (unsigned short) (tempbx & 0xff));
2288 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2289 (unsigned short) (tempcx & 0x0f));
2291 tempax = ((tempbx >> 8) & 0x07) << 3;
2293 tempbx = pVBInfo->VGAVDE;
2294 if (tempbx != pVBInfo->VDE)
2295 tempax |= 0x40;
2297 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
2298 tempax |= 0x40;
2300 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2301 tempax);
2303 tempcx = pVBInfo->VGAVT;
2304 tempbx = pVBInfo->VDE;
2305 tempax = pVBInfo->VGAVDE;
2306 tempcx -= tempax;
2308 temp = tempax; /* 0430 ylshieh */
2309 temp1 = (temp << 18) / tempbx;
2311 tempdx = (unsigned short) ((temp << 18) % tempbx);
2313 if (tempdx != 0)
2314 temp1 += 1;
2316 temp2 = temp1;
2317 push3 = temp2;
2319 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2320 (unsigned short) (temp2 & 0xff));
2321 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2322 (unsigned short) ((temp2 >> 8) & 0xff));
2324 tempbx = (unsigned short) (temp2 >> 16);
2325 tempax = tempbx & 0x03;
2327 tempbx = pVBInfo->VGAVDE;
2328 if (tempbx == pVBInfo->VDE)
2329 tempax |= 0x04;
2331 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2333 if (pVBInfo->VBType & VB_XGI301C) {
2334 temp2 = push3;
2335 xgifb_reg_set(pVBInfo->Part4Port,
2336 0x3c,
2337 (unsigned short) (temp2 & 0xff));
2338 xgifb_reg_set(pVBInfo->Part4Port,
2339 0x3b,
2340 (unsigned short) ((temp2 >> 8) &
2341 0xff));
2342 tempbx = (unsigned short) (temp2 >> 16);
2343 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2344 ~0xc0,
2345 (unsigned short) ((tempbx &
2346 0xff) << 6));
2348 tempcx = pVBInfo->VGAVDE;
2349 if (tempcx == pVBInfo->VDE)
2350 xgifb_reg_and_or(pVBInfo->Part4Port,
2351 0x30, ~0x0c, 0x00);
2352 else
2353 xgifb_reg_and_or(pVBInfo->Part4Port,
2354 0x30, ~0x0c, 0x08);
2357 tempcx = pVBInfo->VGAHDE;
2358 tempbx = pVBInfo->HDE;
2360 temp1 = tempcx << 16;
2362 tempax = (unsigned short) (temp1 / tempbx);
2364 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2365 tempax = 65535;
2367 temp3 = tempax;
2368 temp1 = pVBInfo->VGAHDE << 16;
2370 temp1 /= temp3;
2371 temp3 = temp3 << 16;
2372 temp1 -= 1;
2374 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2376 tempax = (unsigned short) (temp3 & 0xff);
2377 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2379 temp1 = pVBInfo->VGAVDE << 18;
2380 temp1 = temp1 / push3;
2381 tempbx = (unsigned short) (temp1 & 0xffff);
2383 if (pVBInfo->LCDResInfo == Panel_1024x768)
2384 tempbx -= 1;
2386 tempax = ((tempbx >> 8) & 0xff) << 3;
2387 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2388 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2389 (unsigned short) (tempax & 0xff));
2390 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2391 (unsigned short) (tempbx & 0xff));
2393 temp3 = temp3 >> 16;
2395 if (modeflag & HalfDCLK)
2396 temp3 = temp3 >> 1;
2398 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2399 (unsigned short) ((temp3 >> 8) & 0xff));
2400 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2401 (unsigned short) (temp3 & 0xff));
2404 /* --------------------------------------------------------------------- */
2405 /* Function : XGI_GETLCDVCLKPtr */
2406 /* Input : */
2407 /* Output : al -> VCLK Index */
2408 /* Description : */
2409 /* --------------------------------------------------------------------- */
2410 static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2411 struct vb_device_info *pVBInfo)
2413 unsigned short index;
2415 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
2416 index = XGI_GetLCDCapPtr1(pVBInfo);
2418 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2419 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2420 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2421 } else { /* LCDA */
2422 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2423 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2426 return;
2429 static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2430 unsigned short ModeNo, unsigned short ModeIdIndex,
2431 struct vb_device_info *pVBInfo)
2434 unsigned short index, modeflag;
2435 unsigned char tempal;
2437 /* si+Ext_ResInfo */
2438 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2440 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2441 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
2442 index = XGI_GetLCDCapPtr(pVBInfo);
2443 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2445 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
2446 return tempal;
2448 /* {TV} */
2449 if (pVBInfo->VBType &
2450 (VB_SIS301B |
2451 VB_SIS302B |
2452 VB_SIS301LV |
2453 VB_SIS302LV |
2454 VB_XGI301C)) {
2455 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2456 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
2457 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2458 tempal = TVCLKBASE_315 + HiTVVCLK;
2459 if (pVBInfo->TVInfo & TVSimuMode) {
2460 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
2461 if (!(modeflag & Charx8Dot))
2462 tempal = TVCLKBASE_315 + HiTVTextVCLK;
2465 return tempal;
2468 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
2469 tempal = XGI_YPbPr750pVCLK;
2470 return tempal;
2473 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
2474 tempal = YPbPr525pVCLK;
2475 return tempal;
2478 tempal = NTSC1024VCLK;
2480 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
2481 tempal = TVCLKBASE_315 + TVVCLKDIV2;
2482 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2483 tempal = TVCLKBASE_315 + TVVCLK;
2486 if (pVBInfo->VBInfo & SetCRT2ToTV)
2487 return tempal;
2489 } /* {End of VB} */
2491 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
2492 tempal = tempal >> 2;
2493 tempal &= 0x03;
2495 /* for Dot8 Scaling LCD */
2496 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
2497 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2499 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2500 return tempal;
2503 static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2504 unsigned char *di_1, struct vb_device_info *pVBInfo)
2506 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
2507 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
2508 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) && (pVBInfo->SetFlag
2509 & ProgrammingCRT2)) {
2510 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
2511 *di_1 = XGI_VBVCLKData[tempal].SR2C;
2513 } else {
2514 *di_0 = XGI_VCLKData[tempal].SR2B;
2515 *di_1 = XGI_VCLKData[tempal].SR2C;
2519 static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
2520 unsigned short RefreshRateTableIndex,
2521 struct vb_device_info *pVBInfo)
2523 unsigned char di_0, di_1, tempal;
2524 int i;
2526 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2527 pVBInfo);
2528 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2529 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
2531 for (i = 0; i < 4; i++) {
2532 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
2533 (unsigned short) (0x10 * i));
2534 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
2535 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
2536 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
2537 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
2538 } else {
2539 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
2540 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
2545 static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
2546 struct vb_device_info *pVBInfo)
2548 unsigned short tempcl, tempch, temp, tempbl, tempax;
2550 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2551 | VB_SIS302LV | VB_XGI301C)) {
2552 tempcl = 0;
2553 tempch = 0;
2554 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
2556 if (!(temp & 0x20)) {
2557 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
2558 if (temp & 0x80) {
2559 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
2560 if (!(temp & 0x40))
2561 tempcl |= ActiveCRT1;
2565 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
2566 temp &= 0x0f;
2568 if (!(temp == 0x08)) {
2569 /* Check ChannelA by Part1_13 [2003/10/03] */
2570 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
2571 if (tempax & 0x04)
2572 tempcl = tempcl | ActiveLCD;
2574 temp &= 0x05;
2576 if (!(tempcl & ActiveLCD))
2577 if (temp == 0x01)
2578 tempcl |= ActiveCRT2;
2580 if (temp == 0x04)
2581 tempcl |= ActiveLCD;
2583 if (temp == 0x05) {
2584 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
2586 if (!(temp & 0x08))
2587 tempch |= ActiveAVideo;
2589 if (!(temp & 0x04))
2590 tempch |= ActiveSVideo;
2592 if (temp & 0x02)
2593 tempch |= ActiveSCART;
2595 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2596 if (temp & 0x01)
2597 tempch |= ActiveHiTV;
2600 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2601 temp = xgifb_reg_get(
2602 pVBInfo->Part2Port,
2603 0x4d);
2605 if (temp & 0x10)
2606 tempch |= ActiveYPbPr;
2609 if (tempch != 0)
2610 tempcl |= ActiveTV;
2614 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
2615 if (tempcl & ActiveLCD) {
2616 if ((pVBInfo->SetFlag & ReserveTVOption)) {
2617 if (temp & ActiveTV)
2618 tempcl |= ActiveTV;
2621 temp = tempcl;
2622 tempbl = ~XGI_ModeSwitchStatus;
2623 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
2625 if (!(pVBInfo->SetFlag & ReserveTVOption))
2626 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
2627 } else {
2628 return;
2632 void XGI_GetVBType(struct vb_device_info *pVBInfo)
2634 unsigned short flag, tempbx, tempah;
2636 if (pVBInfo->IF_DEF_LVDS == 0) {
2637 tempbx = VB_SIS302B;
2638 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
2639 if (flag != 0x02) {
2640 tempbx = VB_SIS301;
2641 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
2642 if (flag >= 0xB0) {
2643 tempbx = VB_SIS301B;
2644 if (flag >= 0xC0) {
2645 tempbx = VB_XGI301C;
2646 if (flag >= 0xD0) {
2647 tempbx = VB_SIS301LV;
2648 if (flag >= 0xE0) {
2649 tempbx = VB_SIS302LV;
2650 tempah = xgifb_reg_get(
2651 pVBInfo->Part4Port,
2652 0x39);
2653 if (tempah != 0xFF)
2654 tempbx =
2655 VB_XGI301C;
2660 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
2661 flag = xgifb_reg_get(
2662 pVBInfo->Part4Port,
2663 0x23);
2665 if (!(flag & 0x02))
2666 tempbx = tempbx | VB_NoLCD;
2670 pVBInfo->VBType = tempbx;
2674 static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2675 struct xgi_hw_device_info *HwDeviceExtension,
2676 struct vb_device_info *pVBInfo)
2678 unsigned short tempax, push, tempbx, temp, modeflag;
2680 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2681 pVBInfo->SetFlag = 0;
2682 pVBInfo->ModeType = modeflag & ModeTypeMask;
2683 tempbx = 0;
2685 if (pVBInfo->VBType & 0xFFFF) {
2686 /* Check Display Device */
2687 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
2688 tempbx = tempbx | temp;
2689 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
2690 push = temp;
2691 push = push << 8;
2692 tempax = temp << 8;
2693 tempbx = tempbx | tempax;
2694 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
2695 | SetInSlaveMode | DisableCRT2Display);
2696 temp = 0xFFFF ^ temp;
2697 tempbx &= temp;
2699 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
2701 if (pVBInfo->IF_DEF_LCDA == 1) {
2703 if ((HwDeviceExtension->jChipType >= XG20) ||
2704 (HwDeviceExtension->jChipType >= XG40)) {
2705 if (pVBInfo->IF_DEF_LVDS == 0) {
2706 if (pVBInfo->VBType &
2707 (VB_SIS302B |
2708 VB_SIS301LV |
2709 VB_SIS302LV |
2710 VB_XGI301C)) {
2711 if (temp & EnableDualEdge) {
2712 tempbx |=
2713 SetCRT2ToDualEdge;
2715 if (temp & SetToLCDA)
2716 tempbx |=
2717 XGI_SetCRT2ToLCDA;
2724 if (pVBInfo->IF_DEF_YPbPr == 1) {
2725 /* [Billy] 07/05/04 */
2726 if (((pVBInfo->IF_DEF_LVDS == 0) &&
2727 ((pVBInfo->VBType & VB_SIS301LV) ||
2728 (pVBInfo->VBType & VB_SIS302LV) ||
2729 (pVBInfo->VBType & VB_XGI301C)))) {
2730 if (temp & SetYPbPr) {
2731 if (pVBInfo->IF_DEF_HiVision == 1) {
2732 /* shampoo add for new
2733 * scratch */
2734 temp = xgifb_reg_get(
2735 pVBInfo->P3d4,
2736 0x35);
2737 temp &= YPbPrMode;
2738 tempbx |= SetCRT2ToHiVision;
2740 if (temp != YPbPrMode1080i) {
2741 tempbx &=
2742 (~SetCRT2ToHiVision);
2743 tempbx |=
2744 SetCRT2ToYPbPr525750;
2751 tempax = push; /* restore CR31 */
2753 if (pVBInfo->IF_DEF_LVDS == 0) {
2754 if (pVBInfo->IF_DEF_YPbPr == 1) {
2755 if (pVBInfo->IF_DEF_HiVision == 1)
2756 temp = 0x09FC;
2757 else
2758 temp = 0x097C;
2759 } else {
2760 if (pVBInfo->IF_DEF_HiVision == 1)
2761 temp = 0x01FC;
2762 else
2763 temp = 0x017C;
2765 } else { /* 3nd party chip */
2766 temp = SetCRT2ToLCD;
2769 if (!(tempbx & temp)) {
2770 tempax |= DisableCRT2Display;
2771 tempbx = 0;
2774 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
2775 if (!(pVBInfo->VBType & VB_NoLCD)) {
2776 if (tempbx & XGI_SetCRT2ToLCDA) {
2777 if (tempbx & SetSimuScanMode)
2778 tempbx &= (~(SetCRT2ToLCD |
2779 SetCRT2ToRAMDAC |
2780 SwitchCRT2));
2781 else
2782 tempbx &= (~(SetCRT2ToLCD |
2783 SetCRT2ToRAMDAC |
2784 SetCRT2ToTV |
2785 SwitchCRT2));
2790 /* shampoo add */
2791 /* for driver abnormal */
2792 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2793 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2794 if (tempbx & SetCRT2ToRAMDAC) {
2795 tempbx &= (0xFF00 |
2796 SetCRT2ToRAMDAC |
2797 SwitchCRT2 |
2798 SetSimuScanMode);
2799 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2801 } else {
2802 tempbx &= (~(SetCRT2ToRAMDAC |
2803 SetCRT2ToLCD |
2804 SetCRT2ToTV));
2808 if (!(pVBInfo->VBType & VB_NoLCD)) {
2809 if (tempbx & SetCRT2ToLCD) {
2810 tempbx &= (0xFF00 |
2811 SetCRT2ToLCD |
2812 SwitchCRT2 |
2813 SetSimuScanMode);
2814 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2818 if (tempbx & SetCRT2ToSCART) {
2819 tempbx &= (0xFF00 |
2820 SetCRT2ToSCART |
2821 SwitchCRT2 |
2822 SetSimuScanMode);
2823 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2826 if (pVBInfo->IF_DEF_YPbPr == 1) {
2827 if (tempbx & SetCRT2ToYPbPr525750)
2828 tempbx &= (0xFF00 |
2829 SwitchCRT2 |
2830 SetSimuScanMode);
2833 if (pVBInfo->IF_DEF_HiVision == 1) {
2834 if (tempbx & SetCRT2ToHiVision)
2835 tempbx &= (0xFF00 |
2836 SetCRT2ToHiVision |
2837 SwitchCRT2 |
2838 SetSimuScanMode);
2841 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2842 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2843 tempbx = DisableCRT2Display;
2846 if (!(tempbx & DisableCRT2Display)) {
2847 if ((!(tempbx & DriverMode)) ||
2848 (!(modeflag & CRT2Mode))) {
2849 if (pVBInfo->IF_DEF_LCDA == 1) {
2850 if (!(tempbx & XGI_SetCRT2ToLCDA))
2851 tempbx |= (SetInSlaveMode |
2852 SetSimuScanMode);
2856 /* LCD+TV can't support in slave mode
2857 * (Force LCDA+TV->LCDB) */
2858 if ((tempbx & SetInSlaveMode) &&
2859 (tempbx & XGI_SetCRT2ToLCDA)) {
2860 tempbx ^= (SetCRT2ToLCD |
2861 XGI_SetCRT2ToLCDA |
2862 SetCRT2ToDualEdge);
2863 pVBInfo->SetFlag |= ReserveTVOption;
2868 pVBInfo->VBInfo = tempbx;
2871 static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2872 struct vb_device_info *pVBInfo)
2874 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
2876 tempbx = 0;
2877 resinfo = 0;
2879 if (pVBInfo->VBInfo & SetCRT2ToTV) {
2880 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2881 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
2883 if (pVBInfo->VBInfo & SetCRT2ToTV) {
2884 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2885 tempbx = temp;
2886 if (tempbx & TVSetPAL) {
2887 tempbx &= (SetCHTVOverScan |
2888 TVSetPALM |
2889 TVSetPALN |
2890 TVSetPAL);
2891 if (tempbx & TVSetPALM)
2892 /* set to NTSC if PAL-M */
2893 tempbx &= ~TVSetPAL;
2894 } else
2895 tempbx &= (SetCHTVOverScan |
2896 TVSetNTSCJ |
2897 TVSetPAL);
2900 if (pVBInfo->IF_DEF_LVDS == 0) {
2901 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2902 tempbx |= TVSetPAL;
2905 if (pVBInfo->IF_DEF_YPbPr == 1) {
2906 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2907 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2908 index1 &= YPbPrMode;
2910 if (index1 == YPbPrMode525i)
2911 tempbx |= TVSetYPbPr525i;
2913 if (index1 == YPbPrMode525p)
2914 tempbx = tempbx | TVSetYPbPr525p;
2915 if (index1 == YPbPrMode750p)
2916 tempbx = tempbx | TVSetYPbPr750p;
2920 if (pVBInfo->IF_DEF_HiVision == 1) {
2921 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2922 tempbx = tempbx | TVSetHiVision | TVSetPAL;
2925 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
2926 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2927 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2928 tempbx |= TVSimuMode;
2930 if (!(tempbx & TVSetPAL) &&
2931 (modeflag > 13) &&
2932 (resinfo == 8)) /* NTSC 1024x768, */
2933 tempbx |= NTSC1024x768;
2935 tempbx |= RPLLDIV2XO;
2937 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2938 if (pVBInfo->VBInfo & SetInSlaveMode)
2939 tempbx &= (~RPLLDIV2XO);
2940 } else {
2941 if (tempbx &
2942 (TVSetYPbPr525p | TVSetYPbPr750p))
2943 tempbx &= (~RPLLDIV2XO);
2944 else if (!(pVBInfo->VBType &
2945 (VB_SIS301B |
2946 VB_SIS302B |
2947 VB_SIS301LV |
2948 VB_SIS302LV |
2949 VB_XGI301C))) {
2950 if (tempbx & TVSimuMode)
2951 tempbx &= (~RPLLDIV2XO);
2956 pVBInfo->TVInfo = tempbx;
2959 static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2960 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
2962 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
2964 pVBInfo->LCDResInfo = 0;
2965 pVBInfo->LCDTypeInfo = 0;
2966 pVBInfo->LCDInfo = 0;
2968 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2969 /* si+Ext_ResInfo // */
2970 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
2971 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
2972 tempbx = temp & 0x0F;
2974 if (tempbx == 0)
2975 tempbx = Panel_1024x768; /* default */
2977 /* LCD75 [2003/8/22] Vicent */
2978 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
2979 if (pVBInfo->VBInfo & DriverMode) {
2980 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
2981 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
2982 tempax &= 0x0F;
2983 else
2984 tempax = tempax >> 4;
2986 if ((resinfo == 6) || (resinfo == 9)) {
2987 if (tempax >= 3)
2988 tempbx |= PanelRef75Hz;
2989 } else if ((resinfo == 7) || (resinfo == 8)) {
2990 if (tempax >= 4)
2991 tempbx |= PanelRef75Hz;
2996 pVBInfo->LCDResInfo = tempbx;
2998 /* End of LCD75 */
3000 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
3001 return 0;
3003 tempbx = 0;
3005 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
3007 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
3009 tempbx |= temp;
3011 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
3013 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
3015 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3016 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
3017 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
3018 tempbx |= SetLCDDualLink;
3022 if (pVBInfo->IF_DEF_LVDS == 0) {
3023 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
3024 & SetCRT2ToLCD) && (resinfo == 9) &&
3025 (!(tempbx & EnableScalingLCD)))
3026 /* set to center in 1280x1024 LCDB for Panel_1400x1050 */
3027 tempbx |= SetLCDtoNonExpanding;
3030 if (pVBInfo->IF_DEF_ExpLink == 1) {
3031 if (modeflag & HalfDCLK) {
3032 if (!(tempbx & SetLCDtoNonExpanding)) {
3033 tempbx |= XGI_EnableLVDSDDA;
3034 } else {
3035 if (pVBInfo->LCDResInfo == Panel_1024x768) {
3036 if (resinfo == 4) {/* 512x384 */
3037 tempbx |= XGI_EnableLVDSDDA;
3044 if (pVBInfo->VBInfo & SetInSlaveMode) {
3045 if (pVBInfo->VBInfo & SetNotSimuMode)
3046 tempbx |= XGI_LCDVESATiming;
3047 } else {
3048 tempbx |= XGI_LCDVESATiming;
3051 pVBInfo->LCDInfo = tempbx;
3053 return 1;
3056 unsigned char XGI_SearchModeID(unsigned short ModeNo,
3057 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
3059 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3060 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
3061 break;
3062 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
3063 return 0;
3066 return 1;
3069 static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3071 unsigned char ujRet = 0;
3072 unsigned char i = 0;
3074 for (i = 0; i < 8; i++) {
3075 ujRet = ujRet << 1;
3076 ujRet |= (ujDate >> i) & 1;
3079 return ujRet;
3082 /*----------------------------------------------------------------------------*/
3083 /* output */
3084 /* bl[5] : LVDS signal */
3085 /* bl[1] : LVDS backlight */
3086 /* bl[0] : LVDS VDD */
3087 /*----------------------------------------------------------------------------*/
3088 static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3090 unsigned char CR4A, temp;
3092 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3093 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
3095 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3097 temp = XG21GPIODataTransfer(temp);
3098 temp &= 0x23;
3099 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3100 return temp;
3103 /*----------------------------------------------------------------------------*/
3104 /* output */
3105 /* bl[5] : LVDS signal */
3106 /* bl[1] : LVDS backlight */
3107 /* bl[0] : LVDS VDD */
3108 /*----------------------------------------------------------------------------*/
3109 static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3111 unsigned char CR4A, CRB4, temp;
3113 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3114 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
3116 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3118 temp &= 0x0C;
3119 temp >>= 2;
3120 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3121 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
3122 temp |= ((CRB4 & 0x04) << 3);
3123 return temp;
3126 /*----------------------------------------------------------------------------*/
3127 /* input */
3128 /* bl[5] : 1;LVDS signal on */
3129 /* bl[1] : 1;LVDS backlight on */
3130 /* bl[0] : 1:LVDS VDD on */
3131 /* bh: 100000b : clear bit 5, to set bit5 */
3132 /* 000010b : clear bit 1, to set bit1 */
3133 /* 000001b : clear bit 0, to set bit0 */
3134 /*----------------------------------------------------------------------------*/
3135 static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3136 struct vb_device_info *pVBInfo)
3138 unsigned char CR4A, temp;
3140 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3141 tempbh &= 0x23;
3142 tempbl &= 0x23;
3143 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3145 if (tempbh & 0x20) {
3146 temp = (tempbl >> 4) & 0x02;
3148 /* CR B4[1] */
3149 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3153 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3155 temp = XG21GPIODataTransfer(temp);
3156 temp &= ~tempbh;
3157 temp |= tempbl;
3158 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
3161 static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3162 struct vb_device_info *pVBInfo)
3164 unsigned char CR4A, temp;
3165 unsigned short tempbh0, tempbl0;
3167 tempbh0 = tempbh;
3168 tempbl0 = tempbl;
3169 tempbh0 &= 0x20;
3170 tempbl0 &= 0x20;
3171 tempbh0 >>= 3;
3172 tempbl0 >>= 3;
3174 if (tempbh & 0x20) {
3175 temp = (tempbl >> 4) & 0x02;
3177 /* CR B4[1] */
3178 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3181 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
3183 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3184 tempbh &= 0x03;
3185 tempbl &= 0x03;
3186 tempbh <<= 2;
3187 tempbl <<= 2; /* GPIOC,GPIOD */
3188 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3189 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
3192 /* --------------------------------------------------------------------- */
3193 /* Function : XGI_XG21SetPanelDelay */
3194 /* Input : */
3195 /* Output : */
3196 /* Description : */
3197 /* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
3198 /* : bl : 2 ; T2 : the duration signal on and Vdd on */
3199 /* : bl : 3 ; T3 : the duration between CPL off and signal off */
3200 /* : bl : 4 ; T4 : the duration signal off and Vdd off */
3201 /* --------------------------------------------------------------------- */
3202 static void XGI_XG21SetPanelDelay(struct xgifb_video_info *xgifb_info,
3203 unsigned short tempbl,
3204 struct vb_device_info *pVBInfo)
3206 if (tempbl == 1)
3207 mdelay(xgifb_info->lvds_data.PSC_S1);
3209 if (tempbl == 2)
3210 mdelay(xgifb_info->lvds_data.PSC_S2);
3212 if (tempbl == 3)
3213 mdelay(xgifb_info->lvds_data.PSC_S3);
3215 if (tempbl == 4)
3216 mdelay(xgifb_info->lvds_data.PSC_S4);
3219 static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
3220 struct xgi_hw_device_info *pXGIHWDE,
3221 struct vb_device_info *pVBInfo)
3224 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
3225 if (pXGIHWDE->jChipType == XG21) {
3226 if (pVBInfo->IF_DEF_LVDS == 1) {
3227 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
3228 /* LVDS VDD on */
3229 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
3230 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
3232 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
3233 /* LVDS signal on */
3234 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3235 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
3236 /* LVDS backlight on */
3237 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
3238 } else {
3239 /* DVO/DVI signal on */
3240 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3245 if (pXGIHWDE->jChipType == XG27) {
3246 if (pVBInfo->IF_DEF_LVDS == 1) {
3247 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
3248 /* LVDS VDD on */
3249 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
3250 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
3252 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
3253 /* LVDS signal on */
3254 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3255 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
3256 /* LVDS backlight on */
3257 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
3258 } else {
3259 /* DVO/DVI signal on */
3260 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3266 void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
3267 struct xgi_hw_device_info *pXGIHWDE,
3268 struct vb_device_info *pVBInfo)
3271 if (pXGIHWDE->jChipType == XG21) {
3272 if (pVBInfo->IF_DEF_LVDS == 1) {
3273 /* LVDS backlight off */
3274 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
3275 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
3276 } else {
3277 /* DVO/DVI signal off */
3278 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
3282 if (pXGIHWDE->jChipType == XG27) {
3283 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
3284 /* LVDS backlight off */
3285 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
3286 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
3289 if (pVBInfo->IF_DEF_LVDS == 0)
3290 /* DVO/DVI signal off */
3291 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
3294 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
3297 static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
3299 while ((inb(pVBInfo->P3da) & 0x01))
3300 break;
3302 while (!(inb(pVBInfo->P3da) & 0x01))
3303 break;
3306 static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
3308 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
3311 static void XGI_SaveCRT2Info(unsigned short ModeNo,
3312 struct vb_device_info *pVBInfo)
3314 unsigned short temp1, temp2;
3316 /* reserve CR34 for CRT1 Mode No */
3317 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
3318 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3319 temp2 = ~(SetInSlaveMode >> 8);
3320 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
3323 static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3324 unsigned short ModeIdIndex,
3325 struct vb_device_info *pVBInfo)
3327 unsigned short xres, yres, modeflag, resindex;
3329 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3330 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3331 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3332 /* si+St_ModeFlag */
3333 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3335 if (modeflag & HalfDCLK)
3336 xres *= 2;
3338 if (modeflag & DoubleScanMode)
3339 yres *= 2;
3341 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3342 if (pVBInfo->IF_DEF_LVDS == 0) {
3343 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
3344 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
3345 if (yres == 1024)
3346 yres = 1056;
3350 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
3351 if (yres == 400)
3352 yres = 405;
3353 else if (yres == 350)
3354 yres = 360;
3356 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
3357 if (yres == 360)
3358 yres = 375;
3362 if (pVBInfo->LCDResInfo == Panel_1024x768) {
3363 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
3364 if (!(pVBInfo->LCDInfo
3365 & LCDNonExpanding)) {
3366 if (yres == 350)
3367 yres = 357;
3368 else if (yres == 400)
3369 yres = 420;
3370 else if (yres == 480)
3371 yres = 525;
3377 if (xres == 720)
3378 xres = 640;
3381 pVBInfo->VGAHDE = xres;
3382 pVBInfo->HDE = xres;
3383 pVBInfo->VGAVDE = yres;
3384 pVBInfo->VDE = yres;
3387 static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
3390 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
3391 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
3392 return 1;
3394 return 0;
3397 static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3398 unsigned short ModeIdIndex,
3399 unsigned short RefreshRateTableIndex,
3400 struct vb_device_info *pVBInfo)
3402 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
3403 CRT1Index;
3405 pVBInfo->RVBHCMAX = 1;
3406 pVBInfo->RVBHCFACT = 1;
3407 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3408 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3409 CRT1Index &= IndexMask;
3410 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[0];
3411 temp2 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3412 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3413 tempbx = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[8];
3414 tempcx = (unsigned short)
3415 pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3416 tempcx &= 0x0100;
3417 tempcx = tempcx << 2;
3418 tempbx |= tempcx;
3419 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
3421 if (temp1 & 0x01)
3422 tempbx |= 0x0100;
3424 if (temp1 & 0x20)
3425 tempbx |= 0x0200;
3426 tempax += 5;
3428 if (modeflag & Charx8Dot)
3429 tempax *= 8;
3430 else
3431 tempax *= 9;
3433 pVBInfo->VGAHT = tempax;
3434 pVBInfo->HT = tempax;
3435 tempbx++;
3436 pVBInfo->VGAVT = tempbx;
3437 pVBInfo->VT = tempbx;
3440 static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
3441 unsigned short RefreshRateTableIndex,
3442 struct vb_device_info *pVBInfo)
3444 unsigned short tempax = 0, tempbx, modeflag, resinfo;
3446 struct SiS_LCDData *LCDPtr = NULL;
3447 struct SiS_TVData *TVPtr = NULL;
3449 /* si+Ext_ResInfo */
3450 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3451 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3452 pVBInfo->NewFlickerMode = 0;
3453 pVBInfo->RVBHRS = 50;
3455 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3456 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3457 pVBInfo);
3458 return;
3461 tempbx = 4;
3463 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
3464 LCDPtr = (struct SiS_LCDData *) XGI_GetLcdPtr(tempbx,
3465 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3466 pVBInfo);
3468 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
3469 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
3470 pVBInfo->VGAHT = LCDPtr->VGAHT;
3471 pVBInfo->VGAVT = LCDPtr->VGAVT;
3472 pVBInfo->HT = LCDPtr->LCDHT;
3473 pVBInfo->VT = LCDPtr->LCDVT;
3475 if (pVBInfo->LCDResInfo == Panel_1024x768) {
3476 tempax = 1024;
3477 tempbx = 768;
3479 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
3480 if (pVBInfo->VGAVDE == 357)
3481 tempbx = 527;
3482 else if (pVBInfo->VGAVDE == 420)
3483 tempbx = 620;
3484 else if (pVBInfo->VGAVDE == 525)
3485 tempbx = 775;
3486 else if (pVBInfo->VGAVDE == 600)
3487 tempbx = 775;
3488 else
3489 tempbx = 768;
3490 } else
3491 tempbx = 768;
3492 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
3493 tempax = 1024;
3494 tempbx = 768;
3495 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
3496 tempax = 1280;
3497 if (pVBInfo->VGAVDE == 360)
3498 tempbx = 768;
3499 else if (pVBInfo->VGAVDE == 375)
3500 tempbx = 800;
3501 else if (pVBInfo->VGAVDE == 405)
3502 tempbx = 864;
3503 else
3504 tempbx = 1024;
3505 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
3506 tempax = 1280;
3507 tempbx = 1024;
3508 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
3509 tempax = 1280;
3510 if (pVBInfo->VGAVDE == 350)
3511 tempbx = 700;
3512 else if (pVBInfo->VGAVDE == 400)
3513 tempbx = 800;
3514 else if (pVBInfo->VGAVDE == 1024)
3515 tempbx = 960;
3516 else
3517 tempbx = 960;
3518 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
3519 tempax = 1400;
3520 tempbx = 1050;
3522 if (pVBInfo->VGAVDE == 1024) {
3523 tempax = 1280;
3524 tempbx = 1024;
3526 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
3527 tempax = 1600;
3528 tempbx = 1200; /* alan 10/14/2003 */
3529 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
3530 if (pVBInfo->VGAVDE == 350)
3531 tempbx = 875;
3532 else if (pVBInfo->VGAVDE == 400)
3533 tempbx = 1000;
3537 if (pVBInfo->LCDInfo & LCDNonExpanding) {
3538 tempax = pVBInfo->VGAHDE;
3539 tempbx = pVBInfo->VGAVDE;
3542 pVBInfo->HDE = tempax;
3543 pVBInfo->VDE = tempbx;
3544 return;
3547 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
3548 tempbx = 4;
3549 TVPtr = (struct SiS_TVData *) XGI_GetTVPtr(tempbx,
3550 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3551 pVBInfo);
3553 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
3554 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
3555 pVBInfo->VGAHT = TVPtr->VGAHT;
3556 pVBInfo->VGAVT = TVPtr->VGAVT;
3557 pVBInfo->HDE = TVPtr->TVHDE;
3558 pVBInfo->VDE = TVPtr->TVVDE;
3559 pVBInfo->RVBHRS = TVPtr->RVBHRS;
3560 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
3562 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3563 if (resinfo == 0x08)
3564 pVBInfo->NewFlickerMode = 0x40;
3565 else if (resinfo == 0x09)
3566 pVBInfo->NewFlickerMode = 0x40;
3567 else if (resinfo == 0x12)
3568 pVBInfo->NewFlickerMode = 0x40;
3570 if (pVBInfo->VGAVDE == 350)
3571 pVBInfo->TVInfo |= TVSimuMode;
3573 tempax = ExtHiTVHT;
3574 tempbx = ExtHiTVVT;
3576 if (pVBInfo->VBInfo & SetInSlaveMode) {
3577 if (pVBInfo->TVInfo & TVSimuMode) {
3578 tempax = StHiTVHT;
3579 tempbx = StHiTVVT;
3581 if (!(modeflag & Charx8Dot)) {
3582 tempax = StHiTextTVHT;
3583 tempbx = StHiTextTVVT;
3587 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3588 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
3589 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
3590 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
3593 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
3594 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
3595 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
3596 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
3597 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
3598 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
3599 if (pVBInfo->TVInfo & NTSC1024x768)
3600 tempax = NTSC1024x768HT;
3602 } else {
3603 tempax = PALHT;
3604 tempbx = PALVT;
3605 if (!(pVBInfo->TVInfo & TVSetPAL)) {
3606 tempax = NTSCHT;
3607 tempbx = NTSCVT;
3608 if (pVBInfo->TVInfo & NTSC1024x768)
3609 tempax = NTSC1024x768HT;
3613 pVBInfo->HT = tempax;
3614 pVBInfo->VT = tempbx;
3615 return;
3619 static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
3620 unsigned short RefreshRateTableIndex,
3621 struct vb_device_info *pVBInfo)
3623 unsigned char di_0, di_1, tempal;
3625 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3626 pVBInfo);
3627 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3628 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
3630 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
3631 /* 301 */
3632 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
3633 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
3634 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
3635 } else { /* 301b/302b/301lv/302lv */
3636 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
3637 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
3640 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
3642 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
3643 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
3644 else
3645 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
3648 static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
3649 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
3651 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
3652 short index;
3653 unsigned short modeflag;
3655 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3656 index = (modeflag & ModeTypeMask) - ModeEGA;
3658 if (index < 0)
3659 index = 0;
3661 return ColorDepth[index];
3664 static unsigned short XGI_GetOffset(unsigned short ModeNo,
3665 unsigned short ModeIdIndex,
3666 unsigned short RefreshRateTableIndex,
3667 struct xgi_hw_device_info *HwDeviceExtension,
3668 struct vb_device_info *pVBInfo)
3670 unsigned short temp, colordepth, modeinfo, index, infoflag,
3671 ColorDepth[] = { 0x01, 0x02, 0x04 };
3673 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
3674 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
3676 index = (modeinfo >> 8) & 0xFF;
3678 temp = pVBInfo->ScreenOffset[index];
3680 if (infoflag & InterlaceMode)
3681 temp = temp << 1;
3683 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
3685 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
3686 temp = ModeNo - 0x7C;
3687 colordepth = ColorDepth[temp];
3688 temp = 0x6B;
3689 if (infoflag & InterlaceMode)
3690 temp = temp << 1;
3691 return temp * colordepth;
3692 } else {
3693 return temp * colordepth;
3697 static void XGI_SetCRT2Offset(unsigned short ModeNo,
3698 unsigned short ModeIdIndex,
3699 unsigned short RefreshRateTableIndex,
3700 struct xgi_hw_device_info *HwDeviceExtension,
3701 struct vb_device_info *pVBInfo)
3703 unsigned short offset;
3704 unsigned char temp;
3706 if (pVBInfo->VBInfo & SetInSlaveMode)
3707 return;
3709 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3710 HwDeviceExtension, pVBInfo);
3711 temp = (unsigned char) (offset & 0xFF);
3712 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3713 temp = (unsigned char) ((offset & 0xFF00) >> 8);
3714 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
3715 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
3716 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
3719 static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
3721 /* threshold high ,disable auto threshold */
3722 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3723 /* threshold low default 04h */
3724 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
3727 static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
3728 struct xgi_hw_device_info *HwDeviceExtension,
3729 unsigned short RefreshRateTableIndex,
3730 struct vb_device_info *pVBInfo)
3732 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
3734 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3735 CRT1Index &= IndexMask;
3736 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3738 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3739 HwDeviceExtension, pVBInfo);
3740 XGI_SetCRT2FIFO(pVBInfo);
3742 for (tempcx = 4; tempcx < 7; tempcx++)
3743 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
3745 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3746 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
3749 static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
3750 struct xgi_hw_device_info *HwDeviceExtension,
3751 unsigned short RefreshRateTableIndex,
3752 struct vb_device_info *pVBInfo)
3754 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3755 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
3757 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3758 CRT1Index &= IndexMask;
3759 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3760 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3762 /* bainy change table name */
3763 if (modeflag & HalfDCLK) {
3764 /* BTVGA2HT 0x08,0x09 */
3765 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
3766 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
3767 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
3768 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
3769 /* BTVGA2HDEE 0x0A,0x0C */
3770 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
3771 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
3772 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3773 pushbx = pVBInfo->VGAHDE / 2 + 16;
3774 tempcx = tempcx >> 1;
3775 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3776 tempcx += tempbx;
3778 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3779 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
3780 tempbx |= ((pVBInfo->
3781 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
3782 0xC0) << 2);
3783 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3784 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3785 tempcx &= 0x1F;
3786 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
3787 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3788 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3791 tempbx += 4;
3792 tempcx += 4;
3794 if (tempcx > (pVBInfo->VGAHT / 2))
3795 tempcx = pVBInfo->VGAHT / 2;
3797 temp = tempbx & 0x00FF;
3799 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
3800 } else {
3801 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
3802 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
3803 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
3804 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
3805 /* BTVGA2HDEE 0x0A,0x0C */
3806 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
3807 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
3808 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3809 pushbx = pVBInfo->VGAHDE + 16;
3810 tempcx = tempcx >> 1;
3811 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3812 tempcx += tempbx;
3814 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3815 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
3816 tempbx |= ((pVBInfo->
3817 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
3818 0xC0) << 2);
3819 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3820 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
3821 tempcx &= 0x1F;
3822 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
3823 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3824 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3825 tempbx += 16;
3826 tempcx += 16;
3829 if (tempcx > pVBInfo->VGAHT)
3830 tempcx = pVBInfo->VGAHT;
3832 temp = tempbx & 0x00FF;
3833 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
3836 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3837 tempbx = pushbx;
3838 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3839 tempax |= (tempbx & 0xFF00);
3840 temp = (tempax & 0xFF00) >> 8;
3841 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
3842 temp = tempcx & 0x00FF;
3843 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
3844 tempcx = (pVBInfo->VGAVT - 1);
3845 temp = tempcx & 0x00FF;
3847 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
3848 tempbx = pVBInfo->VGAVDE - 1;
3849 temp = tempbx & 0x00FF;
3850 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
3851 temp = ((tempbx & 0xFF00) << 3) >> 8;
3852 temp |= ((tempcx & 0xFF00) >> 8);
3853 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
3855 tempax = pVBInfo->VGAVDE;
3856 tempbx = pVBInfo->VGAVDE;
3857 tempcx = pVBInfo->VGAVT;
3858 /* BTVGA2VRS 0x10,0x11 */
3859 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3860 /* BTVGA2VRE 0x11 */
3861 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
3863 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3864 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
3865 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
3867 if (temp & 0x04)
3868 tempbx |= 0x0100;
3870 if (temp & 0x080)
3871 tempbx |= 0x0200;
3873 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
3875 if (temp & 0x08)
3876 tempbx |= 0x0400;
3878 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
3879 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3882 temp = tempbx & 0x00FF;
3883 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
3884 temp = ((tempbx & 0xFF00) >> 8) << 4;
3885 temp = ((tempcx & 0x000F) | (temp));
3886 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
3887 tempax = 0;
3889 if (modeflag & DoubleScanMode)
3890 tempax |= 0x80;
3892 if (modeflag & HalfDCLK)
3893 tempax |= 0x40;
3895 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
3898 static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3900 unsigned long tempax, tempbx;
3902 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3903 & 0xFFFF;
3904 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3905 tempax = (tempax * pVBInfo->HT) / tempbx;
3907 return (unsigned short) tempax;
3910 static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
3911 struct xgi_hw_device_info *HwDeviceExtension,
3912 unsigned short RefreshRateTableIndex,
3913 struct vb_device_info *pVBInfo)
3915 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
3916 modeflag, CRT1Index;
3918 /* si+Ext_ResInfo */
3919 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3920 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3921 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3922 CRT1Index &= IndexMask;
3924 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3925 return;
3927 temp = 0xFF; /* set MAX HT */
3928 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
3929 tempcx = 0x08;
3931 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
3932 modeflag |= Charx8Dot;
3934 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
3936 if (modeflag & HalfDCLK)
3937 tempax = tempax >> 1;
3939 tempax = (tempax / tempcx) - 1;
3940 tempbx |= ((tempax & 0x00FF) << 8);
3941 temp = tempax & 0x00FF;
3942 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
3944 temp = (tempbx & 0xFF00) >> 8;
3946 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3947 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3948 | VB_SIS302LV | VB_XGI301C)))
3949 temp += 2;
3951 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3952 if (pVBInfo->VBType & VB_SIS301LV) {
3953 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
3954 if (resinfo == 7)
3955 temp -= 2;
3957 } else if (resinfo == 7) {
3958 temp -= 2;
3963 /* 0x05 Horizontal Display Start */
3964 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3965 /* 0x06 Horizontal Blank end */
3966 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
3968 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3969 if (pVBInfo->VBInfo & SetCRT2ToTV)
3970 tempax = pVBInfo->VGAHT;
3971 else
3972 tempax = XGI_GetVGAHT2(pVBInfo);
3975 if (tempax >= pVBInfo->VGAHT)
3976 tempax = pVBInfo->VGAHT;
3978 if (modeflag & HalfDCLK)
3979 tempax = tempax >> 1;
3981 tempax = (tempax / tempcx) - 5;
3982 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
3983 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3984 temp = (tempbx & 0x00FF) - 1;
3985 if (!(modeflag & HalfDCLK)) {
3986 temp -= 6;
3987 if (pVBInfo->TVInfo & TVSimuMode) {
3988 temp -= 4;
3989 temp -= 10;
3992 } else {
3993 tempbx = (tempbx & 0xFF00) >> 8;
3994 tempcx = (tempcx + tempbx) >> 1;
3995 temp = (tempcx & 0x00FF) + 2;
3997 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3998 temp -= 1;
3999 if (!(modeflag & HalfDCLK)) {
4000 if ((modeflag & Charx8Dot)) {
4001 temp += 4;
4002 if (pVBInfo->VGAHDE >= 800)
4003 temp -= 6;
4006 } else if (!(modeflag & HalfDCLK)) {
4007 temp -= 4;
4008 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
4009 pVBInfo->VGAHDE >= 800) {
4010 temp -= 7;
4011 if (pVBInfo->VGAHDE >= 1280 &&
4012 pVBInfo->LCDResInfo != Panel_1280x960 &&
4013 (pVBInfo->LCDInfo & LCDNonExpanding))
4014 temp += 28;
4019 /* 0x07 Horizontal Retrace Start */
4020 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4021 /* 0x08 Horizontal Retrace End */
4022 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
4024 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4025 if (pVBInfo->TVInfo & TVSimuMode) {
4026 if (ModeNo == 0x50) {
4027 if (pVBInfo->TVInfo & SetNTSCTV) {
4028 xgifb_reg_set(pVBInfo->Part1Port,
4029 0x07, 0x30);
4030 xgifb_reg_set(pVBInfo->Part1Port,
4031 0x08, 0x03);
4032 } else {
4033 xgifb_reg_set(pVBInfo->Part1Port,
4034 0x07, 0x2f);
4035 xgifb_reg_set(pVBInfo->Part1Port,
4036 0x08, 0x02);
4042 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
4043 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
4044 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
4046 tempbx = pVBInfo->VGAVT;
4047 push1 = tempbx;
4048 tempcx = 0x121;
4049 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
4051 if (tempbx == 357)
4052 tempbx = 350;
4053 if (tempbx == 360)
4054 tempbx = 350;
4055 if (tempbx == 375)
4056 tempbx = 350;
4057 if (tempbx == 405)
4058 tempbx = 400;
4059 if (tempbx == 525)
4060 tempbx = 480;
4062 push2 = tempbx;
4064 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4065 if (pVBInfo->LCDResInfo == Panel_1024x768) {
4066 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
4067 if (tempbx == 350)
4068 tempbx += 5;
4069 if (tempbx == 480)
4070 tempbx += 5;
4074 tempbx--;
4075 temp = tempbx & 0x00FF;
4076 tempbx--;
4077 temp = tempbx & 0x00FF;
4078 /* 0x10 vertical Blank Start */
4079 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4080 tempbx = push2;
4081 tempbx--;
4082 temp = tempbx & 0x00FF;
4083 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
4085 if (tempbx & 0x0100)
4086 tempcx |= 0x0002;
4088 tempax = 0x000B;
4090 if (modeflag & DoubleScanMode)
4091 tempax |= 0x08000;
4093 if (tempbx & 0x0200)
4094 tempcx |= 0x0040;
4096 temp = (tempax & 0xFF00) >> 8;
4097 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4099 if (tempbx & 0x0400)
4100 tempcx |= 0x0600;
4102 /* 0x11 Vertival Blank End */
4103 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
4105 tempax = push1;
4106 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4107 tempax = tempax >> 2;
4108 push1 = tempax; /* push ax */
4110 if (resinfo != 0x09) {
4111 tempax = tempax << 1;
4112 tempbx += tempax;
4115 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
4116 if (pVBInfo->VBType & VB_SIS301LV) {
4117 if (pVBInfo->TVInfo & TVSetHiVision) {
4118 tempbx -= 10;
4119 } else {
4120 if (pVBInfo->TVInfo & TVSimuMode) {
4121 if (pVBInfo->TVInfo & TVSetPAL) {
4122 if (pVBInfo->VBType &
4123 VB_SIS301LV) {
4124 if (!(pVBInfo->TVInfo &
4125 (TVSetYPbPr525p |
4126 TVSetYPbPr750p |
4127 TVSetHiVision)))
4128 tempbx += 40;
4129 } else {
4130 tempbx += 40;
4135 } else {
4136 tempbx -= 10;
4138 } else {
4139 if (pVBInfo->TVInfo & TVSimuMode) {
4140 if (pVBInfo->TVInfo & TVSetPAL) {
4141 if (pVBInfo->VBType & VB_SIS301LV) {
4142 if (!(pVBInfo->TVInfo &
4143 (TVSetYPbPr525p |
4144 TVSetYPbPr750p |
4145 TVSetHiVision)))
4146 tempbx += 40;
4147 } else {
4148 tempbx += 40;
4153 tempax = push1;
4154 tempax = tempax >> 2;
4155 tempax++;
4156 tempax += tempbx;
4157 push1 = tempax; /* push ax */
4159 if ((pVBInfo->TVInfo & TVSetPAL)) {
4160 if (tempbx <= 513) {
4161 if (tempax >= 513)
4162 tempbx = 513;
4166 temp = tempbx & 0x00FF;
4167 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
4168 tempbx--;
4169 temp = tempbx & 0x00FF;
4170 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4172 if (tempbx & 0x0100)
4173 tempcx |= 0x0008;
4175 if (tempbx & 0x0200)
4176 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
4178 tempbx++;
4180 if (tempbx & 0x0100)
4181 tempcx |= 0x0004;
4183 if (tempbx & 0x0200)
4184 tempcx |= 0x0080;
4186 if (tempbx & 0x0400)
4187 tempcx |= 0x0C00;
4189 tempbx = push1; /* pop ax */
4190 temp = tempbx & 0x00FF;
4191 temp &= 0x0F;
4192 /* 0x0D vertical Retrace End */
4193 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
4195 if (tempbx & 0x0010)
4196 tempcx |= 0x2000;
4198 temp = tempcx & 0x00FF;
4199 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
4200 temp = (tempcx & 0x0FF00) >> 8;
4201 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
4202 tempax = modeflag;
4203 temp = (tempax & 0xFF00) >> 8;
4205 temp = (temp >> 1) & 0x09;
4207 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
4208 temp |= 0x01;
4210 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4211 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4212 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
4214 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4215 temp = 0x80;
4216 else
4217 temp = 0x00;
4219 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
4221 return;
4224 static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
4225 unsigned short RefreshRateTableIndex,
4226 struct xgi_hw_device_info *HwDeviceExtension,
4227 struct vb_device_info *pVBInfo)
4229 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4230 modeflag, resinfo, crt2crtc;
4231 unsigned char *TimingPoint;
4233 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4235 /* si+Ext_ResInfo */
4236 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4237 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4238 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
4240 tempax = 0;
4242 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4243 tempax |= 0x0800;
4245 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4246 tempax |= 0x0400;
4248 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4249 tempax |= 0x0200;
4251 if (!(pVBInfo->TVInfo & TVSetPAL))
4252 tempax |= 0x1000;
4254 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
4255 tempax |= 0x0100;
4257 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
4258 tempax &= 0xfe00;
4260 tempax = (tempax & 0xff00) >> 8;
4262 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
4263 TimingPoint = pVBInfo->NTSCTiming;
4265 if (pVBInfo->TVInfo & TVSetPAL)
4266 TimingPoint = pVBInfo->PALTiming;
4268 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
4269 TimingPoint = pVBInfo->HiTVExtTiming;
4271 if (pVBInfo->VBInfo & SetInSlaveMode)
4272 TimingPoint = pVBInfo->HiTVSt2Timing;
4274 if (pVBInfo->SetFlag & TVSimuMode)
4275 TimingPoint = pVBInfo->HiTVSt1Timing;
4277 if (!(modeflag & Charx8Dot))
4278 TimingPoint = pVBInfo->HiTVTextTiming;
4281 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4282 if (pVBInfo->TVInfo & TVSetYPbPr525i)
4283 TimingPoint = pVBInfo->YPbPr525iTiming;
4285 if (pVBInfo->TVInfo & TVSetYPbPr525p)
4286 TimingPoint = pVBInfo->YPbPr525pTiming;
4288 if (pVBInfo->TVInfo & TVSetYPbPr750p)
4289 TimingPoint = pVBInfo->YPbPr750pTiming;
4292 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
4293 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
4295 for (i = 0x39; i <= 0x45; i++, j++)
4296 /* di->temp2[j] */
4297 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
4299 if (pVBInfo->VBInfo & SetCRT2ToTV)
4300 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
4302 temp = pVBInfo->NewFlickerMode;
4303 temp &= 0x80;
4304 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
4306 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
4307 tempax = 950;
4309 if (pVBInfo->TVInfo & TVSetPAL)
4310 tempax = 520;
4311 else
4312 tempax = 440;
4314 if (pVBInfo->VDE <= tempax) {
4315 tempax -= pVBInfo->VDE;
4316 tempax = tempax >> 2;
4317 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4318 push1 = tempax;
4319 temp = (tempax & 0xFF00) >> 8;
4320 temp += (unsigned short) TimingPoint[0];
4322 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4323 | VB_SIS302LV | VB_XGI301C)) {
4324 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4325 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4326 | SetCRT2ToYPbPr525750)) {
4327 tempcx = pVBInfo->VGAHDE;
4328 if (tempcx >= 1024) {
4329 temp = 0x17; /* NTSC */
4330 if (pVBInfo->TVInfo & TVSetPAL)
4331 temp = 0x19; /* PAL */
4336 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
4337 tempax = push1;
4338 temp = (tempax & 0xFF00) >> 8;
4339 temp += TimingPoint[1];
4341 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4342 | VB_SIS302LV | VB_XGI301C)) {
4343 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4344 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4345 | SetCRT2ToYPbPr525750))) {
4346 tempcx = pVBInfo->VGAHDE;
4347 if (tempcx >= 1024) {
4348 temp = 0x1D; /* NTSC */
4349 if (pVBInfo->TVInfo & TVSetPAL)
4350 temp = 0x52; /* PAL */
4354 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
4357 /* 301b */
4358 tempcx = pVBInfo->HT;
4360 if (XGI_IsLCDDualLink(pVBInfo))
4361 tempcx = tempcx >> 1;
4363 tempcx -= 2;
4364 temp = tempcx & 0x00FF;
4365 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
4367 temp = (tempcx & 0xFF00) >> 8;
4368 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
4370 tempcx = pVBInfo->HT >> 1;
4371 push1 = tempcx; /* push cx */
4372 tempcx += 7;
4374 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
4375 tempcx -= 4;
4377 temp = tempcx & 0x00FF;
4378 temp = temp << 4;
4379 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
4381 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4382 tempbx += tempcx;
4383 push2 = tempbx;
4384 temp = tempbx & 0x00FF;
4385 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
4386 temp = (tempbx & 0xFF00) >> 8;
4387 temp = temp << 4;
4388 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
4390 tempbx = push2;
4391 tempbx = tempbx + 8;
4392 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
4393 tempbx = tempbx - 4;
4394 tempcx = tempbx;
4397 temp = (tempbx & 0x00FF) << 4;
4398 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
4400 j += 2;
4401 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
4402 temp = tempcx & 0x00FF;
4403 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
4404 temp = ((tempcx & 0xFF00) >> 8) << 4;
4405 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
4407 tempcx += 8;
4408 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
4409 tempcx -= 4;
4411 temp = tempcx & 0xFF;
4412 temp = temp << 4;
4413 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
4415 tempcx = push1; /* pop cx */
4416 j += 2;
4417 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4418 tempcx -= temp;
4419 temp = tempcx & 0x00FF;
4420 temp = temp << 4;
4421 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
4423 tempcx -= 11;
4425 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
4426 tempax = XGI_GetVGAHT2(pVBInfo);
4427 tempcx = tempax - 1;
4429 temp = tempcx & 0x00FF;
4430 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
4432 tempbx = pVBInfo->VDE;
4434 if (pVBInfo->VGAVDE == 360)
4435 tempbx = 746;
4436 if (pVBInfo->VGAVDE == 375)
4437 tempbx = 746;
4438 if (pVBInfo->VGAVDE == 405)
4439 tempbx = 853;
4441 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4442 if (pVBInfo->VBType &
4443 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
4444 if (!(pVBInfo->TVInfo &
4445 (TVSetYPbPr525p | TVSetYPbPr750p)))
4446 tempbx = tempbx >> 1;
4447 } else
4448 tempbx = tempbx >> 1;
4451 tempbx -= 2;
4452 temp = tempbx & 0x00FF;
4454 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
4455 if (pVBInfo->VBType & VB_SIS301LV) {
4456 if (pVBInfo->TVInfo & TVSetHiVision) {
4457 if (pVBInfo->VBInfo & SetInSlaveMode) {
4458 if (ModeNo == 0x2f)
4459 temp += 1;
4462 } else {
4463 if (pVBInfo->VBInfo & SetInSlaveMode) {
4464 if (ModeNo == 0x2f)
4465 temp += 1;
4470 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
4472 temp = (tempcx & 0xFF00) >> 8;
4473 temp |= ((tempbx & 0xFF00) >> 8) << 6;
4475 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
4476 if (pVBInfo->VBType & VB_SIS301LV) {
4477 if (pVBInfo->TVInfo & TVSetHiVision) {
4478 temp |= 0x10;
4480 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4481 temp |= 0x20;
4483 } else {
4484 temp |= 0x10;
4485 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4486 temp |= 0x20;
4490 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
4492 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4493 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
4494 tempbx = pVBInfo->VDE;
4495 tempcx = tempbx - 2;
4497 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4498 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
4499 | TVSetYPbPr750p)))
4500 tempbx = tempbx >> 1;
4503 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
4504 temp = 0;
4505 if (tempcx & 0x0400)
4506 temp |= 0x20;
4508 if (tempbx & 0x0400)
4509 temp |= 0x40;
4511 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
4514 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
4515 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
4516 temp = (tempbx - 3) & 0x00FF;
4517 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
4520 tempbx = tempbx & 0x00FF;
4522 if (!(modeflag & HalfDCLK)) {
4523 tempcx = pVBInfo->VGAHDE;
4524 if (tempcx >= pVBInfo->HDE) {
4525 tempbx |= 0x2000;
4526 tempax &= 0x00FF;
4530 tempcx = 0x0101;
4532 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
4533 if (pVBInfo->VGAHDE >= 1024) {
4534 tempcx = 0x1920;
4535 if (pVBInfo->VGAHDE >= 1280) {
4536 tempcx = 0x1420;
4537 tempbx = tempbx & 0xDFFF;
4542 if (!(tempbx & 0x2000)) {
4543 if (modeflag & HalfDCLK)
4544 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
4546 push1 = tempbx;
4547 tempeax = pVBInfo->VGAHDE;
4548 tempebx = (tempcx & 0xFF00) >> 8;
4549 longtemp = tempeax * tempebx;
4550 tempecx = tempcx & 0x00FF;
4551 longtemp = longtemp / tempecx;
4553 /* 301b */
4554 tempecx = 8 * 1024;
4556 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4557 | VB_SIS302LV | VB_XGI301C)) {
4558 tempecx = tempecx * 8;
4561 longtemp = longtemp * tempecx;
4562 tempecx = pVBInfo->HDE;
4563 temp2 = longtemp % tempecx;
4564 tempeax = longtemp / tempecx;
4565 if (temp2 != 0)
4566 tempeax += 1;
4568 tempax = (unsigned short) tempeax;
4570 /* 301b */
4571 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4572 | VB_SIS302LV | VB_XGI301C)) {
4573 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
4575 /* end 301b */
4577 tempbx = push1;
4578 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
4579 | (tempbx & 0x00FF));
4580 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
4581 | (tempax & 0x00FF));
4582 temp = (tempax & 0xFF00) >> 8;
4583 } else {
4584 temp = (tempax & 0x00FF) >> 8;
4587 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
4588 temp = (tempbx & 0xFF00) >> 8;
4589 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
4590 temp = tempcx & 0x00FF;
4592 if (tempbx & 0x2000)
4593 temp = 0;
4595 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4596 temp |= 0x18;
4598 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
4599 if (pVBInfo->TVInfo & TVSetPAL) {
4600 tempbx = 0x0382;
4601 tempcx = 0x007e;
4602 } else {
4603 tempbx = 0x0369;
4604 tempcx = 0x0061;
4607 temp = tempbx & 0x00FF;
4608 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
4609 temp = tempcx & 0x00FF;
4610 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
4612 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
4613 temp = temp << 2;
4614 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
4616 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4617 temp |= 0x10;
4619 if (pVBInfo->TVInfo & TVSetYPbPr525p)
4620 temp |= 0x20;
4622 if (pVBInfo->TVInfo & TVSetYPbPr750p)
4623 temp |= 0x60;
4626 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
4627 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
4628 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
4630 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
4631 if (pVBInfo->TVInfo & NTSC1024x768) {
4632 TimingPoint = XGI_NTSC1024AdjTime;
4633 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
4634 xgifb_reg_set(pVBInfo->Part2Port, i,
4635 TimingPoint[j]);
4637 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
4641 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
4642 if (pVBInfo->VBType & VB_XGI301C) {
4643 if (pVBInfo->TVInfo & TVSetPALM)
4644 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
4645 0x08); /* PALM Mode */
4648 if (pVBInfo->TVInfo & TVSetPALM) {
4649 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
4650 0x01);
4651 tempax--;
4652 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
4654 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
4657 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
4658 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4659 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
4662 if (pVBInfo->VBInfo & SetCRT2ToTV)
4663 return;
4666 static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4667 struct xgi_hw_device_info *HwDeviceExtension,
4668 unsigned short RefreshRateTableIndex,
4669 struct vb_device_info *pVBInfo)
4671 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
4672 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
4674 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
4676 /* si+Ext_ResInfo */
4677 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4678 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4679 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4680 CRT1Index &= IndexMask;
4682 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4683 return;
4685 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
4687 if (XGI_IsLCDDualLink(pVBInfo))
4688 tempbx = tempbx >> 1;
4690 tempbx -= 1;
4691 temp = tempbx & 0x00FF;
4692 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
4693 temp = (tempbx & 0xFF00) >> 8;
4694 temp = temp << 4;
4695 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
4696 temp = 0x01;
4698 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
4699 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
4700 push1 = tempbx;
4701 tempbx--;
4702 temp = tempbx & 0x00FF;
4703 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
4704 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
4705 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
4707 tempcx = pVBInfo->VT - 1;
4708 push2 = tempcx + 1;
4709 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
4710 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
4711 temp = (tempcx & 0xFF00) >> 8;
4712 temp = temp << 5;
4713 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
4714 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
4715 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
4716 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
4717 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
4719 /* Customized LCDB Des no add */
4720 tempbx = 5;
4721 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
4722 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
4723 tempah = pVBInfo->LCDResInfo;
4724 tempah &= PanelResInfo;
4726 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
4727 tempbx = 1024;
4728 tempcx = 768;
4729 } else if ((tempah == Panel_1280x1024) ||
4730 (tempah == Panel_1280x1024x75)) {
4731 tempbx = 1280;
4732 tempcx = 1024;
4733 } else if (tempah == Panel_1400x1050) {
4734 tempbx = 1400;
4735 tempcx = 1050;
4736 } else {
4737 tempbx = 1600;
4738 tempcx = 1200;
4741 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4742 tempbx = pVBInfo->HDE;
4743 tempcx = pVBInfo->VDE;
4746 pushbx = tempbx;
4747 tempax = pVBInfo->VT;
4748 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4749 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4750 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4751 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4752 tempbx = pVBInfo->LCDVDES;
4753 tempcx += tempbx;
4755 if (tempcx >= tempax)
4756 tempcx -= tempax; /* lcdvdes */
4758 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
4759 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
4760 temp = tempcx & 0x00FF;
4761 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
4762 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4763 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4764 tempah = tempch;
4765 tempah = tempah << 3;
4766 tempah |= tempbh;
4767 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
4769 /* getlcdsync() */
4770 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4771 tempcx = tempbx;
4772 tempax = pVBInfo->VT;
4773 tempbx = pVBInfo->LCDVRS;
4775 tempcx += tempbx;
4776 if (tempcx >= tempax)
4777 tempcx -= tempax;
4779 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
4780 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
4781 temp = (tempbx & 0xFF00) >> 8;
4782 temp = temp << 4;
4783 temp |= (tempcx & 0x000F);
4784 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
4785 tempcx = pushbx;
4786 tempax = pVBInfo->HT;
4787 tempbx = pVBInfo->LCDHDES;
4788 tempbx &= 0x0FFF;
4790 if (XGI_IsLCDDualLink(pVBInfo)) {
4791 tempax = tempax >> 1;
4792 tempbx = tempbx >> 1;
4793 tempcx = tempcx >> 1;
4796 if (pVBInfo->VBType & VB_SIS302LV)
4797 tempbx += 1;
4799 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4800 tempbx += 1;
4802 tempcx += tempbx;
4804 if (tempcx >= tempax)
4805 tempcx -= tempax;
4807 temp = tempbx & 0x00FF;
4808 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
4809 temp = ((tempbx & 0xFF00) >> 8) << 4;
4810 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
4811 temp = tempcx & 0x00FF;
4812 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
4813 temp = (tempcx & 0xFF00) >> 8;
4814 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
4816 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4817 tempcx = tempax;
4818 tempax = pVBInfo->HT;
4819 tempbx = pVBInfo->LCDHRS;
4820 if (XGI_IsLCDDualLink(pVBInfo)) {
4821 tempax = tempax >> 1;
4822 tempbx = tempbx >> 1;
4823 tempcx = tempcx >> 1;
4826 if (pVBInfo->VBType & VB_SIS302LV)
4827 tempbx += 1;
4829 tempcx += tempbx;
4831 if (tempcx >= tempax)
4832 tempcx -= tempax;
4834 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
4835 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
4837 temp = (tempbx & 0xFF00) >> 8;
4838 temp = temp << 4;
4839 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
4840 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
4841 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
4843 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
4844 if (pVBInfo->VGAVDE == 525) {
4845 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4846 | VB_SIS301LV | VB_SIS302LV
4847 | VB_XGI301C)) {
4848 temp = 0xC6;
4849 } else
4850 temp = 0xC4;
4852 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4853 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
4856 if (pVBInfo->VGAVDE == 420) {
4857 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4858 | VB_SIS301LV | VB_SIS302LV
4859 | VB_XGI301C)) {
4860 temp = 0x4F;
4861 } else
4862 temp = 0x4E;
4863 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4868 /* --------------------------------------------------------------------- */
4869 /* Function : XGI_GetTap4Ptr */
4870 /* Input : */
4871 /* Output : di -> Tap4 Reg. Setting Pointer */
4872 /* Description : */
4873 /* --------------------------------------------------------------------- */
4874 static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
4875 struct vb_device_info *pVBInfo)
4877 unsigned short tempax, tempbx, i;
4879 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
4881 if (tempcx == 0) {
4882 tempax = pVBInfo->VGAHDE;
4883 tempbx = pVBInfo->HDE;
4884 } else {
4885 tempax = pVBInfo->VGAVDE;
4886 tempbx = pVBInfo->VDE;
4889 if (tempax <= tempbx)
4890 return &xgifb_tap4_timing[0];
4891 else
4892 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
4894 if (pVBInfo->TVInfo & TVSetPAL)
4895 Tap4TimingPtr = PALTap4Timing;
4897 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4898 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4899 (pVBInfo->TVInfo & TVSetYPbPr525p))
4900 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
4901 if (pVBInfo->TVInfo & TVSetYPbPr750p)
4902 Tap4TimingPtr = YPbPr750pTap4Timing;
4905 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
4906 Tap4TimingPtr = xgifb_tap4_timing;
4908 i = 0;
4909 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4910 if (Tap4TimingPtr[i].DE == tempax)
4911 break;
4912 i++;
4914 return &Tap4TimingPtr[i];
4917 static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
4919 unsigned short i, j;
4921 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
4923 if (!(pVBInfo->VBType & VB_XGI301C))
4924 return;
4926 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4927 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
4928 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
4930 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
4931 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
4932 /* Set Vertical Scaling */
4933 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
4934 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
4935 xgifb_reg_set(pVBInfo->Part2Port,
4937 Tap4TimingPtr->Reg[j]);
4940 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
4941 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
4942 /* Enable V.Scaling */
4943 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
4944 else
4945 /* Enable H.Scaling */
4946 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
4949 static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
4950 struct vb_device_info *pVBInfo)
4952 unsigned short i;
4953 unsigned char *tempdi;
4954 unsigned short modeflag;
4956 /* si+Ext_ResInfo */
4957 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4959 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
4960 if (pVBInfo->TVInfo & TVSetPAL) {
4961 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4962 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4963 } else {
4964 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4965 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
4968 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4969 return;
4971 if (pVBInfo->TVInfo & TVSetPALM) {
4972 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4973 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4974 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
4977 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4978 & SetCRT2ToYPbPr525750)) {
4979 if (pVBInfo->TVInfo & TVSetYPbPr525i)
4980 return;
4982 tempdi = pVBInfo->HiTVGroup3Data;
4983 if (pVBInfo->SetFlag & TVSimuMode) {
4984 tempdi = pVBInfo->HiTVGroup3Simu;
4985 if (!(modeflag & Charx8Dot))
4986 tempdi = pVBInfo->HiTVGroup3Text;
4989 if (pVBInfo->TVInfo & TVSetYPbPr525p)
4990 tempdi = pVBInfo->Ren525pGroup3;
4992 if (pVBInfo->TVInfo & TVSetYPbPr750p)
4993 tempdi = pVBInfo->Ren750pGroup3;
4995 for (i = 0; i <= 0x3E; i++)
4996 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
4998 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
4999 if (pVBInfo->TVInfo & TVSetYPbPr525p)
5000 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
5003 return;
5004 } /* {end of XGI_SetGroup3} */
5006 static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
5007 unsigned short RefreshRateTableIndex,
5008 struct xgi_hw_device_info *HwDeviceExtension,
5009 struct vb_device_info *pVBInfo)
5011 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
5013 unsigned long tempebx, tempeax, templong;
5015 /* si+Ext_ResInfo */
5016 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5017 temp = pVBInfo->RVBHCFACT;
5018 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
5020 tempbx = pVBInfo->RVBHCMAX;
5021 temp = tempbx & 0x00FF;
5022 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
5023 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5024 tempcx = pVBInfo->VGAHT - 1;
5025 temp = tempcx & 0x00FF;
5026 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
5028 temp = ((tempcx & 0xFF00) >> 8) << 3;
5029 temp2 |= temp;
5031 tempcx = pVBInfo->VGAVT - 1;
5032 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5033 tempcx -= 5;
5035 temp = tempcx & 0x00FF;
5036 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
5037 temp = temp2 | ((tempcx & 0xFF00) >> 8);
5038 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
5039 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
5040 tempcx = pVBInfo->VBInfo;
5041 tempbx = pVBInfo->VGAHDE;
5043 if (modeflag & HalfDCLK)
5044 tempbx = tempbx >> 1;
5046 if (XGI_IsLCDDualLink(pVBInfo))
5047 tempbx = tempbx >> 1;
5049 if (tempcx & SetCRT2ToHiVision) {
5050 temp = 0;
5051 if (tempbx <= 1024)
5052 temp = 0xA0;
5053 if (tempbx == 1280)
5054 temp = 0xC0;
5055 } else if (tempcx & SetCRT2ToTV) {
5056 temp = 0xA0;
5057 if (tempbx <= 800)
5058 temp = 0x80;
5059 } else {
5060 temp = 0x80;
5061 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5062 temp = 0;
5063 if (tempbx > 800)
5064 temp = 0x60;
5068 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
5069 temp = 0x00;
5070 if (pVBInfo->VGAHDE == 1280)
5071 temp = 0x40;
5072 if (pVBInfo->VGAHDE == 1024)
5073 temp = 0x20;
5075 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
5077 tempebx = pVBInfo->VDE;
5079 if (tempcx & SetCRT2ToHiVision) {
5080 if (!(temp & 0xE000))
5081 tempbx = tempbx >> 1;
5084 tempcx = pVBInfo->RVBHRS;
5085 temp = tempcx & 0x00FF;
5086 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
5088 tempeax = pVBInfo->VGAVDE;
5089 tempcx |= 0x04000;
5091 if (tempeax <= tempebx) {
5092 tempcx = (tempcx & (~0x4000));
5093 tempeax = pVBInfo->VGAVDE;
5094 } else {
5095 tempeax -= tempebx;
5098 templong = (tempeax * 256 * 1024) % tempebx;
5099 tempeax = (tempeax * 256 * 1024) / tempebx;
5100 tempebx = tempeax;
5102 if (templong != 0)
5103 tempebx++;
5105 temp = (unsigned short) (tempebx & 0x000000FF);
5106 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
5108 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
5109 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
5110 tempbx = (unsigned short) (tempebx >> 16);
5111 temp = tempbx & 0x00FF;
5112 temp = temp << 4;
5113 temp |= ((tempcx & 0xFF00) >> 8);
5114 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
5116 /* 301b */
5117 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5118 | VB_SIS302LV | VB_XGI301C)) {
5119 temp = 0x0028;
5120 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
5121 tempax = pVBInfo->VGAHDE;
5122 if (modeflag & HalfDCLK)
5123 tempax = tempax >> 1;
5125 if (XGI_IsLCDDualLink(pVBInfo))
5126 tempax = tempax >> 1;
5128 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5129 if (tempax > 800)
5130 tempax -= 800;
5131 } else {
5132 if (pVBInfo->VGAHDE > 800) {
5133 if (pVBInfo->VGAHDE == 1024)
5134 tempax = (tempax * 25 / 32) - 1;
5135 else
5136 tempax = (tempax * 20 / 32) - 1;
5139 tempax -= 1;
5141 temp = (tempax & 0xFF00) >> 8;
5142 temp = ((temp & 0x0003) << 4);
5143 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
5144 temp = (tempax & 0x00FF);
5145 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
5147 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
5148 if (pVBInfo->VGAHDE > 800)
5149 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
5152 temp = 0x0036;
5154 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5155 if (!(pVBInfo->TVInfo & (NTSC1024x768
5156 | TVSetYPbPr525p | TVSetYPbPr750p
5157 | TVSetHiVision))) {
5158 temp |= 0x0001;
5159 if ((pVBInfo->VBInfo & SetInSlaveMode)
5160 && (!(pVBInfo->TVInfo
5161 & TVSimuMode)))
5162 temp &= (~0x0001);
5166 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
5167 tempbx = pVBInfo->HT;
5168 if (XGI_IsLCDDualLink(pVBInfo))
5169 tempbx = tempbx >> 1;
5170 tempbx = (tempbx >> 1) - 2;
5171 temp = ((tempbx & 0x0700) >> 8) << 3;
5172 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
5173 temp = tempbx & 0x00FF;
5174 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
5176 /* end 301b */
5178 if (pVBInfo->ISXPDOS == 0)
5179 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5180 pVBInfo);
5183 static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5185 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
5188 static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
5189 struct vb_device_info *pVBInfo)
5191 unsigned short Pindex, Pdata;
5193 Pindex = pVBInfo->Part5Port;
5194 Pdata = pVBInfo->Part5Port + 1;
5195 if (pVBInfo->ModeType == ModeVGA) {
5196 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
5197 | DisableCRT2Display))) {
5198 XGINew_EnableCRT2(pVBInfo);
5201 return;
5204 static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
5205 struct vb_device_info *pVBInfo)
5207 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
5210 static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
5211 struct vb_device_info *pVBInfo)
5214 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
5217 static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
5218 unsigned short ModeNo, unsigned short ModeIdIndex,
5219 struct vb_device_info *pVBInfo)
5221 unsigned short xres, yres, colordepth, modeflag, resindex;
5223 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5224 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5225 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5226 /* si+St_ModeFlag */
5227 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5229 if (!(modeflag & Charx8Dot)) {
5230 xres /= 9;
5231 xres *= 8;
5234 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
5235 xres *= 2;
5237 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
5238 yres *= 2;
5240 if (xres > xgifb_info->lvds_data.LVDSHDE)
5241 return 0;
5243 if (yres > xgifb_info->lvds_data.LVDSVDE)
5244 return 0;
5246 if (xres != xgifb_info->lvds_data.LVDSHDE ||
5247 yres != xgifb_info->lvds_data.LVDSVDE) {
5248 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
5249 if (colordepth > 2)
5250 return 0;
5252 return 1;
5255 static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
5256 int chip_id,
5257 unsigned short ModeNo,
5258 unsigned short ModeIdIndex,
5259 struct vb_device_info *pVBInfo)
5261 unsigned char temp, Miscdata;
5262 unsigned short xres, yres, modeflag, resindex;
5263 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
5264 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
5265 unsigned short value;
5267 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
5268 (LCDPolarity << 8)) >> 8);
5269 temp &= LCDPolarity;
5270 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
5272 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
5274 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
5275 /* SR35[7] FP VSync polarity */
5276 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
5277 /* SR30[5] FP HSync polarity */
5278 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
5280 if (chip_id == XG27)
5281 XGI_SetXG27FPBits(pVBInfo);
5282 else
5283 XGI_SetXG21FPBits(pVBInfo);
5285 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5286 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5287 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5288 /* si+St_ModeFlag */
5289 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5291 if (!(modeflag & Charx8Dot))
5292 xres = xres * 8 / 9;
5294 LVDSHT = xgifb_info->lvds_data.LVDSHT;
5296 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
5298 if (LVDSHBS > LVDSHT)
5299 LVDSHBS -= LVDSHT;
5301 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
5302 if (LVDSHRS > LVDSHT)
5303 LVDSHRS -= LVDSHT;
5305 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
5306 if (LVDSHRE > LVDSHT)
5307 LVDSHRE -= LVDSHT;
5309 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
5311 LVDSVT = xgifb_info->lvds_data.LVDSVT;
5313 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
5314 if (modeflag & DoubleScanMode)
5315 LVDSVBS += yres / 2;
5317 if (LVDSVBS > LVDSVT)
5318 LVDSVBS -= LVDSVT;
5320 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
5321 if (LVDSVRS > LVDSVT)
5322 LVDSVRS -= LVDSVT;
5324 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
5325 if (LVDSVRE > LVDSVT)
5326 LVDSVRE -= LVDSVT;
5328 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
5330 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
5331 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
5333 if (!(modeflag & Charx8Dot))
5334 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
5336 /* HT SR0B[1:0] CR00 */
5337 value = (LVDSHT >> 3) - 5;
5338 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
5339 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
5341 /* HBS SR0B[5:4] CR02 */
5342 value = (LVDSHBS >> 3) - 1;
5343 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
5344 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
5346 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
5347 value = (LVDSHBE >> 3) - 1;
5348 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
5349 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
5350 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
5352 /* HRS SR0B[7:6] CR04 */
5353 value = (LVDSHRS >> 3) + 2;
5354 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
5355 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
5357 /* Panel HRS SR2F[1:0] SR2E[7:0] */
5358 value--;
5359 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
5360 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
5362 /* HRE SR0C[2] CR05[4:0] */
5363 value = (LVDSHRE >> 3) + 2;
5364 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
5365 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
5367 /* Panel HRE SR2F[7:2] */
5368 value--;
5369 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
5371 /* VT SR0A[0] CR07[5][0] CR06 */
5372 value = LVDSVT - 2;
5373 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
5374 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
5375 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
5376 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
5378 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
5379 value = LVDSVBS - 1;
5380 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
5381 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
5382 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
5383 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
5385 /* VBE SR0A[4] CR16 */
5386 value = LVDSVBE - 1;
5387 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
5388 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
5390 /* VRS SR0A[3] CR7[7][2] CR10 */
5391 value = LVDSVRS - 1;
5392 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
5393 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
5394 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
5395 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
5397 if (chip_id == XG27) {
5398 /* Panel VRS SR35[2:0] SR34[7:0] */
5399 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
5400 (value & 0x700) >> 8);
5401 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
5402 } else {
5403 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
5404 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
5405 (value & 0x600) >> 9);
5406 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
5407 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
5410 /* VRE SR0A[5] CR11[3:0] */
5411 value = LVDSVRE - 1;
5412 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
5413 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
5415 /* Panel VRE SR3F[7:2] */
5416 if (chip_id == XG27)
5417 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5418 (value << 2) & 0xFC);
5419 else
5420 /* SR3F[7] has to be 0, h/w bug */
5421 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5422 (value << 2) & 0x7C);
5424 for (temp = 0, value = 0; temp < 3; temp++) {
5426 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
5427 xgifb_reg_set(pVBInfo->P3c4,
5428 0x2B, xgifb_info->lvds_data.VCLKData1);
5429 xgifb_reg_set(pVBInfo->P3c4,
5430 0x2C, xgifb_info->lvds_data.VCLKData2);
5431 value += 0x10;
5434 if (!(modeflag & Charx8Dot)) {
5435 inb(pVBInfo->P3da); /* reset 3da */
5436 outb(0x13, pVBInfo->P3c0); /* set index */
5437 /* set data, panning = 0, shift left 1 dot*/
5438 outb(0x00, pVBInfo->P3c0);
5440 inb(pVBInfo->P3da); /* Enable Attribute */
5441 outb(0x20, pVBInfo->P3c0);
5443 inb(pVBInfo->P3da); /* reset 3da */
5448 /* --------------------------------------------------------------------- */
5449 /* Function : XGI_IsLCDON */
5450 /* Input : */
5451 /* Output : 0 : Skip PSC Control */
5452 /* 1: Disable PSC */
5453 /* Description : */
5454 /* --------------------------------------------------------------------- */
5455 static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
5457 unsigned short tempax;
5459 tempax = pVBInfo->VBInfo;
5460 if (tempax & SetCRT2ToDualEdge)
5461 return 0;
5462 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
5463 return 1;
5465 return 0;
5468 /* --------------------------------------------------------------------- */
5469 /* Function : XGI_DisableChISLCD */
5470 /* Input : */
5471 /* Output : 0 -> Not LCD Mode */
5472 /* Description : */
5473 /* --------------------------------------------------------------------- */
5474 static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
5476 unsigned short tempbx, tempah;
5478 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
5479 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
5481 if (tempbx & (EnableChA | DisableChA)) {
5482 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5483 return 0;
5486 if (!(tempbx & (EnableChB | DisableChB)))
5487 return 0;
5489 if (tempah & 0x01) /* Chk LCDB Mode */
5490 return 1;
5492 return 0;
5495 /* --------------------------------------------------------------------- */
5496 /* Function : XGI_EnableChISLCD */
5497 /* Input : */
5498 /* Output : 0 -> Not LCD mode */
5499 /* Description : */
5500 /* --------------------------------------------------------------------- */
5501 static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
5503 unsigned short tempbx, tempah;
5505 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
5506 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
5508 if (tempbx & (EnableChA | DisableChA)) {
5509 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5510 return 0;
5513 if (!(tempbx & (EnableChB | DisableChB)))
5514 return 0;
5516 if (tempah & 0x01) /* Chk LCDB Mode */
5517 return 1;
5519 return 0;
5522 static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
5523 struct xgi_hw_device_info *HwDeviceExtension,
5524 struct vb_device_info *pVBInfo)
5526 unsigned short tempah = 0;
5528 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5529 | VB_SIS302LV | VB_XGI301C)) {
5530 tempah = 0x3F;
5531 if (!(pVBInfo->VBInfo &
5532 (DisableCRT2Display | SetSimuScanMode))) {
5533 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5534 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5535 tempah = 0x7F; /* Disable Channel A */
5536 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
5537 /* Disable Channel B */
5538 tempah = 0xBF;
5540 if (pVBInfo->SetFlag & DisableChB)
5541 /* force to disable Cahnnel */
5542 tempah &= 0xBF;
5544 if (pVBInfo->SetFlag & DisableChA)
5545 /* Force to disable Channel B */
5546 tempah &= 0x7F;
5551 /* disable part4_1f */
5552 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
5554 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
5555 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5556 || (XGI_DisableChISLCD(pVBInfo))
5557 || (XGI_IsLCDON(pVBInfo)))
5558 /* LVDS Driver power down */
5559 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
5562 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
5563 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
5564 | SetSimuScanMode))) {
5565 if (pVBInfo->SetFlag & GatingCRT)
5566 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
5567 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
5570 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5571 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
5572 & XGI_SetCRT2ToLCDA))
5573 /* Power down */
5574 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
5577 /* disable TV as primary VGA swap */
5578 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
5580 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
5581 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
5583 if ((pVBInfo->SetFlag & DisableChB) ||
5584 (pVBInfo->VBInfo &
5585 (DisableCRT2Display | SetSimuScanMode)) ||
5586 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
5587 (pVBInfo->VBInfo &
5588 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
5589 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
5591 if ((pVBInfo->SetFlag & DisableChB) ||
5592 (pVBInfo->VBInfo &
5593 (DisableCRT2Display | SetSimuScanMode)) ||
5594 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
5595 (pVBInfo->VBInfo &
5596 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
5597 /* save Part1 index 0 */
5598 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
5599 /* BTDAC = 1, avoid VB reset */
5600 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
5601 /* disable CRT2 */
5602 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5603 /* restore Part1 index 0 */
5604 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
5606 } else { /* {301} */
5607 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
5608 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
5609 /* Disable CRT2 */
5610 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5611 /* Disable TV asPrimary VGA swap */
5612 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
5615 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
5616 | SetSimuScanMode))
5617 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
5621 /* --------------------------------------------------------------------- */
5622 /* Function : XGI_GetTVPtrIndex */
5623 /* Input : */
5624 /* Output : */
5625 /* Description : bx 0 : ExtNTSC */
5626 /* 1 : StNTSC */
5627 /* 2 : ExtPAL */
5628 /* 3 : StPAL */
5629 /* 4 : ExtHiTV */
5630 /* 5 : StHiTV */
5631 /* 6 : Ext525i */
5632 /* 7 : St525i */
5633 /* 8 : Ext525p */
5634 /* 9 : St525p */
5635 /* A : Ext750p */
5636 /* B : St750p */
5637 /* --------------------------------------------------------------------- */
5638 static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
5640 unsigned short tempbx = 0;
5642 if (pVBInfo->TVInfo & TVSetPAL)
5643 tempbx = 2;
5644 if (pVBInfo->TVInfo & TVSetHiVision)
5645 tempbx = 4;
5646 if (pVBInfo->TVInfo & TVSetYPbPr525i)
5647 tempbx = 6;
5648 if (pVBInfo->TVInfo & TVSetYPbPr525p)
5649 tempbx = 8;
5650 if (pVBInfo->TVInfo & TVSetYPbPr750p)
5651 tempbx = 10;
5652 if (pVBInfo->TVInfo & TVSimuMode)
5653 tempbx++;
5655 return tempbx;
5658 /* --------------------------------------------------------------------- */
5659 /* Function : XGI_GetTVPtrIndex2 */
5660 /* Input : */
5661 /* Output : bx 0 : NTSC */
5662 /* 1 : PAL */
5663 /* 2 : PALM */
5664 /* 3 : PALN */
5665 /* 4 : NTSC1024x768 */
5666 /* 5 : PAL-M 1024x768 */
5667 /* 6-7: reserved */
5668 /* cl 0 : YFilter1 */
5669 /* 1 : YFilter2 */
5670 /* ch 0 : 301A */
5671 /* 1 : 301B/302B/301LV/302LV */
5672 /* Description : */
5673 /* --------------------------------------------------------------------- */
5674 static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
5675 unsigned char *tempch, struct vb_device_info *pVBInfo)
5677 *tempbx = 0;
5678 *tempcl = 0;
5679 *tempch = 0;
5681 if (pVBInfo->TVInfo & TVSetPAL)
5682 *tempbx = 1;
5684 if (pVBInfo->TVInfo & TVSetPALM)
5685 *tempbx = 2;
5687 if (pVBInfo->TVInfo & TVSetPALN)
5688 *tempbx = 3;
5690 if (pVBInfo->TVInfo & NTSC1024x768) {
5691 *tempbx = 4;
5692 if (pVBInfo->TVInfo & TVSetPALM)
5693 *tempbx = 5;
5696 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5697 | VB_SIS302LV | VB_XGI301C)) {
5698 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
5699 & TVSimuMode)) {
5700 *tempbx += 8;
5701 *tempcl += 1;
5705 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5706 | VB_SIS302LV | VB_XGI301C))
5707 (*tempch)++;
5710 static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
5712 unsigned char tempah, tempbl, tempbh;
5714 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5715 | VB_SIS302LV | VB_XGI301C)) {
5716 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
5717 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
5718 tempbh = 0;
5719 tempbl = XGI301TVDelay;
5721 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5722 tempbl = tempbl >> 4;
5723 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
5724 tempbh = XGI301LCDDelay;
5726 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
5727 tempbl = tempbh;
5730 tempbl &= 0x0F;
5731 tempbh &= 0xF0;
5732 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
5734 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5735 | SetCRT2ToTV)) { /* Channel B */
5736 tempah &= 0xF0;
5737 tempah |= tempbl;
5740 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { /* Channel A */
5741 tempah &= 0x0F;
5742 tempah |= tempbh;
5744 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
5746 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5747 tempbl = 0;
5748 tempbh = 0;
5749 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5750 tempah = XGI301LCDDelay;
5751 tempah &= 0x0f;
5752 tempah = tempah << 4;
5753 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
5754 tempah);
5759 static void XGI_SetLCDCap_A(unsigned short tempcx,
5760 struct vb_device_info *pVBInfo)
5762 unsigned short temp;
5764 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
5766 if (temp & LCDRGB18Bit) {
5767 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
5768 /* Enable Dither */
5769 (unsigned short) (0x20 | (tempcx & 0x00C0)));
5770 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
5771 } else {
5772 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
5773 (unsigned short) (0x30 | (tempcx & 0x00C0)));
5774 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
5778 /* --------------------------------------------------------------------- */
5779 /* Function : XGI_SetLCDCap_B */
5780 /* Input : cx -> LCD Capability */
5781 /* Output : */
5782 /* Description : */
5783 /* --------------------------------------------------------------------- */
5784 static void XGI_SetLCDCap_B(unsigned short tempcx,
5785 struct vb_device_info *pVBInfo)
5787 if (tempcx & EnableLCD24bpp) /* 24bits */
5788 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
5789 (unsigned short) (((tempcx & 0x00ff) >> 6)
5790 | 0x0c));
5791 else
5792 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
5793 (unsigned short) (((tempcx & 0x00ff) >> 6)
5794 | 0x18)); /* Enable Dither */
5797 static void XGI_LongWait(struct vb_device_info *pVBInfo)
5799 unsigned short i;
5801 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5803 if (!(i & 0xC0)) {
5804 for (i = 0; i < 0xFFFF; i++) {
5805 if (!(inb(pVBInfo->P3da) & 0x08))
5806 break;
5809 for (i = 0; i < 0xFFFF; i++) {
5810 if ((inb(pVBInfo->P3da) & 0x08))
5811 break;
5816 static void SetSpectrum(struct vb_device_info *pVBInfo)
5818 unsigned short index;
5820 index = XGI_GetLCDCapPtr(pVBInfo);
5822 /* disable down spectrum D[4] */
5823 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
5824 XGI_LongWait(pVBInfo);
5825 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
5826 XGI_LongWait(pVBInfo);
5828 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
5829 pVBInfo->LCDCapList[index].Spectrum_31);
5830 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
5831 pVBInfo->LCDCapList[index].Spectrum_32);
5832 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
5833 pVBInfo->LCDCapList[index].Spectrum_33);
5834 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
5835 pVBInfo->LCDCapList[index].Spectrum_34);
5836 XGI_LongWait(pVBInfo);
5837 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
5840 static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5842 unsigned short tempcx;
5844 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5846 if (pVBInfo->VBType &
5847 (VB_SIS301B |
5848 VB_SIS302B |
5849 VB_SIS301LV |
5850 VB_SIS302LV |
5851 VB_XGI301C)) { /* 301LV/302LV only */
5852 if (pVBInfo->VBType &
5853 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
5854 /* Set 301LV Capability */
5855 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
5856 (unsigned char) (tempcx & 0x1F));
5858 /* VB Driving */
5859 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
5860 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5861 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5862 | EnablePLLSPLOW)) >> 8));
5865 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5866 | VB_SIS302LV | VB_XGI301C)) {
5867 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5868 XGI_SetLCDCap_B(tempcx, pVBInfo);
5869 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5870 XGI_SetLCDCap_A(tempcx, pVBInfo);
5872 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
5873 if (tempcx & EnableSpectrum)
5874 SetSpectrum(pVBInfo);
5876 } else {
5877 /* LVDS,CH7017 */
5878 XGI_SetLCDCap_A(tempcx, pVBInfo);
5882 /* --------------------------------------------------------------------- */
5883 /* Function : XGI_SetAntiFlicker */
5884 /* Input : */
5885 /* Output : */
5886 /* Description : Set TV Customized Param. */
5887 /* --------------------------------------------------------------------- */
5888 static void XGI_SetAntiFlicker(unsigned short ModeNo,
5889 unsigned short ModeIdIndex,
5890 struct vb_device_info *pVBInfo)
5892 unsigned short tempbx;
5894 unsigned char tempah;
5896 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
5897 return;
5899 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5900 tempbx &= 0xFE;
5901 tempah = TVAntiFlickList[tempbx];
5902 tempah = tempah << 4;
5904 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
5907 static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5908 unsigned short ModeIdIndex,
5909 struct vb_device_info *pVBInfo)
5911 unsigned short tempbx;
5913 unsigned char tempah;
5915 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5916 tempbx &= 0xFE;
5917 tempah = TVEdgeList[tempbx];
5918 tempah = tempah << 5;
5920 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
5923 static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
5925 unsigned short tempbx;
5927 unsigned char tempcl, tempch;
5929 unsigned long tempData;
5931 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5932 tempData = TVPhaseList[tempbx];
5934 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
5935 & 0x000000FF));
5936 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
5937 & 0x0000FF00) >> 8));
5938 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
5939 & 0x00FF0000) >> 16));
5940 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
5941 & 0xFF000000) >> 24));
5944 static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
5945 struct vb_device_info *pVBInfo)
5947 unsigned short tempbx, index;
5949 unsigned char tempcl, tempch, tempal, *filterPtr;
5951 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5953 switch (tempbx) {
5954 case 0x00:
5955 case 0x04:
5956 filterPtr = NTSCYFilter1;
5957 break;
5959 case 0x01:
5960 filterPtr = PALYFilter1;
5961 break;
5963 case 0x02:
5964 case 0x05:
5965 case 0x0D:
5966 case 0x03:
5967 filterPtr = xgifb_palmn_yfilter1;
5968 break;
5970 case 0x08:
5971 case 0x0C:
5972 case 0x0A:
5973 case 0x0B:
5974 case 0x09:
5975 filterPtr = xgifb_yfilter2;
5976 break;
5978 default:
5979 return;
5982 tempal = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
5983 if (tempcl == 0)
5984 index = tempal * 4;
5985 else
5986 index = tempal * 7;
5988 if ((tempcl == 0) && (tempch == 1)) {
5989 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5990 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5991 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5992 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
5993 } else {
5994 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5995 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5996 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5997 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
6000 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6001 | VB_SIS302LV | VB_XGI301C)) {
6002 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6003 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6004 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
6008 /* --------------------------------------------------------------------- */
6009 /* Function : XGI_OEM310Setting */
6010 /* Input : */
6011 /* Output : */
6012 /* Description : Customized Param. for 301 */
6013 /* --------------------------------------------------------------------- */
6014 static void XGI_OEM310Setting(unsigned short ModeNo,
6015 unsigned short ModeIdIndex,
6016 struct vb_device_info *pVBInfo)
6018 XGI_SetDelayComp(pVBInfo);
6020 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
6021 XGI_SetLCDCap(pVBInfo);
6023 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6024 XGI_SetPhaseIncr(pVBInfo);
6025 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6026 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
6028 if (pVBInfo->VBType & VB_SIS301)
6029 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
6033 /* --------------------------------------------------------------------- */
6034 /* Function : XGI_SetCRT2ModeRegs */
6035 /* Input : */
6036 /* Output : */
6037 /* Description : Origin code for crt2group */
6038 /* --------------------------------------------------------------------- */
6039 static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
6040 struct xgi_hw_device_info *HwDeviceExtension,
6041 struct vb_device_info *pVBInfo)
6043 unsigned short tempbl;
6044 short tempcl;
6046 unsigned char tempah;
6048 tempah = 0;
6049 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6050 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6051 tempah &= ~0x10; /* BTRAMDAC */
6052 tempah |= 0x40; /* BTRAM */
6054 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6055 | SetCRT2ToLCD)) {
6056 tempah = 0x40; /* BTDRAM */
6057 tempcl = pVBInfo->ModeType;
6058 tempcl -= ModeVGA;
6059 if (tempcl >= 0) {
6060 /* BT Color */
6061 tempah = (0x008 >> tempcl);
6062 if (tempah == 0)
6063 tempah = 1;
6064 tempah |= 0x040;
6066 if (pVBInfo->VBInfo & SetInSlaveMode)
6067 tempah ^= 0x50; /* BTDAC */
6071 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
6072 tempah = 0x08;
6073 tempbl = 0xf0;
6075 if (pVBInfo->VBInfo & DisableCRT2Display) {
6076 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
6077 } else {
6078 tempah = 0x00;
6079 tempbl = 0xff;
6081 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6082 | SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
6083 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
6084 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
6085 tempbl &= 0xf7;
6086 tempah |= 0x01;
6087 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
6088 tempbl, tempah);
6089 } else {
6090 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6091 tempbl &= 0xf7;
6092 tempah |= 0x01;
6095 if (pVBInfo->VBInfo &
6096 (SetCRT2ToRAMDAC |
6097 SetCRT2ToTV |
6098 SetCRT2ToLCD)) {
6099 tempbl &= 0xf8;
6100 tempah = 0x01;
6102 if (!(pVBInfo->VBInfo & SetInSlaveMode))
6103 tempah |= 0x02;
6105 if (!(pVBInfo->VBInfo &
6106 SetCRT2ToRAMDAC)) {
6107 tempah = tempah ^ 0x05;
6108 if (!(pVBInfo->VBInfo &
6109 SetCRT2ToLCD))
6110 tempah = tempah ^ 0x01;
6113 if (!(pVBInfo->VBInfo &
6114 SetCRT2ToDualEdge))
6115 tempah |= 0x08;
6116 xgifb_reg_and_or(pVBInfo->Part1Port,
6117 0x2e, tempbl, tempah);
6118 } else {
6119 xgifb_reg_and_or(pVBInfo->Part1Port,
6120 0x2e, tempbl, tempah);
6123 } else {
6124 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
6125 tempah);
6129 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
6130 | XGI_SetCRT2ToLCDA)) {
6131 tempah &= (~0x08);
6132 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
6133 & SetInSlaveMode))) {
6134 tempah |= 0x010;
6136 tempah |= 0x080;
6138 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6139 tempah |= 0x020;
6140 if (pVBInfo->VBInfo & DriverMode)
6141 tempah = tempah ^ 0x20;
6144 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
6145 tempah = 0;
6147 if (pVBInfo->LCDInfo & SetLCDDualLink)
6148 tempah |= 0x40;
6150 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6151 if (pVBInfo->TVInfo & RPLLDIV2XO)
6152 tempah |= 0x40;
6155 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
6156 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
6157 tempah |= 0x80;
6159 if (pVBInfo->LCDResInfo == Panel_1280x960)
6160 tempah |= 0x80;
6162 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
6165 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6166 | VB_SIS302LV | VB_XGI301C)) {
6167 tempah = 0;
6168 tempbl = 0xfb;
6170 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6171 tempbl = 0xff;
6172 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
6173 tempah |= 0x04; /* shampoo 0129 */
6176 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
6177 tempah = 0x00;
6178 tempbl = 0xcf;
6179 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6180 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6181 tempah |= 0x30;
6184 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
6185 tempah = 0;
6186 tempbl = 0x3f;
6188 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6189 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6190 tempah |= 0xc0;
6192 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
6195 tempah = 0;
6196 tempbl = 0x7f;
6197 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
6198 tempbl = 0xff;
6199 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
6200 tempah |= 0x80;
6203 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
6205 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
6206 if (pVBInfo->LCDInfo & SetLCDDualLink) {
6207 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
6208 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
6214 void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6215 struct vb_device_info *pVBInfo)
6218 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
6222 void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6223 struct vb_device_info *pVBInfo)
6226 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
6230 unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
6232 unsigned short flag;
6234 if (pVBInfo->IF_DEF_LVDS == 1) {
6235 return 1;
6236 } else {
6237 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
6238 if ((flag == 1) || (flag == 2))
6239 return 1; /* 301b */
6240 else
6241 return 0;
6245 unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
6246 unsigned short ModeNo, unsigned short ModeIdIndex,
6247 struct vb_device_info *pVBInfo)
6249 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
6250 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
6251 0x01, 0x01 };
6253 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
6255 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6257 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
6258 index = index >> pVBInfo->SelectCRT2Rate;
6259 index &= 0x0F;
6261 if (pVBInfo->LCDInfo & LCDNonExpanding)
6262 index = 0;
6264 if (index > 0)
6265 index--;
6267 if (pVBInfo->SetFlag & ProgrammingCRT2) {
6268 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
6269 if (pVBInfo->IF_DEF_LVDS == 0) {
6270 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
6271 | VB_SIS301LV | VB_SIS302LV
6272 | VB_XGI301C))
6273 /* 301b */
6274 temp = LCDARefreshIndex[
6275 pVBInfo->LCDResInfo & 0x0F];
6276 else
6277 temp = LCDRefreshIndex[
6278 pVBInfo->LCDResInfo & 0x0F];
6280 if (index > temp)
6281 index = temp;
6282 } else {
6283 index = 0;
6288 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
6289 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
6290 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
6291 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
6292 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
6293 index++;
6295 /* Alan 10/19/2007;
6296 * do the similar adjustment like XGISearchCRT1Rate() */
6297 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
6298 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
6299 index++;
6301 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
6302 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
6303 index++;
6307 i = 0;
6308 do {
6309 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
6310 ModeID != ModeNo)
6311 break;
6312 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
6313 Ext_InfoFlag;
6314 temp &= ModeTypeMask;
6315 if (temp < pVBInfo->ModeType)
6316 break;
6317 i++;
6318 index--;
6320 } while (index != 0xFFFF);
6321 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
6322 if (pVBInfo->VBInfo & SetInSlaveMode) {
6323 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
6324 Ext_InfoFlag;
6325 if (temp & InterlaceMode)
6326 i++;
6329 i--;
6330 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
6331 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
6332 RefreshRateTableIndex, &i, pVBInfo);
6334 return RefreshRateTableIndex + i;
6337 static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
6338 struct xgi_hw_device_info *HwDeviceExtension,
6339 struct vb_device_info *pVBInfo)
6341 unsigned short RefreshRateTableIndex;
6343 pVBInfo->SetFlag |= ProgrammingCRT2;
6344 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6345 ModeIdIndex, pVBInfo);
6346 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
6347 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6348 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6349 HwDeviceExtension, pVBInfo);
6350 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6351 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6354 static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
6355 struct xgi_hw_device_info *HwDeviceExtension,
6356 struct vb_device_info *pVBInfo)
6358 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
6360 tempbx = pVBInfo->VBInfo;
6361 pVBInfo->SetFlag |= ProgrammingCRT2;
6362 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6363 pVBInfo->SelectCRT2Rate = 4;
6364 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6365 ModeIdIndex, pVBInfo);
6366 XGI_SaveCRT2Info(ModeNo, pVBInfo);
6367 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
6368 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6369 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6370 RefreshRateTableIndex, pVBInfo);
6371 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6372 RefreshRateTableIndex, pVBInfo);
6373 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6374 RefreshRateTableIndex, pVBInfo);
6375 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6376 HwDeviceExtension, pVBInfo);
6377 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6378 RefreshRateTableIndex, pVBInfo);
6379 XGI_SetTap4Regs(pVBInfo);
6380 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
6381 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6382 HwDeviceExtension, pVBInfo);
6383 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6384 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
6385 XGI_AutoThreshold(pVBInfo);
6386 return 1;
6389 void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
6391 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
6392 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
6393 0x05, 0x00 };
6395 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
6397 unsigned char CR17, CR63, SR31;
6398 unsigned short temp;
6399 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
6401 int i;
6402 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
6404 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
6405 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
6406 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
6407 pVBInfo->P3d4, 0x53) | 0x02));
6409 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
6410 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
6411 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
6413 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
6414 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
6416 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
6417 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
6419 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
6420 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
6422 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
6423 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
6424 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
6425 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
6427 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
6429 for (i = 0; i < 8; i++)
6430 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
6432 for (i = 8; i < 11; i++)
6433 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
6434 CRTCData[i]);
6436 for (i = 11; i < 13; i++)
6437 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
6438 CRTCData[i]);
6440 for (i = 13; i < 16; i++)
6441 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
6442 CRTCData[i]);
6444 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
6445 & 0xE0));
6447 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
6448 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
6449 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
6451 outb(0x00, pVBInfo->P3c8);
6453 for (i = 0; i < 256; i++) {
6454 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
6455 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
6456 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
6459 mdelay(1);
6461 XGI_WaitDisply(pVBInfo);
6462 temp = inb(pVBInfo->P3c2);
6464 if (temp & 0x10)
6465 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
6466 else
6467 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
6469 /* alan, avoid display something, set BLACK DAC if not restore DAC */
6470 outb(0x00, pVBInfo->P3c8);
6472 for (i = 0; i < 256; i++) {
6473 outb(0, (pVBInfo->P3c8 + 1));
6474 outb(0, (pVBInfo->P3c8 + 1));
6475 outb(0, (pVBInfo->P3c8 + 1));
6478 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
6479 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
6480 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
6482 /* [2004/05/11] Vicent */
6483 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
6484 pVBInfo->P3d4, 0x53) & 0xFD));
6485 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
6488 static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
6489 struct xgi_hw_device_info *HwDeviceExtension,
6490 struct vb_device_info *pVBInfo)
6492 unsigned short tempah;
6494 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6495 | VB_SIS302LV | VB_XGI301C)) {
6496 if (!(pVBInfo->SetFlag & DisableChA)) {
6497 if (pVBInfo->SetFlag & EnableChA) {
6498 /* Power on */
6499 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
6500 } else {
6501 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6502 /* Power on */
6503 xgifb_reg_set(pVBInfo->Part1Port,
6504 0x1E, 0x20);
6509 if (!(pVBInfo->SetFlag & DisableChB)) {
6510 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
6511 & (SetCRT2ToLCD | SetCRT2ToTV
6512 | SetCRT2ToRAMDAC))) {
6513 tempah = (unsigned char) xgifb_reg_get(
6514 pVBInfo->P3c4, 0x32);
6515 tempah &= 0xDF;
6516 if (pVBInfo->VBInfo & SetInSlaveMode) {
6517 if (!(pVBInfo->VBInfo &
6518 SetCRT2ToRAMDAC))
6519 tempah |= 0x20;
6521 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
6522 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
6524 tempah = (unsigned char) xgifb_reg_get(
6525 pVBInfo->Part1Port, 0x2E);
6527 if (!(tempah & 0x80))
6528 xgifb_reg_or(pVBInfo->Part1Port,
6529 0x2E, 0x80);
6530 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
6534 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
6535 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
6536 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
6537 0x20); /* shampoo 0129 */
6538 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
6539 if (!XGI_DisableChISLCD(pVBInfo)) {
6540 if (XGI_EnableChISLCD(pVBInfo) ||
6541 (pVBInfo->VBInfo &
6542 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
6543 /* LVDS PLL power on */
6544 xgifb_reg_and(
6545 pVBInfo->Part4Port,
6546 0x2A,
6547 0x7F);
6549 /* LVDS Driver power on */
6550 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
6554 tempah = 0x00;
6556 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6557 tempah = 0xc0;
6559 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
6560 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6561 if (pVBInfo->VBInfo &
6562 SetCRT2ToDualEdge) {
6563 tempah = tempah & 0x40;
6564 if (pVBInfo->VBInfo &
6565 XGI_SetCRT2ToLCDA)
6566 tempah = tempah ^ 0xC0;
6568 if (pVBInfo->SetFlag &
6569 DisableChB)
6570 tempah &= 0xBF;
6572 if (pVBInfo->SetFlag &
6573 DisableChA)
6574 tempah &= 0x7F;
6576 if (pVBInfo->SetFlag &
6577 EnableChB)
6578 tempah |= 0x40;
6580 if (pVBInfo->SetFlag &
6581 EnableChA)
6582 tempah |= 0x80;
6588 /* EnablePart4_1F */
6589 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
6591 if (!(pVBInfo->SetFlag & DisableChA)) {
6592 if (!(pVBInfo->SetFlag & GatingCRT)) {
6593 XGI_DisableGatingCRT(HwDeviceExtension,
6594 pVBInfo);
6595 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
6596 pVBInfo);
6599 } /* 301 */
6600 else { /* LVDS */
6601 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
6602 | XGI_SetCRT2ToLCDA))
6603 /* enable CRT2 */
6604 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
6606 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
6607 0x2E);
6608 if (!(tempah & 0x80))
6609 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
6611 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
6612 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
6613 } /* End of VB */
6616 static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
6617 struct xgi_hw_device_info *HwDeviceExtension,
6618 unsigned short ModeNo, unsigned short ModeIdIndex,
6619 struct vb_device_info *pVBInfo)
6621 unsigned short RefreshRateTableIndex, temp;
6623 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
6624 outb(pVBInfo->StandTable->MISC, pVBInfo->P3c2);
6625 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
6626 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
6627 XGI_SetGRCRegs(pVBInfo);
6628 XGI_ClearExt1Regs(pVBInfo);
6630 if (HwDeviceExtension->jChipType == XG27) {
6631 if (pVBInfo->IF_DEF_LVDS == 0)
6632 XGI_SetDefaultVCLK(pVBInfo);
6635 temp = ~ProgrammingCRT2;
6636 pVBInfo->SetFlag &= temp;
6637 pVBInfo->SelectCRT2Rate = 0;
6639 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6640 | VB_SIS302LV | VB_XGI301C)) {
6641 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
6642 | SetInSlaveMode)) {
6643 pVBInfo->SetFlag |= ProgrammingCRT2;
6647 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6648 ModeIdIndex, pVBInfo);
6649 if (RefreshRateTableIndex != 0xFFFF) {
6650 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
6651 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6652 pVBInfo, HwDeviceExtension);
6653 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
6654 RefreshRateTableIndex, pVBInfo);
6655 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6656 HwDeviceExtension, pVBInfo);
6657 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
6658 RefreshRateTableIndex, pVBInfo);
6661 if (HwDeviceExtension->jChipType >= XG21) {
6662 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
6663 if (temp & 0xA0) {
6665 if (HwDeviceExtension->jChipType == XG27)
6666 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
6667 RefreshRateTableIndex, pVBInfo);
6668 else
6669 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
6670 RefreshRateTableIndex, pVBInfo);
6672 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
6673 RefreshRateTableIndex);
6675 xgifb_set_lcd(HwDeviceExtension->jChipType,
6676 pVBInfo, RefreshRateTableIndex, ModeNo);
6678 if (pVBInfo->IF_DEF_LVDS == 1)
6679 xgifb_set_lvds(xgifb_info,
6680 HwDeviceExtension->jChipType,
6681 ModeNo, ModeIdIndex, pVBInfo);
6685 pVBInfo->SetFlag &= (~ProgrammingCRT2);
6686 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
6687 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
6688 RefreshRateTableIndex, pVBInfo);
6689 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
6692 unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
6693 struct xgi_hw_device_info *HwDeviceExtension,
6694 unsigned short ModeNo)
6696 unsigned short ModeIdIndex;
6697 struct vb_device_info VBINF;
6698 struct vb_device_info *pVBInfo = &VBINF;
6699 pVBInfo->BaseAddr = xgifb_info->vga_base;
6700 pVBInfo->IF_DEF_LVDS = 0;
6701 pVBInfo->IF_DEF_LCDA = 1;
6703 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
6704 pVBInfo->IF_DEF_YPbPr = 0;
6705 pVBInfo->IF_DEF_HiVision = 0;
6706 pVBInfo->IF_DEF_CRT2Monitor = 0;
6707 pVBInfo->VBType = 0; /*set VBType default 0*/
6708 } else {
6709 pVBInfo->IF_DEF_YPbPr = 1;
6710 pVBInfo->IF_DEF_HiVision = 1;
6711 pVBInfo->IF_DEF_CRT2Monitor = 1;
6714 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
6715 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
6716 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
6717 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
6718 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
6719 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
6720 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
6721 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
6722 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
6723 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
6724 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
6725 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
6726 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
6727 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
6728 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
6729 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
6730 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
6731 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
6733 /* for x86 Linux, XG21 LVDS */
6734 if (HwDeviceExtension->jChipType == XG21) {
6735 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
6736 pVBInfo->IF_DEF_LVDS = 1;
6738 if (HwDeviceExtension->jChipType == XG27) {
6739 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
6740 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
6741 pVBInfo->IF_DEF_LVDS = 1;
6745 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
6746 XGI_GetVBType(pVBInfo);
6748 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
6749 if (ModeNo & 0x80)
6750 ModeNo = ModeNo & 0x7F;
6751 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
6753 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
6754 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6756 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6758 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
6759 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6760 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6761 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
6762 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
6764 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
6765 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6766 ModeIdIndex, pVBInfo);
6768 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6769 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6770 HwDeviceExtension, pVBInfo);
6772 } else {
6773 if (!(pVBInfo->VBInfo & SwitchCRT2)) {
6774 XGI_SetCRT1Group(xgifb_info,
6775 HwDeviceExtension, ModeNo,
6776 ModeIdIndex, pVBInfo);
6777 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6778 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6779 HwDeviceExtension,
6780 pVBInfo);
6785 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
6786 switch (HwDeviceExtension->ujVBChipID) {
6787 case VB_CHIP_301:
6788 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6789 pVBInfo); /*add for CRT2 */
6790 break;
6792 case VB_CHIP_302:
6793 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6794 pVBInfo); /*add for CRT2 */
6795 break;
6797 default:
6798 break;
6802 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6803 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
6804 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
6805 } /* !XG20 */
6806 else {
6807 if (pVBInfo->IF_DEF_LVDS == 1)
6808 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
6809 ModeIdIndex,
6810 pVBInfo))
6811 return 0;
6813 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
6814 Ext_ModeFlag & ModeTypeMask;
6816 pVBInfo->SetFlag = 0;
6817 pVBInfo->VBInfo = DisableCRT2Display;
6819 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
6821 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6822 ModeIdIndex, pVBInfo);
6824 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
6827 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6829 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
6830 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
6833 return 1;