3 #include <linux/delay.h>
4 #include <linux/types.h>
10 #include "vb_struct.h"
14 #include "vb_setmode.h"
17 #define IndexMask 0xff
19 static const unsigned short XGINew_MDA_DAC[] = {
20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
22 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
23 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
26 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
27 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
29 static const unsigned short XGINew_CGA_DAC[] = {
30 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
31 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
32 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
33 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
34 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
35 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
36 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
37 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
39 static const unsigned short XGINew_EGA_DAC[] = {
40 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x05, 0x15,
41 0x20, 0x30, 0x24, 0x34, 0x21, 0x31, 0x25, 0x35,
42 0x08, 0x18, 0x0C, 0x1C, 0x09, 0x19, 0x0D, 0x1D,
43 0x28, 0x38, 0x2C, 0x3C, 0x29, 0x39, 0x2D, 0x3D,
44 0x02, 0x12, 0x06, 0x16, 0x03, 0x13, 0x07, 0x17,
45 0x22, 0x32, 0x26, 0x36, 0x23, 0x33, 0x27, 0x37,
46 0x0A, 0x1A, 0x0E, 0x1E, 0x0B, 0x1B, 0x0F, 0x1F,
47 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
49 static const unsigned short XGINew_VGA_DAC[] = {
50 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
51 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
52 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
53 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
54 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
55 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
56 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
57 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
58 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
59 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
61 void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
63 pVBInfo->SModeIDTable = (struct XGI_StStruct *) XGI330_SModeIDTable;
64 pVBInfo->StandTable = (struct XGI_StandTableStruct *) XGI330_StandTable;
65 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
66 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
67 pVBInfo->XGINEWUB_CRT1Table
68 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
70 /* add for new UNIVGABIOS */
71 /* XGINew_UBLCDDataTable =
72 * (struct XGI_LCDDataTablStruct *) XGI_LCDDataTable; */
73 /* XGINew_UBTVDataTable = (XGI_TVDataTablStruct *) XGI_TVDataTable; */
75 pVBInfo->MCLKData = (struct XGI_MCLKDataStruct *) XGI340New_MCLKData;
76 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
77 pVBInfo->VCLKData = (struct XGI_VCLKDataStruct *) XGI_VCLKData;
78 pVBInfo->VBVCLKData = (struct XGI_VBVCLKDataStruct *) XGI_VBVCLKData;
79 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
80 pVBInfo->StResInfo = (struct XGI_StResInfoStruct *) XGI330_StResInfo;
82 = (struct XGI_ModeResInfoStruct *) XGI330_ModeResInfo;
84 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
85 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
86 pVBInfo->pSR07 = &XGI330_SR07;
87 pVBInfo->LCDResInfo = 0;
88 pVBInfo->LCDTypeInfo = 0;
93 pVBInfo->SR15 = XGI340_SR13;
94 pVBInfo->CR40 = XGI340_cr41;
95 pVBInfo->SR25 = XGI330_sr25;
96 pVBInfo->pSR31 = &XGI330_sr31;
97 pVBInfo->pSR32 = &XGI330_sr32;
98 pVBInfo->CR6B = XGI340_CR6B;
99 pVBInfo->CR6E = XGI340_CR6E;
100 pVBInfo->CR6F = XGI340_CR6F;
101 pVBInfo->CR89 = XGI340_CR89;
102 pVBInfo->AGPReg = XGI340_AGPReg;
103 pVBInfo->SR16 = XGI340_SR16;
104 pVBInfo->pCRCF = &XG40_CRCF;
105 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
107 pVBInfo->CR49 = XGI330_CR49;
108 pVBInfo->pSR1F = &XGI330_SR1F;
109 pVBInfo->pSR21 = &XGI330_SR21;
110 pVBInfo->pSR22 = &XGI330_SR22;
111 pVBInfo->pSR23 = &XGI330_SR23;
112 pVBInfo->pSR24 = &XGI330_SR24;
113 pVBInfo->pSR33 = &XGI330_SR33;
115 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
116 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
117 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
118 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
119 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
120 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
121 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
122 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
123 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
124 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
126 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
127 pVBInfo->PALTiming = XGI330_PALTiming;
128 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
129 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
130 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
131 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
132 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
133 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
134 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
135 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
136 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
137 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
138 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
139 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
141 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
142 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
143 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
145 /* 310 customization related */
146 if ((pVBInfo->VBType & VB_XGI301LV) || (pVBInfo->VBType & VB_XGI302LV))
147 pVBInfo->LCDCapList = XGI_LCDDLCapList;
149 pVBInfo->LCDCapList = XGI_LCDCapList;
151 if ((ChipType == XG21) || (ChipType == XG27))
152 pVBInfo->XG21_LVDSCapList = XGI21_LCDCapList;
154 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
155 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
157 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
159 if (ChipType >= XG20)
160 pVBInfo->pXGINew_CR97 = &XG20_CR97;
162 if (ChipType == XG27) {
164 = (struct XGI_MCLKDataStruct *) XGI27New_MCLKData;
165 pVBInfo->CR40 = XGI27_cr41;
166 pVBInfo->pXGINew_CR97 = &XG27_CR97;
167 pVBInfo->pSR36 = &XG27_SR36;
168 pVBInfo->pCR8F = &XG27_CR8F;
169 pVBInfo->pCRD0 = XG27_CRD0;
170 pVBInfo->pCRDE = XG27_CRDE;
171 pVBInfo->pSR40 = &XG27_SR40;
172 pVBInfo->pSR41 = &XG27_SR41;
176 if (ChipType >= XG20) {
177 pVBInfo->pDVOSetting = &XG21_DVOSetting;
178 pVBInfo->pCR2E = &XG21_CR2E;
179 pVBInfo->pCR2F = &XG21_CR2F;
180 pVBInfo->pCR46 = &XG21_CR46;
181 pVBInfo->pCR47 = &XG21_CR47;
186 static unsigned char XGI_GetModePtr(unsigned short ModeNo,
187 unsigned short ModeIdIndex,
188 struct vb_device_info *pVBInfo)
193 index = pVBInfo->SModeIDTable[ModeIdIndex].St_StTableIndex;
195 if (pVBInfo->ModeType <= 0x02)
196 index = 0x1B; /* 02 -> ModeEGA */
200 return index; /* Get pVBInfo->StandTable index */
203 static void XGI_SetSeqRegs(unsigned short ModeNo,
204 unsigned short StandTableIndex,
205 unsigned short ModeIdIndex,
206 struct vb_device_info *pVBInfo)
208 unsigned char tempah, SRdata;
209 unsigned short i, modeflag;
212 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
214 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
216 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
217 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
220 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
223 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
224 if (pVBInfo->VBInfo & SetInSlaveMode)
229 tempah |= 0x20; /* screen off */
230 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
232 for (i = 02; i <= 04; i++) {
233 /* Get SR2,3,4 from file */
234 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
235 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
239 static void XGI_SetMiscRegs(unsigned short StandTableIndex,
240 struct vb_device_info *pVBInfo)
242 unsigned char Miscdata;
244 /* Get Misc from file */
245 Miscdata = pVBInfo->StandTable[StandTableIndex].MISC;
247 if (pVBInfo->VBType & (VB_XGI301B |
252 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
258 outb(Miscdata, pVBInfo->P3c2); /* Set Misc(3c2) */
261 static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
262 unsigned short StandTableIndex,
263 struct vb_device_info *pVBInfo)
265 unsigned char CRTCdata;
268 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
270 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
272 for (i = 0; i <= 0x18; i++) {
273 /* Get CRTC from file */
274 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
275 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
278 if ((HwDeviceExtension->jChipType == XGI_630) &&
279 (HwDeviceExtension->jChipRevision == 0x30)) {
280 if (pVBInfo->VBInfo & SetInSlaveMode) {
281 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
282 xgifb_reg_set(pVBInfo->P3d4, 0x18, 0xFE);
289 static void XGI_SetATTRegs(unsigned short ModeNo,
290 unsigned short StandTableIndex,
291 unsigned short ModeIdIndex,
292 struct vb_device_info *pVBInfo)
294 unsigned char ARdata;
295 unsigned short i, modeflag;
298 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
300 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
302 for (i = 0; i <= 0x13; i++) {
303 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
304 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
306 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
309 if (pVBInfo->VBInfo & (SetCRT2ToTV
311 if (pVBInfo->VBInfo &
319 inb(pVBInfo->P3da); /* reset 3da */
320 outb(i, pVBInfo->P3c0); /* set index */
321 outb(ARdata, pVBInfo->P3c0); /* set data */
324 inb(pVBInfo->P3da); /* reset 3da */
325 outb(0x14, pVBInfo->P3c0); /* set index */
326 outb(0x00, pVBInfo->P3c0); /* set data */
327 inb(pVBInfo->P3da); /* Enable Attribute */
328 outb(0x20, pVBInfo->P3c0);
331 static void XGI_SetGRCRegs(unsigned short StandTableIndex,
332 struct vb_device_info *pVBInfo)
334 unsigned char GRdata;
337 for (i = 0; i <= 0x08; i++) {
338 /* Get GR from file */
339 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
340 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
343 if (pVBInfo->ModeType > ModeVGA) {
344 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
345 GRdata &= 0xBF; /* 256 color disable */
346 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
350 static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
354 for (i = 0x0A; i <= 0x0E; i++)
355 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
358 static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
361 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
362 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
363 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
365 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
366 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
367 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
369 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
373 static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
374 unsigned short ModeIdIndex,
375 unsigned short RefreshRateTableIndex, unsigned short *i,
376 struct vb_device_info *pVBInfo)
378 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
382 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
384 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
386 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
387 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
390 if (pVBInfo->IF_DEF_LVDS == 0) {
391 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
392 tempax |= SupportRAMDAC2;
394 if (pVBInfo->VBType & VB_XGI301C)
395 tempax |= SupportCRT2in301C;
399 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
400 tempax |= SupportLCD;
402 if (pVBInfo->LCDResInfo != Panel1280x1024) {
403 if (pVBInfo->LCDResInfo != Panel1280x960) {
404 if (pVBInfo->LCDInfo &
415 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiTV */
416 if ((pVBInfo->VBType & VB_XGI301LV) &&
417 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
418 tempax |= SupportYPbPr;
419 if (pVBInfo->VBInfo & SetInSlaveMode) {
430 tempax |= SupportHiVisionTV;
431 if (pVBInfo->VBInfo & SetInSlaveMode) {
446 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
450 SetCRT2ToHiVisionTV)) {
453 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
454 | VB_XGI301LV | VB_XGI302LV
456 tempax |= SupportTV1024;
459 if (!(pVBInfo->VBInfo & SetPALTV)) {
460 if (modeflag & NoSupportSimuTV) {
461 if (pVBInfo->VBInfo &
463 if (!(pVBInfo->VBInfo &
472 } else { /* for LVDS */
473 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
474 tempax |= SupportLCD;
477 return 0; /* 1024x768 */
479 if (pVBInfo->LCDResInfo < Panel1024x768) {
481 return 0; /* 800x600 */
484 return 0; /* 512x384 */
489 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
491 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
493 if (infoflag & tempax)
500 for ((*i) = 0;; (*i)++) {
501 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
503 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
508 if (infoflag & tempax)
514 static void XGI_SetSync(unsigned short RefreshRateTableIndex,
515 struct vb_device_info *pVBInfo)
517 unsigned short sync, temp;
520 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
524 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
527 static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
528 struct xgi_hw_device_info *HwDeviceExtension)
530 unsigned char data, data1, pushax;
533 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
534 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
535 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
538 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
540 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
542 data = pVBInfo->TimingH[0].data[0];
543 xgifb_reg_set(pVBInfo->P3d4, 0, data);
545 for (i = 0x01; i <= 0x04; i++) {
546 data = pVBInfo->TimingH[0].data[i];
547 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
550 for (i = 0x05; i <= 0x06; i++) {
551 data = pVBInfo->TimingH[0].data[i];
552 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
555 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
557 data = pVBInfo->TimingH[0].data[7];
560 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
562 if (HwDeviceExtension->jChipType >= XG20) {
563 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
565 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
566 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
572 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
575 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
580 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
581 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
587 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
591 static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
592 unsigned short ModeNo,
593 struct vb_device_info *pVBInfo)
598 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
599 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
600 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
602 for (i = 0x00; i <= 0x01; i++) {
603 data = pVBInfo->TimingV[0].data[i];
604 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
607 for (i = 0x02; i <= 0x03; i++) {
608 data = pVBInfo->TimingV[0].data[i];
609 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
612 for (i = 0x04; i <= 0x05; i++) {
613 data = pVBInfo->TimingV[0].data[i];
614 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
617 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
619 data = pVBInfo->TimingV[0].data[6];
622 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
624 data = pVBInfo->TimingV[0].data[6];
629 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
631 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
637 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
640 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
643 static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
644 unsigned short RefreshRateTableIndex,
645 struct vb_device_info *pVBInfo,
646 struct xgi_hw_device_info *HwDeviceExtension)
648 unsigned char index, data;
652 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
653 index = index & IndexMask;
655 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
657 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
659 for (i = 0; i < 8; i++)
660 pVBInfo->TimingH[0].data[i]
661 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
663 for (i = 0; i < 7; i++)
664 pVBInfo->TimingV[0].data[i]
665 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
667 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
669 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
671 if (pVBInfo->ModeType > 0x03)
672 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
675 /* --------------------------------------------------------------------- */
676 /* Function : XGI_SetXG21CRTC */
677 /* Input : Stand or enhance CRTC table */
678 /* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
679 /* Description : Set LCD timing */
680 /* --------------------------------------------------------------------- */
681 static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
682 unsigned short RefreshRateTableIndex,
683 struct vb_device_info *pVBInfo)
685 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
686 unsigned short Temp1, Temp2, Temp3;
688 if (ModeNo <= 0x13) {
689 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
691 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
692 /* SR2E [7:0]->HRS */
693 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
694 /* Tempbx: CR05 HRE */
695 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
696 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
698 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
699 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
700 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
701 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
702 Tempdx <<= 2; /* Tempdx << 2 */
703 /* SR2F [7:2]->HRE */
704 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
705 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
707 /* Tempax: CR16 VRS */
708 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
709 Tempbx = Tempax; /* Tempbx=Tempax */
710 Tempax &= 0x01; /* Tempax: VRS[0] */
711 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS */
713 /* Tempax: CR7 VRS */
714 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
715 Tempdx = Tempbx >> 1; /* Tempdx: VRS[7:1] */
716 Tempcx = Tempax & 0x04; /* Tempcx: CR7[2] */
717 Tempcx <<= 5; /* Tempcx[7]: VRS[8] */
718 Tempdx |= Tempcx; /* Tempdx: VRS[8:1] */
719 /* SR34[7:0]: VRS[8:1] */
720 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempdx);
722 /* Temp1[8]: VRS[8] unsigned char -> unsigned short */
724 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
725 Tempax &= 0x80; /* Tempax[7]: CR7[7] */
726 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
727 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
730 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
731 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
732 Temp2 = Temp1 & 0x3F0; /* Temp2[9:4]: VRS[9:4] */
733 Temp2 |= Tempax; /* Temp2[9:0]: VRE[9:0] */
734 Temp3 = Temp1 & 0x0F; /* Temp3[3:0]: VRS[3:0] */
735 if (Tempax < Temp3) /* VRE[3:0]<VRS[3:0] */
736 Temp2 |= 0x10; /* Temp2: VRE + 0x10 */
737 Temp2 &= 0xFF; /* Temp2[7:0]: VRE[7:0] */
738 Tempax = (unsigned char) Temp2; /* Tempax[7:0]: VRE[7:0] */
739 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
740 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
741 Temp1 >>= 9; /* [10:9]->[1:0] */
742 Tempbx = (unsigned char) Temp1; /* Tempbx[1:0]: VRS[10:9] */
743 Tempax |= Tempbx; /* VRE[5:0]VRS[10:9] */
745 /* SR3F D[7:2]->VRE D[1:0]->VRS */
746 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
748 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
749 /* Tempax: CR4 HRS */
750 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
751 Tempcx = Tempax; /* Tempcx: HRS */
753 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
755 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
756 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
757 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
758 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
759 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
761 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
762 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
764 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
765 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
766 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
767 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
769 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
770 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
772 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
773 if (Tempax < Tempcx) /* HRE < HRS */
774 Temp2 |= 0x40; /* Temp2 + 0x40 */
777 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
778 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
779 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
780 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
781 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
782 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
783 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
786 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
787 Tempbx = Tempax; /* Tempbx: VRS */
788 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
789 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
791 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
792 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
793 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
794 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
795 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
796 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
798 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
799 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
800 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
802 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
803 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
805 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
806 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
808 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
809 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
811 /* Tempax: CR11 VRE */
812 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
813 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
815 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
816 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
817 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
818 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
819 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
820 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
822 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
823 if (Tempax < Temp3) /* VRE < VRS */
824 Temp2 |= 0x20; /* VRE + 0x20 */
827 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
828 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
829 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
830 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
831 Tempbx = (unsigned char) Temp1;
832 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
834 /* SR3F D[7:2]->VRE D[1:0]->VRS */
835 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
839 static void XGI_SetXG27CRTC(unsigned short ModeNo,
840 unsigned short ModeIdIndex,
841 unsigned short RefreshRateTableIndex,
842 struct vb_device_info *pVBInfo)
844 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
846 if (ModeNo <= 0x13) {
847 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
849 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
850 /* SR2E [7:0]->HRS */
851 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
852 /* Tempbx: CR05 HRE */
853 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
854 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
856 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
857 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
858 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
859 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
860 Tempdx <<= 2; /* Tempdx << 2 */
861 /* SR2F [7:2]->HRE */
862 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
863 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
865 /* Tempax: CR10 VRS */
866 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
867 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax); /* SR34[7:0]->VRS */
868 Tempcx = Tempax; /* Tempcx=Tempax=VRS[7:0] */
869 /* Tempax[7][2]: CR7[7][2] VRS[9][8] */
870 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
871 Tempbx = Tempax; /* Tempbx=CR07 */
872 Tempax &= 0x04; /* Tempax[2]: CR07[2] VRS[8] */
874 /* SR35 D[0]->VRS D[8] */
875 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
876 Tempcx |= (Tempax << 8); /* Tempcx[8] |= VRS[8] */
877 Tempcx |= (Tempbx & 0x80) << 2; /* Tempcx[9] |= VRS[9] */
880 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
881 Tempax &= 0x0F; /* Tempax: VRE[3:0] */
882 Tempbx = Tempcx; /* Tempbx=Tempcx=VRS[9:0] */
883 Tempbx &= 0x3F0; /* Tempbx[9:4]: VRS[9:4] */
884 Tempbx |= Tempax; /* Tempbx[9:0]: VRE[9:0] */
885 if (Tempax <= (Tempcx & 0x0F)) /* VRE[3:0]<=VRS[3:0] */
886 Tempbx |= 0x10; /* Tempbx: VRE + 0x10 */
887 /* Tempax[7:0]: VRE[7:0] */
888 Tempax = (unsigned char) Tempbx & 0xFF;
889 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
890 Tempcx = (Tempcx & 0x600) >> 8; /* Tempcx VRS[10:9] */
891 /* SR3F D[7:2]->VRE D[5:0] */
892 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
893 /* SR35 D[2:1]->VRS[10:9] */
894 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x06, Tempcx);
896 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
897 /* Tempax: CR4 HRS */
898 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
899 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
901 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
904 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
905 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
906 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
908 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
909 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
910 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
912 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
913 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
914 Tempax <<= 3; /* Tempax[5]: HRE[5] */
915 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
917 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
918 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
920 /* Tempax: CR4 HRS */
921 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
922 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
923 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
924 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
926 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
927 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
928 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
929 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
930 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
931 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
932 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
935 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
936 /* SR34[7:0]->VRS[7:0] */
937 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
939 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
940 /* CR7[7][2] VRS[9][8] */
941 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
942 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
943 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
944 Tempax >>= 2; /* Tempax[0]: VRS[8] */
945 /* SR35[0]: VRS[8] */
946 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
947 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
948 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
950 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
951 Tempax &= 0x08; /* SR0A[3] VRS[10] */
952 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
954 /* Tempax: CR11 VRE */
955 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
956 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
958 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
959 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
960 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
961 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
962 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
963 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
964 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
966 if (Tempbx <= Tempcx) /* VRE <= VRS */
967 Tempbx |= 0x20; /* VRE + 0x20 */
969 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
970 Tempax = (Tempbx << 2) & 0xFF;
971 /* SR3F[7:2]:VRE[5:0] */
972 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
973 Tempax = Tempcx >> 8;
974 /* SR35[2:0]:VRS[10:8] */
975 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
979 static void xgifb_set_lcd(int chip_id,
980 struct vb_device_info *pVBInfo,
981 unsigned short RefreshRateTableIndex,
982 unsigned short ModeNo)
984 unsigned short Data, Temp, b3CC;
985 unsigned short XGI_P3cc;
987 XGI_P3cc = pVBInfo->P3cc;
989 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
990 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
991 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
992 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
994 if (chip_id == XG27) {
995 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
996 if ((Temp & 0x03) == 0) { /* dual 12 */
997 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
998 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
1002 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
1003 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
1004 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
1005 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
1006 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
1009 if (chip_id == XG27) {
1010 XGI_SetXG27FPBits(pVBInfo);
1012 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1015 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
1016 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
1020 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
1022 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
1023 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
1025 if (ModeNo <= 0x13) {
1026 b3CC = (unsigned char) inb(XGI_P3cc);
1028 /* Hsync polarity */
1029 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
1031 /* Vsync polarity */
1032 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1034 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1036 /* Hsync polarity */
1037 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
1039 /* Vsync polarity */
1040 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1044 /* --------------------------------------------------------------------- */
1045 /* Function : XGI_UpdateXG21CRTC */
1047 /* Output : CRT1 CRTC */
1048 /* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
1049 /* --------------------------------------------------------------------- */
1050 static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1051 struct vb_device_info *pVBInfo,
1052 unsigned short RefreshRateTableIndex)
1056 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
1057 if (ModeNo <= 0x13) {
1058 for (i = 0; i < 12; i++) {
1059 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID)
1063 if (ModeNo == 0x2E &&
1064 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1067 else if (ModeNo == 0x2E &&
1068 (pVBInfo->RefIndex[RefreshRateTableIndex].
1069 Ext_CRT1CRTC == RES640x480x72))
1071 else if (ModeNo == 0x2F)
1073 else if (ModeNo == 0x50)
1075 else if (ModeNo == 0x59)
1080 xgifb_reg_set(pVBInfo->P3d4, 0x02,
1081 pVBInfo->UpdateCRT1[index].CR02);
1082 xgifb_reg_set(pVBInfo->P3d4, 0x03,
1083 pVBInfo->UpdateCRT1[index].CR03);
1084 xgifb_reg_set(pVBInfo->P3d4, 0x15,
1085 pVBInfo->UpdateCRT1[index].CR15);
1086 xgifb_reg_set(pVBInfo->P3d4, 0x16,
1087 pVBInfo->UpdateCRT1[index].CR16);
1091 static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
1092 unsigned short ModeNo, unsigned short ModeIdIndex,
1093 unsigned short RefreshRateTableIndex,
1094 struct vb_device_info *pVBInfo)
1096 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
1100 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1102 if (ModeNo <= 0x13) {
1103 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1104 tempax = pVBInfo->StResInfo[resindex].HTotal;
1105 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1107 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1108 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1109 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1112 if (modeflag & HalfDCLK)
1113 tempax = tempax >> 1;
1115 if (ModeNo > 0x13) {
1116 if (modeflag & HalfDCLK)
1117 tempax = tempax << 1;
1119 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1121 if (temp & InterlaceMode)
1122 tempbx = tempbx >> 1;
1124 if (modeflag & DoubleScanMode)
1125 tempbx = tempbx << 1;
1130 /* if (!(modeflag & Charx8Dot)) */
1137 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1138 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1140 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
1141 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
1142 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
1143 (unsigned short) ((tempcx & 0x0ff00) >> 10));
1144 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
1146 tempbx = tempbx >> 8;
1154 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
1155 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
1162 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
1163 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
1166 unsigned short XGI_GetResInfo(unsigned short ModeNo,
1167 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
1169 unsigned short resindex;
1173 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1175 /* si+Ext_ResInfo */
1176 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1180 static void XGI_SetCRT1Offset(unsigned short ModeNo,
1181 unsigned short ModeIdIndex,
1182 unsigned short RefreshRateTableIndex,
1183 struct xgi_hw_device_info *HwDeviceExtension,
1184 struct vb_device_info *pVBInfo)
1186 unsigned short temp, ah, al, temp2, i, DisplayUnit;
1189 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1191 temp = pVBInfo->ScreenOffset[temp];
1193 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1194 temp2 &= InterlaceMode;
1199 temp2 = pVBInfo->ModeType - ModeEGA;
1224 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1225 temp = temp * temp2 + temp2 / 2;
1232 temp = temp >> 8; /* ah */
1234 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
1237 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
1239 temp = (unsigned char) temp2;
1240 temp &= 0xFF; /* al */
1241 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
1243 /* SetDisplayUnit */
1244 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1245 temp2 &= InterlaceMode;
1249 DisplayUnit = DisplayUnit << 5;
1250 ah = (DisplayUnit & 0xff00) >> 8;
1251 al = DisplayUnit & 0x00ff;
1257 if (HwDeviceExtension->jChipType >= XG20)
1258 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1261 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
1264 static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1265 unsigned short ModeIdIndex,
1266 unsigned short RefreshRateTableIndex,
1267 struct xgi_hw_device_info *HwDeviceExtension,
1268 struct vb_device_info *pVBInfo)
1270 unsigned short LCDXlat1VCLK[4] = { VCLK65 + 2,
1274 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1278 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
1279 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1283 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1288 unsigned short CRT2Index, VCLKIndex;
1289 unsigned short modeflag, resinfo;
1291 if (ModeNo <= 0x13) {
1293 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1294 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1295 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1297 /* si+Ext_ResInfo */
1298 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1299 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1300 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1304 if (pVBInfo->IF_DEF_LVDS == 0) {
1305 CRT2Index = CRT2Index >> 6; /* for LCD */
1306 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /*301b*/
1307 if (pVBInfo->LCDResInfo != Panel1024x768)
1308 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1310 VCLKIndex = LCDXlat1VCLK[CRT2Index];
1311 } else { /* for TV */
1312 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1313 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
1314 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1315 VCLKIndex = HiTVVCLKDIV2;
1318 VCLKIndex = HiTVVCLK;
1322 if (pVBInfo->SetFlag & TVSimuMode) {
1323 if (modeflag & Charx8Dot) {
1335 if (pVBInfo->VBType & VB_XGI301LV) {
1336 if (!(pVBInfo->VBExtInfo ==
1340 if (!(pVBInfo->VBExtInfo
1345 if (!(pVBInfo->VBExtInfo
1349 if (!(pVBInfo->SetFlag
1358 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1359 if (pVBInfo->SetFlag &
1361 VCLKIndex = TVVCLKDIV2;
1369 } else { /* for CRT2 */
1371 VCLKIndex = (unsigned char) inb(
1372 (pVBInfo->P3ca + 0x02));
1373 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1374 if (ModeNo > 0x13) {
1375 /* di+Ext_CRTVCLK */
1378 RefreshRateTableIndex].
1380 VCLKIndex &= IndexMask;
1386 VCLKIndex = CRT2Index;
1388 VCLKIndex = CRT2Index;
1390 VCLKIndex = VCLKIndex >> 6;
1391 if ((pVBInfo->LCDResInfo == Panel800x600) ||
1392 (pVBInfo->LCDResInfo == Panel320x480))
1393 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
1394 else if ((pVBInfo->LCDResInfo == Panel1024x768) ||
1395 (pVBInfo->LCDResInfo == Panel1024x768x75))
1396 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1398 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
1400 /* VCLKIndex = VCLKIndex&IndexMask; */
1405 static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1406 unsigned short ModeIdIndex,
1407 struct xgi_hw_device_info *HwDeviceExtension,
1408 unsigned short RefreshRateTableIndex,
1409 struct vb_device_info *pVBInfo)
1411 unsigned char index, data;
1412 unsigned short vclkindex;
1414 if (pVBInfo->IF_DEF_LVDS == 1) {
1415 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1416 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1417 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1418 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
1419 pVBInfo->VCLKData[index].SR2B);
1420 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
1421 pVBInfo->VCLKData[index].SR2C);
1422 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1423 } else if ((pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
1424 | VB_XGI302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1426 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1427 RefreshRateTableIndex, HwDeviceExtension,
1429 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1430 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1431 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
1432 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
1433 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
1434 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1435 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1437 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1438 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1439 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1440 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
1441 pVBInfo->VCLKData[index].SR2B);
1442 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
1443 pVBInfo->VCLKData[index].SR2C);
1444 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1447 if (HwDeviceExtension->jChipType >= XG20) {
1448 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1450 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
1451 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
1452 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
1459 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1464 static void XGI_SetCRT1FIFO(unsigned short ModeNo,
1465 struct xgi_hw_device_info *HwDeviceExtension,
1466 struct vb_device_info *pVBInfo)
1468 unsigned short data;
1470 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1472 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
1474 if (ModeNo > 0x13) {
1475 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1476 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1478 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1479 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1481 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
1483 if (HwDeviceExtension->jChipType == XG27) {
1484 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
1485 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1487 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
1489 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
1490 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1492 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
1496 if (HwDeviceExtension->jChipType == XG21)
1497 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
1500 static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1501 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1502 struct vb_device_info *pVBInfo)
1504 unsigned short data, data2 = 0;
1507 unsigned char index;
1512 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1514 VCLK = pVBInfo->VCLKData[index].CLOCK;
1517 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
1520 data |= 0x0c; /* VCLK > 200 */
1522 if (HwDeviceExtension->jChipType >= XG20)
1523 data &= ~0x04; /* 2 pixel mode */
1525 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
1527 if (HwDeviceExtension->jChipType < XG20) {
1528 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
1532 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
1535 /* Jong for Adavantech LCD ripple issue
1536 if ((VCLK >= 0) && (VCLK < 135))
1538 else if ((VCLK >= 135) && (VCLK < 160))
1540 else if ((VCLK >= 160) && (VCLK < 260))
1542 else if (VCLK > 260)
1547 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
1548 if (HwDeviceExtension->jChipType >= XG27)
1549 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
1553 static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
1554 unsigned short ModeNo, unsigned short ModeIdIndex,
1555 unsigned short RefreshRateTableIndex,
1556 struct vb_device_info *pVBInfo)
1558 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1561 if (ModeNo > 0x13) {
1562 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1563 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1566 /* si+St_ModeFlag */
1567 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1569 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
1570 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
1579 if (ModeNo > 0x13) {
1580 if (pVBInfo->ModeType > 0x02) {
1582 data3 = pVBInfo->ModeType - ModeVGA;
1588 data &= InterlaceMode;
1593 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
1594 /* xgifb_reg_set(pVBInfo->P3c4,0x06,data2); */
1595 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1597 xres = pVBInfo->StResInfo[resindex].HTotal;
1599 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
1602 if (infoflag & InterlaceMode) {
1605 else if (xres == 1280)
1609 data2 = data & 0x00FF;
1610 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
1611 data2 = (data & 0xFF00) >> 8;
1612 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
1614 if (modeflag & HalfDCLK)
1615 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
1619 if (modeflag & LineCompareOff)
1622 if (ModeNo > 0x13) {
1623 if (pVBInfo->ModeType == ModeEGA)
1627 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
1629 if (pVBInfo->ModeType != ModeText) {
1631 if (pVBInfo->ModeType != ModeEGA)
1634 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
1636 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1639 /* if (modeflag&HalfDCLK) //030305 fix lowresolution bug */
1640 /* if (XGINew_IF_DEF_NEW_LOWRES) */
1641 /* XGI_VesaLowResolution(ModeNo, ModeIdIndex);
1642 * //030305 fix lowresolution bug */
1644 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1646 if (HwDeviceExtension->jChipType == XG27) {
1651 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1652 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
1653 } else if (HwDeviceExtension->jChipType >= XG20) {
1658 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1659 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
1665 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1670 static void XGI_WriteDAC(unsigned short dl,
1674 struct vb_device_info *pVBInfo)
1676 unsigned short temp, bh, bl;
1695 outb((unsigned short) dh, pVBInfo->P3c9);
1696 outb((unsigned short) bh, pVBInfo->P3c9);
1697 outb((unsigned short) bl, pVBInfo->P3c9);
1700 static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
1701 struct vb_device_info *pVBInfo)
1703 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
1705 const unsigned short *table = NULL;
1708 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1710 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1712 data &= DACInfoFlag;
1716 table = XGINew_MDA_DAC;
1717 else if (data == 0x08)
1718 table = XGINew_CGA_DAC;
1719 else if (data == 0x10)
1720 table = XGINew_EGA_DAC;
1721 else if (data == 0x18) {
1723 table = XGINew_VGA_DAC;
1731 outb(0xFF, pVBInfo->P3c6);
1732 outb(0x00, pVBInfo->P3c8);
1734 for (i = 0; i < j; i++) {
1737 for (k = 0; k < 3; k++) {
1746 outb(data2, pVBInfo->P3c9);
1752 for (i = 16; i < 32; i++) {
1755 for (k = 0; k < 3; k++)
1756 outb(data, pVBInfo->P3c9);
1761 for (m = 0; m < 9; m++) {
1766 for (n = 0; n < 3; n++) {
1767 for (o = 0; o < 5; o++) {
1772 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1777 for (o = 0; o < 3; o++) {
1782 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1793 static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1794 unsigned short ModeIdIndex,
1795 struct vb_device_info *pVBInfo)
1797 unsigned short resindex, xres, yres, modeflag;
1801 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1803 /* si+Ext_ResInfo */
1804 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1806 /* if (ModeNo > 0x13) */
1807 /* modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; */
1809 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; */
1813 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1815 /* si+Ext_ResInfo */
1816 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1818 /* resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); */
1820 if (ModeNo <= 0x13) {
1821 xres = pVBInfo->StResInfo[resindex].HTotal;
1822 yres = pVBInfo->StResInfo[resindex].VTotal;
1824 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1825 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1827 if (ModeNo > 0x13) {
1828 if (modeflag & HalfDCLK)
1831 if (modeflag & DoubleScanMode)
1834 /* if (modeflag & Charx8Dot) */
1841 pVBInfo->VGAHDE = xres;
1842 pVBInfo->HDE = xres;
1843 pVBInfo->VGAVDE = yres;
1844 pVBInfo->VDE = yres;
1847 static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1848 unsigned short ModeIdIndex,
1849 unsigned short RefreshRateTableIndex,
1850 struct vb_device_info *pVBInfo)
1852 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1854 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1858 if (ModeNo <= 0x13) {
1859 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1860 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1862 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1863 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1866 tempal = tempal & 0x0f;
1868 if (tempbx <= 1) { /* ExpLink */
1869 if (ModeNo <= 0x13) {
1870 /* find no Ext_CRT2CRTC2 */
1871 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1873 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1877 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1879 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1882 tempal = pVBInfo->RefIndex[
1883 RefreshRateTableIndex].
1888 tempal = (tempal >> 4);
1890 tempal = (tempal & 0x0f);
1893 tempcx = LCDLenList[tempbx]; /* mov cl,byte ptr cs:LCDLenList[bx] */
1895 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1896 if ((tempbx == 5) || (tempbx) == 7)
1897 tempcx = LCDDesDataLen2;
1898 else if ((tempbx == 3) || (tempbx == 8))
1899 tempcx = LVDSDesDataLen2;
1901 /* mov di, word ptr cs:LCDDataList[bx] */
1902 /* tempdi = pVideoMemory[LCDDataList + tempbx * 2] |
1903 (pVideoMemory[LCDDataList + tempbx * 2 + 1] << 8); */
1908 tempdi = xgifb_epllcd_crt1;
1911 tempdi = XGI_EPLLCDDataPtr;
1914 tempdi = XGI_EPLLCDDesDataPtr;
1917 tempdi = XGI_LCDDataTable;
1920 tempdi = XGI_LCDDesDataTable;
1923 tempdi = XGI_EPLCHLCDRegPtr;
1934 if (tempdi == NULL) /* OEMUtil */
1940 while (tempdi[i].PANELID != 0xff) {
1941 tempdx = pVBInfo->LCDResInfo;
1942 if (tempbx & 0x0080) { /* OEMUtil */
1943 tempbx &= (~0x0080);
1944 tempdx = pVBInfo->LCDTypeInfo;
1947 if (pVBInfo->LCDInfo & EnableScalingLCD)
1948 tempdx &= (~PanelResInfo);
1950 if (tempdi[i].PANELID == tempdx) {
1951 tempbx = tempdi[i].MASK;
1952 tempdx = pVBInfo->LCDInfo;
1954 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1955 tempdx |= SetLCDStdMode;
1957 if (modeflag & HalfDCLK)
1958 tempdx |= SetLCDLowResolution;
1961 if (tempbx == tempdi[i].CAP)
1968 switch (tempdi[i].DATAPTR) {
1970 return &XGI_LVDSCRT11024x768_1_H[tempal];
1973 return &XGI_LVDSCRT11024x768_2_H[tempal];
1976 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1979 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1982 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1985 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1988 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1991 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1994 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1997 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
2000 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
2005 } else if (table == 1) {
2006 switch (tempdi[i].DATAPTR) {
2008 return &XGI_LVDSCRT11024x768_1_V[tempal];
2011 return &XGI_LVDSCRT11024x768_2_V[tempal];
2014 return &XGI_LVDSCRT11280x1024_1_V[tempal];
2017 return &XGI_LVDSCRT11280x1024_2_V[tempal];
2020 return &XGI_LVDSCRT11400x1050_1_V[tempal];
2023 return &XGI_LVDSCRT11400x1050_2_V[tempal];
2026 return &XGI_LVDSCRT11600x1200_1_V[tempal];
2029 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
2032 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
2035 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
2038 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
2043 } else if (table == 2) {
2044 switch (tempdi[i].DATAPTR) {
2046 return &XGI_LVDS1024x768Data_1[tempal];
2049 return &XGI_LVDS1024x768Data_2[tempal];
2052 return &XGI_LVDS1280x1024Data_1[tempal];
2055 return &XGI_LVDS1280x1024Data_2[tempal];
2058 return &XGI_LVDS1400x1050Data_1[tempal];
2061 return &XGI_LVDS1400x1050Data_2[tempal];
2064 return &XGI_LVDS1600x1200Data_1[tempal];
2067 return &XGI_LVDSNoScalingData[tempal];
2070 return &XGI_LVDS1024x768Data_1x75[tempal];
2073 return &XGI_LVDS1024x768Data_2x75[tempal];
2076 return &XGI_LVDS1280x1024Data_1x75[tempal];
2079 return &XGI_LVDS1280x1024Data_2x75[tempal];
2082 return &XGI_LVDSNoScalingDatax75[tempal];
2087 } else if (table == 3) {
2088 switch (tempdi[i].DATAPTR) {
2090 return &XGI_LVDS1024x768Des_1[tempal];
2093 return &XGI_LVDS1024x768Des_3[tempal];
2096 return &XGI_LVDS1024x768Des_2[tempal];
2099 return &XGI_LVDS1280x1024Des_1[tempal];
2102 return &XGI_LVDS1280x1024Des_2[tempal];
2105 return &XGI_LVDS1400x1050Des_1[tempal];
2108 return &XGI_LVDS1400x1050Des_2[tempal];
2111 return &XGI_LVDS1600x1200Des_1[tempal];
2114 return &XGI_LVDSNoScalingDesData[tempal];
2117 return &XGI_LVDS1024x768Des_1x75[tempal];
2120 return &XGI_LVDS1024x768Des_3x75[tempal];
2123 return &XGI_LVDS1024x768Des_2x75[tempal];
2126 return &XGI_LVDS1280x1024Des_1x75[tempal];
2129 return &XGI_LVDS1280x1024Des_2x75[tempal];
2132 return &XGI_LVDSNoScalingDesDatax75[tempal];
2137 } else if (table == 4) {
2138 switch (tempdi[i].DATAPTR) {
2140 return &XGI_ExtLCD1024x768Data[tempal];
2143 return &XGI_StLCD1024x768Data[tempal];
2146 return &XGI_CetLCD1024x768Data[tempal];
2149 return &XGI_ExtLCD1280x1024Data[tempal];
2152 return &XGI_StLCD1280x1024Data[tempal];
2155 return &XGI_CetLCD1280x1024Data[tempal];
2159 return &xgifb_lcd_1400x1050[tempal];
2162 return &XGI_CetLCD1400x1050Data[tempal];
2165 return &XGI_ExtLCD1600x1200Data[tempal];
2168 return &XGI_StLCD1600x1200Data[tempal];
2171 return &XGI_NoScalingData[tempal];
2174 return &XGI_ExtLCD1024x768x75Data[tempal];
2177 return &XGI_ExtLCD1024x768x75Data[tempal];
2180 return &XGI_CetLCD1024x768x75Data[tempal];
2184 return &xgifb_lcd_1280x1024x75[tempal];
2187 return &XGI_CetLCD1280x1024x75Data[tempal];
2190 return &XGI_NoScalingDatax75[tempal];
2195 } else if (table == 5) {
2196 switch (tempdi[i].DATAPTR) {
2198 return &XGI_ExtLCDDes1024x768Data[tempal];
2201 return &XGI_StLCDDes1024x768Data[tempal];
2204 return &XGI_CetLCDDes1024x768Data[tempal];
2207 if ((pVBInfo->VBType & VB_XGI301LV) ||
2208 (pVBInfo->VBType & VB_XGI302LV))
2209 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
2211 return &XGI_ExtLCDDes1280x1024Data[tempal];
2214 if ((pVBInfo->VBType & VB_XGI301LV) ||
2215 (pVBInfo->VBType & VB_XGI302LV))
2216 return &XGI_StLCDDLDes1280x1024Data[tempal];
2218 return &XGI_StLCDDes1280x1024Data[tempal];
2221 if ((pVBInfo->VBType & VB_XGI301LV) ||
2222 (pVBInfo->VBType & VB_XGI302LV))
2223 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2225 return &XGI_CetLCDDes1280x1024Data[tempal];
2229 if ((pVBInfo->VBType & VB_XGI301LV) ||
2230 (pVBInfo->VBType & VB_XGI302LV))
2231 return &xgifb_lcddldes_1400x1050[tempal];
2233 return &xgifb_lcddes_1400x1050[tempal];
2236 return &XGI_CetLCDDes1400x1050Data[tempal];
2239 return &XGI_CetLCDDes1400x1050Data2[tempal];
2242 if ((pVBInfo->VBType & VB_XGI301LV) ||
2243 (pVBInfo->VBType & VB_XGI302LV))
2244 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2246 return &XGI_ExtLCDDes1600x1200Data[tempal];
2249 if ((pVBInfo->VBType & VB_XGI301LV) ||
2250 (pVBInfo->VBType & VB_XGI302LV))
2251 return &XGI_StLCDDLDes1600x1200Data[tempal];
2253 return &XGI_StLCDDes1600x1200Data[tempal];
2256 return &XGI_NoScalingDesData[tempal];
2260 return &xgifb_lcddes_1024x768x75[tempal];
2263 return &XGI_CetLCDDes1024x768x75Data[tempal];
2267 if ((pVBInfo->VBType & VB_XGI301LV) ||
2268 (pVBInfo->VBType & VB_XGI302LV))
2269 return &xgifb_lcddldes_1280x1024x75[tempal];
2271 return &xgifb_lcddes_1280x1024x75[tempal];
2274 if ((pVBInfo->VBType & VB_XGI301LV) ||
2275 (pVBInfo->VBType & VB_XGI302LV))
2276 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2278 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2281 return &XGI_NoScalingDesDatax75[tempal];
2286 } else if (table == 6) {
2287 switch (tempdi[i].DATAPTR) {
2289 return &XGI_CH7017LV1024x768[tempal];
2292 return &XGI_CH7017LV1400x1050[tempal];
2301 static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2302 unsigned short ModeIdIndex,
2303 unsigned short RefreshRateTableIndex,
2304 struct vb_device_info *pVBInfo)
2306 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2307 struct XGI330_TVDataTablStruct *tempdi = NULL;
2311 if (ModeNo <= 0x13) {
2312 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2313 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2315 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2316 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2319 tempal = tempal & 0x3f;
2324 tempdi = NULL; /*EPLCHTVCRT1Ptr_H;*/
2327 tempdi = NULL; /*EPLCHTVCRT1Ptr_V;*/
2331 tempdi = xgifb_chrontel_tv;
2337 tempdi = XGI_TVDataTable;
2346 if (tempdi == NULL) /* OEMUtil */
2349 tempdx = pVBInfo->TVInfo;
2351 if (pVBInfo->VBInfo & SetInSlaveMode)
2352 tempdx = tempdx | SetTVLockMode;
2354 if (modeflag & HalfDCLK)
2355 tempdx = tempdx | SetTVLowResolution;
2359 while (tempdi[i].MASK != 0xffff) {
2360 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2366 if (table == 0x00) {
2367 } else if (table == 0x01) {
2368 } else if (table == 0x04) {
2369 switch (tempdi[i].DATAPTR) {
2371 return &XGI_ExtPALData[tempal];
2374 return &XGI_ExtNTSCData[tempal];
2377 return &XGI_StPALData[tempal];
2380 return &XGI_StNTSCData[tempal];
2383 return &XGI_ExtHiTVData[tempal];
2386 return &XGI_St2HiTVData[tempal];
2389 return &XGI_ExtYPbPr525iData[tempal];
2392 return &XGI_ExtYPbPr525pData[tempal];
2395 return &XGI_ExtYPbPr750pData[tempal];
2398 return &XGI_StYPbPr525iData[tempal];
2401 return &XGI_StYPbPr525pData[tempal];
2404 return &XGI_StYPbPr750pData[tempal];
2406 case 12: /* avoid system hang */
2407 return &XGI_ExtNTSCData[tempal];
2410 return &XGI_St1HiTVData[tempal];
2415 } else if (table == 0x02) {
2416 switch (tempdi[i].DATAPTR) {
2418 return &XGI_CHTVUNTSCData[tempal];
2421 return &XGI_CHTVONTSCData[tempal];
2424 return &XGI_CHTVUPALData[tempal];
2427 return &XGI_CHTVOPALData[tempal];
2432 } else if (table == 0x06) {
2437 static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
2438 unsigned short RefreshRateTableIndex,
2439 struct vb_device_info *pVBInfo)
2441 unsigned short tempbx;
2442 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
2446 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2447 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2448 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2450 pVBInfo->VGAHT = LCDPtr->VGAHT;
2451 pVBInfo->VGAVT = LCDPtr->VGAVT;
2452 pVBInfo->HT = LCDPtr->LCDHT;
2453 pVBInfo->VT = LCDPtr->LCDVT;
2456 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2457 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2458 | EnableScalingLCD))) {
2459 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2460 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2461 pVBInfo->HDE = 1024;
2463 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2464 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2465 pVBInfo->HDE = 1280;
2466 pVBInfo->VDE = 1024;
2467 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2468 pVBInfo->HDE = 1400;
2469 pVBInfo->VDE = 1050;
2471 pVBInfo->HDE = 1600;
2472 pVBInfo->VDE = 1200;
2478 static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
2479 unsigned short RefreshRateTableIndex,
2480 struct xgi_hw_device_info *HwDeviceExtension,
2481 struct vb_device_info *pVBInfo)
2483 unsigned char index;
2484 unsigned short tempbx, i;
2485 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2486 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
2489 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2491 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2493 index = index & IndexMask;
2497 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2498 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2499 XGI_GetLcdPtr(tempbx, ModeNo,
2501 RefreshRateTableIndex,
2504 for (i = 0; i < 8; i++)
2505 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
2508 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2512 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2513 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2518 RefreshRateTableIndex,
2520 for (i = 0; i < 7; i++)
2521 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2524 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
2527 static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2529 unsigned char tempal, tempah, tempbl, i;
2531 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
2532 tempal = tempah & 0x0F;
2533 tempah = tempah & 0xF0;
2535 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2537 while (tempbl != 0xFF) {
2538 if (tempbl & 0x80) { /* OEMUtil */
2540 tempbl = tempbl & ~(0x80);
2543 if (tempal == tempbl)
2548 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2554 static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2556 unsigned short tempah, tempal, tempbl, i;
2558 tempal = pVBInfo->LCDResInfo;
2559 tempah = pVBInfo->LCDTypeInfo;
2562 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2564 while (tempbl != 0xFF) {
2565 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2570 if (tempal == tempbl)
2574 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2577 if (tempbl == 0xFF) {
2578 pVBInfo->LCDResInfo = Panel1024x768;
2579 pVBInfo->LCDTypeInfo = 0;
2586 static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2587 unsigned short *VSyncWidth,
2588 struct vb_device_info *pVBInfo)
2590 unsigned short Index;
2592 Index = XGI_GetLCDCapPtr(pVBInfo);
2593 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2594 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2599 static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2600 unsigned short RefreshRateTableIndex,
2601 struct vb_device_info *pVBInfo)
2603 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2604 unsigned long temp, temp1, temp2, temp3, push3;
2605 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2606 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
2609 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2611 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2614 if (pVBInfo->LCDInfo & EnableScalingLCD)
2616 (struct XGI330_LCDDataDesStruct2 *)
2621 RefreshRateTableIndex,
2625 (struct XGI330_LCDDataDesStruct *)
2630 RefreshRateTableIndex,
2633 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2638 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2639 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2642 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2643 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2646 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2654 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2655 pVBInfo->HDE = tempax;
2656 pVBInfo->VDE = tempbx;
2657 pVBInfo->VGAHDE = tempax;
2658 pVBInfo->VGAVDE = tempbx;
2661 tempax = pVBInfo->HT;
2663 if (pVBInfo->LCDInfo & EnableScalingLCD)
2664 tempbx = LCDPtr1->LCDHDES;
2666 tempbx = LCDPtr->LCDHDES;
2668 tempcx = pVBInfo->HDE;
2669 tempbx = tempbx & 0x0fff;
2672 if (tempcx >= tempax)
2675 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
2677 tempcx = tempcx >> 3;
2678 tempbx = tempbx >> 3;
2680 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2681 (unsigned short) (tempbx & 0xff));
2682 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2683 (unsigned short) (tempcx & 0xff));
2685 tempax = pVBInfo->HT;
2687 if (pVBInfo->LCDInfo & EnableScalingLCD)
2688 tempbx = LCDPtr1->LCDHRS;
2690 tempbx = LCDPtr->LCDHRS;
2694 if (pVBInfo->LCDInfo & EnableScalingLCD)
2695 tempcx = LCDPtr1->LCDHSync;
2699 if (tempcx >= tempax)
2702 tempax = tempbx & 0x07;
2703 tempax = tempax >> 5;
2704 tempcx = tempcx >> 3;
2705 tempbx = tempbx >> 3;
2710 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2711 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2712 (unsigned short) (tempbx & 0xff));
2714 tempax = pVBInfo->VT;
2715 if (pVBInfo->LCDInfo & EnableScalingLCD)
2716 tempbx = LCDPtr1->LCDVDES;
2718 tempbx = LCDPtr->LCDVDES;
2719 tempcx = pVBInfo->VDE;
2721 tempbx = tempbx & 0x0fff;
2723 if (tempcx >= tempax)
2726 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2727 (unsigned short) (tempbx & 0xff));
2728 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2729 (unsigned short) (tempcx & 0xff));
2731 tempbx = (tempbx >> 8) & 0x07;
2732 tempcx = (tempcx >> 8) & 0x07;
2734 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2735 (unsigned short) ((tempcx << 3)
2738 tempax = pVBInfo->VT;
2739 if (pVBInfo->LCDInfo & EnableScalingLCD)
2740 tempbx = LCDPtr1->LCDVRS;
2742 tempbx = LCDPtr->LCDVRS;
2744 /* tempbx = tempbx >> 4; */
2747 if (pVBInfo->LCDInfo & EnableScalingLCD)
2748 tempcx = LCDPtr1->LCDVSync;
2751 if (tempcx >= tempax)
2754 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2755 (unsigned short) (tempbx & 0xff));
2756 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2757 (unsigned short) (tempcx & 0x0f));
2759 tempax = ((tempbx >> 8) & 0x07) << 3;
2761 tempbx = pVBInfo->VGAVDE;
2762 if (tempbx != pVBInfo->VDE)
2765 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2768 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2771 tempcx = pVBInfo->VGAVT;
2772 tempbx = pVBInfo->VDE;
2773 tempax = pVBInfo->VGAVDE;
2776 temp = tempax; /* 0430 ylshieh */
2777 temp1 = (temp << 18) / tempbx;
2779 tempdx = (unsigned short) ((temp << 18) % tempbx);
2787 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2788 (unsigned short) (temp2 & 0xff));
2789 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2790 (unsigned short) ((temp2 >> 8) & 0xff));
2792 tempbx = (unsigned short) (temp2 >> 16);
2793 tempax = tempbx & 0x03;
2795 tempbx = pVBInfo->VGAVDE;
2796 if (tempbx == pVBInfo->VDE)
2799 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2801 if (pVBInfo->VBType & VB_XGI301C) {
2803 xgifb_reg_set(pVBInfo->Part4Port,
2805 (unsigned short) (temp2 & 0xff));
2806 xgifb_reg_set(pVBInfo->Part4Port,
2808 (unsigned short) ((temp2 >> 8) &
2810 tempbx = (unsigned short) (temp2 >> 16);
2811 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2813 (unsigned short) ((tempbx &
2816 tempcx = pVBInfo->VGAVDE;
2817 if (tempcx == pVBInfo->VDE)
2818 xgifb_reg_and_or(pVBInfo->Part4Port,
2821 xgifb_reg_and_or(pVBInfo->Part4Port,
2825 tempcx = pVBInfo->VGAHDE;
2826 tempbx = pVBInfo->HDE;
2828 temp1 = tempcx << 16;
2830 tempax = (unsigned short) (temp1 / tempbx);
2832 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2836 temp1 = pVBInfo->VGAHDE << 16;
2839 temp3 = temp3 << 16;
2842 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2844 tempax = (unsigned short) (temp3 & 0xff);
2845 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2847 temp1 = pVBInfo->VGAVDE << 18;
2848 temp1 = temp1 / push3;
2849 tempbx = (unsigned short) (temp1 & 0xffff);
2851 if (pVBInfo->LCDResInfo == Panel1024x768)
2854 tempax = ((tempbx >> 8) & 0xff) << 3;
2855 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2856 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2857 (unsigned short) (tempax & 0xff));
2858 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2859 (unsigned short) (tempbx & 0xff));
2861 temp3 = temp3 >> 16;
2863 if (modeflag & HalfDCLK)
2866 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2867 (unsigned short) ((temp3 >> 8) & 0xff));
2868 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2869 (unsigned short) (temp3 & 0xff));
2872 /* --------------------------------------------------------------------- */
2873 /* Function : XGI_GETLCDVCLKPtr */
2875 /* Output : al -> VCLK Index */
2877 /* --------------------------------------------------------------------- */
2878 static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2879 struct vb_device_info *pVBInfo)
2881 unsigned short index;
2883 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2884 /* index = XGI_GetLCDCapPtr(pVBInfo); */
2885 index = XGI_GetLCDCapPtr1(pVBInfo);
2887 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2888 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2889 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2891 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2892 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2898 static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2899 unsigned short ModeNo, unsigned short ModeIdIndex,
2900 struct vb_device_info *pVBInfo)
2903 unsigned short index, modeflag;
2904 unsigned char tempal;
2908 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2910 /* si+Ext_ResInfo */
2911 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2913 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2914 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
2915 index = XGI_GetLCDCapPtr(pVBInfo);
2916 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2918 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
2922 if (pVBInfo->VBType &
2928 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2929 tempal = HiTVVCLKDIV2;
2930 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2932 if (pVBInfo->TVInfo & TVSimuMode) {
2933 tempal = HiTVSimuVCLK;
2934 if (!(modeflag & Charx8Dot))
2935 tempal = HiTVTextVCLK;
2941 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
2942 tempal = YPbPr750pVCLK;
2946 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
2947 tempal = YPbPr525pVCLK;
2951 tempal = NTSC1024VCLK;
2953 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
2954 tempal = TVVCLKDIV2;
2955 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2959 if (pVBInfo->VBInfo & SetCRT2ToTV)
2964 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
2965 tempal = tempal >> 2;
2968 /* for Dot8 Scaling LCD */
2969 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
2970 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2975 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2979 static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2980 unsigned char *di_1, struct vb_device_info *pVBInfo)
2982 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
2983 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
2984 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
2985 & ProgrammingCRT2)) {
2986 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
2987 *di_1 = XGI_VBVCLKData[tempal].SR2C;
2990 *di_0 = XGI_VCLKData[tempal].SR2B;
2991 *di_1 = XGI_VCLKData[tempal].SR2C;
2995 static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
2996 unsigned short RefreshRateTableIndex,
2997 struct vb_device_info *pVBInfo)
2999 unsigned char di_0, di_1, tempal;
3002 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3004 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3005 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
3007 for (i = 0; i < 4; i++) {
3008 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
3009 (unsigned short) (0x10 * i));
3010 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
3011 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
3012 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
3013 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
3015 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
3016 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
3021 static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
3022 struct vb_device_info *pVBInfo)
3024 unsigned short tempcl, tempch, temp, tempbl, tempax;
3026 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
3027 | VB_XGI302LV | VB_XGI301C)) {
3030 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
3032 if (!(temp & 0x20)) {
3033 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
3035 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
3037 tempcl |= ActiveCRT1;
3041 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
3044 if (!(temp == 0x08)) {
3045 /* Check ChannelA by Part1_13 [2003/10/03] */
3046 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
3048 tempcl = tempcl | ActiveLCD;
3052 if (!(tempcl & ActiveLCD))
3054 tempcl |= ActiveCRT2;
3057 tempcl |= ActiveLCD;
3060 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
3063 tempch |= ActiveAVideo;
3066 tempch |= ActiveSVideo;
3069 tempch |= ActiveSCART;
3071 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3073 tempch |= ActiveHiTV;
3076 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
3077 temp = xgifb_reg_get(
3082 tempch |= ActiveYPbPr;
3090 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
3091 if (tempcl & ActiveLCD) {
3092 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3093 if (temp & ActiveTV)
3098 tempbl = ~ModeSwitchStatus;
3099 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
3101 if (!(pVBInfo->SetFlag & ReserveTVOption))
3102 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
3108 void XGI_GetVGAType(struct xgi_hw_device_info *HwDeviceExtension,
3109 struct vb_device_info *pVBInfo)
3112 if ( HwDeviceExtension->jChipType >= XG20 ) {
3113 pVBInfo->Set_VGAType = XG20;
3115 pVBInfo->Set_VGAType = VGA_XGI340;
3118 pVBInfo->Set_VGAType = HwDeviceExtension->jChipType;
3121 void XGI_GetVBType(struct vb_device_info *pVBInfo)
3123 unsigned short flag, tempbx, tempah;
3125 if (pVBInfo->IF_DEF_LVDS == 0) {
3126 tempbx = VB_XGI302B;
3127 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
3130 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
3132 tempbx = VB_XGI301B;
3134 tempbx = VB_XGI301C;
3136 tempbx = VB_XGI301LV;
3138 tempbx = VB_XGI302LV;
3139 tempah = xgifb_reg_get(
3149 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
3150 flag = xgifb_reg_get(
3155 tempbx = tempbx | VB_NoLCD;
3159 pVBInfo->VBType = tempbx;
3163 void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3164 struct xgi_hw_device_info *HwDeviceExtension,
3165 struct vb_device_info *pVBInfo)
3167 unsigned short tempax, push, tempbx, temp, modeflag;
3170 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3172 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3174 pVBInfo->SetFlag = 0;
3175 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3178 if (pVBInfo->VBType & 0xFFFF) {
3179 /* Check Display Device */
3180 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
3181 tempbx = tempbx | temp;
3182 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
3186 tempbx = tempbx | tempax;
3187 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3188 | SetInSlaveMode | DisableCRT2Display);
3189 temp = 0xFFFF ^ temp;
3192 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3194 if (pVBInfo->IF_DEF_LCDA == 1) {
3196 if ((pVBInfo->Set_VGAType >= XG20)
3197 || (pVBInfo->Set_VGAType >= XG40)) {
3198 if (pVBInfo->IF_DEF_LVDS == 0) {
3199 /* if ((pVBInfo->VBType & VB_XGI302B)
3200 || (pVBInfo->VBType & VB_XGI301LV)
3201 || (pVBInfo->VBType & VB_XGI302LV)
3202 || (pVBInfo->VBType & VB_XGI301C))
3204 if (pVBInfo->VBType &
3209 if (temp & EnableDualEdge) {
3213 if (temp & SetToLCDA)
3222 if (pVBInfo->IF_DEF_YPbPr == 1) {
3223 /* [Billy] 07/05/04 */
3224 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3225 ((pVBInfo->VBType & VB_XGI301LV) ||
3226 (pVBInfo->VBType & VB_XGI302LV) ||
3227 (pVBInfo->VBType & VB_XGI301C)))) {
3228 if (temp & SetYPbPr) { /* temp = CR38 */
3229 if (pVBInfo->IF_DEF_HiVision == 1) {
3230 /* shampoo add for new
3232 temp = xgifb_reg_get(
3236 tempbx |= SetCRT2ToHiVisionTV;
3238 if (temp != YPbPrMode1080i) {
3240 (~SetCRT2ToHiVisionTV);
3246 /* tempbx |= SetCRT2ToYPbPr; */
3251 tempax = push; /* restore CR31 */
3253 if (pVBInfo->IF_DEF_LVDS == 0) {
3254 if (pVBInfo->IF_DEF_YPbPr == 1) {
3255 if (pVBInfo->IF_DEF_HiVision == 1)
3260 if (pVBInfo->IF_DEF_HiVision == 1)
3265 } else { /* 3nd party chip */
3266 temp = SetCRT2ToLCD;
3269 if (!(tempbx & temp)) {
3270 tempax |= DisableCRT2Display;
3274 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3275 if (!(pVBInfo->VBType & VB_NoLCD)) {
3276 if (tempbx & SetCRT2ToLCDA) {
3277 if (tempbx & SetSimuScanMode)
3278 tempbx &= (~(SetCRT2ToLCD |
3282 tempbx &= (~(SetCRT2ToLCD |
3291 /* for driver abnormal */
3292 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
3293 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3294 if (tempbx & SetCRT2ToRAMDAC) {
3299 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3302 tempbx &= (~(SetCRT2ToRAMDAC |
3308 if (!(pVBInfo->VBType & VB_NoLCD)) {
3309 if (tempbx & SetCRT2ToLCD) {
3314 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3318 if (tempbx & SetCRT2ToSCART) {
3323 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3326 if (pVBInfo->IF_DEF_YPbPr == 1) {
3327 if (tempbx & SetCRT2ToYPbPr)
3333 if (pVBInfo->IF_DEF_HiVision == 1) {
3334 if (tempbx & SetCRT2ToHiVisionTV)
3336 SetCRT2ToHiVisionTV |
3341 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3342 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3343 tempbx = DisableCRT2Display;
3346 if (!(tempbx & DisableCRT2Display)) {
3347 if ((!(tempbx & DriverMode)) ||
3348 (!(modeflag & CRT2Mode))) {
3349 if (pVBInfo->IF_DEF_LCDA == 1) {
3350 if (!(tempbx & SetCRT2ToLCDA))
3351 tempbx |= (SetInSlaveMode |
3356 /* LCD+TV can't support in slave mode
3357 * (Force LCDA+TV->LCDB) */
3358 if ((tempbx & SetInSlaveMode) &&
3359 (tempbx & SetCRT2ToLCDA)) {
3360 tempbx ^= (SetCRT2ToLCD |
3363 pVBInfo->SetFlag |= ReserveTVOption;
3368 pVBInfo->VBInfo = tempbx;
3371 void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3372 struct vb_device_info *pVBInfo)
3374 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
3379 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3380 if (ModeNo <= 0x13) {
3381 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3382 St_ModeFlag; /* si+St_ModeFlag */
3383 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3384 St_ResInfo; /* si+St_ResInfo */
3386 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3388 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3389 Ext_RESINFO; /* si+Ext_ResInfo */
3392 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3393 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
3395 if (tempbx & SetPALTV) {
3396 tempbx &= (SetCHTVOverScan |
3400 if (tempbx & SetPALMTV)
3401 /* set to NTSC if PAL-M */
3402 tempbx &= ~SetPALTV;
3404 tempbx &= (SetCHTVOverScan |
3408 if (pVBInfo->IF_DEF_LVDS == 0) {
3410 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3411 //00:PAL, 01:PAL-M, 10:PAL-N
3412 temp2 = (index1 & 0xC0) >> 5;
3414 if (temp2 & 0x02) //PAL-M
3415 tempbx &= (~SetPALTV);
3420 if (pVBInfo->IF_DEF_LVDS == 0) {
3421 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3425 if (pVBInfo->IF_DEF_YPbPr == 1) {
3426 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
3427 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
3428 index1 &= YPbPrMode;
3430 if (index1 == YPbPrMode525i)
3431 tempbx |= SetYPbPrMode525i;
3433 if (index1 == YPbPrMode525p)
3434 tempbx = tempbx | SetYPbPrMode525p;
3435 if (index1 == YPbPrMode750p)
3436 tempbx = tempbx | SetYPbPrMode750p;
3440 if (pVBInfo->IF_DEF_HiVision == 1) {
3441 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3442 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3445 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3446 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3447 (!(pVBInfo->VBInfo & SetNotSimuMode)))
3448 tempbx |= TVSimuMode;
3450 if (!(tempbx & SetPALTV) &&
3452 (resinfo == 8)) /* NTSC 1024x768, */
3453 tempbx |= NTSC1024x768;
3455 tempbx |= RPLLDIV2XO;
3457 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3458 if (pVBInfo->VBInfo & SetInSlaveMode)
3459 tempbx &= (~RPLLDIV2XO);
3462 (SetYPbPrMode525p | SetYPbPrMode750p))
3463 tempbx &= (~RPLLDIV2XO);
3464 else if (!(pVBInfo->VBType &
3470 if (tempbx & TVSimuMode)
3471 tempbx &= (~RPLLDIV2XO);
3476 pVBInfo->TVInfo = tempbx;
3479 unsigned char XGI_GetLCDInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3480 struct vb_device_info *pVBInfo)
3482 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
3484 pVBInfo->LCDResInfo = 0;
3485 pVBInfo->LCDTypeInfo = 0;
3486 pVBInfo->LCDInfo = 0;
3488 if (ModeNo <= 0x13) {
3489 /* si+St_ModeFlag // */
3490 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3492 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3493 /* si+Ext_ResInfo // */
3494 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3497 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
3498 tempbx = temp & 0x0F;
3501 tempbx = Panel1024x768; /* default */
3503 /* LCD75 [2003/8/22] Vicent */
3504 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3505 if (pVBInfo->VBInfo & DriverMode) {
3506 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
3507 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3510 tempax = tempax >> 4;
3512 if ((resinfo == 6) || (resinfo == 9)) {
3514 tempbx |= PanelRef75Hz;
3515 } else if ((resinfo == 7) || (resinfo == 8)) {
3517 tempbx |= PanelRef75Hz;
3522 pVBInfo->LCDResInfo = tempbx;
3526 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3531 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
3533 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
3537 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
3539 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
3541 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3542 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3543 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3544 tempbx |= SetLCDDualLink;
3548 if (pVBInfo->IF_DEF_LVDS == 0) {
3549 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3550 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3551 == 9) && (!(tempbx & EnableScalingLCD)))
3552 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3553 tempbx |= SetLCDtoNonExpanding;
3557 if (tempax & LCDBToA) {
3558 tempbx |= SetLCDBToA;
3562 if (pVBInfo->IF_DEF_ExpLink == 1) {
3563 if (modeflag & HalfDCLK) {
3564 /* if (!(pVBInfo->LCDInfo&LCDNonExpanding)) */
3565 if (!(tempbx & SetLCDtoNonExpanding)) {
3566 tempbx |= EnableLVDSDDA;
3568 if (ModeNo > 0x13) {
3569 if (pVBInfo->LCDResInfo
3571 if (resinfo == 4) {/* 512x384 */
3572 tempbx |= EnableLVDSDDA;
3580 if (pVBInfo->VBInfo & SetInSlaveMode) {
3581 if (pVBInfo->VBInfo & SetNotSimuMode)
3582 tempbx |= LCDVESATiming;
3584 tempbx |= LCDVESATiming;
3587 pVBInfo->LCDInfo = tempbx;
3589 if (pVBInfo->IF_DEF_LVDS == 0) {
3590 if (tempax & (LockLCDBToA | StLCDBToA)) {
3591 if (pVBInfo->VBInfo & SetInSlaveMode) {
3592 if (!(tempax & LockLCDBToA)) {
3593 if (ModeNo <= 0x13) {
3608 if (pVBInfo->IF_DEF_LVDS == 0) {
3609 if (tempax & (LockLCDBToA | StLCDBToA)) {
3610 if (pVBInfo->VBInfo & SetInSlaveMode) {
3611 if (!((!(tempax & LockLCDBToA)) &&
3629 unsigned char XGI_SearchModeID(unsigned short ModeNo,
3630 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
3634 if (ModeNo <= 0x13) {
3635 /* for (*ModeIdIndex=0;
3636 *ModeIdIndex < sizeof(pVBInfo->SModeIDTable)
3637 / sizeof(struct XGI_StStruct);
3638 (*ModeIdIndex)++) */
3639 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3640 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3643 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3649 (*ModeIdIndex)++; /* 400 lines */
3651 (*ModeIdIndex) += 2; /* 400 lines */
3652 /* else 350 lines */
3654 /* for (*ModeIdIndex=0;
3655 *ModeIdIndex < sizeof(pVBInfo->EModeIDTable)
3656 / sizeof(struct XGI_ExtStruct);
3657 (*ModeIdIndex)++) */
3658 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3659 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3662 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3671 static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3673 unsigned char ujRet = 0;
3674 unsigned char i = 0;
3676 for (i = 0; i < 8; i++) {
3678 /* ujRet |= GETBITS(ujDate >> i, 0:0); */
3679 ujRet |= (ujDate >> i) & 1;
3685 /*----------------------------------------------------------------------------*/
3687 /* bl[5] : LVDS signal */
3688 /* bl[1] : LVDS backlight */
3689 /* bl[0] : LVDS VDD */
3690 /*----------------------------------------------------------------------------*/
3691 static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3693 unsigned char CR4A, temp;
3695 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3696 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
3698 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3700 temp = XG21GPIODataTransfer(temp);
3702 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3706 /*----------------------------------------------------------------------------*/
3708 /* bl[5] : LVDS signal */
3709 /* bl[1] : LVDS backlight */
3710 /* bl[0] : LVDS VDD */
3711 /*----------------------------------------------------------------------------*/
3712 static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3714 unsigned char CR4A, CRB4, temp;
3716 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3717 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
3719 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3723 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3724 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
3725 temp |= ((CRB4 & 0x04) << 3);
3729 void XGI_DisplayOn(struct xgi_hw_device_info *pXGIHWDE,
3730 struct vb_device_info *pVBInfo)
3733 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
3734 if (pXGIHWDE->jChipType == XG21) {
3735 if (pVBInfo->IF_DEF_LVDS == 1) {
3736 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
3738 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
3739 XGI_XG21SetPanelDelay(2, pVBInfo);
3741 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
3742 /* LVDS signal on */
3743 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3744 XGI_XG21SetPanelDelay(3, pVBInfo);
3745 /* LVDS backlight on */
3746 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
3748 /* DVO/DVI signal on */
3749 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3754 if (pXGIHWDE->jChipType == XG27) {
3755 if (pVBInfo->IF_DEF_LVDS == 1) {
3756 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
3758 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
3759 XGI_XG21SetPanelDelay(2, pVBInfo);
3761 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
3762 /* LVDS signal on */
3763 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3764 XGI_XG21SetPanelDelay(3, pVBInfo);
3765 /* LVDS backlight on */
3766 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
3768 /* DVO/DVI signal on */
3769 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3775 void XGI_DisplayOff(struct xgi_hw_device_info *pXGIHWDE,
3776 struct vb_device_info *pVBInfo)
3779 if (pXGIHWDE->jChipType == XG21) {
3780 if (pVBInfo->IF_DEF_LVDS == 1) {
3781 /* LVDS backlight off */
3782 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
3783 XGI_XG21SetPanelDelay(3, pVBInfo);
3785 /* DVO/DVI signal off */
3786 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
3790 if (pXGIHWDE->jChipType == XG27) {
3791 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
3792 /* LVDS backlight off */
3793 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
3794 XGI_XG21SetPanelDelay(3, pVBInfo);
3797 if (pVBInfo->IF_DEF_LVDS == 0)
3798 /* DVO/DVI signal off */
3799 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
3802 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
3805 static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
3807 while ((inb(pVBInfo->P3da) & 0x01))
3810 while (!(inb(pVBInfo->P3da) & 0x01))
3814 static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
3816 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
3819 static void XGI_SaveCRT2Info(unsigned short ModeNo,
3820 struct vb_device_info *pVBInfo)
3822 unsigned short temp1, temp2;
3824 /* reserve CR34 for CRT1 Mode No */
3825 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
3826 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3827 temp2 = ~(SetInSlaveMode >> 8);
3828 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
3831 static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3832 unsigned short ModeIdIndex,
3833 struct vb_device_info *pVBInfo)
3835 unsigned short xres, yres, modeflag, resindex;
3837 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
3838 if (ModeNo <= 0x13) {
3839 xres = pVBInfo->StResInfo[resindex].HTotal;
3840 yres = pVBInfo->StResInfo[resindex].VTotal;
3842 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;*/
3844 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3845 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3846 /* si+St_ModeFlag */
3847 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3850 if (pVBInfo->IF_DEF_FSTN) {
3855 if (modeflag & HalfDCLK)
3858 if (modeflag & DoubleScanMode)
3863 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3864 if (pVBInfo->IF_DEF_LVDS == 0) {
3865 if (pVBInfo->LCDResInfo == Panel1600x1200) {
3866 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3872 if (pVBInfo->LCDResInfo == Panel1280x1024) {
3875 else if (yres == 350)
3878 if (pVBInfo->LCDInfo & LCDVESATiming) {
3884 if (pVBInfo->LCDResInfo == Panel1024x768) {
3885 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3886 if (!(pVBInfo->LCDInfo
3887 & LCDNonExpanding)) {
3890 else if (yres == 400)
3892 else if (yres == 480)
3903 pVBInfo->VGAHDE = xres;
3904 pVBInfo->HDE = xres;
3905 pVBInfo->VGAVDE = yres;
3906 pVBInfo->VDE = yres;
3909 static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
3912 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
3913 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
3919 static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3920 unsigned short ModeIdIndex,
3921 unsigned short RefreshRateTableIndex,
3922 struct vb_device_info *pVBInfo)
3924 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
3925 StandTableIndex, CRT1Index;
3927 pVBInfo->RVBHCMAX = 1;
3928 pVBInfo->RVBHCFACT = 1;
3930 if (ModeNo <= 0x13) {
3931 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3932 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
3933 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
3934 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
3935 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
3937 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3938 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
3940 CRT1Index &= IndexMask;
3941 temp1 = (unsigned short) pVBInfo->
3942 XGINEWUB_CRT1Table[CRT1Index].CR[0];
3943 temp2 = (unsigned short) pVBInfo->
3944 XGINEWUB_CRT1Table[CRT1Index].CR[5];
3945 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3946 tempbx = (unsigned short) pVBInfo->
3947 XGINEWUB_CRT1Table[CRT1Index].CR[8];
3948 tempcx = (unsigned short) pVBInfo->
3949 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3951 tempcx = tempcx << 2;
3953 temp1 = (unsigned short) pVBInfo->
3954 XGINEWUB_CRT1Table[CRT1Index].CR[9];
3964 if (modeflag & Charx8Dot)
3969 pVBInfo->VGAHT = tempax;
3970 pVBInfo->HT = tempax;
3972 pVBInfo->VGAVT = tempbx;
3973 pVBInfo->VT = tempbx;
3976 static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
3977 unsigned short RefreshRateTableIndex,
3978 struct vb_device_info *pVBInfo)
3980 unsigned short tempax = 0, tempbx, modeflag, resinfo;
3982 struct XGI_LCDDataStruct *LCDPtr = NULL;
3983 struct XGI_TVDataStruct *TVPtr = NULL;
3985 if (ModeNo <= 0x13) {
3987 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3988 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
3990 /* si+Ext_ResInfo */
3991 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3992 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3995 pVBInfo->NewFlickerMode = 0;
3996 pVBInfo->RVBHRS = 50;
3998 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3999 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4006 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4007 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
4008 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4011 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
4012 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
4013 pVBInfo->VGAHT = LCDPtr->VGAHT;
4014 pVBInfo->VGAVT = LCDPtr->VGAVT;
4015 pVBInfo->HT = LCDPtr->LCDHT;
4016 pVBInfo->VT = LCDPtr->LCDVT;
4018 if (pVBInfo->LCDResInfo == Panel1024x768) {
4022 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4023 if (pVBInfo->VGAVDE == 357)
4025 else if (pVBInfo->VGAVDE == 420)
4027 else if (pVBInfo->VGAVDE == 525)
4029 else if (pVBInfo->VGAVDE == 600)
4031 /* else if (pVBInfo->VGAVDE==350) tempbx=560; */
4032 /* else if (pVBInfo->VGAVDE==400) tempbx=640; */
4037 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
4040 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
4042 if (pVBInfo->VGAVDE == 360)
4044 else if (pVBInfo->VGAVDE == 375)
4046 else if (pVBInfo->VGAVDE == 405)
4050 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
4053 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
4055 if (pVBInfo->VGAVDE == 350)
4057 else if (pVBInfo->VGAVDE == 400)
4059 else if (pVBInfo->VGAVDE == 1024)
4063 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4067 if (pVBInfo->VGAVDE == 1024) {
4071 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4073 tempbx = 1200; /* alan 10/14/2003 */
4074 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4075 if (pVBInfo->VGAVDE == 350)
4077 else if (pVBInfo->VGAVDE == 400)
4082 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4083 tempax = pVBInfo->VGAHDE;
4084 tempbx = pVBInfo->VGAVDE;
4087 pVBInfo->HDE = tempax;
4088 pVBInfo->VDE = tempbx;
4092 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4094 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4095 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4098 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4099 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4100 pVBInfo->VGAHT = TVPtr->VGAHT;
4101 pVBInfo->VGAVT = TVPtr->VGAVT;
4102 pVBInfo->HDE = TVPtr->TVHDE;
4103 pVBInfo->VDE = TVPtr->TVVDE;
4104 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4105 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
4107 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4108 if (resinfo == 0x08)
4109 pVBInfo->NewFlickerMode = 0x40;
4110 else if (resinfo == 0x09)
4111 pVBInfo->NewFlickerMode = 0x40;
4112 else if (resinfo == 0x12)
4113 pVBInfo->NewFlickerMode = 0x40;
4115 if (pVBInfo->VGAVDE == 350)
4116 pVBInfo->TVInfo |= TVSimuMode;
4121 if (pVBInfo->VBInfo & SetInSlaveMode) {
4122 if (pVBInfo->TVInfo & TVSimuMode) {
4126 if (!(modeflag & Charx8Dot)) {
4127 tempax = StHiTextTVHT;
4128 tempbx = StHiTextTVVT;
4132 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4133 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4134 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4135 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4138 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4139 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4140 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4141 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4142 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4143 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4144 if (pVBInfo->TVInfo & NTSC1024x768)
4145 tempax = NTSC1024x768HT;
4150 if (!(pVBInfo->TVInfo & SetPALTV)) {
4153 if (pVBInfo->TVInfo & NTSC1024x768)
4154 tempax = NTSC1024x768HT;
4158 pVBInfo->HT = tempax;
4159 pVBInfo->VT = tempbx;
4164 static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
4165 unsigned short RefreshRateTableIndex,
4166 struct vb_device_info *pVBInfo)
4168 unsigned char di_0, di_1, tempal;
4170 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4172 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4173 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
4175 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4177 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4178 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4179 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4180 } else { /* 301b/302b/301lv/302lv */
4181 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4182 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4185 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
4187 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
4188 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
4190 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
4193 static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4194 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
4196 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4198 unsigned short modeflag;
4201 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4203 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4205 index = (modeflag & ModeInfoFlag) - ModeEGA;
4210 return ColorDepth[index];
4213 static unsigned short XGI_GetOffset(unsigned short ModeNo,
4214 unsigned short ModeIdIndex,
4215 unsigned short RefreshRateTableIndex,
4216 struct xgi_hw_device_info *HwDeviceExtension,
4217 struct vb_device_info *pVBInfo)
4219 unsigned short temp, colordepth, modeinfo, index, infoflag,
4220 ColorDepth[] = { 0x01, 0x02, 0x04 };
4222 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4226 infoflag = pVBInfo->
4227 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
4229 index = (modeinfo >> 8) & 0xFF;
4231 temp = pVBInfo->ScreenOffset[index];
4233 if (infoflag & InterlaceMode)
4236 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4238 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4239 temp = ModeNo - 0x7C;
4240 colordepth = ColorDepth[temp];
4242 if (infoflag & InterlaceMode)
4244 return temp * colordepth;
4246 return temp * colordepth;
4250 static void XGI_SetCRT2Offset(unsigned short ModeNo,
4251 unsigned short ModeIdIndex,
4252 unsigned short RefreshRateTableIndex,
4253 struct xgi_hw_device_info *HwDeviceExtension,
4254 struct vb_device_info *pVBInfo)
4256 unsigned short offset;
4259 if (pVBInfo->VBInfo & SetInSlaveMode)
4262 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4263 HwDeviceExtension, pVBInfo);
4264 temp = (unsigned char) (offset & 0xFF);
4265 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4266 temp = (unsigned char) ((offset & 0xFF00) >> 8);
4267 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
4268 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
4269 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
4272 static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
4274 /* threshold high ,disable auto threshold */
4275 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4276 /* threshold low default 04h */
4277 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
4280 static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4281 struct xgi_hw_device_info *HwDeviceExtension,
4282 unsigned short RefreshRateTableIndex,
4283 struct vb_device_info *pVBInfo)
4285 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
4287 if (ModeNo > 0x13) {
4288 CRT1Index = pVBInfo->
4289 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4290 CRT1Index &= IndexMask;
4291 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4294 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4295 HwDeviceExtension, pVBInfo);
4296 XGI_SetCRT2FIFO(pVBInfo);
4297 /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
4299 for (tempcx = 4; tempcx < 7; tempcx++)
4300 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
4302 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4303 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
4306 static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4307 struct xgi_hw_device_info *HwDeviceExtension,
4308 unsigned short RefreshRateTableIndex,
4309 struct vb_device_info *pVBInfo)
4311 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4312 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
4314 if (ModeNo > 0x13) {
4315 CRT1Index = pVBInfo->
4316 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4317 CRT1Index &= IndexMask;
4318 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4322 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4324 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4326 /* bainy change table name */
4327 if (modeflag & HalfDCLK) {
4328 /* BTVGA2HT 0x08,0x09 */
4329 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
4330 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
4331 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
4332 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
4333 /* BTVGA2HDEE 0x0A,0x0C */
4334 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
4335 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
4336 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4337 pushbx = pVBInfo->VGAHDE / 2 + 16;
4338 tempcx = tempcx >> 1;
4339 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4342 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4343 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4344 tempbx |= ((pVBInfo->
4345 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4347 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4348 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4350 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4351 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4352 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4358 if (tempcx > (pVBInfo->VGAHT / 2))
4359 tempcx = pVBInfo->VGAHT / 2;
4361 temp = tempbx & 0x00FF;
4363 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4365 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
4366 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
4367 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
4368 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
4369 /* BTVGA2HDEE 0x0A,0x0C */
4370 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
4371 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
4372 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4373 pushbx = pVBInfo->VGAHDE + 16;
4374 tempcx = tempcx >> 1;
4375 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4378 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4379 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
4380 tempbx |= ((pVBInfo->
4381 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4383 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4384 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4386 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4387 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4388 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4393 if (tempcx > pVBInfo->VGAHT)
4394 tempcx = pVBInfo->VGAHT;
4396 temp = tempbx & 0x00FF;
4397 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4400 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4402 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4403 tempax |= (tempbx & 0xFF00);
4404 temp = (tempax & 0xFF00) >> 8;
4405 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
4406 temp = tempcx & 0x00FF;
4407 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
4408 tempcx = (pVBInfo->VGAVT - 1);
4409 temp = tempcx & 0x00FF;
4411 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
4412 tempbx = pVBInfo->VGAVDE - 1;
4413 temp = tempbx & 0x00FF;
4414 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
4415 temp = ((tempbx & 0xFF00) << 3) >> 8;
4416 temp |= ((tempcx & 0xFF00) >> 8);
4417 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
4419 tempax = pVBInfo->VGAVDE;
4420 tempbx = pVBInfo->VGAVDE;
4421 tempcx = pVBInfo->VGAVT;
4422 /* BTVGA2VRS 0x10,0x11 */
4423 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4424 /* BTVGA2VRE 0x11 */
4425 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
4427 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4428 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4429 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
4437 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
4442 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4443 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4446 temp = tempbx & 0x00FF;
4447 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4448 temp = ((tempbx & 0xFF00) >> 8) << 4;
4449 temp = ((tempcx & 0x000F) | (temp));
4450 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
4453 if (modeflag & DoubleScanMode)
4456 if (modeflag & HalfDCLK)
4459 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
4462 static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4464 unsigned long tempax, tempbx;
4466 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4468 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4469 tempax = (tempax * pVBInfo->HT) / tempbx;
4471 return (unsigned short) tempax;
4474 static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4475 struct xgi_hw_device_info *HwDeviceExtension,
4476 unsigned short RefreshRateTableIndex,
4477 struct vb_device_info *pVBInfo)
4479 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4480 modeflag, CRT1Index;
4482 if (ModeNo <= 0x13) {
4484 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4485 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4487 /* si+Ext_ResInfo */
4488 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4489 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4490 CRT1Index = pVBInfo->
4491 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4492 CRT1Index &= IndexMask;
4495 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4498 temp = 0xFF; /* set MAX HT */
4499 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
4500 /* if (modeflag & Charx8Dot) */
4501 /* tempcx = 0x08; */
4505 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4506 modeflag |= Charx8Dot;
4508 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
4510 if (modeflag & HalfDCLK)
4511 tempax = tempax >> 1;
4513 tempax = (tempax / tempcx) - 1;
4514 tempbx |= ((tempax & 0x00FF) << 8);
4515 temp = tempax & 0x00FF;
4516 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
4518 temp = (tempbx & 0xFF00) >> 8;
4520 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4521 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4522 | VB_XGI302LV | VB_XGI301C)))
4525 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4526 if (pVBInfo->VBType & VB_XGI301LV) {
4527 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4531 } else if (resinfo == 7) {
4537 /* 0x05 Horizontal Display Start */
4538 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4539 /* 0x06 Horizontal Blank end */
4540 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
4542 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4543 if (pVBInfo->VBInfo & SetCRT2ToTV)
4544 tempax = pVBInfo->VGAHT;
4546 tempax = XGI_GetVGAHT2(pVBInfo);
4549 if (tempax >= pVBInfo->VGAHT)
4550 tempax = pVBInfo->VGAHT;
4552 if (modeflag & HalfDCLK)
4553 tempax = tempax >> 1;
4555 tempax = (tempax / tempcx) - 5;
4556 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4557 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4558 temp = (tempbx & 0x00FF) - 1;
4559 if (!(modeflag & HalfDCLK)) {
4561 if (pVBInfo->TVInfo & TVSimuMode) {
4568 /* tempcx = tempbx & 0x00FF ; */
4569 tempbx = (tempbx & 0xFF00) >> 8;
4570 tempcx = (tempcx + tempbx) >> 1;
4571 temp = (tempcx & 0x00FF) + 2;
4573 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4575 if (!(modeflag & HalfDCLK)) {
4576 if ((modeflag & Charx8Dot)) {
4578 if (pVBInfo->VGAHDE >= 800)
4583 if (!(modeflag & HalfDCLK)) {
4585 if (pVBInfo->LCDResInfo != Panel1280x960) {
4586 if (pVBInfo->VGAHDE >= 800) {
4588 if (pVBInfo->ModeType ==
4590 if (pVBInfo->VGAVDE ==
4593 if (pVBInfo->LCDResInfo != Panel1280x1024) {
4600 if (pVBInfo->VGAHDE >= 1280) {
4601 if (pVBInfo->LCDResInfo
4603 if (pVBInfo->LCDInfo
4604 & LCDNonExpanding) {
4616 /* 0x07 Horizontal Retrace Start */
4617 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4618 /* 0x08 Horizontal Retrace End */
4619 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
4621 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4622 if (pVBInfo->TVInfo & TVSimuMode) {
4623 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4624 == 0x11) || (ModeNo == 0x13) || (ModeNo
4626 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4627 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
4630 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4631 if (pVBInfo->TVInfo & SetNTSCTV) {
4632 xgifb_reg_set(pVBInfo->Part1Port,
4634 xgifb_reg_set(pVBInfo->Part1Port,
4637 xgifb_reg_set(pVBInfo->Part1Port,
4639 xgifb_reg_set(pVBInfo->Part1Port,
4641 xgifb_reg_set(pVBInfo->Part1Port,
4646 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4648 if (pVBInfo->TVInfo & SetNTSCTV) {
4649 xgifb_reg_set(pVBInfo->Part1Port,
4651 xgifb_reg_set(pVBInfo->Part1Port,
4654 xgifb_reg_set(pVBInfo->Part1Port,
4656 xgifb_reg_set(pVBInfo->Part1Port,
4658 xgifb_reg_set(pVBInfo->Part1Port,
4663 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4664 == 0x0D) || (ModeNo == 0x50)) {
4665 if (pVBInfo->TVInfo & SetNTSCTV) {
4666 xgifb_reg_set(pVBInfo->Part1Port,
4668 xgifb_reg_set(pVBInfo->Part1Port,
4671 xgifb_reg_set(pVBInfo->Part1Port,
4673 xgifb_reg_set(pVBInfo->Part1Port,
4680 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
4681 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
4682 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
4684 tempbx = pVBInfo->VGAVT;
4687 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
4702 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4703 if (pVBInfo->LCDResInfo == Panel1024x768) {
4704 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4713 temp = tempbx & 0x00FF;
4715 temp = tempbx & 0x00FF;
4716 /* 0x10 vertical Blank Start */
4717 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4720 temp = tempbx & 0x00FF;
4721 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
4723 if (tempbx & 0x0100)
4728 if (modeflag & DoubleScanMode)
4731 if (tempbx & 0x0200)
4734 temp = (tempax & 0xFF00) >> 8;
4735 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4737 if (tempbx & 0x0400)
4740 /* 0x11 Vertival Blank End */
4741 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
4744 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4745 tempax = tempax >> 2;
4746 push1 = tempax; /* push ax */
4748 if (resinfo != 0x09) {
4749 tempax = tempax << 1;
4753 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4754 if (pVBInfo->VBType & VB_XGI301LV) {
4755 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
4758 if (pVBInfo->TVInfo & TVSimuMode) {
4759 if (pVBInfo->TVInfo & SetPALTV) {
4760 if (pVBInfo->VBType &
4762 if (!(pVBInfo->TVInfo &
4765 SetYPbPrMode1080i)))
4777 if (pVBInfo->TVInfo & TVSimuMode) {
4778 if (pVBInfo->TVInfo & SetPALTV) {
4779 if (pVBInfo->VBType & VB_XGI301LV) {
4780 if (!(pVBInfo->TVInfo &
4783 SetYPbPrMode1080i)))
4792 tempax = tempax >> 2;
4795 push1 = tempax; /* push ax */
4797 if ((pVBInfo->TVInfo & SetPALTV)) {
4798 if (tempbx <= 513) {
4804 temp = tempbx & 0x00FF;
4805 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
4807 temp = tempbx & 0x00FF;
4808 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4810 if (tempbx & 0x0100)
4813 if (tempbx & 0x0200)
4814 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
4818 if (tempbx & 0x0100)
4821 if (tempbx & 0x0200)
4824 if (tempbx & 0x0400)
4827 tempbx = push1; /* pop ax */
4828 temp = tempbx & 0x00FF;
4830 /* 0x0D vertical Retrace End */
4831 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
4833 if (tempbx & 0x0010)
4836 temp = tempcx & 0x00FF;
4837 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
4838 temp = (tempcx & 0x0FF00) >> 8;
4839 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
4841 temp = (tempax & 0xFF00) >> 8;
4843 temp = (temp >> 1) & 0x09;
4845 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4848 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4849 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4850 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
4852 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4857 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
4862 static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
4863 unsigned short RefreshRateTableIndex,
4864 struct xgi_hw_device_info *HwDeviceExtension,
4865 struct vb_device_info *pVBInfo)
4867 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4868 modeflag, resinfo, crt2crtc;
4869 unsigned char *TimingPoint;
4871 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4873 if (ModeNo <= 0x13) {
4875 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4876 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4877 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4879 /* si+Ext_ResInfo */
4880 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4881 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4882 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
4888 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4891 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4894 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4897 if (!(pVBInfo->TVInfo & SetPALTV))
4900 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4903 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
4906 tempax = (tempax & 0xff00) >> 8;
4908 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
4909 TimingPoint = pVBInfo->NTSCTiming;
4911 if (pVBInfo->TVInfo & SetPALTV)
4912 TimingPoint = pVBInfo->PALTiming;
4914 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4915 TimingPoint = pVBInfo->HiTVExtTiming;
4917 if (pVBInfo->VBInfo & SetInSlaveMode)
4918 TimingPoint = pVBInfo->HiTVSt2Timing;
4920 if (pVBInfo->SetFlag & TVSimuMode)
4921 TimingPoint = pVBInfo->HiTVSt1Timing;
4923 if (!(modeflag & Charx8Dot))
4924 TimingPoint = pVBInfo->HiTVTextTiming;
4927 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4928 if (pVBInfo->TVInfo & SetYPbPrMode525i)
4929 TimingPoint = pVBInfo->YPbPr525iTiming;
4931 if (pVBInfo->TVInfo & SetYPbPrMode525p)
4932 TimingPoint = pVBInfo->YPbPr525pTiming;
4934 if (pVBInfo->TVInfo & SetYPbPrMode750p)
4935 TimingPoint = pVBInfo->YPbPr750pTiming;
4938 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
4939 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
4941 for (i = 0x39; i <= 0x45; i++, j++)
4943 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
4945 if (pVBInfo->VBInfo & SetCRT2ToTV)
4946 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
4948 temp = pVBInfo->NewFlickerMode;
4950 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
4952 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4955 if (pVBInfo->TVInfo & SetPALTV)
4960 if (pVBInfo->VDE <= tempax) {
4961 tempax -= pVBInfo->VDE;
4962 tempax = tempax >> 2;
4963 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4965 temp = (tempax & 0xFF00) >> 8;
4966 temp += (unsigned short) TimingPoint[0];
4968 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4969 | VB_XGI302LV | VB_XGI301C)) {
4970 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4971 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4972 | SetCRT2ToYPbPr)) {
4973 tempcx = pVBInfo->VGAHDE;
4974 if (tempcx >= 1024) {
4975 temp = 0x17; /* NTSC */
4976 if (pVBInfo->TVInfo & SetPALTV)
4977 temp = 0x19; /* PAL */
4982 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
4984 temp = (tempax & 0xFF00) >> 8;
4985 temp += TimingPoint[1];
4987 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4988 | VB_XGI302LV | VB_XGI301C)) {
4989 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4990 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4991 | SetCRT2ToYPbPr))) {
4992 tempcx = pVBInfo->VGAHDE;
4993 if (tempcx >= 1024) {
4994 temp = 0x1D; /* NTSC */
4995 if (pVBInfo->TVInfo & SetPALTV)
4996 temp = 0x52; /* PAL */
5000 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
5004 tempcx = pVBInfo->HT;
5006 if (XGI_IsLCDDualLink(pVBInfo))
5007 tempcx = tempcx >> 1;
5010 temp = tempcx & 0x00FF;
5011 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
5013 temp = (tempcx & 0xFF00) >> 8;
5014 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
5016 tempcx = pVBInfo->HT >> 1;
5017 push1 = tempcx; /* push cx */
5020 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5023 temp = tempcx & 0x00FF;
5025 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
5027 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5030 temp = tempbx & 0x00FF;
5031 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
5032 temp = (tempbx & 0xFF00) >> 8;
5034 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
5037 tempbx = tempbx + 8;
5038 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5039 tempbx = tempbx - 4;
5043 temp = (tempbx & 0x00FF) << 4;
5044 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
5047 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
5048 temp = tempcx & 0x00FF;
5049 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
5050 temp = ((tempcx & 0xFF00) >> 8) << 4;
5051 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
5054 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5057 temp = tempcx & 0xFF;
5059 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
5061 tempcx = push1; /* pop cx */
5063 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5065 temp = tempcx & 0x00FF;
5067 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
5071 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
5072 tempax = XGI_GetVGAHT2(pVBInfo);
5073 tempcx = tempax - 1;
5075 temp = tempcx & 0x00FF;
5076 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
5078 tempbx = pVBInfo->VDE;
5080 if (pVBInfo->VGAVDE == 360)
5082 if (pVBInfo->VGAVDE == 375)
5084 if (pVBInfo->VGAVDE == 405)
5087 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5088 if (pVBInfo->VBType &
5089 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5090 if (!(pVBInfo->TVInfo &
5091 (SetYPbPrMode525p | SetYPbPrMode750p)))
5092 tempbx = tempbx >> 1;
5094 tempbx = tempbx >> 1;
5098 temp = tempbx & 0x00FF;
5100 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5101 if (pVBInfo->VBType & VB_XGI301LV) {
5102 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5103 if (pVBInfo->VBInfo & SetInSlaveMode) {
5109 if (pVBInfo->VBInfo & SetInSlaveMode) {
5116 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
5118 temp = (tempcx & 0xFF00) >> 8;
5119 temp |= ((tempbx & 0xFF00) >> 8) << 6;
5121 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5122 if (pVBInfo->VBType & VB_XGI301LV) {
5123 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5126 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5131 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5136 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
5138 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5139 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5140 tempbx = pVBInfo->VDE;
5141 tempcx = tempbx - 2;
5143 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5144 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5145 | SetYPbPrMode750p)))
5146 tempbx = tempbx >> 1;
5149 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5151 if (tempcx & 0x0400)
5154 if (tempbx & 0x0400)
5157 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
5160 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
5161 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
5162 temp = (tempbx - 3) & 0x00FF;
5163 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
5166 tempbx = tempbx & 0x00FF;
5168 if (!(modeflag & HalfDCLK)) {
5169 tempcx = pVBInfo->VGAHDE;
5170 if (tempcx >= pVBInfo->HDE) {
5178 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5179 if (pVBInfo->VGAHDE >= 1024) {
5181 if (pVBInfo->VGAHDE >= 1280) {
5183 tempbx = tempbx & 0xDFFF;
5188 if (!(tempbx & 0x2000)) {
5189 if (modeflag & HalfDCLK)
5190 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
5193 tempeax = pVBInfo->VGAHDE;
5194 tempebx = (tempcx & 0xFF00) >> 8;
5195 longtemp = tempeax * tempebx;
5196 tempecx = tempcx & 0x00FF;
5197 longtemp = longtemp / tempecx;
5202 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5203 | VB_XGI302LV | VB_XGI301C)) {
5204 tempecx = tempecx * 8;
5207 longtemp = longtemp * tempecx;
5208 tempecx = pVBInfo->HDE;
5209 temp2 = longtemp % tempecx;
5210 tempeax = longtemp / tempecx;
5214 tempax = (unsigned short) tempeax;
5217 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5218 | VB_XGI302LV | VB_XGI301C)) {
5219 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5224 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5225 | (tempbx & 0x00FF));
5226 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5227 | (tempax & 0x00FF));
5228 temp = (tempax & 0xFF00) >> 8;
5230 temp = (tempax & 0x00FF) >> 8;
5233 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
5234 temp = (tempbx & 0xFF00) >> 8;
5235 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
5236 temp = tempcx & 0x00FF;
5238 if (tempbx & 0x2000)
5241 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5244 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
5245 if (pVBInfo->TVInfo & SetPALTV) {
5253 temp = tempbx & 0x00FF;
5254 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
5255 temp = tempcx & 0x00FF;
5256 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
5258 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5260 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
5262 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5265 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5268 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5272 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
5273 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
5274 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
5276 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5277 if (pVBInfo->TVInfo & NTSC1024x768) {
5278 TimingPoint = XGI_NTSC1024AdjTime;
5279 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
5280 xgifb_reg_set(pVBInfo->Part2Port, i,
5283 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
5287 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5288 if (pVBInfo->VBType & VB_XGI301C) {
5289 if (pVBInfo->TVInfo & SetPALMTV)
5290 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
5291 0x08); /* PALM Mode */
5294 if (pVBInfo->TVInfo & SetPALMTV) {
5295 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
5298 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
5300 /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
5301 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
5304 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5305 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5306 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
5309 if (pVBInfo->VBInfo & SetCRT2ToTV)
5313 static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
5314 struct xgi_hw_device_info *HwDeviceExtension,
5315 unsigned short RefreshRateTableIndex,
5316 struct vb_device_info *pVBInfo)
5318 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5319 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
5321 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5323 if (ModeNo <= 0x13) {
5325 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5326 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5328 /* si+Ext_ResInfo */
5329 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5330 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5331 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5333 CRT1Index &= IndexMask;
5336 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5339 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
5341 if (XGI_IsLCDDualLink(pVBInfo))
5342 tempbx = tempbx >> 1;
5345 temp = tempbx & 0x00FF;
5346 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
5347 temp = (tempbx & 0xFF00) >> 8;
5349 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
5352 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5353 if (pVBInfo->ModeType == ModeEGA) {
5354 if (pVBInfo->VGAHDE >= 1024) {
5356 if (pVBInfo->LCDInfo & LCDVESATiming)
5362 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
5363 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5366 temp = tempbx & 0x00FF;
5367 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
5368 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
5369 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
5371 tempcx = pVBInfo->VT - 1;
5373 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
5374 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
5375 temp = (tempcx & 0xFF00) >> 8;
5377 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
5378 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5379 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5380 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5381 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
5383 /* Customized LCDB Des no add */
5385 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5386 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5387 tempah = pVBInfo->LCDResInfo;
5388 tempah &= PanelResInfo;
5390 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5393 } else if ((tempah == Panel1280x1024) ||
5394 (tempah == Panel1280x1024x75)) {
5397 } else if (tempah == Panel1400x1050) {
5405 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5406 tempbx = pVBInfo->HDE;
5407 tempcx = pVBInfo->VDE;
5411 tempax = pVBInfo->VT;
5412 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5413 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5414 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5415 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5416 tempbx = pVBInfo->LCDVDES;
5419 if (tempcx >= tempax)
5420 tempcx -= tempax; /* lcdvdes */
5422 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
5423 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
5424 temp = tempcx & 0x00FF;
5425 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
5426 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5427 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5429 tempah = tempah << 3;
5431 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
5434 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5436 tempax = pVBInfo->VT;
5437 tempbx = pVBInfo->LCDVRS;
5439 /* if (SetLCD_Info & EnableScalingLCD) */
5441 if (tempcx >= tempax)
5444 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
5445 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
5446 temp = (tempbx & 0xFF00) >> 8;
5448 temp |= (tempcx & 0x000F);
5449 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
5451 tempax = pVBInfo->HT;
5452 tempbx = pVBInfo->LCDHDES;
5455 if (XGI_IsLCDDualLink(pVBInfo)) {
5456 tempax = tempax >> 1;
5457 tempbx = tempbx >> 1;
5458 tempcx = tempcx >> 1;
5461 if (pVBInfo->VBType & VB_XGI302LV)
5464 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5469 if (tempcx >= tempax)
5472 temp = tempbx & 0x00FF;
5473 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
5474 temp = ((tempbx & 0xFF00) >> 8) << 4;
5475 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
5476 temp = tempcx & 0x00FF;
5477 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
5478 temp = (tempcx & 0xFF00) >> 8;
5479 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
5482 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5484 tempax = pVBInfo->HT;
5485 tempbx = pVBInfo->LCDHRS;
5486 /* if ( SetLCD_Info & EnableScalingLCD) */
5487 if (XGI_IsLCDDualLink(pVBInfo)) {
5488 tempax = tempax >> 1;
5489 tempbx = tempbx >> 1;
5490 tempcx = tempcx >> 1;
5493 if (pVBInfo->VBType & VB_XGI302LV)
5498 if (tempcx >= tempax)
5501 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
5502 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
5504 temp = (tempbx & 0xFF00) >> 8;
5506 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
5507 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
5508 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
5510 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5511 if (pVBInfo->VGAVDE == 525) {
5512 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5513 | VB_XGI301LV | VB_XGI302LV
5519 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5520 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
5523 if (pVBInfo->VGAVDE == 420) {
5524 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5525 | VB_XGI301LV | VB_XGI302LV
5530 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5535 /* --------------------------------------------------------------------- */
5536 /* Function : XGI_GetTap4Ptr */
5538 /* Output : di -> Tap4 Reg. Setting Pointer */
5540 /* --------------------------------------------------------------------- */
5541 static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
5542 struct vb_device_info *pVBInfo)
5544 unsigned short tempax, tempbx, i;
5546 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5549 tempax = pVBInfo->VGAHDE;
5550 tempbx = pVBInfo->HDE;
5552 tempax = pVBInfo->VGAVDE;
5553 tempbx = pVBInfo->VDE;
5556 if (tempax <= tempbx)
5557 return &xgifb_tap4_timing[0];
5559 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
5561 if (pVBInfo->TVInfo & SetPALTV)
5562 Tap4TimingPtr = PALTap4Timing;
5564 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5565 if ((pVBInfo->TVInfo & SetYPbPrMode525i) ||
5566 (pVBInfo->TVInfo & SetYPbPrMode525p))
5567 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
5568 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5569 Tap4TimingPtr = YPbPr750pTap4Timing;
5572 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5573 Tap4TimingPtr = xgifb_tap4_timing;
5576 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5577 if (Tap4TimingPtr[i].DE == tempax)
5581 return &Tap4TimingPtr[i];
5584 static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
5586 unsigned short i, j;
5588 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5590 if (!(pVBInfo->VBType & VB_XGI301C))
5593 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5594 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
5595 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
5597 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5598 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5599 /* Set Vertical Scaling */
5600 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
5601 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
5602 xgifb_reg_set(pVBInfo->Part2Port,
5604 Tap4TimingPtr->Reg[j]);
5607 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5608 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5609 /* Enable V.Scaling */
5610 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
5612 /* Enable H.Scaling */
5613 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
5616 static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
5617 struct vb_device_info *pVBInfo)
5620 unsigned char *tempdi;
5621 unsigned short modeflag;
5625 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5627 /* si+Ext_ResInfo */
5628 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5630 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
5631 if (pVBInfo->TVInfo & SetPALTV) {
5632 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5633 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5635 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5636 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
5639 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5642 if (pVBInfo->TVInfo & SetPALMTV) {
5643 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5644 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5645 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
5648 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5649 & SetCRT2ToYPbPr)) {
5650 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5653 tempdi = pVBInfo->HiTVGroup3Data;
5654 if (pVBInfo->SetFlag & TVSimuMode) {
5655 tempdi = pVBInfo->HiTVGroup3Simu;
5656 if (!(modeflag & Charx8Dot))
5657 tempdi = pVBInfo->HiTVGroup3Text;
5660 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5661 tempdi = pVBInfo->Ren525pGroup3;
5663 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5664 tempdi = pVBInfo->Ren750pGroup3;
5666 for (i = 0; i <= 0x3E; i++)
5667 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
5669 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5670 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5671 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
5675 } /* {end of XGI_SetGroup3} */
5677 static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
5678 unsigned short RefreshRateTableIndex,
5679 struct xgi_hw_device_info *HwDeviceExtension,
5680 struct vb_device_info *pVBInfo)
5682 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
5684 unsigned long tempebx, tempeax, templong;
5688 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5690 /* si+Ext_ResInfo */
5691 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5693 temp = pVBInfo->RVBHCFACT;
5694 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
5696 tempbx = pVBInfo->RVBHCMAX;
5697 temp = tempbx & 0x00FF;
5698 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
5699 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5700 tempcx = pVBInfo->VGAHT - 1;
5701 temp = tempcx & 0x00FF;
5702 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
5704 temp = ((tempcx & 0xFF00) >> 8) << 3;
5707 tempcx = pVBInfo->VGAVT - 1;
5708 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5711 temp = tempcx & 0x00FF;
5712 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
5713 temp = temp2 | ((tempcx & 0xFF00) >> 8);
5714 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
5715 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
5716 tempcx = pVBInfo->VBInfo;
5717 tempbx = pVBInfo->VGAHDE;
5719 if (modeflag & HalfDCLK)
5720 tempbx = tempbx >> 1;
5722 if (XGI_IsLCDDualLink(pVBInfo))
5723 tempbx = tempbx >> 1;
5725 if (tempcx & SetCRT2ToHiVisionTV) {
5731 } else if (tempcx & SetCRT2ToTV) {
5737 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5744 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
5746 if (pVBInfo->VGAHDE == 1280)
5748 if (pVBInfo->VGAHDE == 1024)
5751 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
5753 tempebx = pVBInfo->VDE;
5755 if (tempcx & SetCRT2ToHiVisionTV) {
5756 if (!(temp & 0xE000))
5757 tempbx = tempbx >> 1;
5760 tempcx = pVBInfo->RVBHRS;
5761 temp = tempcx & 0x00FF;
5762 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
5764 tempeax = pVBInfo->VGAVDE;
5767 if (tempeax <= tempebx) {
5768 tempcx = (tempcx & (~0x4000));
5769 tempeax = pVBInfo->VGAVDE;
5774 templong = (tempeax * 256 * 1024) % tempebx;
5775 tempeax = (tempeax * 256 * 1024) / tempebx;
5781 temp = (unsigned short) (tempebx & 0x000000FF);
5782 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
5784 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
5785 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
5786 tempbx = (unsigned short) (tempebx >> 16);
5787 temp = tempbx & 0x00FF;
5789 temp |= ((tempcx & 0xFF00) >> 8);
5790 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
5793 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5794 | VB_XGI302LV | VB_XGI301C)) {
5796 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
5797 tempax = pVBInfo->VGAHDE;
5798 if (modeflag & HalfDCLK)
5799 tempax = tempax >> 1;
5801 if (XGI_IsLCDDualLink(pVBInfo))
5802 tempax = tempax >> 1;
5804 /* if((pVBInfo->VBInfo&(SetCRT2ToLCD)) ||
5805 ((pVBInfo->TVInfo&SetYPbPrMode525p) ||
5806 (pVBInfo->TVInfo&SetYPbPrMode750p))) { */
5807 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5811 if (pVBInfo->VGAHDE > 800) {
5812 if (pVBInfo->VGAHDE == 1024)
5813 tempax = (tempax * 25 / 32) - 1;
5815 tempax = (tempax * 20 / 32) - 1;
5821 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5822 if (pVBInfo->VBType & VB_XGI301LV) {
5823 if (!(pVBInfo->TVInfo &
5826 SetYPbPrMode1080i))) {
5827 if (pVBInfo->VGAHDE > 800) {
5828 if (pVBInfo->VGAHDE == 1024)
5829 tempax =(tempax * 25 /
5832 tempax = (tempax * 20 /
5837 if (pVBInfo->VGAHDE > 800) {
5838 if (pVBInfo->VGAHDE == 1024)
5839 tempax = (tempax * 25 / 32) - 1;
5841 tempax = (tempax * 20 / 32) - 1;
5847 temp = (tempax & 0xFF00) >> 8;
5848 temp = ((temp & 0x0003) << 4);
5849 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
5850 temp = (tempax & 0x00FF);
5851 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
5853 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5854 if (pVBInfo->VGAHDE > 800)
5855 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
5860 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5861 if (!(pVBInfo->TVInfo & (NTSC1024x768
5862 | SetYPbPrMode525p | SetYPbPrMode750p
5863 | SetYPbPrMode1080i))) {
5865 if ((pVBInfo->VBInfo & SetInSlaveMode)
5866 && (!(pVBInfo->TVInfo
5872 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
5873 tempbx = pVBInfo->HT;
5874 if (XGI_IsLCDDualLink(pVBInfo))
5875 tempbx = tempbx >> 1;
5876 tempbx = (tempbx >> 1) - 2;
5877 temp = ((tempbx & 0x0700) >> 8) << 3;
5878 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
5879 temp = tempbx & 0x00FF;
5880 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
5884 if (pVBInfo->ISXPDOS == 0)
5885 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5889 static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5891 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
5894 static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
5895 struct vb_device_info *pVBInfo)
5897 unsigned short Pindex, Pdata;
5899 Pindex = pVBInfo->Part5Port;
5900 Pdata = pVBInfo->Part5Port + 1;
5901 if (pVBInfo->ModeType == ModeVGA) {
5902 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
5903 | CRT2DisplayFlag))) {
5904 XGINew_EnableCRT2(pVBInfo);
5905 /* LoadDAC2(pVBInfo->Part5Port, ModeNo, ModeIdIndex); */
5911 static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
5912 struct vb_device_info *pVBInfo)
5914 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
5917 static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
5918 struct vb_device_info *pVBInfo)
5921 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
5924 /*----------------------------------------------------------------------------*/
5926 /* bl[5] : 1;LVDS signal on */
5927 /* bl[1] : 1;LVDS backlight on */
5928 /* bl[0] : 1:LVDS VDD on */
5929 /* bh: 100000b : clear bit 5, to set bit5 */
5930 /* 000010b : clear bit 1, to set bit1 */
5931 /* 000001b : clear bit 0, to set bit0 */
5932 /*----------------------------------------------------------------------------*/
5933 void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
5934 struct vb_device_info *pVBInfo)
5936 unsigned char CR4A, temp;
5938 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
5941 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
5943 if (tempbh & 0x20) {
5944 temp = (tempbl >> 4) & 0x02;
5947 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
5951 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
5953 temp = XG21GPIODataTransfer(temp);
5956 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
5959 void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
5960 struct vb_device_info *pVBInfo)
5962 unsigned char CR4A, temp;
5963 unsigned short tempbh0, tempbl0;
5972 if (tempbh & 0x20) {
5973 temp = (tempbl >> 4) & 0x02;
5976 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
5979 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
5981 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
5985 tempbl <<= 2; /* GPIOC,GPIOD */
5986 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
5987 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
5990 /* --------------------------------------------------------------------- */
5991 unsigned short XGI_GetLVDSOEMTableIndex(struct vb_device_info *pVBInfo)
5993 unsigned short index;
5995 index = xgifb_reg_get(pVBInfo->P3d4, 0x36);
5996 if (index < sizeof(XGI21_LCDCapList)
5997 / sizeof(struct XGI21_LVDSCapStruct))
6002 /* --------------------------------------------------------------------- */
6003 /* Function : XGI_XG21SetPanelDelay */
6007 /* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
6008 /* : bl : 2 ; T2 : the duration signal on and Vdd on */
6009 /* : bl : 3 ; T3 : the duration between CPL off and signal off */
6010 /* : bl : 4 ; T4 : the duration signal off and Vdd off */
6011 /* --------------------------------------------------------------------- */
6012 void XGI_XG21SetPanelDelay(unsigned short tempbl,
6013 struct vb_device_info *pVBInfo)
6015 unsigned short index;
6017 index = XGI_GetLVDSOEMTableIndex(pVBInfo);
6019 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S1);
6022 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S2);
6025 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S3);
6028 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S4);
6031 unsigned char XGI_XG21CheckLVDSMode(unsigned short ModeNo,
6032 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
6034 unsigned short xres, yres, colordepth, modeflag, resindex,
6037 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6038 if (ModeNo <= 0x13) {
6039 xres = pVBInfo->StResInfo[resindex].HTotal;
6040 yres = pVBInfo->StResInfo[resindex].VTotal;
6042 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
6044 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6045 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
6046 /* si+St_ModeFlag */
6047 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6050 if (!(modeflag & Charx8Dot)) {
6055 if (ModeNo > 0x13) {
6056 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
6059 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6064 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6065 if (xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE))
6068 if (yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE))
6071 if (ModeNo > 0x13) {
6072 if ((xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6074 (yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6076 colordepth = XGI_GetColorDepth(ModeNo,
6087 void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
6091 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
6092 temp = (temp & 1) << 6;
6093 /* SR06[6] 18bit Dither */
6094 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
6095 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
6096 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
6100 void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
6104 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
6105 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
6106 temp = (temp & 3) << 6;
6107 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
6108 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
6109 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
6110 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
6114 static void xgifb_set_lvds(int chip_id,
6115 unsigned short ModeNo,
6116 unsigned short ModeIdIndex,
6117 struct vb_device_info *pVBInfo)
6119 unsigned char temp, Miscdata;
6120 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6121 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6122 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6123 unsigned short value;
6125 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6126 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6128 (LCDPolarity << 8)) >> 8);
6129 temp &= LCDPolarity;
6130 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
6132 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
6134 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6135 LVDS_Capability & LCDPolarity);
6136 /* SR35[7] FP VSync polarity */
6137 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6138 /* SR30[5] FP HSync polarity */
6139 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
6141 if (chip_id == XG27)
6142 XGI_SetXG27FPBits(pVBInfo);
6144 XGI_SetXG21FPBits(pVBInfo);
6146 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6147 if (ModeNo <= 0x13) {
6148 xres = pVBInfo->StResInfo[resindex].HTotal;
6149 yres = pVBInfo->StResInfo[resindex].VTotal;
6151 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
6153 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6154 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
6155 /* si+St_ModeFlag */
6156 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6159 if (!(modeflag & Charx8Dot))
6160 xres = xres * 8 / 9;
6162 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
6164 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6166 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6167 LVDSHBS -= xres / 4;
6169 if (LVDSHBS > LVDSHT)
6172 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6173 if (LVDSHRS > LVDSHT)
6176 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6177 if (LVDSHRE > LVDSHT)
6180 LVDSHBE = LVDSHBS + LVDSHT
6181 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
6183 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
6185 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6187 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6188 LVDSVBS += yres / 2;
6190 if (LVDSVBS > LVDSVT)
6193 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6194 if (LVDSVRS > LVDSVT)
6197 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].
6199 if (LVDSVRE > LVDSVT)
6202 LVDSVBE = LVDSVBS + LVDSVT
6203 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
6205 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
6206 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
6208 if (!(modeflag & Charx8Dot))
6209 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
6211 /* HT SR0B[1:0] CR00 */
6212 value = (LVDSHT >> 3) - 5;
6213 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
6214 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
6216 /* HBS SR0B[5:4] CR02 */
6217 value = (LVDSHBS >> 3) - 1;
6218 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
6219 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
6221 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6222 value = (LVDSHBE >> 3) - 1;
6223 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6224 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6225 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
6227 /* HRS SR0B[7:6] CR04 */
6228 value = (LVDSHRS >> 3) + 2;
6229 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
6230 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
6232 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6234 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
6235 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
6237 /* HRE SR0C[2] CR05[4:0] */
6238 value = (LVDSHRE >> 3) + 2;
6239 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6240 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
6242 /* Panel HRE SR2F[7:2] */
6244 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
6246 /* VT SR0A[0] CR07[5][0] CR06 */
6248 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6249 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6250 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
6251 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
6253 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6254 value = LVDSVBS - 1;
6255 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6256 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6257 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
6258 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
6260 /* VBE SR0A[4] CR16 */
6261 value = LVDSVBE - 1;
6262 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
6263 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
6265 /* VRS SR0A[3] CR7[7][2] CR10 */
6266 value = LVDSVRS - 1;
6267 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6268 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6269 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
6270 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
6272 if (chip_id == XG27) {
6273 /* Panel VRS SR35[2:0] SR34[7:0] */
6274 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
6275 (value & 0x700) >> 8);
6276 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
6278 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
6279 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
6280 (value & 0x600) >> 9);
6281 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
6282 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
6285 /* VRE SR0A[5] CR11[3:0] */
6286 value = LVDSVRE - 1;
6287 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6288 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
6290 /* Panel VRE SR3F[7:2] */
6291 if (chip_id == XG27)
6292 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6293 (value << 2) & 0xFC);
6295 /* SR3F[7] has to be 0, h/w bug */
6296 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6297 (value << 2) & 0x7C);
6299 for (temp = 0, value = 0; temp < 3; temp++) {
6301 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
6302 xgifb_reg_set(pVBInfo->P3c4,
6304 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6306 xgifb_reg_set(pVBInfo->P3c4,
6308 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6313 if (!(modeflag & Charx8Dot)) {
6314 inb(pVBInfo->P3da); /* reset 3da */
6315 outb(0x13, pVBInfo->P3c0); /* set index */
6316 /* set data, panning = 0, shift left 1 dot*/
6317 outb(0x00, pVBInfo->P3c0);
6319 inb(pVBInfo->P3da); /* Enable Attribute */
6320 outb(0x20, pVBInfo->P3c0);
6322 inb(pVBInfo->P3da); /* reset 3da */
6327 /* --------------------------------------------------------------------- */
6328 /* Function : XGI_IsLCDON */
6330 /* Output : 0 : Skip PSC Control */
6331 /* 1: Disable PSC */
6333 /* --------------------------------------------------------------------- */
6334 static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
6336 unsigned short tempax;
6338 tempax = pVBInfo->VBInfo;
6339 if (tempax & SetCRT2ToDualEdge)
6341 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6347 /* --------------------------------------------------------------------- */
6348 /* Function : XGI_DisableChISLCD */
6350 /* Output : 0 -> Not LCD Mode */
6352 /* --------------------------------------------------------------------- */
6353 static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
6355 unsigned short tempbx, tempah;
6357 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
6358 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
6360 if (tempbx & (EnableChA | DisableChA)) {
6361 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6365 if (!(tempbx & (EnableChB | DisableChB)))
6368 if (tempah & 0x01) /* Chk LCDB Mode */
6374 /* --------------------------------------------------------------------- */
6375 /* Function : XGI_EnableChISLCD */
6377 /* Output : 0 -> Not LCD mode */
6379 /* --------------------------------------------------------------------- */
6380 static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
6382 unsigned short tempbx, tempah;
6384 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
6385 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
6387 if (tempbx & (EnableChA | DisableChA)) {
6388 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6392 if (!(tempbx & (EnableChB | DisableChB)))
6395 if (tempah & 0x01) /* Chk LCDB Mode */
6401 void XGI_DisableBridge(struct xgi_hw_device_info *HwDeviceExtension,
6402 struct vb_device_info *pVBInfo)
6404 unsigned short tempah = 0;
6406 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6407 | VB_XGI302LV | VB_XGI301C)) {
6409 if (!(pVBInfo->VBInfo &
6410 (DisableCRT2Display | SetSimuScanMode))) {
6411 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6412 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6413 tempah = 0x7F; /* Disable Channel A */
6414 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6415 /* Disable Channel B */
6418 if (pVBInfo->SetFlag & DisableChB)
6419 /* force to disable Cahnnel */
6422 if (pVBInfo->SetFlag & DisableChA)
6423 /* Force to disable Channel B */
6429 /* disable part4_1f */
6430 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
6432 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6433 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6434 || (XGI_DisableChISLCD(pVBInfo))
6435 || (XGI_IsLCDON(pVBInfo)))
6436 /* LVDS Driver power down */
6437 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
6440 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6441 & (DisableCRT2Display | SetCRT2ToLCDA
6442 | SetSimuScanMode))) {
6443 if (pVBInfo->SetFlag & GatingCRT)
6444 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6445 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6448 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6449 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6452 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
6455 /* disable TV as primary VGA swap */
6456 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
6458 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
6459 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
6461 if ((pVBInfo->SetFlag & DisableChB) ||
6463 (DisableCRT2Display | SetSimuScanMode)) ||
6464 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6466 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6468 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6470 if ((pVBInfo->SetFlag & DisableChB) ||
6472 (DisableCRT2Display | SetSimuScanMode)) ||
6473 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6475 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6476 /* save Part1 index 0 */
6477 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6478 /* BTDAC = 1, avoid VB reset */
6479 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6481 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6482 /* restore Part1 index 0 */
6483 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
6485 } else { /* {301} */
6486 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
6488 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6490 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6491 /* Disable TV asPrimary VGA swap */
6492 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
6495 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6497 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6501 /* --------------------------------------------------------------------- */
6502 /* Function : XGI_GetTVPtrIndex */
6505 /* Description : bx 0 : ExtNTSC */
6517 /* --------------------------------------------------------------------- */
6518 static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
6520 unsigned short tempbx = 0;
6522 if (pVBInfo->TVInfo & SetPALTV)
6524 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
6526 if (pVBInfo->TVInfo & SetYPbPrMode525i)
6528 if (pVBInfo->TVInfo & SetYPbPrMode525p)
6530 if (pVBInfo->TVInfo & SetYPbPrMode750p)
6532 if (pVBInfo->TVInfo & TVSimuMode)
6538 /* --------------------------------------------------------------------- */
6539 /* Function : XGI_GetTVPtrIndex2 */
6541 /* Output : bx 0 : NTSC */
6545 /* 4 : NTSC1024x768 */
6546 /* 5 : PAL-M 1024x768 */
6548 /* cl 0 : YFilter1 */
6551 /* 1 : 301B/302B/301LV/302LV */
6553 /* --------------------------------------------------------------------- */
6554 static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
6555 unsigned char *tempch, struct vb_device_info *pVBInfo)
6561 if (pVBInfo->TVInfo & SetPALTV)
6564 if (pVBInfo->TVInfo & SetPALMTV)
6567 if (pVBInfo->TVInfo & SetPALNTV)
6570 if (pVBInfo->TVInfo & NTSC1024x768) {
6572 if (pVBInfo->TVInfo & SetPALMTV)
6576 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6577 | VB_XGI302LV | VB_XGI301C)) {
6578 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
6585 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6586 | VB_XGI302LV | VB_XGI301C))
6590 static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
6592 unsigned short index;
6594 unsigned char tempah, tempbl, tempbh;
6596 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6597 | VB_XGI302LV | VB_XGI301C)) {
6598 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
6599 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
6603 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
6604 tempbl = pVBInfo->XGI_TVDelayList[index];
6606 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6607 | VB_XGI301LV | VB_XGI302LV
6609 tempbl = pVBInfo->XGI_TVDelayList2[index];
6611 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6612 tempbl = tempbl >> 4;
6614 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
6615 tempbl = CRT2Delay1; // Get CRT2 Delay
6616 if (pVBInfo->VBType &
6622 tempbl = CRT2Delay2;
6624 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
6626 index = XGI_GetLCDCapPtr(pVBInfo);
6627 tempbh = pVBInfo->LCDCapList[index].
6628 LCD_DelayCompensation;
6630 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6636 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
6638 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
6639 | SetCRT2ToTV)) { /* Channel B */
6644 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
6648 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
6650 } else if (pVBInfo->IF_DEF_LVDS == 1) {
6653 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
6654 /* / Get LCD Delay */
6655 tempah = pVBInfo->LCDCapList[
6656 XGI_GetLCDCapPtr(pVBInfo)].
6657 LCD_DelayCompensation;
6659 tempah = tempah << 4;
6660 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
6666 static void XGI_SetLCDCap_A(unsigned short tempcx,
6667 struct vb_device_info *pVBInfo)
6669 unsigned short temp;
6671 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
6673 if (temp & LCDRGB18Bit) {
6674 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
6676 (unsigned short) (0x20 | (tempcx & 0x00C0)));
6677 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
6679 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
6680 (unsigned short) (0x30 | (tempcx & 0x00C0)));
6681 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
6685 if (tempcx & EnableLCD24bpp) { // 24bits
6686 xgifb_reg_and_or(pVBInfo->Part1Port,
6689 (unsigned short)(0x30 | (tempcx&0x00C0)));
6690 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
6692 xgifb_reg_and_or(pVBInfo->Part1Port,
6696 (unsigned short)(0x20 | (tempcx&0x00C0)));
6697 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
6702 /* --------------------------------------------------------------------- */
6703 /* Function : XGI_SetLCDCap_B */
6704 /* Input : cx -> LCD Capability */
6707 /* --------------------------------------------------------------------- */
6708 static void XGI_SetLCDCap_B(unsigned short tempcx,
6709 struct vb_device_info *pVBInfo)
6711 if (tempcx & EnableLCD24bpp) /* 24bits */
6712 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
6713 (unsigned short) (((tempcx & 0x00ff) >> 6)
6716 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
6717 (unsigned short) (((tempcx & 0x00ff) >> 6)
6718 | 0x18)); /* Enable Dither */
6721 static void SetSpectrum(struct vb_device_info *pVBInfo)
6723 unsigned short index;
6725 index = XGI_GetLCDCapPtr(pVBInfo);
6727 /* disable down spectrum D[4] */
6728 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
6729 XGI_LongWait(pVBInfo);
6730 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
6731 XGI_LongWait(pVBInfo);
6733 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
6734 pVBInfo->LCDCapList[index].Spectrum_31);
6735 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
6736 pVBInfo->LCDCapList[index].Spectrum_32);
6737 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
6738 pVBInfo->LCDCapList[index].Spectrum_33);
6739 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
6740 pVBInfo->LCDCapList[index].Spectrum_34);
6741 XGI_LongWait(pVBInfo);
6742 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
6745 static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
6747 unsigned short tempcx;
6749 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
6751 if (pVBInfo->VBType &
6756 VB_XGI301C)) { /* 301LV/302LV only */
6757 if (pVBInfo->VBType &
6758 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
6759 /* Set 301LV Capability */
6760 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
6761 (unsigned char) (tempcx & 0x1F));
6764 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
6765 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6766 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6767 | EnablePLLSPLOW)) >> 8));
6770 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6771 | VB_XGI302LV | VB_XGI301C)) {
6772 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6773 XGI_SetLCDCap_B(tempcx, pVBInfo);
6774 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6775 XGI_SetLCDCap_A(tempcx, pVBInfo);
6777 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6778 if (tempcx & EnableSpectrum)
6779 SetSpectrum(pVBInfo);
6783 XGI_SetLCDCap_A(tempcx, pVBInfo);
6787 /* --------------------------------------------------------------------- */
6788 /* Function : XGI_SetAntiFlicker */
6791 /* Description : Set TV Customized Param. */
6792 /* --------------------------------------------------------------------- */
6793 static void XGI_SetAntiFlicker(unsigned short ModeNo,
6794 unsigned short ModeIdIndex,
6795 struct vb_device_info *pVBInfo)
6797 unsigned short tempbx, index;
6799 unsigned char tempah;
6801 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
6804 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6808 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6810 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
6813 tempah = TVAntiFlickList[tempbx];
6814 tempah = tempah << 4;
6816 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
6819 static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6820 unsigned short ModeIdIndex,
6821 struct vb_device_info *pVBInfo)
6823 unsigned short tempbx, index;
6825 unsigned char tempah;
6827 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6831 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6833 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
6836 tempah = TVEdgeList[tempbx];
6837 tempah = tempah << 5;
6839 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
6842 static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
6844 unsigned short tempbx;
6846 unsigned char tempcl, tempch;
6848 unsigned long tempData;
6850 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6851 tempData = TVPhaseList[tempbx];
6853 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
6855 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
6856 & 0x0000FF00) >> 8));
6857 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
6858 & 0x00FF0000) >> 16));
6859 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
6860 & 0xFF000000) >> 24));
6863 static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
6864 struct vb_device_info *pVBInfo)
6866 unsigned short tempbx, index;
6868 unsigned char tempcl, tempch, tempal, *filterPtr;
6870 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6875 filterPtr = NTSCYFilter1;
6879 filterPtr = PALYFilter1;
6886 filterPtr = xgifb_palmn_yfilter1;
6894 filterPtr = xgifb_yfilter2;
6902 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
6903 VB_StTVYFilterIndex;
6905 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
6906 VB_ExtTVYFilterIndex;
6913 if ((tempcl == 0) && (tempch == 1)) {
6914 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6915 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6916 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6917 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
6919 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6920 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6921 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6922 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
6925 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6926 | VB_XGI302LV | VB_XGI301C)) {
6927 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6928 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6929 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
6933 /* --------------------------------------------------------------------- */
6934 /* Function : XGI_OEM310Setting */
6937 /* Description : Customized Param. for 301 */
6938 /* --------------------------------------------------------------------- */
6939 static void XGI_OEM310Setting(unsigned short ModeNo,
6940 unsigned short ModeIdIndex,
6941 struct vb_device_info *pVBInfo)
6944 XGI_SetDelayComp(pVBInfo);
6946 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
6947 XGI_SetLCDCap(pVBInfo);
6949 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6951 XGI_SetPhaseIncr(pVBInfo);
6952 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6953 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
6955 if (pVBInfo->VBType & VB_XGI301)
6956 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
6960 /* --------------------------------------------------------------------- */
6961 /* Function : XGI_SetCRT2ModeRegs */
6964 /* Description : Origin code for crt2group */
6965 /* --------------------------------------------------------------------- */
6966 void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
6967 struct xgi_hw_device_info *HwDeviceExtension,
6968 struct vb_device_info *pVBInfo)
6970 unsigned short tempbl;
6973 unsigned char tempah;
6975 /* // fix write part1 index 0 BTDRAM bit Bug
6976 * xgifb_reg_set(pVBInfo->Part1Port, 0x03, 0x00); */
6978 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6979 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6980 tempah &= ~0x10; /* BTRAMDAC */
6981 tempah |= 0x40; /* BTRAM */
6983 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6985 tempah = 0x40; /* BTDRAM */
6986 if (ModeNo > 0x13) {
6987 tempcl = pVBInfo->ModeType;
6991 tempah = (0x008 >> tempcl);
6997 if (pVBInfo->VBInfo & SetInSlaveMode)
6998 tempah ^= 0x50; /* BTDAC */
7003 if (pVBInfo->VBInfo & DisableCRT2Display) {
7007 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
7008 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)) {
7009 tempcl = pVBInfo->ModeType;
7010 if (ModeNo > 0x13) {
7012 if ((tempcl > 0) || (tempcl == 0)) {
7013 tempah=(0x008>>tempcl) ;
7022 if (pVBInfo->VBInfo & SetInSlaveMode) {
7023 tempah = (tempah ^ 0x050);
7028 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
7032 if (pVBInfo->VBInfo & DisableCRT2Display) {
7033 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
7038 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7039 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
7040 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
7041 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
7044 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
7047 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7052 if (pVBInfo->VBInfo &
7059 if (!(pVBInfo->VBInfo & SetInSlaveMode))
7062 if (!(pVBInfo->VBInfo &
7064 tempah = tempah ^ 0x05;
7065 if (!(pVBInfo->VBInfo &
7067 tempah = tempah ^ 0x01;
7070 if (!(pVBInfo->VBInfo &
7073 xgifb_reg_and_or(pVBInfo->Part1Port,
7074 0x2e, tempbl, tempah);
7076 xgifb_reg_and_or(pVBInfo->Part1Port,
7077 0x2e, tempbl, tempah);
7081 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
7086 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
7089 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
7090 & SetInSlaveMode))) {
7095 if (pVBInfo->VBInfo & SetCRT2ToTV) {
7096 /* if (!(pVBInfo->TVInfo &
7097 (SetYPbPrMode525p | SetYPbPrMode750p))) { */
7099 if (ModeNo > 0x13) {
7100 if (pVBInfo->VBInfo & DriverMode)
7101 tempah = tempah ^ 0x20;
7106 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
7109 if (pVBInfo->LCDInfo & SetLCDDualLink)
7112 if (pVBInfo->VBInfo & SetCRT2ToTV) {
7113 /* if ((!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) &&
7114 (!(pVBInfo->TVInfo &
7115 (SetYPbPrMode525p | SetYPbPrMode750p)))) { */
7116 if (pVBInfo->TVInfo & RPLLDIV2XO)
7121 if ((pVBInfo->LCDResInfo == Panel1280x1024)
7122 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
7125 if (pVBInfo->LCDResInfo == Panel1280x960)
7128 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
7131 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7132 | VB_XGI302LV | VB_XGI301C)) {
7136 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7138 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7139 tempah |= 0x04; /* shampoo 0129 */
7142 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
7145 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7146 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7150 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
7154 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7155 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7158 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
7163 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
7165 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
7169 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
7171 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7172 if (pVBInfo->LCDInfo & SetLCDDualLink) {
7173 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
7174 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
7179 static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
7180 struct vb_device_info *pVBInfo)
7182 unsigned short tempbx;
7186 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7191 void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7192 struct vb_device_info *pVBInfo)
7195 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
7199 void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7200 struct vb_device_info *pVBInfo)
7203 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
7207 unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
7209 unsigned short flag;
7211 if (pVBInfo->IF_DEF_LVDS == 1) {
7214 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
7215 if ((flag == 1) || (flag == 2))
7216 return 1; /* 301b */
7222 void XGI_LongWait(struct vb_device_info *pVBInfo)
7226 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
7229 for (i = 0; i < 0xFFFF; i++) {
7230 if (!(inb(pVBInfo->P3da) & 0x08))
7234 for (i = 0; i < 0xFFFF; i++) {
7235 if ((inb(pVBInfo->P3da) & 0x08))
7241 static void XGI_VBLongWait(struct vb_device_info *pVBInfo)
7243 unsigned short tempal, temp, i, j;
7245 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
7247 for (i = 0; i < 3; i++) {
7248 for (j = 0; j < 100; j++) {
7249 tempal = inb(pVBInfo->P3da);
7250 if (temp & 0x01) { /* VBWaitMode2 */
7251 if ((tempal & 0x08))
7254 if (!(tempal & 0x08))
7257 } else { /* VBWaitMode1 */
7258 if (!(tempal & 0x08))
7261 if ((tempal & 0x08))
7268 XGI_LongWait(pVBInfo);
7273 unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
7274 unsigned short ModeNo, unsigned short ModeIdIndex,
7275 struct vb_device_info *pVBInfo)
7277 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
7278 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
7281 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
7284 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7286 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7291 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
7292 index = index >> pVBInfo->SelectCRT2Rate;
7295 if (pVBInfo->LCDInfo & LCDNonExpanding)
7301 if (pVBInfo->SetFlag & ProgrammingCRT2) {
7302 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
7303 if (pVBInfo->IF_DEF_LVDS == 0) {
7304 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7305 | VB_XGI301LV | VB_XGI302LV
7308 temp = LCDARefreshIndex[
7309 pVBInfo->LCDResInfo & 0x0F];
7311 temp = LCDRefreshIndex[
7312 pVBInfo->LCDResInfo & 0x0F];
7322 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
7323 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
7324 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
7326 if (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag &
7331 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
7332 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
7336 * do the similar adjustment like XGISearchCRT1Rate() */
7337 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
7338 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
7341 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
7342 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
7349 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
7352 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
7354 temp &= ModeInfoFlag;
7355 if (temp < pVBInfo->ModeType)
7360 } while (index != 0xFFFF);
7361 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
7362 if (pVBInfo->VBInfo & SetInSlaveMode) {
7363 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
7365 if (temp & InterlaceMode)
7370 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7371 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7372 RefreshRateTableIndex, &i, pVBInfo);
7374 return RefreshRateTableIndex + i; /* return (0x01 | (temp1<<1)); */
7377 static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
7378 struct xgi_hw_device_info *HwDeviceExtension,
7379 struct vb_device_info *pVBInfo)
7381 unsigned short RefreshRateTableIndex;
7382 /* unsigned short temp ; */
7384 /* pVBInfo->SelectCRT2Rate = 0; */
7386 pVBInfo->SetFlag |= ProgrammingCRT2;
7387 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7388 ModeIdIndex, pVBInfo);
7389 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7390 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7391 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7392 HwDeviceExtension, pVBInfo);
7393 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7394 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7397 unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
7398 struct xgi_hw_device_info *HwDeviceExtension,
7399 struct vb_device_info *pVBInfo)
7401 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
7403 tempbx = pVBInfo->VBInfo;
7404 pVBInfo->SetFlag |= ProgrammingCRT2;
7405 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7406 pVBInfo->SelectCRT2Rate = 4;
7407 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7408 ModeIdIndex, pVBInfo);
7409 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7410 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7411 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7412 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7413 RefreshRateTableIndex, pVBInfo);
7414 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7415 RefreshRateTableIndex, pVBInfo);
7416 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7417 RefreshRateTableIndex, pVBInfo);
7418 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7419 HwDeviceExtension, pVBInfo);
7420 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7421 RefreshRateTableIndex, pVBInfo);
7422 XGI_SetTap4Regs(pVBInfo);
7423 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7424 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7425 HwDeviceExtension, pVBInfo);
7426 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7427 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7428 XGI_AutoThreshold(pVBInfo);
7432 void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7434 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7435 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7438 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
7440 unsigned char CR17, CR63, SR31;
7441 unsigned short temp;
7442 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
7445 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
7447 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
7448 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
7449 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
7450 pVBInfo->P3d4, 0x53) | 0x02));
7452 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7453 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7454 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
7456 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7457 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
7459 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
7460 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
7462 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
7463 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
7465 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
7466 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
7467 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
7468 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
7470 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
7472 for (i = 0; i < 8; i++)
7473 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
7475 for (i = 8; i < 11; i++)
7476 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
7479 for (i = 11; i < 13; i++)
7480 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
7483 for (i = 13; i < 16; i++)
7484 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
7487 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
7490 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
7491 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7492 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
7494 outb(0x00, pVBInfo->P3c8);
7496 for (i = 0; i < 256; i++) {
7497 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
7498 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
7499 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
7502 XGI_VBLongWait(pVBInfo);
7503 XGI_VBLongWait(pVBInfo);
7504 XGI_VBLongWait(pVBInfo);
7508 XGI_WaitDisply(pVBInfo);
7509 temp = inb(pVBInfo->P3c2);
7512 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
7514 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
7516 /* alan, avoid display something, set BLACK DAC if not restore DAC */
7517 outb(0x00, pVBInfo->P3c8);
7519 for (i = 0; i < 256; i++) {
7520 outb(0, (pVBInfo->P3c8 + 1));
7521 outb(0, (pVBInfo->P3c8 + 1));
7522 outb(0, (pVBInfo->P3c8 + 1));
7525 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
7526 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
7527 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
7529 /* [2004/05/11] Vicent */
7530 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
7531 pVBInfo->P3d4, 0x53) & 0xFD));
7532 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
7535 void XGI_EnableBridge(struct xgi_hw_device_info *HwDeviceExtension,
7536 struct vb_device_info *pVBInfo)
7538 unsigned short tempah;
7540 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7541 | VB_XGI302LV | VB_XGI301C)) {
7542 if (!(pVBInfo->SetFlag & DisableChA)) {
7543 if (pVBInfo->SetFlag & EnableChA) {
7545 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
7547 /* SetCRT2ToLCDA ) */
7548 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7550 xgifb_reg_set(pVBInfo->Part1Port,
7556 if (!(pVBInfo->SetFlag & DisableChB)) {
7557 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
7558 & (SetCRT2ToLCD | SetCRT2ToTV
7559 | SetCRT2ToRAMDAC))) {
7560 tempah = (unsigned char) xgifb_reg_get(
7561 pVBInfo->P3c4, 0x32);
7563 if (pVBInfo->VBInfo & SetInSlaveMode) {
7564 if (!(pVBInfo->VBInfo &
7568 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
7569 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
7571 tempah = (unsigned char) xgifb_reg_get(
7572 pVBInfo->Part1Port, 0x2E);
7574 if (!(tempah & 0x80))
7575 /* BVBDOENABLE = 1 */
7576 xgifb_reg_or(pVBInfo->Part1Port,
7578 /* BScreenOFF = 0 */
7579 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
7583 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
7584 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
7585 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
7586 0x20); /* shampoo 0129 */
7587 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7588 if (!XGI_DisableChISLCD(pVBInfo)) {
7589 if (XGI_EnableChISLCD(pVBInfo) ||
7591 (SetCRT2ToLCD | SetCRT2ToLCDA)))
7592 /* LVDS PLL power on */
7598 /* LVDS Driver power on */
7599 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
7605 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7608 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
7609 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7610 if (pVBInfo->VBInfo &
7611 SetCRT2ToDualEdge) {
7612 tempah = tempah & 0x40;
7613 if (pVBInfo->VBInfo &
7615 tempah = tempah ^ 0xC0;
7617 if (pVBInfo->SetFlag &
7621 if (pVBInfo->SetFlag &
7625 if (pVBInfo->SetFlag &
7629 if (pVBInfo->SetFlag &
7637 /* EnablePart4_1F */
7638 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
7640 if (!(pVBInfo->SetFlag & DisableChA)) {
7641 XGI_VBLongWait(pVBInfo);
7642 if (!(pVBInfo->SetFlag & GatingCRT)) {
7643 XGI_DisableGatingCRT(HwDeviceExtension,
7645 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7646 XGI_VBLongWait(pVBInfo);
7651 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
7654 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
7656 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
7658 if (!(tempah & 0x80))
7659 /* BVBDOENABLE = 1 */
7660 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
7662 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
7663 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7667 static void XGI_SetCRT1Group(struct xgi_hw_device_info *HwDeviceExtension,
7668 unsigned short ModeNo, unsigned short ModeIdIndex,
7669 struct vb_device_info *pVBInfo)
7671 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
7673 unsigned short XGINew_P3cc = pVBInfo->P3cc;
7675 /* XGINew_CRT1Mode = ModeNo; // SaveModeID */
7676 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
7677 /* XGI_SetBIOSData(ModeNo, ModeIdIndex); */
7678 /* XGI_ClearBankRegs(ModeNo, ModeIdIndex); */
7679 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7680 XGI_SetMiscRegs(StandTableIndex, pVBInfo);
7681 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7682 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7683 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7684 XGI_ClearExt1Regs(pVBInfo);
7686 /* if (pVBInfo->IF_DEF_ExpLink) */
7687 if (HwDeviceExtension->jChipType == XG27) {
7688 if (pVBInfo->IF_DEF_LVDS == 0)
7689 XGI_SetDefaultVCLK(pVBInfo);
7692 temp = ~ProgrammingCRT2;
7693 pVBInfo->SetFlag &= temp;
7694 pVBInfo->SelectCRT2Rate = 0;
7696 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7697 | VB_XGI302LV | VB_XGI301C)) {
7698 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
7699 | SetInSlaveMode)) {
7700 pVBInfo->SetFlag |= ProgrammingCRT2;
7704 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7705 ModeIdIndex, pVBInfo);
7706 if (RefreshRateTableIndex != 0xFFFF) {
7707 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
7708 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7709 pVBInfo, HwDeviceExtension);
7710 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
7711 RefreshRateTableIndex, pVBInfo);
7712 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7713 HwDeviceExtension, pVBInfo);
7714 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
7715 RefreshRateTableIndex, pVBInfo);
7718 if ((HwDeviceExtension->jChipType >= XG20) &&
7719 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
7720 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
7721 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7722 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
7723 b3CC = (unsigned char) inb(XGINew_P3cc);
7724 outb((b3CC |= 0x0C), XGINew_P3cc);
7725 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7727 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7728 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
7729 b3CC = (unsigned char) inb(XGINew_P3cc);
7730 outb((b3CC |= 0x0C), XGINew_P3cc);
7734 if (HwDeviceExtension->jChipType >= XG21) {
7735 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
7738 /* Enable write GPIOF */
7739 /* xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20); */
7741 /* xgifb_reg_and(pVBInfo->P3d4, 0x48, ~0x20); */
7742 /* XG21 CRT1 Timing */
7743 if (HwDeviceExtension->jChipType == XG27)
7744 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
7745 RefreshRateTableIndex, pVBInfo);
7747 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
7748 RefreshRateTableIndex, pVBInfo);
7750 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
7751 RefreshRateTableIndex);
7753 xgifb_set_lcd(HwDeviceExtension->jChipType,
7754 pVBInfo, RefreshRateTableIndex, ModeNo);
7756 if (pVBInfo->IF_DEF_LVDS == 1)
7757 xgifb_set_lvds(HwDeviceExtension->jChipType,
7758 ModeNo, ModeIdIndex, pVBInfo);
7760 /* xgifb_reg_or(pVBInfo->P3d4, 0x48, 0x20); */
7764 pVBInfo->SetFlag &= (~ProgrammingCRT2);
7765 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
7766 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
7767 RefreshRateTableIndex, pVBInfo);
7769 /* XGI_LoadCharacter(); //dif ifdef TVFont */
7771 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
7772 /* XGI_ClearBuffer(HwDeviceExtension, ModeNo, pVBInfo); */
7775 unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
7776 unsigned short ModeNo)
7778 unsigned short ModeIdIndex;
7779 /* unsigned char *pVBInfo->FBAddr =
7780 HwDeviceExtension->pjVideoMemoryAddress; */
7781 struct vb_device_info VBINF;
7782 struct vb_device_info *pVBInfo = &VBINF;
7783 pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase;
7784 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
7785 pVBInfo->IF_DEF_LVDS = 0;
7786 pVBInfo->IF_DEF_LCDA = 1;
7788 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
7789 pVBInfo->IF_DEF_YPbPr = 0;
7790 pVBInfo->IF_DEF_HiVision = 0;
7791 pVBInfo->IF_DEF_CRT2Monitor = 0;
7792 pVBInfo->VBType = 0; /*set VBType default 0*/
7794 pVBInfo->IF_DEF_YPbPr = 1;
7795 pVBInfo->IF_DEF_HiVision = 1;
7796 pVBInfo->IF_DEF_CRT2Monitor = 1;
7799 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
7800 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
7801 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
7802 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
7803 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
7804 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
7805 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
7806 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
7807 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
7808 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
7809 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
7810 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
7811 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
7812 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
7813 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
7814 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
7815 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
7816 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
7818 /* for x86 Linux, XG21 LVDS */
7819 if (HwDeviceExtension->jChipType == XG21) {
7820 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
7821 pVBInfo->IF_DEF_LVDS = 1;
7823 if (HwDeviceExtension->jChipType == XG27) {
7824 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
7825 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
7826 pVBInfo->IF_DEF_LVDS = 1;
7830 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
7831 XGI_GetVBType(pVBInfo);
7833 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
7834 if (ModeNo & 0x80) {
7835 ModeNo = ModeNo & 0x7F;
7836 /* XGINew_flag_clearbuffer = 0; */
7839 XGINew_flag_clearbuffer = 1;
7842 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
7844 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
7845 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
7847 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7849 XGI_GetVGAType(HwDeviceExtension, pVBInfo);
7851 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7852 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
7853 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
7854 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
7855 XGI_DisableBridge(HwDeviceExtension, pVBInfo);
7857 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
7858 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7859 ModeIdIndex, pVBInfo);
7861 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7862 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7863 HwDeviceExtension, pVBInfo);
7866 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
7867 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7868 ModeIdIndex, pVBInfo);
7869 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7870 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7877 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
7878 switch (HwDeviceExtension->ujVBChipID) {
7880 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7881 pVBInfo); /*add for CRT2 */
7885 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7886 pVBInfo); /*add for CRT2 */
7894 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
7895 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
7896 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
7897 XGI_EnableBridge(HwDeviceExtension, pVBInfo);
7900 if (pVBInfo->IF_DEF_LVDS == 1)
7901 if (!XGI_XG21CheckLVDSMode(ModeNo,
7906 if (ModeNo <= 0x13) {
7907 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
7908 St_ModeFlag & ModeInfoFlag;
7910 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
7911 Ext_ModeFlag & ModeInfoFlag;
7914 pVBInfo->SetFlag = 0;
7915 pVBInfo->VBInfo = DisableCRT2Display;
7917 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
7919 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex,
7922 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7924 if (HwDeviceExtension->jChipType == XG21)
7925 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0x80, 0x80);
7930 if (ModeNo <= 0x13) {
7931 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7933 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7935 pVBInfo->ModeType = modeflag&ModeInfoFlag;
7936 pVBInfo->SetFlag = 0x00;
7937 pVBInfo->VBInfo = DisableCRT2Display;
7938 temp = XGINew_CheckMemorySize(HwDeviceExtension,
7946 XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
7947 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo);
7948 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7951 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
7953 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7954 XGI_LockCRT2(HwDeviceExtension, pVBInfo);