sb/amd/{agesa,pi}/hudson: Explicitly enable LPC controller
[coreboot.git] / src / drivers / xgi / common / vb_setmode.c
blobfdb70390136c972a15a4985dedca660dde222df9
1 /*
2 * This file is part of the coreboot project.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 /* File taken from the Linux xgifb driver (v3.18.5) */
16 #include "xgi_coreboot.h"
17 #include "vstruct.h"
18 #include "XGIfb.h"
19 #include "vb_def.h"
20 #include "vb_init.h"
21 #include "vb_util.h"
22 #include "vb_table.h"
23 #include "vb_setmode.h"
25 #define IndexMask 0xff
26 #define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
28 static const unsigned short XGINew_VGA_DAC[] = {
29 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
30 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
31 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
32 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
33 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
34 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
35 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
36 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
37 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
38 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
40 void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
42 pVBInfo->MCLKData = XGI340New_MCLKData;
44 pVBInfo->LCDResInfo = 0;
45 pVBInfo->LCDTypeInfo = 0;
46 pVBInfo->LCDInfo = 0;
47 pVBInfo->VBInfo = 0;
48 pVBInfo->TVInfo = 0;
50 pVBInfo->SR18 = XGI340_SR18;
51 pVBInfo->CR40 = XGI340_cr41;
53 if (ChipType < XG20)
54 XGI_GetVBType(pVBInfo);
56 /* 310 customization related */
57 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
58 pVBInfo->LCDCapList = XGI_LCDDLCapList;
59 else
60 pVBInfo->LCDCapList = XGI_LCDCapList;
62 if (ChipType >= XG20)
63 pVBInfo->XGINew_CR97 = 0x10;
65 if (ChipType == XG27) {
66 unsigned char temp;
68 pVBInfo->MCLKData = XGI27New_MCLKData;
69 pVBInfo->CR40 = XGI27_cr41;
70 pVBInfo->XGINew_CR97 = 0xc1;
71 pVBInfo->SR18 = XG27_SR18;
73 /*Z11m DDR*/
74 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
75 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
76 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
77 pVBInfo->XGINew_CR97 = 0x80;
82 static void XGI_SetSeqRegs(struct vb_device_info *pVBInfo)
84 unsigned char SRdata, i;
86 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
88 for (i = 0; i < 4; i++) {
89 /* Get SR1,2,3,4 from file */
90 /* SR1 is with screen off 0x20 */
91 SRdata = XGI330_StandTable.SR[i];
92 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
96 static void XGI_SetCRTCRegs(struct vb_device_info *pVBInfo)
98 unsigned char CRTCdata;
99 unsigned short i;
101 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
102 CRTCdata &= 0x7f;
103 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
105 for (i = 0; i <= 0x18; i++) {
106 /* Get CRTC from file */
107 CRTCdata = XGI330_StandTable.CRTC[i];
108 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
112 static void XGI_SetATTRegs(unsigned short ModeIdIndex,
113 struct vb_device_info *pVBInfo)
115 unsigned char ARdata;
116 unsigned short i, modeflag;
118 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
120 for (i = 0; i <= 0x13; i++) {
121 ARdata = XGI330_StandTable.ATTR[i];
123 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
124 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
125 ARdata = 0;
126 } else if ((pVBInfo->VBInfo &
127 (SetCRT2ToTV | SetCRT2ToLCD)) &&
128 (pVBInfo->VBInfo & SetInSlaveMode)) {
129 ARdata = 0;
133 inb(pVBInfo->P3da); /* reset 3da */
134 outb(i, pVBInfo->P3c0); /* set index */
135 outb(ARdata, pVBInfo->P3c0); /* set data */
138 inb(pVBInfo->P3da); /* reset 3da */
139 outb(0x14, pVBInfo->P3c0); /* set index */
140 outb(0x00, pVBInfo->P3c0); /* set data */
141 inb(pVBInfo->P3da); /* Enable Attribute */
142 outb(0x20, pVBInfo->P3c0);
145 static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
147 unsigned char GRdata;
148 unsigned short i;
150 for (i = 0; i <= 0x08; i++) {
151 /* Get GR from file */
152 GRdata = XGI330_StandTable.GRC[i];
153 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
156 if (pVBInfo->ModeType > ModeVGA) {
157 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
158 GRdata &= 0xBF; /* 256 color disable */
159 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
163 static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
165 unsigned short i;
167 for (i = 0x0A; i <= 0x0E; i++)
168 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
171 static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
174 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
175 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
176 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
178 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
179 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
180 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
182 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
183 return 0;
186 static unsigned char XGI_AjustCRT2Rate(unsigned short ModeIdIndex,
187 unsigned short RefreshRateTableIndex, unsigned short *i,
188 struct vb_device_info *pVBInfo)
190 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
192 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
193 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
194 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
195 tempax = 0;
197 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
198 tempax |= SupportRAMDAC2;
200 if (pVBInfo->VBType & VB_XGI301C)
201 tempax |= SupportCRT2in301C;
204 /* 301b */
205 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
206 tempax |= SupportLCD;
208 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
209 pVBInfo->LCDResInfo != Panel_1280x960 &&
210 (pVBInfo->LCDInfo & LCDNonExpanding) &&
211 resinfo >= 9)
212 return 0;
215 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
216 tempax |= SupportHiVision;
217 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
218 ((resinfo == 4) ||
219 (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
220 (resinfo > 7)))
221 return 0;
222 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
223 SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
224 SetCRT2ToHiVision)) {
225 tempax |= SupportTV;
227 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
228 VB_SIS302LV | VB_XGI301C))
229 tempax |= SupportTV1024;
231 if (!(pVBInfo->VBInfo & TVSetPAL) &&
232 (modeflag & NoSupportSimuTV) &&
233 (pVBInfo->VBInfo & SetInSlaveMode) &&
234 (!(pVBInfo->VBInfo & SetNotSimuMode)))
235 return 0;
238 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
239 tempbx; (*i)--) {
240 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
241 Ext_InfoFlag;
242 if (infoflag & tempax)
243 return 1;
245 if ((*i) == 0)
246 break;
249 for ((*i) = 0;; (*i)++) {
250 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
251 Ext_InfoFlag;
252 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
253 != tempbx) {
254 return 0;
257 if (infoflag & tempax)
258 return 1;
260 return 1;
263 static void XGI_SetSync(unsigned short RefreshRateTableIndex,
264 struct vb_device_info *pVBInfo)
266 unsigned short sync, temp;
268 /* di+0x00 */
269 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
270 sync &= 0xC0;
271 temp = 0x2F;
272 temp |= sync;
273 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
276 static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
277 struct xgi_hw_device_info *HwDeviceExtension)
279 unsigned char data, data1, pushax;
280 unsigned short i, j;
282 /* unlock cr0-7 */
283 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
284 data &= 0x7F;
285 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
287 data = pVBInfo->TimingH.data[0];
288 xgifb_reg_set(pVBInfo->P3d4, 0, data);
290 for (i = 0x01; i <= 0x04; i++) {
291 data = pVBInfo->TimingH.data[i];
292 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
295 for (i = 0x05; i <= 0x06; i++) {
296 data = pVBInfo->TimingH.data[i];
297 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
300 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
301 j &= 0x1F;
302 data = pVBInfo->TimingH.data[7];
303 data &= 0xE0;
304 data |= j;
305 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
307 if (HwDeviceExtension->jChipType >= XG20) {
308 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
309 data = data - 1;
310 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
311 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
312 data1 = data;
313 data1 &= 0xE0;
314 data &= 0x1F;
315 if (data == 0) {
316 pushax = data;
317 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
318 data &= 0xFB;
319 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
320 data = pushax;
322 data = data - 1;
323 data |= data1;
324 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
325 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
326 data = data >> 5;
327 data = data + 3;
328 if (data > 7)
329 data = data - 7;
330 data = data << 5;
331 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
335 static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
336 struct vb_device_info *pVBInfo)
338 unsigned char data;
339 unsigned short i, j;
341 for (i = 0x00; i <= 0x01; i++) {
342 data = pVBInfo->TimingV.data[i];
343 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
346 for (i = 0x02; i <= 0x03; i++) {
347 data = pVBInfo->TimingV.data[i];
348 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
351 for (i = 0x04; i <= 0x05; i++) {
352 data = pVBInfo->TimingV.data[i];
353 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
356 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
357 j &= 0xC0;
358 data = pVBInfo->TimingV.data[6];
359 data &= 0x3F;
360 data |= j;
361 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
363 data = pVBInfo->TimingV.data[6];
364 data &= 0x80;
365 data = data >> 2;
367 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
368 i &= DoubleScanMode;
369 if (i)
370 data |= 0x80;
372 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
373 j &= 0x5F;
374 data |= j;
375 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
378 static void XGI_SetCRT1CRTC(unsigned short ModeIdIndex,
379 unsigned short RefreshRateTableIndex,
380 struct vb_device_info *pVBInfo,
381 struct xgi_hw_device_info *HwDeviceExtension)
383 unsigned char index, data;
384 unsigned short i;
386 /* Get index */
387 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
388 index = index & IndexMask;
390 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
391 data &= 0x7F;
392 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
394 for (i = 0; i < 8; i++)
395 pVBInfo->TimingH.data[i]
396 = XGI_CRT1Table[index].CR[i];
398 for (i = 0; i < 7; i++)
399 pVBInfo->TimingV.data[i]
400 = XGI_CRT1Table[index].CR[i + 8];
402 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
404 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
406 if (pVBInfo->ModeType > 0x03)
407 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
410 /* --------------------------------------------------------------------- */
411 /* Function : XGI_SetXG21CRTC */
412 /* Input : Stand or enhance CRTC table */
413 /* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
414 /* Description : Set LCD timing */
415 /* --------------------------------------------------------------------- */
416 static void XGI_SetXG21CRTC(unsigned short RefreshRateTableIndex,
417 struct vb_device_info *pVBInfo)
419 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
420 unsigned short Temp1, Temp2, Temp3;
422 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
423 /* Tempax: CR4 HRS */
424 Tempax = XGI_CRT1Table[index].CR[3];
425 Tempcx = Tempax; /* Tempcx: HRS */
426 /* SR2E[7:0]->HRS */
427 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
429 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
430 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
431 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
432 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
433 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
435 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
436 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
438 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
439 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
440 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
441 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
443 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
444 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
446 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
447 if (Tempax < Tempcx) /* HRE < HRS */
448 Temp2 |= 0x40; /* Temp2 + 0x40 */
450 Temp2 &= 0xFF;
451 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
452 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
453 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
454 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
455 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
456 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
457 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
459 /* CR10 VRS */
460 Tempax = XGI_CRT1Table[index].CR[10];
461 Tempbx = Tempax; /* Tempbx: VRS */
462 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
463 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
464 /* CR7[2][7] VRE */
465 Tempax = XGI_CRT1Table[index].CR[9];
466 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
467 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
468 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
469 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
470 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
472 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
473 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
474 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
475 Tempax &= 0x80;
476 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
477 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
478 /* Tempax: SRA */
479 Tempax = XGI_CRT1Table[index].CR[14];
480 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
481 Temp2 = Tempax;
482 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
483 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
485 /* Tempax: CR11 VRE */
486 Tempax = XGI_CRT1Table[index].CR[11];
487 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
488 /* Tempbx: SRA */
489 Tempbx = XGI_CRT1Table[index].CR[14];
490 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
491 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
492 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
493 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
494 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
496 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
497 if (Tempax < Temp3) /* VRE < VRS */
498 Temp2 |= 0x20; /* VRE + 0x20 */
500 Temp2 &= 0xFF;
501 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
502 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
503 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
504 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
505 Tempbx = (unsigned char) Temp1;
506 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
507 Tempax &= 0x7F;
508 /* SR3F D[7:2]->VRE D[1:0]->VRS */
509 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
512 static void XGI_SetXG27CRTC(unsigned short RefreshRateTableIndex,
513 struct vb_device_info *pVBInfo)
515 unsigned short index, Tempax, Tempbx, Tempcx;
517 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
518 /* Tempax: CR4 HRS */
519 Tempax = XGI_CRT1Table[index].CR[3];
520 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
521 /* SR2E[7:0]->HRS */
522 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
524 /* SR0B */
525 Tempax = XGI_CRT1Table[index].CR[5];
526 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
527 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
529 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
530 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
531 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
533 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
534 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
535 Tempax <<= 3; /* Tempax[5]: HRE[5] */
536 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
538 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
539 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
541 /* Tempax: CR4 HRS */
542 Tempax = XGI_CRT1Table[index].CR[3];
543 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
544 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
545 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
547 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
548 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
549 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
550 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
551 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
552 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
553 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
555 /* CR10 VRS */
556 Tempax = XGI_CRT1Table[index].CR[10];
557 /* SR34[7:0]->VRS[7:0] */
558 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
560 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
561 /* CR7[7][2] VRS[9][8] */
562 Tempax = XGI_CRT1Table[index].CR[9];
563 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
564 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
565 Tempax >>= 2; /* Tempax[0]: VRS[8] */
566 /* SR35[0]: VRS[8] */
567 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
568 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
569 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
570 /* Tempax: SR0A */
571 Tempax = XGI_CRT1Table[index].CR[14];
572 Tempax &= 0x08; /* SR0A[3] VRS[10] */
573 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
575 /* Tempax: CR11 VRE */
576 Tempax = XGI_CRT1Table[index].CR[11];
577 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
578 /* Tempbx: SR0A */
579 Tempbx = XGI_CRT1Table[index].CR[14];
580 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
581 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
582 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
583 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
584 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
585 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
587 if (Tempbx <= Tempcx) /* VRE <= VRS */
588 Tempbx |= 0x20; /* VRE + 0x20 */
590 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
591 Tempax = (Tempbx << 2) & 0xFF;
592 /* SR3F[7:2]:VRE[5:0] */
593 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
594 Tempax = Tempcx >> 8;
595 /* SR35[2:0]:VRS[10:8] */
596 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
599 static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
601 unsigned char temp;
603 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
604 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
605 temp = (temp & 3) << 6;
606 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
607 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
608 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
609 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
613 static void xgifb_set_lcd(int chip_id,
614 struct vb_device_info *pVBInfo,
615 unsigned short RefreshRateTableIndex)
617 unsigned short temp;
619 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
620 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
621 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
622 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
624 if (chip_id == XG27) {
625 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
626 if ((temp & 0x03) == 0) { /* dual 12 */
627 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
628 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
632 if (chip_id == XG27) {
633 XGI_SetXG27FPBits(pVBInfo);
634 } else {
635 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
636 if (temp & 0x01) {
637 /* 18 bits FP */
638 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
639 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
643 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
645 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
646 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
648 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
649 if (temp & 0x4000)
650 /* Hsync polarity */
651 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
652 if (temp & 0x8000)
653 /* Vsync polarity */
654 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
657 /* --------------------------------------------------------------------- */
658 /* Function : XGI_UpdateXG21CRTC */
659 /* Input : */
660 /* Output : CRT1 CRTC */
661 /* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
662 /* --------------------------------------------------------------------- */
663 static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
664 struct vb_device_info *pVBInfo,
665 unsigned short RefreshRateTableIndex)
667 int index = -1;
669 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
670 if (ModeNo == 0x2E &&
671 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
672 RES640x480x60))
673 index = 12;
674 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
675 Ext_CRT1CRTC == RES640x480x72))
676 index = 13;
677 else if (ModeNo == 0x2F)
678 index = 14;
679 else if (ModeNo == 0x50)
680 index = 15;
681 else if (ModeNo == 0x59)
682 index = 16;
684 if (index != -1) {
685 xgifb_reg_set(pVBInfo->P3d4, 0x02,
686 XGI_UpdateCRT1Table[index].CR02);
687 xgifb_reg_set(pVBInfo->P3d4, 0x03,
688 XGI_UpdateCRT1Table[index].CR03);
689 xgifb_reg_set(pVBInfo->P3d4, 0x15,
690 XGI_UpdateCRT1Table[index].CR15);
691 xgifb_reg_set(pVBInfo->P3d4, 0x16,
692 XGI_UpdateCRT1Table[index].CR16);
696 static void XGI_SetCRT1DE(unsigned short ModeIdIndex,
697 unsigned short RefreshRateTableIndex,
698 struct vb_device_info *pVBInfo)
700 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
702 unsigned char data;
704 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
706 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
707 tempax = XGI330_ModeResInfo[resindex].HTotal;
708 tempbx = XGI330_ModeResInfo[resindex].VTotal;
710 if (modeflag & HalfDCLK)
711 tempax = tempax >> 1;
713 if (modeflag & HalfDCLK)
714 tempax = tempax << 1;
716 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
718 if (temp & InterlaceMode)
719 tempbx = tempbx >> 1;
721 if (modeflag & DoubleScanMode)
722 tempbx = tempbx << 1;
724 tempcx = 8;
726 tempax /= tempcx;
727 tempax -= 1;
728 tempbx -= 1;
729 tempcx = tempax;
730 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
731 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
732 data &= 0x7F;
733 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
734 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
735 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
736 (unsigned short) ((tempcx & 0x0ff00) >> 10));
737 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
738 tempax = 0;
739 tempbx = tempbx >> 8;
741 if (tempbx & 0x01)
742 tempax |= 0x02;
744 if (tempbx & 0x02)
745 tempax |= 0x40;
747 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
748 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
749 tempax = 0;
751 if (tempbx & 0x04)
752 tempax |= 0x02;
754 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
755 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
758 static void XGI_SetCRT1Offset(unsigned short ModeNo,
759 unsigned short ModeIdIndex,
760 unsigned short RefreshRateTableIndex,
761 struct xgi_hw_device_info *HwDeviceExtension,
762 struct vb_device_info *pVBInfo)
764 unsigned short temp, ah, al, temp2, i, DisplayUnit;
766 /* GetOffset */
767 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
768 temp = temp >> 8;
769 temp = XGI330_ScreenOffset[temp];
771 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
772 temp2 &= InterlaceMode;
774 if (temp2)
775 temp = temp << 1;
777 temp2 = pVBInfo->ModeType - ModeEGA;
779 switch (temp2) {
780 case 0:
781 temp2 = 1;
782 break;
783 case 1:
784 temp2 = 2;
785 break;
786 case 2:
787 temp2 = 4;
788 break;
789 case 3:
790 temp2 = 4;
791 break;
792 case 4:
793 temp2 = 6;
794 break;
795 case 5:
796 temp2 = 8;
797 break;
798 default:
799 break;
802 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
803 temp = temp * temp2 + temp2 / 2;
804 else
805 temp *= temp2;
807 /* SetOffset */
808 DisplayUnit = temp;
809 temp2 = temp;
810 temp = temp >> 8; /* ah */
811 temp &= 0x0F;
812 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
813 i &= 0xF0;
814 i |= temp;
815 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
817 temp = (unsigned char) temp2;
818 temp &= 0xFF; /* al */
819 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
821 /* SetDisplayUnit */
822 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
823 temp2 &= InterlaceMode;
824 if (temp2)
825 DisplayUnit >>= 1;
827 DisplayUnit = DisplayUnit << 5;
828 ah = (DisplayUnit & 0xff00) >> 8;
829 al = DisplayUnit & 0x00ff;
830 if (al == 0)
831 ah += 1;
832 else
833 ah += 2;
835 if (HwDeviceExtension->jChipType >= XG20)
836 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
837 ah -= 1;
839 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
842 static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeIdIndex,
843 unsigned short RefreshRateTableIndex,
844 struct vb_device_info *pVBInfo)
846 unsigned short VCLKIndex, modeflag;
848 /* si+Ext_ResInfo */
849 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
851 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
852 if (pVBInfo->LCDResInfo != Panel_1024x768)
853 /* LCDXlat2VCLK */
854 VCLKIndex = VCLK108_2_315 + 5;
855 else
856 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
857 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
858 if (pVBInfo->SetFlag & RPLLDIV2XO)
859 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
860 else
861 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
863 if (pVBInfo->SetFlag & TVSimuMode) {
864 if (modeflag & Charx8Dot)
865 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
866 else
867 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
870 /* 301lv */
871 if (pVBInfo->VBType & VB_SIS301LV) {
872 if (pVBInfo->SetFlag & RPLLDIV2XO)
873 VCLKIndex = YPbPr525iVCLK_2;
874 else
875 VCLKIndex = YPbPr525iVCLK;
877 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
878 if (pVBInfo->SetFlag & RPLLDIV2XO)
879 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
880 else
881 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
882 } else { /* for CRT2 */
883 /* di+Ext_CRTVCLK */
884 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
885 VCLKIndex &= IndexMask;
888 return VCLKIndex;
891 static void XGI_SetCRT1VCLK(unsigned short ModeIdIndex,
892 struct xgi_hw_device_info *HwDeviceExtension,
893 unsigned short RefreshRateTableIndex,
894 struct vb_device_info *pVBInfo)
896 unsigned char index, data;
897 unsigned short vclkindex;
899 if ((pVBInfo->IF_DEF_LVDS == 0) &&
900 (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
901 VB_SIS302LV | VB_XGI301C)) &&
902 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
903 vclkindex = XGI_GetVCLK2Ptr(ModeIdIndex, RefreshRateTableIndex,
904 pVBInfo);
905 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
906 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
907 data = XGI_VBVCLKData[vclkindex].Part4_A;
908 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
909 data = XGI_VBVCLKData[vclkindex].Part4_B;
910 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
911 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
912 } else {
913 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
914 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
915 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
916 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
917 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
918 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
921 if (HwDeviceExtension->jChipType >= XG20) {
922 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
923 HalfDCLK) {
924 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
925 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
926 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
927 index = data;
928 index &= 0xE0;
929 data &= 0x1F;
930 data = data << 1;
931 data += 1;
932 data |= index;
933 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
938 static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
940 unsigned char temp;
942 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
943 temp = (temp & 1) << 6;
944 /* SR06[6] 18bit Dither */
945 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
946 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
947 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
951 static void XGI_SetCRT1FIFO(struct xgi_hw_device_info *HwDeviceExtension,
952 struct vb_device_info *pVBInfo)
954 unsigned short data;
956 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
957 data &= 0xfe;
958 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* disable auto-threshold */
960 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
961 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
962 data &= 0xC0;
963 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
964 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
965 data |= 0x01;
966 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
968 if (HwDeviceExtension->jChipType == XG21)
969 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
972 static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
973 unsigned short RefreshRateTableIndex,
974 struct vb_device_info *pVBInfo)
976 unsigned short data, data2 = 0;
977 short VCLK;
979 unsigned char index;
981 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
982 index &= IndexMask;
983 VCLK = XGI_VCLKData[index].CLOCK;
985 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
986 data &= 0xf3;
987 if (VCLK >= 200)
988 data |= 0x0c; /* VCLK > 200 */
990 if (HwDeviceExtension->jChipType >= XG20)
991 data &= ~0x04; /* 2 pixel mode */
993 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
995 if (HwDeviceExtension->jChipType < XG20) {
996 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
997 data &= 0xE7;
998 if (VCLK < 200)
999 data |= 0x10;
1000 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
1003 data2 = 0x00;
1005 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
1006 if (HwDeviceExtension->jChipType >= XG27)
1007 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
1011 static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
1012 unsigned short ModeIdIndex,
1013 unsigned short RefreshRateTableIndex,
1014 struct vb_device_info *pVBInfo)
1016 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1017 xres;
1019 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1020 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1022 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
1023 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
1025 data = infoflag;
1026 data2 = 0;
1027 data2 |= 0x02;
1028 data3 = pVBInfo->ModeType - ModeVGA;
1029 data3 = data3 << 2;
1030 data2 |= data3;
1031 data &= InterlaceMode;
1033 if (data)
1034 data2 |= 0x20;
1036 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
1037 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
1038 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
1040 data = 0x0000;
1041 if (infoflag & InterlaceMode) {
1042 if (xres == 1024)
1043 data = 0x0035;
1044 else if (xres == 1280)
1045 data = 0x0048;
1048 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1049 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
1051 if (modeflag & HalfDCLK)
1052 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
1054 data2 = 0;
1056 if (modeflag & LineCompareOff)
1057 data2 |= 0x08;
1059 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
1060 data = 0x60;
1061 data = data ^ 0x60;
1062 data = data ^ 0xA0;
1063 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
1065 XGI_SetVCLKState(HwDeviceExtension, RefreshRateTableIndex, pVBInfo);
1067 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1069 if (HwDeviceExtension->jChipType == XG27) {
1070 if (data & 0x40)
1071 data = 0x2c;
1072 else
1073 data = 0x6c;
1074 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1075 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
1076 } else if (HwDeviceExtension->jChipType >= XG20) {
1077 if (data & 0x40)
1078 data = 0x33;
1079 else
1080 data = 0x73;
1081 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1082 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
1083 } else {
1084 if (data & 0x40)
1085 data = 0x2c;
1086 else
1087 data = 0x6c;
1088 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1093 static void XGI_WriteDAC(unsigned short dl,
1094 unsigned short ah,
1095 unsigned short al,
1096 unsigned short dh,
1097 struct vb_device_info *pVBInfo)
1099 unsigned short temp, bh, bl;
1101 bh = ah;
1102 bl = al;
1104 if (dl != 0) {
1105 temp = bh;
1106 bh = dh;
1107 dh = temp;
1108 if (dl == 1) {
1109 temp = bl;
1110 bl = dh;
1111 dh = temp;
1112 } else {
1113 temp = bl;
1114 bl = bh;
1115 bh = temp;
1118 outb((unsigned short) dh, pVBInfo->P3c9);
1119 outb((unsigned short) bh, pVBInfo->P3c9);
1120 outb((unsigned short) bl, pVBInfo->P3c9);
1123 static void XGI_LoadDAC(struct vb_device_info *pVBInfo)
1125 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1126 const unsigned short *table = XGINew_VGA_DAC;
1128 outb(0xFF, pVBInfo->P3c6);
1129 outb(0x00, pVBInfo->P3c8);
1131 for (i = 0; i < 16; i++) {
1132 data = table[i];
1134 for (k = 0; k < 3; k++) {
1135 data2 = 0;
1137 if (data & 0x01)
1138 data2 = 0x2A;
1140 if (data & 0x02)
1141 data2 += 0x15;
1143 outb(data2, pVBInfo->P3c9);
1144 data = data >> 2;
1148 for (i = 16; i < 32; i++) {
1149 data = table[i];
1151 for (k = 0; k < 3; k++)
1152 outb(data, pVBInfo->P3c9);
1155 si = 32;
1157 for (m = 0; m < 9; m++) {
1158 di = si;
1159 bx = si + 0x04;
1160 dl = 0;
1162 for (n = 0; n < 3; n++) {
1163 for (o = 0; o < 5; o++) {
1164 dh = table[si];
1165 ah = table[di];
1166 al = table[bx];
1167 si++;
1168 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1171 si -= 2;
1173 for (o = 0; o < 3; o++) {
1174 dh = table[bx];
1175 ah = table[di];
1176 al = table[si];
1177 si--;
1178 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1181 dl++;
1184 si += 5;
1188 static void XGI_GetLVDSResInfo(unsigned short ModeIdIndex,
1189 struct vb_device_info *pVBInfo)
1191 unsigned short resindex, xres, yres, modeflag;
1193 /* si+Ext_ResInfo */
1194 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
1196 /* si+Ext_ResInfo */
1197 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
1199 xres = XGI330_ModeResInfo[resindex].HTotal;
1200 yres = XGI330_ModeResInfo[resindex].VTotal;
1202 if (modeflag & HalfDCLK)
1203 xres = xres << 1;
1205 if (modeflag & DoubleScanMode)
1206 yres = yres << 1;
1208 if (xres == 720)
1209 xres = 640;
1211 pVBInfo->VGAHDE = xres;
1212 pVBInfo->HDE = xres;
1213 pVBInfo->VGAVDE = yres;
1214 pVBInfo->VDE = yres;
1217 static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
1218 unsigned short ModeIdIndex,
1219 struct vb_device_info *pVBInfo)
1221 unsigned short i, tempdx, tempbx, modeflag;
1223 tempbx = 0;
1225 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1227 i = 0;
1229 while (table[i].PANELID != 0xff) {
1230 tempdx = pVBInfo->LCDResInfo;
1231 if (tempbx & 0x0080) { /* OEMUtil */
1232 tempbx &= (~0x0080);
1233 tempdx = pVBInfo->LCDTypeInfo;
1236 if (pVBInfo->LCDInfo & EnableScalingLCD)
1237 tempdx &= (~PanelResInfo);
1239 if (table[i].PANELID == tempdx) {
1240 tempbx = table[i].MASK;
1241 tempdx = pVBInfo->LCDInfo;
1243 if (modeflag & HalfDCLK)
1244 tempdx |= SetLCDLowResolution;
1246 tempbx &= tempdx;
1247 if (tempbx == table[i].CAP)
1248 break;
1250 i++;
1253 return table[i].DATAPTR;
1256 static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex,
1257 unsigned short RefreshRateTableIndex,
1258 struct vb_device_info *pVBInfo)
1260 unsigned short i, tempdx, tempal, modeflag;
1262 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1263 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1264 tempal = tempal & 0x3f;
1265 tempdx = pVBInfo->TVInfo;
1267 if (pVBInfo->VBInfo & SetInSlaveMode)
1268 tempdx = tempdx | SetTVLockMode;
1270 if (modeflag & HalfDCLK)
1271 tempdx = tempdx | SetTVLowResolution;
1273 i = 0;
1275 while (XGI_TVDataTable[i].MASK != 0xffff) {
1276 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1277 XGI_TVDataTable[i].CAP)
1278 break;
1279 i++;
1282 return &XGI_TVDataTable[i].DATAPTR[tempal];
1285 static void XGI_GetLVDSData(unsigned short ModeIdIndex,
1286 struct vb_device_info *pVBInfo)
1288 struct SiS_LVDSData const *LCDPtr;
1290 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1291 return;
1293 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeIdIndex, pVBInfo);
1294 pVBInfo->VGAHT = LCDPtr->VGAHT;
1295 pVBInfo->VGAVT = LCDPtr->VGAVT;
1296 pVBInfo->HT = LCDPtr->LCDHT;
1297 pVBInfo->VT = LCDPtr->LCDVT;
1299 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1300 return;
1302 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1303 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1304 pVBInfo->HDE = 1024;
1305 pVBInfo->VDE = 768;
1306 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1307 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1308 pVBInfo->HDE = 1280;
1309 pVBInfo->VDE = 1024;
1310 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1311 pVBInfo->HDE = 1400;
1312 pVBInfo->VDE = 1050;
1313 } else {
1314 pVBInfo->HDE = 1600;
1315 pVBInfo->VDE = 1200;
1319 static void XGI_ModCRT1Regs(unsigned short ModeIdIndex,
1320 struct xgi_hw_device_info *HwDeviceExtension,
1321 struct vb_device_info *pVBInfo)
1323 unsigned short i;
1324 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1325 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
1327 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
1328 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeIdIndex,
1329 pVBInfo);
1331 for (i = 0; i < 8; i++)
1332 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
1335 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1337 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
1338 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeIdIndex,
1339 pVBInfo);
1340 for (i = 0; i < 7; i++)
1341 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
1344 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
1347 static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1349 unsigned char tempal, tempah, tempbl, i;
1351 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
1352 tempal = tempah & 0x0F;
1353 tempah = tempah & 0xF0;
1354 i = 0;
1355 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1357 while (tempbl != 0xFF) {
1358 if (tempbl & 0x80) { /* OEMUtil */
1359 tempal = tempah;
1360 tempbl = tempbl & ~(0x80);
1363 if (tempal == tempbl)
1364 break;
1366 i++;
1368 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1371 return i;
1374 static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1376 unsigned short tempah, tempal, tempbl, i;
1378 tempal = pVBInfo->LCDResInfo;
1379 tempah = pVBInfo->LCDTypeInfo;
1381 i = 0;
1382 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1384 while (tempbl != 0xFF) {
1385 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1386 tempal = tempah;
1387 tempbl &= ~0x80;
1390 if (tempal == tempbl)
1391 break;
1393 i++;
1394 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1397 if (tempbl == 0xFF) {
1398 pVBInfo->LCDResInfo = Panel_1024x768;
1399 pVBInfo->LCDTypeInfo = 0;
1400 i = 0;
1403 return i;
1406 static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1407 unsigned short *VSyncWidth,
1408 struct vb_device_info *pVBInfo)
1410 unsigned short Index;
1412 Index = XGI_GetLCDCapPtr(pVBInfo);
1413 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1414 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1417 static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
1418 struct vb_device_info *pVBInfo)
1420 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1421 unsigned long temp, temp1, temp2, temp3, push3;
1422 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
1424 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1425 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeIdIndex, pVBInfo);
1427 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1428 push1 = tempbx;
1429 push2 = tempax;
1431 /* GetLCDResInfo */
1432 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1433 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1434 tempax = 1024;
1435 tempbx = 768;
1436 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1437 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1438 tempax = 1280;
1439 tempbx = 1024;
1440 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1441 tempax = 1400;
1442 tempbx = 1050;
1443 } else {
1444 tempax = 1600;
1445 tempbx = 1200;
1448 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1449 pVBInfo->HDE = tempax;
1450 pVBInfo->VDE = tempbx;
1451 pVBInfo->VGAHDE = tempax;
1452 pVBInfo->VGAVDE = tempbx;
1455 tempax = pVBInfo->HT;
1457 tempbx = LCDPtr1->LCDHDES;
1459 tempcx = pVBInfo->HDE;
1460 tempbx = tempbx & 0x0fff;
1461 tempcx += tempbx;
1463 if (tempcx >= tempax)
1464 tempcx -= tempax;
1466 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
1468 tempcx = tempcx >> 3;
1469 tempbx = tempbx >> 3;
1471 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1472 (unsigned short) (tempbx & 0xff));
1473 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1474 (unsigned short) (tempcx & 0xff));
1476 tempax = pVBInfo->HT;
1478 tempbx = LCDPtr1->LCDHRS;
1480 tempcx = push2;
1482 if (pVBInfo->LCDInfo & EnableScalingLCD)
1483 tempcx = LCDPtr1->LCDHSync;
1485 tempcx += tempbx;
1487 if (tempcx >= tempax)
1488 tempcx -= tempax;
1490 tempax = tempbx & 0x07;
1491 tempax = tempax >> 5;
1492 tempcx = tempcx >> 3;
1493 tempbx = tempbx >> 3;
1495 tempcx &= 0x1f;
1496 tempax |= tempcx;
1498 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1499 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1500 (unsigned short) (tempbx & 0xff));
1502 tempax = pVBInfo->VT;
1503 tempbx = LCDPtr1->LCDVDES;
1504 tempcx = pVBInfo->VDE;
1506 tempbx = tempbx & 0x0fff;
1507 tempcx += tempbx;
1508 if (tempcx >= tempax)
1509 tempcx -= tempax;
1511 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1512 (unsigned short) (tempbx & 0xff));
1513 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1514 (unsigned short) (tempcx & 0xff));
1516 tempbx = (tempbx >> 8) & 0x07;
1517 tempcx = (tempcx >> 8) & 0x07;
1519 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1520 (unsigned short) ((tempcx << 3)
1521 | tempbx));
1523 tempax = pVBInfo->VT;
1524 tempbx = LCDPtr1->LCDVRS;
1526 tempcx = push1;
1528 if (pVBInfo->LCDInfo & EnableScalingLCD)
1529 tempcx = LCDPtr1->LCDVSync;
1531 tempcx += tempbx;
1532 if (tempcx >= tempax)
1533 tempcx -= tempax;
1535 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1536 (unsigned short) (tempbx & 0xff));
1537 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1538 (unsigned short) (tempcx & 0x0f));
1540 tempax = ((tempbx >> 8) & 0x07) << 3;
1542 tempbx = pVBInfo->VGAVDE;
1543 if (tempbx != pVBInfo->VDE)
1544 tempax |= 0x40;
1546 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
1547 tempax |= 0x40;
1549 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1550 tempax);
1552 tempbx = pVBInfo->VDE;
1553 tempax = pVBInfo->VGAVDE;
1555 temp = tempax; /* 0430 ylshieh */
1556 temp1 = (temp << 18) / tempbx;
1558 tempdx = (unsigned short) ((temp << 18) % tempbx);
1560 if (tempdx != 0)
1561 temp1 += 1;
1563 temp2 = temp1;
1564 push3 = temp2;
1566 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1567 (unsigned short) (temp2 & 0xff));
1568 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1569 (unsigned short) ((temp2 >> 8) & 0xff));
1571 tempbx = (unsigned short) (temp2 >> 16);
1572 tempax = tempbx & 0x03;
1574 tempbx = pVBInfo->VGAVDE;
1575 if (tempbx == pVBInfo->VDE)
1576 tempax |= 0x04;
1578 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1580 if (pVBInfo->VBType & VB_XGI301C) {
1581 temp2 = push3;
1582 xgifb_reg_set(pVBInfo->Part4Port,
1583 0x3c,
1584 (unsigned short) (temp2 & 0xff));
1585 xgifb_reg_set(pVBInfo->Part4Port,
1586 0x3b,
1587 (unsigned short) ((temp2 >> 8) &
1588 0xff));
1589 tempbx = (unsigned short) (temp2 >> 16);
1590 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1591 ~0xc0,
1592 (unsigned short) ((tempbx &
1593 0xff) << 6));
1595 tempcx = pVBInfo->VGAVDE;
1596 if (tempcx == pVBInfo->VDE)
1597 xgifb_reg_and_or(pVBInfo->Part4Port,
1598 0x30, ~0x0c, 0x00);
1599 else
1600 xgifb_reg_and_or(pVBInfo->Part4Port,
1601 0x30, ~0x0c, 0x08);
1604 tempcx = pVBInfo->VGAHDE;
1605 tempbx = pVBInfo->HDE;
1607 temp1 = tempcx << 16;
1609 tempax = (unsigned short) (temp1 / tempbx);
1611 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1612 tempax = 65535;
1614 temp3 = tempax;
1615 temp1 = pVBInfo->VGAHDE << 16;
1617 temp1 /= temp3;
1618 temp3 = temp3 << 16;
1619 temp1 -= 1;
1621 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1623 tempax = (unsigned short) (temp3 & 0xff);
1624 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1626 temp1 = pVBInfo->VGAVDE << 18;
1627 temp1 = temp1 / push3;
1628 tempbx = (unsigned short) (temp1 & 0xffff);
1630 if (pVBInfo->LCDResInfo == Panel_1024x768)
1631 tempbx -= 1;
1633 tempax = ((tempbx >> 8) & 0xff) << 3;
1634 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1635 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1636 (unsigned short) (tempax & 0xff));
1637 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1638 (unsigned short) (tempbx & 0xff));
1640 temp3 = temp3 >> 16;
1642 if (modeflag & HalfDCLK)
1643 temp3 = temp3 >> 1;
1645 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1646 (unsigned short) ((temp3 >> 8) & 0xff));
1647 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1648 (unsigned short) (temp3 & 0xff));
1651 /* --------------------------------------------------------------------- */
1652 /* Function : XGI_GETLCDVCLKPtr */
1653 /* Input : */
1654 /* Output : al -> VCLK Index */
1655 /* Description : */
1656 /* --------------------------------------------------------------------- */
1657 static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1658 struct vb_device_info *pVBInfo)
1660 unsigned short index;
1662 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
1663 index = XGI_GetLCDCapPtr1(pVBInfo);
1665 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1666 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1667 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1668 } else { /* LCDA */
1669 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1670 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1675 static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1676 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
1679 unsigned short index, modeflag;
1680 unsigned char tempal;
1682 /* si+Ext_ResInfo */
1683 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1685 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1686 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
1687 index = XGI_GetLCDCapPtr(pVBInfo);
1688 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1690 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
1691 return tempal;
1693 /* {TV} */
1694 if (pVBInfo->VBType &
1695 (VB_SIS301B |
1696 VB_SIS302B |
1697 VB_SIS301LV |
1698 VB_SIS302LV |
1699 VB_XGI301C)) {
1700 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
1701 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
1702 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
1703 tempal = TVCLKBASE_315 + HiTVVCLK;
1704 if (pVBInfo->TVInfo & TVSimuMode) {
1705 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
1706 if (!(modeflag & Charx8Dot))
1707 tempal = TVCLKBASE_315 +
1708 HiTVTextVCLK;
1711 return tempal;
1714 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
1715 tempal = XGI_YPbPr750pVCLK;
1716 return tempal;
1719 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
1720 tempal = YPbPr525pVCLK;
1721 return tempal;
1724 tempal = NTSC1024VCLK;
1726 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
1727 tempal = TVCLKBASE_315 + TVVCLKDIV2;
1728 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
1729 tempal = TVCLKBASE_315 + TVVCLK;
1732 if (pVBInfo->VBInfo & SetCRT2ToTV)
1733 return tempal;
1735 } /* {End of VB} */
1737 inb((pVBInfo->P3ca + 0x02));
1738 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1739 return tempal;
1742 static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1743 unsigned char *di_1, struct vb_device_info *pVBInfo)
1745 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1746 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
1747 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1748 (pVBInfo->SetFlag & ProgrammingCRT2)) {
1749 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
1750 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
1752 } else {
1753 *di_0 = XGI_VCLKData[tempal].SR2B;
1754 *di_1 = XGI_VCLKData[tempal].SR2C;
1758 static void XGI_SetCRT2ECLK(unsigned short ModeIdIndex,
1759 unsigned short RefreshRateTableIndex,
1760 struct vb_device_info *pVBInfo)
1762 unsigned char di_0, di_1, tempal;
1763 int i;
1765 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
1766 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1767 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
1769 for (i = 0; i < 4; i++) {
1770 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
1771 (unsigned short) (0x10 * i));
1772 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
1773 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
1774 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1775 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
1776 } else {
1777 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1778 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
1783 static void XGI_UpdateModeInfo(struct vb_device_info *pVBInfo)
1785 unsigned short tempcl, tempch, temp, tempbl, tempax;
1787 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1788 | VB_SIS302LV | VB_XGI301C)) {
1789 tempcl = 0;
1790 tempch = 0;
1791 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
1793 if (!(temp & 0x20)) {
1794 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
1795 if (temp & 0x80) {
1796 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
1797 if (!(temp & 0x40))
1798 tempcl |= ActiveCRT1;
1802 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
1803 temp &= 0x0f;
1805 if (!(temp == 0x08)) {
1806 /* Check ChannelA */
1807 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
1808 if (tempax & 0x04)
1809 tempcl = tempcl | ActiveLCD;
1811 temp &= 0x05;
1813 if (!(tempcl & ActiveLCD))
1814 if (temp == 0x01)
1815 tempcl |= ActiveCRT2;
1817 if (temp == 0x04)
1818 tempcl |= ActiveLCD;
1820 if (temp == 0x05) {
1821 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
1823 if (!(temp & 0x08))
1824 tempch |= ActiveAVideo;
1826 if (!(temp & 0x04))
1827 tempch |= ActiveSVideo;
1829 if (temp & 0x02)
1830 tempch |= ActiveSCART;
1832 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
1833 if (temp & 0x01)
1834 tempch |= ActiveHiTV;
1837 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
1838 temp = xgifb_reg_get(
1839 pVBInfo->Part2Port,
1840 0x4d);
1842 if (temp & 0x10)
1843 tempch |= ActiveYPbPr;
1846 if (tempch != 0)
1847 tempcl |= ActiveTV;
1851 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
1852 if (tempcl & ActiveLCD) {
1853 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1854 if (temp & ActiveTV)
1855 tempcl |= ActiveTV;
1858 temp = tempcl;
1859 tempbl = ~XGI_ModeSwitchStatus;
1860 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
1862 if (!(pVBInfo->SetFlag & ReserveTVOption))
1863 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
1867 void XGI_GetVBType(struct vb_device_info *pVBInfo)
1869 unsigned short flag, tempbx, tempah;
1871 tempbx = VB_SIS302B;
1872 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1873 if (flag == 0x02)
1874 goto finish;
1876 tempbx = VB_SIS301;
1877 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1878 if (flag < 0xB0)
1879 goto finish;
1881 tempbx = VB_SIS301B;
1882 if (flag < 0xC0)
1883 goto bigger_than_0xB0;
1885 tempbx = VB_XGI301C;
1886 if (flag < 0xD0)
1887 goto bigger_than_0xB0;
1889 tempbx = VB_SIS301LV;
1890 if (flag < 0xE0)
1891 goto bigger_than_0xB0;
1893 tempbx = VB_SIS302LV;
1894 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1895 if (tempah != 0xFF)
1896 tempbx = VB_XGI301C;
1898 bigger_than_0xB0:
1899 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1900 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1901 if (!(flag & 0x02))
1902 tempbx = tempbx | VB_NoLCD;
1905 finish:
1906 pVBInfo->VBType = tempbx;
1909 static void XGI_GetVBInfo(unsigned short ModeIdIndex,
1910 struct vb_device_info *pVBInfo)
1912 unsigned short tempax, push, tempbx, temp, modeflag;
1914 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1915 pVBInfo->SetFlag = 0;
1916 pVBInfo->ModeType = modeflag & ModeTypeMask;
1917 tempbx = 0;
1919 if (!(pVBInfo->VBType & 0xFFFF))
1920 return;
1922 /* Check Display Device */
1923 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1924 tempbx = tempbx | temp;
1925 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1926 push = temp;
1927 push = push << 8;
1928 tempax = temp << 8;
1929 tempbx = tempbx | tempax;
1930 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1931 | SetInSlaveMode | DisableCRT2Display);
1932 temp = 0xFFFF ^ temp;
1933 tempbx &= temp;
1935 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
1937 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1938 VB_XGI301C)) {
1939 if (temp & EnableDualEdge) {
1940 tempbx |= SetCRT2ToDualEdge;
1941 if (temp & SetToLCDA)
1942 tempbx |= XGI_SetCRT2ToLCDA;
1946 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
1947 if (temp & SetYPbPr) {
1948 /* shampoo add for new scratch */
1949 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
1950 temp &= YPbPrMode;
1951 tempbx |= SetCRT2ToHiVision;
1953 if (temp != YPbPrMode1080i) {
1954 tempbx &= (~SetCRT2ToHiVision);
1955 tempbx |= SetCRT2ToYPbPr525750;
1960 tempax = push; /* restore CR31 */
1962 temp = 0x09FC;
1964 if (!(tempbx & temp)) {
1965 tempax |= DisableCRT2Display;
1966 tempbx = 0;
1969 if (!(pVBInfo->VBType & VB_NoLCD)) {
1970 if (tempbx & XGI_SetCRT2ToLCDA) {
1971 if (tempbx & SetSimuScanMode)
1972 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1973 SwitchCRT2));
1974 else
1975 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1976 SetCRT2ToTV | SwitchCRT2));
1980 /* shampoo add */
1981 /* for driver abnormal */
1982 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
1983 if (tempbx & SetCRT2ToRAMDAC) {
1984 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
1985 SwitchCRT2 | SetSimuScanMode);
1986 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1990 if (!(pVBInfo->VBType & VB_NoLCD)) {
1991 if (tempbx & SetCRT2ToLCD) {
1992 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
1993 SetSimuScanMode);
1994 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1998 if (tempbx & SetCRT2ToSCART) {
1999 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
2000 SetSimuScanMode);
2001 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2004 if (tempbx & SetCRT2ToYPbPr525750)
2005 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
2007 if (tempbx & SetCRT2ToHiVision)
2008 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
2009 SetSimuScanMode);
2011 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2012 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2013 tempbx = DisableCRT2Display;
2016 if (!(tempbx & DisableCRT2Display)) {
2017 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
2018 if (!(tempbx & XGI_SetCRT2ToLCDA))
2019 tempbx |= (SetInSlaveMode | SetSimuScanMode);
2022 /* LCD+TV can't support in slave mode
2023 * (Force LCDA+TV->LCDB) */
2024 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2025 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
2026 SetCRT2ToDualEdge);
2027 pVBInfo->SetFlag |= ReserveTVOption;
2031 pVBInfo->VBInfo = tempbx;
2034 static void XGI_GetTVInfo(unsigned short ModeIdIndex,
2035 struct vb_device_info *pVBInfo)
2037 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
2039 if (pVBInfo->VBInfo & SetCRT2ToTV) {
2040 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2041 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2043 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2044 if (tempbx & TVSetPAL) {
2045 tempbx &= (SetCHTVOverScan |
2046 TVSetPALM |
2047 TVSetPALN |
2048 TVSetPAL);
2049 if (tempbx & TVSetPALM)
2050 /* set to NTSC if PAL-M */
2051 tempbx &= ~TVSetPAL;
2052 } else
2053 tempbx &= (SetCHTVOverScan |
2054 TVSetNTSCJ |
2055 TVSetPAL);
2057 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2058 tempbx |= TVSetPAL;
2060 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2061 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2062 index1 &= YPbPrMode;
2064 if (index1 == YPbPrMode525i)
2065 tempbx |= TVSetYPbPr525i;
2067 if (index1 == YPbPrMode525p)
2068 tempbx = tempbx | TVSetYPbPr525p;
2069 if (index1 == YPbPrMode750p)
2070 tempbx = tempbx | TVSetYPbPr750p;
2073 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2074 tempbx = tempbx | TVSetHiVision | TVSetPAL;
2076 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2077 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2078 tempbx |= TVSimuMode;
2080 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2081 /* NTSC 1024x768, */
2082 tempbx |= NTSC1024x768;
2084 tempbx |= RPLLDIV2XO;
2086 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2087 if (pVBInfo->VBInfo & SetInSlaveMode)
2088 tempbx &= (~RPLLDIV2XO);
2089 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2090 tempbx &= (~RPLLDIV2XO);
2091 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2092 VB_SIS301LV | VB_SIS302LV |
2093 VB_XGI301C))) {
2094 if (tempbx & TVSimuMode)
2095 tempbx &= (~RPLLDIV2XO);
2098 pVBInfo->TVInfo = tempbx;
2101 static unsigned char XGI_GetLCDInfo(unsigned short ModeIdIndex,
2102 struct vb_device_info *pVBInfo)
2104 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
2106 pVBInfo->LCDResInfo = 0;
2107 pVBInfo->LCDTypeInfo = 0;
2108 pVBInfo->LCDInfo = 0;
2110 /* si+Ext_ResInfo // */
2111 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2112 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
2113 tempbx = temp & 0x0F;
2115 if (tempbx == 0)
2116 tempbx = Panel_1024x768; /* default */
2118 /* LCD75 */
2119 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
2120 if (pVBInfo->VBInfo & DriverMode) {
2121 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
2122 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
2123 tempax &= 0x0F;
2124 else
2125 tempax = tempax >> 4;
2127 if ((resinfo == 6) || (resinfo == 9)) {
2128 if (tempax >= 3)
2129 tempbx |= PanelRef75Hz;
2130 } else if ((resinfo == 7) || (resinfo == 8)) {
2131 if (tempax >= 4)
2132 tempbx |= PanelRef75Hz;
2137 pVBInfo->LCDResInfo = tempbx;
2139 /* End of LCD75 */
2141 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
2142 return 0;
2144 tempbx = 0;
2146 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
2148 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
2150 tempbx |= temp;
2152 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
2154 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
2156 if (((pVBInfo->VBType & VB_SIS302LV) ||
2157 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2158 tempbx |= SetLCDDualLink;
2160 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2161 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2162 (!(tempbx & EnableScalingLCD)))
2164 * set to center in 1280x1024 LCDB
2165 * for Panel_1400x1050
2167 tempbx |= SetLCDtoNonExpanding;
2169 if (pVBInfo->VBInfo & SetInSlaveMode) {
2170 if (pVBInfo->VBInfo & SetNotSimuMode)
2171 tempbx |= XGI_LCDVESATiming;
2172 } else {
2173 tempbx |= XGI_LCDVESATiming;
2176 pVBInfo->LCDInfo = tempbx;
2178 return 1;
2181 unsigned char XGI_SearchModeID(unsigned short ModeNo,
2182 unsigned short *ModeIdIndex)
2184 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
2185 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
2186 break;
2187 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
2188 return 0;
2191 return 1;
2194 static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2196 unsigned char ujRet = 0;
2197 unsigned char i = 0;
2199 for (i = 0; i < 8; i++) {
2200 ujRet = ujRet << 1;
2201 ujRet |= (ujDate >> i) & 1;
2204 return ujRet;
2207 /*----------------------------------------------------------------------------*/
2208 /* output */
2209 /* bl[5] : LVDS signal */
2210 /* bl[1] : LVDS backlight */
2211 /* bl[0] : LVDS VDD */
2212 /*----------------------------------------------------------------------------*/
2213 static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2215 unsigned char CR4A, temp;
2217 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2218 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
2220 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2222 temp = XG21GPIODataTransfer(temp);
2223 temp &= 0x23;
2224 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
2225 return temp;
2228 /*----------------------------------------------------------------------------*/
2229 /* output */
2230 /* bl[5] : LVDS signal */
2231 /* bl[1] : LVDS backlight */
2232 /* bl[0] : LVDS VDD */
2233 /*----------------------------------------------------------------------------*/
2234 static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2236 unsigned char CR4A, CRB4, temp;
2238 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2239 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
2241 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2243 temp &= 0x0C;
2244 temp >>= 2;
2245 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
2246 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
2247 temp |= ((CRB4 & 0x04) << 3);
2248 return temp;
2251 /*----------------------------------------------------------------------------*/
2252 /* input */
2253 /* bl[5] : 1;LVDS signal on */
2254 /* bl[1] : 1;LVDS backlight on */
2255 /* bl[0] : 1:LVDS VDD on */
2256 /* bh: 100000b : clear bit 5, to set bit5 */
2257 /* 000010b : clear bit 1, to set bit1 */
2258 /* 000001b : clear bit 0, to set bit0 */
2259 /*----------------------------------------------------------------------------*/
2260 static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2261 struct vb_device_info *pVBInfo)
2263 unsigned char CR4A, temp;
2265 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2266 tempbh &= 0x23;
2267 tempbl &= 0x23;
2268 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2270 if (tempbh & 0x20) {
2271 temp = (tempbl >> 4) & 0x02;
2273 /* CR B4[1] */
2274 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2278 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2280 temp = XG21GPIODataTransfer(temp);
2281 temp &= ~tempbh;
2282 temp |= tempbl;
2283 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2286 static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2287 struct vb_device_info *pVBInfo)
2289 unsigned char CR4A, temp;
2290 unsigned short tempbh0, tempbl0;
2292 tempbh0 = tempbh;
2293 tempbl0 = tempbl;
2294 tempbh0 &= 0x20;
2295 tempbl0 &= 0x20;
2296 tempbh0 >>= 3;
2297 tempbl0 >>= 3;
2299 if (tempbh & 0x20) {
2300 temp = (tempbl >> 4) & 0x02;
2302 /* CR B4[1] */
2303 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2306 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2308 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2309 tempbh &= 0x03;
2310 tempbl &= 0x03;
2311 tempbh <<= 2;
2312 tempbl <<= 2; /* GPIOC,GPIOD */
2313 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2314 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2317 static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2318 struct xgi_hw_device_info *pXGIHWDE,
2319 struct vb_device_info *pVBInfo)
2322 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
2323 if (pXGIHWDE->jChipType == XG21) {
2324 if (pVBInfo->IF_DEF_LVDS == 1) {
2325 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
2326 /* LVDS VDD on */
2327 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
2328 mdelay(xgifb_info->lvds_data.PSC_S2);
2330 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
2331 /* LVDS signal on */
2332 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
2333 mdelay(xgifb_info->lvds_data.PSC_S3);
2334 /* LVDS backlight on */
2335 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
2336 } else {
2337 /* DVO/DVI signal on */
2338 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
2343 if (pXGIHWDE->jChipType == XG27) {
2344 if (pVBInfo->IF_DEF_LVDS == 1) {
2345 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
2346 /* LVDS VDD on */
2347 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
2348 mdelay(xgifb_info->lvds_data.PSC_S2);
2350 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
2351 /* LVDS signal on */
2352 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
2353 mdelay(xgifb_info->lvds_data.PSC_S3);
2354 /* LVDS backlight on */
2355 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
2356 } else {
2357 /* DVO/DVI signal on */
2358 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
2364 void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2365 struct xgi_hw_device_info *pXGIHWDE,
2366 struct vb_device_info *pVBInfo)
2369 if (pXGIHWDE->jChipType == XG21) {
2370 if (pVBInfo->IF_DEF_LVDS == 1) {
2371 /* LVDS backlight off */
2372 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
2373 mdelay(xgifb_info->lvds_data.PSC_S3);
2374 } else {
2375 /* DVO/DVI signal off */
2376 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
2380 if (pXGIHWDE->jChipType == XG27) {
2381 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
2382 /* LVDS backlight off */
2383 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
2384 mdelay(xgifb_info->lvds_data.PSC_S3);
2387 if (pVBInfo->IF_DEF_LVDS == 0)
2388 /* DVO/DVI signal off */
2389 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
2392 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
2395 static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
2397 while ((inb(pVBInfo->P3da) & 0x01))
2398 break;
2400 while (!(inb(pVBInfo->P3da) & 0x01))
2401 break;
2404 static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
2406 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
2409 static void XGI_SaveCRT2Info(unsigned short ModeNo,
2410 struct vb_device_info *pVBInfo)
2412 unsigned short temp1, temp2;
2414 /* reserve CR34 for CRT1 Mode No */
2415 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
2416 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2417 temp2 = ~(SetInSlaveMode >> 8);
2418 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
2421 static void XGI_GetCRT2ResInfo(unsigned short ModeIdIndex,
2422 struct vb_device_info *pVBInfo)
2424 unsigned short xres, yres, modeflag, resindex;
2426 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2427 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2428 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
2429 /* si+St_ModeFlag */
2430 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2432 if (modeflag & HalfDCLK)
2433 xres *= 2;
2435 if (modeflag & DoubleScanMode)
2436 yres *= 2;
2438 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2439 goto exit;
2441 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2442 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2443 if (yres == 1024)
2444 yres = 1056;
2448 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2449 if (yres == 400)
2450 yres = 405;
2451 else if (yres == 350)
2452 yres = 360;
2454 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2455 if (yres == 360)
2456 yres = 375;
2460 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2461 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2462 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2463 if (yres == 350)
2464 yres = 357;
2465 else if (yres == 400)
2466 yres = 420;
2467 else if (yres == 480)
2468 yres = 525;
2473 if (xres == 720)
2474 xres = 640;
2476 exit:
2477 pVBInfo->VGAHDE = xres;
2478 pVBInfo->HDE = xres;
2479 pVBInfo->VGAVDE = yres;
2480 pVBInfo->VDE = yres;
2483 static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
2486 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
2487 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
2488 return 1;
2490 return 0;
2493 static void XGI_GetRAMDAC2DATA(unsigned short ModeIdIndex,
2494 unsigned short RefreshRateTableIndex,
2495 struct vb_device_info *pVBInfo)
2497 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
2498 CRT1Index;
2500 pVBInfo->RVBHCMAX = 1;
2501 pVBInfo->RVBHCFACT = 1;
2502 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2503 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
2504 CRT1Index &= IndexMask;
2505 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2506 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
2507 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
2508 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
2509 tempcx = (unsigned short)
2510 XGI_CRT1Table[CRT1Index].CR[14] << 8;
2511 tempcx &= 0x0100;
2512 tempcx = tempcx << 2;
2513 tempbx |= tempcx;
2514 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
2516 if (temp1 & 0x01)
2517 tempbx |= 0x0100;
2519 if (temp1 & 0x20)
2520 tempbx |= 0x0200;
2521 tempax += 5;
2523 if (modeflag & Charx8Dot)
2524 tempax *= 8;
2525 else
2526 tempax *= 9;
2528 pVBInfo->VGAHT = tempax;
2529 pVBInfo->HT = tempax;
2530 tempbx++;
2531 pVBInfo->VGAVT = tempbx;
2532 pVBInfo->VT = tempbx;
2535 static void XGI_GetCRT2Data(unsigned short ModeIdIndex,
2536 unsigned short RefreshRateTableIndex,
2537 struct vb_device_info *pVBInfo)
2539 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
2541 struct SiS_LCDData const *LCDPtr = NULL;
2543 /* si+Ext_ResInfo */
2544 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2545 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2546 pVBInfo->NewFlickerMode = 0;
2547 pVBInfo->RVBHRS = 50;
2549 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2550 XGI_GetRAMDAC2DATA(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
2551 return;
2554 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
2555 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeIdIndex,
2556 pVBInfo);
2558 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2559 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2560 pVBInfo->VGAHT = LCDPtr->VGAHT;
2561 pVBInfo->VGAVT = LCDPtr->VGAVT;
2562 pVBInfo->HT = LCDPtr->LCDHT;
2563 pVBInfo->VT = LCDPtr->LCDVT;
2565 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2566 tempax = 1024;
2567 tempbx = 768;
2569 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2570 if (pVBInfo->VGAVDE == 357)
2571 tempbx = 527;
2572 else if (pVBInfo->VGAVDE == 420)
2573 tempbx = 620;
2574 else if (pVBInfo->VGAVDE == 525)
2575 tempbx = 775;
2576 else if (pVBInfo->VGAVDE == 600)
2577 tempbx = 775;
2579 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
2580 tempax = 1024;
2581 tempbx = 768;
2582 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2583 tempax = 1280;
2584 if (pVBInfo->VGAVDE == 360)
2585 tempbx = 768;
2586 else if (pVBInfo->VGAVDE == 375)
2587 tempbx = 800;
2588 else if (pVBInfo->VGAVDE == 405)
2589 tempbx = 864;
2590 else
2591 tempbx = 1024;
2592 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
2593 tempax = 1280;
2594 tempbx = 1024;
2595 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
2596 tempax = 1280;
2597 if (pVBInfo->VGAVDE == 350)
2598 tempbx = 700;
2599 else if (pVBInfo->VGAVDE == 400)
2600 tempbx = 800;
2601 else if (pVBInfo->VGAVDE == 1024)
2602 tempbx = 960;
2603 else
2604 tempbx = 960;
2605 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
2606 tempax = 1400;
2607 tempbx = 1050;
2609 if (pVBInfo->VGAVDE == 1024) {
2610 tempax = 1280;
2611 tempbx = 1024;
2613 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2614 tempax = 1600;
2615 tempbx = 1200; /* alan 10/14/2003 */
2616 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2617 if (pVBInfo->VGAVDE == 350)
2618 tempbx = 875;
2619 else if (pVBInfo->VGAVDE == 400)
2620 tempbx = 1000;
2624 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2625 tempax = pVBInfo->VGAHDE;
2626 tempbx = pVBInfo->VGAVDE;
2629 pVBInfo->HDE = tempax;
2630 pVBInfo->VDE = tempbx;
2631 return;
2634 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
2635 struct SiS_TVData const *TVPtr;
2637 TVPtr = XGI_GetTVPtr(ModeIdIndex, RefreshRateTableIndex,
2638 pVBInfo);
2640 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2641 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2642 pVBInfo->VGAHT = TVPtr->VGAHT;
2643 pVBInfo->VGAVT = TVPtr->VGAVT;
2644 pVBInfo->HDE = TVPtr->TVHDE;
2645 pVBInfo->VDE = TVPtr->TVVDE;
2646 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2647 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
2649 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2650 if (resinfo == 0x08)
2651 pVBInfo->NewFlickerMode = 0x40;
2652 else if (resinfo == 0x09)
2653 pVBInfo->NewFlickerMode = 0x40;
2654 else if (resinfo == 0x12)
2655 pVBInfo->NewFlickerMode = 0x40;
2657 if (pVBInfo->VGAVDE == 350)
2658 pVBInfo->TVInfo |= TVSimuMode;
2660 tempax = ExtHiTVHT;
2661 tempbx = ExtHiTVVT;
2663 if (pVBInfo->VBInfo & SetInSlaveMode) {
2664 if (pVBInfo->TVInfo & TVSimuMode) {
2665 tempax = StHiTVHT;
2666 tempbx = StHiTVVT;
2668 if (!(modeflag & Charx8Dot)) {
2669 tempax = StHiTextTVHT;
2670 tempbx = StHiTextTVVT;
2674 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2675 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
2676 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2677 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2680 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
2681 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2682 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
2683 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
2684 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2685 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2686 if (pVBInfo->TVInfo & NTSC1024x768)
2687 tempax = NTSC1024x768HT;
2689 } else {
2690 tempax = PALHT;
2691 tempbx = PALVT;
2692 if (!(pVBInfo->TVInfo & TVSetPAL)) {
2693 tempax = NTSCHT;
2694 tempbx = NTSCVT;
2695 if (pVBInfo->TVInfo & NTSC1024x768)
2696 tempax = NTSC1024x768HT;
2700 pVBInfo->HT = tempax;
2701 pVBInfo->VT = tempbx;
2705 static void XGI_SetCRT2VCLK(unsigned short ModeIdIndex,
2706 unsigned short RefreshRateTableIndex,
2707 struct vb_device_info *pVBInfo)
2709 unsigned char di_0, di_1, tempal;
2711 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
2712 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2713 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
2715 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
2716 /* 301 */
2717 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2718 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2719 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2720 } else { /* 301b/302b/301lv/302lv */
2721 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2722 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2725 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
2727 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
2728 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
2729 else
2730 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
2733 static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex)
2735 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2736 short index;
2737 unsigned short modeflag;
2739 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2740 index = (modeflag & ModeTypeMask) - ModeEGA;
2742 if (index < 0)
2743 index = 0;
2745 return ColorDepth[index];
2748 static unsigned short XGI_GetOffset(unsigned short ModeNo,
2749 unsigned short ModeIdIndex,
2750 unsigned short RefreshRateTableIndex)
2752 unsigned short temp, colordepth, modeinfo, index, infoflag,
2753 ColorDepth[] = { 0x01, 0x02, 0x04 };
2755 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
2756 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
2758 index = (modeinfo >> 8) & 0xFF;
2760 temp = XGI330_ScreenOffset[index];
2762 if (infoflag & InterlaceMode)
2763 temp = temp << 1;
2765 colordepth = XGI_GetColorDepth(ModeIdIndex);
2767 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2768 temp = ModeNo - 0x7C;
2769 colordepth = ColorDepth[temp];
2770 temp = 0x6B;
2771 if (infoflag & InterlaceMode)
2772 temp = temp << 1;
2774 return temp * colordepth;
2777 static void XGI_SetCRT2Offset(unsigned short ModeNo,
2778 unsigned short ModeIdIndex,
2779 unsigned short RefreshRateTableIndex,
2780 struct vb_device_info *pVBInfo)
2782 unsigned short offset;
2783 unsigned char temp;
2785 if (pVBInfo->VBInfo & SetInSlaveMode)
2786 return;
2788 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex);
2789 temp = (unsigned char) (offset & 0xFF);
2790 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
2791 temp = (unsigned char) ((offset & 0xFF00) >> 8);
2792 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
2793 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
2794 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
2797 static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
2799 /* threshold high, disable auto threshold */
2800 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2801 /* threshold low default 04h */
2802 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
2805 static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
2806 unsigned short RefreshRateTableIndex,
2807 struct vb_device_info *pVBInfo)
2809 u8 tempcx;
2811 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
2812 XGI_SetCRT2FIFO(pVBInfo);
2814 for (tempcx = 4; tempcx < 7; tempcx++)
2815 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
2817 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2818 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
2821 static void XGI_SetGroup1(unsigned short ModeIdIndex,
2822 unsigned short RefreshRateTableIndex,
2823 struct vb_device_info *pVBInfo)
2825 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
2826 pushbx = 0, CRT1Index, modeflag;
2828 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
2829 CRT1Index &= IndexMask;
2830 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2832 /* bainy change table name */
2833 if (modeflag & HalfDCLK) {
2834 /* BTVGA2HT 0x08,0x09 */
2835 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
2836 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
2837 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
2838 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
2839 /* BTVGA2HDEE 0x0A,0x0C */
2840 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
2841 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
2842 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2843 pushbx = pVBInfo->VGAHDE / 2 + 16;
2844 tempcx = tempcx >> 1;
2845 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2846 tempcx += tempbx;
2848 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2849 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2850 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
2851 0xC0) << 2);
2852 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
2853 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
2854 tempcx &= 0x1F;
2855 temp = XGI_CRT1Table[CRT1Index].CR[15];
2856 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2857 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2860 tempbx += 4;
2861 tempcx += 4;
2863 if (tempcx > (pVBInfo->VGAHT / 2))
2864 tempcx = pVBInfo->VGAHT / 2;
2866 temp = tempbx & 0x00FF;
2868 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
2869 } else {
2870 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
2871 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
2872 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
2873 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
2874 /* BTVGA2HDEE 0x0A,0x0C */
2875 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
2876 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
2877 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2878 pushbx = pVBInfo->VGAHDE + 16;
2879 tempcx = tempcx >> 1;
2880 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2881 tempcx += tempbx;
2883 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2884 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2885 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
2886 0xC0) << 2);
2887 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
2888 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
2889 tempcx &= 0x1F;
2890 temp = XGI_CRT1Table[CRT1Index].CR[6];
2891 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2892 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2893 tempbx += 16;
2894 tempcx += 16;
2897 if (tempcx > pVBInfo->VGAHT)
2898 tempcx = pVBInfo->VGAHT;
2900 temp = tempbx & 0x00FF;
2901 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
2904 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2905 tempbx = pushbx;
2906 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2907 tempax |= (tempbx & 0xFF00);
2908 temp = (tempax & 0xFF00) >> 8;
2909 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
2910 temp = tempcx & 0x00FF;
2911 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
2912 tempcx = (pVBInfo->VGAVT - 1);
2913 temp = tempcx & 0x00FF;
2915 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
2916 tempbx = pVBInfo->VGAVDE - 1;
2917 temp = tempbx & 0x00FF;
2918 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
2919 temp = ((tempbx & 0xFF00) << 3) >> 8;
2920 temp |= ((tempcx & 0xFF00) >> 8);
2921 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
2923 /* BTVGA2VRS 0x10,0x11 */
2924 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2925 /* BTVGA2VRE 0x11 */
2926 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
2928 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2929 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2930 temp = XGI_CRT1Table[CRT1Index].CR[9];
2932 if (temp & 0x04)
2933 tempbx |= 0x0100;
2935 if (temp & 0x080)
2936 tempbx |= 0x0200;
2938 temp = XGI_CRT1Table[CRT1Index].CR[14];
2940 if (temp & 0x08)
2941 tempbx |= 0x0400;
2943 temp = XGI_CRT1Table[CRT1Index].CR[11];
2944 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
2947 temp = tempbx & 0x00FF;
2948 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
2949 temp = ((tempbx & 0xFF00) >> 8) << 4;
2950 temp = ((tempcx & 0x000F) | (temp));
2951 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
2952 tempax = 0;
2954 if (modeflag & DoubleScanMode)
2955 tempax |= 0x80;
2957 if (modeflag & HalfDCLK)
2958 tempax |= 0x40;
2960 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
2963 static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
2965 unsigned long tempax, tempbx;
2967 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
2968 & 0xFFFF;
2969 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
2970 tempax = (tempax * pVBInfo->HT) / tempbx;
2972 return (unsigned short) tempax;
2975 static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2976 struct vb_device_info *pVBInfo)
2978 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
2979 modeflag;
2981 /* si+Ext_ResInfo */
2982 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2983 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2985 if (!(pVBInfo->VBInfo & SetInSlaveMode))
2986 return;
2988 temp = 0xFF; /* set MAX HT */
2989 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
2990 tempcx = 0x08;
2992 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
2993 modeflag |= Charx8Dot;
2995 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
2997 if (modeflag & HalfDCLK)
2998 tempax = tempax >> 1;
3000 tempax = (tempax / tempcx) - 1;
3001 tempbx |= ((tempax & 0x00FF) << 8);
3002 temp = tempax & 0x00FF;
3003 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
3005 temp = (tempbx & 0xFF00) >> 8;
3007 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3008 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3009 | VB_SIS302LV | VB_XGI301C)))
3010 temp += 2;
3012 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3013 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
3014 temp -= 2;
3017 /* 0x05 Horizontal Display Start */
3018 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3019 /* 0x06 Horizontal Blank end */
3020 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
3022 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3023 if (pVBInfo->VBInfo & SetCRT2ToTV)
3024 tempax = pVBInfo->VGAHT;
3025 else
3026 tempax = XGI_GetVGAHT2(pVBInfo);
3029 if (tempax >= pVBInfo->VGAHT)
3030 tempax = pVBInfo->VGAHT;
3032 if (modeflag & HalfDCLK)
3033 tempax = tempax >> 1;
3035 tempax = (tempax / tempcx) - 5;
3036 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
3037 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3038 temp = (tempbx & 0x00FF) - 1;
3039 if (!(modeflag & HalfDCLK)) {
3040 temp -= 6;
3041 if (pVBInfo->TVInfo & TVSimuMode) {
3042 temp -= 4;
3043 temp -= 10;
3046 } else {
3047 tempbx = (tempbx & 0xFF00) >> 8;
3048 tempcx = (tempcx + tempbx) >> 1;
3049 temp = (tempcx & 0x00FF) + 2;
3051 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3052 temp -= 1;
3053 if (!(modeflag & HalfDCLK)) {
3054 if ((modeflag & Charx8Dot)) {
3055 temp += 4;
3056 if (pVBInfo->VGAHDE >= 800)
3057 temp -= 6;
3060 } else if (!(modeflag & HalfDCLK)) {
3061 temp -= 4;
3062 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
3063 pVBInfo->VGAHDE >= 800) {
3064 temp -= 7;
3065 if (pVBInfo->VGAHDE >= 1280 &&
3066 pVBInfo->LCDResInfo != Panel_1280x960 &&
3067 (pVBInfo->LCDInfo & LCDNonExpanding))
3068 temp += 28;
3073 /* 0x07 Horizontal Retrace Start */
3074 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3075 /* 0x08 Horizontal Retrace End */
3076 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
3078 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3079 if (pVBInfo->TVInfo & TVSimuMode) {
3080 if (ModeNo == 0x50) {
3081 if (pVBInfo->TVInfo == SetNTSCTV) {
3082 xgifb_reg_set(pVBInfo->Part1Port,
3083 0x07, 0x30);
3084 xgifb_reg_set(pVBInfo->Part1Port,
3085 0x08, 0x03);
3086 } else {
3087 xgifb_reg_set(pVBInfo->Part1Port,
3088 0x07, 0x2f);
3089 xgifb_reg_set(pVBInfo->Part1Port,
3090 0x08, 0x02);
3096 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
3097 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
3098 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
3100 tempbx = pVBInfo->VGAVT;
3101 push1 = tempbx;
3102 tempcx = 0x121;
3103 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
3105 if (tempbx == 357)
3106 tempbx = 350;
3107 if (tempbx == 360)
3108 tempbx = 350;
3109 if (tempbx == 375)
3110 tempbx = 350;
3111 if (tempbx == 405)
3112 tempbx = 400;
3113 if (tempbx == 525)
3114 tempbx = 480;
3116 push2 = tempbx;
3118 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3119 if (pVBInfo->LCDResInfo == Panel_1024x768) {
3120 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
3121 if (tempbx == 350)
3122 tempbx += 5;
3123 if (tempbx == 480)
3124 tempbx += 5;
3128 tempbx--;
3129 tempbx--;
3130 temp = tempbx & 0x00FF;
3131 /* 0x10 vertical Blank Start */
3132 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
3133 tempbx = push2;
3134 tempbx--;
3135 temp = tempbx & 0x00FF;
3136 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
3138 if (tempbx & 0x0100)
3139 tempcx |= 0x0002;
3141 tempax = 0x000B;
3143 if (modeflag & DoubleScanMode)
3144 tempax |= 0x08000;
3146 if (tempbx & 0x0200)
3147 tempcx |= 0x0040;
3149 temp = (tempax & 0xFF00) >> 8;
3150 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
3152 if (tempbx & 0x0400)
3153 tempcx |= 0x0600;
3155 /* 0x11 Vertival Blank End */
3156 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
3158 tempax = push1;
3159 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3160 tempax = tempax >> 2;
3161 push1 = tempax; /* push ax */
3163 if (resinfo != 0x09) {
3164 tempax = tempax << 1;
3165 tempbx += tempax;
3168 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3169 if ((pVBInfo->VBType & VB_SIS301LV) &&
3170 !(pVBInfo->TVInfo & TVSetHiVision)) {
3171 if ((pVBInfo->TVInfo & TVSimuMode) &&
3172 (pVBInfo->TVInfo & TVSetPAL)) {
3173 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3174 !(pVBInfo->TVInfo &
3175 (TVSetYPbPr525p |
3176 TVSetYPbPr750p |
3177 TVSetHiVision)))
3178 tempbx += 40;
3180 } else {
3181 tempbx -= 10;
3183 } else if (pVBInfo->TVInfo & TVSimuMode) {
3184 if (pVBInfo->TVInfo & TVSetPAL) {
3185 if (pVBInfo->VBType & VB_SIS301LV) {
3186 if (!(pVBInfo->TVInfo &
3187 (TVSetYPbPr525p |
3188 TVSetYPbPr750p |
3189 TVSetHiVision)))
3190 tempbx += 40;
3191 } else {
3192 tempbx += 40;
3196 tempax = push1;
3197 tempax = tempax >> 2;
3198 tempax++;
3199 tempax += tempbx;
3200 push1 = tempax; /* push ax */
3202 if ((pVBInfo->TVInfo & TVSetPAL)) {
3203 if (tempbx <= 513) {
3204 if (tempax >= 513)
3205 tempbx = 513;
3209 temp = tempbx & 0x00FF;
3210 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
3211 tempbx--;
3212 temp = tempbx & 0x00FF;
3213 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
3215 if (tempbx & 0x0100)
3216 tempcx |= 0x0008;
3218 if (tempbx & 0x0200)
3219 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
3221 tempbx++;
3223 if (tempbx & 0x0100)
3224 tempcx |= 0x0004;
3226 if (tempbx & 0x0200)
3227 tempcx |= 0x0080;
3229 if (tempbx & 0x0400)
3230 tempcx |= 0x0C00;
3232 tempbx = push1; /* pop ax */
3233 temp = tempbx & 0x00FF;
3234 temp &= 0x0F;
3235 /* 0x0D vertical Retrace End */
3236 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
3238 if (tempbx & 0x0010)
3239 tempcx |= 0x2000;
3241 temp = tempcx & 0x00FF;
3242 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
3243 temp = (tempcx & 0x0FF00) >> 8;
3244 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
3245 tempax = modeflag;
3246 temp = (tempax & 0xFF00) >> 8;
3248 temp = (temp >> 1) & 0x09;
3250 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
3251 temp |= 0x01;
3253 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3254 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3255 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
3257 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3258 temp = 0x80;
3259 else
3260 temp = 0x00;
3262 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
3265 static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
3266 struct vb_device_info *pVBInfo)
3268 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
3269 modeflag;
3270 unsigned char const *TimingPoint;
3272 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3274 /* si+Ext_ResInfo */
3275 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3277 tempax = 0;
3279 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3280 tempax |= 0x0800;
3282 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3283 tempax |= 0x0400;
3285 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3286 tempax |= 0x0200;
3288 if (!(pVBInfo->TVInfo & TVSetPAL))
3289 tempax |= 0x1000;
3291 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3292 tempax |= 0x0100;
3294 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
3295 tempax &= 0xfe00;
3297 tempax = (tempax & 0xff00) >> 8;
3299 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
3300 TimingPoint = XGI330_NTSCTiming;
3302 if (pVBInfo->TVInfo & TVSetPAL)
3303 TimingPoint = XGI330_PALTiming;
3305 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3306 TimingPoint = XGI330_HiTVExtTiming;
3308 if (pVBInfo->VBInfo & SetInSlaveMode)
3309 TimingPoint = XGI330_HiTVSt2Timing;
3311 if (pVBInfo->SetFlag & TVSimuMode)
3312 TimingPoint = XGI330_HiTVSt1Timing;
3314 if (!(modeflag & Charx8Dot))
3315 TimingPoint = XGI330_HiTVTextTiming;
3318 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3319 if (pVBInfo->TVInfo & TVSetYPbPr525i)
3320 TimingPoint = XGI330_YPbPr525iTiming;
3322 if (pVBInfo->TVInfo & TVSetYPbPr525p)
3323 TimingPoint = XGI330_YPbPr525pTiming;
3325 if (pVBInfo->TVInfo & TVSetYPbPr750p)
3326 TimingPoint = XGI330_YPbPr750pTiming;
3329 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
3330 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
3332 for (i = 0x39; i <= 0x45; i++, j++)
3333 /* di->temp2[j] */
3334 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
3336 if (pVBInfo->VBInfo & SetCRT2ToTV)
3337 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
3339 temp = pVBInfo->NewFlickerMode;
3340 temp &= 0x80;
3341 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
3343 if (pVBInfo->TVInfo & TVSetPAL)
3344 tempax = 520;
3345 else
3346 tempax = 440;
3348 if (pVBInfo->VDE <= tempax) {
3349 tempax -= pVBInfo->VDE;
3350 tempax = tempax >> 2;
3351 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3352 push1 = tempax;
3353 temp = (tempax & 0xFF00) >> 8;
3354 temp += (unsigned short) TimingPoint[0];
3356 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3357 | VB_SIS302LV | VB_XGI301C)) {
3358 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3359 | SetCRT2ToSVIDEO | SetCRT2ToSCART
3360 | SetCRT2ToYPbPr525750)) {
3361 tempcx = pVBInfo->VGAHDE;
3362 if (tempcx >= 1024) {
3363 temp = 0x17; /* NTSC */
3364 if (pVBInfo->TVInfo & TVSetPAL)
3365 temp = 0x19; /* PAL */
3370 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
3371 tempax = push1;
3372 temp = (tempax & 0xFF00) >> 8;
3373 temp += TimingPoint[1];
3375 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3376 | VB_SIS302LV | VB_XGI301C)) {
3377 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3378 | SetCRT2ToSVIDEO | SetCRT2ToSCART
3379 | SetCRT2ToYPbPr525750))) {
3380 tempcx = pVBInfo->VGAHDE;
3381 if (tempcx >= 1024) {
3382 temp = 0x1D; /* NTSC */
3383 if (pVBInfo->TVInfo & TVSetPAL)
3384 temp = 0x52; /* PAL */
3388 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
3391 /* 301b */
3392 tempcx = pVBInfo->HT;
3394 if (XGI_IsLCDDualLink(pVBInfo))
3395 tempcx = tempcx >> 1;
3397 tempcx -= 2;
3398 temp = tempcx & 0x00FF;
3399 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
3401 temp = (tempcx & 0xFF00) >> 8;
3402 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
3404 tempcx = pVBInfo->HT >> 1;
3405 push1 = tempcx; /* push cx */
3406 tempcx += 7;
3408 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3409 tempcx -= 4;
3411 temp = tempcx & 0x00FF;
3412 temp = temp << 4;
3413 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
3415 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3416 tempbx += tempcx;
3417 push2 = tempbx;
3418 temp = tempbx & 0x00FF;
3419 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
3420 temp = (tempbx & 0xFF00) >> 8;
3421 temp = temp << 4;
3422 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
3424 tempbx = push2;
3425 tempbx = tempbx + 8;
3426 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3427 tempbx = tempbx - 4;
3428 tempcx = tempbx;
3431 temp = (tempbx & 0x00FF) << 4;
3432 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
3434 j += 2;
3435 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3436 temp = tempcx & 0x00FF;
3437 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
3438 temp = ((tempcx & 0xFF00) >> 8) << 4;
3439 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
3441 tempcx += 8;
3442 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3443 tempcx -= 4;
3445 temp = tempcx & 0xFF;
3446 temp = temp << 4;
3447 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
3449 tempcx = push1; /* pop cx */
3450 j += 2;
3451 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3452 tempcx -= temp;
3453 temp = tempcx & 0x00FF;
3454 temp = temp << 4;
3455 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
3457 tempcx -= 11;
3459 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3460 tempax = XGI_GetVGAHT2(pVBInfo);
3461 tempcx = tempax - 1;
3463 temp = tempcx & 0x00FF;
3464 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
3466 tempbx = pVBInfo->VDE;
3468 if (pVBInfo->VGAVDE == 360)
3469 tempbx = 746;
3470 if (pVBInfo->VGAVDE == 375)
3471 tempbx = 746;
3472 if (pVBInfo->VGAVDE == 405)
3473 tempbx = 853;
3475 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3476 if (pVBInfo->VBType &
3477 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
3478 if (!(pVBInfo->TVInfo &
3479 (TVSetYPbPr525p | TVSetYPbPr750p)))
3480 tempbx = tempbx >> 1;
3481 } else
3482 tempbx = tempbx >> 1;
3485 tempbx -= 2;
3486 temp = tempbx & 0x00FF;
3488 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3489 if (pVBInfo->VBType & VB_SIS301LV) {
3490 if (pVBInfo->TVInfo & TVSetHiVision) {
3491 if (pVBInfo->VBInfo & SetInSlaveMode) {
3492 if (ModeNo == 0x2f)
3493 temp += 1;
3496 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3497 if (ModeNo == 0x2f)
3498 temp += 1;
3502 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
3504 temp = (tempcx & 0xFF00) >> 8;
3505 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3507 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
3508 if (pVBInfo->VBType & VB_SIS301LV) {
3509 if (pVBInfo->TVInfo & TVSetHiVision) {
3510 temp |= 0x10;
3512 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3513 temp |= 0x20;
3515 } else {
3516 temp |= 0x10;
3517 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3518 temp |= 0x20;
3522 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
3524 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3525 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
3526 tempbx = pVBInfo->VDE;
3527 tempcx = tempbx - 2;
3529 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3530 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3531 | TVSetYPbPr750p)))
3532 tempbx = tempbx >> 1;
3535 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
3536 temp = 0;
3537 if (tempcx & 0x0400)
3538 temp |= 0x20;
3540 if (tempbx & 0x0400)
3541 temp |= 0x40;
3543 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
3546 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
3547 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
3548 temp = (tempbx - 3) & 0x00FF;
3549 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
3552 tempbx = tempbx & 0x00FF;
3554 if (!(modeflag & HalfDCLK)) {
3555 tempcx = pVBInfo->VGAHDE;
3556 if (tempcx >= pVBInfo->HDE) {
3557 tempbx |= 0x2000;
3558 tempax &= 0x00FF;
3562 tempcx = 0x0101;
3564 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3565 if (pVBInfo->VGAHDE >= 1024) {
3566 tempcx = 0x1920;
3567 if (pVBInfo->VGAHDE >= 1280) {
3568 tempcx = 0x1420;
3569 tempbx = tempbx & 0xDFFF;
3574 if (!(tempbx & 0x2000)) {
3575 if (modeflag & HalfDCLK)
3576 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3578 push1 = tempbx;
3579 tempeax = pVBInfo->VGAHDE;
3580 tempebx = (tempcx & 0xFF00) >> 8;
3581 longtemp = tempeax * tempebx;
3582 tempecx = tempcx & 0x00FF;
3583 longtemp = longtemp / tempecx;
3585 /* 301b */
3586 tempecx = 8 * 1024;
3588 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3589 | VB_SIS302LV | VB_XGI301C)) {
3590 tempecx = tempecx * 8;
3593 longtemp = longtemp * tempecx;
3594 tempecx = pVBInfo->HDE;
3595 temp2 = longtemp % tempecx;
3596 tempeax = longtemp / tempecx;
3597 if (temp2 != 0)
3598 tempeax += 1;
3600 tempax = (unsigned short) tempeax;
3602 /* 301b */
3603 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3604 | VB_SIS302LV | VB_XGI301C)) {
3605 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3607 /* end 301b */
3609 tempbx = push1;
3610 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3611 | (tempbx & 0x00FF));
3612 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3613 | (tempax & 0x00FF));
3614 temp = (tempax & 0xFF00) >> 8;
3615 } else {
3616 temp = (tempax & 0x00FF);
3619 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
3620 temp = (tempbx & 0xFF00) >> 8;
3621 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
3622 temp = tempcx & 0x00FF;
3624 if (tempbx & 0x2000)
3625 temp = 0;
3627 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3628 temp |= 0x18;
3630 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
3631 if (pVBInfo->TVInfo & TVSetPAL) {
3632 tempbx = 0x0382;
3633 tempcx = 0x007e;
3634 } else {
3635 tempbx = 0x0369;
3636 tempcx = 0x0061;
3639 temp = tempbx & 0x00FF;
3640 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
3641 temp = tempcx & 0x00FF;
3642 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
3644 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3645 temp = temp << 2;
3646 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3648 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3649 temp |= 0x10;
3651 if (pVBInfo->TVInfo & TVSetYPbPr525p)
3652 temp |= 0x20;
3654 if (pVBInfo->TVInfo & TVSetYPbPr750p)
3655 temp |= 0x60;
3658 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
3659 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
3660 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
3662 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
3663 if (pVBInfo->TVInfo & NTSC1024x768) {
3664 TimingPoint = XGI_NTSC1024AdjTime;
3665 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
3666 xgifb_reg_set(pVBInfo->Part2Port, i,
3667 TimingPoint[j]);
3669 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
3673 /* Modify for 301C PALM Support */
3674 if (pVBInfo->VBType & VB_XGI301C) {
3675 if (pVBInfo->TVInfo & TVSetPALM)
3676 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
3677 0x08); /* PALM Mode */
3680 if (pVBInfo->TVInfo & TVSetPALM) {
3681 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
3682 tempax--;
3683 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
3685 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
3688 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
3689 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3690 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
3694 static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
3695 struct vb_device_info *pVBInfo)
3697 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3698 tempbh, tempch;
3700 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
3702 /* si+Ext_ResInfo */
3703 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3704 return;
3706 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3708 if (XGI_IsLCDDualLink(pVBInfo))
3709 tempbx = tempbx >> 1;
3711 tempbx -= 1;
3712 temp = tempbx & 0x00FF;
3713 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
3714 temp = (tempbx & 0xFF00) >> 8;
3715 temp = temp << 4;
3716 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
3717 temp = 0x01;
3719 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
3720 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
3721 tempbx--;
3722 temp = tempbx & 0x00FF;
3723 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
3724 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
3725 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
3727 tempcx = pVBInfo->VT - 1;
3728 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
3729 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
3730 temp = (tempcx & 0xFF00) >> 8;
3731 temp = temp << 5;
3732 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
3733 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3734 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3735 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3736 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
3738 /* Customized LCDB Does not add */
3739 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3740 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeIdIndex,
3741 pVBInfo);
3742 else
3743 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeIdIndex,
3744 pVBInfo);
3746 tempah = pVBInfo->LCDResInfo;
3747 tempah &= PanelResInfo;
3749 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
3750 tempbx = 1024;
3751 tempcx = 768;
3752 } else if ((tempah == Panel_1280x1024) ||
3753 (tempah == Panel_1280x1024x75)) {
3754 tempbx = 1280;
3755 tempcx = 1024;
3756 } else if (tempah == Panel_1400x1050) {
3757 tempbx = 1400;
3758 tempcx = 1050;
3759 } else {
3760 tempbx = 1600;
3761 tempcx = 1200;
3764 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3765 tempbx = pVBInfo->HDE;
3766 tempcx = pVBInfo->VDE;
3769 pushbx = tempbx;
3770 tempax = pVBInfo->VT;
3771 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3772 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3773 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3774 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3775 tempbx = pVBInfo->LCDVDES;
3776 tempcx += tempbx;
3778 if (tempcx >= tempax)
3779 tempcx -= tempax; /* lcdvdes */
3781 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
3782 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
3783 temp = tempcx & 0x00FF;
3784 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
3785 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3786 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3787 tempah = tempch;
3788 tempah = tempah << 3;
3789 tempah |= tempbh;
3790 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
3792 /* getlcdsync() */
3793 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3794 tempcx = tempbx;
3795 tempax = pVBInfo->VT;
3796 tempbx = pVBInfo->LCDVRS;
3798 tempcx += tempbx;
3799 if (tempcx >= tempax)
3800 tempcx -= tempax;
3802 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
3803 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
3804 temp = (tempbx & 0xFF00) >> 8;
3805 temp = temp << 4;
3806 temp |= (tempcx & 0x000F);
3807 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
3808 tempcx = pushbx;
3809 tempax = pVBInfo->HT;
3810 tempbx = pVBInfo->LCDHDES;
3811 tempbx &= 0x0FFF;
3813 if (XGI_IsLCDDualLink(pVBInfo)) {
3814 tempax = tempax >> 1;
3815 tempbx = tempbx >> 1;
3816 tempcx = tempcx >> 1;
3819 if (pVBInfo->VBType & VB_SIS302LV)
3820 tempbx += 1;
3822 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3823 tempbx += 1;
3825 tempcx += tempbx;
3827 if (tempcx >= tempax)
3828 tempcx -= tempax;
3830 temp = tempbx & 0x00FF;
3831 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
3832 temp = ((tempbx & 0xFF00) >> 8) << 4;
3833 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
3834 temp = tempcx & 0x00FF;
3835 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
3836 temp = (tempcx & 0xFF00) >> 8;
3837 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
3839 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3840 tempcx = tempax;
3841 tempax = pVBInfo->HT;
3842 tempbx = pVBInfo->LCDHRS;
3843 if (XGI_IsLCDDualLink(pVBInfo)) {
3844 tempax = tempax >> 1;
3845 tempbx = tempbx >> 1;
3846 tempcx = tempcx >> 1;
3849 if (pVBInfo->VBType & VB_SIS302LV)
3850 tempbx += 1;
3852 tempcx += tempbx;
3854 if (tempcx >= tempax)
3855 tempcx -= tempax;
3857 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
3858 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
3860 temp = (tempbx & 0xFF00) >> 8;
3861 temp = temp << 4;
3862 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
3863 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
3864 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
3866 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
3867 if (pVBInfo->VGAVDE == 525) {
3868 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3869 | VB_SIS301LV | VB_SIS302LV
3870 | VB_XGI301C)) {
3871 temp = 0xC6;
3872 } else
3873 temp = 0xC4;
3875 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3876 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
3879 if (pVBInfo->VGAVDE == 420) {
3880 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3881 | VB_SIS301LV | VB_SIS302LV
3882 | VB_XGI301C)) {
3883 temp = 0x4F;
3884 } else
3885 temp = 0x4E;
3886 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3891 /* --------------------------------------------------------------------- */
3892 /* Function : XGI_GetTap4Ptr */
3893 /* Input : */
3894 /* Output : di -> Tap4 Reg. Setting Pointer */
3895 /* Description : */
3896 /* --------------------------------------------------------------------- */
3897 static struct XGI301C_Tap4TimingStruct const
3898 *XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
3900 unsigned short tempax, tempbx, i;
3901 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
3903 if (tempcx == 0) {
3904 tempax = pVBInfo->VGAHDE;
3905 tempbx = pVBInfo->HDE;
3906 } else {
3907 tempax = pVBInfo->VGAVDE;
3908 tempbx = pVBInfo->VDE;
3911 if (tempax <= tempbx)
3912 return &xgifb_tap4_timing[0];
3913 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
3915 if (pVBInfo->TVInfo & TVSetPAL)
3916 Tap4TimingPtr = PALTap4Timing;
3918 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3919 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3920 (pVBInfo->TVInfo & TVSetYPbPr525p))
3921 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
3922 if (pVBInfo->TVInfo & TVSetYPbPr750p)
3923 Tap4TimingPtr = YPbPr750pTap4Timing;
3926 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3927 Tap4TimingPtr = xgifb_tap4_timing;
3929 i = 0;
3930 while (Tap4TimingPtr[i].DE != 0xFFFF) {
3931 if (Tap4TimingPtr[i].DE == tempax)
3932 break;
3933 i++;
3935 return &Tap4TimingPtr[i];
3938 static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
3940 unsigned short i, j;
3941 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
3943 if (!(pVBInfo->VBType & VB_XGI301C))
3944 return;
3946 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
3947 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
3948 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
3950 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
3951 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
3952 /* Set Vertical Scaling */
3953 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
3954 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
3955 xgifb_reg_set(pVBInfo->Part2Port,
3957 Tap4TimingPtr->Reg[j]);
3960 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
3961 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
3962 /* Enable V.Scaling */
3963 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
3964 else
3965 /* Enable H.Scaling */
3966 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
3969 static void XGI_SetGroup3(unsigned short ModeIdIndex,
3970 struct vb_device_info *pVBInfo)
3972 unsigned short i;
3973 unsigned char const *tempdi;
3974 unsigned short modeflag;
3976 /* si+Ext_ResInfo */
3977 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3979 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
3980 if (pVBInfo->TVInfo & TVSetPAL) {
3981 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3982 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
3983 } else {
3984 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
3985 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
3988 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
3989 return;
3991 if (pVBInfo->TVInfo & TVSetPALM) {
3992 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3993 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
3994 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
3997 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
3998 & SetCRT2ToYPbPr525750)) {
3999 if (pVBInfo->TVInfo & TVSetYPbPr525i)
4000 return;
4002 tempdi = XGI330_HiTVGroup3Data;
4003 if (pVBInfo->SetFlag & TVSimuMode) {
4004 tempdi = XGI330_HiTVGroup3Simu;
4005 if (!(modeflag & Charx8Dot))
4006 tempdi = XGI330_HiTVGroup3Text;
4009 if (pVBInfo->TVInfo & TVSetYPbPr525p)
4010 tempdi = XGI330_Ren525pGroup3;
4012 if (pVBInfo->TVInfo & TVSetYPbPr750p)
4013 tempdi = XGI330_Ren750pGroup3;
4015 for (i = 0; i <= 0x3E; i++)
4016 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
4018 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
4019 if (pVBInfo->TVInfo & TVSetYPbPr525p)
4020 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
4025 static void XGI_SetGroup4(unsigned short ModeIdIndex,
4026 unsigned short RefreshRateTableIndex,
4027 struct vb_device_info *pVBInfo)
4029 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
4031 unsigned long tempebx, tempeax, templong;
4033 /* si+Ext_ResInfo */
4034 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4035 temp = pVBInfo->RVBHCFACT;
4036 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
4038 tempbx = pVBInfo->RVBHCMAX;
4039 temp = tempbx & 0x00FF;
4040 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
4041 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4042 tempcx = pVBInfo->VGAHT - 1;
4043 temp = tempcx & 0x00FF;
4044 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
4046 temp = ((tempcx & 0xFF00) >> 8) << 3;
4047 temp2 |= temp;
4049 tempcx = pVBInfo->VGAVT - 1;
4050 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4051 tempcx -= 5;
4053 temp = tempcx & 0x00FF;
4054 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
4055 temp = temp2 | ((tempcx & 0xFF00) >> 8);
4056 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
4057 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
4058 tempcx = pVBInfo->VBInfo;
4059 tempbx = pVBInfo->VGAHDE;
4061 if (modeflag & HalfDCLK)
4062 tempbx = tempbx >> 1;
4064 if (XGI_IsLCDDualLink(pVBInfo))
4065 tempbx = tempbx >> 1;
4067 if (tempcx & SetCRT2ToHiVision) {
4068 temp = 0;
4069 if (tempbx <= 1024)
4070 temp = 0xA0;
4071 if (tempbx == 1280)
4072 temp = 0xC0;
4073 } else if (tempcx & SetCRT2ToTV) {
4074 temp = 0xA0;
4075 if (tempbx <= 800)
4076 temp = 0x80;
4077 } else {
4078 temp = 0x80;
4079 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4080 temp = 0;
4081 if (tempbx > 800)
4082 temp = 0x60;
4086 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
4087 temp = 0x00;
4088 if (pVBInfo->VGAHDE == 1280)
4089 temp = 0x40;
4090 if (pVBInfo->VGAHDE == 1024)
4091 temp = 0x20;
4093 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
4095 tempebx = pVBInfo->VDE;
4097 tempcx = pVBInfo->RVBHRS;
4098 temp = tempcx & 0x00FF;
4099 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
4101 tempeax = pVBInfo->VGAVDE;
4102 tempcx |= 0x04000;
4104 if (tempeax <= tempebx) {
4105 tempcx = (tempcx & (~0x4000));
4106 tempeax = pVBInfo->VGAVDE;
4107 } else {
4108 tempeax -= tempebx;
4111 templong = (tempeax * 256 * 1024) % tempebx;
4112 tempeax = (tempeax * 256 * 1024) / tempebx;
4113 tempebx = tempeax;
4115 if (templong != 0)
4116 tempebx++;
4118 temp = (unsigned short) (tempebx & 0x000000FF);
4119 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
4121 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
4122 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
4123 tempbx = (unsigned short) (tempebx >> 16);
4124 temp = tempbx & 0x00FF;
4125 temp = temp << 4;
4126 temp |= ((tempcx & 0xFF00) >> 8);
4127 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
4129 /* 301b */
4130 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4131 | VB_SIS302LV | VB_XGI301C)) {
4132 temp = 0x0028;
4133 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
4134 tempax = pVBInfo->VGAHDE;
4135 if (modeflag & HalfDCLK)
4136 tempax = tempax >> 1;
4138 if (XGI_IsLCDDualLink(pVBInfo))
4139 tempax = tempax >> 1;
4141 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4142 if (tempax > 800)
4143 tempax -= 800;
4144 } else if (pVBInfo->VGAHDE > 800) {
4145 if (pVBInfo->VGAHDE == 1024)
4146 tempax = (tempax * 25 / 32) - 1;
4147 else
4148 tempax = (tempax * 20 / 32) - 1;
4150 tempax -= 1;
4152 temp = (tempax & 0xFF00) >> 8;
4153 temp = ((temp & 0x0003) << 4);
4154 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
4155 temp = (tempax & 0x00FF);
4156 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
4158 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
4159 if (pVBInfo->VGAHDE > 800)
4160 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
4163 temp = 0x0036;
4165 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4166 if (!(pVBInfo->TVInfo & (NTSC1024x768
4167 | TVSetYPbPr525p | TVSetYPbPr750p
4168 | TVSetHiVision))) {
4169 temp |= 0x0001;
4170 if ((pVBInfo->VBInfo & SetInSlaveMode)
4171 && (!(pVBInfo->TVInfo
4172 & TVSimuMode)))
4173 temp &= (~0x0001);
4177 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
4178 tempbx = pVBInfo->HT;
4179 if (XGI_IsLCDDualLink(pVBInfo))
4180 tempbx = tempbx >> 1;
4181 tempbx = (tempbx >> 1) - 2;
4182 temp = ((tempbx & 0x0700) >> 8) << 3;
4183 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
4184 temp = tempbx & 0x00FF;
4185 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
4187 /* end 301b */
4189 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
4192 static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4194 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
4197 static void XGI_SetGroup5(struct vb_device_info *pVBInfo)
4199 if (pVBInfo->ModeType == ModeVGA) {
4200 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
4201 | DisableCRT2Display))) {
4202 XGINew_EnableCRT2(pVBInfo);
4207 static void XGI_DisableGatingCRT(struct vb_device_info *pVBInfo)
4209 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
4212 static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4213 unsigned short ModeNo, unsigned short ModeIdIndex)
4215 unsigned short xres, yres, colordepth, modeflag, resindex;
4217 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
4218 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4219 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
4220 /* si+St_ModeFlag */
4221 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4223 if (!(modeflag & Charx8Dot)) {
4224 xres /= 9;
4225 xres *= 8;
4228 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4229 xres *= 2;
4231 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4232 yres *= 2;
4234 if (xres > xgifb_info->lvds_data.LVDSHDE)
4235 return 0;
4237 if (yres > xgifb_info->lvds_data.LVDSVDE)
4238 return 0;
4240 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4241 yres != xgifb_info->lvds_data.LVDSVDE) {
4242 colordepth = XGI_GetColorDepth(ModeIdIndex);
4243 if (colordepth > 2)
4244 return 0;
4246 return 1;
4249 static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4250 int chip_id,
4251 unsigned short ModeIdIndex,
4252 struct vb_device_info *pVBInfo)
4254 unsigned char temp, Miscdata;
4255 unsigned short xres, yres, modeflag, resindex;
4256 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4257 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4258 unsigned short value;
4260 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
4261 (LCDPolarity << 8)) >> 8);
4262 temp &= LCDPolarity;
4263 Miscdata = inb(pVBInfo->P3cc);
4265 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
4267 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
4268 /* SR35[7] FP VSync polarity */
4269 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4270 /* SR30[5] FP HSync polarity */
4271 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
4273 if (chip_id == XG27)
4274 XGI_SetXG27FPBits(pVBInfo);
4275 else
4276 XGI_SetXG21FPBits(pVBInfo);
4278 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
4279 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4280 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
4281 /* si+St_ModeFlag */
4282 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4284 if (!(modeflag & Charx8Dot))
4285 xres = xres * 8 / 9;
4287 LVDSHT = xgifb_info->lvds_data.LVDSHT;
4289 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
4291 if (LVDSHBS > LVDSHT)
4292 LVDSHBS -= LVDSHT;
4294 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
4295 if (LVDSHRS > LVDSHT)
4296 LVDSHRS -= LVDSHT;
4298 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
4299 if (LVDSHRE > LVDSHT)
4300 LVDSHRE -= LVDSHT;
4302 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
4304 LVDSVT = xgifb_info->lvds_data.LVDSVT;
4306 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
4307 if (modeflag & DoubleScanMode)
4308 LVDSVBS += yres / 2;
4310 if (LVDSVBS > LVDSVT)
4311 LVDSVBS -= LVDSVT;
4313 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
4314 if (LVDSVRS > LVDSVT)
4315 LVDSVRS -= LVDSVT;
4317 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
4318 if (LVDSVRE > LVDSVT)
4319 LVDSVRE -= LVDSVT;
4321 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
4323 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
4324 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
4326 if (!(modeflag & Charx8Dot))
4327 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
4329 /* HT SR0B[1:0] CR00 */
4330 value = (LVDSHT >> 3) - 5;
4331 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
4332 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
4334 /* HBS SR0B[5:4] CR02 */
4335 value = (LVDSHBS >> 3) - 1;
4336 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
4337 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
4339 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4340 value = (LVDSHBE >> 3) - 1;
4341 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4342 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4343 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
4345 /* HRS SR0B[7:6] CR04 */
4346 value = (LVDSHRS >> 3) + 2;
4347 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
4348 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
4350 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4351 value--;
4352 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
4353 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
4355 /* HRE SR0C[2] CR05[4:0] */
4356 value = (LVDSHRE >> 3) + 2;
4357 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4358 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
4360 /* Panel HRE SR2F[7:2] */
4361 value--;
4362 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
4364 /* VT SR0A[0] CR07[5][0] CR06 */
4365 value = LVDSVT - 2;
4366 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4367 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4368 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
4369 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
4371 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4372 value = LVDSVBS - 1;
4373 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4374 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4375 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
4376 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
4378 /* VBE SR0A[4] CR16 */
4379 value = LVDSVBE - 1;
4380 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
4381 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
4383 /* VRS SR0A[3] CR7[7][2] CR10 */
4384 value = LVDSVRS - 1;
4385 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4386 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4387 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
4388 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
4390 if (chip_id == XG27) {
4391 /* Panel VRS SR35[2:0] SR34[7:0] */
4392 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4393 (value & 0x700) >> 8);
4394 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4395 } else {
4396 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4397 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4398 (value & 0x600) >> 9);
4399 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4400 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4403 /* VRE SR0A[5] CR11[3:0] */
4404 value = LVDSVRE - 1;
4405 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4406 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
4408 /* Panel VRE SR3F[7:2] */
4409 if (chip_id == XG27)
4410 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4411 (value << 2) & 0xFC);
4412 else
4413 /* SR3F[7] has to be 0, h/w bug */
4414 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4415 (value << 2) & 0x7C);
4417 for (temp = 0, value = 0; temp < 3; temp++) {
4419 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
4420 xgifb_reg_set(pVBInfo->P3c4,
4421 0x2B, xgifb_info->lvds_data.VCLKData1);
4422 xgifb_reg_set(pVBInfo->P3c4,
4423 0x2C, xgifb_info->lvds_data.VCLKData2);
4424 value += 0x10;
4427 if (!(modeflag & Charx8Dot)) {
4428 inb(pVBInfo->P3da); /* reset 3da */
4429 outb(0x13, pVBInfo->P3c0); /* set index */
4430 /* set data, panning = 0, shift left 1 dot*/
4431 outb(0x00, pVBInfo->P3c0);
4433 inb(pVBInfo->P3da); /* Enable Attribute */
4434 outb(0x20, pVBInfo->P3c0);
4436 inb(pVBInfo->P3da); /* reset 3da */
4441 /* --------------------------------------------------------------------- */
4442 /* Function : XGI_IsLCDON */
4443 /* Input : */
4444 /* Output : 0 : Skip PSC Control */
4445 /* 1: Disable PSC */
4446 /* Description : */
4447 /* --------------------------------------------------------------------- */
4448 static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
4450 unsigned short tempax;
4452 tempax = pVBInfo->VBInfo;
4453 if (tempax & SetCRT2ToDualEdge)
4454 return 0;
4455 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
4456 return 1;
4458 return 0;
4461 static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4462 struct xgi_hw_device_info *HwDeviceExtension,
4463 struct vb_device_info *pVBInfo)
4465 unsigned short tempah = 0;
4467 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4468 | VB_SIS302LV | VB_XGI301C)) {
4469 tempah = 0x3F;
4470 if (!(pVBInfo->VBInfo &
4471 (DisableCRT2Display | SetSimuScanMode))) {
4472 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4473 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4474 tempah = 0x7F; /* Disable Channel A */
4478 /* disable part4_1f */
4479 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
4481 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
4482 if (((pVBInfo->VBInfo &
4483 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
4484 (XGI_IsLCDON(pVBInfo)))
4485 /* LVDS Driver power down */
4486 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
4489 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4490 SetSimuScanMode))
4491 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
4493 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4494 /* Power down */
4495 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
4497 /* disable TV as primary VGA swap */
4498 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
4500 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
4501 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
4503 if ((pVBInfo->VBInfo &
4504 (DisableCRT2Display | SetSimuScanMode)) ||
4505 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
4506 (pVBInfo->VBInfo &
4507 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
4508 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4510 if ((pVBInfo->VBInfo &
4511 (DisableCRT2Display | SetSimuScanMode)) ||
4512 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
4513 (pVBInfo->VBInfo &
4514 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4515 /* save Part1 index 0 */
4516 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4517 /* BTDAC = 1, avoid VB reset */
4518 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4519 /* disable CRT2 */
4520 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4521 /* restore Part1 index 0 */
4522 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
4524 } else { /* {301} */
4525 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
4526 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4527 /* Disable CRT2 */
4528 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4529 /* Disable TV asPrimary VGA swap */
4530 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
4533 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
4534 | SetSimuScanMode))
4535 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
4539 /* --------------------------------------------------------------------- */
4540 /* Function : XGI_GetTVPtrIndex */
4541 /* Input : */
4542 /* Output : */
4543 /* Description : bx 0 : ExtNTSC */
4544 /* 1 : StNTSC */
4545 /* 2 : ExtPAL */
4546 /* 3 : StPAL */
4547 /* 4 : ExtHiTV */
4548 /* 5 : StHiTV */
4549 /* 6 : Ext525i */
4550 /* 7 : St525i */
4551 /* 8 : Ext525p */
4552 /* 9 : St525p */
4553 /* A : Ext750p */
4554 /* B : St750p */
4555 /* --------------------------------------------------------------------- */
4556 static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
4558 unsigned short tempbx = 0;
4560 if (pVBInfo->TVInfo & TVSetPAL)
4561 tempbx = 2;
4562 if (pVBInfo->TVInfo & TVSetHiVision)
4563 tempbx = 4;
4564 if (pVBInfo->TVInfo & TVSetYPbPr525i)
4565 tempbx = 6;
4566 if (pVBInfo->TVInfo & TVSetYPbPr525p)
4567 tempbx = 8;
4568 if (pVBInfo->TVInfo & TVSetYPbPr750p)
4569 tempbx = 10;
4570 if (pVBInfo->TVInfo & TVSimuMode)
4571 tempbx++;
4573 return tempbx;
4576 /* --------------------------------------------------------------------- */
4577 /* Function : XGI_GetTVPtrIndex2 */
4578 /* Input : */
4579 /* Output : bx 0 : NTSC */
4580 /* 1 : PAL */
4581 /* 2 : PALM */
4582 /* 3 : PALN */
4583 /* 4 : NTSC1024x768 */
4584 /* 5 : PAL-M 1024x768 */
4585 /* 6-7: reserved */
4586 /* cl 0 : YFilter1 */
4587 /* 1 : YFilter2 */
4588 /* ch 0 : 301A */
4589 /* 1 : 301B/302B/301LV/302LV */
4590 /* Description : */
4591 /* --------------------------------------------------------------------- */
4592 static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4593 unsigned char *tempch, struct vb_device_info *pVBInfo)
4595 *tempbx = 0;
4596 *tempcl = 0;
4597 *tempch = 0;
4599 if (pVBInfo->TVInfo & TVSetPAL)
4600 *tempbx = 1;
4602 if (pVBInfo->TVInfo & TVSetPALM)
4603 *tempbx = 2;
4605 if (pVBInfo->TVInfo & TVSetPALN)
4606 *tempbx = 3;
4608 if (pVBInfo->TVInfo & NTSC1024x768) {
4609 *tempbx = 4;
4610 if (pVBInfo->TVInfo & TVSetPALM)
4611 *tempbx = 5;
4614 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4615 | VB_SIS302LV | VB_XGI301C)) {
4616 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4617 & TVSimuMode)) {
4618 *tempbx += 8;
4619 *tempcl += 1;
4623 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4624 | VB_SIS302LV | VB_XGI301C))
4625 (*tempch)++;
4628 static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
4630 unsigned char tempah, tempbl, tempbh;
4632 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4633 | VB_SIS302LV | VB_XGI301C)) {
4634 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
4635 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
4636 tempbh = 0;
4637 tempbl = XGI301TVDelay;
4639 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4640 tempbl = tempbl >> 4;
4641 if (pVBInfo->VBInfo &
4642 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
4643 tempbh = XGI301LCDDelay;
4645 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
4646 tempbl = tempbh;
4649 tempbl &= 0x0F;
4650 tempbh &= 0xF0;
4651 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
4653 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4654 | SetCRT2ToTV)) { /* Channel B */
4655 tempah &= 0xF0;
4656 tempah |= tempbl;
4659 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4660 /* Channel A */
4661 tempah &= 0x0F;
4662 tempah |= tempbh;
4664 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
4669 static void XGI_SetLCDCap_A(unsigned short tempcx,
4670 struct vb_device_info *pVBInfo)
4672 unsigned short temp;
4674 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
4676 if (temp & LCDRGB18Bit) {
4677 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
4678 /* Enable Dither */
4679 (unsigned short) (0x20 | (tempcx & 0x00C0)));
4680 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
4681 } else {
4682 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
4683 (unsigned short) (0x30 | (tempcx & 0x00C0)));
4684 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
4688 /* --------------------------------------------------------------------- */
4689 /* Function : XGI_SetLCDCap_B */
4690 /* Input : cx -> LCD Capability */
4691 /* Output : */
4692 /* Description : */
4693 /* --------------------------------------------------------------------- */
4694 static void XGI_SetLCDCap_B(unsigned short tempcx,
4695 struct vb_device_info *pVBInfo)
4697 if (tempcx & EnableLCD24bpp) /* 24bits */
4698 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
4699 (unsigned short) (((tempcx & 0x00ff) >> 6)
4700 | 0x0c));
4701 else
4702 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
4703 (unsigned short) (((tempcx & 0x00ff) >> 6)
4704 | 0x18)); /* Enable Dither */
4707 static void XGI_LongWait(struct vb_device_info *pVBInfo)
4709 unsigned short i;
4711 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4713 if (!(i & 0xC0)) {
4714 for (i = 0; i < 0xFFFF; i++) {
4715 if (!(inb(pVBInfo->P3da) & 0x08))
4716 break;
4719 for (i = 0; i < 0xFFFF; i++) {
4720 if ((inb(pVBInfo->P3da) & 0x08))
4721 break;
4726 static void SetSpectrum(struct vb_device_info *pVBInfo)
4728 unsigned short index;
4730 index = XGI_GetLCDCapPtr(pVBInfo);
4732 /* disable down spectrum D[4] */
4733 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
4734 XGI_LongWait(pVBInfo);
4735 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
4736 XGI_LongWait(pVBInfo);
4738 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
4739 pVBInfo->LCDCapList[index].Spectrum_31);
4740 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
4741 pVBInfo->LCDCapList[index].Spectrum_32);
4742 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
4743 pVBInfo->LCDCapList[index].Spectrum_33);
4744 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
4745 pVBInfo->LCDCapList[index].Spectrum_34);
4746 XGI_LongWait(pVBInfo);
4747 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
4750 static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4752 unsigned short tempcx;
4754 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4756 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4757 VB_SIS302LV | VB_XGI301C)) {
4758 if (pVBInfo->VBType &
4759 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
4760 /* Set 301LV Capability */
4761 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
4762 (unsigned char) (tempcx & 0x1F));
4764 /* VB Driving */
4765 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
4766 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4767 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4768 | EnablePLLSPLOW)) >> 8));
4770 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4771 XGI_SetLCDCap_B(tempcx, pVBInfo);
4772 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4773 XGI_SetLCDCap_A(tempcx, pVBInfo);
4775 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
4776 if (tempcx & EnableSpectrum)
4777 SetSpectrum(pVBInfo);
4779 } else {
4780 /* LVDS,CH7017 */
4781 XGI_SetLCDCap_A(tempcx, pVBInfo);
4785 /* --------------------------------------------------------------------- */
4786 /* Function : XGI_SetAntiFlicker */
4787 /* Input : */
4788 /* Output : */
4789 /* Description : Set TV Customized Param. */
4790 /* --------------------------------------------------------------------- */
4791 static void XGI_SetAntiFlicker(struct vb_device_info *pVBInfo)
4793 unsigned short tempbx;
4795 unsigned char tempah;
4797 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
4798 return;
4800 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4801 tempbx &= 0xFE;
4802 tempah = TVAntiFlickList[tempbx];
4803 tempah = tempah << 4;
4805 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
4808 static void XGI_SetEdgeEnhance(struct vb_device_info *pVBInfo)
4810 unsigned short tempbx;
4812 unsigned char tempah;
4814 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4815 tempbx &= 0xFE;
4816 tempah = TVEdgeList[tempbx];
4817 tempah = tempah << 5;
4819 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
4822 static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
4824 unsigned short tempbx;
4826 unsigned char tempcl, tempch;
4828 unsigned long tempData;
4830 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4831 tempData = TVPhaseList[tempbx];
4833 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
4834 & 0x000000FF));
4835 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
4836 & 0x0000FF00) >> 8));
4837 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
4838 & 0x00FF0000) >> 16));
4839 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
4840 & 0xFF000000) >> 24));
4843 static void XGI_SetYFilter(unsigned short ModeIdIndex,
4844 struct vb_device_info *pVBInfo)
4846 unsigned short tempbx, index;
4847 unsigned char const *filterPtr;
4848 unsigned char tempcl, tempch, tempal;
4850 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4852 switch (tempbx) {
4853 case 0x00:
4854 case 0x04:
4855 filterPtr = NTSCYFilter1;
4856 break;
4858 case 0x01:
4859 filterPtr = PALYFilter1;
4860 break;
4862 case 0x02:
4863 case 0x05:
4864 case 0x0D:
4865 case 0x03:
4866 filterPtr = xgifb_palmn_yfilter1;
4867 break;
4869 case 0x08:
4870 case 0x0C:
4871 case 0x0A:
4872 case 0x0B:
4873 case 0x09:
4874 filterPtr = xgifb_yfilter2;
4875 break;
4877 default:
4878 return;
4881 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
4882 if (tempcl == 0)
4883 index = tempal * 4;
4884 else
4885 index = tempal * 7;
4887 if ((tempcl == 0) && (tempch == 1)) {
4888 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4889 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4890 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4891 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
4892 } else {
4893 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4894 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4895 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4896 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
4899 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4900 | VB_SIS302LV | VB_XGI301C)) {
4901 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4902 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4903 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
4907 /* --------------------------------------------------------------------- */
4908 /* Function : XGI_OEM310Setting */
4909 /* Input : */
4910 /* Output : */
4911 /* Description : Customized Param. for 301 */
4912 /* --------------------------------------------------------------------- */
4913 static void XGI_OEM310Setting(unsigned short ModeIdIndex,
4914 struct vb_device_info *pVBInfo)
4916 XGI_SetDelayComp(pVBInfo);
4918 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
4919 XGI_SetLCDCap(pVBInfo);
4921 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4922 XGI_SetPhaseIncr(pVBInfo);
4923 XGI_SetYFilter(ModeIdIndex, pVBInfo);
4924 XGI_SetAntiFlicker(pVBInfo);
4926 if (pVBInfo->VBType & VB_SIS301)
4927 XGI_SetEdgeEnhance(pVBInfo);
4931 /* --------------------------------------------------------------------- */
4932 /* Function : XGI_SetCRT2ModeRegs */
4933 /* Input : */
4934 /* Output : */
4935 /* Description : Origin code for crt2group */
4936 /* --------------------------------------------------------------------- */
4937 static void XGI_SetCRT2ModeRegs(struct vb_device_info *pVBInfo)
4939 unsigned short tempbl;
4940 short tempcl;
4942 unsigned char tempah;
4944 tempah = 0;
4945 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
4946 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4947 tempah &= ~0x10; /* BTRAMDAC */
4948 tempah |= 0x40; /* BTRAM */
4950 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
4951 | SetCRT2ToLCD)) {
4952 tempah = 0x40; /* BTDRAM */
4953 tempcl = pVBInfo->ModeType;
4954 tempcl -= ModeVGA;
4955 if (tempcl >= 0) {
4956 /* BT Color */
4957 tempah = (0x008 >> tempcl);
4958 if (tempah == 0)
4959 tempah = 1;
4960 tempah |= 0x040;
4962 if (pVBInfo->VBInfo & SetInSlaveMode)
4963 tempah ^= 0x50; /* BTDAC */
4967 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
4968 tempah = 0x08;
4969 tempbl = 0xf0;
4971 if (pVBInfo->VBInfo & DisableCRT2Display)
4972 goto reg_and_or;
4974 tempah = 0x00;
4975 tempbl = 0xff;
4977 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
4978 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4979 goto reg_and_or;
4981 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
4982 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
4983 tempbl &= 0xf7;
4984 tempah |= 0x01;
4985 goto reg_and_or;
4988 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4989 tempbl &= 0xf7;
4990 tempah |= 0x01;
4993 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
4994 goto reg_and_or;
4996 tempbl &= 0xf8;
4997 tempah = 0x01;
4999 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5000 tempah |= 0x02;
5002 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5003 tempah = tempah ^ 0x05;
5004 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5005 tempah = tempah ^ 0x01;
5008 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5009 tempah |= 0x08;
5011 reg_and_or:
5012 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5014 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
5015 | XGI_SetCRT2ToLCDA)) {
5016 tempah &= (~0x08);
5017 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5018 & SetInSlaveMode))) {
5019 tempah |= 0x010;
5021 tempah |= 0x080;
5023 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5024 tempah |= 0x020;
5025 if (pVBInfo->VBInfo & DriverMode)
5026 tempah = tempah ^ 0x20;
5029 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
5030 tempah = 0;
5032 if (pVBInfo->LCDInfo & SetLCDDualLink)
5033 tempah |= 0x40;
5035 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5036 if (pVBInfo->TVInfo & RPLLDIV2XO)
5037 tempah |= 0x40;
5040 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5041 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
5042 tempah |= 0x80;
5044 if (pVBInfo->LCDResInfo == Panel_1280x960)
5045 tempah |= 0x80;
5047 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
5050 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5051 | VB_SIS302LV | VB_XGI301C)) {
5052 tempah = 0;
5053 tempbl = 0xfb;
5055 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5056 tempbl = 0xff;
5057 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5058 tempah |= 0x04; /* shampoo 0129 */
5061 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
5062 tempah = 0x00;
5063 tempbl = 0xcf;
5064 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5065 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5066 tempah |= 0x30;
5069 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
5070 tempah = 0;
5071 tempbl = 0x3f;
5073 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5074 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5075 tempah |= 0xc0;
5077 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
5080 tempah = 0;
5081 tempbl = 0x7f;
5082 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
5083 tempbl = 0xff;
5084 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5085 tempah |= 0x80;
5088 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
5090 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
5091 if (pVBInfo->LCDInfo & SetLCDDualLink) {
5092 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5093 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
5099 void XGI_UnLockCRT2(struct vb_device_info *pVBInfo)
5101 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
5104 void XGI_LockCRT2(struct vb_device_info *pVBInfo)
5106 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
5109 unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5110 unsigned short ModeNo, unsigned short ModeIdIndex,
5111 struct vb_device_info *pVBInfo)
5113 const u8 LCDARefreshIndex[] = {
5114 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
5116 unsigned short RefreshRateTableIndex, i, index, temp;
5118 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
5119 index = index >> pVBInfo->SelectCRT2Rate;
5120 index &= 0x0F;
5122 if (pVBInfo->LCDInfo & LCDNonExpanding)
5123 index = 0;
5125 if (index > 0)
5126 index--;
5128 if (pVBInfo->SetFlag & ProgrammingCRT2) {
5129 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
5130 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
5132 if (index > temp)
5133 index = temp;
5137 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
5138 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
5139 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
5140 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5141 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
5142 index++;
5144 /* do the similar adjustment like XGISearchCRT1Rate() */
5145 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5146 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
5147 index++;
5149 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5150 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
5151 index++;
5155 i = 0;
5156 do {
5157 if (XGI330_RefIndex[RefreshRateTableIndex + i].
5158 ModeID != ModeNo)
5159 break;
5160 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
5161 temp &= ModeTypeMask;
5162 if (temp < pVBInfo->ModeType)
5163 break;
5164 i++;
5165 index--;
5167 } while (index != 0xFFFF);
5168 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5169 if (pVBInfo->VBInfo & SetInSlaveMode) {
5170 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
5171 Ext_InfoFlag;
5172 if (temp & InterlaceMode)
5173 i++;
5176 i--;
5177 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5178 temp = XGI_AjustCRT2Rate(ModeIdIndex, RefreshRateTableIndex,
5179 &i, pVBInfo);
5181 return RefreshRateTableIndex + i;
5184 static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
5185 struct xgi_hw_device_info *HwDeviceExtension,
5186 struct vb_device_info *pVBInfo)
5188 unsigned short RefreshRateTableIndex;
5190 pVBInfo->SetFlag |= ProgrammingCRT2;
5191 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5192 ModeIdIndex, pVBInfo);
5193 XGI_GetLVDSResInfo(ModeIdIndex, pVBInfo);
5194 XGI_GetLVDSData(ModeIdIndex, pVBInfo);
5195 XGI_ModCRT1Regs(ModeIdIndex, HwDeviceExtension, pVBInfo);
5196 XGI_SetLVDSRegs(ModeIdIndex, pVBInfo);
5197 XGI_SetCRT2ECLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5200 static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
5201 struct xgi_hw_device_info *HwDeviceExtension,
5202 struct vb_device_info *pVBInfo)
5204 unsigned short ModeIdIndex, RefreshRateTableIndex;
5206 pVBInfo->SetFlag |= ProgrammingCRT2;
5207 XGI_SearchModeID(ModeNo, &ModeIdIndex);
5208 pVBInfo->SelectCRT2Rate = 4;
5209 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5210 ModeIdIndex, pVBInfo);
5211 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5212 XGI_GetCRT2ResInfo(ModeIdIndex, pVBInfo);
5213 XGI_GetCRT2Data(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5214 XGI_PreSetGroup1(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5215 XGI_SetGroup1(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5216 XGI_SetLockRegs(ModeNo, ModeIdIndex, pVBInfo);
5217 XGI_SetGroup2(ModeNo, ModeIdIndex, pVBInfo);
5218 XGI_SetLCDRegs(ModeIdIndex, pVBInfo);
5219 XGI_SetTap4Regs(pVBInfo);
5220 XGI_SetGroup3(ModeIdIndex, pVBInfo);
5221 XGI_SetGroup4(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5222 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5223 XGI_SetGroup5(pVBInfo);
5224 XGI_AutoThreshold(pVBInfo);
5225 return 1;
5228 void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5230 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5231 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5232 0x05, 0x00 };
5234 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5236 unsigned char CR17, CR63, SR31;
5237 unsigned short temp;
5239 int i;
5241 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
5243 /* to fix XG42 single LCD sense to CRT+LCD */
5244 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
5245 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
5246 pVBInfo->P3d4, 0x53) | 0x02));
5248 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5249 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5250 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
5252 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5253 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
5255 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
5256 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
5258 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5259 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
5261 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
5262 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
5263 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
5264 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
5266 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
5268 for (i = 0; i < 8; i++)
5269 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
5271 for (i = 8; i < 11; i++)
5272 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
5273 CRTCData[i]);
5275 for (i = 11; i < 13; i++)
5276 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
5277 CRTCData[i]);
5279 for (i = 13; i < 16; i++)
5280 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
5281 CRTCData[i]);
5283 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
5284 & 0xE0));
5286 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5287 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5288 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
5290 outb(0x00, pVBInfo->P3c8);
5292 for (i = 0; i < 256 * 3; i++)
5293 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
5295 mdelay(1);
5297 XGI_WaitDisply(pVBInfo);
5298 temp = inb(pVBInfo->P3c2);
5300 if (temp & 0x10)
5301 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
5302 else
5303 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
5305 /* avoid display something, set BLACK DAC if not restore DAC */
5306 outb(0x00, pVBInfo->P3c8);
5308 for (i = 0; i < 256 * 3; i++)
5309 outb(0, (pVBInfo->P3c8 + 1));
5311 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5312 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5313 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
5315 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
5316 pVBInfo->P3d4, 0x53) & 0xFD));
5317 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
5320 static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5321 struct xgi_hw_device_info *HwDeviceExtension,
5322 struct vb_device_info *pVBInfo)
5324 unsigned short tempah;
5326 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5327 | VB_SIS302LV | VB_XGI301C)) {
5328 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5329 /* Power on */
5330 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
5332 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5333 SetCRT2ToRAMDAC)) {
5334 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5335 tempah &= 0xDF;
5336 if (pVBInfo->VBInfo & SetInSlaveMode) {
5337 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5338 tempah |= 0x20;
5340 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5341 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5343 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5345 if (!(tempah & 0x80))
5346 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5347 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
5350 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5351 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
5352 0x20); /* shampoo 0129 */
5353 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
5354 if (pVBInfo->VBInfo &
5355 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5356 /* LVDS PLL power on */
5357 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5358 0x7F);
5359 /* LVDS Driver power on */
5360 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
5364 tempah = 0x00;
5366 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5367 tempah = 0xc0;
5369 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5370 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5371 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5372 tempah = tempah & 0x40;
5373 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5374 tempah = tempah ^ 0xC0;
5378 /* EnablePart4_1F */
5379 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
5381 XGI_DisableGatingCRT(pVBInfo);
5382 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
5383 } /* 301 */
5384 else { /* LVDS */
5385 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
5386 | XGI_SetCRT2ToLCDA))
5387 /* enable CRT2 */
5388 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
5390 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5391 if (!(tempah & 0x80))
5392 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5394 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
5395 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
5396 } /* End of VB */
5399 static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5400 struct xgi_hw_device_info *HwDeviceExtension,
5401 unsigned short ModeNo, unsigned short ModeIdIndex,
5402 struct vb_device_info *pVBInfo)
5404 unsigned short RefreshRateTableIndex, temp;
5406 XGI_SetSeqRegs(pVBInfo);
5407 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
5408 XGI_SetCRTCRegs(pVBInfo);
5409 XGI_SetATTRegs(ModeIdIndex, pVBInfo);
5410 XGI_SetGRCRegs(pVBInfo);
5411 XGI_ClearExt1Regs(pVBInfo);
5413 if (HwDeviceExtension->jChipType == XG27) {
5414 if (pVBInfo->IF_DEF_LVDS == 0)
5415 XGI_SetDefaultVCLK(pVBInfo);
5418 temp = ~ProgrammingCRT2;
5419 pVBInfo->SetFlag &= temp;
5420 pVBInfo->SelectCRT2Rate = 0;
5422 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5423 | VB_SIS302LV | VB_XGI301C)) {
5424 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
5425 | SetInSlaveMode)) {
5426 pVBInfo->SetFlag |= ProgrammingCRT2;
5430 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5431 ModeIdIndex, pVBInfo);
5432 if (RefreshRateTableIndex != 0xFFFF) {
5433 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5434 XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
5435 pVBInfo, HwDeviceExtension);
5436 XGI_SetCRT1DE(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5437 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5438 HwDeviceExtension, pVBInfo);
5439 XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
5440 RefreshRateTableIndex, pVBInfo);
5443 if (HwDeviceExtension->jChipType >= XG21) {
5444 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
5445 if (temp & 0xA0) {
5447 if (HwDeviceExtension->jChipType == XG27)
5448 XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
5449 else
5450 XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
5452 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5453 RefreshRateTableIndex);
5455 xgifb_set_lcd(HwDeviceExtension->jChipType,
5456 pVBInfo, RefreshRateTableIndex);
5458 if (pVBInfo->IF_DEF_LVDS == 1)
5459 xgifb_set_lvds(xgifb_info,
5460 HwDeviceExtension->jChipType,
5461 ModeIdIndex, pVBInfo);
5465 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5466 XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
5467 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
5468 RefreshRateTableIndex, pVBInfo);
5469 XGI_LoadDAC(pVBInfo);
5472 unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5473 struct xgi_hw_device_info *HwDeviceExtension,
5474 unsigned short ModeNo)
5476 unsigned short ModeIdIndex;
5477 struct vb_device_info VBINF;
5478 struct vb_device_info *pVBInfo = &VBINF;
5480 pVBInfo->IF_DEF_LVDS = 0;
5482 if (HwDeviceExtension->jChipType >= XG20)
5483 pVBInfo->VBType = 0; /*set VBType default 0*/
5485 XGIRegInit(pVBInfo, xgifb_info->vga_base);
5487 /* for x86 Linux, XG21 LVDS */
5488 if (HwDeviceExtension->jChipType == XG21) {
5489 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
5490 pVBInfo->IF_DEF_LVDS = 1;
5492 if (HwDeviceExtension->jChipType == XG27) {
5493 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5494 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
5495 pVBInfo->IF_DEF_LVDS = 1;
5499 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
5500 if (ModeNo & 0x80)
5501 ModeNo = ModeNo & 0x7F;
5502 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
5504 if (HwDeviceExtension->jChipType < XG20)
5505 XGI_UnLockCRT2(pVBInfo);
5507 XGI_SearchModeID(ModeNo, &ModeIdIndex);
5509 if (HwDeviceExtension->jChipType < XG20) {
5510 XGI_GetVBInfo(ModeIdIndex, pVBInfo);
5511 XGI_GetTVInfo(ModeIdIndex, pVBInfo);
5512 XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
5513 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
5515 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5516 (!(pVBInfo->VBInfo & SwitchCRT2))) {
5517 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5518 ModeIdIndex, pVBInfo);
5520 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5521 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5522 HwDeviceExtension, pVBInfo);
5526 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
5527 switch (HwDeviceExtension->ujVBChipID) {
5528 case VB_CHIP_301: /* fall through */
5529 case VB_CHIP_302:
5530 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5531 pVBInfo); /*add for CRT2 */
5532 break;
5534 default:
5535 break;
5539 XGI_SetCRT2ModeRegs(pVBInfo);
5540 XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
5541 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
5542 } /* !XG20 */
5543 else {
5544 if (pVBInfo->IF_DEF_LVDS == 1)
5545 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
5546 ModeIdIndex))
5547 return 0;
5549 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
5550 Ext_ModeFlag & ModeTypeMask;
5552 pVBInfo->SetFlag = 0;
5553 pVBInfo->VBInfo = DisableCRT2Display;
5555 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
5557 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5558 ModeIdIndex, pVBInfo);
5560 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
5563 XGI_UpdateModeInfo(pVBInfo);
5565 if (HwDeviceExtension->jChipType < XG20)
5566 XGI_LockCRT2(pVBInfo);
5568 return 1;