staging: brcm80211: remove brcms_b_dotxstatus wrapper function
[zen-stable.git] / drivers / staging / xgifb / vb_setmode.c
blob8f3a8127d09de03aa8e668ec5ead3058b816cf4b
2 #include <linux/io.h>
3 #include <linux/delay.h>
4 #include <linux/types.h>
5 #include "XGIfb.h"
8 #include "vb_def.h"
9 #include "vgatypes.h"
10 #include "vb_struct.h"
11 #include "vb_init.h"
12 #include "vb_util.h"
13 #include "vb_table.h"
14 #include "vb_setmode.h"
17 #define IndexMask 0xff
19 static 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 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 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 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;
81 pVBInfo->ModeResInfo
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;
89 pVBInfo->LCDInfo = 0;
90 pVBInfo->VBInfo = 0;
91 pVBInfo->TVInfo = 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;
148 else
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) {
163 pVBInfo->MCLKData
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)
190 unsigned char index;
192 if (ModeNo <= 0x13)
193 index = pVBInfo->SModeIDTable[ModeIdIndex].St_StTableIndex;
194 else {
195 if (pVBInfo->ModeType <= 0x02)
196 index = 0x1B; /* 02 -> ModeEGA */
197 else
198 index = 0x0F;
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;
211 if (ModeNo <= 0x13)
212 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
213 else
214 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
216 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
217 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
219 i = SetCRT2ToLCDA;
220 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
221 tempah |= 0x01;
222 } else {
223 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
224 if (pVBInfo->VBInfo & SetInSlaveMode)
225 tempah |= 0x01;
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 |
248 VB_XGI302B |
249 VB_XGI301LV |
250 VB_XGI302LV |
251 VB_XGI301C)) {
252 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
253 Miscdata |= 0x0C;
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;
266 unsigned short i;
268 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
269 CRTCdata &= 0x7f;
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;
297 if (ModeNo <= 0x13)
298 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
299 else
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 */
305 if (i == 0x13) {
306 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
307 ARdata = 0;
308 } else {
309 if (pVBInfo->VBInfo & (SetCRT2ToTV
310 | SetCRT2ToLCD)) {
311 if (pVBInfo->VBInfo &
312 SetInSlaveMode)
313 ARdata = 0;
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;
335 unsigned short i;
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)
352 unsigned short i;
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);
370 return 0;
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;
380 if (ModeNo <= 0x13)
381 /* si+St_ModeFlag */
382 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
383 else
384 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
386 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
387 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
388 tempax = 0;
390 if (pVBInfo->IF_DEF_LVDS == 0) {
391 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
392 tempax |= SupportRAMDAC2;
394 if (pVBInfo->VBType & VB_XGI301C)
395 tempax |= SupportCRT2in301C;
398 /* 301b */
399 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
400 tempax |= SupportLCD;
402 if (pVBInfo->LCDResInfo != Panel1280x1024) {
403 if (pVBInfo->LCDResInfo != Panel1280x960) {
404 if (pVBInfo->LCDInfo &
405 LCDNonExpanding) {
406 if (resinfo >= 9) {
407 tempax = 0;
408 return 0;
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) {
420 if (resinfo == 4)
421 return 0;
423 if (resinfo == 3)
424 return 0;
426 if (resinfo > 7)
427 return 0;
429 } else {
430 tempax |= SupportHiVisionTV;
431 if (pVBInfo->VBInfo & SetInSlaveMode) {
432 if (resinfo == 4)
433 return 0;
435 if (resinfo == 3) {
436 if (pVBInfo->SetFlag
437 & TVSimuMode)
438 return 0;
441 if (resinfo > 7)
442 return 0;
445 } else {
446 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
447 SetCRT2ToSVIDEO |
448 SetCRT2ToSCART |
449 SetCRT2ToYPbPr |
450 SetCRT2ToHiVisionTV)) {
451 tempax |= SupportTV;
453 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
454 | VB_XGI301LV | VB_XGI302LV
455 | VB_XGI301C)) {
456 tempax |= SupportTV1024;
459 if (!(pVBInfo->VBInfo & SetPALTV)) {
460 if (modeflag & NoSupportSimuTV) {
461 if (pVBInfo->VBInfo &
462 SetInSlaveMode) {
463 if (!(pVBInfo->VBInfo &
464 SetNotSimuMode)) {
465 return 0;
472 } else { /* for LVDS */
473 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
474 tempax |= SupportLCD;
476 if (resinfo > 0x08)
477 return 0; /* 1024x768 */
479 if (pVBInfo->LCDResInfo < Panel1024x768) {
480 if (resinfo > 0x07)
481 return 0; /* 800x600 */
483 if (resinfo == 0x04)
484 return 0; /* 512x384 */
489 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
490 tempbx; (*i)--) {
491 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
492 Ext_InfoFlag;
493 if (infoflag & tempax)
494 return 1;
496 if ((*i) == 0)
497 break;
500 for ((*i) = 0;; (*i)++) {
501 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
502 Ext_InfoFlag;
503 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
504 != tempbx) {
505 return 0;
508 if (infoflag & tempax)
509 return 1;
511 return 1;
514 static void XGI_SetSync(unsigned short RefreshRateTableIndex,
515 struct vb_device_info *pVBInfo)
517 unsigned short sync, temp;
519 /* di+0x00 */
520 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
521 sync &= 0xC0;
522 temp = 0x2F;
523 temp |= sync;
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;
531 unsigned short i, j;
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); */
537 /* unlock cr0-7 */
538 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
539 data &= 0x7F;
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);
556 j &= 0x1F;
557 data = pVBInfo->TimingH[0].data[7];
558 data &= 0xE0;
559 data |= j;
560 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
562 if (HwDeviceExtension->jChipType >= XG20) {
563 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
564 data = data - 1;
565 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
566 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
567 data1 = data;
568 data1 &= 0xE0;
569 data &= 0x1F;
570 if (data == 0) {
571 pushax = data;
572 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
573 0x0c);
574 data &= 0xFB;
575 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
576 data = pushax;
578 data = data - 1;
579 data |= data1;
580 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
581 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
582 data = data >> 5;
583 data = data + 3;
584 if (data > 7)
585 data = data - 7;
586 data = data << 5;
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)
595 unsigned char data;
596 unsigned short i, j;
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);
618 j &= 0xC0;
619 data = pVBInfo->TimingV[0].data[6];
620 data &= 0x3F;
621 data |= j;
622 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
624 data = pVBInfo->TimingV[0].data[6];
625 data &= 0x80;
626 data = data >> 2;
628 if (ModeNo <= 0x13)
629 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
630 else
631 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
633 i &= DoubleScanMode;
634 if (i)
635 data |= 0x80;
637 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
638 j &= 0x5F;
639 data |= j;
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;
649 unsigned short i;
651 /* Get index */
652 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
653 index = index & IndexMask;
655 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
656 data &= 0x7F;
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);
690 /* CR04 HRS */
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] */
697 Tempcx = Tempax;
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 */
723 Temp1 = Tempcx << 1;
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] */
729 /* CR16 VRE */
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] */
744 Tempax &= 0x7F;
745 /* SR3F D[7:2]->VRE D[1:0]->VRS */
746 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
747 } else {
748 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
749 /* Tempax: CR4 HRS */
750 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
751 Tempcx = Tempax; /* Tempcx: HRS */
752 /* SR2E[7:0]->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 */
776 Temp2 &= 0xFF;
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);
785 /* CR10 VRS */
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] */
790 /* CR7[2][7] VRE */
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] */
801 Tempax &= 0x80;
802 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
803 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
804 /* Tempax: SRA */
805 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
806 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
807 Temp2 = Tempax;
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] */
814 /* Tempbx: SRA */
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 */
826 Temp2 &= 0xFF;
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] */
833 Tempax &= 0x7F;
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);
848 /* CR04 HRS */
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] */
855 Tempcx = Tempax;
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] */
873 Tempax >>= 2;
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] */
879 /* CR11 VRE */
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);
895 } else {
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] */
900 /* SR2E[7:0]->HRS */
901 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
903 /* SR0B */
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);
934 /* CR10 VRS */
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] */
949 /* Tempax: SR0A */
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] */
957 /* Tempbx: SR0A */
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);
1011 } else {
1012 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1013 if (Temp & 0x01) {
1014 /* 18 bits FP */
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);
1027 if (b3CC & 0x40)
1028 /* Hsync polarity */
1029 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
1030 if (b3CC & 0x80)
1031 /* Vsync polarity */
1032 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1033 } else {
1034 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1035 if (Data & 0x4000)
1036 /* Hsync polarity */
1037 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
1038 if (Data & 0x8000)
1039 /* Vsync polarity */
1040 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1044 /* --------------------------------------------------------------------- */
1045 /* Function : XGI_UpdateXG21CRTC */
1046 /* Input : */
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)
1054 int i, index = -1;
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)
1060 index = i;
1062 } else {
1063 if (ModeNo == 0x2E &&
1064 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1065 RES640x480x60))
1066 index = 12;
1067 else if (ModeNo == 0x2E &&
1068 (pVBInfo->RefIndex[RefreshRateTableIndex].
1069 Ext_CRT1CRTC == RES640x480x72))
1070 index = 13;
1071 else if (ModeNo == 0x2F)
1072 index = 14;
1073 else if (ModeNo == 0x50)
1074 index = 15;
1075 else if (ModeNo == 0x59)
1076 index = 16;
1079 if (index != -1) {
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;
1098 unsigned char data;
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;
1106 } else {
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;
1128 tempcx = 8;
1130 /* if (!(modeflag & Charx8Dot)) */
1131 /* tempcx = 9; */
1133 tempax /= tempcx;
1134 tempax -= 1;
1135 tempbx -= 1;
1136 tempcx = tempax;
1137 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1138 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1139 data &= 0x7F;
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));
1145 tempax = 0;
1146 tempbx = tempbx >> 8;
1148 if (tempbx & 0x01)
1149 tempax |= 0x02;
1151 if (tempbx & 0x02)
1152 tempax |= 0x40;
1154 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
1155 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
1156 data &= 0xFF;
1157 tempax = 0;
1159 if (tempbx & 0x04)
1160 tempax |= 0x02;
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;
1171 if (ModeNo <= 0x13)
1172 /* si+St_ResInfo */
1173 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1174 else
1175 /* si+Ext_ResInfo */
1176 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1177 return resindex;
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;
1188 /* GetOffset */
1189 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1190 temp = temp >> 8;
1191 temp = pVBInfo->ScreenOffset[temp];
1193 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1194 temp2 &= InterlaceMode;
1196 if (temp2)
1197 temp = temp << 1;
1199 temp2 = pVBInfo->ModeType - ModeEGA;
1201 switch (temp2) {
1202 case 0:
1203 temp2 = 1;
1204 break;
1205 case 1:
1206 temp2 = 2;
1207 break;
1208 case 2:
1209 temp2 = 4;
1210 break;
1211 case 3:
1212 temp2 = 4;
1213 break;
1214 case 4:
1215 temp2 = 6;
1216 break;
1217 case 5:
1218 temp2 = 8;
1219 break;
1220 default:
1221 break;
1224 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1225 temp = temp * temp2 + temp2 / 2;
1226 else
1227 temp *= temp2;
1229 /* SetOffset */
1230 DisplayUnit = temp;
1231 temp2 = temp;
1232 temp = temp >> 8; /* ah */
1233 temp &= 0x0F;
1234 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
1235 i &= 0xF0;
1236 i |= temp;
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;
1246 if (temp2)
1247 DisplayUnit >>= 1;
1249 DisplayUnit = DisplayUnit << 5;
1250 ah = (DisplayUnit & 0xff00) >> 8;
1251 al = DisplayUnit & 0x00ff;
1252 if (al == 0)
1253 ah += 1;
1254 else
1255 ah += 2;
1257 if (HwDeviceExtension->jChipType >= XG20)
1258 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1259 ah -= 1;
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,
1271 VCLK65 + 2,
1272 VCLK65 + 2,
1273 VCLK65 + 2 };
1274 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1275 VCLK108_2 + 5,
1276 VCLK108_2 + 5,
1277 VCLK108_2 + 5 };
1278 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
1279 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1280 VCLK65 + 2,
1281 VCLK65 + 2,
1282 VCLK65 + 2 };
1283 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1284 VCLK65 + 2,
1285 VCLK65 + 2,
1286 VCLK65 + 2 };
1288 unsigned short CRT2Index, VCLKIndex;
1289 unsigned short modeflag, resinfo;
1291 if (ModeNo <= 0x13) {
1292 /* si+St_ResInfo */
1293 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1294 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1295 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1296 } else {
1297 /* si+Ext_ResInfo */
1298 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1299 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1300 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1301 Ext_CRT2CRTC;
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];
1309 else
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;
1316 VCLKIndex += 25;
1317 } else {
1318 VCLKIndex = HiTVVCLK;
1319 VCLKIndex += 25;
1322 if (pVBInfo->SetFlag & TVSimuMode) {
1323 if (modeflag & Charx8Dot) {
1324 VCLKIndex =
1325 HiTVSimuVCLK;
1326 VCLKIndex += 25;
1327 } else {
1328 VCLKIndex =
1329 HiTVTextVCLK;
1330 VCLKIndex += 25;
1334 /* 301lv */
1335 if (pVBInfo->VBType & VB_XGI301LV) {
1336 if (!(pVBInfo->VBExtInfo ==
1337 VB_YPbPr1080i)) {
1338 VCLKIndex =
1339 YPbPr750pVCLK;
1340 if (!(pVBInfo->VBExtInfo
1342 VB_YPbPr750p)) {
1343 VCLKIndex =
1344 YPbPr525pVCLK;
1345 if (!(pVBInfo->VBExtInfo
1346 == VB_YPbPr525p)) {
1347 VCLKIndex
1348 = YPbPr525iVCLK_2;
1349 if (!(pVBInfo->SetFlag
1350 & RPLLDIV2XO))
1351 VCLKIndex
1352 = YPbPr525iVCLK;
1357 } else {
1358 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1359 if (pVBInfo->SetFlag &
1360 RPLLDIV2XO) {
1361 VCLKIndex = TVVCLKDIV2;
1362 VCLKIndex += 25;
1363 } else {
1364 VCLKIndex = TVVCLK;
1365 VCLKIndex += 25;
1369 } else { /* for CRT2 */
1370 /* Port 3cch */
1371 VCLKIndex = (unsigned char) inb(
1372 (pVBInfo->P3ca + 0x02));
1373 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1374 if (ModeNo > 0x13) {
1375 /* di+Ext_CRTVCLK */
1376 VCLKIndex =
1377 pVBInfo->RefIndex[
1378 RefreshRateTableIndex].
1379 Ext_CRTVCLK;
1380 VCLKIndex &= IndexMask;
1384 } else { /* LVDS */
1385 if (ModeNo <= 0x13)
1386 VCLKIndex = CRT2Index;
1387 else
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];
1397 else
1398 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
1400 /* VCLKIndex = VCLKIndex&IndexMask; */
1402 return VCLKIndex;
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
1425 & SetCRT2ToLCDA)) {
1426 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1427 RefreshRateTableIndex, HwDeviceExtension,
1428 pVBInfo);
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);
1436 } else {
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 &
1449 HalfDCLK) {
1450 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
1451 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
1452 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
1453 index = data;
1454 index &= 0xE0;
1455 data &= 0x1F;
1456 data = data << 1;
1457 data += 1;
1458 data |= index;
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);
1471 data &= 0xfe;
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);
1477 data &= 0xC0;
1478 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1479 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1480 data |= 0x01;
1481 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
1482 } else {
1483 if (HwDeviceExtension->jChipType == XG27) {
1484 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
1485 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1486 data &= 0xC0;
1487 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
1488 } else {
1489 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
1490 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1491 data &= 0xF0;
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;
1505 short VCLK;
1507 unsigned char index;
1509 if (ModeNo <= 0x13)
1510 VCLK = 0;
1511 else {
1512 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1513 index &= IndexMask;
1514 VCLK = pVBInfo->VCLKData[index].CLOCK;
1517 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
1518 data &= 0xf3;
1519 if (VCLK >= 200)
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);
1529 data &= 0xE7;
1530 if (VCLK < 200)
1531 data |= 0x10;
1532 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
1535 /* Jong for Adavantech LCD ripple issue
1536 if ((VCLK >= 0) && (VCLK < 135))
1537 data2 = 0x03;
1538 else if ((VCLK >= 135) && (VCLK < 160))
1539 data2 = 0x02;
1540 else if ((VCLK >= 160) && (VCLK < 260))
1541 data2 = 0x01;
1542 else if (VCLK > 260)
1543 data2 = 0x00;
1545 data2 = 0x00;
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,
1559 xres;
1561 if (ModeNo > 0x13) {
1562 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1563 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1564 Ext_InfoFlag;
1565 } else
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);
1572 if (ModeNo > 0x13)
1573 data = infoflag;
1574 else
1575 data = 0;
1577 data2 = 0;
1579 if (ModeNo > 0x13) {
1580 if (pVBInfo->ModeType > 0x02) {
1581 data2 |= 0x02;
1582 data3 = pVBInfo->ModeType - ModeVGA;
1583 data3 = data3 << 2;
1584 data2 |= data3;
1588 data &= InterlaceMode;
1590 if (data)
1591 data2 |= 0x20;
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);
1596 if (ModeNo <= 0x13)
1597 xres = pVBInfo->StResInfo[resindex].HTotal;
1598 else
1599 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
1601 data = 0x0000;
1602 if (infoflag & InterlaceMode) {
1603 if (xres == 1024)
1604 data = 0x0035;
1605 else if (xres == 1280)
1606 data = 0x0048;
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);
1617 data2 = 0;
1619 if (modeflag & LineCompareOff)
1620 data2 |= 0x08;
1622 if (ModeNo > 0x13) {
1623 if (pVBInfo->ModeType == ModeEGA)
1624 data2 |= 0x40;
1627 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
1628 data = 0x60;
1629 if (pVBInfo->ModeType != ModeText) {
1630 data = data ^ 0x60;
1631 if (pVBInfo->ModeType != ModeEGA)
1632 data = data ^ 0xA0;
1634 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
1636 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1637 pVBInfo);
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) {
1647 if (data & 0x40)
1648 data = 0x2c;
1649 else
1650 data = 0x6c;
1651 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1652 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
1653 } else if (HwDeviceExtension->jChipType >= XG20) {
1654 if (data & 0x40)
1655 data = 0x33;
1656 else
1657 data = 0x73;
1658 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1659 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
1660 } else {
1661 if (data & 0x40)
1662 data = 0x2c;
1663 else
1664 data = 0x6c;
1665 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1670 static void XGI_WriteDAC(unsigned short dl,
1671 unsigned short ah,
1672 unsigned short al,
1673 unsigned short dh,
1674 struct vb_device_info *pVBInfo)
1676 unsigned short temp, bh, bl;
1678 bh = ah;
1679 bl = al;
1681 if (dl != 0) {
1682 temp = bh;
1683 bh = dh;
1684 dh = temp;
1685 if (dl == 1) {
1686 temp = bl;
1687 bl = dh;
1688 dh = temp;
1689 } else {
1690 temp = bl;
1691 bl = bh;
1692 bh = temp;
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,
1704 ah, dh, *table = NULL;
1706 if (ModeNo <= 0x13)
1707 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1708 else
1709 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1711 data &= DACInfoFlag;
1712 time = 64;
1714 if (data == 0x00)
1715 table = XGINew_MDA_DAC;
1716 else if (data == 0x08)
1717 table = XGINew_CGA_DAC;
1718 else if (data == 0x10)
1719 table = XGINew_EGA_DAC;
1720 else if (data == 0x18) {
1721 time = 256;
1722 table = XGINew_VGA_DAC;
1725 if (time == 256)
1726 j = 16;
1727 else
1728 j = time;
1730 outb(0xFF, pVBInfo->P3c6);
1731 outb(0x00, pVBInfo->P3c8);
1733 for (i = 0; i < j; i++) {
1734 data = table[i];
1736 for (k = 0; k < 3; k++) {
1737 data2 = 0;
1739 if (data & 0x01)
1740 data2 = 0x2A;
1742 if (data & 0x02)
1743 data2 += 0x15;
1745 outb(data2, pVBInfo->P3c9);
1746 data = data >> 2;
1750 if (time == 256) {
1751 for (i = 16; i < 32; i++) {
1752 data = table[i];
1754 for (k = 0; k < 3; k++)
1755 outb(data, pVBInfo->P3c9);
1758 si = 32;
1760 for (m = 0; m < 9; m++) {
1761 di = si;
1762 bx = si + 0x04;
1763 dl = 0;
1765 for (n = 0; n < 3; n++) {
1766 for (o = 0; o < 5; o++) {
1767 dh = table[si];
1768 ah = table[di];
1769 al = table[bx];
1770 si++;
1771 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1774 si -= 2;
1776 for (o = 0; o < 3; o++) {
1777 dh = table[bx];
1778 ah = table[di];
1779 al = table[si];
1780 si--;
1781 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1784 dl++;
1787 si += 5;
1792 static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1793 unsigned short ModeIdIndex,
1794 struct vb_device_info *pVBInfo)
1796 unsigned short resindex, xres, yres, modeflag;
1798 if (ModeNo <= 0x13)
1799 /* si+St_ResInfo */
1800 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1801 else
1802 /* si+Ext_ResInfo */
1803 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1805 /* if (ModeNo > 0x13) */
1806 /* modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; */
1807 /* else */
1808 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; */
1810 if (ModeNo <= 0x13)
1811 /* si+St_ResInfo */
1812 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1813 else
1814 /* si+Ext_ResInfo */
1815 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1817 /* resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); */
1819 if (ModeNo <= 0x13) {
1820 xres = pVBInfo->StResInfo[resindex].HTotal;
1821 yres = pVBInfo->StResInfo[resindex].VTotal;
1822 } else {
1823 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1824 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1826 if (ModeNo > 0x13) {
1827 if (modeflag & HalfDCLK)
1828 xres = xres << 1;
1830 if (modeflag & DoubleScanMode)
1831 yres = yres << 1;
1833 /* if (modeflag & Charx8Dot) */
1834 /* { */
1836 if (xres == 720)
1837 xres = 640;
1839 /* } */
1840 pVBInfo->VGAHDE = xres;
1841 pVBInfo->HDE = xres;
1842 pVBInfo->VGAVDE = yres;
1843 pVBInfo->VDE = yres;
1846 static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1847 unsigned short ModeIdIndex,
1848 unsigned short RefreshRateTableIndex,
1849 struct vb_device_info *pVBInfo)
1851 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1853 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1855 tempbx = BX;
1857 if (ModeNo <= 0x13) {
1858 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1859 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1860 } else {
1861 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1862 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1865 tempal = tempal & 0x0f;
1867 if (tempbx <= 1) { /* ExpLink */
1868 if (ModeNo <= 0x13) {
1869 /* find no Ext_CRT2CRTC2 */
1870 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1871 } else {
1872 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1873 Ext_CRT2CRTC;
1876 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1877 if (ModeNo <= 0x13)
1878 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1879 St_CRT2CRTC2;
1880 else
1881 tempal = pVBInfo->RefIndex[
1882 RefreshRateTableIndex].
1883 Ext_CRT2CRTC2;
1886 if (tempbx & 0x01)
1887 tempal = (tempal >> 4);
1889 tempal = (tempal & 0x0f);
1892 tempcx = LCDLenList[tempbx]; /* mov cl,byte ptr cs:LCDLenList[bx] */
1894 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1895 if ((tempbx == 5) || (tempbx) == 7)
1896 tempcx = LCDDesDataLen2;
1897 else if ((tempbx == 3) || (tempbx == 8))
1898 tempcx = LVDSDesDataLen2;
1900 /* mov di, word ptr cs:LCDDataList[bx] */
1901 /* tempdi = pVideoMemory[LCDDataList + tempbx * 2] |
1902 (pVideoMemory[LCDDataList + tempbx * 2 + 1] << 8); */
1904 switch (tempbx) {
1905 case 0:
1906 case 1:
1907 tempdi = xgifb_epllcd_crt1;
1908 break;
1909 case 2:
1910 tempdi = XGI_EPLLCDDataPtr;
1911 break;
1912 case 3:
1913 tempdi = XGI_EPLLCDDesDataPtr;
1914 break;
1915 case 4:
1916 tempdi = XGI_LCDDataTable;
1917 break;
1918 case 5:
1919 tempdi = XGI_LCDDesDataTable;
1920 break;
1921 case 6:
1922 tempdi = XGI_EPLCHLCDRegPtr;
1923 break;
1924 case 7:
1925 case 8:
1926 case 9:
1927 tempdi = NULL;
1928 break;
1929 default:
1930 break;
1933 if (tempdi == NULL) /* OEMUtil */
1934 return NULL;
1936 table = tempbx;
1937 i = 0;
1939 while (tempdi[i].PANELID != 0xff) {
1940 tempdx = pVBInfo->LCDResInfo;
1941 if (tempbx & 0x0080) { /* OEMUtil */
1942 tempbx &= (~0x0080);
1943 tempdx = pVBInfo->LCDTypeInfo;
1946 if (pVBInfo->LCDInfo & EnableScalingLCD)
1947 tempdx &= (~PanelResInfo);
1949 if (tempdi[i].PANELID == tempdx) {
1950 tempbx = tempdi[i].MASK;
1951 tempdx = pVBInfo->LCDInfo;
1953 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1954 tempdx |= SetLCDStdMode;
1956 if (modeflag & HalfDCLK)
1957 tempdx |= SetLCDLowResolution;
1959 tempbx &= tempdx;
1960 if (tempbx == tempdi[i].CAP)
1961 break;
1963 i++;
1966 if (table == 0) {
1967 switch (tempdi[i].DATAPTR) {
1968 case 0:
1969 return &XGI_LVDSCRT11024x768_1_H[tempal];
1970 break;
1971 case 1:
1972 return &XGI_LVDSCRT11024x768_2_H[tempal];
1973 break;
1974 case 2:
1975 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1976 break;
1977 case 3:
1978 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1979 break;
1980 case 4:
1981 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1982 break;
1983 case 5:
1984 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1985 break;
1986 case 6:
1987 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1988 break;
1989 case 7:
1990 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1991 break;
1992 case 8:
1993 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1994 break;
1995 case 9:
1996 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1997 break;
1998 case 10:
1999 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
2000 break;
2001 default:
2002 break;
2004 } else if (table == 1) {
2005 switch (tempdi[i].DATAPTR) {
2006 case 0:
2007 return &XGI_LVDSCRT11024x768_1_V[tempal];
2008 break;
2009 case 1:
2010 return &XGI_LVDSCRT11024x768_2_V[tempal];
2011 break;
2012 case 2:
2013 return &XGI_LVDSCRT11280x1024_1_V[tempal];
2014 break;
2015 case 3:
2016 return &XGI_LVDSCRT11280x1024_2_V[tempal];
2017 break;
2018 case 4:
2019 return &XGI_LVDSCRT11400x1050_1_V[tempal];
2020 break;
2021 case 5:
2022 return &XGI_LVDSCRT11400x1050_2_V[tempal];
2023 break;
2024 case 6:
2025 return &XGI_LVDSCRT11600x1200_1_V[tempal];
2026 break;
2027 case 7:
2028 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
2029 break;
2030 case 8:
2031 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
2032 break;
2033 case 9:
2034 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
2035 break;
2036 case 10:
2037 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
2038 break;
2039 default:
2040 break;
2042 } else if (table == 2) {
2043 switch (tempdi[i].DATAPTR) {
2044 case 0:
2045 return &XGI_LVDS1024x768Data_1[tempal];
2046 break;
2047 case 1:
2048 return &XGI_LVDS1024x768Data_2[tempal];
2049 break;
2050 case 2:
2051 return &XGI_LVDS1280x1024Data_1[tempal];
2052 break;
2053 case 3:
2054 return &XGI_LVDS1280x1024Data_2[tempal];
2055 break;
2056 case 4:
2057 return &XGI_LVDS1400x1050Data_1[tempal];
2058 break;
2059 case 5:
2060 return &XGI_LVDS1400x1050Data_2[tempal];
2061 break;
2062 case 6:
2063 return &XGI_LVDS1600x1200Data_1[tempal];
2064 break;
2065 case 7:
2066 return &XGI_LVDSNoScalingData[tempal];
2067 break;
2068 case 8:
2069 return &XGI_LVDS1024x768Data_1x75[tempal];
2070 break;
2071 case 9:
2072 return &XGI_LVDS1024x768Data_2x75[tempal];
2073 break;
2074 case 10:
2075 return &XGI_LVDS1280x1024Data_1x75[tempal];
2076 break;
2077 case 11:
2078 return &XGI_LVDS1280x1024Data_2x75[tempal];
2079 break;
2080 case 12:
2081 return &XGI_LVDSNoScalingDatax75[tempal];
2082 break;
2083 default:
2084 break;
2086 } else if (table == 3) {
2087 switch (tempdi[i].DATAPTR) {
2088 case 0:
2089 return &XGI_LVDS1024x768Des_1[tempal];
2090 break;
2091 case 1:
2092 return &XGI_LVDS1024x768Des_3[tempal];
2093 break;
2094 case 2:
2095 return &XGI_LVDS1024x768Des_2[tempal];
2096 break;
2097 case 3:
2098 return &XGI_LVDS1280x1024Des_1[tempal];
2099 break;
2100 case 4:
2101 return &XGI_LVDS1280x1024Des_2[tempal];
2102 break;
2103 case 5:
2104 return &XGI_LVDS1400x1050Des_1[tempal];
2105 break;
2106 case 6:
2107 return &XGI_LVDS1400x1050Des_2[tempal];
2108 break;
2109 case 7:
2110 return &XGI_LVDS1600x1200Des_1[tempal];
2111 break;
2112 case 8:
2113 return &XGI_LVDSNoScalingDesData[tempal];
2114 break;
2115 case 9:
2116 return &XGI_LVDS1024x768Des_1x75[tempal];
2117 break;
2118 case 10:
2119 return &XGI_LVDS1024x768Des_3x75[tempal];
2120 break;
2121 case 11:
2122 return &XGI_LVDS1024x768Des_2x75[tempal];
2123 break;
2124 case 12:
2125 return &XGI_LVDS1280x1024Des_1x75[tempal];
2126 break;
2127 case 13:
2128 return &XGI_LVDS1280x1024Des_2x75[tempal];
2129 break;
2130 case 14:
2131 return &XGI_LVDSNoScalingDesDatax75[tempal];
2132 break;
2133 default:
2134 break;
2136 } else if (table == 4) {
2137 switch (tempdi[i].DATAPTR) {
2138 case 0:
2139 return &XGI_ExtLCD1024x768Data[tempal];
2140 break;
2141 case 1:
2142 return &XGI_StLCD1024x768Data[tempal];
2143 break;
2144 case 2:
2145 return &XGI_CetLCD1024x768Data[tempal];
2146 break;
2147 case 3:
2148 return &XGI_ExtLCD1280x1024Data[tempal];
2149 break;
2150 case 4:
2151 return &XGI_StLCD1280x1024Data[tempal];
2152 break;
2153 case 5:
2154 return &XGI_CetLCD1280x1024Data[tempal];
2155 break;
2156 case 6:
2157 case 7:
2158 return &xgifb_lcd_1400x1050[tempal];
2159 break;
2160 case 8:
2161 return &XGI_CetLCD1400x1050Data[tempal];
2162 break;
2163 case 9:
2164 return &XGI_ExtLCD1600x1200Data[tempal];
2165 break;
2166 case 10:
2167 return &XGI_StLCD1600x1200Data[tempal];
2168 break;
2169 case 11:
2170 return &XGI_NoScalingData[tempal];
2171 break;
2172 case 12:
2173 return &XGI_ExtLCD1024x768x75Data[tempal];
2174 break;
2175 case 13:
2176 return &XGI_ExtLCD1024x768x75Data[tempal];
2177 break;
2178 case 14:
2179 return &XGI_CetLCD1024x768x75Data[tempal];
2180 break;
2181 case 15:
2182 case 16:
2183 return &xgifb_lcd_1280x1024x75[tempal];
2184 break;
2185 case 17:
2186 return &XGI_CetLCD1280x1024x75Data[tempal];
2187 break;
2188 case 18:
2189 return &XGI_NoScalingDatax75[tempal];
2190 break;
2191 default:
2192 break;
2194 } else if (table == 5) {
2195 switch (tempdi[i].DATAPTR) {
2196 case 0:
2197 return &XGI_ExtLCDDes1024x768Data[tempal];
2198 break;
2199 case 1:
2200 return &XGI_StLCDDes1024x768Data[tempal];
2201 break;
2202 case 2:
2203 return &XGI_CetLCDDes1024x768Data[tempal];
2204 break;
2205 case 3:
2206 if ((pVBInfo->VBType & VB_XGI301LV) ||
2207 (pVBInfo->VBType & VB_XGI302LV))
2208 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
2209 else
2210 return &XGI_ExtLCDDes1280x1024Data[tempal];
2211 break;
2212 case 4:
2213 if ((pVBInfo->VBType & VB_XGI301LV) ||
2214 (pVBInfo->VBType & VB_XGI302LV))
2215 return &XGI_StLCDDLDes1280x1024Data[tempal];
2216 else
2217 return &XGI_StLCDDes1280x1024Data[tempal];
2218 break;
2219 case 5:
2220 if ((pVBInfo->VBType & VB_XGI301LV) ||
2221 (pVBInfo->VBType & VB_XGI302LV))
2222 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2223 else
2224 return &XGI_CetLCDDes1280x1024Data[tempal];
2225 break;
2226 case 6:
2227 case 7:
2228 if ((pVBInfo->VBType & VB_XGI301LV) ||
2229 (pVBInfo->VBType & VB_XGI302LV))
2230 return &xgifb_lcddldes_1400x1050[tempal];
2231 else
2232 return &xgifb_lcddes_1400x1050[tempal];
2233 break;
2234 case 8:
2235 return &XGI_CetLCDDes1400x1050Data[tempal];
2236 break;
2237 case 9:
2238 return &XGI_CetLCDDes1400x1050Data2[tempal];
2239 break;
2240 case 10:
2241 if ((pVBInfo->VBType & VB_XGI301LV) ||
2242 (pVBInfo->VBType & VB_XGI302LV))
2243 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2244 else
2245 return &XGI_ExtLCDDes1600x1200Data[tempal];
2246 break;
2247 case 11:
2248 if ((pVBInfo->VBType & VB_XGI301LV) ||
2249 (pVBInfo->VBType & VB_XGI302LV))
2250 return &XGI_StLCDDLDes1600x1200Data[tempal];
2251 else
2252 return &XGI_StLCDDes1600x1200Data[tempal];
2253 break;
2254 case 12:
2255 return &XGI_NoScalingDesData[tempal];
2256 break;
2257 case 13:
2258 case 14:
2259 return &xgifb_lcddes_1024x768x75[tempal];
2260 break;
2261 case 15:
2262 return &XGI_CetLCDDes1024x768x75Data[tempal];
2263 break;
2264 case 16:
2265 case 17:
2266 if ((pVBInfo->VBType & VB_XGI301LV) ||
2267 (pVBInfo->VBType & VB_XGI302LV))
2268 return &xgifb_lcddldes_1280x1024x75[tempal];
2269 else
2270 return &xgifb_lcddes_1280x1024x75[tempal];
2271 break;
2272 case 18:
2273 if ((pVBInfo->VBType & VB_XGI301LV) ||
2274 (pVBInfo->VBType & VB_XGI302LV))
2275 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2276 else
2277 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2278 break;
2279 case 19:
2280 return &XGI_NoScalingDesDatax75[tempal];
2281 break;
2282 default:
2283 break;
2285 } else if (table == 6) {
2286 switch (tempdi[i].DATAPTR) {
2287 case 0:
2288 return &XGI_CH7017LV1024x768[tempal];
2289 break;
2290 case 1:
2291 return &XGI_CH7017LV1400x1050[tempal];
2292 break;
2293 default:
2294 break;
2297 return NULL;
2300 static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2301 unsigned short ModeIdIndex,
2302 unsigned short RefreshRateTableIndex,
2303 struct vb_device_info *pVBInfo)
2305 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2306 struct XGI330_TVDataTablStruct *tempdi = NULL;
2308 tempbx = BX;
2310 if (ModeNo <= 0x13) {
2311 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2312 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2313 } else {
2314 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2315 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2318 tempal = tempal & 0x3f;
2319 table = tempbx;
2321 switch (tempbx) {
2322 case 0:
2323 tempdi = NULL; /*EPLCHTVCRT1Ptr_H;*/
2324 break;
2325 case 1:
2326 tempdi = NULL; /*EPLCHTVCRT1Ptr_V;*/
2327 break;
2328 case 2:
2329 case 6:
2330 tempdi = xgifb_chrontel_tv;
2331 break;
2332 case 3:
2333 tempdi = NULL;
2334 break;
2335 case 4:
2336 tempdi = XGI_TVDataTable;
2337 break;
2338 case 5:
2339 tempdi = NULL;
2340 break;
2341 default:
2342 break;
2345 if (tempdi == NULL) /* OEMUtil */
2346 return NULL;
2348 tempdx = pVBInfo->TVInfo;
2350 if (pVBInfo->VBInfo & SetInSlaveMode)
2351 tempdx = tempdx | SetTVLockMode;
2353 if (modeflag & HalfDCLK)
2354 tempdx = tempdx | SetTVLowResolution;
2356 i = 0;
2358 while (tempdi[i].MASK != 0xffff) {
2359 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2360 break;
2361 i++;
2364 /* 07/05/22 */
2365 if (table == 0x00) {
2366 } else if (table == 0x01) {
2367 } else if (table == 0x04) {
2368 switch (tempdi[i].DATAPTR) {
2369 case 0:
2370 return &XGI_ExtPALData[tempal];
2371 break;
2372 case 1:
2373 return &XGI_ExtNTSCData[tempal];
2374 break;
2375 case 2:
2376 return &XGI_StPALData[tempal];
2377 break;
2378 case 3:
2379 return &XGI_StNTSCData[tempal];
2380 break;
2381 case 4:
2382 return &XGI_ExtHiTVData[tempal];
2383 break;
2384 case 5:
2385 return &XGI_St2HiTVData[tempal];
2386 break;
2387 case 6:
2388 return &XGI_ExtYPbPr525iData[tempal];
2389 break;
2390 case 7:
2391 return &XGI_ExtYPbPr525pData[tempal];
2392 break;
2393 case 8:
2394 return &XGI_ExtYPbPr750pData[tempal];
2395 break;
2396 case 9:
2397 return &XGI_StYPbPr525iData[tempal];
2398 break;
2399 case 10:
2400 return &XGI_StYPbPr525pData[tempal];
2401 break;
2402 case 11:
2403 return &XGI_StYPbPr750pData[tempal];
2404 break;
2405 case 12: /* avoid system hang */
2406 return &XGI_ExtNTSCData[tempal];
2407 break;
2408 case 13:
2409 return &XGI_St1HiTVData[tempal];
2410 break;
2411 default:
2412 break;
2414 } else if (table == 0x02) {
2415 switch (tempdi[i].DATAPTR) {
2416 case 0:
2417 return &XGI_CHTVUNTSCData[tempal];
2418 break;
2419 case 1:
2420 return &XGI_CHTVONTSCData[tempal];
2421 break;
2422 case 2:
2423 return &XGI_CHTVUPALData[tempal];
2424 break;
2425 case 3:
2426 return &XGI_CHTVOPALData[tempal];
2427 break;
2428 default:
2429 break;
2431 } else if (table == 0x06) {
2433 return NULL;
2436 static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
2437 unsigned short RefreshRateTableIndex,
2438 struct vb_device_info *pVBInfo)
2440 unsigned short tempbx;
2441 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
2443 tempbx = 2;
2445 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2446 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2447 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2448 pVBInfo);
2449 pVBInfo->VGAHT = LCDPtr->VGAHT;
2450 pVBInfo->VGAVT = LCDPtr->VGAVT;
2451 pVBInfo->HT = LCDPtr->LCDHT;
2452 pVBInfo->VT = LCDPtr->LCDVT;
2455 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2456 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2457 | EnableScalingLCD))) {
2458 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2459 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2460 pVBInfo->HDE = 1024;
2461 pVBInfo->VDE = 768;
2462 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2463 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2464 pVBInfo->HDE = 1280;
2465 pVBInfo->VDE = 1024;
2466 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2467 pVBInfo->HDE = 1400;
2468 pVBInfo->VDE = 1050;
2469 } else {
2470 pVBInfo->HDE = 1600;
2471 pVBInfo->VDE = 1200;
2477 static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
2478 unsigned short RefreshRateTableIndex,
2479 struct xgi_hw_device_info *HwDeviceExtension,
2480 struct vb_device_info *pVBInfo)
2482 unsigned char index;
2483 unsigned short tempbx, i;
2484 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2485 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
2487 if (ModeNo <= 0x13)
2488 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2489 else
2490 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2492 index = index & IndexMask;
2494 tempbx = 0;
2496 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2497 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2498 XGI_GetLcdPtr(tempbx, ModeNo,
2499 ModeIdIndex,
2500 RefreshRateTableIndex,
2501 pVBInfo);
2503 for (i = 0; i < 8; i++)
2504 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
2507 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2509 tempbx = 1;
2511 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2512 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2513 XGI_GetLcdPtr(
2514 tempbx,
2515 ModeNo,
2516 ModeIdIndex,
2517 RefreshRateTableIndex,
2518 pVBInfo);
2519 for (i = 0; i < 7; i++)
2520 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2523 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
2526 static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2528 unsigned char tempal, tempah, tempbl, i;
2530 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
2531 tempal = tempah & 0x0F;
2532 tempah = tempah & 0xF0;
2533 i = 0;
2534 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2536 while (tempbl != 0xFF) {
2537 if (tempbl & 0x80) { /* OEMUtil */
2538 tempal = tempah;
2539 tempbl = tempbl & ~(0x80);
2542 if (tempal == tempbl)
2543 break;
2545 i++;
2547 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2550 return i;
2553 static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2555 unsigned short tempah, tempal, tempbl, i;
2557 tempal = pVBInfo->LCDResInfo;
2558 tempah = pVBInfo->LCDTypeInfo;
2560 i = 0;
2561 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2563 while (tempbl != 0xFF) {
2564 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2565 tempal = tempah;
2566 tempbl &= ~0x80;
2569 if (tempal == tempbl)
2570 break;
2572 i++;
2573 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2576 if (tempbl == 0xFF) {
2577 pVBInfo->LCDResInfo = Panel1024x768;
2578 pVBInfo->LCDTypeInfo = 0;
2579 i = 0;
2582 return i;
2585 static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2586 unsigned short *VSyncWidth,
2587 struct vb_device_info *pVBInfo)
2589 unsigned short Index;
2591 Index = XGI_GetLCDCapPtr(pVBInfo);
2592 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2593 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2595 return;
2598 static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2599 unsigned short RefreshRateTableIndex,
2600 struct vb_device_info *pVBInfo)
2602 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2603 unsigned long temp, temp1, temp2, temp3, push3;
2604 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2605 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
2607 if (ModeNo > 0x13)
2608 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2609 else
2610 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2612 tempbx = 3;
2613 if (pVBInfo->LCDInfo & EnableScalingLCD)
2614 LCDPtr1 =
2615 (struct XGI330_LCDDataDesStruct2 *)
2616 XGI_GetLcdPtr(
2617 tempbx,
2618 ModeNo,
2619 ModeIdIndex,
2620 RefreshRateTableIndex,
2621 pVBInfo);
2622 else
2623 LCDPtr =
2624 (struct XGI330_LCDDataDesStruct *)
2625 XGI_GetLcdPtr(
2626 tempbx,
2627 ModeNo,
2628 ModeIdIndex,
2629 RefreshRateTableIndex,
2630 pVBInfo);
2632 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2633 push1 = tempbx;
2634 push2 = tempax;
2636 /* GetLCDResInfo */
2637 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2638 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2639 tempax = 1024;
2640 tempbx = 768;
2641 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2642 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2643 tempax = 1280;
2644 tempbx = 1024;
2645 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2646 tempax = 1400;
2647 tempbx = 1050;
2648 } else {
2649 tempax = 1600;
2650 tempbx = 1200;
2653 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2654 pVBInfo->HDE = tempax;
2655 pVBInfo->VDE = tempbx;
2656 pVBInfo->VGAHDE = tempax;
2657 pVBInfo->VGAVDE = tempbx;
2660 tempax = pVBInfo->HT;
2662 if (pVBInfo->LCDInfo & EnableScalingLCD)
2663 tempbx = LCDPtr1->LCDHDES;
2664 else
2665 tempbx = LCDPtr->LCDHDES;
2667 tempcx = pVBInfo->HDE;
2668 tempbx = tempbx & 0x0fff;
2669 tempcx += tempbx;
2671 if (tempcx >= tempax)
2672 tempcx -= tempax;
2674 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
2676 tempcx = tempcx >> 3;
2677 tempbx = tempbx >> 3;
2679 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2680 (unsigned short) (tempbx & 0xff));
2681 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2682 (unsigned short) (tempcx & 0xff));
2684 tempax = pVBInfo->HT;
2686 if (pVBInfo->LCDInfo & EnableScalingLCD)
2687 tempbx = LCDPtr1->LCDHRS;
2688 else
2689 tempbx = LCDPtr->LCDHRS;
2691 tempcx = push2;
2693 if (pVBInfo->LCDInfo & EnableScalingLCD)
2694 tempcx = LCDPtr1->LCDHSync;
2696 tempcx += tempbx;
2698 if (tempcx >= tempax)
2699 tempcx -= tempax;
2701 tempax = tempbx & 0x07;
2702 tempax = tempax >> 5;
2703 tempcx = tempcx >> 3;
2704 tempbx = tempbx >> 3;
2706 tempcx &= 0x1f;
2707 tempax |= tempcx;
2709 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2710 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2711 (unsigned short) (tempbx & 0xff));
2713 tempax = pVBInfo->VT;
2714 if (pVBInfo->LCDInfo & EnableScalingLCD)
2715 tempbx = LCDPtr1->LCDVDES;
2716 else
2717 tempbx = LCDPtr->LCDVDES;
2718 tempcx = pVBInfo->VDE;
2720 tempbx = tempbx & 0x0fff;
2721 tempcx += tempbx;
2722 if (tempcx >= tempax)
2723 tempcx -= tempax;
2725 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2726 (unsigned short) (tempbx & 0xff));
2727 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2728 (unsigned short) (tempcx & 0xff));
2730 tempbx = (tempbx >> 8) & 0x07;
2731 tempcx = (tempcx >> 8) & 0x07;
2733 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2734 (unsigned short) ((tempcx << 3)
2735 | tempbx));
2737 tempax = pVBInfo->VT;
2738 if (pVBInfo->LCDInfo & EnableScalingLCD)
2739 tempbx = LCDPtr1->LCDVRS;
2740 else
2741 tempbx = LCDPtr->LCDVRS;
2743 /* tempbx = tempbx >> 4; */
2744 tempcx = push1;
2746 if (pVBInfo->LCDInfo & EnableScalingLCD)
2747 tempcx = LCDPtr1->LCDVSync;
2749 tempcx += tempbx;
2750 if (tempcx >= tempax)
2751 tempcx -= tempax;
2753 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2754 (unsigned short) (tempbx & 0xff));
2755 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2756 (unsigned short) (tempcx & 0x0f));
2758 tempax = ((tempbx >> 8) & 0x07) << 3;
2760 tempbx = pVBInfo->VGAVDE;
2761 if (tempbx != pVBInfo->VDE)
2762 tempax |= 0x40;
2764 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2765 tempax |= 0x40;
2767 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2768 tempax);
2770 tempcx = pVBInfo->VGAVT;
2771 tempbx = pVBInfo->VDE;
2772 tempax = pVBInfo->VGAVDE;
2773 tempcx -= tempax;
2775 temp = tempax; /* 0430 ylshieh */
2776 temp1 = (temp << 18) / tempbx;
2778 tempdx = (unsigned short) ((temp << 18) % tempbx);
2780 if (tempdx != 0)
2781 temp1 += 1;
2783 temp2 = temp1;
2784 push3 = temp2;
2786 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2787 (unsigned short) (temp2 & 0xff));
2788 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2789 (unsigned short) ((temp2 >> 8) & 0xff));
2791 tempbx = (unsigned short) (temp2 >> 16);
2792 tempax = tempbx & 0x03;
2794 tempbx = pVBInfo->VGAVDE;
2795 if (tempbx == pVBInfo->VDE)
2796 tempax |= 0x04;
2798 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2800 if (pVBInfo->VBType & VB_XGI301C) {
2801 temp2 = push3;
2802 xgifb_reg_set(pVBInfo->Part4Port,
2803 0x3c,
2804 (unsigned short) (temp2 & 0xff));
2805 xgifb_reg_set(pVBInfo->Part4Port,
2806 0x3b,
2807 (unsigned short) ((temp2 >> 8) &
2808 0xff));
2809 tempbx = (unsigned short) (temp2 >> 16);
2810 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2811 ~0xc0,
2812 (unsigned short) ((tempbx &
2813 0xff) << 6));
2815 tempcx = pVBInfo->VGAVDE;
2816 if (tempcx == pVBInfo->VDE)
2817 xgifb_reg_and_or(pVBInfo->Part4Port,
2818 0x30, ~0x0c, 0x00);
2819 else
2820 xgifb_reg_and_or(pVBInfo->Part4Port,
2821 0x30, ~0x0c, 0x08);
2824 tempcx = pVBInfo->VGAHDE;
2825 tempbx = pVBInfo->HDE;
2827 temp1 = tempcx << 16;
2829 tempax = (unsigned short) (temp1 / tempbx);
2831 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2832 tempax = 65535;
2834 temp3 = tempax;
2835 temp1 = pVBInfo->VGAHDE << 16;
2837 temp1 /= temp3;
2838 temp3 = temp3 << 16;
2839 temp1 -= 1;
2841 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2843 tempax = (unsigned short) (temp3 & 0xff);
2844 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2846 temp1 = pVBInfo->VGAVDE << 18;
2847 temp1 = temp1 / push3;
2848 tempbx = (unsigned short) (temp1 & 0xffff);
2850 if (pVBInfo->LCDResInfo == Panel1024x768)
2851 tempbx -= 1;
2853 tempax = ((tempbx >> 8) & 0xff) << 3;
2854 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2855 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2856 (unsigned short) (tempax & 0xff));
2857 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2858 (unsigned short) (tempbx & 0xff));
2860 temp3 = temp3 >> 16;
2862 if (modeflag & HalfDCLK)
2863 temp3 = temp3 >> 1;
2865 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2866 (unsigned short) ((temp3 >> 8) & 0xff));
2867 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2868 (unsigned short) (temp3 & 0xff));
2871 /* --------------------------------------------------------------------- */
2872 /* Function : XGI_GETLCDVCLKPtr */
2873 /* Input : */
2874 /* Output : al -> VCLK Index */
2875 /* Description : */
2876 /* --------------------------------------------------------------------- */
2877 static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2878 struct vb_device_info *pVBInfo)
2880 unsigned short index;
2882 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2883 /* index = XGI_GetLCDCapPtr(pVBInfo); */
2884 index = XGI_GetLCDCapPtr1(pVBInfo);
2886 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2887 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2888 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2889 } else { /* LCDA */
2890 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2891 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2894 return;
2897 static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2898 unsigned short ModeNo, unsigned short ModeIdIndex,
2899 struct vb_device_info *pVBInfo)
2902 unsigned short index, modeflag;
2903 unsigned char tempal;
2905 if (ModeNo <= 0x13)
2906 /* si+St_ResInfo */
2907 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2908 else
2909 /* si+Ext_ResInfo */
2910 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2912 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2913 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
2914 index = XGI_GetLCDCapPtr(pVBInfo);
2915 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2917 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
2918 return tempal;
2920 /* {TV} */
2921 if (pVBInfo->VBType &
2922 (VB_XGI301B |
2923 VB_XGI302B |
2924 VB_XGI301LV |
2925 VB_XGI302LV |
2926 VB_XGI301C)) {
2927 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2928 tempal = HiTVVCLKDIV2;
2929 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2930 tempal = HiTVVCLK;
2931 if (pVBInfo->TVInfo & TVSimuMode) {
2932 tempal = HiTVSimuVCLK;
2933 if (!(modeflag & Charx8Dot))
2934 tempal = HiTVTextVCLK;
2937 return tempal;
2940 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
2941 tempal = YPbPr750pVCLK;
2942 return tempal;
2945 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
2946 tempal = YPbPr525pVCLK;
2947 return tempal;
2950 tempal = NTSC1024VCLK;
2952 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
2953 tempal = TVVCLKDIV2;
2954 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2955 tempal = TVVCLK;
2958 if (pVBInfo->VBInfo & SetCRT2ToTV)
2959 return tempal;
2961 } /* {End of VB} */
2963 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
2964 tempal = tempal >> 2;
2965 tempal &= 0x03;
2967 /* for Dot8 Scaling LCD */
2968 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
2969 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2971 if (ModeNo <= 0x13)
2972 return tempal;
2974 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2975 return tempal;
2978 static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2979 unsigned char *di_1, struct vb_device_info *pVBInfo)
2981 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
2982 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
2983 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
2984 & ProgrammingCRT2)) {
2985 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
2986 *di_1 = XGI_VBVCLKData[tempal].SR2C;
2988 } else {
2989 *di_0 = XGI_VCLKData[tempal].SR2B;
2990 *di_1 = XGI_VCLKData[tempal].SR2C;
2994 static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
2995 unsigned short RefreshRateTableIndex,
2996 struct vb_device_info *pVBInfo)
2998 unsigned char di_0, di_1, tempal;
2999 int i;
3001 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3002 pVBInfo);
3003 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3004 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
3006 for (i = 0; i < 4; i++) {
3007 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
3008 (unsigned short) (0x10 * i));
3009 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
3010 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
3011 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
3012 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
3013 } else {
3014 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
3015 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
3020 static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
3021 struct vb_device_info *pVBInfo)
3023 unsigned short tempcl, tempch, temp, tempbl, tempax;
3025 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
3026 | VB_XGI302LV | VB_XGI301C)) {
3027 tempcl = 0;
3028 tempch = 0;
3029 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
3031 if (!(temp & 0x20)) {
3032 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
3033 if (temp & 0x80) {
3034 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
3035 if (!(temp & 0x40))
3036 tempcl |= ActiveCRT1;
3040 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
3041 temp &= 0x0f;
3043 if (!(temp == 0x08)) {
3044 /* Check ChannelA by Part1_13 [2003/10/03] */
3045 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
3046 if (tempax & 0x04)
3047 tempcl = tempcl | ActiveLCD;
3049 temp &= 0x05;
3051 if (!(tempcl & ActiveLCD))
3052 if (temp == 0x01)
3053 tempcl |= ActiveCRT2;
3055 if (temp == 0x04)
3056 tempcl |= ActiveLCD;
3058 if (temp == 0x05) {
3059 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
3061 if (!(temp & 0x08))
3062 tempch |= ActiveAVideo;
3064 if (!(temp & 0x04))
3065 tempch |= ActiveSVideo;
3067 if (temp & 0x02)
3068 tempch |= ActiveSCART;
3070 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3071 if (temp & 0x01)
3072 tempch |= ActiveHiTV;
3075 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
3076 temp = xgifb_reg_get(
3077 pVBInfo->Part2Port,
3078 0x4d);
3080 if (temp & 0x10)
3081 tempch |= ActiveYPbPr;
3084 if (tempch != 0)
3085 tempcl |= ActiveTV;
3089 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
3090 if (tempcl & ActiveLCD) {
3091 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3092 if (temp & ActiveTV)
3093 tempcl |= ActiveTV;
3096 temp = tempcl;
3097 tempbl = ~ModeSwitchStatus;
3098 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
3100 if (!(pVBInfo->SetFlag & ReserveTVOption))
3101 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
3102 } else {
3103 return;
3107 void XGI_GetVGAType(struct xgi_hw_device_info *HwDeviceExtension,
3108 struct vb_device_info *pVBInfo)
3111 if ( HwDeviceExtension->jChipType >= XG20 ) {
3112 pVBInfo->Set_VGAType = XG20;
3113 } else {
3114 pVBInfo->Set_VGAType = VGA_XGI340;
3117 pVBInfo->Set_VGAType = HwDeviceExtension->jChipType;
3120 void XGI_GetVBType(struct vb_device_info *pVBInfo)
3122 unsigned short flag, tempbx, tempah;
3124 if (pVBInfo->IF_DEF_LVDS == 0) {
3125 tempbx = VB_XGI302B;
3126 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
3127 if (flag != 0x02) {
3128 tempbx = VB_XGI301;
3129 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
3130 if (flag >= 0xB0) {
3131 tempbx = VB_XGI301B;
3132 if (flag >= 0xC0) {
3133 tempbx = VB_XGI301C;
3134 if (flag >= 0xD0) {
3135 tempbx = VB_XGI301LV;
3136 if (flag >= 0xE0) {
3137 tempbx = VB_XGI302LV;
3138 tempah = xgifb_reg_get(
3139 pVBInfo->Part4Port,
3140 0x39);
3141 if (tempah != 0xFF)
3142 tempbx =
3143 VB_XGI301C;
3148 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
3149 flag = xgifb_reg_get(
3150 pVBInfo->Part4Port,
3151 0x23);
3153 if (!(flag & 0x02))
3154 tempbx = tempbx | VB_NoLCD;
3158 pVBInfo->VBType = tempbx;
3162 void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3163 struct xgi_hw_device_info *HwDeviceExtension,
3164 struct vb_device_info *pVBInfo)
3166 unsigned short tempax, push, tempbx, temp, modeflag;
3168 if (ModeNo <= 0x13)
3169 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3170 else
3171 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3173 pVBInfo->SetFlag = 0;
3174 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3175 tempbx = 0;
3177 if (pVBInfo->VBType & 0xFFFF) {
3178 /* Check Display Device */
3179 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
3180 tempbx = tempbx | temp;
3181 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
3182 push = temp;
3183 push = push << 8;
3184 tempax = temp << 8;
3185 tempbx = tempbx | tempax;
3186 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3187 | SetInSlaveMode | DisableCRT2Display);
3188 temp = 0xFFFF ^ temp;
3189 tempbx &= temp;
3191 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3193 if (pVBInfo->IF_DEF_LCDA == 1) {
3195 if ((pVBInfo->Set_VGAType >= XG20)
3196 || (pVBInfo->Set_VGAType >= XG40)) {
3197 if (pVBInfo->IF_DEF_LVDS == 0) {
3198 /* if ((pVBInfo->VBType & VB_XGI302B)
3199 || (pVBInfo->VBType & VB_XGI301LV)
3200 || (pVBInfo->VBType & VB_XGI302LV)
3201 || (pVBInfo->VBType & VB_XGI301C))
3203 if (pVBInfo->VBType &
3204 (VB_XGI302B |
3205 VB_XGI301LV |
3206 VB_XGI302LV |
3207 VB_XGI301C)) {
3208 if (temp & EnableDualEdge) {
3209 tempbx |=
3210 SetCRT2ToDualEdge;
3212 if (temp & SetToLCDA)
3213 tempbx |=
3214 SetCRT2ToLCDA;
3221 if (pVBInfo->IF_DEF_YPbPr == 1) {
3222 /* [Billy] 07/05/04 */
3223 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3224 ((pVBInfo->VBType & VB_XGI301LV) ||
3225 (pVBInfo->VBType & VB_XGI302LV) ||
3226 (pVBInfo->VBType & VB_XGI301C)))) {
3227 if (temp & SetYPbPr) { /* temp = CR38 */
3228 if (pVBInfo->IF_DEF_HiVision == 1) {
3229 /* shampoo add for new
3230 * scratch */
3231 temp = xgifb_reg_get(
3232 pVBInfo->P3d4,
3233 0x35);
3234 temp &= YPbPrMode;
3235 tempbx |= SetCRT2ToHiVisionTV;
3237 if (temp != YPbPrMode1080i) {
3238 tempbx &=
3239 (~SetCRT2ToHiVisionTV);
3240 tempbx |=
3241 SetCRT2ToYPbPr;
3245 /* tempbx |= SetCRT2ToYPbPr; */
3250 tempax = push; /* restore CR31 */
3252 if (pVBInfo->IF_DEF_LVDS == 0) {
3253 if (pVBInfo->IF_DEF_YPbPr == 1) {
3254 if (pVBInfo->IF_DEF_HiVision == 1)
3255 temp = 0x09FC;
3256 else
3257 temp = 0x097C;
3258 } else {
3259 if (pVBInfo->IF_DEF_HiVision == 1)
3260 temp = 0x01FC;
3261 else
3262 temp = 0x017C;
3264 } else { /* 3nd party chip */
3265 temp = SetCRT2ToLCD;
3268 if (!(tempbx & temp)) {
3269 tempax |= DisableCRT2Display;
3270 tempbx = 0;
3273 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3274 if (!(pVBInfo->VBType & VB_NoLCD)) {
3275 if (tempbx & SetCRT2ToLCDA) {
3276 if (tempbx & SetSimuScanMode)
3277 tempbx &= (~(SetCRT2ToLCD |
3278 SetCRT2ToRAMDAC |
3279 SwitchToCRT2));
3280 else
3281 tempbx &= (~(SetCRT2ToLCD |
3282 SetCRT2ToRAMDAC |
3283 SetCRT2ToTV |
3284 SwitchToCRT2));
3289 /* shampoo add */
3290 /* for driver abnormal */
3291 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
3292 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3293 if (tempbx & SetCRT2ToRAMDAC) {
3294 tempbx &= (0xFF00 |
3295 SetCRT2ToRAMDAC |
3296 SwitchToCRT2 |
3297 SetSimuScanMode);
3298 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3300 } else {
3301 tempbx &= (~(SetCRT2ToRAMDAC |
3302 SetCRT2ToLCD |
3303 SetCRT2ToTV));
3307 if (!(pVBInfo->VBType & VB_NoLCD)) {
3308 if (tempbx & SetCRT2ToLCD) {
3309 tempbx &= (0xFF00 |
3310 SetCRT2ToLCD |
3311 SwitchToCRT2 |
3312 SetSimuScanMode);
3313 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3317 if (tempbx & SetCRT2ToSCART) {
3318 tempbx &= (0xFF00 |
3319 SetCRT2ToSCART |
3320 SwitchToCRT2 |
3321 SetSimuScanMode);
3322 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3325 if (pVBInfo->IF_DEF_YPbPr == 1) {
3326 if (tempbx & SetCRT2ToYPbPr)
3327 tempbx &= (0xFF00 |
3328 SwitchToCRT2 |
3329 SetSimuScanMode);
3332 if (pVBInfo->IF_DEF_HiVision == 1) {
3333 if (tempbx & SetCRT2ToHiVisionTV)
3334 tempbx &= (0xFF00 |
3335 SetCRT2ToHiVisionTV |
3336 SwitchToCRT2 |
3337 SetSimuScanMode);
3340 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3341 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3342 tempbx = DisableCRT2Display;
3345 if (!(tempbx & DisableCRT2Display)) {
3346 if ((!(tempbx & DriverMode)) ||
3347 (!(modeflag & CRT2Mode))) {
3348 if (pVBInfo->IF_DEF_LCDA == 1) {
3349 if (!(tempbx & SetCRT2ToLCDA))
3350 tempbx |= (SetInSlaveMode |
3351 SetSimuScanMode);
3355 /* LCD+TV can't support in slave mode
3356 * (Force LCDA+TV->LCDB) */
3357 if ((tempbx & SetInSlaveMode) &&
3358 (tempbx & SetCRT2ToLCDA)) {
3359 tempbx ^= (SetCRT2ToLCD |
3360 SetCRT2ToLCDA |
3361 SetCRT2ToDualEdge);
3362 pVBInfo->SetFlag |= ReserveTVOption;
3367 pVBInfo->VBInfo = tempbx;
3370 void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3371 struct vb_device_info *pVBInfo)
3373 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
3375 tempbx = 0;
3376 resinfo = 0;
3378 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3379 if (ModeNo <= 0x13) {
3380 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3381 St_ModeFlag; /* si+St_ModeFlag */
3382 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3383 St_ResInfo; /* si+St_ResInfo */
3384 } else {
3385 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3386 Ext_ModeFlag;
3387 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3388 Ext_RESINFO; /* si+Ext_ResInfo */
3391 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3392 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
3393 tempbx = temp;
3394 if (tempbx & SetPALTV) {
3395 tempbx &= (SetCHTVOverScan |
3396 SetPALMTV |
3397 SetPALNTV |
3398 SetPALTV);
3399 if (tempbx & SetPALMTV)
3400 /* set to NTSC if PAL-M */
3401 tempbx &= ~SetPALTV;
3402 } else
3403 tempbx &= (SetCHTVOverScan |
3404 SetNTSCJ |
3405 SetPALTV);
3407 if (pVBInfo->IF_DEF_LVDS == 0) {
3408 //PAL-M/PAL-N Info
3409 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3410 //00:PAL, 01:PAL-M, 10:PAL-N
3411 temp2 = (index1 & 0xC0) >> 5;
3412 tempbx |= temp2;
3413 if (temp2 & 0x02) //PAL-M
3414 tempbx &= (~SetPALTV);
3419 if (pVBInfo->IF_DEF_LVDS == 0) {
3420 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3421 tempbx |= SetPALTV;
3424 if (pVBInfo->IF_DEF_YPbPr == 1) {
3425 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
3426 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
3427 index1 &= YPbPrMode;
3429 if (index1 == YPbPrMode525i)
3430 tempbx |= SetYPbPrMode525i;
3432 if (index1 == YPbPrMode525p)
3433 tempbx = tempbx | SetYPbPrMode525p;
3434 if (index1 == YPbPrMode750p)
3435 tempbx = tempbx | SetYPbPrMode750p;
3439 if (pVBInfo->IF_DEF_HiVision == 1) {
3440 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3441 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3444 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3445 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3446 (!(pVBInfo->VBInfo & SetNotSimuMode)))
3447 tempbx |= TVSimuMode;
3449 if (!(tempbx & SetPALTV) &&
3450 (modeflag > 13) &&
3451 (resinfo == 8)) /* NTSC 1024x768, */
3452 tempbx |= NTSC1024x768;
3454 tempbx |= RPLLDIV2XO;
3456 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3457 if (pVBInfo->VBInfo & SetInSlaveMode)
3458 tempbx &= (~RPLLDIV2XO);
3459 } else {
3460 if (tempbx &
3461 (SetYPbPrMode525p | SetYPbPrMode750p))
3462 tempbx &= (~RPLLDIV2XO);
3463 else if (!(pVBInfo->VBType &
3464 (VB_XGI301B |
3465 VB_XGI302B |
3466 VB_XGI301LV |
3467 VB_XGI302LV |
3468 VB_XGI301C))) {
3469 if (tempbx & TVSimuMode)
3470 tempbx &= (~RPLLDIV2XO);
3475 pVBInfo->TVInfo = tempbx;
3478 unsigned char XGI_GetLCDInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3479 struct vb_device_info *pVBInfo)
3481 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
3483 pVBInfo->LCDResInfo = 0;
3484 pVBInfo->LCDTypeInfo = 0;
3485 pVBInfo->LCDInfo = 0;
3487 if (ModeNo <= 0x13) {
3488 /* si+St_ModeFlag // */
3489 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3490 } else {
3491 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3492 /* si+Ext_ResInfo // */
3493 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3496 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
3497 tempbx = temp & 0x0F;
3499 if (tempbx == 0)
3500 tempbx = Panel1024x768; /* default */
3502 /* LCD75 [2003/8/22] Vicent */
3503 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3504 if (pVBInfo->VBInfo & DriverMode) {
3505 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
3506 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3507 tempax &= 0x0F;
3508 else
3509 tempax = tempax >> 4;
3511 if ((resinfo == 6) || (resinfo == 9)) {
3512 if (tempax >= 3)
3513 tempbx |= PanelRef75Hz;
3514 } else if ((resinfo == 7) || (resinfo == 8)) {
3515 if (tempax >= 4)
3516 tempbx |= PanelRef75Hz;
3521 pVBInfo->LCDResInfo = tempbx;
3523 /* End of LCD75 */
3525 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3526 return 0;
3528 tempbx = 0;
3530 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
3532 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
3534 tempbx |= temp;
3536 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
3538 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
3540 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3541 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3542 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3543 tempbx |= SetLCDDualLink;
3547 if (pVBInfo->IF_DEF_LVDS == 0) {
3548 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3549 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3550 == 9) && (!(tempbx & EnableScalingLCD)))
3551 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3552 tempbx |= SetLCDtoNonExpanding;
3556 if (tempax & LCDBToA) {
3557 tempbx |= SetLCDBToA;
3561 if (pVBInfo->IF_DEF_ExpLink == 1) {
3562 if (modeflag & HalfDCLK) {
3563 /* if (!(pVBInfo->LCDInfo&LCDNonExpanding)) */
3564 if (!(tempbx & SetLCDtoNonExpanding)) {
3565 tempbx |= EnableLVDSDDA;
3566 } else {
3567 if (ModeNo > 0x13) {
3568 if (pVBInfo->LCDResInfo
3569 == Panel1024x768) {
3570 if (resinfo == 4) {/* 512x384 */
3571 tempbx |= EnableLVDSDDA;
3579 if (pVBInfo->VBInfo & SetInSlaveMode) {
3580 if (pVBInfo->VBInfo & SetNotSimuMode)
3581 tempbx |= LCDVESATiming;
3582 } else {
3583 tempbx |= LCDVESATiming;
3586 pVBInfo->LCDInfo = tempbx;
3588 if (pVBInfo->IF_DEF_LVDS == 0) {
3589 if (tempax & (LockLCDBToA | StLCDBToA)) {
3590 if (pVBInfo->VBInfo & SetInSlaveMode) {
3591 if (!(tempax & LockLCDBToA)) {
3592 if (ModeNo <= 0x13) {
3593 pVBInfo->VBInfo &=
3594 ~(SetSimuScanMode |
3595 SetInSlaveMode |
3596 SetCRT2ToLCD);
3597 pVBInfo->VBInfo |=
3598 SetCRT2ToLCDA |
3599 SetCRT2ToDualEdge;
3607 if (pVBInfo->IF_DEF_LVDS == 0) {
3608 if (tempax & (LockLCDBToA | StLCDBToA)) {
3609 if (pVBInfo->VBInfo & SetInSlaveMode) {
3610 if (!((!(tempax & LockLCDBToA)) &&
3611 (ModeNo > 0x13))) {
3612 pVBInfo->VBInfo &=
3613 ~(SetSimuScanMode |
3614 SetInSlaveMode |
3615 SetCRT2ToLCD);
3616 pVBInfo->VBInfo |=
3617 SetCRT2ToLCDA |
3618 SetCRT2ToDualEdge;
3625 return 1;
3628 unsigned char XGI_SearchModeID(unsigned short ModeNo,
3629 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
3631 if (ModeNo <= 5)
3632 ModeNo |= 1;
3633 if (ModeNo <= 0x13) {
3634 /* for (*ModeIdIndex=0;
3635 *ModeIdIndex < sizeof(pVBInfo->SModeIDTable)
3636 / sizeof(struct XGI_StStruct);
3637 (*ModeIdIndex)++) */
3638 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3639 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3640 ModeNo)
3641 break;
3642 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3643 0xFF)
3644 return 0;
3647 if (ModeNo == 0x07)
3648 (*ModeIdIndex)++; /* 400 lines */
3649 if (ModeNo <= 3)
3650 (*ModeIdIndex) += 2; /* 400 lines */
3651 /* else 350 lines */
3652 } else {
3653 /* for (*ModeIdIndex=0;
3654 *ModeIdIndex < sizeof(pVBInfo->EModeIDTable)
3655 / sizeof(struct XGI_ExtStruct);
3656 (*ModeIdIndex)++) */
3657 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3658 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3659 ModeNo)
3660 break;
3661 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3662 0xFF)
3663 return 0;
3667 return 1;
3670 static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3672 unsigned char ujRet = 0;
3673 unsigned char i = 0;
3675 for (i = 0; i < 8; i++) {
3676 ujRet = ujRet << 1;
3677 /* ujRet |= GETBITS(ujDate >> i, 0:0); */
3678 ujRet |= (ujDate >> i) & 1;
3681 return ujRet;
3684 /*----------------------------------------------------------------------------*/
3685 /* output */
3686 /* bl[5] : LVDS signal */
3687 /* bl[1] : LVDS backlight */
3688 /* bl[0] : LVDS VDD */
3689 /*----------------------------------------------------------------------------*/
3690 static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3692 unsigned char CR4A, temp;
3694 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3695 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
3697 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3699 temp = XG21GPIODataTransfer(temp);
3700 temp &= 0x23;
3701 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3702 return temp;
3705 /*----------------------------------------------------------------------------*/
3706 /* output */
3707 /* bl[5] : LVDS signal */
3708 /* bl[1] : LVDS backlight */
3709 /* bl[0] : LVDS VDD */
3710 /*----------------------------------------------------------------------------*/
3711 static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3713 unsigned char CR4A, CRB4, temp;
3715 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3716 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
3718 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3720 temp &= 0x0C;
3721 temp >>= 2;
3722 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3723 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
3724 temp |= ((CRB4 & 0x04) << 3);
3725 return temp;
3728 void XGI_DisplayOn(struct xgi_hw_device_info *pXGIHWDE,
3729 struct vb_device_info *pVBInfo)
3732 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
3733 if (pXGIHWDE->jChipType == XG21) {
3734 if (pVBInfo->IF_DEF_LVDS == 1) {
3735 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
3736 /* LVDS VDD on */
3737 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
3738 XGI_XG21SetPanelDelay(2, pVBInfo);
3740 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
3741 /* LVDS signal on */
3742 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3743 XGI_XG21SetPanelDelay(3, pVBInfo);
3744 /* LVDS backlight on */
3745 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
3746 } else {
3747 /* DVO/DVI signal on */
3748 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3753 if (pXGIHWDE->jChipType == XG27) {
3754 if (pVBInfo->IF_DEF_LVDS == 1) {
3755 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
3756 /* LVDS VDD on */
3757 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
3758 XGI_XG21SetPanelDelay(2, pVBInfo);
3760 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
3761 /* LVDS signal on */
3762 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3763 XGI_XG21SetPanelDelay(3, pVBInfo);
3764 /* LVDS backlight on */
3765 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
3766 } else {
3767 /* DVO/DVI signal on */
3768 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3774 void XGI_DisplayOff(struct xgi_hw_device_info *pXGIHWDE,
3775 struct vb_device_info *pVBInfo)
3778 if (pXGIHWDE->jChipType == XG21) {
3779 if (pVBInfo->IF_DEF_LVDS == 1) {
3780 /* LVDS backlight off */
3781 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
3782 XGI_XG21SetPanelDelay(3, pVBInfo);
3783 } else {
3784 /* DVO/DVI signal off */
3785 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
3789 if (pXGIHWDE->jChipType == XG27) {
3790 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
3791 /* LVDS backlight off */
3792 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
3793 XGI_XG21SetPanelDelay(3, pVBInfo);
3796 if (pVBInfo->IF_DEF_LVDS == 0)
3797 /* DVO/DVI signal off */
3798 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
3801 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
3804 static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
3806 while ((inb(pVBInfo->P3da) & 0x01))
3807 break;
3809 while (!(inb(pVBInfo->P3da) & 0x01))
3810 break;
3813 static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
3815 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
3818 static void XGI_SaveCRT2Info(unsigned short ModeNo,
3819 struct vb_device_info *pVBInfo)
3821 unsigned short temp1, temp2;
3823 /* reserve CR34 for CRT1 Mode No */
3824 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
3825 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3826 temp2 = ~(SetInSlaveMode >> 8);
3827 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
3830 static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3831 unsigned short ModeIdIndex,
3832 struct vb_device_info *pVBInfo)
3834 unsigned short xres, yres, modeflag, resindex;
3836 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
3837 if (ModeNo <= 0x13) {
3838 xres = pVBInfo->StResInfo[resindex].HTotal;
3839 yres = pVBInfo->StResInfo[resindex].VTotal;
3840 /* si+St_ResInfo */
3841 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;*/
3842 } else {
3843 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3844 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3845 /* si+St_ModeFlag */
3846 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3849 if (pVBInfo->IF_DEF_FSTN) {
3850 xres *= 2;
3851 yres *= 2;
3852 } else {
3854 if (modeflag & HalfDCLK)
3855 xres *= 2;
3857 if (modeflag & DoubleScanMode)
3858 yres *= 2;
3859 /* } */
3862 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3863 if (pVBInfo->IF_DEF_LVDS == 0) {
3864 if (pVBInfo->LCDResInfo == Panel1600x1200) {
3865 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3866 if (yres == 1024)
3867 yres = 1056;
3871 if (pVBInfo->LCDResInfo == Panel1280x1024) {
3872 if (yres == 400)
3873 yres = 405;
3874 else if (yres == 350)
3875 yres = 360;
3877 if (pVBInfo->LCDInfo & LCDVESATiming) {
3878 if (yres == 360)
3879 yres = 375;
3883 if (pVBInfo->LCDResInfo == Panel1024x768) {
3884 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3885 if (!(pVBInfo->LCDInfo
3886 & LCDNonExpanding)) {
3887 if (yres == 350)
3888 yres = 357;
3889 else if (yres == 400)
3890 yres = 420;
3891 else if (yres == 480)
3892 yres = 525;
3898 if (xres == 720)
3899 xres = 640;
3902 pVBInfo->VGAHDE = xres;
3903 pVBInfo->HDE = xres;
3904 pVBInfo->VGAVDE = yres;
3905 pVBInfo->VDE = yres;
3908 static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
3911 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
3912 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
3913 return 1;
3915 return 0;
3918 static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3919 unsigned short ModeIdIndex,
3920 unsigned short RefreshRateTableIndex,
3921 struct vb_device_info *pVBInfo)
3923 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
3924 StandTableIndex, CRT1Index;
3926 pVBInfo->RVBHCMAX = 1;
3927 pVBInfo->RVBHCFACT = 1;
3929 if (ModeNo <= 0x13) {
3930 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3931 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
3932 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
3933 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
3934 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
3935 } else {
3936 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3937 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
3938 Ext_CRT1CRTC;
3939 CRT1Index &= IndexMask;
3940 temp1 = (unsigned short) pVBInfo->
3941 XGINEWUB_CRT1Table[CRT1Index].CR[0];
3942 temp2 = (unsigned short) pVBInfo->
3943 XGINEWUB_CRT1Table[CRT1Index].CR[5];
3944 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3945 tempbx = (unsigned short) pVBInfo->
3946 XGINEWUB_CRT1Table[CRT1Index].CR[8];
3947 tempcx = (unsigned short) pVBInfo->
3948 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3949 tempcx &= 0x0100;
3950 tempcx = tempcx << 2;
3951 tempbx |= tempcx;
3952 temp1 = (unsigned short) pVBInfo->
3953 XGINEWUB_CRT1Table[CRT1Index].CR[9];
3956 if (temp1 & 0x01)
3957 tempbx |= 0x0100;
3959 if (temp1 & 0x20)
3960 tempbx |= 0x0200;
3961 tempax += 5;
3963 if (modeflag & Charx8Dot)
3964 tempax *= 8;
3965 else
3966 tempax *= 9;
3968 pVBInfo->VGAHT = tempax;
3969 pVBInfo->HT = tempax;
3970 tempbx++;
3971 pVBInfo->VGAVT = tempbx;
3972 pVBInfo->VT = tempbx;
3975 static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
3976 unsigned short RefreshRateTableIndex,
3977 struct vb_device_info *pVBInfo)
3979 unsigned short tempax = 0, tempbx, modeflag, resinfo;
3981 struct XGI_LCDDataStruct *LCDPtr = NULL;
3982 struct XGI_TVDataStruct *TVPtr = NULL;
3984 if (ModeNo <= 0x13) {
3985 /* si+St_ResInfo */
3986 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3987 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
3988 } else {
3989 /* si+Ext_ResInfo */
3990 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3991 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3994 pVBInfo->NewFlickerMode = 0;
3995 pVBInfo->RVBHRS = 50;
3997 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3998 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3999 pVBInfo);
4000 return;
4003 tempbx = 4;
4005 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4006 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
4007 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4008 pVBInfo);
4010 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
4011 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
4012 pVBInfo->VGAHT = LCDPtr->VGAHT;
4013 pVBInfo->VGAVT = LCDPtr->VGAVT;
4014 pVBInfo->HT = LCDPtr->LCDHT;
4015 pVBInfo->VT = LCDPtr->LCDVT;
4017 if (pVBInfo->LCDResInfo == Panel1024x768) {
4018 tempax = 1024;
4019 tempbx = 768;
4021 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4022 if (pVBInfo->VGAVDE == 357)
4023 tempbx = 527;
4024 else if (pVBInfo->VGAVDE == 420)
4025 tempbx = 620;
4026 else if (pVBInfo->VGAVDE == 525)
4027 tempbx = 775;
4028 else if (pVBInfo->VGAVDE == 600)
4029 tempbx = 775;
4030 /* else if (pVBInfo->VGAVDE==350) tempbx=560; */
4031 /* else if (pVBInfo->VGAVDE==400) tempbx=640; */
4032 else
4033 tempbx = 768;
4034 } else
4035 tempbx = 768;
4036 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
4037 tempax = 1024;
4038 tempbx = 768;
4039 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
4040 tempax = 1280;
4041 if (pVBInfo->VGAVDE == 360)
4042 tempbx = 768;
4043 else if (pVBInfo->VGAVDE == 375)
4044 tempbx = 800;
4045 else if (pVBInfo->VGAVDE == 405)
4046 tempbx = 864;
4047 else
4048 tempbx = 1024;
4049 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
4050 tempax = 1280;
4051 tempbx = 1024;
4052 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
4053 tempax = 1280;
4054 if (pVBInfo->VGAVDE == 350)
4055 tempbx = 700;
4056 else if (pVBInfo->VGAVDE == 400)
4057 tempbx = 800;
4058 else if (pVBInfo->VGAVDE == 1024)
4059 tempbx = 960;
4060 else
4061 tempbx = 960;
4062 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4063 tempax = 1400;
4064 tempbx = 1050;
4066 if (pVBInfo->VGAVDE == 1024) {
4067 tempax = 1280;
4068 tempbx = 1024;
4070 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4071 tempax = 1600;
4072 tempbx = 1200; /* alan 10/14/2003 */
4073 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4074 if (pVBInfo->VGAVDE == 350)
4075 tempbx = 875;
4076 else if (pVBInfo->VGAVDE == 400)
4077 tempbx = 1000;
4081 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4082 tempax = pVBInfo->VGAHDE;
4083 tempbx = pVBInfo->VGAVDE;
4086 pVBInfo->HDE = tempax;
4087 pVBInfo->VDE = tempbx;
4088 return;
4091 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4092 tempbx = 4;
4093 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4094 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4095 pVBInfo);
4097 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4098 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4099 pVBInfo->VGAHT = TVPtr->VGAHT;
4100 pVBInfo->VGAVT = TVPtr->VGAVT;
4101 pVBInfo->HDE = TVPtr->TVHDE;
4102 pVBInfo->VDE = TVPtr->TVVDE;
4103 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4104 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
4106 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4107 if (resinfo == 0x08)
4108 pVBInfo->NewFlickerMode = 0x40;
4109 else if (resinfo == 0x09)
4110 pVBInfo->NewFlickerMode = 0x40;
4111 else if (resinfo == 0x12)
4112 pVBInfo->NewFlickerMode = 0x40;
4114 if (pVBInfo->VGAVDE == 350)
4115 pVBInfo->TVInfo |= TVSimuMode;
4117 tempax = ExtHiTVHT;
4118 tempbx = ExtHiTVVT;
4120 if (pVBInfo->VBInfo & SetInSlaveMode) {
4121 if (pVBInfo->TVInfo & TVSimuMode) {
4122 tempax = StHiTVHT;
4123 tempbx = StHiTVVT;
4125 if (!(modeflag & Charx8Dot)) {
4126 tempax = StHiTextTVHT;
4127 tempbx = StHiTextTVVT;
4131 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4132 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4133 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4134 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4137 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4138 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4139 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4140 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4141 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4142 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4143 if (pVBInfo->TVInfo & NTSC1024x768)
4144 tempax = NTSC1024x768HT;
4146 } else {
4147 tempax = PALHT;
4148 tempbx = PALVT;
4149 if (!(pVBInfo->TVInfo & SetPALTV)) {
4150 tempax = NTSCHT;
4151 tempbx = NTSCVT;
4152 if (pVBInfo->TVInfo & NTSC1024x768)
4153 tempax = NTSC1024x768HT;
4157 pVBInfo->HT = tempax;
4158 pVBInfo->VT = tempbx;
4159 return;
4163 static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
4164 unsigned short RefreshRateTableIndex,
4165 struct vb_device_info *pVBInfo)
4167 unsigned char di_0, di_1, tempal;
4169 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4170 pVBInfo);
4171 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4172 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
4174 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4175 /* 301 */
4176 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4177 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4178 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4179 } else { /* 301b/302b/301lv/302lv */
4180 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4181 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4184 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
4186 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
4187 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
4188 else
4189 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
4192 static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4193 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
4195 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4196 short index;
4197 unsigned short modeflag;
4199 if (ModeNo <= 0x13)
4200 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4201 else
4202 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4204 index = (modeflag & ModeInfoFlag) - ModeEGA;
4206 if (index < 0)
4207 index = 0;
4209 return ColorDepth[index];
4212 static unsigned short XGI_GetOffset(unsigned short ModeNo,
4213 unsigned short ModeIdIndex,
4214 unsigned short RefreshRateTableIndex,
4215 struct xgi_hw_device_info *HwDeviceExtension,
4216 struct vb_device_info *pVBInfo)
4218 unsigned short temp, colordepth, modeinfo, index, infoflag,
4219 ColorDepth[] = { 0x01, 0x02, 0x04 };
4221 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4222 if (ModeNo <= 0x14)
4223 infoflag = 0;
4224 else
4225 infoflag = pVBInfo->
4226 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
4228 index = (modeinfo >> 8) & 0xFF;
4230 temp = pVBInfo->ScreenOffset[index];
4232 if (infoflag & InterlaceMode)
4233 temp = temp << 1;
4235 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4237 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4238 temp = ModeNo - 0x7C;
4239 colordepth = ColorDepth[temp];
4240 temp = 0x6B;
4241 if (infoflag & InterlaceMode)
4242 temp = temp << 1;
4243 return temp * colordepth;
4244 } else {
4245 return temp * colordepth;
4249 static void XGI_SetCRT2Offset(unsigned short ModeNo,
4250 unsigned short ModeIdIndex,
4251 unsigned short RefreshRateTableIndex,
4252 struct xgi_hw_device_info *HwDeviceExtension,
4253 struct vb_device_info *pVBInfo)
4255 unsigned short offset;
4256 unsigned char temp;
4258 if (pVBInfo->VBInfo & SetInSlaveMode)
4259 return;
4261 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4262 HwDeviceExtension, pVBInfo);
4263 temp = (unsigned char) (offset & 0xFF);
4264 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4265 temp = (unsigned char) ((offset & 0xFF00) >> 8);
4266 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
4267 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
4268 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
4271 static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
4273 /* threshold high ,disable auto threshold */
4274 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4275 /* threshold low default 04h */
4276 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
4279 static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4280 struct xgi_hw_device_info *HwDeviceExtension,
4281 unsigned short RefreshRateTableIndex,
4282 struct vb_device_info *pVBInfo)
4284 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
4286 if (ModeNo > 0x13) {
4287 CRT1Index = pVBInfo->
4288 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4289 CRT1Index &= IndexMask;
4290 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4293 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4294 HwDeviceExtension, pVBInfo);
4295 XGI_SetCRT2FIFO(pVBInfo);
4296 /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
4298 for (tempcx = 4; tempcx < 7; tempcx++)
4299 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
4301 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4302 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
4305 static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4306 struct xgi_hw_device_info *HwDeviceExtension,
4307 unsigned short RefreshRateTableIndex,
4308 struct vb_device_info *pVBInfo)
4310 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4311 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
4313 if (ModeNo > 0x13) {
4314 CRT1Index = pVBInfo->
4315 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4316 CRT1Index &= IndexMask;
4317 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4320 if (ModeNo <= 0x13)
4321 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4322 else
4323 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4325 /* bainy change table name */
4326 if (modeflag & HalfDCLK) {
4327 /* BTVGA2HT 0x08,0x09 */
4328 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
4329 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
4330 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
4331 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
4332 /* BTVGA2HDEE 0x0A,0x0C */
4333 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
4334 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
4335 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4336 pushbx = pVBInfo->VGAHDE / 2 + 16;
4337 tempcx = tempcx >> 1;
4338 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4339 tempcx += tempbx;
4341 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4342 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4343 tempbx |= ((pVBInfo->
4344 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4345 0xC0) << 2);
4346 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4347 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4348 tempcx &= 0x1F;
4349 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4350 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4351 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4354 tempbx += 4;
4355 tempcx += 4;
4357 if (tempcx > (pVBInfo->VGAHT / 2))
4358 tempcx = pVBInfo->VGAHT / 2;
4360 temp = tempbx & 0x00FF;
4362 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4363 } else {
4364 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
4365 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
4366 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
4367 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
4368 /* BTVGA2HDEE 0x0A,0x0C */
4369 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
4370 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
4371 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4372 pushbx = pVBInfo->VGAHDE + 16;
4373 tempcx = tempcx >> 1;
4374 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4375 tempcx += tempbx;
4377 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4378 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
4379 tempbx |= ((pVBInfo->
4380 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4381 0xC0) << 2);
4382 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4383 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4384 tempcx &= 0x1F;
4385 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4386 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4387 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4388 tempbx += 16;
4389 tempcx += 16;
4392 if (tempcx > pVBInfo->VGAHT)
4393 tempcx = pVBInfo->VGAHT;
4395 temp = tempbx & 0x00FF;
4396 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4399 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4400 tempbx = pushbx;
4401 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4402 tempax |= (tempbx & 0xFF00);
4403 temp = (tempax & 0xFF00) >> 8;
4404 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
4405 temp = tempcx & 0x00FF;
4406 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
4407 tempcx = (pVBInfo->VGAVT - 1);
4408 temp = tempcx & 0x00FF;
4410 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
4411 tempbx = pVBInfo->VGAVDE - 1;
4412 temp = tempbx & 0x00FF;
4413 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
4414 temp = ((tempbx & 0xFF00) << 3) >> 8;
4415 temp |= ((tempcx & 0xFF00) >> 8);
4416 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
4418 tempax = pVBInfo->VGAVDE;
4419 tempbx = pVBInfo->VGAVDE;
4420 tempcx = pVBInfo->VGAVT;
4421 /* BTVGA2VRS 0x10,0x11 */
4422 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4423 /* BTVGA2VRE 0x11 */
4424 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
4426 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4427 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4428 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
4430 if (temp & 0x04)
4431 tempbx |= 0x0100;
4433 if (temp & 0x080)
4434 tempbx |= 0x0200;
4436 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
4438 if (temp & 0x08)
4439 tempbx |= 0x0400;
4441 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4442 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4445 temp = tempbx & 0x00FF;
4446 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4447 temp = ((tempbx & 0xFF00) >> 8) << 4;
4448 temp = ((tempcx & 0x000F) | (temp));
4449 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
4450 tempax = 0;
4452 if (modeflag & DoubleScanMode)
4453 tempax |= 0x80;
4455 if (modeflag & HalfDCLK)
4456 tempax |= 0x40;
4458 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
4461 static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4463 unsigned long tempax, tempbx;
4465 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4466 & 0xFFFF;
4467 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4468 tempax = (tempax * pVBInfo->HT) / tempbx;
4470 return (unsigned short) tempax;
4473 static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4474 struct xgi_hw_device_info *HwDeviceExtension,
4475 unsigned short RefreshRateTableIndex,
4476 struct vb_device_info *pVBInfo)
4478 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4479 modeflag, CRT1Index;
4481 if (ModeNo <= 0x13) {
4482 /* si+St_ResInfo */
4483 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4484 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4485 } else {
4486 /* si+Ext_ResInfo */
4487 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4488 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4489 CRT1Index = pVBInfo->
4490 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4491 CRT1Index &= IndexMask;
4494 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4495 return;
4497 temp = 0xFF; /* set MAX HT */
4498 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
4499 /* if (modeflag & Charx8Dot) */
4500 /* tempcx = 0x08; */
4501 /* else */
4502 tempcx = 0x08;
4504 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4505 modeflag |= Charx8Dot;
4507 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
4509 if (modeflag & HalfDCLK)
4510 tempax = tempax >> 1;
4512 tempax = (tempax / tempcx) - 1;
4513 tempbx |= ((tempax & 0x00FF) << 8);
4514 temp = tempax & 0x00FF;
4515 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
4517 temp = (tempbx & 0xFF00) >> 8;
4519 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4520 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4521 | VB_XGI302LV | VB_XGI301C)))
4522 temp += 2;
4524 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4525 if (pVBInfo->VBType & VB_XGI301LV) {
4526 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4527 if (resinfo == 7)
4528 temp -= 2;
4530 } else if (resinfo == 7) {
4531 temp -= 2;
4536 /* 0x05 Horizontal Display Start */
4537 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4538 /* 0x06 Horizontal Blank end */
4539 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
4541 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4542 if (pVBInfo->VBInfo & SetCRT2ToTV)
4543 tempax = pVBInfo->VGAHT;
4544 else
4545 tempax = XGI_GetVGAHT2(pVBInfo);
4548 if (tempax >= pVBInfo->VGAHT)
4549 tempax = pVBInfo->VGAHT;
4551 if (modeflag & HalfDCLK)
4552 tempax = tempax >> 1;
4554 tempax = (tempax / tempcx) - 5;
4555 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4556 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4557 temp = (tempbx & 0x00FF) - 1;
4558 if (!(modeflag & HalfDCLK)) {
4559 temp -= 6;
4560 if (pVBInfo->TVInfo & TVSimuMode) {
4561 temp -= 4;
4562 if (ModeNo > 0x13)
4563 temp -= 10;
4566 } else {
4567 /* tempcx = tempbx & 0x00FF ; */
4568 tempbx = (tempbx & 0xFF00) >> 8;
4569 tempcx = (tempcx + tempbx) >> 1;
4570 temp = (tempcx & 0x00FF) + 2;
4572 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4573 temp -= 1;
4574 if (!(modeflag & HalfDCLK)) {
4575 if ((modeflag & Charx8Dot)) {
4576 temp += 4;
4577 if (pVBInfo->VGAHDE >= 800)
4578 temp -= 6;
4581 } else {
4582 if (!(modeflag & HalfDCLK)) {
4583 temp -= 4;
4584 if (pVBInfo->LCDResInfo != Panel1280x960) {
4585 if (pVBInfo->VGAHDE >= 800) {
4586 temp -= 7;
4587 if (pVBInfo->ModeType ==
4588 ModeEGA) {
4589 if (pVBInfo->VGAVDE ==
4590 1024) {
4591 temp += 15;
4592 if (pVBInfo->LCDResInfo != Panel1280x1024) {
4593 temp +=
4599 if (pVBInfo->VGAHDE >= 1280) {
4600 if (pVBInfo->LCDResInfo
4601 != Panel1280x960) {
4602 if (pVBInfo->LCDInfo
4603 & LCDNonExpanding) {
4604 temp
4605 += 28;
4615 /* 0x07 Horizontal Retrace Start */
4616 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4617 /* 0x08 Horizontal Retrace End */
4618 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
4620 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4621 if (pVBInfo->TVInfo & TVSimuMode) {
4622 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4623 == 0x11) || (ModeNo == 0x13) || (ModeNo
4624 == 0x0F)) {
4625 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4626 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
4629 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4630 if (pVBInfo->TVInfo & SetNTSCTV) {
4631 xgifb_reg_set(pVBInfo->Part1Port,
4632 0x07, 0x2A);
4633 xgifb_reg_set(pVBInfo->Part1Port,
4634 0x08, 0x61);
4635 } else {
4636 xgifb_reg_set(pVBInfo->Part1Port,
4637 0x07, 0x2A);
4638 xgifb_reg_set(pVBInfo->Part1Port,
4639 0x08, 0x41);
4640 xgifb_reg_set(pVBInfo->Part1Port,
4641 0x0C, 0xF0);
4645 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4646 == 0x07)) {
4647 if (pVBInfo->TVInfo & SetNTSCTV) {
4648 xgifb_reg_set(pVBInfo->Part1Port,
4649 0x07, 0x54);
4650 xgifb_reg_set(pVBInfo->Part1Port,
4651 0x08, 0x00);
4652 } else {
4653 xgifb_reg_set(pVBInfo->Part1Port,
4654 0x07, 0x55);
4655 xgifb_reg_set(pVBInfo->Part1Port,
4656 0x08, 0x00);
4657 xgifb_reg_set(pVBInfo->Part1Port,
4658 0x0C, 0xF0);
4662 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4663 == 0x0D) || (ModeNo == 0x50)) {
4664 if (pVBInfo->TVInfo & SetNTSCTV) {
4665 xgifb_reg_set(pVBInfo->Part1Port,
4666 0x07, 0x30);
4667 xgifb_reg_set(pVBInfo->Part1Port,
4668 0x08, 0x03);
4669 } else {
4670 xgifb_reg_set(pVBInfo->Part1Port,
4671 0x07, 0x2f);
4672 xgifb_reg_set(pVBInfo->Part1Port,
4673 0x08, 0x02);
4679 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
4680 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
4681 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
4683 tempbx = pVBInfo->VGAVT;
4684 push1 = tempbx;
4685 tempcx = 0x121;
4686 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
4688 if (tempbx == 357)
4689 tempbx = 350;
4690 if (tempbx == 360)
4691 tempbx = 350;
4692 if (tempbx == 375)
4693 tempbx = 350;
4694 if (tempbx == 405)
4695 tempbx = 400;
4696 if (tempbx == 525)
4697 tempbx = 480;
4699 push2 = tempbx;
4701 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4702 if (pVBInfo->LCDResInfo == Panel1024x768) {
4703 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4704 if (tempbx == 350)
4705 tempbx += 5;
4706 if (tempbx == 480)
4707 tempbx += 5;
4711 tempbx--;
4712 temp = tempbx & 0x00FF;
4713 tempbx--;
4714 temp = tempbx & 0x00FF;
4715 /* 0x10 vertical Blank Start */
4716 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4717 tempbx = push2;
4718 tempbx--;
4719 temp = tempbx & 0x00FF;
4720 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
4722 if (tempbx & 0x0100)
4723 tempcx |= 0x0002;
4725 tempax = 0x000B;
4727 if (modeflag & DoubleScanMode)
4728 tempax |= 0x08000;
4730 if (tempbx & 0x0200)
4731 tempcx |= 0x0040;
4733 temp = (tempax & 0xFF00) >> 8;
4734 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4736 if (tempbx & 0x0400)
4737 tempcx |= 0x0600;
4739 /* 0x11 Vertival Blank End */
4740 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
4742 tempax = push1;
4743 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4744 tempax = tempax >> 2;
4745 push1 = tempax; /* push ax */
4747 if (resinfo != 0x09) {
4748 tempax = tempax << 1;
4749 tempbx += tempax;
4752 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4753 if (pVBInfo->VBType & VB_XGI301LV) {
4754 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
4755 tempbx -= 10;
4756 } else {
4757 if (pVBInfo->TVInfo & TVSimuMode) {
4758 if (pVBInfo->TVInfo & SetPALTV) {
4759 if (pVBInfo->VBType &
4760 VB_XGI301LV) {
4761 if (!(pVBInfo->TVInfo &
4762 (SetYPbPrMode525p |
4763 SetYPbPrMode750p |
4764 SetYPbPrMode1080i)))
4765 tempbx += 40;
4766 } else {
4767 tempbx += 40;
4772 } else {
4773 tempbx -= 10;
4775 } else {
4776 if (pVBInfo->TVInfo & TVSimuMode) {
4777 if (pVBInfo->TVInfo & SetPALTV) {
4778 if (pVBInfo->VBType & VB_XGI301LV) {
4779 if (!(pVBInfo->TVInfo &
4780 (SetYPbPrMode525p |
4781 SetYPbPrMode750p |
4782 SetYPbPrMode1080i)))
4783 tempbx += 40;
4784 } else {
4785 tempbx += 40;
4790 tempax = push1;
4791 tempax = tempax >> 2;
4792 tempax++;
4793 tempax += tempbx;
4794 push1 = tempax; /* push ax */
4796 if ((pVBInfo->TVInfo & SetPALTV)) {
4797 if (tempbx <= 513) {
4798 if (tempax >= 513)
4799 tempbx = 513;
4803 temp = tempbx & 0x00FF;
4804 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
4805 tempbx--;
4806 temp = tempbx & 0x00FF;
4807 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4809 if (tempbx & 0x0100)
4810 tempcx |= 0x0008;
4812 if (tempbx & 0x0200)
4813 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
4815 tempbx++;
4817 if (tempbx & 0x0100)
4818 tempcx |= 0x0004;
4820 if (tempbx & 0x0200)
4821 tempcx |= 0x0080;
4823 if (tempbx & 0x0400)
4824 tempcx |= 0x0C00;
4826 tempbx = push1; /* pop ax */
4827 temp = tempbx & 0x00FF;
4828 temp &= 0x0F;
4829 /* 0x0D vertical Retrace End */
4830 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
4832 if (tempbx & 0x0010)
4833 tempcx |= 0x2000;
4835 temp = tempcx & 0x00FF;
4836 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
4837 temp = (tempcx & 0x0FF00) >> 8;
4838 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
4839 tempax = modeflag;
4840 temp = (tempax & 0xFF00) >> 8;
4842 temp = (temp >> 1) & 0x09;
4844 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4845 temp |= 0x01;
4847 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4848 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4849 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
4851 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4852 temp = 0x80;
4853 else
4854 temp = 0x00;
4856 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
4858 return;
4861 static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
4862 unsigned short RefreshRateTableIndex,
4863 struct xgi_hw_device_info *HwDeviceExtension,
4864 struct vb_device_info *pVBInfo)
4866 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4867 modeflag, resinfo, crt2crtc;
4868 unsigned char *TimingPoint;
4870 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4872 if (ModeNo <= 0x13) {
4873 /* si+St_ResInfo */
4874 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4875 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4876 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4877 } else {
4878 /* si+Ext_ResInfo */
4879 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4880 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4881 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
4882 Ext_CRT2CRTC;
4885 tempax = 0;
4887 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4888 tempax |= 0x0800;
4890 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4891 tempax |= 0x0400;
4893 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4894 tempax |= 0x0200;
4896 if (!(pVBInfo->TVInfo & SetPALTV))
4897 tempax |= 0x1000;
4899 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4900 tempax |= 0x0100;
4902 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
4903 tempax &= 0xfe00;
4905 tempax = (tempax & 0xff00) >> 8;
4907 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
4908 TimingPoint = pVBInfo->NTSCTiming;
4910 if (pVBInfo->TVInfo & SetPALTV)
4911 TimingPoint = pVBInfo->PALTiming;
4913 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4914 TimingPoint = pVBInfo->HiTVExtTiming;
4916 if (pVBInfo->VBInfo & SetInSlaveMode)
4917 TimingPoint = pVBInfo->HiTVSt2Timing;
4919 if (pVBInfo->SetFlag & TVSimuMode)
4920 TimingPoint = pVBInfo->HiTVSt1Timing;
4922 if (!(modeflag & Charx8Dot))
4923 TimingPoint = pVBInfo->HiTVTextTiming;
4926 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4927 if (pVBInfo->TVInfo & SetYPbPrMode525i)
4928 TimingPoint = pVBInfo->YPbPr525iTiming;
4930 if (pVBInfo->TVInfo & SetYPbPrMode525p)
4931 TimingPoint = pVBInfo->YPbPr525pTiming;
4933 if (pVBInfo->TVInfo & SetYPbPrMode750p)
4934 TimingPoint = pVBInfo->YPbPr750pTiming;
4937 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
4938 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
4940 for (i = 0x39; i <= 0x45; i++, j++)
4941 /* di->temp2[j] */
4942 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
4944 if (pVBInfo->VBInfo & SetCRT2ToTV)
4945 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
4947 temp = pVBInfo->NewFlickerMode;
4948 temp &= 0x80;
4949 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
4951 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4952 tempax = 950;
4954 if (pVBInfo->TVInfo & SetPALTV)
4955 tempax = 520;
4956 else
4957 tempax = 440;
4959 if (pVBInfo->VDE <= tempax) {
4960 tempax -= pVBInfo->VDE;
4961 tempax = tempax >> 2;
4962 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4963 push1 = tempax;
4964 temp = (tempax & 0xFF00) >> 8;
4965 temp += (unsigned short) TimingPoint[0];
4967 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4968 | VB_XGI302LV | VB_XGI301C)) {
4969 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4970 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4971 | SetCRT2ToYPbPr)) {
4972 tempcx = pVBInfo->VGAHDE;
4973 if (tempcx >= 1024) {
4974 temp = 0x17; /* NTSC */
4975 if (pVBInfo->TVInfo & SetPALTV)
4976 temp = 0x19; /* PAL */
4981 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
4982 tempax = push1;
4983 temp = (tempax & 0xFF00) >> 8;
4984 temp += TimingPoint[1];
4986 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4987 | VB_XGI302LV | VB_XGI301C)) {
4988 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4989 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4990 | SetCRT2ToYPbPr))) {
4991 tempcx = pVBInfo->VGAHDE;
4992 if (tempcx >= 1024) {
4993 temp = 0x1D; /* NTSC */
4994 if (pVBInfo->TVInfo & SetPALTV)
4995 temp = 0x52; /* PAL */
4999 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
5002 /* 301b */
5003 tempcx = pVBInfo->HT;
5005 if (XGI_IsLCDDualLink(pVBInfo))
5006 tempcx = tempcx >> 1;
5008 tempcx -= 2;
5009 temp = tempcx & 0x00FF;
5010 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
5012 temp = (tempcx & 0xFF00) >> 8;
5013 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
5015 tempcx = pVBInfo->HT >> 1;
5016 push1 = tempcx; /* push cx */
5017 tempcx += 7;
5019 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5020 tempcx -= 4;
5022 temp = tempcx & 0x00FF;
5023 temp = temp << 4;
5024 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
5026 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5027 tempbx += tempcx;
5028 push2 = tempbx;
5029 temp = tempbx & 0x00FF;
5030 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
5031 temp = (tempbx & 0xFF00) >> 8;
5032 temp = temp << 4;
5033 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
5035 tempbx = push2;
5036 tempbx = tempbx + 8;
5037 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5038 tempbx = tempbx - 4;
5039 tempcx = tempbx;
5042 temp = (tempbx & 0x00FF) << 4;
5043 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
5045 j += 2;
5046 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
5047 temp = tempcx & 0x00FF;
5048 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
5049 temp = ((tempcx & 0xFF00) >> 8) << 4;
5050 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
5052 tempcx += 8;
5053 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5054 tempcx -= 4;
5056 temp = tempcx & 0xFF;
5057 temp = temp << 4;
5058 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
5060 tempcx = push1; /* pop cx */
5061 j += 2;
5062 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5063 tempcx -= temp;
5064 temp = tempcx & 0x00FF;
5065 temp = temp << 4;
5066 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
5068 tempcx -= 11;
5070 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
5071 tempax = XGI_GetVGAHT2(pVBInfo);
5072 tempcx = tempax - 1;
5074 temp = tempcx & 0x00FF;
5075 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
5077 tempbx = pVBInfo->VDE;
5079 if (pVBInfo->VGAVDE == 360)
5080 tempbx = 746;
5081 if (pVBInfo->VGAVDE == 375)
5082 tempbx = 746;
5083 if (pVBInfo->VGAVDE == 405)
5084 tempbx = 853;
5086 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5087 if (pVBInfo->VBType &
5088 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5089 if (!(pVBInfo->TVInfo &
5090 (SetYPbPrMode525p | SetYPbPrMode750p)))
5091 tempbx = tempbx >> 1;
5092 } else
5093 tempbx = tempbx >> 1;
5096 tempbx -= 2;
5097 temp = tempbx & 0x00FF;
5099 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5100 if (pVBInfo->VBType & VB_XGI301LV) {
5101 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5102 if (pVBInfo->VBInfo & SetInSlaveMode) {
5103 if (ModeNo == 0x2f)
5104 temp += 1;
5107 } else {
5108 if (pVBInfo->VBInfo & SetInSlaveMode) {
5109 if (ModeNo == 0x2f)
5110 temp += 1;
5115 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
5117 temp = (tempcx & 0xFF00) >> 8;
5118 temp |= ((tempbx & 0xFF00) >> 8) << 6;
5120 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5121 if (pVBInfo->VBType & VB_XGI301LV) {
5122 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5123 temp |= 0x10;
5125 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5126 temp |= 0x20;
5128 } else {
5129 temp |= 0x10;
5130 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5131 temp |= 0x20;
5135 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
5137 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5138 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5139 tempbx = pVBInfo->VDE;
5140 tempcx = tempbx - 2;
5142 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5143 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5144 | SetYPbPrMode750p)))
5145 tempbx = tempbx >> 1;
5148 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5149 temp = 0;
5150 if (tempcx & 0x0400)
5151 temp |= 0x20;
5153 if (tempbx & 0x0400)
5154 temp |= 0x40;
5156 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
5159 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
5160 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
5161 temp = (tempbx - 3) & 0x00FF;
5162 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
5165 tempbx = tempbx & 0x00FF;
5167 if (!(modeflag & HalfDCLK)) {
5168 tempcx = pVBInfo->VGAHDE;
5169 if (tempcx >= pVBInfo->HDE) {
5170 tempbx |= 0x2000;
5171 tempax &= 0x00FF;
5175 tempcx = 0x0101;
5177 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5178 if (pVBInfo->VGAHDE >= 1024) {
5179 tempcx = 0x1920;
5180 if (pVBInfo->VGAHDE >= 1280) {
5181 tempcx = 0x1420;
5182 tempbx = tempbx & 0xDFFF;
5187 if (!(tempbx & 0x2000)) {
5188 if (modeflag & HalfDCLK)
5189 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
5191 push1 = tempbx;
5192 tempeax = pVBInfo->VGAHDE;
5193 tempebx = (tempcx & 0xFF00) >> 8;
5194 longtemp = tempeax * tempebx;
5195 tempecx = tempcx & 0x00FF;
5196 longtemp = longtemp / tempecx;
5198 /* 301b */
5199 tempecx = 8 * 1024;
5201 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5202 | VB_XGI302LV | VB_XGI301C)) {
5203 tempecx = tempecx * 8;
5206 longtemp = longtemp * tempecx;
5207 tempecx = pVBInfo->HDE;
5208 temp2 = longtemp % tempecx;
5209 tempeax = longtemp / tempecx;
5210 if (temp2 != 0)
5211 tempeax += 1;
5213 tempax = (unsigned short) tempeax;
5215 /* 301b */
5216 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5217 | VB_XGI302LV | VB_XGI301C)) {
5218 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5220 /* end 301b */
5222 tempbx = push1;
5223 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5224 | (tempbx & 0x00FF));
5225 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5226 | (tempax & 0x00FF));
5227 temp = (tempax & 0xFF00) >> 8;
5228 } else {
5229 temp = (tempax & 0x00FF) >> 8;
5232 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
5233 temp = (tempbx & 0xFF00) >> 8;
5234 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
5235 temp = tempcx & 0x00FF;
5237 if (tempbx & 0x2000)
5238 temp = 0;
5240 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5241 temp |= 0x18;
5243 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
5244 if (pVBInfo->TVInfo & SetPALTV) {
5245 tempbx = 0x0382;
5246 tempcx = 0x007e;
5247 } else {
5248 tempbx = 0x0369;
5249 tempcx = 0x0061;
5252 temp = tempbx & 0x00FF;
5253 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
5254 temp = tempcx & 0x00FF;
5255 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
5257 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5258 temp = temp << 2;
5259 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
5261 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5262 temp |= 0x10;
5264 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5265 temp |= 0x20;
5267 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5268 temp |= 0x60;
5271 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
5272 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
5273 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
5275 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5276 if (pVBInfo->TVInfo & NTSC1024x768) {
5277 TimingPoint = XGI_NTSC1024AdjTime;
5278 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
5279 xgifb_reg_set(pVBInfo->Part2Port, i,
5280 TimingPoint[j]);
5282 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
5286 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5287 if (pVBInfo->VBType & VB_XGI301C) {
5288 if (pVBInfo->TVInfo & SetPALMTV)
5289 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
5290 0x08); /* PALM Mode */
5293 if (pVBInfo->TVInfo & SetPALMTV) {
5294 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
5295 0x01);
5296 tempax--;
5297 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
5299 /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
5300 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
5303 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5304 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5305 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
5308 if (pVBInfo->VBInfo & SetCRT2ToTV)
5309 return;
5312 static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
5313 struct xgi_hw_device_info *HwDeviceExtension,
5314 unsigned short RefreshRateTableIndex,
5315 struct vb_device_info *pVBInfo)
5317 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5318 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
5320 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5322 if (ModeNo <= 0x13) {
5323 /* si+St_ResInfo */
5324 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5325 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5326 } else {
5327 /* si+Ext_ResInfo */
5328 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5329 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5330 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5331 Ext_CRT1CRTC;
5332 CRT1Index &= IndexMask;
5335 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5336 return;
5338 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
5340 if (XGI_IsLCDDualLink(pVBInfo))
5341 tempbx = tempbx >> 1;
5343 tempbx -= 1;
5344 temp = tempbx & 0x00FF;
5345 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
5346 temp = (tempbx & 0xFF00) >> 8;
5347 temp = temp << 4;
5348 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
5349 temp = 0x01;
5351 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5352 if (pVBInfo->ModeType == ModeEGA) {
5353 if (pVBInfo->VGAHDE >= 1024) {
5354 temp = 0x02;
5355 if (pVBInfo->LCDInfo & LCDVESATiming)
5356 temp = 0x01;
5361 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
5362 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5363 push1 = tempbx;
5364 tempbx--;
5365 temp = tempbx & 0x00FF;
5366 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
5367 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
5368 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
5370 tempcx = pVBInfo->VT - 1;
5371 push2 = tempcx + 1;
5372 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
5373 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
5374 temp = (tempcx & 0xFF00) >> 8;
5375 temp = temp << 5;
5376 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
5377 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5378 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5379 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5380 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
5382 /* Customized LCDB Des no add */
5383 tempbx = 5;
5384 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5385 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5386 tempah = pVBInfo->LCDResInfo;
5387 tempah &= PanelResInfo;
5389 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5390 tempbx = 1024;
5391 tempcx = 768;
5392 } else if ((tempah == Panel1280x1024) ||
5393 (tempah == Panel1280x1024x75)) {
5394 tempbx = 1280;
5395 tempcx = 1024;
5396 } else if (tempah == Panel1400x1050) {
5397 tempbx = 1400;
5398 tempcx = 1050;
5399 } else {
5400 tempbx = 1600;
5401 tempcx = 1200;
5404 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5405 tempbx = pVBInfo->HDE;
5406 tempcx = pVBInfo->VDE;
5409 pushbx = tempbx;
5410 tempax = pVBInfo->VT;
5411 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5412 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5413 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5414 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5415 tempbx = pVBInfo->LCDVDES;
5416 tempcx += tempbx;
5418 if (tempcx >= tempax)
5419 tempcx -= tempax; /* lcdvdes */
5421 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
5422 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
5423 temp = tempcx & 0x00FF;
5424 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
5425 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5426 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5427 tempah = tempch;
5428 tempah = tempah << 3;
5429 tempah |= tempbh;
5430 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
5432 /* getlcdsync() */
5433 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5434 tempcx = tempbx;
5435 tempax = pVBInfo->VT;
5436 tempbx = pVBInfo->LCDVRS;
5438 /* if (SetLCD_Info & EnableScalingLCD) */
5439 tempcx += tempbx;
5440 if (tempcx >= tempax)
5441 tempcx -= tempax;
5443 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
5444 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
5445 temp = (tempbx & 0xFF00) >> 8;
5446 temp = temp << 4;
5447 temp |= (tempcx & 0x000F);
5448 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
5449 tempcx = pushbx;
5450 tempax = pVBInfo->HT;
5451 tempbx = pVBInfo->LCDHDES;
5452 tempbx &= 0x0FFF;
5454 if (XGI_IsLCDDualLink(pVBInfo)) {
5455 tempax = tempax >> 1;
5456 tempbx = tempbx >> 1;
5457 tempcx = tempcx >> 1;
5460 if (pVBInfo->VBType & VB_XGI302LV)
5461 tempbx += 1;
5463 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5464 tempbx += 1;
5466 tempcx += tempbx;
5468 if (tempcx >= tempax)
5469 tempcx -= tempax;
5471 temp = tempbx & 0x00FF;
5472 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
5473 temp = ((tempbx & 0xFF00) >> 8) << 4;
5474 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
5475 temp = tempcx & 0x00FF;
5476 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
5477 temp = (tempcx & 0xFF00) >> 8;
5478 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
5480 /* getlcdsync() */
5481 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5482 tempcx = tempax;
5483 tempax = pVBInfo->HT;
5484 tempbx = pVBInfo->LCDHRS;
5485 /* if ( SetLCD_Info & EnableScalingLCD) */
5486 if (XGI_IsLCDDualLink(pVBInfo)) {
5487 tempax = tempax >> 1;
5488 tempbx = tempbx >> 1;
5489 tempcx = tempcx >> 1;
5492 if (pVBInfo->VBType & VB_XGI302LV)
5493 tempbx += 1;
5495 tempcx += tempbx;
5497 if (tempcx >= tempax)
5498 tempcx -= tempax;
5500 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
5501 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
5503 temp = (tempbx & 0xFF00) >> 8;
5504 temp = temp << 4;
5505 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
5506 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
5507 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
5509 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5510 if (pVBInfo->VGAVDE == 525) {
5511 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5512 | VB_XGI301LV | VB_XGI302LV
5513 | VB_XGI301C)) {
5514 temp = 0xC6;
5515 } else
5516 temp = 0xC4;
5518 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5519 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
5522 if (pVBInfo->VGAVDE == 420) {
5523 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5524 | VB_XGI301LV | VB_XGI302LV
5525 | VB_XGI301C)) {
5526 temp = 0x4F;
5527 } else
5528 temp = 0x4E;
5529 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5534 /* --------------------------------------------------------------------- */
5535 /* Function : XGI_GetTap4Ptr */
5536 /* Input : */
5537 /* Output : di -> Tap4 Reg. Setting Pointer */
5538 /* Description : */
5539 /* --------------------------------------------------------------------- */
5540 static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
5541 struct vb_device_info *pVBInfo)
5543 unsigned short tempax, tempbx, i;
5545 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5547 if (tempcx == 0) {
5548 tempax = pVBInfo->VGAHDE;
5549 tempbx = pVBInfo->HDE;
5550 } else {
5551 tempax = pVBInfo->VGAVDE;
5552 tempbx = pVBInfo->VDE;
5555 if (tempax <= tempbx)
5556 return &xgifb_tap4_timing[0];
5557 else
5558 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
5560 if (pVBInfo->TVInfo & SetPALTV)
5561 Tap4TimingPtr = PALTap4Timing;
5563 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5564 if ((pVBInfo->TVInfo & SetYPbPrMode525i) ||
5565 (pVBInfo->TVInfo & SetYPbPrMode525p))
5566 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
5567 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5568 Tap4TimingPtr = YPbPr750pTap4Timing;
5571 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5572 Tap4TimingPtr = xgifb_tap4_timing;
5574 i = 0;
5575 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5576 if (Tap4TimingPtr[i].DE == tempax)
5577 break;
5578 i++;
5580 return &Tap4TimingPtr[i];
5583 static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
5585 unsigned short i, j;
5587 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5589 if (!(pVBInfo->VBType & VB_XGI301C))
5590 return;
5592 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5593 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
5594 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
5596 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5597 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5598 /* Set Vertical Scaling */
5599 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
5600 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
5601 xgifb_reg_set(pVBInfo->Part2Port,
5603 Tap4TimingPtr->Reg[j]);
5606 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5607 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5608 /* Enable V.Scaling */
5609 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
5610 else
5611 /* Enable H.Scaling */
5612 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
5615 static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
5616 struct vb_device_info *pVBInfo)
5618 unsigned short i;
5619 unsigned char *tempdi;
5620 unsigned short modeflag;
5622 if (ModeNo <= 0x13)
5623 /* si+St_ResInfo */
5624 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5625 else
5626 /* si+Ext_ResInfo */
5627 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5629 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
5630 if (pVBInfo->TVInfo & SetPALTV) {
5631 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5632 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5633 } else {
5634 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5635 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
5638 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5639 return;
5641 if (pVBInfo->TVInfo & SetPALMTV) {
5642 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5643 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5644 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
5647 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5648 & SetCRT2ToYPbPr)) {
5649 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5650 return;
5652 tempdi = pVBInfo->HiTVGroup3Data;
5653 if (pVBInfo->SetFlag & TVSimuMode) {
5654 tempdi = pVBInfo->HiTVGroup3Simu;
5655 if (!(modeflag & Charx8Dot))
5656 tempdi = pVBInfo->HiTVGroup3Text;
5659 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5660 tempdi = pVBInfo->Ren525pGroup3;
5662 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5663 tempdi = pVBInfo->Ren750pGroup3;
5665 for (i = 0; i <= 0x3E; i++)
5666 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
5668 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5669 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5670 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
5673 return;
5674 } /* {end of XGI_SetGroup3} */
5676 static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
5677 unsigned short RefreshRateTableIndex,
5678 struct xgi_hw_device_info *HwDeviceExtension,
5679 struct vb_device_info *pVBInfo)
5681 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
5683 unsigned long tempebx, tempeax, templong;
5685 if (ModeNo <= 0x13)
5686 /* si+St_ResInfo */
5687 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5688 else
5689 /* si+Ext_ResInfo */
5690 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5692 temp = pVBInfo->RVBHCFACT;
5693 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
5695 tempbx = pVBInfo->RVBHCMAX;
5696 temp = tempbx & 0x00FF;
5697 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
5698 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5699 tempcx = pVBInfo->VGAHT - 1;
5700 temp = tempcx & 0x00FF;
5701 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
5703 temp = ((tempcx & 0xFF00) >> 8) << 3;
5704 temp2 |= temp;
5706 tempcx = pVBInfo->VGAVT - 1;
5707 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5708 tempcx -= 5;
5710 temp = tempcx & 0x00FF;
5711 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
5712 temp = temp2 | ((tempcx & 0xFF00) >> 8);
5713 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
5714 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
5715 tempcx = pVBInfo->VBInfo;
5716 tempbx = pVBInfo->VGAHDE;
5718 if (modeflag & HalfDCLK)
5719 tempbx = tempbx >> 1;
5721 if (XGI_IsLCDDualLink(pVBInfo))
5722 tempbx = tempbx >> 1;
5724 if (tempcx & SetCRT2ToHiVisionTV) {
5725 temp = 0;
5726 if (tempbx <= 1024)
5727 temp = 0xA0;
5728 if (tempbx == 1280)
5729 temp = 0xC0;
5730 } else if (tempcx & SetCRT2ToTV) {
5731 temp = 0xA0;
5732 if (tempbx <= 800)
5733 temp = 0x80;
5734 } else {
5735 temp = 0x80;
5736 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5737 temp = 0;
5738 if (tempbx > 800)
5739 temp = 0x60;
5743 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
5744 temp = 0x00;
5745 if (pVBInfo->VGAHDE == 1280)
5746 temp = 0x40;
5747 if (pVBInfo->VGAHDE == 1024)
5748 temp = 0x20;
5750 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
5752 tempebx = pVBInfo->VDE;
5754 if (tempcx & SetCRT2ToHiVisionTV) {
5755 if (!(temp & 0xE000))
5756 tempbx = tempbx >> 1;
5759 tempcx = pVBInfo->RVBHRS;
5760 temp = tempcx & 0x00FF;
5761 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
5763 tempeax = pVBInfo->VGAVDE;
5764 tempcx |= 0x04000;
5766 if (tempeax <= tempebx) {
5767 tempcx = (tempcx & (~0x4000));
5768 tempeax = pVBInfo->VGAVDE;
5769 } else {
5770 tempeax -= tempebx;
5773 templong = (tempeax * 256 * 1024) % tempebx;
5774 tempeax = (tempeax * 256 * 1024) / tempebx;
5775 tempebx = tempeax;
5777 if (templong != 0)
5778 tempebx++;
5780 temp = (unsigned short) (tempebx & 0x000000FF);
5781 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
5783 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
5784 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
5785 tempbx = (unsigned short) (tempebx >> 16);
5786 temp = tempbx & 0x00FF;
5787 temp = temp << 4;
5788 temp |= ((tempcx & 0xFF00) >> 8);
5789 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
5791 /* 301b */
5792 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5793 | VB_XGI302LV | VB_XGI301C)) {
5794 temp = 0x0028;
5795 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
5796 tempax = pVBInfo->VGAHDE;
5797 if (modeflag & HalfDCLK)
5798 tempax = tempax >> 1;
5800 if (XGI_IsLCDDualLink(pVBInfo))
5801 tempax = tempax >> 1;
5803 /* if((pVBInfo->VBInfo&(SetCRT2ToLCD)) ||
5804 ((pVBInfo->TVInfo&SetYPbPrMode525p) ||
5805 (pVBInfo->TVInfo&SetYPbPrMode750p))) { */
5806 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5807 if (tempax > 800)
5808 tempax -= 800;
5809 } else {
5810 if (pVBInfo->VGAHDE > 800) {
5811 if (pVBInfo->VGAHDE == 1024)
5812 tempax = (tempax * 25 / 32) - 1;
5813 else
5814 tempax = (tempax * 20 / 32) - 1;
5817 tempax -= 1;
5820 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5821 if (pVBInfo->VBType & VB_XGI301LV) {
5822 if (!(pVBInfo->TVInfo &
5823 (SetYPbPrMode525p |
5824 SetYPbPrMode750p |
5825 SetYPbPrMode1080i))) {
5826 if (pVBInfo->VGAHDE > 800) {
5827 if (pVBInfo->VGAHDE == 1024)
5828 tempax =(tempax * 25 /
5829 32) - 1;
5830 else
5831 tempax = (tempax * 20 /
5832 32) - 1;
5835 } else {
5836 if (pVBInfo->VGAHDE > 800) {
5837 if (pVBInfo->VGAHDE == 1024)
5838 tempax = (tempax * 25 / 32) - 1;
5839 else
5840 tempax = (tempax * 20 / 32) - 1;
5846 temp = (tempax & 0xFF00) >> 8;
5847 temp = ((temp & 0x0003) << 4);
5848 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
5849 temp = (tempax & 0x00FF);
5850 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
5852 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5853 if (pVBInfo->VGAHDE > 800)
5854 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
5857 temp = 0x0036;
5859 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5860 if (!(pVBInfo->TVInfo & (NTSC1024x768
5861 | SetYPbPrMode525p | SetYPbPrMode750p
5862 | SetYPbPrMode1080i))) {
5863 temp |= 0x0001;
5864 if ((pVBInfo->VBInfo & SetInSlaveMode)
5865 && (!(pVBInfo->TVInfo
5866 & TVSimuMode)))
5867 temp &= (~0x0001);
5871 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
5872 tempbx = pVBInfo->HT;
5873 if (XGI_IsLCDDualLink(pVBInfo))
5874 tempbx = tempbx >> 1;
5875 tempbx = (tempbx >> 1) - 2;
5876 temp = ((tempbx & 0x0700) >> 8) << 3;
5877 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
5878 temp = tempbx & 0x00FF;
5879 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
5881 /* end 301b */
5883 if (pVBInfo->ISXPDOS == 0)
5884 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5885 pVBInfo);
5888 static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5890 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
5893 static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
5894 struct vb_device_info *pVBInfo)
5896 unsigned short Pindex, Pdata;
5898 Pindex = pVBInfo->Part5Port;
5899 Pdata = pVBInfo->Part5Port + 1;
5900 if (pVBInfo->ModeType == ModeVGA) {
5901 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
5902 | CRT2DisplayFlag))) {
5903 XGINew_EnableCRT2(pVBInfo);
5904 /* LoadDAC2(pVBInfo->Part5Port, ModeNo, ModeIdIndex); */
5907 return;
5910 static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
5911 struct vb_device_info *pVBInfo)
5913 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
5916 static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
5917 struct vb_device_info *pVBInfo)
5920 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
5923 /*----------------------------------------------------------------------------*/
5924 /* input */
5925 /* bl[5] : 1;LVDS signal on */
5926 /* bl[1] : 1;LVDS backlight on */
5927 /* bl[0] : 1:LVDS VDD on */
5928 /* bh: 100000b : clear bit 5, to set bit5 */
5929 /* 000010b : clear bit 1, to set bit1 */
5930 /* 000001b : clear bit 0, to set bit0 */
5931 /*----------------------------------------------------------------------------*/
5932 void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
5933 struct vb_device_info *pVBInfo)
5935 unsigned char CR4A, temp;
5937 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
5938 tempbh &= 0x23;
5939 tempbl &= 0x23;
5940 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
5942 if (tempbh & 0x20) {
5943 temp = (tempbl >> 4) & 0x02;
5945 /* CR B4[1] */
5946 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
5950 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
5952 temp = XG21GPIODataTransfer(temp);
5953 temp &= ~tempbh;
5954 temp |= tempbl;
5955 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
5958 void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
5959 struct vb_device_info *pVBInfo)
5961 unsigned char CR4A, temp;
5962 unsigned short tempbh0, tempbl0;
5964 tempbh0 = tempbh;
5965 tempbl0 = tempbl;
5966 tempbh0 &= 0x20;
5967 tempbl0 &= 0x20;
5968 tempbh0 >>= 3;
5969 tempbl0 >>= 3;
5971 if (tempbh & 0x20) {
5972 temp = (tempbl >> 4) & 0x02;
5974 /* CR B4[1] */
5975 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
5978 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
5980 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
5981 tempbh &= 0x03;
5982 tempbl &= 0x03;
5983 tempbh <<= 2;
5984 tempbl <<= 2; /* GPIOC,GPIOD */
5985 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
5986 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
5989 /* --------------------------------------------------------------------- */
5990 unsigned short XGI_GetLVDSOEMTableIndex(struct vb_device_info *pVBInfo)
5992 unsigned short index;
5994 index = xgifb_reg_get(pVBInfo->P3d4, 0x36);
5995 if (index < sizeof(XGI21_LCDCapList)
5996 / sizeof(struct XGI21_LVDSCapStruct))
5997 return index;
5998 return 0;
6001 /* --------------------------------------------------------------------- */
6002 /* Function : XGI_XG21SetPanelDelay */
6003 /* Input : */
6004 /* Output : */
6005 /* Description : */
6006 /* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
6007 /* : bl : 2 ; T2 : the duration signal on and Vdd on */
6008 /* : bl : 3 ; T3 : the duration between CPL off and signal off */
6009 /* : bl : 4 ; T4 : the duration signal off and Vdd off */
6010 /* --------------------------------------------------------------------- */
6011 void XGI_XG21SetPanelDelay(unsigned short tempbl,
6012 struct vb_device_info *pVBInfo)
6014 unsigned short index;
6016 index = XGI_GetLVDSOEMTableIndex(pVBInfo);
6017 if (tempbl == 1)
6018 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S1);
6020 if (tempbl == 2)
6021 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S2);
6023 if (tempbl == 3)
6024 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S3);
6026 if (tempbl == 4)
6027 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S4);
6030 unsigned char XGI_XG21CheckLVDSMode(unsigned short ModeNo,
6031 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
6033 unsigned short xres, yres, colordepth, modeflag, resindex,
6034 lvdstableindex;
6036 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6037 if (ModeNo <= 0x13) {
6038 xres = pVBInfo->StResInfo[resindex].HTotal;
6039 yres = pVBInfo->StResInfo[resindex].VTotal;
6040 /* si+St_ResInfo */
6041 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
6042 } else {
6043 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6044 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
6045 /* si+St_ModeFlag */
6046 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6049 if (!(modeflag & Charx8Dot)) {
6050 xres /= 9;
6051 xres *= 8;
6054 if (ModeNo > 0x13) {
6055 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
6056 xres *= 2;
6058 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6059 yres *= 2;
6063 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6064 if (xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE))
6065 return 0;
6067 if (yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE))
6068 return 0;
6070 if (ModeNo > 0x13) {
6071 if ((xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6072 LVDSHDE)) ||
6073 (yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6074 LVDSVDE))) {
6075 colordepth = XGI_GetColorDepth(ModeNo,
6076 ModeIdIndex,
6077 pVBInfo);
6078 if (colordepth > 2)
6079 return 0;
6083 return 1;
6086 void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
6088 unsigned char temp;
6090 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
6091 temp = (temp & 1) << 6;
6092 /* SR06[6] 18bit Dither */
6093 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
6094 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
6095 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
6099 void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
6101 unsigned char temp;
6103 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
6104 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
6105 temp = (temp & 3) << 6;
6106 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
6107 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
6108 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
6109 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
6113 static void xgifb_set_lvds(int chip_id,
6114 unsigned short ModeNo,
6115 unsigned short ModeIdIndex,
6116 struct vb_device_info *pVBInfo)
6118 unsigned char temp, Miscdata;
6119 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6120 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6121 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6122 unsigned short value;
6124 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6125 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6126 LVDS_Capability &
6127 (LCDPolarity << 8)) >> 8);
6128 temp &= LCDPolarity;
6129 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
6131 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
6133 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6134 LVDS_Capability & LCDPolarity);
6135 /* SR35[7] FP VSync polarity */
6136 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6137 /* SR30[5] FP HSync polarity */
6138 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
6140 if (chip_id == XG27)
6141 XGI_SetXG27FPBits(pVBInfo);
6142 else
6143 XGI_SetXG21FPBits(pVBInfo);
6145 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6146 if (ModeNo <= 0x13) {
6147 xres = pVBInfo->StResInfo[resindex].HTotal;
6148 yres = pVBInfo->StResInfo[resindex].VTotal;
6149 /* si+St_ResInfo */
6150 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
6151 } else {
6152 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6153 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
6154 /* si+St_ModeFlag */
6155 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6158 if (!(modeflag & Charx8Dot))
6159 xres = xres * 8 / 9;
6161 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
6163 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6164 - xres) / 2;
6165 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6166 LVDSHBS -= xres / 4;
6168 if (LVDSHBS > LVDSHT)
6169 LVDSHBS -= LVDSHT;
6171 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6172 if (LVDSHRS > LVDSHT)
6173 LVDSHRS -= LVDSHT;
6175 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6176 if (LVDSHRE > LVDSHT)
6177 LVDSHRE -= LVDSHT;
6179 LVDSHBE = LVDSHBS + LVDSHT
6180 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
6182 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
6184 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6185 - yres) / 2;
6186 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6187 LVDSVBS += yres / 2;
6189 if (LVDSVBS > LVDSVT)
6190 LVDSVBS -= LVDSVT;
6192 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6193 if (LVDSVRS > LVDSVT)
6194 LVDSVRS -= LVDSVT;
6196 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].
6197 LVDSVSYNC;
6198 if (LVDSVRE > LVDSVT)
6199 LVDSVRE -= LVDSVT;
6201 LVDSVBE = LVDSVBS + LVDSVT
6202 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
6204 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
6205 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
6207 if (!(modeflag & Charx8Dot))
6208 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
6210 /* HT SR0B[1:0] CR00 */
6211 value = (LVDSHT >> 3) - 5;
6212 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
6213 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
6215 /* HBS SR0B[5:4] CR02 */
6216 value = (LVDSHBS >> 3) - 1;
6217 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
6218 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
6220 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6221 value = (LVDSHBE >> 3) - 1;
6222 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6223 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6224 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
6226 /* HRS SR0B[7:6] CR04 */
6227 value = (LVDSHRS >> 3) + 2;
6228 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
6229 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
6231 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6232 value--;
6233 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
6234 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
6236 /* HRE SR0C[2] CR05[4:0] */
6237 value = (LVDSHRE >> 3) + 2;
6238 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6239 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
6241 /* Panel HRE SR2F[7:2] */
6242 value--;
6243 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
6245 /* VT SR0A[0] CR07[5][0] CR06 */
6246 value = LVDSVT - 2;
6247 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6248 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6249 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
6250 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
6252 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6253 value = LVDSVBS - 1;
6254 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6255 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6256 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
6257 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
6259 /* VBE SR0A[4] CR16 */
6260 value = LVDSVBE - 1;
6261 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
6262 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
6264 /* VRS SR0A[3] CR7[7][2] CR10 */
6265 value = LVDSVRS - 1;
6266 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6267 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6268 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
6269 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
6271 if (chip_id == XG27) {
6272 /* Panel VRS SR35[2:0] SR34[7:0] */
6273 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
6274 (value & 0x700) >> 8);
6275 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
6276 } else {
6277 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
6278 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
6279 (value & 0x600) >> 9);
6280 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
6281 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
6284 /* VRE SR0A[5] CR11[3:0] */
6285 value = LVDSVRE - 1;
6286 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6287 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
6289 /* Panel VRE SR3F[7:2] */
6290 if (chip_id == XG27)
6291 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6292 (value << 2) & 0xFC);
6293 else
6294 /* SR3F[7] has to be 0, h/w bug */
6295 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6296 (value << 2) & 0x7C);
6298 for (temp = 0, value = 0; temp < 3; temp++) {
6300 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
6301 xgifb_reg_set(pVBInfo->P3c4,
6302 0x2B,
6303 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6304 VCLKData1);
6305 xgifb_reg_set(pVBInfo->P3c4,
6306 0x2C,
6307 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6308 VCLKData2);
6309 value += 0x10;
6312 if (!(modeflag & Charx8Dot)) {
6313 inb(pVBInfo->P3da); /* reset 3da */
6314 outb(0x13, pVBInfo->P3c0); /* set index */
6315 /* set data, panning = 0, shift left 1 dot*/
6316 outb(0x00, pVBInfo->P3c0);
6318 inb(pVBInfo->P3da); /* Enable Attribute */
6319 outb(0x20, pVBInfo->P3c0);
6321 inb(pVBInfo->P3da); /* reset 3da */
6326 /* --------------------------------------------------------------------- */
6327 /* Function : XGI_IsLCDON */
6328 /* Input : */
6329 /* Output : 0 : Skip PSC Control */
6330 /* 1: Disable PSC */
6331 /* Description : */
6332 /* --------------------------------------------------------------------- */
6333 static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
6335 unsigned short tempax;
6337 tempax = pVBInfo->VBInfo;
6338 if (tempax & SetCRT2ToDualEdge)
6339 return 0;
6340 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6341 return 1;
6343 return 0;
6346 /* --------------------------------------------------------------------- */
6347 /* Function : XGI_DisableChISLCD */
6348 /* Input : */
6349 /* Output : 0 -> Not LCD Mode */
6350 /* Description : */
6351 /* --------------------------------------------------------------------- */
6352 static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
6354 unsigned short tempbx, tempah;
6356 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
6357 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
6359 if (tempbx & (EnableChA | DisableChA)) {
6360 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6361 return 0;
6364 if (!(tempbx & (EnableChB | DisableChB)))
6365 return 0;
6367 if (tempah & 0x01) /* Chk LCDB Mode */
6368 return 1;
6370 return 0;
6373 /* --------------------------------------------------------------------- */
6374 /* Function : XGI_EnableChISLCD */
6375 /* Input : */
6376 /* Output : 0 -> Not LCD mode */
6377 /* Description : */
6378 /* --------------------------------------------------------------------- */
6379 static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
6381 unsigned short tempbx, tempah;
6383 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
6384 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
6386 if (tempbx & (EnableChA | DisableChA)) {
6387 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6388 return 0;
6391 if (!(tempbx & (EnableChB | DisableChB)))
6392 return 0;
6394 if (tempah & 0x01) /* Chk LCDB Mode */
6395 return 1;
6397 return 0;
6400 void XGI_DisableBridge(struct xgi_hw_device_info *HwDeviceExtension,
6401 struct vb_device_info *pVBInfo)
6403 unsigned short tempah = 0;
6405 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6406 | VB_XGI302LV | VB_XGI301C)) {
6407 tempah = 0x3F;
6408 if (!(pVBInfo->VBInfo &
6409 (DisableCRT2Display | SetSimuScanMode))) {
6410 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6411 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6412 tempah = 0x7F; /* Disable Channel A */
6413 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6414 /* Disable Channel B */
6415 tempah = 0xBF;
6417 if (pVBInfo->SetFlag & DisableChB)
6418 /* force to disable Cahnnel */
6419 tempah &= 0xBF;
6421 if (pVBInfo->SetFlag & DisableChA)
6422 /* Force to disable Channel B */
6423 tempah &= 0x7F;
6428 /* disable part4_1f */
6429 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
6431 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6432 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6433 || (XGI_DisableChISLCD(pVBInfo))
6434 || (XGI_IsLCDON(pVBInfo)))
6435 /* LVDS Driver power down */
6436 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
6439 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6440 & (DisableCRT2Display | SetCRT2ToLCDA
6441 | SetSimuScanMode))) {
6442 if (pVBInfo->SetFlag & GatingCRT)
6443 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6444 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6447 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6448 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6449 & SetCRT2ToLCDA))
6450 /* Power down */
6451 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
6454 /* disable TV as primary VGA swap */
6455 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
6457 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
6458 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
6460 if ((pVBInfo->SetFlag & DisableChB) ||
6461 (pVBInfo->VBInfo &
6462 (DisableCRT2Display | SetSimuScanMode)) ||
6463 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6464 (pVBInfo->VBInfo &
6465 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6466 /* BScreenOff=1 */
6467 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6469 if ((pVBInfo->SetFlag & DisableChB) ||
6470 (pVBInfo->VBInfo &
6471 (DisableCRT2Display | SetSimuScanMode)) ||
6472 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6473 (pVBInfo->VBInfo &
6474 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6475 /* save Part1 index 0 */
6476 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6477 /* BTDAC = 1, avoid VB reset */
6478 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6479 /* disable CRT2 */
6480 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6481 /* restore Part1 index 0 */
6482 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
6484 } else { /* {301} */
6485 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
6486 /* BScreenOff=1 */
6487 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6488 /* Disable CRT2 */
6489 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6490 /* Disable TV asPrimary VGA swap */
6491 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
6494 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6495 | SetSimuScanMode))
6496 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6500 /* --------------------------------------------------------------------- */
6501 /* Function : XGI_GetTVPtrIndex */
6502 /* Input : */
6503 /* Output : */
6504 /* Description : bx 0 : ExtNTSC */
6505 /* 1 : StNTSC */
6506 /* 2 : ExtPAL */
6507 /* 3 : StPAL */
6508 /* 4 : ExtHiTV */
6509 /* 5 : StHiTV */
6510 /* 6 : Ext525i */
6511 /* 7 : St525i */
6512 /* 8 : Ext525p */
6513 /* 9 : St525p */
6514 /* A : Ext750p */
6515 /* B : St750p */
6516 /* --------------------------------------------------------------------- */
6517 static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
6519 unsigned short tempbx = 0;
6521 if (pVBInfo->TVInfo & SetPALTV)
6522 tempbx = 2;
6523 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
6524 tempbx = 4;
6525 if (pVBInfo->TVInfo & SetYPbPrMode525i)
6526 tempbx = 6;
6527 if (pVBInfo->TVInfo & SetYPbPrMode525p)
6528 tempbx = 8;
6529 if (pVBInfo->TVInfo & SetYPbPrMode750p)
6530 tempbx = 10;
6531 if (pVBInfo->TVInfo & TVSimuMode)
6532 tempbx++;
6534 return tempbx;
6537 /* --------------------------------------------------------------------- */
6538 /* Function : XGI_GetTVPtrIndex2 */
6539 /* Input : */
6540 /* Output : bx 0 : NTSC */
6541 /* 1 : PAL */
6542 /* 2 : PALM */
6543 /* 3 : PALN */
6544 /* 4 : NTSC1024x768 */
6545 /* 5 : PAL-M 1024x768 */
6546 /* 6-7: reserved */
6547 /* cl 0 : YFilter1 */
6548 /* 1 : YFilter2 */
6549 /* ch 0 : 301A */
6550 /* 1 : 301B/302B/301LV/302LV */
6551 /* Description : */
6552 /* --------------------------------------------------------------------- */
6553 static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
6554 unsigned char *tempch, struct vb_device_info *pVBInfo)
6556 *tempbx = 0;
6557 *tempcl = 0;
6558 *tempch = 0;
6560 if (pVBInfo->TVInfo & SetPALTV)
6561 *tempbx = 1;
6563 if (pVBInfo->TVInfo & SetPALMTV)
6564 *tempbx = 2;
6566 if (pVBInfo->TVInfo & SetPALNTV)
6567 *tempbx = 3;
6569 if (pVBInfo->TVInfo & NTSC1024x768) {
6570 *tempbx = 4;
6571 if (pVBInfo->TVInfo & SetPALMTV)
6572 *tempbx = 5;
6575 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6576 | VB_XGI302LV | VB_XGI301C)) {
6577 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
6578 & TVSimuMode)) {
6579 *tempbx += 8;
6580 *tempcl += 1;
6584 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6585 | VB_XGI302LV | VB_XGI301C))
6586 (*tempch)++;
6589 static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
6591 unsigned short index;
6593 unsigned char tempah, tempbl, tempbh;
6595 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6596 | VB_XGI302LV | VB_XGI301C)) {
6597 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
6598 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
6599 tempbl = 0;
6600 tempbh = 0;
6602 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
6603 tempbl = pVBInfo->XGI_TVDelayList[index];
6605 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6606 | VB_XGI301LV | VB_XGI302LV
6607 | VB_XGI301C))
6608 tempbl = pVBInfo->XGI_TVDelayList2[index];
6610 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6611 tempbl = tempbl >> 4;
6613 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
6614 tempbl = CRT2Delay1; // Get CRT2 Delay
6615 if (pVBInfo->VBType &
6616 (VB_XGI301B |
6617 VB_XGI302B |
6618 VB_XGI301LV |
6619 VB_XGI302LV |
6620 VB_XGI301C))
6621 tempbl = CRT2Delay2;
6623 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
6624 /* Get LCD Delay */
6625 index = XGI_GetLCDCapPtr(pVBInfo);
6626 tempbh = pVBInfo->LCDCapList[index].
6627 LCD_DelayCompensation;
6629 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6630 tempbl = tempbh;
6633 tempbl &= 0x0F;
6634 tempbh &= 0xF0;
6635 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
6637 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
6638 | SetCRT2ToTV)) { /* Channel B */
6639 tempah &= 0xF0;
6640 tempah |= tempbl;
6643 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
6644 tempah &= 0x0F;
6645 tempah |= tempbh;
6647 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
6649 } else if (pVBInfo->IF_DEF_LVDS == 1) {
6650 tempbl = 0;
6651 tempbh = 0;
6652 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
6653 /* / Get LCD Delay */
6654 tempah = pVBInfo->LCDCapList[
6655 XGI_GetLCDCapPtr(pVBInfo)].
6656 LCD_DelayCompensation;
6657 tempah &= 0x0f;
6658 tempah = tempah << 4;
6659 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
6660 tempah);
6665 static void XGI_SetLCDCap_A(unsigned short tempcx,
6666 struct vb_device_info *pVBInfo)
6668 unsigned short temp;
6670 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
6672 if (temp & LCDRGB18Bit) {
6673 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
6674 /* Enable Dither */
6675 (unsigned short) (0x20 | (tempcx & 0x00C0)));
6676 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
6677 } else {
6678 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
6679 (unsigned short) (0x30 | (tempcx & 0x00C0)));
6680 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
6684 if (tempcx & EnableLCD24bpp) { // 24bits
6685 xgifb_reg_and_or(pVBInfo->Part1Port,
6686 0x19,
6687 0x0F,
6688 (unsigned short)(0x30 | (tempcx&0x00C0)));
6689 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
6690 } else {
6691 xgifb_reg_and_or(pVBInfo->Part1Port,
6692 0x19,
6693 0x0F,
6694 // Enable Dither
6695 (unsigned short)(0x20 | (tempcx&0x00C0)));
6696 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
6701 /* --------------------------------------------------------------------- */
6702 /* Function : XGI_SetLCDCap_B */
6703 /* Input : cx -> LCD Capability */
6704 /* Output : */
6705 /* Description : */
6706 /* --------------------------------------------------------------------- */
6707 static void XGI_SetLCDCap_B(unsigned short tempcx,
6708 struct vb_device_info *pVBInfo)
6710 if (tempcx & EnableLCD24bpp) /* 24bits */
6711 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
6712 (unsigned short) (((tempcx & 0x00ff) >> 6)
6713 | 0x0c));
6714 else
6715 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
6716 (unsigned short) (((tempcx & 0x00ff) >> 6)
6717 | 0x18)); /* Enable Dither */
6720 static void SetSpectrum(struct vb_device_info *pVBInfo)
6722 unsigned short index;
6724 index = XGI_GetLCDCapPtr(pVBInfo);
6726 /* disable down spectrum D[4] */
6727 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
6728 XGI_LongWait(pVBInfo);
6729 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
6730 XGI_LongWait(pVBInfo);
6732 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
6733 pVBInfo->LCDCapList[index].Spectrum_31);
6734 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
6735 pVBInfo->LCDCapList[index].Spectrum_32);
6736 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
6737 pVBInfo->LCDCapList[index].Spectrum_33);
6738 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
6739 pVBInfo->LCDCapList[index].Spectrum_34);
6740 XGI_LongWait(pVBInfo);
6741 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
6744 static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
6746 unsigned short tempcx;
6748 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
6750 if (pVBInfo->VBType &
6751 (VB_XGI301B |
6752 VB_XGI302B |
6753 VB_XGI301LV |
6754 VB_XGI302LV |
6755 VB_XGI301C)) { /* 301LV/302LV only */
6756 if (pVBInfo->VBType &
6757 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
6758 /* Set 301LV Capability */
6759 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
6760 (unsigned char) (tempcx & 0x1F));
6762 /* VB Driving */
6763 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
6764 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6765 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6766 | EnablePLLSPLOW)) >> 8));
6769 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6770 | VB_XGI302LV | VB_XGI301C)) {
6771 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6772 XGI_SetLCDCap_B(tempcx, pVBInfo);
6773 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6774 XGI_SetLCDCap_A(tempcx, pVBInfo);
6776 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6777 if (tempcx & EnableSpectrum)
6778 SetSpectrum(pVBInfo);
6780 } else {
6781 /* LVDS,CH7017 */
6782 XGI_SetLCDCap_A(tempcx, pVBInfo);
6786 /* --------------------------------------------------------------------- */
6787 /* Function : XGI_SetAntiFlicker */
6788 /* Input : */
6789 /* Output : */
6790 /* Description : Set TV Customized Param. */
6791 /* --------------------------------------------------------------------- */
6792 static void XGI_SetAntiFlicker(unsigned short ModeNo,
6793 unsigned short ModeIdIndex,
6794 struct vb_device_info *pVBInfo)
6796 unsigned short tempbx, index;
6798 unsigned char tempah;
6800 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
6801 return;
6803 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6804 tempbx &= 0xFE;
6806 if (ModeNo <= 0x13)
6807 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6808 else
6809 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
6811 tempbx += index;
6812 tempah = TVAntiFlickList[tempbx];
6813 tempah = tempah << 4;
6815 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
6818 static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6819 unsigned short ModeIdIndex,
6820 struct vb_device_info *pVBInfo)
6822 unsigned short tempbx, index;
6824 unsigned char tempah;
6826 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6827 tempbx &= 0xFE;
6829 if (ModeNo <= 0x13)
6830 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6831 else
6832 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
6834 tempbx += index;
6835 tempah = TVEdgeList[tempbx];
6836 tempah = tempah << 5;
6838 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
6841 static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
6843 unsigned short tempbx;
6845 unsigned char tempcl, tempch;
6847 unsigned long tempData;
6849 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6850 tempData = TVPhaseList[tempbx];
6852 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
6853 & 0x000000FF));
6854 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
6855 & 0x0000FF00) >> 8));
6856 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
6857 & 0x00FF0000) >> 16));
6858 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
6859 & 0xFF000000) >> 24));
6862 static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
6863 struct vb_device_info *pVBInfo)
6865 unsigned short tempbx, index;
6867 unsigned char tempcl, tempch, tempal, *filterPtr;
6869 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6871 switch (tempbx) {
6872 case 0x00:
6873 case 0x04:
6874 filterPtr = NTSCYFilter1;
6875 break;
6877 case 0x01:
6878 filterPtr = PALYFilter1;
6879 break;
6881 case 0x02:
6882 case 0x05:
6883 case 0x0D:
6884 case 0x03:
6885 filterPtr = xgifb_palmn_yfilter1;
6886 break;
6888 case 0x08:
6889 case 0x0C:
6890 case 0x0A:
6891 case 0x0B:
6892 case 0x09:
6893 filterPtr = xgifb_yfilter2;
6894 break;
6896 default:
6897 return;
6900 if (ModeNo <= 0x13)
6901 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
6902 VB_StTVYFilterIndex;
6903 else
6904 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
6905 VB_ExtTVYFilterIndex;
6907 if (tempcl == 0)
6908 index = tempal * 4;
6909 else
6910 index = tempal * 7;
6912 if ((tempcl == 0) && (tempch == 1)) {
6913 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6914 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6915 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6916 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
6917 } else {
6918 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6919 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6920 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6921 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
6924 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6925 | VB_XGI302LV | VB_XGI301C)) {
6926 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6927 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6928 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
6932 /* --------------------------------------------------------------------- */
6933 /* Function : XGI_OEM310Setting */
6934 /* Input : */
6935 /* Output : */
6936 /* Description : Customized Param. for 301 */
6937 /* --------------------------------------------------------------------- */
6938 static void XGI_OEM310Setting(unsigned short ModeNo,
6939 unsigned short ModeIdIndex,
6940 struct vb_device_info *pVBInfo)
6942 /* GetPart1IO(); */
6943 XGI_SetDelayComp(pVBInfo);
6945 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
6946 XGI_SetLCDCap(pVBInfo);
6948 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6949 /* GetPart2IO() */
6950 XGI_SetPhaseIncr(pVBInfo);
6951 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6952 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
6954 if (pVBInfo->VBType & VB_XGI301)
6955 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
6959 /* --------------------------------------------------------------------- */
6960 /* Function : XGI_SetCRT2ModeRegs */
6961 /* Input : */
6962 /* Output : */
6963 /* Description : Origin code for crt2group */
6964 /* --------------------------------------------------------------------- */
6965 void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
6966 struct xgi_hw_device_info *HwDeviceExtension,
6967 struct vb_device_info *pVBInfo)
6969 unsigned short tempbl;
6970 short tempcl;
6972 unsigned char tempah;
6974 /* // fix write part1 index 0 BTDRAM bit Bug
6975 * xgifb_reg_set(pVBInfo->Part1Port, 0x03, 0x00); */
6976 tempah = 0;
6977 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6978 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6979 tempah &= ~0x10; /* BTRAMDAC */
6980 tempah |= 0x40; /* BTRAM */
6982 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6983 | SetCRT2ToLCD)) {
6984 tempah = 0x40; /* BTDRAM */
6985 if (ModeNo > 0x13) {
6986 tempcl = pVBInfo->ModeType;
6987 tempcl -= ModeVGA;
6988 if (tempcl >= 0) {
6989 /* BT Color */
6990 tempah = (0x008 >> tempcl);
6991 if (tempah == 0)
6992 tempah = 1;
6993 tempah |= 0x040;
6996 if (pVBInfo->VBInfo & SetInSlaveMode)
6997 tempah ^= 0x50; /* BTDAC */
7001 /* 0210 shampoo
7002 if (pVBInfo->VBInfo & DisableCRT2Display) {
7003 tempah = 0;
7006 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
7007 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)) {
7008 tempcl = pVBInfo->ModeType;
7009 if (ModeNo > 0x13) {
7010 tempcl -= ModeVGA;
7011 if ((tempcl > 0) || (tempcl == 0)) {
7012 tempah=(0x008>>tempcl) ;
7013 if (tempah == 0)
7014 tempah = 1;
7015 tempah |= 0x040;
7017 } else {
7018 tempah = 0x040;
7021 if (pVBInfo->VBInfo & SetInSlaveMode) {
7022 tempah = (tempah ^ 0x050);
7027 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
7028 tempah = 0x08;
7029 tempbl = 0xf0;
7031 if (pVBInfo->VBInfo & DisableCRT2Display) {
7032 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
7033 } else {
7034 tempah = 0x00;
7035 tempbl = 0xff;
7037 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7038 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
7039 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
7040 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
7041 tempbl &= 0xf7;
7042 tempah |= 0x01;
7043 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
7044 tempbl, tempah);
7045 } else {
7046 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7047 tempbl &= 0xf7;
7048 tempah |= 0x01;
7051 if (pVBInfo->VBInfo &
7052 (SetCRT2ToRAMDAC |
7053 SetCRT2ToTV |
7054 SetCRT2ToLCD)) {
7055 tempbl &= 0xf8;
7056 tempah = 0x01;
7058 if (!(pVBInfo->VBInfo & SetInSlaveMode))
7059 tempah |= 0x02;
7061 if (!(pVBInfo->VBInfo &
7062 SetCRT2ToRAMDAC)) {
7063 tempah = tempah ^ 0x05;
7064 if (!(pVBInfo->VBInfo &
7065 SetCRT2ToLCD))
7066 tempah = tempah ^ 0x01;
7069 if (!(pVBInfo->VBInfo &
7070 SetCRT2ToDualEdge))
7071 tempah |= 0x08;
7072 xgifb_reg_and_or(pVBInfo->Part1Port,
7073 0x2e, tempbl, tempah);
7074 } else {
7075 xgifb_reg_and_or(pVBInfo->Part1Port,
7076 0x2e, tempbl, tempah);
7079 } else {
7080 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
7081 tempah);
7085 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
7086 | SetCRT2ToLCDA)) {
7087 tempah &= (~0x08);
7088 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
7089 & SetInSlaveMode))) {
7090 tempah |= 0x010;
7092 tempah |= 0x080;
7094 if (pVBInfo->VBInfo & SetCRT2ToTV) {
7095 /* if (!(pVBInfo->TVInfo &
7096 (SetYPbPrMode525p | SetYPbPrMode750p))) { */
7097 tempah |= 0x020;
7098 if (ModeNo > 0x13) {
7099 if (pVBInfo->VBInfo & DriverMode)
7100 tempah = tempah ^ 0x20;
7102 /* } */
7105 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
7106 tempah = 0;
7108 if (pVBInfo->LCDInfo & SetLCDDualLink)
7109 tempah |= 0x40;
7111 if (pVBInfo->VBInfo & SetCRT2ToTV) {
7112 /* if ((!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) &&
7113 (!(pVBInfo->TVInfo &
7114 (SetYPbPrMode525p | SetYPbPrMode750p)))) { */
7115 if (pVBInfo->TVInfo & RPLLDIV2XO)
7116 tempah |= 0x40;
7117 /* } */
7120 if ((pVBInfo->LCDResInfo == Panel1280x1024)
7121 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
7122 tempah |= 0x80;
7124 if (pVBInfo->LCDResInfo == Panel1280x960)
7125 tempah |= 0x80;
7127 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
7130 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7131 | VB_XGI302LV | VB_XGI301C)) {
7132 tempah = 0;
7133 tempbl = 0xfb;
7135 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7136 tempbl = 0xff;
7137 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7138 tempah |= 0x04; /* shampoo 0129 */
7141 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
7142 tempah = 0x00;
7143 tempbl = 0xcf;
7144 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7145 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7146 tempah |= 0x30;
7149 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
7150 tempah = 0;
7151 tempbl = 0x3f;
7153 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7154 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7155 tempah |= 0xc0;
7157 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
7160 tempah = 0;
7161 tempbl = 0x7f;
7162 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
7163 tempbl = 0xff;
7164 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
7165 tempah |= 0x80;
7168 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
7170 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7171 if (pVBInfo->LCDInfo & SetLCDDualLink) {
7172 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
7173 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
7178 static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
7179 struct vb_device_info *pVBInfo)
7181 unsigned short tempbx;
7183 tempbx = 0;
7185 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7186 tempbx = 0x08A0;
7190 void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7191 struct vb_device_info *pVBInfo)
7194 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
7198 void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7199 struct vb_device_info *pVBInfo)
7202 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
7206 unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
7208 unsigned short flag;
7210 if (pVBInfo->IF_DEF_LVDS == 1) {
7211 return 1;
7212 } else {
7213 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
7214 if ((flag == 1) || (flag == 2))
7215 return 1; /* 301b */
7216 else
7217 return 0;
7221 void XGI_LongWait(struct vb_device_info *pVBInfo)
7223 unsigned short i;
7225 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
7227 if (!(i & 0xC0)) {
7228 for (i = 0; i < 0xFFFF; i++) {
7229 if (!(inb(pVBInfo->P3da) & 0x08))
7230 break;
7233 for (i = 0; i < 0xFFFF; i++) {
7234 if ((inb(pVBInfo->P3da) & 0x08))
7235 break;
7240 static void XGI_VBLongWait(struct vb_device_info *pVBInfo)
7242 unsigned short tempal, temp, i, j;
7243 return;
7244 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
7245 temp = 0;
7246 for (i = 0; i < 3; i++) {
7247 for (j = 0; j < 100; j++) {
7248 tempal = inb(pVBInfo->P3da);
7249 if (temp & 0x01) { /* VBWaitMode2 */
7250 if ((tempal & 0x08))
7251 continue;
7253 if (!(tempal & 0x08))
7254 break;
7256 } else { /* VBWaitMode1 */
7257 if (!(tempal & 0x08))
7258 continue;
7260 if ((tempal & 0x08))
7261 break;
7264 temp = temp ^ 0x01;
7266 } else {
7267 XGI_LongWait(pVBInfo);
7269 return;
7272 unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
7273 unsigned short ModeNo, unsigned short ModeIdIndex,
7274 struct vb_device_info *pVBInfo)
7276 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
7277 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
7278 0x01, 0x01 };
7280 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
7282 if (ModeNo <= 0x13)
7283 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7284 else
7285 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7287 if (ModeNo < 0x14)
7288 return 0xFFFF;
7290 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
7291 index = index >> pVBInfo->SelectCRT2Rate;
7292 index &= 0x0F;
7294 if (pVBInfo->LCDInfo & LCDNonExpanding)
7295 index = 0;
7297 if (index > 0)
7298 index--;
7300 if (pVBInfo->SetFlag & ProgrammingCRT2) {
7301 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
7302 if (pVBInfo->IF_DEF_LVDS == 0) {
7303 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7304 | VB_XGI301LV | VB_XGI302LV
7305 | VB_XGI301C))
7306 /* 301b */
7307 temp = LCDARefreshIndex[
7308 pVBInfo->LCDResInfo & 0x0F];
7309 else
7310 temp = LCDRefreshIndex[
7311 pVBInfo->LCDResInfo & 0x0F];
7313 if (index > temp)
7314 index = temp;
7315 } else {
7316 index = 0;
7321 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
7322 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
7323 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
7325 if (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag &
7326 XG2xNotSupport) {
7327 index++;
7330 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
7331 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
7332 index++;
7334 /* Alan 10/19/2007;
7335 * do the similar adjustment like XGISearchCRT1Rate() */
7336 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
7337 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
7338 index++;
7340 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
7341 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
7342 index++;
7346 i = 0;
7347 do {
7348 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
7349 ModeID != ModeNo)
7350 break;
7351 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
7352 Ext_InfoFlag;
7353 temp &= ModeInfoFlag;
7354 if (temp < pVBInfo->ModeType)
7355 break;
7356 i++;
7357 index--;
7359 } while (index != 0xFFFF);
7360 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
7361 if (pVBInfo->VBInfo & SetInSlaveMode) {
7362 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
7363 Ext_InfoFlag;
7364 if (temp & InterlaceMode)
7365 i++;
7368 i--;
7369 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7370 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7371 RefreshRateTableIndex, &i, pVBInfo);
7373 return RefreshRateTableIndex + i; /* return (0x01 | (temp1<<1)); */
7376 static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
7377 struct xgi_hw_device_info *HwDeviceExtension,
7378 struct vb_device_info *pVBInfo)
7380 unsigned short RefreshRateTableIndex;
7381 /* unsigned short temp ; */
7383 /* pVBInfo->SelectCRT2Rate = 0; */
7385 pVBInfo->SetFlag |= ProgrammingCRT2;
7386 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7387 ModeIdIndex, pVBInfo);
7388 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7389 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7390 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7391 HwDeviceExtension, pVBInfo);
7392 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7393 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7396 unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
7397 struct xgi_hw_device_info *HwDeviceExtension,
7398 struct vb_device_info *pVBInfo)
7400 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
7402 tempbx = pVBInfo->VBInfo;
7403 pVBInfo->SetFlag |= ProgrammingCRT2;
7404 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7405 pVBInfo->SelectCRT2Rate = 4;
7406 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7407 ModeIdIndex, pVBInfo);
7408 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7409 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7410 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7411 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7412 RefreshRateTableIndex, pVBInfo);
7413 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7414 RefreshRateTableIndex, pVBInfo);
7415 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7416 RefreshRateTableIndex, pVBInfo);
7417 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7418 HwDeviceExtension, pVBInfo);
7419 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7420 RefreshRateTableIndex, pVBInfo);
7421 XGI_SetTap4Regs(pVBInfo);
7422 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7423 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7424 HwDeviceExtension, pVBInfo);
7425 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7426 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7427 XGI_AutoThreshold(pVBInfo);
7428 return 1;
7431 void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7433 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7434 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7435 0x05, 0x00 };
7437 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
7439 unsigned char CR17, CR63, SR31;
7440 unsigned short temp;
7441 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
7443 int i;
7444 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
7446 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
7447 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
7448 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
7449 pVBInfo->P3d4, 0x53) | 0x02));
7451 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7452 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7453 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
7455 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7456 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
7458 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
7459 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
7461 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
7462 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
7464 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
7465 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
7466 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
7467 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
7469 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
7471 for (i = 0; i < 8; i++)
7472 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
7474 for (i = 8; i < 11; i++)
7475 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
7476 CRTCData[i]);
7478 for (i = 11; i < 13; i++)
7479 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
7480 CRTCData[i]);
7482 for (i = 13; i < 16; i++)
7483 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
7484 CRTCData[i]);
7486 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
7487 & 0xE0));
7489 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
7490 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7491 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
7493 outb(0x00, pVBInfo->P3c8);
7495 for (i = 0; i < 256; i++) {
7496 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
7497 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
7498 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
7501 XGI_VBLongWait(pVBInfo);
7502 XGI_VBLongWait(pVBInfo);
7503 XGI_VBLongWait(pVBInfo);
7505 mdelay(1);
7507 XGI_WaitDisply(pVBInfo);
7508 temp = inb(pVBInfo->P3c2);
7510 if (temp & 0x10)
7511 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
7512 else
7513 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
7515 /* alan, avoid display something, set BLACK DAC if not restore DAC */
7516 outb(0x00, pVBInfo->P3c8);
7518 for (i = 0; i < 256; i++) {
7519 outb(0, (pVBInfo->P3c8 + 1));
7520 outb(0, (pVBInfo->P3c8 + 1));
7521 outb(0, (pVBInfo->P3c8 + 1));
7524 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
7525 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
7526 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
7528 /* [2004/05/11] Vicent */
7529 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
7530 pVBInfo->P3d4, 0x53) & 0xFD));
7531 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
7534 void XGI_EnableBridge(struct xgi_hw_device_info *HwDeviceExtension,
7535 struct vb_device_info *pVBInfo)
7537 unsigned short tempah;
7539 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7540 | VB_XGI302LV | VB_XGI301C)) {
7541 if (!(pVBInfo->SetFlag & DisableChA)) {
7542 if (pVBInfo->SetFlag & EnableChA) {
7543 /* Power on */
7544 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
7545 } else {
7546 /* SetCRT2ToLCDA ) */
7547 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7548 /* Power on */
7549 xgifb_reg_set(pVBInfo->Part1Port,
7550 0x1E, 0x20);
7555 if (!(pVBInfo->SetFlag & DisableChB)) {
7556 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
7557 & (SetCRT2ToLCD | SetCRT2ToTV
7558 | SetCRT2ToRAMDAC))) {
7559 tempah = (unsigned char) xgifb_reg_get(
7560 pVBInfo->P3c4, 0x32);
7561 tempah &= 0xDF;
7562 if (pVBInfo->VBInfo & SetInSlaveMode) {
7563 if (!(pVBInfo->VBInfo &
7564 SetCRT2ToRAMDAC))
7565 tempah |= 0x20;
7567 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
7568 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
7570 tempah = (unsigned char) xgifb_reg_get(
7571 pVBInfo->Part1Port, 0x2E);
7573 if (!(tempah & 0x80))
7574 /* BVBDOENABLE = 1 */
7575 xgifb_reg_or(pVBInfo->Part1Port,
7576 0x2E, 0x80);
7577 /* BScreenOFF = 0 */
7578 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
7582 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
7583 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
7584 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
7585 0x20); /* shampoo 0129 */
7586 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7587 if (!XGI_DisableChISLCD(pVBInfo)) {
7588 if (XGI_EnableChISLCD(pVBInfo) ||
7589 (pVBInfo->VBInfo &
7590 (SetCRT2ToLCD | SetCRT2ToLCDA)))
7591 /* LVDS PLL power on */
7592 xgifb_reg_and(
7593 pVBInfo->Part4Port,
7594 0x2A,
7595 0x7F);
7597 /* LVDS Driver power on */
7598 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
7602 tempah = 0x00;
7604 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7605 tempah = 0xc0;
7607 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
7608 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7609 if (pVBInfo->VBInfo &
7610 SetCRT2ToDualEdge) {
7611 tempah = tempah & 0x40;
7612 if (pVBInfo->VBInfo &
7613 SetCRT2ToLCDA)
7614 tempah = tempah ^ 0xC0;
7616 if (pVBInfo->SetFlag &
7617 DisableChB)
7618 tempah &= 0xBF;
7620 if (pVBInfo->SetFlag &
7621 DisableChA)
7622 tempah &= 0x7F;
7624 if (pVBInfo->SetFlag &
7625 EnableChB)
7626 tempah |= 0x40;
7628 if (pVBInfo->SetFlag &
7629 EnableChA)
7630 tempah |= 0x80;
7636 /* EnablePart4_1F */
7637 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
7639 if (!(pVBInfo->SetFlag & DisableChA)) {
7640 XGI_VBLongWait(pVBInfo);
7641 if (!(pVBInfo->SetFlag & GatingCRT)) {
7642 XGI_DisableGatingCRT(HwDeviceExtension,
7643 pVBInfo);
7644 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7645 XGI_VBLongWait(pVBInfo);
7648 } /* 301 */
7649 else { /* LVDS */
7650 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
7651 | SetCRT2ToLCDA))
7652 /* enable CRT2 */
7653 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
7655 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
7656 0x2E);
7657 if (!(tempah & 0x80))
7658 /* BVBDOENABLE = 1 */
7659 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
7661 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
7662 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7663 } /* End of VB */
7666 static void XGI_SetCRT1Group(struct xgi_hw_device_info *HwDeviceExtension,
7667 unsigned short ModeNo, unsigned short ModeIdIndex,
7668 struct vb_device_info *pVBInfo)
7670 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
7672 unsigned short XGINew_P3cc = pVBInfo->P3cc;
7674 /* XGINew_CRT1Mode = ModeNo; // SaveModeID */
7675 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
7676 /* XGI_SetBIOSData(ModeNo, ModeIdIndex); */
7677 /* XGI_ClearBankRegs(ModeNo, ModeIdIndex); */
7678 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7679 XGI_SetMiscRegs(StandTableIndex, pVBInfo);
7680 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7681 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7682 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7683 XGI_ClearExt1Regs(pVBInfo);
7685 /* if (pVBInfo->IF_DEF_ExpLink) */
7686 if (HwDeviceExtension->jChipType == XG27) {
7687 if (pVBInfo->IF_DEF_LVDS == 0)
7688 XGI_SetDefaultVCLK(pVBInfo);
7691 temp = ~ProgrammingCRT2;
7692 pVBInfo->SetFlag &= temp;
7693 pVBInfo->SelectCRT2Rate = 0;
7695 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7696 | VB_XGI302LV | VB_XGI301C)) {
7697 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
7698 | SetInSlaveMode)) {
7699 pVBInfo->SetFlag |= ProgrammingCRT2;
7703 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7704 ModeIdIndex, pVBInfo);
7705 if (RefreshRateTableIndex != 0xFFFF) {
7706 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
7707 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7708 pVBInfo, HwDeviceExtension);
7709 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
7710 RefreshRateTableIndex, pVBInfo);
7711 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7712 HwDeviceExtension, pVBInfo);
7713 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
7714 RefreshRateTableIndex, pVBInfo);
7717 if ((HwDeviceExtension->jChipType >= XG20) &&
7718 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
7719 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
7720 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7721 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
7722 b3CC = (unsigned char) inb(XGINew_P3cc);
7723 outb((b3CC |= 0x0C), XGINew_P3cc);
7724 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7725 == 0x0D)) {
7726 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7727 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
7728 b3CC = (unsigned char) inb(XGINew_P3cc);
7729 outb((b3CC |= 0x0C), XGINew_P3cc);
7733 if (HwDeviceExtension->jChipType >= XG21) {
7734 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
7735 if (temp & 0xA0) {
7737 /* Enable write GPIOF */
7738 /* xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20); */
7739 /* P. DWN */
7740 /* xgifb_reg_and(pVBInfo->P3d4, 0x48, ~0x20); */
7741 /* XG21 CRT1 Timing */
7742 if (HwDeviceExtension->jChipType == XG27)
7743 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
7744 RefreshRateTableIndex, pVBInfo);
7745 else
7746 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
7747 RefreshRateTableIndex, pVBInfo);
7749 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
7750 RefreshRateTableIndex);
7752 xgifb_set_lcd(HwDeviceExtension->jChipType,
7753 pVBInfo, RefreshRateTableIndex, ModeNo);
7755 if (pVBInfo->IF_DEF_LVDS == 1)
7756 xgifb_set_lvds(HwDeviceExtension->jChipType,
7757 ModeNo, ModeIdIndex, pVBInfo);
7758 /* P. ON */
7759 /* xgifb_reg_or(pVBInfo->P3d4, 0x48, 0x20); */
7763 pVBInfo->SetFlag &= (~ProgrammingCRT2);
7764 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
7765 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
7766 RefreshRateTableIndex, pVBInfo);
7768 /* XGI_LoadCharacter(); //dif ifdef TVFont */
7770 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
7771 /* XGI_ClearBuffer(HwDeviceExtension, ModeNo, pVBInfo); */
7774 unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
7775 unsigned short ModeNo)
7777 unsigned short ModeIdIndex;
7778 /* unsigned char *pVBInfo->FBAddr =
7779 HwDeviceExtension->pjVideoMemoryAddress; */
7780 struct vb_device_info VBINF;
7781 struct vb_device_info *pVBInfo = &VBINF;
7782 pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase;
7783 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
7784 pVBInfo->IF_DEF_LVDS = 0;
7785 pVBInfo->IF_DEF_LCDA = 1;
7787 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
7788 pVBInfo->IF_DEF_YPbPr = 0;
7789 pVBInfo->IF_DEF_HiVision = 0;
7790 pVBInfo->IF_DEF_CRT2Monitor = 0;
7791 pVBInfo->VBType = 0; /*set VBType default 0*/
7792 } else {
7793 pVBInfo->IF_DEF_YPbPr = 1;
7794 pVBInfo->IF_DEF_HiVision = 1;
7795 pVBInfo->IF_DEF_CRT2Monitor = 1;
7798 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
7799 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
7800 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
7801 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
7802 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
7803 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
7804 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
7805 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
7806 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
7807 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
7808 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
7809 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
7810 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
7811 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
7812 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
7813 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
7814 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
7815 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
7817 /* for x86 Linux, XG21 LVDS */
7818 if (HwDeviceExtension->jChipType == XG21) {
7819 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
7820 pVBInfo->IF_DEF_LVDS = 1;
7822 if (HwDeviceExtension->jChipType == XG27) {
7823 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
7824 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
7825 pVBInfo->IF_DEF_LVDS = 1;
7829 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
7830 XGI_GetVBType(pVBInfo);
7832 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
7833 if (ModeNo & 0x80) {
7834 ModeNo = ModeNo & 0x7F;
7835 /* XGINew_flag_clearbuffer = 0; */
7837 /* else {
7838 XGINew_flag_clearbuffer = 1;
7841 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
7843 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
7844 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
7846 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7848 XGI_GetVGAType(HwDeviceExtension, pVBInfo);
7850 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7851 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
7852 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
7853 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
7854 XGI_DisableBridge(HwDeviceExtension, pVBInfo);
7856 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
7857 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7858 ModeIdIndex, pVBInfo);
7860 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7861 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7862 HwDeviceExtension, pVBInfo);
7864 } else {
7865 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
7866 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7867 ModeIdIndex, pVBInfo);
7868 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7869 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7870 HwDeviceExtension,
7871 pVBInfo);
7876 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
7877 switch (HwDeviceExtension->ujVBChipID) {
7878 case VB_CHIP_301:
7879 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7880 pVBInfo); /*add for CRT2 */
7881 break;
7883 case VB_CHIP_302:
7884 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7885 pVBInfo); /*add for CRT2 */
7886 break;
7888 default:
7889 break;
7893 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
7894 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
7895 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
7896 XGI_EnableBridge(HwDeviceExtension, pVBInfo);
7897 } /* !XG20 */
7898 else {
7899 if (pVBInfo->IF_DEF_LVDS == 1)
7900 if (!XGI_XG21CheckLVDSMode(ModeNo,
7901 ModeIdIndex,
7902 pVBInfo))
7903 return 0;
7905 if (ModeNo <= 0x13) {
7906 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
7907 St_ModeFlag & ModeInfoFlag;
7908 } else {
7909 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
7910 Ext_ModeFlag & ModeInfoFlag;
7913 pVBInfo->SetFlag = 0;
7914 pVBInfo->VBInfo = DisableCRT2Display;
7916 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
7918 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex,
7919 pVBInfo);
7921 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7923 if (HwDeviceExtension->jChipType == XG21)
7924 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0x80, 0x80);
7929 if (ModeNo <= 0x13) {
7930 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7931 } else {
7932 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7934 pVBInfo->ModeType = modeflag&ModeInfoFlag;
7935 pVBInfo->SetFlag = 0x00;
7936 pVBInfo->VBInfo = DisableCRT2Display;
7937 temp = XGINew_CheckMemorySize(HwDeviceExtension,
7938 ModeNo,
7939 ModeIdIndex,
7940 pVBInfo);
7942 if (temp == 0)
7943 return (0);
7945 XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
7946 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo);
7947 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7950 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
7952 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7953 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
7956 return 1;