1 #include <linux/delay.h>
8 #include "vb_setmode.h"
10 #define IndexMask 0xff
11 #define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
13 static const unsigned short XGINew_VGA_DAC[] = {
14 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
15 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
16 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
17 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
18 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
19 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
20 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
21 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
22 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
23 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
25 void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
27 pVBInfo->MCLKData = XGI340New_MCLKData;
29 pVBInfo->LCDResInfo = 0;
30 pVBInfo->LCDTypeInfo = 0;
35 pVBInfo->SR18 = XGI340_SR18;
36 pVBInfo->CR40 = XGI340_cr41;
39 XGI_GetVBType(pVBInfo);
41 /* 310 customization related */
42 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
43 pVBInfo->LCDCapList = XGI_LCDDLCapList;
45 pVBInfo->LCDCapList = XGI_LCDCapList;
48 pVBInfo->XGINew_CR97 = 0x10;
50 if (ChipType == XG27) {
53 pVBInfo->MCLKData = XGI27New_MCLKData;
54 pVBInfo->CR40 = XGI27_cr41;
55 pVBInfo->XGINew_CR97 = 0xc1;
56 pVBInfo->SR18 = XG27_SR18;
59 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
60 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
61 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
62 pVBInfo->XGINew_CR97 = 0x80;
67 static void XGI_SetSeqRegs(struct vb_device_info *pVBInfo)
69 unsigned char SRdata, i;
71 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
73 for (i = 0; i < 4; i++) {
74 /* Get SR1,2,3,4 from file */
75 /* SR1 is with screen off 0x20 */
76 SRdata = XGI330_StandTable.SR[i];
77 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
81 static void XGI_SetCRTCRegs(struct vb_device_info *pVBInfo)
83 unsigned char CRTCdata;
86 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
88 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
90 for (i = 0; i <= 0x18; i++) {
91 /* Get CRTC from file */
92 CRTCdata = XGI330_StandTable.CRTC[i];
93 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
97 static void XGI_SetATTRegs(unsigned short ModeIdIndex,
98 struct vb_device_info *pVBInfo)
100 unsigned char ARdata;
101 unsigned short i, modeflag;
103 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
105 for (i = 0; i <= 0x13; i++) {
106 ARdata = XGI330_StandTable.ATTR[i];
108 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
109 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
111 } else if ((pVBInfo->VBInfo &
112 (SetCRT2ToTV | SetCRT2ToLCD)) &&
113 (pVBInfo->VBInfo & SetInSlaveMode)) {
118 inb(pVBInfo->P3da); /* reset 3da */
119 outb(i, pVBInfo->P3c0); /* set index */
120 outb(ARdata, pVBInfo->P3c0); /* set data */
123 inb(pVBInfo->P3da); /* reset 3da */
124 outb(0x14, pVBInfo->P3c0); /* set index */
125 outb(0x00, pVBInfo->P3c0); /* set data */
126 inb(pVBInfo->P3da); /* Enable Attribute */
127 outb(0x20, pVBInfo->P3c0);
130 static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
132 unsigned char GRdata;
135 for (i = 0; i <= 0x08; i++) {
136 /* Get GR from file */
137 GRdata = XGI330_StandTable.GRC[i];
138 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
141 if (pVBInfo->ModeType > ModeVGA) {
142 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
143 GRdata &= 0xBF; /* 256 color disable */
144 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
148 static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
152 for (i = 0x0A; i <= 0x0E; i++)
153 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
156 static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
159 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
160 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
161 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
163 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
164 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
165 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
167 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
171 static unsigned char XGI_AjustCRT2Rate(unsigned short ModeIdIndex,
172 unsigned short RefreshRateTableIndex, unsigned short *i,
173 struct vb_device_info *pVBInfo)
175 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
177 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
178 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
179 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
182 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
183 tempax |= SupportRAMDAC2;
185 if (pVBInfo->VBType & VB_XGI301C)
186 tempax |= SupportCRT2in301C;
190 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
191 tempax |= SupportLCD;
193 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
194 pVBInfo->LCDResInfo != Panel_1280x960 &&
195 (pVBInfo->LCDInfo & LCDNonExpanding) &&
200 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
201 tempax |= SupportHiVision;
202 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
204 (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
207 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
208 SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
209 SetCRT2ToHiVision)) {
212 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
213 VB_SIS302LV | VB_XGI301C))
214 tempax |= SupportTV1024;
216 if (!(pVBInfo->VBInfo & TVSetPAL) &&
217 (modeflag & NoSupportSimuTV) &&
218 (pVBInfo->VBInfo & SetInSlaveMode) &&
219 (!(pVBInfo->VBInfo & SetNotSimuMode)))
223 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
225 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
227 if (infoflag & tempax)
234 for ((*i) = 0;; (*i)++) {
235 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
237 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
242 if (infoflag & tempax)
248 static void XGI_SetSync(unsigned short RefreshRateTableIndex,
249 struct vb_device_info *pVBInfo)
251 unsigned short sync, temp;
254 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
258 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
261 static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
262 struct xgi_hw_device_info *HwDeviceExtension)
264 unsigned char data, data1, pushax;
268 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
270 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
272 data = pVBInfo->TimingH.data[0];
273 xgifb_reg_set(pVBInfo->P3d4, 0, data);
275 for (i = 0x01; i <= 0x04; i++) {
276 data = pVBInfo->TimingH.data[i];
277 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
280 for (i = 0x05; i <= 0x06; i++) {
281 data = pVBInfo->TimingH.data[i];
282 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
285 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
287 data = pVBInfo->TimingH.data[7];
290 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
292 if (HwDeviceExtension->jChipType >= XG20) {
293 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
295 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
296 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
302 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
304 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
309 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
310 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
316 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
320 static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
321 struct vb_device_info *pVBInfo)
326 for (i = 0x00; i <= 0x01; i++) {
327 data = pVBInfo->TimingV.data[i];
328 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
331 for (i = 0x02; i <= 0x03; i++) {
332 data = pVBInfo->TimingV.data[i];
333 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
336 for (i = 0x04; i <= 0x05; i++) {
337 data = pVBInfo->TimingV.data[i];
338 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
341 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
343 data = pVBInfo->TimingV.data[6];
346 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
348 data = pVBInfo->TimingV.data[6];
352 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
357 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
360 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
363 static void XGI_SetCRT1CRTC(unsigned short ModeIdIndex,
364 unsigned short RefreshRateTableIndex,
365 struct vb_device_info *pVBInfo,
366 struct xgi_hw_device_info *HwDeviceExtension)
368 unsigned char index, data;
372 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
373 index = index & IndexMask;
375 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
377 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
379 for (i = 0; i < 8; i++)
380 pVBInfo->TimingH.data[i]
381 = XGI_CRT1Table[index].CR[i];
383 for (i = 0; i < 7; i++)
384 pVBInfo->TimingV.data[i]
385 = XGI_CRT1Table[index].CR[i + 8];
387 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
389 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
391 if (pVBInfo->ModeType > 0x03)
392 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
395 /* --------------------------------------------------------------------- */
396 /* Function : XGI_SetXG21CRTC */
397 /* Input : Stand or enhance CRTC table */
398 /* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
399 /* Description : Set LCD timing */
400 /* --------------------------------------------------------------------- */
401 static void XGI_SetXG21CRTC(unsigned short RefreshRateTableIndex,
402 struct vb_device_info *pVBInfo)
404 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
405 unsigned short Temp1, Temp2, Temp3;
407 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
408 /* Tempax: CR4 HRS */
409 Tempax = XGI_CRT1Table[index].CR[3];
410 Tempcx = Tempax; /* Tempcx: HRS */
412 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
414 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
415 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
416 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
417 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
418 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
420 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
421 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
423 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
424 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
425 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
426 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
428 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
429 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
431 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
432 if (Tempax < Tempcx) /* HRE < HRS */
433 Temp2 |= 0x40; /* Temp2 + 0x40 */
436 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
437 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
438 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
439 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
440 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
441 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
442 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
445 Tempax = XGI_CRT1Table[index].CR[10];
446 Tempbx = Tempax; /* Tempbx: VRS */
447 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
448 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
450 Tempax = XGI_CRT1Table[index].CR[9];
451 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
452 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
453 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
454 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
455 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
457 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
458 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
459 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
461 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
462 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
464 Tempax = XGI_CRT1Table[index].CR[14];
465 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
467 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
468 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
470 /* Tempax: CR11 VRE */
471 Tempax = XGI_CRT1Table[index].CR[11];
472 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
474 Tempbx = XGI_CRT1Table[index].CR[14];
475 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
476 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
477 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
478 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
479 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
481 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
482 if (Tempax < Temp3) /* VRE < VRS */
483 Temp2 |= 0x20; /* VRE + 0x20 */
486 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
487 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
488 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
489 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
490 Tempbx = (unsigned char) Temp1;
491 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
493 /* SR3F D[7:2]->VRE D[1:0]->VRS */
494 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
497 static void XGI_SetXG27CRTC(unsigned short RefreshRateTableIndex,
498 struct vb_device_info *pVBInfo)
500 unsigned short index, Tempax, Tempbx, Tempcx;
502 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
503 /* Tempax: CR4 HRS */
504 Tempax = XGI_CRT1Table[index].CR[3];
505 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
507 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
510 Tempax = XGI_CRT1Table[index].CR[5];
511 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
512 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
514 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
515 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
516 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
518 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
519 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
520 Tempax <<= 3; /* Tempax[5]: HRE[5] */
521 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
523 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
524 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
526 /* Tempax: CR4 HRS */
527 Tempax = XGI_CRT1Table[index].CR[3];
528 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
529 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
530 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
532 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
533 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
534 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
535 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
536 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
537 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
538 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
541 Tempax = XGI_CRT1Table[index].CR[10];
542 /* SR34[7:0]->VRS[7:0] */
543 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
545 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
546 /* CR7[7][2] VRS[9][8] */
547 Tempax = XGI_CRT1Table[index].CR[9];
548 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
549 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
550 Tempax >>= 2; /* Tempax[0]: VRS[8] */
551 /* SR35[0]: VRS[8] */
552 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
553 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
554 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
556 Tempax = XGI_CRT1Table[index].CR[14];
557 Tempax &= 0x08; /* SR0A[3] VRS[10] */
558 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
560 /* Tempax: CR11 VRE */
561 Tempax = XGI_CRT1Table[index].CR[11];
562 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
564 Tempbx = XGI_CRT1Table[index].CR[14];
565 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
566 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
567 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
568 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
569 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
570 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
572 if (Tempbx <= Tempcx) /* VRE <= VRS */
573 Tempbx |= 0x20; /* VRE + 0x20 */
575 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
576 Tempax = (Tempbx << 2) & 0xFF;
577 /* SR3F[7:2]:VRE[5:0] */
578 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
579 Tempax = Tempcx >> 8;
580 /* SR35[2:0]:VRS[10:8] */
581 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
584 static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
588 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
589 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
590 temp = (temp & 3) << 6;
591 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
592 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
593 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
594 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
598 static void xgifb_set_lcd(int chip_id,
599 struct vb_device_info *pVBInfo,
600 unsigned short RefreshRateTableIndex)
604 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
605 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
606 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
607 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
609 if (chip_id == XG27) {
610 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
611 if ((temp & 0x03) == 0) { /* dual 12 */
612 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
613 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
617 if (chip_id == XG27) {
618 XGI_SetXG27FPBits(pVBInfo);
620 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
623 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
624 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
628 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
630 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
631 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
633 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
636 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
639 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
642 /* --------------------------------------------------------------------- */
643 /* Function : XGI_UpdateXG21CRTC */
645 /* Output : CRT1 CRTC */
646 /* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
647 /* --------------------------------------------------------------------- */
648 static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
649 struct vb_device_info *pVBInfo,
650 unsigned short RefreshRateTableIndex)
654 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
655 if (ModeNo == 0x2E &&
656 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
659 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
660 Ext_CRT1CRTC == RES640x480x72))
662 else if (ModeNo == 0x2F)
664 else if (ModeNo == 0x50)
666 else if (ModeNo == 0x59)
670 xgifb_reg_set(pVBInfo->P3d4, 0x02,
671 XGI_UpdateCRT1Table[index].CR02);
672 xgifb_reg_set(pVBInfo->P3d4, 0x03,
673 XGI_UpdateCRT1Table[index].CR03);
674 xgifb_reg_set(pVBInfo->P3d4, 0x15,
675 XGI_UpdateCRT1Table[index].CR15);
676 xgifb_reg_set(pVBInfo->P3d4, 0x16,
677 XGI_UpdateCRT1Table[index].CR16);
681 static void XGI_SetCRT1DE(unsigned short ModeIdIndex,
682 unsigned short RefreshRateTableIndex,
683 struct vb_device_info *pVBInfo)
685 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
689 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
691 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
692 tempax = XGI330_ModeResInfo[resindex].HTotal;
693 tempbx = XGI330_ModeResInfo[resindex].VTotal;
695 if (modeflag & HalfDCLK)
698 if (modeflag & HalfDCLK)
701 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
703 if (temp & InterlaceMode)
706 if (modeflag & DoubleScanMode)
715 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
716 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
718 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
719 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
720 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
721 (unsigned short) ((tempcx & 0x0ff00) >> 10));
722 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
732 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
733 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
739 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
740 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
743 static void XGI_SetCRT1Offset(unsigned short ModeNo,
744 unsigned short ModeIdIndex,
745 unsigned short RefreshRateTableIndex,
746 struct xgi_hw_device_info *HwDeviceExtension,
747 struct vb_device_info *pVBInfo)
749 unsigned short temp, ah, al, temp2, i, DisplayUnit;
752 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
754 temp = XGI330_ScreenOffset[temp];
756 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
757 temp2 &= InterlaceMode;
762 temp2 = pVBInfo->ModeType - ModeEGA;
787 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
788 temp = temp * temp2 + temp2 / 2;
797 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
800 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
802 temp = (unsigned char) temp2;
803 temp &= 0xFF; /* al */
804 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
807 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
808 temp2 &= InterlaceMode;
813 ah = (DisplayUnit & 0xff00) >> 8;
814 al = DisplayUnit & 0x00ff;
820 if (HwDeviceExtension->jChipType >= XG20)
821 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
824 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
827 static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeIdIndex,
828 unsigned short RefreshRateTableIndex,
829 struct vb_device_info *pVBInfo)
831 unsigned short VCLKIndex, modeflag;
834 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
836 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
837 if (pVBInfo->LCDResInfo != Panel_1024x768)
839 VCLKIndex = VCLK108_2_315 + 5;
841 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
842 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
843 if (pVBInfo->SetFlag & RPLLDIV2XO)
844 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
846 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
848 if (pVBInfo->SetFlag & TVSimuMode) {
849 if (modeflag & Charx8Dot)
850 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
852 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
856 if (pVBInfo->VBType & VB_SIS301LV) {
857 if (pVBInfo->SetFlag & RPLLDIV2XO)
858 VCLKIndex = YPbPr525iVCLK_2;
860 VCLKIndex = YPbPr525iVCLK;
862 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
863 if (pVBInfo->SetFlag & RPLLDIV2XO)
864 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
866 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
867 } else { /* for CRT2 */
869 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
870 VCLKIndex &= IndexMask;
876 static void XGI_SetCRT1VCLK(unsigned short ModeIdIndex,
877 struct xgi_hw_device_info *HwDeviceExtension,
878 unsigned short RefreshRateTableIndex,
879 struct vb_device_info *pVBInfo)
881 unsigned char index, data;
882 unsigned short vclkindex;
884 if ((pVBInfo->IF_DEF_LVDS == 0) &&
885 (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
886 VB_SIS302LV | VB_XGI301C)) &&
887 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
888 vclkindex = XGI_GetVCLK2Ptr(ModeIdIndex, RefreshRateTableIndex,
890 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
891 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
892 data = XGI_VBVCLKData[vclkindex].Part4_A;
893 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
894 data = XGI_VBVCLKData[vclkindex].Part4_B;
895 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
896 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
898 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
899 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
900 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
901 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
902 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
903 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
906 if (HwDeviceExtension->jChipType >= XG20) {
907 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
909 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
910 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
911 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
918 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
923 static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
927 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
928 temp = (temp & 1) << 6;
929 /* SR06[6] 18bit Dither */
930 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
931 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
932 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
936 static void XGI_SetCRT1FIFO(struct xgi_hw_device_info *HwDeviceExtension,
937 struct vb_device_info *pVBInfo)
941 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
943 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* disable auto-threshold */
945 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
946 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
948 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
949 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
951 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
953 if (HwDeviceExtension->jChipType == XG21)
954 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
957 static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
958 unsigned short RefreshRateTableIndex,
959 struct vb_device_info *pVBInfo)
961 unsigned short data, data2 = 0;
966 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
968 VCLK = XGI_VCLKData[index].CLOCK;
970 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
973 data |= 0x0c; /* VCLK > 200 */
975 if (HwDeviceExtension->jChipType >= XG20)
976 data &= ~0x04; /* 2 pixel mode */
978 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
980 if (HwDeviceExtension->jChipType < XG20) {
981 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
985 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
990 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
991 if (HwDeviceExtension->jChipType >= XG27)
992 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
996 static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
997 unsigned short ModeIdIndex,
998 unsigned short RefreshRateTableIndex,
999 struct vb_device_info *pVBInfo)
1001 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1004 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1005 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1007 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
1008 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
1013 data3 = pVBInfo->ModeType - ModeVGA;
1016 data &= InterlaceMode;
1021 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
1022 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
1023 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
1026 if (infoflag & InterlaceMode) {
1029 else if (xres == 1280)
1033 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1034 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
1036 if (modeflag & HalfDCLK)
1037 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
1041 if (modeflag & LineCompareOff)
1044 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
1048 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
1050 XGI_SetVCLKState(HwDeviceExtension, RefreshRateTableIndex, pVBInfo);
1052 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1054 if (HwDeviceExtension->jChipType == XG27) {
1059 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1060 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
1061 } else if (HwDeviceExtension->jChipType >= XG20) {
1066 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1067 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
1073 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1078 static void XGI_WriteDAC(unsigned short dl,
1082 struct vb_device_info *pVBInfo)
1084 unsigned short bh, bl;
1096 outb((unsigned short) dh, pVBInfo->P3c9);
1097 outb((unsigned short) bh, pVBInfo->P3c9);
1098 outb((unsigned short) bl, pVBInfo->P3c9);
1101 static void XGI_LoadDAC(struct vb_device_info *pVBInfo)
1103 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1104 const unsigned short *table = XGINew_VGA_DAC;
1106 outb(0xFF, pVBInfo->P3c6);
1107 outb(0x00, pVBInfo->P3c8);
1109 for (i = 0; i < 16; i++) {
1112 for (k = 0; k < 3; k++) {
1121 outb(data2, pVBInfo->P3c9);
1126 for (i = 16; i < 32; i++) {
1129 for (k = 0; k < 3; k++)
1130 outb(data, pVBInfo->P3c9);
1135 for (m = 0; m < 9; m++) {
1140 for (n = 0; n < 3; n++) {
1141 for (o = 0; o < 5; o++) {
1146 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1151 for (o = 0; o < 3; o++) {
1156 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1166 static void XGI_GetLVDSResInfo(unsigned short ModeIdIndex,
1167 struct vb_device_info *pVBInfo)
1169 unsigned short resindex, xres, yres, modeflag;
1171 /* si+Ext_ResInfo */
1172 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
1174 /* si+Ext_ResInfo */
1175 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
1177 xres = XGI330_ModeResInfo[resindex].HTotal;
1178 yres = XGI330_ModeResInfo[resindex].VTotal;
1180 if (modeflag & HalfDCLK)
1183 if (modeflag & DoubleScanMode)
1189 pVBInfo->VGAHDE = xres;
1190 pVBInfo->HDE = xres;
1191 pVBInfo->VGAVDE = yres;
1192 pVBInfo->VDE = yres;
1195 static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
1196 unsigned short ModeIdIndex,
1197 struct vb_device_info *pVBInfo)
1199 unsigned short i, tempdx, tempbx, modeflag;
1203 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1207 while (table[i].PANELID != 0xff) {
1208 tempdx = pVBInfo->LCDResInfo;
1209 if (tempbx & 0x0080) { /* OEMUtil */
1210 tempbx &= (~0x0080);
1211 tempdx = pVBInfo->LCDTypeInfo;
1214 if (pVBInfo->LCDInfo & EnableScalingLCD)
1215 tempdx &= (~PanelResInfo);
1217 if (table[i].PANELID == tempdx) {
1218 tempbx = table[i].MASK;
1219 tempdx = pVBInfo->LCDInfo;
1221 if (modeflag & HalfDCLK)
1222 tempdx |= SetLCDLowResolution;
1225 if (tempbx == table[i].CAP)
1231 return table[i].DATAPTR;
1234 static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex,
1235 unsigned short RefreshRateTableIndex,
1236 struct vb_device_info *pVBInfo)
1238 unsigned short i, tempdx, tempal, modeflag;
1240 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1241 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1242 tempal = tempal & 0x3f;
1243 tempdx = pVBInfo->TVInfo;
1245 if (pVBInfo->VBInfo & SetInSlaveMode)
1246 tempdx = tempdx | SetTVLockMode;
1248 if (modeflag & HalfDCLK)
1249 tempdx = tempdx | SetTVLowResolution;
1253 while (XGI_TVDataTable[i].MASK != 0xffff) {
1254 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1255 XGI_TVDataTable[i].CAP)
1260 return &XGI_TVDataTable[i].DATAPTR[tempal];
1263 static void XGI_GetLVDSData(unsigned short ModeIdIndex,
1264 struct vb_device_info *pVBInfo)
1266 struct SiS_LVDSData const *LCDPtr;
1268 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1271 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeIdIndex, pVBInfo);
1272 pVBInfo->VGAHT = LCDPtr->VGAHT;
1273 pVBInfo->VGAVT = LCDPtr->VGAVT;
1274 pVBInfo->HT = LCDPtr->LCDHT;
1275 pVBInfo->VT = LCDPtr->LCDVT;
1277 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1280 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1281 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1282 pVBInfo->HDE = 1024;
1284 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1285 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1286 pVBInfo->HDE = 1280;
1287 pVBInfo->VDE = 1024;
1288 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1289 pVBInfo->HDE = 1400;
1290 pVBInfo->VDE = 1050;
1292 pVBInfo->HDE = 1600;
1293 pVBInfo->VDE = 1200;
1297 static void XGI_ModCRT1Regs(unsigned short ModeIdIndex,
1298 struct xgi_hw_device_info *HwDeviceExtension,
1299 struct vb_device_info *pVBInfo)
1302 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1303 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
1305 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
1306 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeIdIndex,
1309 for (i = 0; i < 8; i++)
1310 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
1313 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1315 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
1316 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeIdIndex,
1318 for (i = 0; i < 7; i++)
1319 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
1322 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
1325 static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1327 unsigned char tempal, tempah, tempbl, i;
1329 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
1330 tempal = tempah & 0x0F;
1331 tempah = tempah & 0xF0;
1333 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1335 while (tempbl != 0xFF) {
1336 if (tempbl & 0x80) { /* OEMUtil */
1338 tempbl = tempbl & ~(0x80);
1341 if (tempal == tempbl)
1346 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1352 static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1354 unsigned short tempah, tempal, tempbl, i;
1356 tempal = pVBInfo->LCDResInfo;
1357 tempah = pVBInfo->LCDTypeInfo;
1360 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1362 while (tempbl != 0xFF) {
1363 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1368 if (tempal == tempbl)
1372 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1375 if (tempbl == 0xFF) {
1376 pVBInfo->LCDResInfo = Panel_1024x768;
1377 pVBInfo->LCDTypeInfo = 0;
1384 static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1385 unsigned short *VSyncWidth,
1386 struct vb_device_info *pVBInfo)
1388 unsigned short Index;
1390 Index = XGI_GetLCDCapPtr(pVBInfo);
1391 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1392 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1395 static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
1396 struct vb_device_info *pVBInfo)
1398 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1399 unsigned long temp, temp1, temp2, temp3, push3;
1400 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
1402 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1403 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeIdIndex, pVBInfo);
1405 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1410 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1411 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1414 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1415 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1418 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1426 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1427 pVBInfo->HDE = tempax;
1428 pVBInfo->VDE = tempbx;
1429 pVBInfo->VGAHDE = tempax;
1430 pVBInfo->VGAVDE = tempbx;
1433 tempax = pVBInfo->HT;
1435 tempbx = LCDPtr1->LCDHDES;
1437 tempcx = pVBInfo->HDE;
1438 tempbx = tempbx & 0x0fff;
1441 if (tempcx >= tempax)
1444 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
1449 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1450 (unsigned short) (tempbx & 0xff));
1451 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1452 (unsigned short) (tempcx & 0xff));
1454 tempax = pVBInfo->HT;
1456 tempbx = LCDPtr1->LCDHRS;
1460 if (pVBInfo->LCDInfo & EnableScalingLCD)
1461 tempcx = LCDPtr1->LCDHSync;
1465 if (tempcx >= tempax)
1468 tempax = tempbx & 0x07;
1476 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1477 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1478 (unsigned short) (tempbx & 0xff));
1480 tempax = pVBInfo->VT;
1481 tempbx = LCDPtr1->LCDVDES;
1482 tempcx = pVBInfo->VDE;
1484 tempbx = tempbx & 0x0fff;
1486 if (tempcx >= tempax)
1489 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1490 (unsigned short) (tempbx & 0xff));
1491 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1492 (unsigned short) (tempcx & 0xff));
1494 tempbx = (tempbx >> 8) & 0x07;
1495 tempcx = (tempcx >> 8) & 0x07;
1497 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1498 (unsigned short) ((tempcx << 3)
1501 tempax = pVBInfo->VT;
1502 tempbx = LCDPtr1->LCDVRS;
1506 if (pVBInfo->LCDInfo & EnableScalingLCD)
1507 tempcx = LCDPtr1->LCDVSync;
1510 if (tempcx >= tempax)
1513 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1514 (unsigned short) (tempbx & 0xff));
1515 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1516 (unsigned short) (tempcx & 0x0f));
1518 tempax = ((tempbx >> 8) & 0x07) << 3;
1520 tempbx = pVBInfo->VGAVDE;
1521 if (tempbx != pVBInfo->VDE)
1524 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
1527 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1530 tempbx = pVBInfo->VDE;
1531 tempax = pVBInfo->VGAVDE;
1533 temp = tempax; /* 0430 ylshieh */
1534 temp1 = (temp << 18) / tempbx;
1536 tempdx = (unsigned short) ((temp << 18) % tempbx);
1544 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1545 (unsigned short) (temp2 & 0xff));
1546 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1547 (unsigned short) ((temp2 >> 8) & 0xff));
1549 tempbx = (unsigned short) (temp2 >> 16);
1550 tempax = tempbx & 0x03;
1552 tempbx = pVBInfo->VGAVDE;
1553 if (tempbx == pVBInfo->VDE)
1556 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1558 if (pVBInfo->VBType & VB_XGI301C) {
1560 xgifb_reg_set(pVBInfo->Part4Port,
1562 (unsigned short) (temp2 & 0xff));
1563 xgifb_reg_set(pVBInfo->Part4Port,
1565 (unsigned short) ((temp2 >> 8) &
1567 tempbx = (unsigned short) (temp2 >> 16);
1568 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1570 (unsigned short) ((tempbx &
1573 tempcx = pVBInfo->VGAVDE;
1574 if (tempcx == pVBInfo->VDE)
1575 xgifb_reg_and_or(pVBInfo->Part4Port,
1578 xgifb_reg_and_or(pVBInfo->Part4Port,
1582 tempcx = pVBInfo->VGAHDE;
1583 tempbx = pVBInfo->HDE;
1585 temp1 = tempcx << 16;
1587 tempax = (unsigned short) (temp1 / tempbx);
1589 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1593 temp1 = pVBInfo->VGAHDE << 16;
1599 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1601 tempax = (unsigned short) (temp3 & 0xff);
1602 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1604 temp1 = pVBInfo->VGAVDE << 18;
1605 temp1 = temp1 / push3;
1606 tempbx = (unsigned short) (temp1 & 0xffff);
1608 if (pVBInfo->LCDResInfo == Panel_1024x768)
1611 tempax = ((tempbx >> 8) & 0xff) << 3;
1612 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1613 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1614 (unsigned short) (tempax & 0xff));
1615 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1616 (unsigned short) (tempbx & 0xff));
1620 if (modeflag & HalfDCLK)
1623 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1624 (unsigned short) ((temp3 >> 8) & 0xff));
1625 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1626 (unsigned short) (temp3 & 0xff));
1629 /* --------------------------------------------------------------------- */
1630 /* Function : XGI_GETLCDVCLKPtr */
1632 /* Output : al -> VCLK Index */
1634 /* --------------------------------------------------------------------- */
1635 static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1636 struct vb_device_info *pVBInfo)
1638 unsigned short index;
1640 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
1641 index = XGI_GetLCDCapPtr1(pVBInfo);
1643 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1644 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1645 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1647 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1648 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1653 static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1654 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
1657 unsigned short index, modeflag;
1658 unsigned char tempal;
1660 /* si+Ext_ResInfo */
1661 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1663 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1664 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
1665 index = XGI_GetLCDCapPtr(pVBInfo);
1666 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1668 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
1672 if (pVBInfo->VBType &
1678 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
1679 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
1680 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
1681 tempal = TVCLKBASE_315 + HiTVVCLK;
1682 if (pVBInfo->TVInfo & TVSimuMode) {
1683 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
1684 if (!(modeflag & Charx8Dot))
1685 tempal = TVCLKBASE_315 +
1692 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
1693 tempal = XGI_YPbPr750pVCLK;
1697 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
1698 tempal = YPbPr525pVCLK;
1702 tempal = NTSC1024VCLK;
1704 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
1705 tempal = TVCLKBASE_315 + TVVCLKDIV2;
1706 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
1707 tempal = TVCLKBASE_315 + TVVCLK;
1710 if (pVBInfo->VBInfo & SetCRT2ToTV)
1715 inb((pVBInfo->P3ca + 0x02));
1716 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1720 static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1721 unsigned char *di_1, struct vb_device_info *pVBInfo)
1723 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1724 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
1725 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1726 (pVBInfo->SetFlag & ProgrammingCRT2)) {
1727 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
1728 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
1731 *di_0 = XGI_VCLKData[tempal].SR2B;
1732 *di_1 = XGI_VCLKData[tempal].SR2C;
1736 static void XGI_SetCRT2ECLK(unsigned short ModeIdIndex,
1737 unsigned short RefreshRateTableIndex,
1738 struct vb_device_info *pVBInfo)
1740 unsigned char di_0, di_1, tempal;
1743 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
1744 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1745 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
1747 for (i = 0; i < 4; i++) {
1748 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
1749 (unsigned short) (0x10 * i));
1750 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
1751 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
1752 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1753 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
1755 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1756 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
1761 static void XGI_UpdateModeInfo(struct vb_device_info *pVBInfo)
1763 unsigned short tempcl, tempch, temp, tempbl, tempax;
1765 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1766 | VB_SIS302LV | VB_XGI301C)) {
1769 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
1771 if (!(temp & 0x20)) {
1772 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
1774 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
1776 tempcl |= ActiveCRT1;
1780 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
1783 if (!(temp == 0x08)) {
1784 /* Check ChannelA */
1785 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
1787 tempcl = tempcl | ActiveLCD;
1791 if (!(tempcl & ActiveLCD))
1793 tempcl |= ActiveCRT2;
1796 tempcl |= ActiveLCD;
1799 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
1802 tempch |= ActiveAVideo;
1805 tempch |= ActiveSVideo;
1808 tempch |= ActiveSCART;
1810 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
1812 tempch |= ActiveHiTV;
1815 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
1816 temp = xgifb_reg_get(
1821 tempch |= ActiveYPbPr;
1829 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
1830 if (tempcl & ActiveLCD) {
1831 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1832 if (temp & ActiveTV)
1837 tempbl = ~XGI_ModeSwitchStatus;
1838 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
1840 if (!(pVBInfo->SetFlag & ReserveTVOption))
1841 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
1845 void XGI_GetVBType(struct vb_device_info *pVBInfo)
1847 unsigned short flag, tempbx, tempah;
1849 tempbx = VB_SIS302B;
1850 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1855 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1859 tempbx = VB_SIS301B;
1861 goto bigger_than_0xB0;
1863 tempbx = VB_XGI301C;
1865 goto bigger_than_0xB0;
1867 tempbx = VB_SIS301LV;
1869 goto bigger_than_0xB0;
1871 tempbx = VB_SIS302LV;
1872 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1874 tempbx = VB_XGI301C;
1877 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1878 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1880 tempbx = tempbx | VB_NoLCD;
1884 pVBInfo->VBType = tempbx;
1887 static void XGI_GetVBInfo(unsigned short ModeIdIndex,
1888 struct vb_device_info *pVBInfo)
1890 unsigned short tempax, push, tempbx, temp, modeflag;
1892 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1893 pVBInfo->SetFlag = 0;
1894 pVBInfo->ModeType = modeflag & ModeTypeMask;
1897 if (!(pVBInfo->VBType & 0xFFFF))
1900 /* Check Display Device */
1901 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1902 tempbx = tempbx | temp;
1903 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1907 tempbx = tempbx | tempax;
1908 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1909 | SetInSlaveMode | DisableCRT2Display);
1910 temp = 0xFFFF ^ temp;
1913 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
1915 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1917 if (temp & EnableDualEdge) {
1918 tempbx |= SetCRT2ToDualEdge;
1919 if (temp & SetToLCDA)
1920 tempbx |= XGI_SetCRT2ToLCDA;
1924 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
1925 if (temp & SetYPbPr) {
1926 /* shampoo add for new scratch */
1927 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
1929 tempbx |= SetCRT2ToHiVision;
1931 if (temp != YPbPrMode1080i) {
1932 tempbx &= (~SetCRT2ToHiVision);
1933 tempbx |= SetCRT2ToYPbPr525750;
1938 tempax = push; /* restore CR31 */
1942 if (!(tempbx & temp)) {
1943 tempax |= DisableCRT2Display;
1947 if (!(pVBInfo->VBType & VB_NoLCD)) {
1948 if (tempbx & XGI_SetCRT2ToLCDA) {
1949 if (tempbx & SetSimuScanMode)
1950 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1953 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1954 SetCRT2ToTV | SwitchCRT2));
1959 /* for driver abnormal */
1960 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
1961 if (tempbx & SetCRT2ToRAMDAC) {
1962 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
1963 SwitchCRT2 | SetSimuScanMode);
1964 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1968 if (!(pVBInfo->VBType & VB_NoLCD)) {
1969 if (tempbx & SetCRT2ToLCD) {
1970 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
1972 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1976 if (tempbx & SetCRT2ToSCART) {
1977 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
1979 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1982 if (tempbx & SetCRT2ToYPbPr525750)
1983 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
1985 if (tempbx & SetCRT2ToHiVision)
1986 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
1989 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
1990 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
1991 tempbx = DisableCRT2Display;
1994 if (!(tempbx & DisableCRT2Display)) {
1995 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
1996 if (!(tempbx & XGI_SetCRT2ToLCDA))
1997 tempbx |= (SetInSlaveMode | SetSimuScanMode);
2000 /* LCD+TV can't support in slave mode
2001 * (Force LCDA+TV->LCDB) */
2002 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2003 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
2005 pVBInfo->SetFlag |= ReserveTVOption;
2009 pVBInfo->VBInfo = tempbx;
2012 static void XGI_GetTVInfo(unsigned short ModeIdIndex,
2013 struct vb_device_info *pVBInfo)
2015 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
2017 if (pVBInfo->VBInfo & SetCRT2ToTV) {
2018 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2019 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2021 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2022 if (tempbx & TVSetPAL) {
2023 tempbx &= (SetCHTVOverScan |
2027 if (tempbx & TVSetPALM)
2028 /* set to NTSC if PAL-M */
2029 tempbx &= ~TVSetPAL;
2031 tempbx &= (SetCHTVOverScan |
2035 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2038 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2039 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2040 index1 &= YPbPrMode;
2042 if (index1 == YPbPrMode525i)
2043 tempbx |= TVSetYPbPr525i;
2045 if (index1 == YPbPrMode525p)
2046 tempbx = tempbx | TVSetYPbPr525p;
2047 if (index1 == YPbPrMode750p)
2048 tempbx = tempbx | TVSetYPbPr750p;
2051 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2052 tempbx = tempbx | TVSetHiVision | TVSetPAL;
2054 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2055 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2056 tempbx |= TVSimuMode;
2058 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2059 /* NTSC 1024x768, */
2060 tempbx |= NTSC1024x768;
2062 tempbx |= RPLLDIV2XO;
2064 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2065 if (pVBInfo->VBInfo & SetInSlaveMode)
2066 tempbx &= (~RPLLDIV2XO);
2067 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2068 tempbx &= (~RPLLDIV2XO);
2069 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2070 VB_SIS301LV | VB_SIS302LV |
2072 if (tempbx & TVSimuMode)
2073 tempbx &= (~RPLLDIV2XO);
2076 pVBInfo->TVInfo = tempbx;
2079 static unsigned char XGI_GetLCDInfo(unsigned short ModeIdIndex,
2080 struct vb_device_info *pVBInfo)
2082 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
2084 pVBInfo->LCDResInfo = 0;
2085 pVBInfo->LCDTypeInfo = 0;
2086 pVBInfo->LCDInfo = 0;
2088 /* si+Ext_ResInfo // */
2089 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2090 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
2091 tempbx = temp & 0x0F;
2094 tempbx = Panel_1024x768; /* default */
2097 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
2098 if (pVBInfo->VBInfo & DriverMode) {
2099 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
2100 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
2105 if ((resinfo == 6) || (resinfo == 9)) {
2107 tempbx |= PanelRef75Hz;
2108 } else if ((resinfo == 7) || (resinfo == 8)) {
2110 tempbx |= PanelRef75Hz;
2115 pVBInfo->LCDResInfo = tempbx;
2119 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
2124 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
2126 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
2130 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
2132 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
2134 if (((pVBInfo->VBType & VB_SIS302LV) ||
2135 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2136 tempbx |= SetLCDDualLink;
2138 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2139 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2140 (!(tempbx & EnableScalingLCD)))
2142 * set to center in 1280x1024 LCDB
2143 * for Panel_1400x1050
2145 tempbx |= SetLCDtoNonExpanding;
2147 if (pVBInfo->VBInfo & SetInSlaveMode) {
2148 if (pVBInfo->VBInfo & SetNotSimuMode)
2149 tempbx |= XGI_LCDVESATiming;
2151 tempbx |= XGI_LCDVESATiming;
2154 pVBInfo->LCDInfo = tempbx;
2159 unsigned char XGI_SearchModeID(unsigned short ModeNo,
2160 unsigned short *ModeIdIndex)
2162 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
2163 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
2165 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
2172 static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2174 unsigned char ujRet = 0;
2175 unsigned char i = 0;
2177 for (i = 0; i < 8; i++) {
2179 ujRet |= (ujDate >> i) & 1;
2185 /*----------------------------------------------------------------------------*/
2187 /* bl[5] : LVDS signal */
2188 /* bl[1] : LVDS backlight */
2189 /* bl[0] : LVDS VDD */
2190 /*----------------------------------------------------------------------------*/
2191 static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2193 unsigned char CR4A, temp;
2195 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2196 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
2198 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2200 temp = XG21GPIODataTransfer(temp);
2202 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
2206 /*----------------------------------------------------------------------------*/
2208 /* bl[5] : LVDS signal */
2209 /* bl[1] : LVDS backlight */
2210 /* bl[0] : LVDS VDD */
2211 /*----------------------------------------------------------------------------*/
2212 static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2214 unsigned char CR4A, CRB4, temp;
2216 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2217 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
2219 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2223 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
2224 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
2225 temp |= ((CRB4 & 0x04) << 3);
2229 /*----------------------------------------------------------------------------*/
2231 /* bl[5] : 1;LVDS signal on */
2232 /* bl[1] : 1;LVDS backlight on */
2233 /* bl[0] : 1:LVDS VDD on */
2234 /* bh: 100000b : clear bit 5, to set bit5 */
2235 /* 000010b : clear bit 1, to set bit1 */
2236 /* 000001b : clear bit 0, to set bit0 */
2237 /*----------------------------------------------------------------------------*/
2238 static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2239 struct vb_device_info *pVBInfo)
2241 unsigned char CR4A, temp;
2243 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2246 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2248 if (tempbh & 0x20) {
2249 temp = (tempbl >> 4) & 0x02;
2252 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2256 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2258 temp = XG21GPIODataTransfer(temp);
2261 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2264 static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2265 struct vb_device_info *pVBInfo)
2267 unsigned char CR4A, temp;
2268 unsigned short tempbh0, tempbl0;
2277 if (tempbh & 0x20) {
2278 temp = (tempbl >> 4) & 0x02;
2281 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2284 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2286 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2290 tempbl <<= 2; /* GPIOC,GPIOD */
2291 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2292 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2295 static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2296 struct xgi_hw_device_info *pXGIHWDE,
2297 struct vb_device_info *pVBInfo)
2300 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
2301 if (pXGIHWDE->jChipType == XG21) {
2302 if (pVBInfo->IF_DEF_LVDS == 1) {
2303 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
2305 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
2306 mdelay(xgifb_info->lvds_data.PSC_S2);
2308 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
2309 /* LVDS signal on */
2310 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
2311 mdelay(xgifb_info->lvds_data.PSC_S3);
2312 /* LVDS backlight on */
2313 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
2315 /* DVO/DVI signal on */
2316 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
2321 if (pXGIHWDE->jChipType == XG27) {
2322 if (pVBInfo->IF_DEF_LVDS == 1) {
2323 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
2325 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
2326 mdelay(xgifb_info->lvds_data.PSC_S2);
2328 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
2329 /* LVDS signal on */
2330 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
2331 mdelay(xgifb_info->lvds_data.PSC_S3);
2332 /* LVDS backlight on */
2333 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
2335 /* DVO/DVI signal on */
2336 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
2342 void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2343 struct xgi_hw_device_info *pXGIHWDE,
2344 struct vb_device_info *pVBInfo)
2347 if (pXGIHWDE->jChipType == XG21) {
2348 if (pVBInfo->IF_DEF_LVDS == 1) {
2349 /* LVDS backlight off */
2350 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
2351 mdelay(xgifb_info->lvds_data.PSC_S3);
2353 /* DVO/DVI signal off */
2354 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
2358 if (pXGIHWDE->jChipType == XG27) {
2359 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
2360 /* LVDS backlight off */
2361 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
2362 mdelay(xgifb_info->lvds_data.PSC_S3);
2365 if (pVBInfo->IF_DEF_LVDS == 0)
2366 /* DVO/DVI signal off */
2367 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
2370 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
2373 static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
2375 while ((inb(pVBInfo->P3da) & 0x01))
2378 while (!(inb(pVBInfo->P3da) & 0x01))
2382 static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
2384 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
2387 static void XGI_SaveCRT2Info(unsigned short ModeNo,
2388 struct vb_device_info *pVBInfo)
2390 unsigned short temp1, temp2;
2392 /* reserve CR34 for CRT1 Mode No */
2393 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
2394 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2395 temp2 = ~(SetInSlaveMode >> 8);
2396 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
2399 static void XGI_GetCRT2ResInfo(unsigned short ModeIdIndex,
2400 struct vb_device_info *pVBInfo)
2402 unsigned short xres, yres, modeflag, resindex;
2404 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2405 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2406 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
2407 /* si+St_ModeFlag */
2408 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2410 if (modeflag & HalfDCLK)
2413 if (modeflag & DoubleScanMode)
2416 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2419 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2420 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2426 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2429 else if (yres == 350)
2432 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2438 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2439 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2440 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2443 else if (yres == 400)
2445 else if (yres == 480)
2455 pVBInfo->VGAHDE = xres;
2456 pVBInfo->HDE = xres;
2457 pVBInfo->VGAVDE = yres;
2458 pVBInfo->VDE = yres;
2461 static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
2464 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
2465 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
2471 static void XGI_GetRAMDAC2DATA(unsigned short ModeIdIndex,
2472 unsigned short RefreshRateTableIndex,
2473 struct vb_device_info *pVBInfo)
2475 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
2478 pVBInfo->RVBHCMAX = 1;
2479 pVBInfo->RVBHCFACT = 1;
2480 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2481 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
2482 CRT1Index &= IndexMask;
2483 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2484 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
2485 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
2486 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
2487 tempcx = (unsigned short)
2488 XGI_CRT1Table[CRT1Index].CR[14] << 8;
2492 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
2501 if (modeflag & Charx8Dot)
2506 pVBInfo->VGAHT = tempax;
2507 pVBInfo->HT = tempax;
2509 pVBInfo->VGAVT = tempbx;
2510 pVBInfo->VT = tempbx;
2513 static void XGI_GetCRT2Data(unsigned short ModeIdIndex,
2514 unsigned short RefreshRateTableIndex,
2515 struct vb_device_info *pVBInfo)
2517 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
2519 struct SiS_LCDData const *LCDPtr = NULL;
2521 /* si+Ext_ResInfo */
2522 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2523 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2524 pVBInfo->NewFlickerMode = 0;
2525 pVBInfo->RVBHRS = 50;
2527 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2528 XGI_GetRAMDAC2DATA(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
2532 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
2533 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeIdIndex,
2536 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2537 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2538 pVBInfo->VGAHT = LCDPtr->VGAHT;
2539 pVBInfo->VGAVT = LCDPtr->VGAVT;
2540 pVBInfo->HT = LCDPtr->LCDHT;
2541 pVBInfo->VT = LCDPtr->LCDVT;
2543 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2547 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2548 if (pVBInfo->VGAVDE == 357)
2550 else if (pVBInfo->VGAVDE == 420)
2552 else if (pVBInfo->VGAVDE == 525)
2554 else if (pVBInfo->VGAVDE == 600)
2557 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
2560 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2562 if (pVBInfo->VGAVDE == 360)
2564 else if (pVBInfo->VGAVDE == 375)
2566 else if (pVBInfo->VGAVDE == 405)
2570 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
2573 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
2575 if (pVBInfo->VGAVDE == 350)
2577 else if (pVBInfo->VGAVDE == 400)
2579 else if (pVBInfo->VGAVDE == 1024)
2583 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
2587 if (pVBInfo->VGAVDE == 1024) {
2591 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2593 tempbx = 1200; /* alan 10/14/2003 */
2594 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2595 if (pVBInfo->VGAVDE == 350)
2597 else if (pVBInfo->VGAVDE == 400)
2602 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2603 tempax = pVBInfo->VGAHDE;
2604 tempbx = pVBInfo->VGAVDE;
2607 pVBInfo->HDE = tempax;
2608 pVBInfo->VDE = tempbx;
2612 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
2613 struct SiS_TVData const *TVPtr;
2615 TVPtr = XGI_GetTVPtr(ModeIdIndex, RefreshRateTableIndex,
2618 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2619 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2620 pVBInfo->VGAHT = TVPtr->VGAHT;
2621 pVBInfo->VGAVT = TVPtr->VGAVT;
2622 pVBInfo->HDE = TVPtr->TVHDE;
2623 pVBInfo->VDE = TVPtr->TVVDE;
2624 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2625 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
2627 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2628 if (resinfo == 0x08)
2629 pVBInfo->NewFlickerMode = 0x40;
2630 else if (resinfo == 0x09)
2631 pVBInfo->NewFlickerMode = 0x40;
2632 else if (resinfo == 0x12)
2633 pVBInfo->NewFlickerMode = 0x40;
2635 if (pVBInfo->VGAVDE == 350)
2636 pVBInfo->TVInfo |= TVSimuMode;
2641 if (pVBInfo->VBInfo & SetInSlaveMode) {
2642 if (pVBInfo->TVInfo & TVSimuMode) {
2646 if (!(modeflag & Charx8Dot)) {
2647 tempax = StHiTextTVHT;
2648 tempbx = StHiTextTVVT;
2652 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2653 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
2654 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2655 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2658 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
2659 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2660 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
2661 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
2662 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2663 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2664 if (pVBInfo->TVInfo & NTSC1024x768)
2665 tempax = NTSC1024x768HT;
2670 if (!(pVBInfo->TVInfo & TVSetPAL)) {
2673 if (pVBInfo->TVInfo & NTSC1024x768)
2674 tempax = NTSC1024x768HT;
2678 pVBInfo->HT = tempax;
2679 pVBInfo->VT = tempbx;
2683 static void XGI_SetCRT2VCLK(unsigned short ModeIdIndex,
2684 unsigned short RefreshRateTableIndex,
2685 struct vb_device_info *pVBInfo)
2687 unsigned char di_0, di_1, tempal;
2689 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
2690 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2691 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
2693 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
2695 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2696 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2697 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2698 } else { /* 301b/302b/301lv/302lv */
2699 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2700 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2703 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
2705 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
2706 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
2708 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
2711 static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex)
2713 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2715 unsigned short modeflag;
2717 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2718 index = (modeflag & ModeTypeMask) - ModeEGA;
2723 return ColorDepth[index];
2726 static unsigned short XGI_GetOffset(unsigned short ModeNo,
2727 unsigned short ModeIdIndex,
2728 unsigned short RefreshRateTableIndex)
2730 unsigned short temp, colordepth, modeinfo, index, infoflag,
2731 ColorDepth[] = { 0x01, 0x02, 0x04 };
2733 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
2734 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
2736 index = (modeinfo >> 8) & 0xFF;
2738 temp = XGI330_ScreenOffset[index];
2740 if (infoflag & InterlaceMode)
2743 colordepth = XGI_GetColorDepth(ModeIdIndex);
2745 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2746 temp = ModeNo - 0x7C;
2747 colordepth = ColorDepth[temp];
2749 if (infoflag & InterlaceMode)
2752 return temp * colordepth;
2755 static void XGI_SetCRT2Offset(unsigned short ModeNo,
2756 unsigned short ModeIdIndex,
2757 unsigned short RefreshRateTableIndex,
2758 struct vb_device_info *pVBInfo)
2760 unsigned short offset;
2763 if (pVBInfo->VBInfo & SetInSlaveMode)
2766 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex);
2767 temp = (unsigned char) (offset & 0xFF);
2768 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
2769 temp = (unsigned char) ((offset & 0xFF00) >> 8);
2770 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
2771 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
2772 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
2775 static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
2777 /* threshold high ,disable auto threshold */
2778 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2779 /* threshold low default 04h */
2780 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
2783 static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
2784 unsigned short RefreshRateTableIndex,
2785 struct vb_device_info *pVBInfo)
2789 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
2790 XGI_SetCRT2FIFO(pVBInfo);
2792 for (tempcx = 4; tempcx < 7; tempcx++)
2793 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
2795 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2796 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
2799 static void XGI_SetGroup1(unsigned short ModeIdIndex,
2800 unsigned short RefreshRateTableIndex,
2801 struct vb_device_info *pVBInfo)
2803 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
2804 pushbx = 0, CRT1Index, modeflag;
2806 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
2807 CRT1Index &= IndexMask;
2808 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2810 /* bainy change table name */
2811 if (modeflag & HalfDCLK) {
2812 /* BTVGA2HT 0x08,0x09 */
2813 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
2814 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
2815 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
2816 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
2817 /* BTVGA2HDEE 0x0A,0x0C */
2818 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
2819 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
2820 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2821 pushbx = pVBInfo->VGAHDE / 2 + 16;
2823 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2826 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2827 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2828 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
2830 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
2831 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
2833 temp = XGI_CRT1Table[CRT1Index].CR[15];
2834 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2835 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2841 if (tempcx > (pVBInfo->VGAHT / 2))
2842 tempcx = pVBInfo->VGAHT / 2;
2844 temp = tempbx & 0x00FF;
2846 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
2848 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
2849 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
2850 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
2851 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
2852 /* BTVGA2HDEE 0x0A,0x0C */
2853 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
2854 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
2855 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2856 pushbx = pVBInfo->VGAHDE + 16;
2858 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2861 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2862 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2863 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
2865 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
2866 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
2868 temp = XGI_CRT1Table[CRT1Index].CR[6];
2869 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2870 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2875 if (tempcx > pVBInfo->VGAHT)
2876 tempcx = pVBInfo->VGAHT;
2878 temp = tempbx & 0x00FF;
2879 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
2882 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2884 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2885 tempax |= (tempbx & 0xFF00);
2886 temp = (tempax & 0xFF00) >> 8;
2887 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
2888 temp = tempcx & 0x00FF;
2889 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
2890 tempcx = (pVBInfo->VGAVT - 1);
2891 temp = tempcx & 0x00FF;
2893 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
2894 tempbx = pVBInfo->VGAVDE - 1;
2895 temp = tempbx & 0x00FF;
2896 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
2897 temp = ((tempbx & 0xFF00) << 3) >> 8;
2898 temp |= ((tempcx & 0xFF00) >> 8);
2899 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
2901 /* BTVGA2VRS 0x10,0x11 */
2902 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2903 /* BTVGA2VRE 0x11 */
2904 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
2906 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2907 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2908 temp = XGI_CRT1Table[CRT1Index].CR[9];
2916 temp = XGI_CRT1Table[CRT1Index].CR[14];
2921 temp = XGI_CRT1Table[CRT1Index].CR[11];
2922 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
2925 temp = tempbx & 0x00FF;
2926 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
2927 temp = ((tempbx & 0xFF00) >> 8) << 4;
2928 temp = ((tempcx & 0x000F) | (temp));
2929 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
2932 if (modeflag & DoubleScanMode)
2935 if (modeflag & HalfDCLK)
2938 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
2941 static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
2943 unsigned long tempax, tempbx;
2945 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
2947 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
2948 tempax = (tempax * pVBInfo->HT) / tempbx;
2950 return (unsigned short) tempax;
2953 static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2954 struct vb_device_info *pVBInfo)
2956 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
2959 /* si+Ext_ResInfo */
2960 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2961 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2963 if (!(pVBInfo->VBInfo & SetInSlaveMode))
2966 temp = 0xFF; /* set MAX HT */
2967 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
2970 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
2971 modeflag |= Charx8Dot;
2973 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
2975 if (modeflag & HalfDCLK)
2978 tempax = (tempax / tempcx) - 1;
2979 tempbx |= ((tempax & 0x00FF) << 8);
2980 temp = tempax & 0x00FF;
2981 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
2983 temp = (tempbx & 0xFF00) >> 8;
2985 if (pVBInfo->VBInfo & SetCRT2ToTV) {
2986 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2987 | VB_SIS302LV | VB_XGI301C)))
2990 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
2991 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
2995 /* 0x05 Horizontal Display Start */
2996 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
2997 /* 0x06 Horizontal Blank end */
2998 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
3000 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3001 if (pVBInfo->VBInfo & SetCRT2ToTV)
3002 tempax = pVBInfo->VGAHT;
3004 tempax = XGI_GetVGAHT2(pVBInfo);
3007 if (tempax >= pVBInfo->VGAHT)
3008 tempax = pVBInfo->VGAHT;
3010 if (modeflag & HalfDCLK)
3013 tempax = (tempax / tempcx) - 5;
3014 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
3015 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3016 temp = (tempbx & 0x00FF) - 1;
3017 if (!(modeflag & HalfDCLK)) {
3019 if (pVBInfo->TVInfo & TVSimuMode) {
3025 tempbx = (tempbx & 0xFF00) >> 8;
3026 tempcx = (tempcx + tempbx) >> 1;
3027 temp = (tempcx & 0x00FF) + 2;
3029 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3031 if (!(modeflag & HalfDCLK)) {
3032 if ((modeflag & Charx8Dot)) {
3034 if (pVBInfo->VGAHDE >= 800)
3038 } else if (!(modeflag & HalfDCLK)) {
3040 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
3041 pVBInfo->VGAHDE >= 800) {
3043 if (pVBInfo->VGAHDE >= 1280 &&
3044 pVBInfo->LCDResInfo != Panel_1280x960 &&
3045 (pVBInfo->LCDInfo & LCDNonExpanding))
3051 /* 0x07 Horizontal Retrace Start */
3052 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3053 /* 0x08 Horizontal Retrace End */
3054 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
3056 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3057 if (pVBInfo->TVInfo & TVSimuMode) {
3058 if (ModeNo == 0x50) {
3059 if (pVBInfo->TVInfo == SetNTSCTV) {
3060 xgifb_reg_set(pVBInfo->Part1Port,
3062 xgifb_reg_set(pVBInfo->Part1Port,
3065 xgifb_reg_set(pVBInfo->Part1Port,
3067 xgifb_reg_set(pVBInfo->Part1Port,
3074 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
3075 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
3076 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
3078 tempbx = pVBInfo->VGAVT;
3081 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
3096 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3097 if (pVBInfo->LCDResInfo == Panel_1024x768) {
3098 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
3108 temp = tempbx & 0x00FF;
3109 /* 0x10 vertical Blank Start */
3110 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
3113 temp = tempbx & 0x00FF;
3114 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
3116 if (tempbx & 0x0100)
3121 if (modeflag & DoubleScanMode)
3124 if (tempbx & 0x0200)
3127 temp = (tempax & 0xFF00) >> 8;
3128 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
3130 if (tempbx & 0x0400)
3133 /* 0x11 Vertival Blank End */
3134 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
3137 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3139 push1 = tempax; /* push ax */
3141 if (resinfo != 0x09) {
3146 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3147 if ((pVBInfo->VBType & VB_SIS301LV) &&
3148 !(pVBInfo->TVInfo & TVSetHiVision)) {
3149 if ((pVBInfo->TVInfo & TVSimuMode) &&
3150 (pVBInfo->TVInfo & TVSetPAL)) {
3151 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3161 } else if (pVBInfo->TVInfo & TVSimuMode) {
3162 if (pVBInfo->TVInfo & TVSetPAL) {
3163 if (pVBInfo->VBType & VB_SIS301LV) {
3164 if (!(pVBInfo->TVInfo &
3178 push1 = tempax; /* push ax */
3180 if ((pVBInfo->TVInfo & TVSetPAL)) {
3181 if (tempbx <= 513) {
3187 temp = tempbx & 0x00FF;
3188 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
3190 temp = tempbx & 0x00FF;
3191 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
3193 if (tempbx & 0x0100)
3196 if (tempbx & 0x0200)
3197 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
3201 if (tempbx & 0x0100)
3204 if (tempbx & 0x0200)
3207 if (tempbx & 0x0400)
3210 tempbx = push1; /* pop ax */
3211 temp = tempbx & 0x00FF;
3213 /* 0x0D vertical Retrace End */
3214 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
3216 if (tempbx & 0x0010)
3219 temp = tempcx & 0x00FF;
3220 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
3221 temp = (tempcx & 0x0FF00) >> 8;
3222 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
3224 temp = (tempax & 0xFF00) >> 8;
3226 temp = (temp >> 1) & 0x09;
3228 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
3231 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3232 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3233 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
3235 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3240 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
3243 static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
3244 struct vb_device_info *pVBInfo)
3246 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
3248 unsigned char const *TimingPoint;
3250 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3252 /* si+Ext_ResInfo */
3253 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3257 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3260 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3263 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3266 if (!(pVBInfo->TVInfo & TVSetPAL))
3269 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3272 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
3275 tempax = (tempax & 0xff00) >> 8;
3277 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
3278 TimingPoint = XGI330_NTSCTiming;
3280 if (pVBInfo->TVInfo & TVSetPAL)
3281 TimingPoint = XGI330_PALTiming;
3283 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3284 TimingPoint = XGI330_HiTVExtTiming;
3286 if (pVBInfo->VBInfo & SetInSlaveMode)
3287 TimingPoint = XGI330_HiTVSt2Timing;
3289 if (pVBInfo->SetFlag & TVSimuMode)
3290 TimingPoint = XGI330_HiTVSt1Timing;
3292 if (!(modeflag & Charx8Dot))
3293 TimingPoint = XGI330_HiTVTextTiming;
3296 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3297 if (pVBInfo->TVInfo & TVSetYPbPr525i)
3298 TimingPoint = XGI330_YPbPr525iTiming;
3300 if (pVBInfo->TVInfo & TVSetYPbPr525p)
3301 TimingPoint = XGI330_YPbPr525pTiming;
3303 if (pVBInfo->TVInfo & TVSetYPbPr750p)
3304 TimingPoint = XGI330_YPbPr750pTiming;
3307 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
3308 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
3310 for (i = 0x39; i <= 0x45; i++, j++)
3312 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
3314 if (pVBInfo->VBInfo & SetCRT2ToTV)
3315 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
3317 temp = pVBInfo->NewFlickerMode;
3319 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
3321 if (pVBInfo->TVInfo & TVSetPAL)
3326 if (pVBInfo->VDE <= tempax) {
3327 tempax -= pVBInfo->VDE;
3329 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3331 temp = (tempax & 0xFF00) >> 8;
3332 temp += (unsigned short) TimingPoint[0];
3334 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3335 | VB_SIS302LV | VB_XGI301C)) {
3336 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3337 | SetCRT2ToSVIDEO | SetCRT2ToSCART
3338 | SetCRT2ToYPbPr525750)) {
3339 tempcx = pVBInfo->VGAHDE;
3340 if (tempcx >= 1024) {
3341 temp = 0x17; /* NTSC */
3342 if (pVBInfo->TVInfo & TVSetPAL)
3343 temp = 0x19; /* PAL */
3348 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
3350 temp = (tempax & 0xFF00) >> 8;
3351 temp += TimingPoint[1];
3353 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3354 | VB_SIS302LV | VB_XGI301C)) {
3355 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3356 | SetCRT2ToSVIDEO | SetCRT2ToSCART
3357 | SetCRT2ToYPbPr525750))) {
3358 tempcx = pVBInfo->VGAHDE;
3359 if (tempcx >= 1024) {
3360 temp = 0x1D; /* NTSC */
3361 if (pVBInfo->TVInfo & TVSetPAL)
3362 temp = 0x52; /* PAL */
3366 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
3370 tempcx = pVBInfo->HT;
3372 if (XGI_IsLCDDualLink(pVBInfo))
3376 temp = tempcx & 0x00FF;
3377 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
3379 temp = (tempcx & 0xFF00) >> 8;
3380 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
3382 tempcx = pVBInfo->HT >> 1;
3383 push1 = tempcx; /* push cx */
3386 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3389 temp = tempcx & 0x00FF;
3391 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
3393 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3396 temp = tempbx & 0x00FF;
3397 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
3398 temp = (tempbx & 0xFF00) >> 8;
3400 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
3403 tempbx = tempbx + 8;
3404 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3405 tempbx = tempbx - 4;
3409 temp = (tempbx & 0x00FF) << 4;
3410 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
3413 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3414 temp = tempcx & 0x00FF;
3415 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
3416 temp = ((tempcx & 0xFF00) >> 8) << 4;
3417 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
3420 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3423 temp = tempcx & 0xFF;
3425 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
3427 tempcx = push1; /* pop cx */
3429 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3431 temp = tempcx & 0x00FF;
3433 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
3437 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3438 tempax = XGI_GetVGAHT2(pVBInfo);
3439 tempcx = tempax - 1;
3441 temp = tempcx & 0x00FF;
3442 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
3444 tempbx = pVBInfo->VDE;
3446 if (pVBInfo->VGAVDE == 360)
3448 if (pVBInfo->VGAVDE == 375)
3450 if (pVBInfo->VGAVDE == 405)
3453 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3454 if (pVBInfo->VBType &
3455 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
3456 if (!(pVBInfo->TVInfo &
3457 (TVSetYPbPr525p | TVSetYPbPr750p)))
3464 temp = tempbx & 0x00FF;
3466 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3467 if (pVBInfo->VBType & VB_SIS301LV) {
3468 if (pVBInfo->TVInfo & TVSetHiVision) {
3469 if (pVBInfo->VBInfo & SetInSlaveMode) {
3474 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3480 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
3482 temp = (tempcx & 0xFF00) >> 8;
3483 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3485 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
3486 if (pVBInfo->VBType & VB_SIS301LV) {
3487 if (pVBInfo->TVInfo & TVSetHiVision) {
3490 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3495 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3500 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
3502 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3503 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
3504 tempbx = pVBInfo->VDE;
3505 tempcx = tempbx - 2;
3507 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3508 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3513 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
3515 if (tempcx & 0x0400)
3518 if (tempbx & 0x0400)
3521 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
3524 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
3525 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
3526 temp = (tempbx - 3) & 0x00FF;
3527 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
3530 tempbx = tempbx & 0x00FF;
3532 if (!(modeflag & HalfDCLK)) {
3533 tempcx = pVBInfo->VGAHDE;
3534 if (tempcx >= pVBInfo->HDE) {
3542 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3543 if (pVBInfo->VGAHDE >= 1024) {
3545 if (pVBInfo->VGAHDE >= 1280) {
3547 tempbx = tempbx & 0xDFFF;
3552 if (!(tempbx & 0x2000)) {
3553 if (modeflag & HalfDCLK)
3554 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3557 tempeax = pVBInfo->VGAHDE;
3558 tempebx = (tempcx & 0xFF00) >> 8;
3559 longtemp = tempeax * tempebx;
3560 tempecx = tempcx & 0x00FF;
3561 longtemp = longtemp / tempecx;
3566 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3567 | VB_SIS302LV | VB_XGI301C)) {
3568 tempecx = tempecx * 8;
3571 longtemp = longtemp * tempecx;
3572 tempecx = pVBInfo->HDE;
3573 temp2 = longtemp % tempecx;
3574 tempeax = longtemp / tempecx;
3578 tempax = (unsigned short) tempeax;
3581 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3582 | VB_SIS302LV | VB_XGI301C)) {
3583 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3588 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3589 | (tempbx & 0x00FF));
3590 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3591 | (tempax & 0x00FF));
3592 temp = (tempax & 0xFF00) >> 8;
3594 temp = (tempax & 0x00FF) >> 8;
3597 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
3598 temp = (tempbx & 0xFF00) >> 8;
3599 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
3600 temp = tempcx & 0x00FF;
3602 if (tempbx & 0x2000)
3605 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3608 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
3609 if (pVBInfo->TVInfo & TVSetPAL) {
3617 temp = tempbx & 0x00FF;
3618 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
3619 temp = tempcx & 0x00FF;
3620 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
3622 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3624 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3626 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3629 if (pVBInfo->TVInfo & TVSetYPbPr525p)
3632 if (pVBInfo->TVInfo & TVSetYPbPr750p)
3636 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
3637 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
3638 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
3640 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
3641 if (pVBInfo->TVInfo & NTSC1024x768) {
3642 TimingPoint = XGI_NTSC1024AdjTime;
3643 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
3644 xgifb_reg_set(pVBInfo->Part2Port, i,
3647 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
3651 /* Modify for 301C PALM Support */
3652 if (pVBInfo->VBType & VB_XGI301C) {
3653 if (pVBInfo->TVInfo & TVSetPALM)
3654 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
3655 0x08); /* PALM Mode */
3658 if (pVBInfo->TVInfo & TVSetPALM) {
3659 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
3661 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
3663 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
3666 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3667 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3668 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
3672 static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
3673 struct vb_device_info *pVBInfo)
3675 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3678 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
3680 /* si+Ext_ResInfo */
3681 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3684 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3686 if (XGI_IsLCDDualLink(pVBInfo))
3690 temp = tempbx & 0x00FF;
3691 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
3692 temp = (tempbx & 0xFF00) >> 8;
3694 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
3697 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
3698 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
3700 temp = tempbx & 0x00FF;
3701 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
3702 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
3703 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
3705 tempcx = pVBInfo->VT - 1;
3706 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
3707 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
3708 temp = (tempcx & 0xFF00) >> 8;
3710 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
3711 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3712 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3713 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3714 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
3716 /* Customized LCDB Does not add */
3717 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3718 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeIdIndex,
3721 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeIdIndex,
3724 tempah = pVBInfo->LCDResInfo;
3725 tempah &= PanelResInfo;
3727 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
3730 } else if ((tempah == Panel_1280x1024) ||
3731 (tempah == Panel_1280x1024x75)) {
3734 } else if (tempah == Panel_1400x1050) {
3742 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3743 tempbx = pVBInfo->HDE;
3744 tempcx = pVBInfo->VDE;
3748 tempax = pVBInfo->VT;
3749 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3750 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3751 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3752 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3753 tempbx = pVBInfo->LCDVDES;
3756 if (tempcx >= tempax)
3757 tempcx -= tempax; /* lcdvdes */
3759 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
3760 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
3761 temp = tempcx & 0x00FF;
3762 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
3763 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3764 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3768 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
3771 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3773 tempax = pVBInfo->VT;
3774 tempbx = pVBInfo->LCDVRS;
3777 if (tempcx >= tempax)
3780 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
3781 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
3782 temp = (tempbx & 0xFF00) >> 8;
3784 temp |= (tempcx & 0x000F);
3785 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
3787 tempax = pVBInfo->HT;
3788 tempbx = pVBInfo->LCDHDES;
3791 if (XGI_IsLCDDualLink(pVBInfo)) {
3797 if (pVBInfo->VBType & VB_SIS302LV)
3800 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3805 if (tempcx >= tempax)
3808 temp = tempbx & 0x00FF;
3809 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
3810 temp = ((tempbx & 0xFF00) >> 8) << 4;
3811 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
3812 temp = tempcx & 0x00FF;
3813 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
3814 temp = (tempcx & 0xFF00) >> 8;
3815 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
3817 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3819 tempax = pVBInfo->HT;
3820 tempbx = pVBInfo->LCDHRS;
3821 if (XGI_IsLCDDualLink(pVBInfo)) {
3827 if (pVBInfo->VBType & VB_SIS302LV)
3832 if (tempcx >= tempax)
3835 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
3836 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
3838 temp = (tempbx & 0xFF00) >> 8;
3840 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
3841 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
3842 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
3844 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
3845 if (pVBInfo->VGAVDE == 525) {
3846 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3847 | VB_SIS301LV | VB_SIS302LV
3853 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3854 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
3857 if (pVBInfo->VGAVDE == 420) {
3858 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3859 | VB_SIS301LV | VB_SIS302LV
3864 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3869 /* --------------------------------------------------------------------- */
3870 /* Function : XGI_GetTap4Ptr */
3872 /* Output : di -> Tap4 Reg. Setting Pointer */
3874 /* --------------------------------------------------------------------- */
3875 static struct XGI301C_Tap4TimingStruct const
3876 *XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
3878 unsigned short tempax, tempbx, i;
3879 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
3882 tempax = pVBInfo->VGAHDE;
3883 tempbx = pVBInfo->HDE;
3885 tempax = pVBInfo->VGAVDE;
3886 tempbx = pVBInfo->VDE;
3889 if (tempax <= tempbx)
3890 return &xgifb_tap4_timing[0];
3891 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
3893 if (pVBInfo->TVInfo & TVSetPAL)
3894 Tap4TimingPtr = PALTap4Timing;
3896 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3897 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3898 (pVBInfo->TVInfo & TVSetYPbPr525p))
3899 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
3900 if (pVBInfo->TVInfo & TVSetYPbPr750p)
3901 Tap4TimingPtr = YPbPr750pTap4Timing;
3904 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3905 Tap4TimingPtr = xgifb_tap4_timing;
3908 while (Tap4TimingPtr[i].DE != 0xFFFF) {
3909 if (Tap4TimingPtr[i].DE == tempax)
3913 return &Tap4TimingPtr[i];
3916 static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
3918 unsigned short i, j;
3919 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
3921 if (!(pVBInfo->VBType & VB_XGI301C))
3924 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
3925 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
3926 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
3928 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
3929 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
3930 /* Set Vertical Scaling */
3931 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
3932 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
3933 xgifb_reg_set(pVBInfo->Part2Port,
3935 Tap4TimingPtr->Reg[j]);
3938 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
3939 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
3940 /* Enable V.Scaling */
3941 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
3943 /* Enable H.Scaling */
3944 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
3947 static void XGI_SetGroup3(unsigned short ModeIdIndex,
3948 struct vb_device_info *pVBInfo)
3951 unsigned char const *tempdi;
3952 unsigned short modeflag;
3954 /* si+Ext_ResInfo */
3955 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3957 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
3958 if (pVBInfo->TVInfo & TVSetPAL) {
3959 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3960 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
3962 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
3963 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
3966 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
3969 if (pVBInfo->TVInfo & TVSetPALM) {
3970 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3971 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
3972 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
3975 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
3976 & SetCRT2ToYPbPr525750)) {
3977 if (pVBInfo->TVInfo & TVSetYPbPr525i)
3980 tempdi = XGI330_HiTVGroup3Data;
3981 if (pVBInfo->SetFlag & TVSimuMode) {
3982 tempdi = XGI330_HiTVGroup3Simu;
3983 if (!(modeflag & Charx8Dot))
3984 tempdi = XGI330_HiTVGroup3Text;
3987 if (pVBInfo->TVInfo & TVSetYPbPr525p)
3988 tempdi = XGI330_Ren525pGroup3;
3990 if (pVBInfo->TVInfo & TVSetYPbPr750p)
3991 tempdi = XGI330_Ren750pGroup3;
3993 for (i = 0; i <= 0x3E; i++)
3994 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
3996 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
3997 if (pVBInfo->TVInfo & TVSetYPbPr525p)
3998 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
4003 static void XGI_SetGroup4(unsigned short ModeIdIndex,
4004 unsigned short RefreshRateTableIndex,
4005 struct vb_device_info *pVBInfo)
4007 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
4009 unsigned long tempebx, tempeax, templong;
4011 /* si+Ext_ResInfo */
4012 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4013 temp = pVBInfo->RVBHCFACT;
4014 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
4016 tempbx = pVBInfo->RVBHCMAX;
4017 temp = tempbx & 0x00FF;
4018 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
4019 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4020 tempcx = pVBInfo->VGAHT - 1;
4021 temp = tempcx & 0x00FF;
4022 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
4024 temp = ((tempcx & 0xFF00) >> 8) << 3;
4027 tempcx = pVBInfo->VGAVT - 1;
4028 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4031 temp = tempcx & 0x00FF;
4032 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
4033 temp = temp2 | ((tempcx & 0xFF00) >> 8);
4034 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
4035 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
4036 tempcx = pVBInfo->VBInfo;
4037 tempbx = pVBInfo->VGAHDE;
4039 if (modeflag & HalfDCLK)
4042 if (XGI_IsLCDDualLink(pVBInfo))
4045 if (tempcx & SetCRT2ToHiVision) {
4051 } else if (tempcx & SetCRT2ToTV) {
4057 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4064 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
4066 if (pVBInfo->VGAHDE == 1280)
4068 if (pVBInfo->VGAHDE == 1024)
4071 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
4073 tempebx = pVBInfo->VDE;
4075 tempcx = pVBInfo->RVBHRS;
4076 temp = tempcx & 0x00FF;
4077 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
4079 tempeax = pVBInfo->VGAVDE;
4082 if (tempeax <= tempebx) {
4083 tempcx = (tempcx & (~0x4000));
4084 tempeax = pVBInfo->VGAVDE;
4089 templong = (tempeax * 256 * 1024) % tempebx;
4090 tempeax = (tempeax * 256 * 1024) / tempebx;
4096 temp = (unsigned short) (tempebx & 0x000000FF);
4097 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
4099 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
4100 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
4101 tempbx = (unsigned short) (tempebx >> 16);
4102 temp = tempbx & 0x00FF;
4104 temp |= ((tempcx & 0xFF00) >> 8);
4105 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
4108 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4109 | VB_SIS302LV | VB_XGI301C)) {
4111 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
4112 tempax = pVBInfo->VGAHDE;
4113 if (modeflag & HalfDCLK)
4116 if (XGI_IsLCDDualLink(pVBInfo))
4119 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4122 } else if (pVBInfo->VGAHDE > 800) {
4123 if (pVBInfo->VGAHDE == 1024)
4124 tempax = (tempax * 25 / 32) - 1;
4126 tempax = (tempax * 20 / 32) - 1;
4130 temp = (tempax & 0xFF00) >> 8;
4131 temp = (temp & 0x0003) << 4;
4132 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
4133 temp = (tempax & 0x00FF);
4134 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
4136 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
4137 if (pVBInfo->VGAHDE > 800)
4138 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
4143 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4144 if (!(pVBInfo->TVInfo & (NTSC1024x768
4145 | TVSetYPbPr525p | TVSetYPbPr750p
4146 | TVSetHiVision))) {
4148 if ((pVBInfo->VBInfo & SetInSlaveMode)
4149 && (!(pVBInfo->TVInfo
4155 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
4156 tempbx = pVBInfo->HT;
4157 if (XGI_IsLCDDualLink(pVBInfo))
4159 tempbx = (tempbx >> 1) - 2;
4160 temp = ((tempbx & 0x0700) >> 8) << 3;
4161 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
4162 temp = tempbx & 0x00FF;
4163 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
4167 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
4170 static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4172 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
4175 static void XGI_SetGroup5(struct vb_device_info *pVBInfo)
4177 if (pVBInfo->ModeType == ModeVGA) {
4178 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
4179 | DisableCRT2Display))) {
4180 XGINew_EnableCRT2(pVBInfo);
4185 static void XGI_DisableGatingCRT(struct vb_device_info *pVBInfo)
4187 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
4190 static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4191 unsigned short ModeNo, unsigned short ModeIdIndex)
4193 unsigned short xres, yres, colordepth, modeflag, resindex;
4195 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
4196 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4197 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
4198 /* si+St_ModeFlag */
4199 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4201 if (!(modeflag & Charx8Dot)) {
4206 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4209 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4212 if (xres > xgifb_info->lvds_data.LVDSHDE)
4215 if (yres > xgifb_info->lvds_data.LVDSVDE)
4218 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4219 yres != xgifb_info->lvds_data.LVDSVDE) {
4220 colordepth = XGI_GetColorDepth(ModeIdIndex);
4227 static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4229 unsigned short ModeIdIndex,
4230 struct vb_device_info *pVBInfo)
4232 unsigned char temp, Miscdata;
4233 unsigned short xres, yres, modeflag, resindex;
4234 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4235 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4236 unsigned short value;
4238 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
4239 (LCDPolarity << 8)) >> 8);
4240 temp &= LCDPolarity;
4241 Miscdata = inb(pVBInfo->P3cc);
4243 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
4245 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
4246 /* SR35[7] FP VSync polarity */
4247 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4248 /* SR30[5] FP HSync polarity */
4249 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
4251 if (chip_id == XG27)
4252 XGI_SetXG27FPBits(pVBInfo);
4254 XGI_SetXG21FPBits(pVBInfo);
4256 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
4257 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4258 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
4259 /* si+St_ModeFlag */
4260 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4262 if (!(modeflag & Charx8Dot))
4263 xres = xres * 8 / 9;
4265 LVDSHT = xgifb_info->lvds_data.LVDSHT;
4267 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
4269 if (LVDSHBS > LVDSHT)
4272 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
4273 if (LVDSHRS > LVDSHT)
4276 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
4277 if (LVDSHRE > LVDSHT)
4280 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
4282 LVDSVT = xgifb_info->lvds_data.LVDSVT;
4284 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
4285 if (modeflag & DoubleScanMode)
4286 LVDSVBS += yres / 2;
4288 if (LVDSVBS > LVDSVT)
4291 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
4292 if (LVDSVRS > LVDSVT)
4295 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
4296 if (LVDSVRE > LVDSVT)
4299 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
4301 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
4302 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
4304 if (!(modeflag & Charx8Dot))
4305 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
4307 /* HT SR0B[1:0] CR00 */
4308 value = (LVDSHT >> 3) - 5;
4309 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
4310 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
4312 /* HBS SR0B[5:4] CR02 */
4313 value = (LVDSHBS >> 3) - 1;
4314 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
4315 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
4317 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4318 value = (LVDSHBE >> 3) - 1;
4319 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4320 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4321 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
4323 /* HRS SR0B[7:6] CR04 */
4324 value = (LVDSHRS >> 3) + 2;
4325 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
4326 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
4328 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4330 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
4331 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
4333 /* HRE SR0C[2] CR05[4:0] */
4334 value = (LVDSHRE >> 3) + 2;
4335 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4336 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
4338 /* Panel HRE SR2F[7:2] */
4340 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
4342 /* VT SR0A[0] CR07[5][0] CR06 */
4344 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4345 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4346 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
4347 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
4349 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4350 value = LVDSVBS - 1;
4351 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4352 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4353 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
4354 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
4356 /* VBE SR0A[4] CR16 */
4357 value = LVDSVBE - 1;
4358 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
4359 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
4361 /* VRS SR0A[3] CR7[7][2] CR10 */
4362 value = LVDSVRS - 1;
4363 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4364 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4365 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
4366 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
4368 if (chip_id == XG27) {
4369 /* Panel VRS SR35[2:0] SR34[7:0] */
4370 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4371 (value & 0x700) >> 8);
4372 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4374 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4375 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4376 (value & 0x600) >> 9);
4377 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4378 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4381 /* VRE SR0A[5] CR11[3:0] */
4382 value = LVDSVRE - 1;
4383 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4384 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
4386 /* Panel VRE SR3F[7:2] */
4387 if (chip_id == XG27)
4388 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4389 (value << 2) & 0xFC);
4391 /* SR3F[7] has to be 0, h/w bug */
4392 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4393 (value << 2) & 0x7C);
4395 for (temp = 0, value = 0; temp < 3; temp++) {
4397 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
4398 xgifb_reg_set(pVBInfo->P3c4,
4399 0x2B, xgifb_info->lvds_data.VCLKData1);
4400 xgifb_reg_set(pVBInfo->P3c4,
4401 0x2C, xgifb_info->lvds_data.VCLKData2);
4405 if (!(modeflag & Charx8Dot)) {
4406 inb(pVBInfo->P3da); /* reset 3da */
4407 outb(0x13, pVBInfo->P3c0); /* set index */
4408 /* set data, panning = 0, shift left 1 dot*/
4409 outb(0x00, pVBInfo->P3c0);
4411 inb(pVBInfo->P3da); /* Enable Attribute */
4412 outb(0x20, pVBInfo->P3c0);
4414 inb(pVBInfo->P3da); /* reset 3da */
4419 /* --------------------------------------------------------------------- */
4420 /* Function : XGI_IsLCDON */
4422 /* Output : 0 : Skip PSC Control */
4423 /* 1: Disable PSC */
4425 /* --------------------------------------------------------------------- */
4426 static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
4428 unsigned short tempax;
4430 tempax = pVBInfo->VBInfo;
4431 if (tempax & SetCRT2ToDualEdge)
4433 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
4439 static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4440 struct xgi_hw_device_info *HwDeviceExtension,
4441 struct vb_device_info *pVBInfo)
4443 unsigned short tempah = 0;
4445 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4446 | VB_SIS302LV | VB_XGI301C)) {
4448 if (!(pVBInfo->VBInfo &
4449 (DisableCRT2Display | SetSimuScanMode))) {
4450 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4451 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4452 tempah = 0x7F; /* Disable Channel A */
4456 /* disable part4_1f */
4457 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
4459 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
4460 if (((pVBInfo->VBInfo &
4461 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
4462 (XGI_IsLCDON(pVBInfo)))
4463 /* LVDS Driver power down */
4464 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
4467 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4469 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
4471 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4473 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
4475 /* disable TV as primary VGA swap */
4476 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
4478 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
4479 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
4481 if ((pVBInfo->VBInfo &
4482 (DisableCRT2Display | SetSimuScanMode)) ||
4483 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
4485 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
4486 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4488 if ((pVBInfo->VBInfo &
4489 (DisableCRT2Display | SetSimuScanMode)) ||
4490 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
4492 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4493 /* save Part1 index 0 */
4494 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4495 /* BTDAC = 1, avoid VB reset */
4496 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4498 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4499 /* restore Part1 index 0 */
4500 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
4502 } else { /* {301} */
4503 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
4504 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4506 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4507 /* Disable TV asPrimary VGA swap */
4508 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
4511 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
4513 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
4517 /* --------------------------------------------------------------------- */
4518 /* Function : XGI_GetTVPtrIndex */
4521 /* Description : bx 0 : ExtNTSC */
4533 /* --------------------------------------------------------------------- */
4534 static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
4536 unsigned short tempbx = 0;
4538 if (pVBInfo->TVInfo & TVSetPAL)
4540 if (pVBInfo->TVInfo & TVSetHiVision)
4542 if (pVBInfo->TVInfo & TVSetYPbPr525i)
4544 if (pVBInfo->TVInfo & TVSetYPbPr525p)
4546 if (pVBInfo->TVInfo & TVSetYPbPr750p)
4548 if (pVBInfo->TVInfo & TVSimuMode)
4554 /* --------------------------------------------------------------------- */
4555 /* Function : XGI_GetTVPtrIndex2 */
4557 /* Output : bx 0 : NTSC */
4561 /* 4 : NTSC1024x768 */
4562 /* 5 : PAL-M 1024x768 */
4564 /* cl 0 : YFilter1 */
4567 /* 1 : 301B/302B/301LV/302LV */
4569 /* --------------------------------------------------------------------- */
4570 static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4571 unsigned char *tempch, struct vb_device_info *pVBInfo)
4577 if (pVBInfo->TVInfo & TVSetPAL)
4580 if (pVBInfo->TVInfo & TVSetPALM)
4583 if (pVBInfo->TVInfo & TVSetPALN)
4586 if (pVBInfo->TVInfo & NTSC1024x768) {
4588 if (pVBInfo->TVInfo & TVSetPALM)
4592 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4593 | VB_SIS302LV | VB_XGI301C)) {
4594 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4601 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4602 | VB_SIS302LV | VB_XGI301C))
4606 static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
4608 unsigned char tempah, tempbl, tempbh;
4610 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4611 | VB_SIS302LV | VB_XGI301C)) {
4612 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
4613 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
4615 tempbl = XGI301TVDelay;
4617 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4619 if (pVBInfo->VBInfo &
4620 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
4621 tempbh = XGI301LCDDelay;
4623 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
4629 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
4631 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4632 | SetCRT2ToTV)) { /* Channel B */
4637 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4642 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
4647 static void XGI_SetLCDCap_A(unsigned short tempcx,
4648 struct vb_device_info *pVBInfo)
4650 unsigned short temp;
4652 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
4654 if (temp & LCDRGB18Bit) {
4655 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
4657 (unsigned short) (0x20 | (tempcx & 0x00C0)));
4658 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
4660 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
4661 (unsigned short) (0x30 | (tempcx & 0x00C0)));
4662 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
4666 /* --------------------------------------------------------------------- */
4667 /* Function : XGI_SetLCDCap_B */
4668 /* Input : cx -> LCD Capability */
4671 /* --------------------------------------------------------------------- */
4672 static void XGI_SetLCDCap_B(unsigned short tempcx,
4673 struct vb_device_info *pVBInfo)
4675 if (tempcx & EnableLCD24bpp) /* 24bits */
4676 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
4677 (unsigned short) (((tempcx & 0x00ff) >> 6)
4680 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
4681 (unsigned short) (((tempcx & 0x00ff) >> 6)
4682 | 0x18)); /* Enable Dither */
4685 static void XGI_LongWait(struct vb_device_info *pVBInfo)
4689 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4692 for (i = 0; i < 0xFFFF; i++) {
4693 if (!(inb(pVBInfo->P3da) & 0x08))
4697 for (i = 0; i < 0xFFFF; i++) {
4698 if ((inb(pVBInfo->P3da) & 0x08))
4704 static void SetSpectrum(struct vb_device_info *pVBInfo)
4706 unsigned short index;
4708 index = XGI_GetLCDCapPtr(pVBInfo);
4710 /* disable down spectrum D[4] */
4711 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
4712 XGI_LongWait(pVBInfo);
4713 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
4714 XGI_LongWait(pVBInfo);
4716 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
4717 pVBInfo->LCDCapList[index].Spectrum_31);
4718 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
4719 pVBInfo->LCDCapList[index].Spectrum_32);
4720 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
4721 pVBInfo->LCDCapList[index].Spectrum_33);
4722 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
4723 pVBInfo->LCDCapList[index].Spectrum_34);
4724 XGI_LongWait(pVBInfo);
4725 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
4728 static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4730 unsigned short tempcx;
4732 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4734 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4735 VB_SIS302LV | VB_XGI301C)) {
4736 if (pVBInfo->VBType &
4737 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
4738 /* Set 301LV Capability */
4739 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
4740 (unsigned char) (tempcx & 0x1F));
4743 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
4744 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4745 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4746 | EnablePLLSPLOW)) >> 8));
4748 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4749 XGI_SetLCDCap_B(tempcx, pVBInfo);
4750 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4751 XGI_SetLCDCap_A(tempcx, pVBInfo);
4753 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
4754 if (tempcx & EnableSpectrum)
4755 SetSpectrum(pVBInfo);
4759 XGI_SetLCDCap_A(tempcx, pVBInfo);
4763 /* --------------------------------------------------------------------- */
4764 /* Function : XGI_SetAntiFlicker */
4767 /* Description : Set TV Customized Param. */
4768 /* --------------------------------------------------------------------- */
4769 static void XGI_SetAntiFlicker(struct vb_device_info *pVBInfo)
4771 unsigned short tempbx;
4773 unsigned char tempah;
4775 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
4778 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4780 tempah = TVAntiFlickList[tempbx];
4783 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
4786 static void XGI_SetEdgeEnhance(struct vb_device_info *pVBInfo)
4788 unsigned short tempbx;
4790 unsigned char tempah;
4792 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4794 tempah = TVEdgeList[tempbx];
4797 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
4800 static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
4802 unsigned short tempbx;
4804 unsigned char tempcl, tempch;
4806 unsigned long tempData;
4808 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4809 tempData = TVPhaseList[tempbx];
4811 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
4813 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
4814 & 0x0000FF00) >> 8));
4815 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
4816 & 0x00FF0000) >> 16));
4817 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
4818 & 0xFF000000) >> 24));
4821 static void XGI_SetYFilter(unsigned short ModeIdIndex,
4822 struct vb_device_info *pVBInfo)
4824 unsigned short tempbx, index;
4825 unsigned char const *filterPtr;
4826 unsigned char tempcl, tempch, tempal;
4828 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4833 filterPtr = NTSCYFilter1;
4837 filterPtr = PALYFilter1;
4844 filterPtr = xgifb_palmn_yfilter1;
4852 filterPtr = xgifb_yfilter2;
4859 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
4865 if ((tempcl == 0) && (tempch == 1)) {
4866 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4867 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4868 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4869 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
4871 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4872 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4873 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4874 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
4877 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4878 | VB_SIS302LV | VB_XGI301C)) {
4879 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4880 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4881 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
4885 /* --------------------------------------------------------------------- */
4886 /* Function : XGI_OEM310Setting */
4889 /* Description : Customized Param. for 301 */
4890 /* --------------------------------------------------------------------- */
4891 static void XGI_OEM310Setting(unsigned short ModeIdIndex,
4892 struct vb_device_info *pVBInfo)
4894 XGI_SetDelayComp(pVBInfo);
4896 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
4897 XGI_SetLCDCap(pVBInfo);
4899 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4900 XGI_SetPhaseIncr(pVBInfo);
4901 XGI_SetYFilter(ModeIdIndex, pVBInfo);
4902 XGI_SetAntiFlicker(pVBInfo);
4904 if (pVBInfo->VBType & VB_SIS301)
4905 XGI_SetEdgeEnhance(pVBInfo);
4909 /* --------------------------------------------------------------------- */
4910 /* Function : XGI_SetCRT2ModeRegs */
4913 /* Description : Origin code for crt2group */
4914 /* --------------------------------------------------------------------- */
4915 static void XGI_SetCRT2ModeRegs(struct vb_device_info *pVBInfo)
4917 unsigned short tempbl;
4920 unsigned char tempah;
4923 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
4924 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4925 tempah &= ~0x10; /* BTRAMDAC */
4926 tempah |= 0x40; /* BTRAM */
4928 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
4930 tempah = 0x40; /* BTDRAM */
4931 tempcl = pVBInfo->ModeType;
4935 tempah = (0x008 >> tempcl);
4940 if (pVBInfo->VBInfo & SetInSlaveMode)
4941 tempah ^= 0x50; /* BTDAC */
4945 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
4949 if (pVBInfo->VBInfo & DisableCRT2Display)
4955 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
4956 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4959 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
4960 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
4966 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4971 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
4977 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4980 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
4981 tempah = tempah ^ 0x05;
4982 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4983 tempah = tempah ^ 0x01;
4986 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
4990 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
4992 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
4993 | XGI_SetCRT2ToLCDA)) {
4995 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
4996 & SetInSlaveMode))) {
5001 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5003 if (pVBInfo->VBInfo & DriverMode)
5004 tempah = tempah ^ 0x20;
5007 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
5010 if (pVBInfo->LCDInfo & SetLCDDualLink)
5013 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5014 if (pVBInfo->TVInfo & RPLLDIV2XO)
5018 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5019 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
5022 if (pVBInfo->LCDResInfo == Panel_1280x960)
5025 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
5028 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5029 | VB_SIS302LV | VB_XGI301C)) {
5033 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5035 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5036 tempah |= 0x04; /* shampoo 0129 */
5039 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
5042 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5043 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5047 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
5051 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5052 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5055 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
5060 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
5062 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5066 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
5068 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
5069 if (pVBInfo->LCDInfo & SetLCDDualLink) {
5070 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5071 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
5077 void XGI_UnLockCRT2(struct vb_device_info *pVBInfo)
5079 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
5082 void XGI_LockCRT2(struct vb_device_info *pVBInfo)
5084 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
5087 unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5088 unsigned short ModeNo, unsigned short ModeIdIndex,
5089 struct vb_device_info *pVBInfo)
5091 const u8 LCDARefreshIndex[] = {
5092 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
5094 unsigned short RefreshRateTableIndex, i, index, temp;
5096 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
5097 index >>= pVBInfo->SelectCRT2Rate;
5100 if (pVBInfo->LCDInfo & LCDNonExpanding)
5106 if (pVBInfo->SetFlag & ProgrammingCRT2) {
5107 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
5108 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
5115 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
5116 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
5117 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
5118 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5119 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
5122 /* do the similar adjustment like XGISearchCRT1Rate() */
5123 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5124 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
5127 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5128 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
5135 if (XGI330_RefIndex[RefreshRateTableIndex + i].
5138 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
5139 temp &= ModeTypeMask;
5140 if (temp < pVBInfo->ModeType)
5145 } while (index != 0xFFFF);
5146 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5147 if (pVBInfo->VBInfo & SetInSlaveMode) {
5148 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
5150 if (temp & InterlaceMode)
5155 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5156 temp = XGI_AjustCRT2Rate(ModeIdIndex, RefreshRateTableIndex,
5159 return RefreshRateTableIndex + i;
5162 static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
5163 struct xgi_hw_device_info *HwDeviceExtension,
5164 struct vb_device_info *pVBInfo)
5166 unsigned short RefreshRateTableIndex;
5168 pVBInfo->SetFlag |= ProgrammingCRT2;
5169 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5170 ModeIdIndex, pVBInfo);
5171 XGI_GetLVDSResInfo(ModeIdIndex, pVBInfo);
5172 XGI_GetLVDSData(ModeIdIndex, pVBInfo);
5173 XGI_ModCRT1Regs(ModeIdIndex, HwDeviceExtension, pVBInfo);
5174 XGI_SetLVDSRegs(ModeIdIndex, pVBInfo);
5175 XGI_SetCRT2ECLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5178 static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
5179 struct xgi_hw_device_info *HwDeviceExtension,
5180 struct vb_device_info *pVBInfo)
5182 unsigned short ModeIdIndex, RefreshRateTableIndex;
5184 pVBInfo->SetFlag |= ProgrammingCRT2;
5185 XGI_SearchModeID(ModeNo, &ModeIdIndex);
5186 pVBInfo->SelectCRT2Rate = 4;
5187 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5188 ModeIdIndex, pVBInfo);
5189 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5190 XGI_GetCRT2ResInfo(ModeIdIndex, pVBInfo);
5191 XGI_GetCRT2Data(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5192 XGI_PreSetGroup1(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5193 XGI_SetGroup1(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5194 XGI_SetLockRegs(ModeNo, ModeIdIndex, pVBInfo);
5195 XGI_SetGroup2(ModeNo, ModeIdIndex, pVBInfo);
5196 XGI_SetLCDRegs(ModeIdIndex, pVBInfo);
5197 XGI_SetTap4Regs(pVBInfo);
5198 XGI_SetGroup3(ModeIdIndex, pVBInfo);
5199 XGI_SetGroup4(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5200 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5201 XGI_SetGroup5(pVBInfo);
5202 XGI_AutoThreshold(pVBInfo);
5206 void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5208 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5209 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5212 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5214 unsigned char CR17, CR63, SR31;
5215 unsigned short temp;
5219 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
5221 /* to fix XG42 single LCD sense to CRT+LCD */
5222 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
5223 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
5224 pVBInfo->P3d4, 0x53) | 0x02));
5226 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5227 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5228 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
5230 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5231 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
5233 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
5234 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
5236 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5237 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
5239 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
5240 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
5241 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
5242 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
5244 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
5246 for (i = 0; i < 8; i++)
5247 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
5249 for (i = 8; i < 11; i++)
5250 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
5253 for (i = 11; i < 13; i++)
5254 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
5257 for (i = 13; i < 16; i++)
5258 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
5261 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
5264 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5265 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5266 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
5268 outb(0x00, pVBInfo->P3c8);
5270 for (i = 0; i < 256 * 3; i++)
5271 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
5275 XGI_WaitDisply(pVBInfo);
5276 temp = inb(pVBInfo->P3c2);
5279 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
5281 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
5283 /* avoid display something, set BLACK DAC if not restore DAC */
5284 outb(0x00, pVBInfo->P3c8);
5286 for (i = 0; i < 256 * 3; i++)
5287 outb(0, (pVBInfo->P3c8 + 1));
5289 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5290 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5291 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
5293 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
5294 pVBInfo->P3d4, 0x53) & 0xFD));
5295 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
5298 static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5299 struct xgi_hw_device_info *HwDeviceExtension,
5300 struct vb_device_info *pVBInfo)
5302 unsigned short tempah;
5304 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5305 | VB_SIS302LV | VB_XGI301C)) {
5306 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5308 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
5310 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5312 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5314 if (pVBInfo->VBInfo & SetInSlaveMode) {
5315 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5318 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5319 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5321 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5323 if (!(tempah & 0x80))
5324 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5325 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
5328 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5329 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
5330 0x20); /* shampoo 0129 */
5331 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
5332 if (pVBInfo->VBInfo &
5333 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5334 /* LVDS PLL power on */
5335 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5337 /* LVDS Driver power on */
5338 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
5344 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5347 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5348 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5349 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5350 tempah = tempah & 0x40;
5351 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5352 tempah = tempah ^ 0xC0;
5356 /* EnablePart4_1F */
5357 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
5359 XGI_DisableGatingCRT(pVBInfo);
5360 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
5363 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
5364 | XGI_SetCRT2ToLCDA))
5366 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
5368 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5369 if (!(tempah & 0x80))
5370 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5372 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
5373 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
5377 static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5378 struct xgi_hw_device_info *HwDeviceExtension,
5379 unsigned short ModeNo, unsigned short ModeIdIndex,
5380 struct vb_device_info *pVBInfo)
5382 unsigned short RefreshRateTableIndex, temp;
5384 XGI_SetSeqRegs(pVBInfo);
5385 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
5386 XGI_SetCRTCRegs(pVBInfo);
5387 XGI_SetATTRegs(ModeIdIndex, pVBInfo);
5388 XGI_SetGRCRegs(pVBInfo);
5389 XGI_ClearExt1Regs(pVBInfo);
5391 if (HwDeviceExtension->jChipType == XG27) {
5392 if (pVBInfo->IF_DEF_LVDS == 0)
5393 XGI_SetDefaultVCLK(pVBInfo);
5396 temp = ~ProgrammingCRT2;
5397 pVBInfo->SetFlag &= temp;
5398 pVBInfo->SelectCRT2Rate = 0;
5400 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5401 | VB_SIS302LV | VB_XGI301C)) {
5402 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
5403 | SetInSlaveMode)) {
5404 pVBInfo->SetFlag |= ProgrammingCRT2;
5408 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5409 ModeIdIndex, pVBInfo);
5410 if (RefreshRateTableIndex != 0xFFFF) {
5411 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5412 XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
5413 pVBInfo, HwDeviceExtension);
5414 XGI_SetCRT1DE(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5415 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5416 HwDeviceExtension, pVBInfo);
5417 XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
5418 RefreshRateTableIndex, pVBInfo);
5421 if (HwDeviceExtension->jChipType >= XG21) {
5422 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
5425 if (HwDeviceExtension->jChipType == XG27)
5426 XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
5428 XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
5430 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5431 RefreshRateTableIndex);
5433 xgifb_set_lcd(HwDeviceExtension->jChipType,
5434 pVBInfo, RefreshRateTableIndex);
5436 if (pVBInfo->IF_DEF_LVDS == 1)
5437 xgifb_set_lvds(xgifb_info,
5438 HwDeviceExtension->jChipType,
5439 ModeIdIndex, pVBInfo);
5443 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5444 XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
5445 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
5446 RefreshRateTableIndex, pVBInfo);
5447 XGI_LoadDAC(pVBInfo);
5450 unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5451 struct xgi_hw_device_info *HwDeviceExtension,
5452 unsigned short ModeNo)
5454 unsigned short ModeIdIndex;
5455 struct vb_device_info VBINF;
5456 struct vb_device_info *pVBInfo = &VBINF;
5458 pVBInfo->IF_DEF_LVDS = 0;
5460 if (HwDeviceExtension->jChipType >= XG20)
5461 pVBInfo->VBType = 0; /*set VBType default 0*/
5463 XGIRegInit(pVBInfo, xgifb_info->vga_base);
5465 /* for x86 Linux, XG21 LVDS */
5466 if (HwDeviceExtension->jChipType == XG21) {
5467 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
5468 pVBInfo->IF_DEF_LVDS = 1;
5470 if (HwDeviceExtension->jChipType == XG27) {
5471 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5472 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
5473 pVBInfo->IF_DEF_LVDS = 1;
5477 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
5479 ModeNo = ModeNo & 0x7F;
5480 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
5482 if (HwDeviceExtension->jChipType < XG20)
5483 XGI_UnLockCRT2(pVBInfo);
5485 XGI_SearchModeID(ModeNo, &ModeIdIndex);
5487 if (HwDeviceExtension->jChipType < XG20) {
5488 XGI_GetVBInfo(ModeIdIndex, pVBInfo);
5489 XGI_GetTVInfo(ModeIdIndex, pVBInfo);
5490 XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
5491 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
5493 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5494 (!(pVBInfo->VBInfo & SwitchCRT2))) {
5495 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5496 ModeIdIndex, pVBInfo);
5498 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5499 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5500 HwDeviceExtension, pVBInfo);
5504 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
5505 switch (HwDeviceExtension->ujVBChipID) {
5506 case VB_CHIP_301: /* fall through */
5508 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5509 pVBInfo); /*add for CRT2 */
5517 XGI_SetCRT2ModeRegs(pVBInfo);
5518 XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
5519 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
5522 if (pVBInfo->IF_DEF_LVDS == 1)
5523 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
5527 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
5528 Ext_ModeFlag & ModeTypeMask;
5530 pVBInfo->SetFlag = 0;
5531 pVBInfo->VBInfo = DisableCRT2Display;
5533 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
5535 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5536 ModeIdIndex, pVBInfo);
5538 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
5541 XGI_UpdateModeInfo(pVBInfo);
5543 if (HwDeviceExtension->jChipType < XG20)
5544 XGI_LockCRT2(pVBInfo);